diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 9698d16084..4591d5720c 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -11043,6 +11043,7 @@ class CGDescriptor(CGThing): hasPromiseReturningMethod) = False, False, False, False, False, False jsonifierMethod = None crossOriginMethods, crossOriginGetters, crossOriginSetters = set(), set(), set() + unscopableNames = list() for n in descriptor.interface.namedConstructors: cgThings.append(CGClassConstructor(descriptor, n, NamedConstructorName(n))) @@ -11055,6 +11056,9 @@ class CGDescriptor(CGThing): props = memberProperties(m, descriptor) if m.isMethod(): + if m.getExtendedAttribute("Unscopable"): + assert not m.isStatic() + unscopableNames.append(m.identifier.name) if props.isJsonifier: jsonifierMethod = m elif not m.isIdentifierLess() or m == descriptor.operations['Stringifier']: @@ -11076,6 +11080,9 @@ class CGDescriptor(CGThing): raise TypeError("Stringifier attributes not supported yet. " "See bug 824857.\n" "%s" % m.location) + if m.getExtendedAttribute("Unscopable"): + assert not m.isStatic() + unscopableNames.append(m.identifier.name) if m.isStatic(): assert descriptor.interface.hasInterfaceObject() cgThings.append(CGStaticGetter(descriptor, m)) @@ -11260,8 +11267,18 @@ class CGDescriptor(CGThing): cgThings.extend(CGClearCachedValueMethod(descriptor, m) for m in clearableCachedAttrs(descriptor)) + haveUnscopables = (len(unscopableNames) != 0 and + descriptor.interface.hasInterfacePrototypeObject()) + if haveUnscopables: + cgThings.append( + CGList([CGGeneric("static const char* const unscopableNames[] = {"), + CGIndenter(CGList([CGGeneric('"%s"' % name) for + name in unscopableNames] + + [CGGeneric("nullptr")], ",\n")), + CGGeneric("};\n")], "\n")) + # CGCreateInterfaceObjectsMethod needs to come after our - # CGDOMJSClass, if any. + # CGDOMJSClass and unscopables, if any. cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties)) # CGGetProtoObjectMethod and CGGetConstructorObjectMethod need diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 6a4674a42a..7dba781a94 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -3455,6 +3455,14 @@ class IDLAttribute(IDLInterfaceMember): "readonly attributes" % attr.value(), [attr.location, self.location]) self._setDependsOn(attr.value()) + elif identifier == "Unscopable": + if not attr.noArguments(): + raise WebIDLError("[Unscopable] must take no arguments", + [attr.location]) + if self.isStatic(): + raise WebIDLError("[Unscopable] is only allowed on non-static " + "attributes and operations", + [attr.location, self.location]) elif (identifier == "Pref" or identifier == "SetterThrows" or identifier == "Throws" or @@ -4078,6 +4086,14 @@ class IDLMethod(IDLInterfaceMember, IDLScope): raise WebIDLError("[DependsOn] takes an identifier", [attr.location]) self._setDependsOn(attr.value()) + elif identifier == "Unscopable": + if not attr.noArguments(): + raise WebIDLError("[Unscopable] must take no arguments", + [attr.location]) + if self.isStatic(): + raise WebIDLError("[Unscopable] is only allowed on non-static " + "attributes and operations", + [attr.location, self.location]) elif (identifier == "Throws" or identifier == "NewObject" or identifier == "ChromeOnly" or