diff options
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index fbe2c46e9de..14a26268efd 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -3413,7 +3413,7 @@ pub const strings: &'static [&'static str] = &[ ]; impl ToJSValConvertible for super::%s { - fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { + unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { strings[*self as usize].to_jsval(cx, rval); } } @@ -3534,7 +3534,7 @@ pub enum %s { } impl ToJSValConvertible for %s { - fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { + unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { match *self { %s } @@ -3644,12 +3644,12 @@ class CGUnionConversionStruct(CGThing): names.append(name) conversions.append(CGGeneric( - "unsafe { throw_not_in_union(cx, \"%s\"); }\n" + "throw_not_in_union(cx, \"%s\");\n" "Err(())" % ", ".join(names))) method = CGWrapper( CGIndenter(CGList(conversions, "\n\n")), - pre="fn from_jsval(cx: *mut JSContext,\n" - " value: HandleValue, _option: ()) -> Result<%s, ()> {\n" % self.type, + pre="unsafe fn from_jsval(cx: *mut JSContext,\n" + " value: HandleValue, _option: ()) -> Result<%s, ()> {\n" % self.type, post="\n}") return CGWrapper( CGIndenter(CGList([ @@ -3666,7 +3666,7 @@ class CGUnionConversionStruct(CGThing): return CGWrapper( CGIndenter(jsConversion, 4), - pre="fn TryConvertTo%s(cx: *mut JSContext, value: HandleValue) -> %s {\n" % (t.name, returnType), + pre="unsafe fn TryConvertTo%s(cx: *mut JSContext, value: HandleValue) -> %s {\n" % (t.name, returnType), post="\n}") def define(self): @@ -4967,8 +4967,8 @@ class CGDictionary(CGThing): "}\n" "\n" "impl ToJSValConvertible for ${selfName} {\n" - " fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {\n" - " let obj = unsafe { RootedObject::new(cx, JS_NewObject(cx, ptr::null())) };\n" + " unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {\n" + " let obj = RootedObject::new(cx, JS_NewObject(cx, ptr::null()));\n" "${insertMembers}" " rval.set(ObjectOrNullValue(obj.ptr))\n" " }\n" @@ -5459,7 +5459,7 @@ impl CallbackContainer for ${type} { } impl ToJSValConvertible for ${type} { - fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { + unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { self.callback().to_jsval(cx, rval); } }\ @@ -5563,10 +5563,10 @@ class CallbackMember(CGNativeMember): "${convertArgs}" "${doCall}" "${returnResult}").substitute(replacements) - return CGList([ + return CGWrapper(CGIndenter(CGList([ CGGeneric(pre), CGGeneric(body), - ], "\n").define() + ], "\n"), 4), pre="unsafe {\n", post="\n}").define() def getResultConversion(self): replacements = { @@ -5709,15 +5709,13 @@ class CallbackMethod(CallbackMember): replacements["argc"] = "0" return string.Template( "${getCallable}" - "let ok = unsafe {\n" - " let rootedThis = RootedObject::new(cx, ${thisObj});\n" - " JS_CallFunctionValue(\n" - " cx, rootedThis.handle(), callable.handle(),\n" - " &HandleValueArray {\n" - " length_: ${argc} as ::libc::size_t,\n" - " elements_: ${argv}\n" - " }, rval.handle_mut())\n" - "};\n" + "let rootedThis = RootedObject::new(cx, ${thisObj});\n" + "let ok = JS_CallFunctionValue(\n" + " cx, rootedThis.handle(), callable.handle(),\n" + " &HandleValueArray {\n" + " length_: ${argc} as ::libc::size_t,\n" + " elements_: ${argv}\n" + " }, rval.handle_mut());\n" "if !ok {\n" " return Err(JSFailed);\n" "}\n").substitute(replacements) @@ -5732,7 +5730,7 @@ class CallCallback(CallbackMethod): return "aThisObj.get()" def getCallableDecl(self): - return "let callable = RootedValue::new(cx, ObjectValue(unsafe {&*self.parent.callback()}));\n" + return "let callable = RootedValue::new(cx, ObjectValue(&*self.parent.callback()));\n" class CallbackOperationBase(CallbackMethod): @@ -5762,11 +5760,11 @@ class CallbackOperationBase(CallbackMethod): if not self.singleOperation: return 'JS::Rooted<JS::Value> callable(cx);\n' + getCallableFromProp return ( - 'let isCallable = unsafe { IsCallable(self.parent.callback()) };\n' + 'let isCallable = IsCallable(self.parent.callback());\n' 'let callable =\n' + CGIndenter( CGIfElseWrapper('isCallable', - CGGeneric('unsafe { RootedValue::new(cx, ObjectValue(&*self.parent.callback())) }'), + CGGeneric('RootedValue::new(cx, ObjectValue(&*self.parent.callback()))'), CGGeneric(getCallableFromProp))).define() + ';\n') |