diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-06-25 02:18:06 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-06-25 02:18:06 -0600 |
commit | 57cc84b2935c429c92774649275625a7fd63973c (patch) | |
tree | 90af5b35684d234c9207913d9102d003d0516b95 /components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 605b83da54dc7c33def4fb1e3162e377e1715d0b (diff) | |
parent | d33579183a19796b702576a9eb99805f20a608b1 (diff) | |
download | servo-57cc84b2935c429c92774649275625a7fd63973c.tar.gz servo-57cc84b2935c429c92774649275625a7fd63973c.zip |
Auto merge of #6110 - klusark:NamedConstructor, r=Ms2ger
Implement Named constructors and the Image constructor for HTMLImageElement
I'm not sure if I like how I mostly just duplicated the code in CodegenRust.py, so that might need to be refactored.
Instead of just calling it Image, we might want to call it ConstructorImage, to make it clear that it's a constructor. Anyone have an opinion on that?
There seems to be a bug in the HTMLImageElement getter/setter as the value is 0 regardless of what I do. This seems to be unrelated to my commits, so I'll investigate that separately.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6110)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 832dd564736..2847401e65c 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2286,11 +2286,25 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): call = """\ do_create_interface_objects(cx, receiver, parent_proto.handle(), %s, %s, + &named_constructors, %s, &sNativeProperties, rval);""" % (protoClass, constructor, domClass) + createArray = """\ +let named_constructors: [(NonNullJSNative, &'static str, u32); %d] = [ +""" % len(self.descriptor.interface.namedConstructors) + for ctor in self.descriptor.interface.namedConstructors: + constructHook = CONSTRUCT_HOOK_NAME + "_" + ctor.identifier.name; + constructArgs = methodLength(ctor) + constructor = '(%s as NonNullJSNative, "%s", %d)' % ( + constructHook, ctor.identifier.name, constructArgs) + createArray += constructor + createArray += "," + createArray += "];" + return CGList([ CGGeneric(getParentProto), + CGGeneric(createArray), CGGeneric(call % self.properties.variableNames()) ], "\n") @@ -4422,6 +4436,30 @@ let args = CallArgs::from_vp(vp, argc); self.descriptor, self._ctor) return CGList([preamble, callGenerator]) +class CGClassNameConstructHook(CGAbstractExternMethod): + """ + JS-visible named constructor for our objects + """ + def __init__(self, descriptor, ctor): + args = [Argument('*mut JSContext', 'cx'), Argument('u32', 'argc'), Argument('*mut JSVal', 'vp')] + self._ctor = ctor + CGAbstractExternMethod.__init__(self, descriptor, + CONSTRUCT_HOOK_NAME + "_" + + self._ctor.identifier.name, + 'u8', args) + + def definition_body(self): + preamble = CGGeneric("""\ +let global = global_object_for_js_object(JS_CALLEE(cx, vp).to_object()); +let args = CallArgs::from_vp(vp, argc); +""") + name = self._ctor.identifier.name + nativeName = MakeNativeName(self.descriptor.binaryNameFor(name)) + callGenerator = CGMethodCall(["global.r()"], nativeName, True, + self.descriptor, self._ctor) + return CGList([preamble, callGenerator]) + + class CGClassFinalizeHook(CGAbstractClassHook): """ A hook for finalize, used to release our native object. @@ -4568,6 +4606,8 @@ class CGDescriptor(CGThing): if descriptor.interface.hasInterfaceObject(): cgThings.append(CGClassConstructHook(descriptor)) + for ctor in descriptor.interface.namedConstructors: + cgThings.append(CGClassNameConstructHook(descriptor, ctor)) cgThings.append(CGInterfaceObjectJSClass(descriptor)) if not descriptor.interface.isCallback(): |