From 036228ec9f2431893beefdb46630153485c9a825 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 30 Jul 2013 22:28:30 -0700 Subject: [PATCH] Bug 892609. Implement support for [ArrayClass]. r=khuey --- dom/bindings/Codegen.py | 5 +++- dom/bindings/parser/WebIDL.py | 26 +++++++++++++----- dom/bindings/parser/tests/test_interface.py | 29 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 3636f56f2e79..65be3ac80451 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -1670,8 +1670,11 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): def definition_body(self): protoChain = self.descriptor.prototypeChain if len(protoChain) == 1: - getParentProto = "aCx, JS_GetObjectPrototype(aCx, aGlobal)" parentProtoType = "Rooted" + if self.descriptor.interface.getExtendedAttribute("ArrayClass"): + getParentProto = "aCx, JS_GetArrayPrototype(aCx, aGlobal)" + else: + getParentProto = "aCx, JS_GetObjectPrototype(aCx, aGlobal)" else: parentProtoName = self.descriptor.prototypeChain[-2] getParentProto = ("%s::GetProtoObject(aCx, aGlobal)" % diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index dadbd5d8b5de..3909d3c6470b 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -913,16 +913,30 @@ class IDLInterface(IDLObjectWithScope): elif not newMethod in self.namedConstructors: raise WebIDLError("NamedConstructor conflicts with a NamedConstructor of a different interface", [method.location, newMethod.location]) + elif (identifier == "ArrayClass"): + if not attr.noArguments(): + raise WebIDLError("[ArrayClass] must take no arguments", + [attr.location]) + if self.parent: + raise WebIDLError("[ArrayClass] must not be specified on " + "an interface with inherited interfaces", + [attr.location, self.location]) elif (identifier == "PrefControlled" or - identifier == "Pref" or identifier == "NeedNewResolve" or - identifier == "JSImplementation" or - identifier == "HeaderFile" or - identifier == "NavigatorProperty" or identifier == "OverrideBuiltins" or identifier == "ChromeOnly"): - # Known attributes that we don't need to do anything with here - pass + # Known extended attributes that do not take values + if not attr.noArguments(): + raise WebIDLError("[%s] must take no arguments" % identifier, + [attr.location]) + elif (identifier == "Pref" or + identifier == "JSImplementation" or + identifier == "HeaderFile" or + identifier == "NavigatorProperty"): + # Known extended attributes that take a string value + if not attr.hasValue(): + raise WebIDLError("[%s] must have a value" % identifier, + [attr.location]) else: raise WebIDLError("Unknown extended attribute %s on interface" % identifier, [attr.location]) diff --git a/dom/bindings/parser/tests/test_interface.py b/dom/bindings/parser/tests/test_interface.py index 94d575715341..5b76bc6ac18e 100644 --- a/dom/bindings/parser/tests/test_interface.py +++ b/dom/bindings/parser/tests/test_interface.py @@ -374,3 +374,32 @@ def WebIDLTest(parser, harness): threw = True harness.ok(threw, "Should not allow unknown extended attributes on interfaces") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface B {}; + [ArrayClass] + interface A : B { + }; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow [ArrayClass] on interfaces with parents") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [ArrayClass] + interface A { + }; + """) + results = parser.finish() + except: + threw = True + harness.ok(not threw, + "Should allow [ArrayClass] on interfaces without parents")