Skip to content

Commit

Permalink
Sync WebIDL.py with gecko
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Jul 12, 2019
1 parent 5fdc7c0 commit 56f31c8
Show file tree
Hide file tree
Showing 35 changed files with 727 additions and 221 deletions.
337 changes: 231 additions & 106 deletions components/script/dom/bindings/codegen/parser/WebIDL.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions components/script/dom/bindings/codegen/parser/abstract.patch
@@ -1,12 +1,12 @@
--- WebIDL.py
+++ WebIDL.py
@@ -1786,7 +1786,8 @@ class IDLInterface(IDLInterfaceOrNamespace):
identifier == "ProbablyShortLivingWrapper" or
@@ -1768,7 +1768,8 @@ class IDLInterface(IDLInterfaceOrNamespace):
identifier == "LegacyUnenumerableNamedProperties" or
identifier == "RunConstructorInCallerCompartment" or
- identifier == "WantsEventListenerHooks"):
+ identifier == "WantsEventListenerHooks" or
identifier == "WantsEventListenerHooks" or
- identifier == "Serializable"):
+ identifier == "Serializable" or
+ identifier == "Abstract"):
# Known extended attributes that do not take values
if not attr.noArguments():
raise WebIDLError("[%s] must take no arguments" % identifier,
raise WebIDLError("[%s] must take no arguments" % identifier,
@@ -1,15 +1,15 @@
--- WebIDL.py
+++ WebIDL.py
@@ -2275,7 +2275,7 @@ class IDLUnresolvedType(IDLType):
return typedefType.complete(scope)
@@ -2283,7 +2283,7 @@ class IDLUnresolvedType(IDLType):
return typedefType.complete(scope).withExtendedAttributes(self.extraTypeAttributes)
elif obj.isCallback() and not obj.isInterface():
assert self.name.name == obj.identifier.name
- return IDLCallbackType(self.location, obj)
+ return IDLCallbackType(obj.location, obj)

name = self.name.resolve(scope, None)
return IDLWrapperType(self.location, obj)
@@ -6688,7 +6688,7 @@ class Parser(Tokenizer):
@@ -6854,7 +6854,7 @@ class Parser(Tokenizer):
type = IDLTypedefType(self.getLocation(p, 1), obj.innerType,
obj.identifier.name)
elif obj.isCallback() and not obj.isInterface():
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bindings/codegen/parser/debug.patch
@@ -1,6 +1,6 @@
--- WebIDL.py
+++ WebIDL.py
@@ -6959,7 +6959,8 @@ class Parser(Tokenizer):
@@ -7123,7 +7123,8 @@ class Parser(Tokenizer):
self.parser = yacc.yacc(module=self,
outputdir=outputdir,
tabmodule='webidlyacc',
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/bindings/codegen/parser/inline.patch
@@ -1,9 +1,9 @@
--- WebIDL.py
+++ WebIDL.py
@@ -1787,7 +1787,8 @@ class IDLInterface(IDLInterfaceOrNamespace):
identifier == "LegacyUnenumerableNamedProperties" or
@@ -1769,7 +1769,8 @@ class IDLInterface(IDLInterfaceOrNamespace):
identifier == "RunConstructorInCallerCompartment" or
identifier == "WantsEventListenerHooks" or
identifier == "Serializable" or
- identifier == "Abstract"):
+ identifier == "Abstract" or
+ identifier == "Inline"):
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion components/script/dom/bindings/codegen/parser/runtests.py
Expand Up @@ -62,7 +62,7 @@ def run_tests(tests, verbose):
harness.start()
try:
_test.WebIDLTest.__call__(WebIDL.Parser(), harness)
except Exception, ex:
except Exception as ex:
print("TEST-UNEXPECTED-FAIL | Unhandled exception in test %s: %s" % (testpath, ex))
traceback.print_exc()
finally:
Expand Down
Expand Up @@ -133,7 +133,7 @@ def checkAttr(attr, QName, name, type, readonly):
};
""")
results = parser.finish()
except Exception, x:
except Exception as x:
threw = True
harness.ok(threw, "Should not allow [SetterThrows] on readonly attributes")

Expand All @@ -146,7 +146,7 @@ def checkAttr(attr, QName, name, type, readonly):
};
""")
results = parser.finish()
except Exception, x:
except Exception as x:
threw = True
harness.ok(threw, "Should spell [Throws] correctly")

