Convert internal methods to handle safe JSContext instead of raw JSContext

This commit is contained in:
marmeladema 2019-07-21 22:22:44 +01:00
parent 2fb3f1f983
commit 808fa65aef
4 changed files with 151 additions and 139 deletions

View file

@ -323,7 +323,7 @@ class CGMethodCall(CGThing):
if requiredArgs > 0:
code = (
"if argc < %d {\n"
" throw_type_error(cx, \"Not enough arguments to %s.\");\n"
" throw_type_error(*cx, \"Not enough arguments to %s.\");\n"
" return false;\n"
"}" % (requiredArgs, methodName))
self.cgRoot.prepend(
@ -448,7 +448,7 @@ class CGMethodCall(CGThing):
# XXXbz Now we're supposed to check for distinguishingArg being
# an array or a platform object that supports indexed
# properties... skip that last for now. It's a bit of a pain.
pickFirstSignature("%s.get().is_object() && is_array_like(cx, %s)" %
pickFirstSignature("%s.get().is_object() && is_array_like(*cx, %s)" %
(distinguishingArg, distinguishingArg),
lambda s:
(s[1][distinguishingIndex].type.isSequence() or
@ -457,9 +457,9 @@ class CGMethodCall(CGThing):
# Check for Date objects
# XXXbz Do we need to worry about security wrappers around the Date?
pickFirstSignature("%s.get().is_object() && "
"{ rooted!(in(cx) let obj = %s.get().to_object()); "
"{ rooted!(in(*cx) let obj = %s.get().to_object()); "
"let mut is_date = false; "
"assert!(ObjectIsDate(cx, obj.handle(), &mut is_date)); "
"assert!(ObjectIsDate(*cx, obj.handle(), &mut is_date)); "
"is_date }" %
(distinguishingArg, distinguishingArg),
lambda s: (s[1][distinguishingIndex].type.isDate() or
@ -467,7 +467,7 @@ class CGMethodCall(CGThing):
# Check for vanilla JS objects
# XXXbz Do we need to worry about security wrappers?
pickFirstSignature("%s.get().is_object() && !is_platform_object(%s.get().to_object(), cx)" %
pickFirstSignature("%s.get().is_object() && !is_platform_object(%s.get().to_object(), *cx)" %
(distinguishingArg, distinguishingArg),
lambda s: (s[1][distinguishingIndex].type.isCallback() or
s[1][distinguishingIndex].type.isCallbackInterface() or
@ -492,7 +492,7 @@ class CGMethodCall(CGThing):
else:
# Just throw; we have no idea what we're supposed to
# do with this.
caseBody.append(CGGeneric("throw_internal_error(cx, \"Could not convert JavaScript argument\");\n"
caseBody.append(CGGeneric("throw_internal_error(*cx, \"Could not convert JavaScript argument\");\n"
"return false;"))
argCountCases.append(CGCase(str(argCount),
@ -505,7 +505,7 @@ class CGMethodCall(CGThing):
overloadCGThings.append(
CGSwitch("argcount",
argCountCases,
CGGeneric("throw_type_error(cx, \"Not enough arguments to %s.\");\n"
CGGeneric("throw_type_error(*cx, \"Not enough arguments to %s.\");\n"
"return false;" % methodName)))
# XXXjdm Avoid unreachable statement warnings
# overloadCGThings.append(
@ -638,7 +638,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
exceptionCode = "return false;\n"
if failureCode is None:
failOrPropagate = "throw_type_error(cx, &error);\n%s" % exceptionCode
failOrPropagate = "throw_type_error(*cx, &error);\n%s" % exceptionCode
else:
failOrPropagate = failureCode
@ -657,20 +657,20 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
return CGWrapper(
CGGeneric(
failureCode or
('throw_type_error(cx, "%s is not an object.");\n'
('throw_type_error(*cx, "%s is not an object.");\n'
'%s' % (firstCap(sourceDescription), exceptionCode))),
post="\n")
def onFailureInvalidEnumValue(failureCode, passedVarName):
return CGGeneric(
failureCode or
('throw_type_error(cx, &format!("\'{}\' is not a valid enum value for enumeration \'%s\'.", %s)); %s'
('throw_type_error(*cx, &format!("\'{}\' is not a valid enum value for enumeration \'%s\'.", %s)); %s'
% (type.name, passedVarName, exceptionCode)))
def onFailureNotCallable(failureCode):
return CGGeneric(
failureCode or
('throw_type_error(cx, \"%s is not callable.\");\n'
('throw_type_error(*cx, \"%s is not callable.\");\n'
'%s' % (firstCap(sourceDescription), exceptionCode)))
# A helper function for handling default values.
@ -723,7 +723,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=" >")
templateBody = ("match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
templateBody = ("match FromJSValConvertible::from_jsval(*cx, ${val}, %s) {\n"
" Ok(ConversionResult::Success(value)) => value,\n"
" Ok(ConversionResult::Failure(error)) => {\n"
"%s\n"
@ -738,7 +738,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=" >")
templateBody = ("match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
templateBody = ("match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
" Ok(ConversionResult::Success(value)) => value,\n"
" Ok(ConversionResult::Failure(error)) => {\n"
"%s\n"
@ -803,17 +803,17 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
"""
{ // Scope for our JSAutoRealm.
rooted!(in(cx) let globalObj = CurrentGlobalOrNull(cx));
let promiseGlobal = GlobalScope::from_object_maybe_wrapped(globalObj.handle().get(), cx);
rooted!(in(*cx) let globalObj = CurrentGlobalOrNull(*cx));
let promiseGlobal = GlobalScope::from_object_maybe_wrapped(globalObj.handle().get(), *cx);
rooted!(in(cx) let mut valueToResolve = $${val}.get());
if !JS_WrapValue(cx, valueToResolve.handle_mut()) {
rooted!(in(*cx) let mut valueToResolve = $${val}.get());
if !JS_WrapValue(*cx, valueToResolve.handle_mut()) {
$*{exceptionCode}
}
match Promise::new_resolved(&promiseGlobal, cx, valueToResolve.handle()) {
match Promise::new_resolved(&promiseGlobal, *cx, valueToResolve.handle()) {
Ok(value) => value,
Err(error) => {
throw_dom_exception(cx, &promiseGlobal, error);
throw_dom_exception(*cx, &promiseGlobal, error);
$*{exceptionCode}
}
}
@ -836,7 +836,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if descriptor.interface.isCallback():
name = descriptor.nativeType
declType = CGWrapper(CGGeneric(name), pre="Rc<", post=">")
template = "%s::new(SafeJSContext::from_ptr(cx), ${val}.get().to_object())" % name
template = "%s::new(cx, ${val}.get().to_object())" % name
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=">")
template = wrapObjectTemplate("Some(%s)" % template, "None",
@ -864,7 +864,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
"exceptionCode": exceptionCode,
}
unwrapFailureCode = string.Template(
'throw_type_error(cx, "${sourceDescription} does not '
'throw_type_error(*cx, "${sourceDescription} does not '
'implement interface ${interface}.");\n'
'${exceptionCode}').substitute(substitutions)
else:
@ -872,7 +872,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
templateBody = fill(
"""
match ${function}($${val}, cx) {
match ${function}($${val}, *cx) {
Ok(val) => val,
Err(()) => {
$*{failureCode}
@ -899,7 +899,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
"exceptionCode": exceptionCode,
}
unwrapFailureCode = string.Template(
'throw_type_error(cx, "${sourceDescription} is not a typed array.");\n'
'throw_type_error(*cx, "${sourceDescription} is not a typed array.");\n'
'${exceptionCode}').substitute(substitutions)
else:
unwrapFailureCode = failureCode
@ -942,7 +942,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
nullBehavior = getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs)
conversionCode = (
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
"match FromJSValConvertible::from_jsval(*cx, ${val}, %s) {\n"
" Ok(ConversionResult::Success(strval)) => strval,\n"
" Ok(ConversionResult::Failure(error)) => {\n"
"%s\n"
@ -971,7 +971,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
assert not isEnforceRange and not isClamp
conversionCode = (
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
"match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
" Ok(ConversionResult::Success(strval)) => strval,\n"
" Ok(ConversionResult::Failure(error)) => {\n"
"%s\n"
@ -1000,7 +1000,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
assert not isEnforceRange and not isClamp
conversionCode = (
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
"match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
" Ok(ConversionResult::Success(strval)) => strval,\n"
" Ok(ConversionResult::Failure(error)) => {\n"
"%s\n"
@ -1038,7 +1038,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
handleInvalidEnumValueCode = "return true;"
template = (
"match find_enum_value(cx, ${val}, %(pairs)s) {\n"
"match find_enum_value(*cx, ${val}, %(pairs)s) {\n"
" Err(_) => { %(exceptionCode)s },\n"
" Ok((None, search)) => { %(handleInvalidEnumValueCode)s },\n"
" Ok((Some(&value), _)) => value,\n"
@ -1174,7 +1174,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type_needs_tracing(type):
declType = CGTemplatedType("RootedTraceableBox", declType)
template = ("match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
template = ("match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
" Ok(ConversionResult::Success(dictionary)) => dictionary,\n"
" Ok(ConversionResult::Failure(error)) => {\n"
"%s\n"
@ -1202,7 +1202,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
declType = CGWrapper(declType, pre="Option<", post=">")
template = (
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
"match FromJSValConvertible::from_jsval(*cx, ${val}, %s) {\n"
" Ok(ConversionResult::Success(v)) => v,\n"
" Ok(ConversionResult::Failure(error)) => {\n"
"%s\n"
@ -1260,7 +1260,7 @@ def instantiateJSToNativeConversionTemplate(templateBody, replacements,
result.append(conversion)
if needsAutoRoot:
result.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (declName, declName)))
result.append(CGGeneric("auto_root!(in(*cx) let %s = %s);" % (declName, declName)))
# Add an empty CGGeneric to get an extra newline after the argument
# conversion.
result.append(CGGeneric(""))
@ -1383,7 +1383,7 @@ def wrapForType(jsvalRef, result='result', successCode='return true;', pre=''):
* 'successCode': the code to run once we have done the conversion.
* 'pre': code to run before the conversion if rooting is necessary
"""
wrap = "%s\n(%s).to_jsval(cx, %s);" % (pre, result, jsvalRef)
wrap = "%s\n(%s).to_jsval(*cx, %s);" % (pre, result, jsvalRef)
if successCode:
wrap += "\n%s" % successCode
return wrap
@ -2364,7 +2364,7 @@ class CGGeneric(CGThing):
class CGCallbackTempRoot(CGGeneric):
def __init__(self, name):
CGGeneric.__init__(self, "%s::new(SafeJSContext::from_ptr(cx), ${val}.get().to_object())" % name)
CGGeneric.__init__(self, "%s::new(cx, ${val}.get().to_object())" % name)
def getAllTypes(descriptors, dictionaries, callbacks, typedefs):
@ -2410,6 +2410,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'crate::dom::bindings::str::USVString',
'crate::dom::bindings::trace::RootedTraceableBox',
'crate::dom::types::*',
'crate::script_runtime::JSContext as SafeJSContext',
'js::error::throw_type_error',
'js::rust::HandleValue',
'js::jsapi::Heap',
@ -3331,9 +3332,9 @@ class CGCallGenerator(CGThing):
needsCx = needCx(returnType, (a for (a, _) in arguments), True)
if "cx" not in argsPre and needsCx:
args.prepend(CGGeneric("cx"))
args.prepend(CGGeneric("*cx"))
if nativeMethodName in descriptor.inCompartmentMethods:
args.append(CGGeneric("InCompartment::in_compartment(&AlreadyInCompartment::assert_for_cx(cx))"))
args.append(CGGeneric("InCompartment::in_compartment(&AlreadyInCompartment::assert_for_cx(*cx))"))
# Build up our actual call
self.cgRoot = CGList([], "\n")
@ -3369,7 +3370,7 @@ class CGCallGenerator(CGThing):
"let result = match result {\n"
" Ok(result) => result,\n"
" Err(e) => {\n"
" throw_dom_exception(cx, %s, e);\n"
" throw_dom_exception(*cx, %s, e);\n"
" return%s;\n"
" },\n"
"};" % (glob, errorResult)))
@ -3593,7 +3594,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
def __init__(self, descriptor, method):
self.method = method
name = method.identifier.name
args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', '_obj'),
args = [Argument('SafeJSContext', 'cx'), Argument('HandleObject', '_obj'),
Argument('*const %s' % descriptor.concreteType, 'this'),
Argument('*const JSJitMethodCallArgs', 'args')]
CGAbstractExternMethod.__init__(self, descriptor, name, 'bool', args)
@ -3628,9 +3629,10 @@ class CGStaticMethod(CGAbstractStaticBindingMethod):
def generate_code(self):
nativeName = CGSpecializedMethod.makeNativeName(self.descriptor,
self.method)
safeContext = CGGeneric("let cx = SafeJSContext::from_ptr(cx);\n")
setupArgs = CGGeneric("let args = CallArgs::from_vp(vp, argc);\n")
call = CGMethodCall(["&global"], nativeName, True, self.descriptor, self.method)
return CGList([setupArgs, call])
return CGList([safeContext, setupArgs, call])
class CGSpecializedGetter(CGAbstractExternMethod):
@ -3641,7 +3643,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
def __init__(self, descriptor, attr):
self.attr = attr
name = 'get_' + descriptor.internalNameFor(attr.identifier.name)
args = [Argument('*mut JSContext', 'cx'),
args = [Argument('SafeJSContext', 'cx'),
Argument('HandleObject', '_obj'),
Argument('*const %s' % descriptor.concreteType, 'this'),
Argument('JSJitGetterCallArgs', 'args')]
@ -3682,10 +3684,11 @@ class CGStaticGetter(CGAbstractStaticBindingMethod):
def generate_code(self):
nativeName = CGSpecializedGetter.makeNativeName(self.descriptor,
self.attr)
safeContext = CGGeneric("let cx = SafeJSContext::from_ptr(cx);\n")
setupArgs = CGGeneric("let args = CallArgs::from_vp(vp, argc);\n")
call = CGGetterCall(["&global"], self.attr.type, nativeName, self.descriptor,
self.attr)
return CGList([setupArgs, call])
return CGList([safeContext, setupArgs, call])
class CGSpecializedSetter(CGAbstractExternMethod):
@ -3696,7 +3699,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
def __init__(self, descriptor, attr):
self.attr = attr
name = 'set_' + descriptor.internalNameFor(attr.identifier.name)
args = [Argument('*mut JSContext', 'cx'),
args = [Argument('SafeJSContext', 'cx'),
Argument('HandleObject', 'obj'),
Argument('*const %s' % descriptor.concreteType, 'this'),
Argument('JSJitSetterCallArgs', 'args')]
@ -3730,15 +3733,16 @@ class CGStaticSetter(CGAbstractStaticBindingMethod):
def generate_code(self):
nativeName = CGSpecializedSetter.makeNativeName(self.descriptor,
self.attr)
safeContext = CGGeneric("let cx = SafeJSContext::from_ptr(cx);\n")
checkForArg = CGGeneric(
"let args = CallArgs::from_vp(vp, argc);\n"
"if argc == 0 {\n"
" throw_type_error(cx, \"Not enough arguments to %s setter.\");\n"
" throw_type_error(*cx, \"Not enough arguments to %s setter.\");\n"
" return false;\n"
"}" % self.attr.identifier.name)
call = CGSetterCall(["&global"], self.attr.type, nativeName, self.descriptor,
self.attr)
return CGList([checkForArg, call])
return CGList([safeContext, checkForArg, call])
class CGSpecializedForwardingSetter(CGSpecializedSetter):
@ -3755,16 +3759,16 @@ class CGSpecializedForwardingSetter(CGSpecializedSetter):
assert all(ord(c) < 128 for c in attrName)
assert all(ord(c) < 128 for c in forwardToAttrName)
return CGGeneric("""\
rooted!(in(cx) let mut v = UndefinedValue());
if !JS_GetProperty(cx, obj, %s as *const u8 as *const libc::c_char, v.handle_mut()) {
rooted!(in(*cx) let mut v = UndefinedValue());
if !JS_GetProperty(*cx, obj, %s as *const u8 as *const libc::c_char, v.handle_mut()) {
return false;
}
if !v.is_object() {
throw_type_error(cx, "Value.%s is not an object.");
throw_type_error(*cx, "Value.%s is not an object.");
return false;
}
rooted!(in(cx) let target_obj = v.to_object());
JS_SetProperty(cx, target_obj.handle(), %s as *const u8 as *const libc::c_char, HandleValue::from_raw(args.get(0)))
rooted!(in(*cx) let target_obj = v.to_object());
JS_SetProperty(*cx, target_obj.handle(), %s as *const u8 as *const libc::c_char, HandleValue::from_raw(args.get(0)))
""" % (str_to_const_array(attrName), attrName, str_to_const_array(forwardToAttrName)))
@ -3781,7 +3785,7 @@ class CGSpecializedReplaceableSetter(CGSpecializedSetter):
# JS_DefineProperty can only deal with ASCII.
assert all(ord(c) < 128 for c in name)
return CGGeneric("""\
JS_DefineProperty(cx, obj, %s as *const u8 as *const libc::c_char,
JS_DefineProperty(*cx, obj, %s as *const u8 as *const libc::c_char,
HandleValue::from_raw(args.get(0)), JSPROP_ENUMERATE as u32)""" % name)
@ -4370,7 +4374,7 @@ class CGUnionConversionStruct(CGThing):
def get_match(name):
return (
"match %s::TryConvertTo%s(cx, value) {\n"
"match %s::TryConvertTo%s(SafeJSContext::from_ptr(cx), value) {\n"
" Err(_) => return Err(()),\n"
" Ok(Some(value)) => return Ok(ConversionResult::Success(%s::%s(value))),\n"
" Ok(None) => (),\n"
@ -4510,7 +4514,7 @@ class CGUnionConversionStruct(CGThing):
return CGWrapper(
CGIndenter(jsConversion, 4),
pre="unsafe fn TryConvertTo%s(cx: *mut JSContext, value: HandleValue) -> %s {\n"
pre="unsafe fn TryConvertTo%s(cx: SafeJSContext, value: HandleValue) -> %s {\n"
% (t.name, returnType),
post="\n}")
@ -4903,7 +4907,7 @@ class CGProxySpecialOperation(CGPerSignatureCall):
}
self.cgRoot.prepend(instantiateJSToNativeConversionTemplate(
template, templateValues, declType, argument.identifier.name))
self.cgRoot.prepend(CGGeneric("rooted!(in(cx) let value = desc.value);"))
self.cgRoot.prepend(CGGeneric("rooted!(in(*cx) let value = desc.value);"))
def getArguments(self):
args = [(a, process_arg(a.identifier.name, a)) for a in self.arguments]
@ -4946,7 +4950,7 @@ class CGProxyNamedOperation(CGProxySpecialOperation):
def define(self):
# Our first argument is the id we're getting.
argName = self.arguments[0].identifier.name
return ("let %s = jsid_to_string(cx, Handle::from_raw(id)).expect(\"Not a string-convertible JSID?\");\n"
return ("let %s = jsid_to_string(*cx, Handle::from_raw(id)).expect(\"Not a string-convertible JSID?\");\n"
"let this = UnwrapProxy(proxy);\n"
"let this = &*this;\n" % argName +
CGProxySpecialOperation.define(self))
@ -5015,9 +5019,9 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
def getBody(self):
indexedGetter = self.descriptor.operations['IndexedGetter']
get = ""
get = "let cx = SafeJSContext::from_ptr(cx);\n"
if indexedGetter:
get = "let index = get_array_index_from_id(cx, Handle::from_raw(id));\n"
get += "let index = get_array_index_from_id(*cx, Handle::from_raw(id));\n"
attrs = "JSPROP_ENUMERATE"
if self.descriptor.operations['IndexedSetter'] is None:
@ -5029,7 +5033,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
templateValues = {
'jsvalRef': 'result_root.handle_mut()',
'successCode': fillDescriptor,
'pre': 'rooted!(in(cx) let mut result_root = UndefinedValue());'
'pre': 'rooted!(in(*cx) let mut result_root = UndefinedValue());'
}
get += ("if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
@ -5055,7 +5059,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
templateValues = {
'jsvalRef': 'result_root.handle_mut()',
'successCode': fillDescriptor,
'pre': 'rooted!(in(cx) let mut result_root = UndefinedValue());'
'pre': 'rooted!(in(*cx) let mut result_root = UndefinedValue());'
}
# See the similar-looking in CGDOMJSProxyHandler_get for the spec quote.
@ -5068,7 +5072,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
namedGet = """
if %s {
let mut has_on_proto = false;
if !has_property_on_prototype(cx, proxy_lt, id_lt, &mut has_on_proto) {
if !has_property_on_prototype(*cx, proxy_lt, id_lt, &mut has_on_proto) {
return false;
}
if !has_on_proto {
@ -5080,13 +5084,13 @@ if %s {
namedGet = ""
return get + """\
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
rooted!(in(*cx) let mut expando = ptr::null_mut::<JSObject>());
get_expando_object(proxy, expando.handle_mut());
//if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
let proxy_lt = Handle::from_raw(proxy);
let id_lt = Handle::from_raw(id);
if !expando.is_null() {
if !JS_GetPropertyDescriptorById(cx, expando.handle().into(), id, desc) {
if !JS_GetPropertyDescriptorById(*cx, expando.handle().into(), id, desc) {
return false;
}
if !desc.obj.is_null() {
@ -5113,11 +5117,11 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
self.descriptor = descriptor
def getBody(self):
set = ""
set = "let cx = SafeJSContext::from_ptr(cx);\n"
indexedSetter = self.descriptor.operations['IndexedSetter']
if indexedSetter:
set += ("let index = get_array_index_from_id(cx, Handle::from_raw(id));\n" +
set += ("let index = get_array_index_from_id(*cx, Handle::from_raw(id));\n" +
"if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
@ -5125,7 +5129,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" return (*opresult).succeed();\n" +
"}\n")
elif self.descriptor.operations['IndexedGetter']:
set += ("if get_array_index_from_id(cx, Handle::from_raw(id)).is_some() {\n" +
set += ("if get_array_index_from_id(*cx, Handle::from_raw(id)).is_some() {\n" +
" return (*opresult).failNoIndexedSetter();\n" +
"}\n")
@ -5145,7 +5149,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" return (*opresult).failNoNamedSetter();\n"
" }\n"
"}\n")
set += "return proxyhandler::define_property(%s);" % ", ".join(a.name for a in self.args)
set += "return proxyhandler::define_property(*cx, %s);" % ", ".join(a.name for a in self.args[1:])
return set
def definition_body(self):
@ -5161,13 +5165,13 @@ class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
self.descriptor = descriptor
def getBody(self):
set = ""
set = "let cx = SafeJSContext::from_ptr(cx);\n"
if self.descriptor.operations['NamedDeleter']:
if self.descriptor.hasUnforgeableMembers:
raise TypeError("Can't handle a deleter on an interface that has "
"unforgeables. Figure out how that should work!")
set += CGProxyNamedDeleter(self.descriptor).define()
set += "return proxyhandler::delete(%s);" % ", ".join(a.name for a in self.args)
set += "return proxyhandler::delete(*cx, %s);" % ", ".join(a.name for a in self.args[1:])
return set
def definition_body(self):
@ -5185,6 +5189,7 @@ class CGDOMJSProxyHandler_ownPropertyKeys(CGAbstractExternMethod):
def getBody(self):
body = dedent(
"""
let cx = SafeJSContext::from_ptr(cx);
let unwrapped_proxy = UnwrapProxy(proxy);
""")
@ -5192,7 +5197,7 @@ class CGDOMJSProxyHandler_ownPropertyKeys(CGAbstractExternMethod):
body += dedent(
"""
for i in 0..(*unwrapped_proxy).Length() {
rooted!(in(cx) let rooted_jsid = int_to_jsid(i as i32));
rooted!(in(*cx) let rooted_jsid = int_to_jsid(i as i32));
AppendToAutoIdVector(props, rooted_jsid.handle().get());
}
""")
@ -5202,20 +5207,20 @@ class CGDOMJSProxyHandler_ownPropertyKeys(CGAbstractExternMethod):
"""
for name in (*unwrapped_proxy).SupportedPropertyNames() {
let cstring = CString::new(name).unwrap();
let jsstring = JS_AtomizeAndPinString(cx, cstring.as_ptr());
rooted!(in(cx) let rooted = jsstring);
let jsid = INTERNED_STRING_TO_JSID(cx, rooted.handle().get());
rooted!(in(cx) let rooted_jsid = jsid);
let jsstring = JS_AtomizeAndPinString(*cx, cstring.as_ptr());
rooted!(in(*cx) let rooted = jsstring);
let jsid = INTERNED_STRING_TO_JSID(*cx, rooted.handle().get());
rooted!(in(*cx) let rooted_jsid = jsid);
AppendToAutoIdVector(props, rooted_jsid.handle().get());
}
""")
body += dedent(
"""
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
rooted!(in(*cx) let mut expando = ptr::null_mut::<JSObject>());
get_expando_object(proxy, expando.handle_mut());
if !expando.is_null() {
GetPropertyKeys(cx, expando.handle(), JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, props);
GetPropertyKeys(*cx, expando.handle(), JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, props);
}
return true;
@ -5241,6 +5246,7 @@ class CGDOMJSProxyHandler_getOwnEnumerablePropertyKeys(CGAbstractExternMethod):
def getBody(self):
body = dedent(
"""
let cx = SafeJSContext::from_ptr(cx);
let unwrapped_proxy = UnwrapProxy(proxy);
""")
@ -5248,17 +5254,17 @@ class CGDOMJSProxyHandler_getOwnEnumerablePropertyKeys(CGAbstractExternMethod):
body += dedent(
"""
for i in 0..(*unwrapped_proxy).Length() {
rooted!(in(cx) let rooted_jsid = int_to_jsid(i as i32));
rooted!(in(*cx) let rooted_jsid = int_to_jsid(i as i32));
AppendToAutoIdVector(props, rooted_jsid.handle().get());
}
""")
body += dedent(
"""
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
rooted!(in(*cx) let mut expando = ptr::null_mut::<JSObject>());
get_expando_object(proxy, expando.handle_mut());
if !expando.is_null() {
GetPropertyKeys(cx, expando.handle(), JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, props);
GetPropertyKeys(*cx, expando.handle(), JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, props);
}
return true;
@ -5279,17 +5285,16 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
def getBody(self):
indexedGetter = self.descriptor.operations['IndexedGetter']
indexed = "let cx = SafeJSContext::from_ptr(cx);\n"
if indexedGetter:
indexed = ("let index = get_array_index_from_id(cx, Handle::from_raw(id));\n" +
"if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
" *bp = result.is_some();\n" +
" return true;\n" +
"}\n\n")
else:
indexed = ""
indexed += ("let index = get_array_index_from_id(*cx, Handle::from_raw(id));\n" +
"if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
" *bp = result.is_some();\n" +
" return true;\n" +
"}\n\n")
namedGetter = self.descriptor.operations['NamedGetter']
condition = "RUST_JSID_IS_STRING(id) || RUST_JSID_IS_INT(id)"
@ -5299,7 +5304,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
named = """\
if %s {
let mut has_on_proto = false;
if !has_property_on_prototype(cx, proxy_lt, id_lt, &mut has_on_proto) {
if !has_property_on_prototype(*cx, proxy_lt, id_lt, &mut has_on_proto) {
return false;
}
if !has_on_proto {
@ -5314,12 +5319,12 @@ if %s {
named = ""
return indexed + """\
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
rooted!(in(*cx) let mut expando = ptr::null_mut::<JSObject>());
let proxy_lt = Handle::from_raw(proxy);
let id_lt = Handle::from_raw(id);
get_expando_object(proxy, expando.handle_mut());
if !expando.is_null() {
let ok = JS_HasPropertyById(cx, expando.handle().into(), id, bp);
let ok = JS_HasPropertyById(*cx, expando.handle().into(), id, bp);
if !ok || *bp {
return ok;
}
@ -5343,16 +5348,16 @@ class CGDOMJSProxyHandler_get(CGAbstractExternMethod):
# https://heycam.github.io/webidl/#LegacyPlatformObjectGetOwnProperty
def getBody(self):
getFromExpando = """\
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
rooted!(in(*cx) let mut expando = ptr::null_mut::<JSObject>());
get_expando_object(proxy, expando.handle_mut());
if !expando.is_null() {
let mut hasProp = false;
if !JS_HasPropertyById(cx, expando.handle().into(), id, &mut hasProp) {
if !JS_HasPropertyById(*cx, expando.handle().into(), id, &mut hasProp) {
return false;
}
if hasProp {
return JS_ForwardGetPropertyTo(cx, expando.handle().into(), id, receiver, vp);
return JS_ForwardGetPropertyTo(*cx, expando.handle().into(), id, receiver, vp);
}
}"""
@ -5363,7 +5368,7 @@ if !expando.is_null() {
indexedGetter = self.descriptor.operations['IndexedGetter']
if indexedGetter:
getIndexedOrExpando = ("let index = get_array_index_from_id(cx, id_lt);\n" +
getIndexedOrExpando = ("let index = get_array_index_from_id(*cx, id_lt);\n" +
"if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
@ -5396,6 +5401,7 @@ if !expando.is_null() {
return """\
//MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
//"Should not have a XrayWrapper here");
let cx = SafeJSContext::from_ptr(cx);
let proxy_lt = Handle::from_raw(proxy);
let vp_lt = MutableHandle::from_raw(vp);
let id_lt = Handle::from_raw(id);
@ -5403,7 +5409,7 @@ let receiver_lt = Handle::from_raw(receiver);
%s
let mut found = false;
if !get_property_on_prototype(cx, proxy_lt, receiver_lt, id_lt, &mut found, vp_lt) {
if !get_property_on_prototype(*cx, proxy_lt, receiver_lt, id_lt, &mut found, vp_lt) {
return false;
}
@ -5526,7 +5532,9 @@ class CGClassConstructHook(CGAbstractExternMethod):
self.exposureSet = descriptor.interface.exposureSet
def definition_body(self):
preamble = """let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n"""
preamble = """let cx = SafeJSContext::from_ptr(cx);
let global = GlobalScope::from_object(JS_CALLEE(*cx, vp).to_object());
"""
if len(self.exposureSet) == 1:
preamble += """\
let global = DomRoot::downcast::<dom::types::%s>(global).unwrap();
@ -5542,24 +5550,24 @@ let global = DomRoot::downcast::<dom::types::%s>(global).unwrap();
// The new_target might be a cross-compartment wrapper. Get the underlying object
// so we can do the spec's object-identity checks.
rooted!(in(cx) let new_target = UnwrapObjectDynamic(args.new_target().to_object(), cx, 1));
rooted!(in(*cx) let new_target = UnwrapObjectDynamic(args.new_target().to_object(), *cx, 1));
if new_target.is_null() {
throw_dom_exception(cx, global.upcast::<GlobalScope>(), Error::Type("new.target is null".to_owned()));
throw_dom_exception(*cx, global.upcast::<GlobalScope>(), Error::Type("new.target is null".to_owned()));
return false;
}
if args.callee() == new_target.get() {
throw_dom_exception(cx, global.upcast::<GlobalScope>(),
throw_dom_exception(*cx, global.upcast::<GlobalScope>(),
Error::Type("new.target must not be the active function object".to_owned()));
return false;
}
// Step 6
rooted!(in(cx) let mut prototype = ptr::null_mut::<JSObject>());
rooted!(in(*cx) let mut prototype = ptr::null_mut::<JSObject>());
{
rooted!(in(cx) let mut proto_val = UndefinedValue());
let _ac = JSAutoRealm::new(cx, new_target.get());
if !JS_GetProperty(cx, new_target.handle(), b"prototype\\0".as_ptr() as *const _, proto_val.handle_mut()) {
rooted!(in(*cx) let mut proto_val = UndefinedValue());
let _ac = JSAutoRealm::new(*cx, new_target.get());
if !JS_GetProperty(*cx, new_target.handle(), b"prototype\\0".as_ptr() as *const _, proto_val.handle_mut()) {
return false;
}
@ -5573,8 +5581,8 @@ rooted!(in(cx) let mut prototype = ptr::null_mut::<JSObject>());
// whose target is not same-compartment with the proxy, or bound functions, etc).
// https://bugzilla.mozilla.org/show_bug.cgi?id=1317658
rooted!(in(cx) let global_object = CurrentGlobalOrNull(cx));
GetProtoObject(SafeJSContext::from_ptr(cx), global_object.handle(), prototype.handle_mut());
rooted!(in(*cx) let global_object = CurrentGlobalOrNull(*cx));
GetProtoObject(cx, global_object.handle(), prototype.handle_mut());
} else {
// Step 6
prototype.set(proto_val.to_object());
@ -5582,7 +5590,7 @@ rooted!(in(cx) let mut prototype = ptr::null_mut::<JSObject>());
}
// Wrap prototype in this context since it is from the newTarget compartment
if !JS_WrapObject(cx, prototype.handle_mut()) {
if !JS_WrapObject(*cx, prototype.handle_mut()) {
return false;
}
@ -5590,19 +5598,19 @@ let result: Result<DomRoot<%s>, Error> = html_constructor(&global, &args);
let result = match result {
Ok(result) => result,
Err(e) => {
throw_dom_exception(cx, global.upcast::<GlobalScope>(), e);
throw_dom_exception(*cx, global.upcast::<GlobalScope>(), e);
return false;
},
};
rooted!(in(cx) let mut element = result.reflector().get_jsobject().get());
if !JS_WrapObject(cx, element.handle_mut()) {
rooted!(in(*cx) let mut element = result.reflector().get_jsobject().get());
if !JS_WrapObject(*cx, element.handle_mut()) {
return false;
}
JS_SetPrototype(cx, element.handle(), prototype.handle());
JS_SetPrototype(*cx, element.handle(), prototype.handle());
(result).to_jsval(cx, MutableHandleValue::from_raw(args.rval()));
(result).to_jsval(*cx, MutableHandleValue::from_raw(args.rval()));
return true;
""" % self.descriptor.name)
else:
@ -6290,7 +6298,7 @@ class CGDictionary(CGThing):
" match r#try!(%s::%s::new(cx, val)) {\n"
" ConversionResult::Success(v) => v,\n"
" ConversionResult::Failure(error) => {\n"
" throw_type_error(cx, &error);\n"
" throw_type_error(*cx, &error);\n"
" return Err(());\n"
" }\n"
" }\n"
@ -6344,7 +6352,7 @@ class CGDictionary(CGThing):
return string.Template(
"impl ${selfName} {\n"
"${empty}\n"
" pub unsafe fn new(cx: *mut JSContext, val: HandleValue) \n"
" pub unsafe fn new(cx: SafeJSContext, val: HandleValue) \n"
" -> Result<ConversionResult<${actualType}>, ()> {\n"
" let object = if val.get().is_null_or_undefined() {\n"
" ptr::null_mut()\n"
@ -6353,7 +6361,7 @@ class CGDictionary(CGThing):
" } else {\n"
" return Ok(ConversionResult::Failure(\"Value is not an object.\".into()));\n"
" };\n"
" rooted!(in(cx) let object = object);\n"
" rooted!(in(*cx) let object = object);\n"
"${preInitial}"
"${initParent}"
"${initMembers}"
@ -6366,7 +6374,7 @@ class CGDictionary(CGThing):
" type Config = ();\n"
" unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _option: ())\n"
" -> Result<ConversionResult<${actualType}>, ()> {\n"
" ${selfName}::new(cx, value)\n"
" ${selfName}::new(SafeJSContext::from_ptr(cx), value)\n"
" }\n"
"}\n"
"\n"
@ -6424,7 +6432,7 @@ class CGDictionary(CGThing):
assert (member.defaultValue is None) == (default is None)
if not member.optional:
assert default is None
default = ("throw_type_error(cx, \"Missing required member \\\"%s\\\".\");\n"
default = ("throw_type_error(*cx, \"Missing required member \\\"%s\\\".\");\n"
"return Err(());") % member.identifier.name
elif not default:
default = "None"
@ -6432,8 +6440,8 @@ class CGDictionary(CGThing):
conversion = (
"{\n"
" rooted!(in(cx) let mut rval = UndefinedValue());\n"
" if r#try!(get_dictionary_property(cx, object.handle(), \"%s\", rval.handle_mut()))"
" rooted!(in(*cx) let mut rval = UndefinedValue());\n"
" if r#try!(get_dictionary_property(*cx, object.handle(), \"%s\", rval.handle_mut()))"
" && !rval.is_undefined() {\n"
"%s\n"
" } else {\n"
@ -6808,14 +6816,14 @@ class CGCallback(CGClass):
args = list(method.args)
# Strip out the JSContext*/JSObject* args
# that got added.
assert args[0].name == "cx" and args[0].argType == "*mut JSContext"
assert args[0].name == "cx" and args[0].argType == "SafeJSContext"
assert args[1].name == "aThisObj" and args[1].argType == "HandleObject"
args = args[2:]
# Record the names of all the arguments, so we can use them when we call
# the private method.
argnames = [arg.name for arg in args]
argnamesWithThis = ["s.get_context()", "thisObjJS.handle()"] + argnames
argnamesWithoutThis = ["s.get_context()", "thisObjJS.handle()"] + argnames
argnamesWithThis = ["SafeJSContext::from_ptr(s.get_context())", "thisObjJS.handle()"] + argnames
argnamesWithoutThis = ["SafeJSContext::from_ptr(s.get_context())", "thisObjJS.handle()"] + argnames
# Now that we've recorded the argnames for our call to our private
# method, insert our optional argument for deciding whether the
# CallSetup should re-throw exceptions on aRv.
@ -7066,7 +7074,7 @@ class CallbackMember(CGNativeMember):
"*arg = Heap::default();\n" +
"arg.set(argv_root.get());\n" +
"}") % jsvalIndex,
pre="rooted!(in(cx) let mut argv_root = UndefinedValue());")
pre="rooted!(in(*cx) let mut argv_root = UndefinedValue());")
if arg.variadic:
conversion = string.Template(
"for idx in 0..${arg}.len() {\n" +
@ -7095,7 +7103,7 @@ class CallbackMember(CGNativeMember):
return args
# We want to allow the caller to pass in a "this" object, as
# well as a JSContext.
return [Argument("*mut JSContext", "cx"),
return [Argument("SafeJSContext", "cx"),
Argument("HandleObject", "aThisObj")] + args
def getCallSetup(self):
@ -7136,7 +7144,7 @@ class CallbackMethod(CallbackMember):
needThisHandling)
def getRvalDecl(self):
return "rooted!(in(cx) let mut rval = UndefinedValue());\n"
return "rooted!(in(*cx) let mut rval = UndefinedValue());\n"
def getCall(self):
replacements = {
@ -7152,9 +7160,9 @@ class CallbackMethod(CallbackMember):
replacements["argc"] = "0"
return string.Template(
"${getCallable}"
"rooted!(in(cx) let rootedThis = ${thisObj});\n"
"rooted!(in(*cx) let rootedThis = ${thisObj});\n"
"let ok = ${callGuard}JS_CallFunctionValue(\n"
" cx, rootedThis.handle(), callable.handle(),\n"
" *cx, rootedThis.handle(), callable.handle(),\n"
" &HandleValueArray {\n"
" length_: ${argc} as ::libc::size_t,\n"
" elements_: ${argv}\n"
@ -7175,7 +7183,7 @@ class CallCallback(CallbackMethod):
return "aThisObj.get()"
def getCallableDecl(self):
return "rooted!(in(cx) let callable = ObjectValue(self.callback()));\n"
return "rooted!(in(*cx) let callable = ObjectValue(self.callback()));\n"
def getCallGuard(self):
if self.callback._treatNonObjectAsNull:
@ -7205,13 +7213,13 @@ class CallbackOperationBase(CallbackMethod):
"methodName": self.methodName
}
getCallableFromProp = string.Template(
'r#try!(self.parent.get_callable_property(cx, "${methodName}"))'
'r#try!(self.parent.get_callable_property(*cx, "${methodName}"))'
).substitute(replacements)
if not self.singleOperation:
return 'rooted!(in(cx) let callable =\n' + getCallableFromProp + ');\n'
return 'rooted!(in(*cx) let callable =\n' + getCallableFromProp + ');\n'
return (
'let isCallable = IsCallable(self.callback());\n'
'rooted!(in(cx) let callable =\n' +
'rooted!(in(*cx) let callable =\n' +
CGIndenter(
CGIfElseWrapper('isCallable',
CGGeneric('ObjectValue(self.callback())'),
@ -7246,21 +7254,21 @@ class CGIterableMethodGenerator(CGGeneric):
CGGeneric.__init__(self, fill(
"""
if !IsCallable(arg0) {
throw_type_error(cx, "Argument 1 of ${ifaceName}.forEach is not callable.");
throw_type_error(*cx, "Argument 1 of ${ifaceName}.forEach is not callable.");
return false;
}
rooted!(in(cx) let arg0 = ObjectValue(arg0));
rooted!(in(cx) let mut call_arg1 = UndefinedValue());
rooted!(in(cx) let mut call_arg2 = UndefinedValue());
rooted!(in(*cx) let arg0 = ObjectValue(arg0));
rooted!(in(*cx) let mut call_arg1 = UndefinedValue());
rooted!(in(*cx) let mut call_arg2 = UndefinedValue());
let mut call_args = vec![UndefinedValue(), UndefinedValue(), ObjectValue(*_obj)];
rooted!(in(cx) let mut ignoredReturnVal = UndefinedValue());
rooted!(in(*cx) let mut ignoredReturnVal = UndefinedValue());
for i in 0..(*this).get_iterable_length() {
(*this).get_value_at_index(i).to_jsval(cx, call_arg1.handle_mut());
(*this).get_key_at_index(i).to_jsval(cx, call_arg2.handle_mut());
(*this).get_value_at_index(i).to_jsval(*cx, call_arg1.handle_mut());
(*this).get_key_at_index(i).to_jsval(*cx, call_arg2.handle_mut());
call_args[0] = call_arg1.handle().get();
call_args[1] = call_arg2.handle().get();
let call_args = HandleValueArray { length_: 3, elements_: call_args.as_ptr() };
if !Call(cx, arg1, arg0.handle(), &call_args,
if !Call(*cx, arg1, arg0.handle(), &call_args,
ignoredReturnVal.handle_mut()) {
return false;
}

View file

@ -30,6 +30,7 @@ use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::permissions::{get_descriptor_permission_state, PermissionAlgorithm};
use crate::dom::promise::Promise;
use crate::script_runtime::JSContext as SafeJSContext;
use crate::task::TaskOnce;
use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcSender};
@ -625,7 +626,8 @@ impl PermissionAlgorithm for Bluetooth {
.handle_mut()
.set(ObjectValue(permission_descriptor_obj));
unsafe {
match BluetoothPermissionDescriptor::new(cx, property.handle()) {
match BluetoothPermissionDescriptor::new(SafeJSContext::from_ptr(cx), property.handle())
{
Ok(ConversionResult::Success(descriptor)) => Ok(descriptor),
Ok(ConversionResult::Failure(error)) => Err(Error::Type(error.into_owned())),
Err(_) => Err(Error::Type(String::from(BT_DESC_CONVERSION_ERROR))),

View file

@ -28,6 +28,7 @@ use crate::dom::webgl2renderingcontext::WebGL2RenderingContext;
use crate::dom::webglrenderingcontext::{
LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext,
};
use crate::script_runtime::JSContext as SafeJSContext;
use base64;
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromScriptMsg};
use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
@ -263,7 +264,7 @@ impl HTMLCanvasElement {
cx: *mut JSContext,
options: HandleValue,
) -> Option<GLContextAttributes> {
match WebGLContextAttributes::new(cx, options) {
match WebGLContextAttributes::new(SafeJSContext::from_ptr(cx), options) {
Ok(ConversionResult::Success(ref attrs)) => Some(From::from(attrs)),
Ok(ConversionResult::Failure(ref error)) => {
throw_type_error(cx, &error);

View file

@ -17,6 +17,7 @@ use crate::dom::bluetoothpermissionresult::BluetoothPermissionResult;
use crate::dom::globalscope::GlobalScope;
use crate::dom::permissionstatus::PermissionStatus;
use crate::dom::promise::Promise;
use crate::script_runtime::JSContext as SafeJSContext;
use dom_struct::dom_struct;
use js::conversions::ConversionResult;
use js::jsapi::{JSContext, JSObject};
@ -232,7 +233,7 @@ impl PermissionAlgorithm for Permissions {
.handle_mut()
.set(ObjectValue(permission_descriptor_obj));
unsafe {
match PermissionDescriptor::new(cx, property.handle()) {
match PermissionDescriptor::new(SafeJSContext::from_ptr(cx), property.handle()) {
Ok(ConversionResult::Success(descriptor)) => Ok(descriptor),
Ok(ConversionResult::Failure(error)) => Err(Error::Type(error.into_owned())),
Err(_) => Err(Error::JSFailed),