aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py59
1 files changed, 42 insertions, 17 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index c1d4ac46aaa..61efa579241 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -100,12 +100,11 @@ class CastableObjectUnwrapper():
"source" : source,
"target" : target,
"codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define(),
- "unwrapped_val" : "Some(val)" if isOptional else "val",
- "unwrapFn": "unwrap_jsmanaged" if 'JS' in descriptor.nativeType else "unwrap_object"}
+ "unwrapped_val" : "Some(val)" if isOptional else "val"}
def __str__(self):
return string.Template(
-"""match ${unwrapFn}(${source}, ${prototype}, ${depth}) {
+"""match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) {
Ok(val) => ${target} = ${unwrapped_val},
Err(()) => {
${codeOnFailure}
@@ -1920,6 +1919,32 @@ class CGWrapMethod(CGAbstractMethod):
raw.mut_reflector().set_jsobject(obj);
return raw;""" % CreateBindingJSObject(self.descriptor)
+
+class CGIDLInterface(CGThing):
+ """
+ Class for codegen of an implementation of the IDLInterface trait.
+ """
+ def __init__(self, descriptor):
+ CGThing.__init__(self)
+ self.descriptor = descriptor
+
+ def define(self):
+ replacer = {
+ 'type': self.descriptor.name,
+ 'depth': self.descriptor.interface.inheritanceDepth(),
+ }
+ return string.Template("""
+impl IDLInterface for ${type} {
+ fn get_prototype_id(_: Option<${type}>) -> PrototypeList::id::ID {
+ PrototypeList::id::${type}
+ }
+ fn get_prototype_depth(_: Option<${type}>) -> uint {
+ ${depth}
+ }
+}
+""").substitute(replacer)
+
+
class CGAbstractExternMethod(CGAbstractMethod):
"""
Abstract base class for codegen of implementation-only (no
@@ -2123,7 +2148,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
"""
def __init__(self, descriptor):
args = [Argument('&mut JSPageInfo', 'js_info')]
- CGAbstractMethod.__init__(self, descriptor, 'DefineDOMInterface', 'bool', args, pub=True)
+ CGAbstractMethod.__init__(self, descriptor, 'DefineDOMInterface', 'void', args, pub=True)
def define(self):
return CGAbstractMethod.define(self)
@@ -2180,7 +2205,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
return (body + """ let cx = js_info.js_context.deref().ptr;
let receiver = js_info.js_compartment.global_obj;
let global: *JSObject = JS_GetGlobalForObject(cx, receiver);
- return %s(cx, global, receiver).is_not_null();""" % (getter))
+ assert!(%s(cx, global, receiver).is_not_null());""" % (getter))
def needCx(returnType, arguments, extendedAttributes, considerTypes):
return (considerTypes and
@@ -2470,7 +2495,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
" return false as JSBool;\n"
"}\n"
"\n"
- "let this: *mut %s;" % self.descriptor.concreteType))
+ "let this: JS<%s>;" % self.descriptor.concreteType))
def generate_code(self):
assert(False) # Override me
@@ -2487,7 +2512,7 @@ class CGGenericMethod(CGAbstractBindingMethod):
def generate_code(self):
return CGIndenter(CGGeneric(
"let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n"
- "return CallJitMethodOp(_info, cx, obj, this as *libc::c_void, argc, &*vp);"))
+ "return CallJitMethodOp(_info, cx, obj, this.unsafe_get() as *libc::c_void, argc, &*vp);"))
class CGSpecializedMethod(CGAbstractExternMethod):
"""
@@ -2497,7 +2522,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
def __init__(self, descriptor, method):
self.method = method
name = method.identifier.name
- args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'),
+ args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', '_obj'),
Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')]
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
@@ -2514,7 +2539,6 @@ class CGSpecializedMethod(CGAbstractExternMethod):
return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(),
self.descriptor, self.method),
pre=extraPre +
- " let obj = *obj.unnamed;\n" +
" let this = &mut *this;\n").define()
class CGGenericGetter(CGAbstractBindingMethod):
@@ -2540,7 +2564,7 @@ class CGGenericGetter(CGAbstractBindingMethod):
return CGIndenter(CGGeneric(
"return with_gc_disabled(cx, || {\n"
" let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n"
- " CallJitPropertyOp(info, cx, obj, this as *libc::c_void, &*vp)\n"
+ " CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, &*vp)\n"
"});\n"))
class CGSpecializedGetter(CGAbstractExternMethod):
@@ -2552,7 +2576,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
self.attr = attr
name = 'get_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'),
- Argument('JSHandleObject', 'obj'),
+ Argument('JSHandleObject', '_obj'),
Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'vp') ]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@@ -2574,7 +2598,6 @@ class CGSpecializedGetter(CGAbstractExternMethod):
return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName,
self.descriptor, self.attr)),
pre=extraPre +
- " let obj = *obj.unnamed;\n" +
" let this = &mut *this;\n").define()
class CGGenericSetter(CGAbstractBindingMethod):
@@ -2601,7 +2624,7 @@ class CGGenericSetter(CGAbstractBindingMethod):
"let argv: *JSVal = if argc != 0 { JS_ARGV(cx, vp as *JSVal) } else { &undef as *JSVal };\n"
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp as *JSVal));\n"
"let ok = with_gc_disabled(cx, || {\n"
- " CallJitPropertyOp(info, cx, obj, this as *libc::c_void, argv)\n"
+ " CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, argv)\n"
"});\n"
"if ok == 0 {\n"
" return 0;\n"
@@ -2618,7 +2641,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
self.attr = attr
name = 'set_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'),
- Argument('JSHandleObject', 'obj'),
+ Argument('JSHandleObject', '_obj'),
Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'argv')]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@@ -2635,7 +2658,6 @@ class CGSpecializedSetter(CGAbstractExternMethod):
return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName,
self.descriptor, self.attr)),
pre=extraPre +
- " let obj = *obj.unnamed;\n" +
" let this = &mut *this;\n").define()
@@ -4080,6 +4102,8 @@ class CGDescriptor(CGThing):
cgThings.append(CGWrapMethod(descriptor))
+ cgThings.append(CGIDLInterface(descriptor))
+
cgThings = CGList(cgThings, "\n")
cgThings = CGWrapper(cgThings, pre='\n', post='\n')
#self.cgRoot = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name),
@@ -4378,7 +4402,7 @@ class CGRegisterProtos(CGAbstractMethod):
self.config = config
def _registerProtos(self):
- lines = [" assert!(codegen::%sBinding::DefineDOMInterface(js_info));" % (desc.name)
+ lines = [" codegen::%sBinding::DefineDOMInterface(js_info);" % desc.name
for desc in self.config.getDescriptors(hasInterfaceObject=True,
register=True)]
return '\n'.join(lines) + '\n'
@@ -4489,13 +4513,14 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
- 'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}',
+ 'dom::bindings::utils::{VoidVal, with_gc_disabled}',
'dom::bindings::utils::{with_gc_enabled}',
'dom::bindings::trace::Traceable',
'dom::bindings::callback::{CallbackContainer,CallbackInterface}',
'dom::bindings::callback::{CallSetup,ExceptionHandling}',
'dom::bindings::callback::{WrapCallThisObject}',
'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}',
+ 'dom::bindings::conversions::IDLInterface',
'dom::bindings::conversions::{Default, Empty}',
'dom::bindings::codegen::*',
'dom::bindings::codegen::UnionTypes::*',