Expand All @@ -159,7 +159,7 @@ def checkAttr(attr, QName, name, type, readonly):
};
""")
results = parser.finish()
except Exception, x:
except Exception as x:
threw = True
harness.ok(threw, "Should not allow [SameObject] on attributes not of interface type")

Expand All @@ -172,6 +172,6 @@ def checkAttr(attr, QName, name, type, readonly):
};
""")
results = parser.finish()
except Exception, x:
except Exception as x:
threw = True
harness.ok(not threw, "Should allow [SameObject] on attributes of interface type")
Expand Up @@ -32,3 +32,6 @@ def WebIDLTest(parser, harness):
harness.ok(not isinstance(t, WebIDL.IDLWrapperType), "Attr has the right type")
harness.ok(isinstance(t, WebIDL.IDLNullableType), "Attr has the right type")
harness.ok(t.isCallback(), "Attr has the right type")

callback = results[1]
harness.ok(not callback.isConstructor(), "callback is not constructor")
@@ -0,0 +1,63 @@
import WebIDL

def WebIDLTest(parser, harness):
parser.parse("""
interface TestCallbackConstructor {
attribute CallbackConstructorType? constructorAttribute;
};
callback constructor CallbackConstructorType = TestCallbackConstructor (unsigned long arg);
""")

results = parser.finish()

harness.ok(True, "TestCallbackConstructor interface parsed without error.")
harness.check(len(results), 2, "Should be two productions.")
iface = results[0]
harness.ok(isinstance(iface, WebIDL.IDLInterface),
"Should be an IDLInterface")
harness.check(iface.identifier.QName(), "::TestCallbackConstructor", "Interface has the right QName")
harness.check(iface.identifier.name, "TestCallbackConstructor", "Interface has the right name")
harness.check(len(iface.members), 1, "Expect %s members" % 1)

attr = iface.members[0]
harness.ok(isinstance(attr, WebIDL.IDLAttribute),
"Should be an IDLAttribute")
harness.ok(attr.isAttr(), "Should be an attribute")
harness.ok(not attr.isMethod(), "Attr is not an method")
harness.ok(not attr.isConst(), "Attr is not a const")
harness.check(attr.identifier.QName(), "::TestCallbackConstructor::constructorAttribute", "Attr has the right QName")
harness.check(attr.identifier.name, "constructorAttribute", "Attr has the right name")
t = attr.type
harness.ok(not isinstance(t, WebIDL.IDLWrapperType), "Attr has the right type")
harness.ok(isinstance(t, WebIDL.IDLNullableType), "Attr has the right type")
harness.ok(t.isCallback(), "Attr has the right type")

callback = results[1]
harness.ok(callback.isConstructor(), "Callback is constructor")

parser.reset()
threw = False
try:
parser.parse("""
[TreatNonObjectAsNull]
callback constructor CallbackConstructorType = object ();
""")
results = parser.finish()
except:
threw = True

harness.ok(threw, "Should throw on TreatNonObjectAsNull callback constructors")

parser.reset()
threw = False
try:
parser.parse("""
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback constructor CallbackConstructorType = object ();
""")
results = parser.finish()
except:
threw = True

