Bug 1104955: Implement IDL [Unscopable] (partially)

This commit is contained in:
janekptacijarabaci
2017-10-13 23:03:56 +02:00
committed by Roy Tam
parent 6b7653b9c6
commit a3d13fd290
2 changed files with 34 additions and 1 deletions
+18 -1
View File
@@ -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
+16
View File
@@ -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