harness.ok(threw, "Should not permit MOZ_CAN_RUN_SCRIPT_BOUNDARY callback constructors")
Expand Up @@ -38,7 +38,7 @@ def WebIDLTest(parser, harness):
""")

results = parser.finish()
except Exception, e:
except Exception as e:
harness.ok(False, "Shouldn't have thrown for [CEReactions] used on writable attribute. %s" % e)
threw = True

Expand All @@ -52,7 +52,7 @@ def WebIDLTest(parser, harness):
""")

results = parser.finish()
except Exception, e:
except Exception as e:
harness.ok(False, "Shouldn't have thrown for [CEReactions] used on regular operations. %s" % e)
threw = True

Expand Down
Expand Up @@ -44,7 +44,7 @@ def WebIDLTest(parser, harness):
};
""")
results = parser.finish()
except Exception, exception:
except Exception as exception:
pass

harness.ok(exception, "Should have thrown.")
Expand All @@ -70,7 +70,7 @@ def WebIDLTest(parser, harness):
};
""")
results = parser.finish()
except Exception, exception:
except Exception as exception:
pass

harness.ok(exception, "Should have thrown (2).")
Expand Down Expand Up @@ -100,7 +100,7 @@ def WebIDLTest(parser, harness):
};
""")
results = parser.finish()
except Exception, exception:
except Exception as exception:
pass

harness.ok(exception, "Should have thrown (3).")
Expand Down
19 changes: 13 additions & 6 deletions components/script/dom/bindings/codegen/parser/tests/test_const.py
Expand Up @@ -12,9 +12,6 @@
("::TestConsts::ll", "ll", "LongLong", -8),
("::TestConsts::t", "t", "Boolean", True),
("::TestConsts::f", "f", "Boolean", False),
("::TestConsts::n", "n", "BooleanOrNull", None),
("::TestConsts::nt", "nt", "BooleanOrNull", True),
("::TestConsts::nf", "nf", "BooleanOrNull", False),
("::TestConsts::fl", "fl", "Float", 0.2),
("::TestConsts::db", "db", "Double", 0.2),
("::TestConsts::ufl", "ufl", "UnrestrictedFloat", 0.2),
Expand All @@ -39,9 +36,6 @@ def WebIDLTest(parser, harness):
const long long ll = -010;
const boolean t = true;
const boolean f = false;
const boolean? n = null;
const boolean? nt = true;
const boolean? nf = false;
const float fl = 0.2;
const double db = 0.2;
const unrestricted float ufl = 0.2;
Expand Down Expand Up @@ -78,3 +72,16 @@ def WebIDLTest(parser, harness):
"Const's value has the same type as the type")
harness.check(const.value.value, value, "Const value has the right value.")


parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestConsts {
const boolean? zero = 0;
};
""")
parser.finish()
except:
threw = True
harness.ok(threw, "Nullable types are not allowed for consts.")
@@ -0,0 +1,87 @@
def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
[Constructor, Global]
interface TestConstructorGlobal {
};
""")

results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")

parser = parser.reset()
threw = False
try:
parser.parse("""
[Global, Constructor]
interface TestConstructorGlobal {
};
""")

results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")

parser = parser.reset()
threw = False
try:
parser.parse("""
[Global, NamedConstructor=FooBar]
interface TestNamedConstructorGlobal {
};
""")
results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")

parser = parser.reset()
threw = False
try:
parser.parse("""
[NamedConstructor=FooBar, Global]
interface TestNamedConstructorGlobal {
};
""")
results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")

parser = parser.reset()
threw = False
try:
parser.parse("""
[Global, HTMLConstructor]
interface TestHTMLConstructorGlobal {
};
""")

results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")

parser = parser.reset()
threw = False
try:
parser.parse("""
[HTMLConstructor, Global]
interface TestHTMLConstructorGlobal {
};
""")

results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")
Expand Up @@ -13,6 +13,7 @@ def WebIDLTest(parser, harness):

harness.ok(threw, "Should have thrown.")

parser = parser.reset()
threw = False
try:
parser.parse("""
Expand Down

0 comments on commit 56f31c8

Please sign in to comment.