Migrate to new constructor operation syntax

This commit is contained in:
Kagami Sascha Rosylight 2019-10-02 21:45:01 +09:00
parent 9706cd497d
commit 9ce82ea1ae
103 changed files with 659 additions and 413 deletions

View file

@ -0,0 +1,17 @@
def WebIDLTest(parser, harness):
parser.parse("""
interface Foo {
void foo(object constructor);
};
""")
results = parser.finish()
harness.check(len(results), 1, "Should have an interface");
iface = results[0];
harness.check(len(iface.members), 1, "Should have an operation");
operation = iface.members[0];
harness.check(len(operation.signatures()), 1, "Should have one signature");
(retval, args) = operation.signatures()[0];
harness.check(len(args), 1, "Should have an argument");
harness.check(args[0].identifier.name, "constructor",
"Should have an identifier named 'constructor'");

View file

@ -205,6 +205,18 @@ def WebIDLTest(parser, harness):
harness.ok(threw, "Should not allow [TreatNullAs] on long")
parser = parser.reset()
threw = False
try:
parser.parse("""
typedef [TreatNullAs=EmptyString] JSString Foo;
""")
parser.finish()
except:
threw = True
harness.ok(threw, "Should not allow [TreatNullAs] on JSString")
parser = parser.reset()
threw = False
try:

View file

@ -43,45 +43,55 @@ def WebIDLTest(parser, harness):
(QName, name, type, optional, variadic) = expectedArgs[i]
checkArgument(gotArgs[i], QName, name, type, optional, variadic)
def checkResults(results):
harness.check(len(results), 3, "Should be three productions")
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
"Should be an IDLInterface")
harness.ok(isinstance(results[1], WebIDL.IDLInterface),
"Should be an IDLInterface")
harness.ok(isinstance(results[2], WebIDL.IDLInterface),
"Should be an IDLInterface")
checkMethod(results[0].ctor(), "::TestConstructorNoArgs::constructor",
"constructor", [("TestConstructorNoArgs (Wrapper)", [])])
harness.check(len(results[0].members), 0,
"TestConstructorNoArgs should not have members")
checkMethod(results[1].ctor(), "::TestConstructorWithArgs::constructor",
"constructor",
[("TestConstructorWithArgs (Wrapper)",
[("::TestConstructorWithArgs::constructor::name", "name", "String", False, False)])])
harness.check(len(results[1].members), 0,
"TestConstructorWithArgs should not have members")
checkMethod(results[2].ctor(), "::TestConstructorOverloads::constructor",
"constructor",
[("TestConstructorOverloads (Wrapper)",
[("::TestConstructorOverloads::constructor::foo", "foo", "Object", False, False)]),
("TestConstructorOverloads (Wrapper)",
[("::TestConstructorOverloads::constructor::bar", "bar", "Boolean", False, False)])])
harness.check(len(results[2].members), 0,
"TestConstructorOverloads should not have members")
parser.parse("""
[Constructor]
interface TestConstructorNoArgs {
constructor();
};
[Constructor(DOMString name)]
interface TestConstructorWithArgs {
constructor(DOMString name);
};
[Constructor(object foo), Constructor(boolean bar)]
interface TestConstructorOverloads {
constructor(object foo);
constructor(boolean bar);
};
""")
results = parser.finish()
harness.check(len(results), 3, "Should be three productions")
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
"Should be an IDLInterface")
harness.ok(isinstance(results[1], WebIDL.IDLInterface),
"Should be an IDLInterface")
harness.ok(isinstance(results[2], WebIDL.IDLInterface),
"Should be an IDLInterface")
checkMethod(results[0].ctor(), "::TestConstructorNoArgs::constructor",
"constructor", [("TestConstructorNoArgs (Wrapper)", [])])
checkMethod(results[1].ctor(), "::TestConstructorWithArgs::constructor",
"constructor",
[("TestConstructorWithArgs (Wrapper)",
[("::TestConstructorWithArgs::constructor::name", "name", "String", False, False)])])
checkMethod(results[2].ctor(), "::TestConstructorOverloads::constructor",
"constructor",
[("TestConstructorOverloads (Wrapper)",
[("::TestConstructorOverloads::constructor::foo", "foo", "Object", False, False)]),
("TestConstructorOverloads (Wrapper)",
[("::TestConstructorOverloads::constructor::bar", "bar", "Boolean", False, False)])])
checkResults(results)
parser = parser.reset()
parser.parse("""
[ChromeConstructor()]
interface TestChromeConstructor {
interface TestChromeOnlyConstructor {
[ChromeOnly] constructor();
};
""")
results = parser.finish()
@ -89,8 +99,8 @@ def WebIDLTest(parser, harness):
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
"Should be an IDLInterface")
checkMethod(results[0].ctor(), "::TestChromeConstructor::constructor",
"constructor", [("TestChromeConstructor (Wrapper)", [])],
checkMethod(results[0].ctor(), "::TestChromeOnlyConstructor::constructor",
"constructor", [("TestChromeOnlyConstructor (Wrapper)", [])],
chromeOnly=True)
parser = parser.reset()
@ -112,16 +122,16 @@ def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
[Constructor(),
ChromeConstructor(DOMString a)]
interface TestChromeConstructor {
interface TestChromeOnlyConstructor {
constructor()
[ChromeOnly] constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Can't have both a Constructor and a ChromeConstructor")
harness.ok(threw, "Can't have both a constructor and a ChromeOnly constructor")
# Test HTMLConstructor with argument
parser = parser.reset()
@ -153,120 +163,197 @@ def WebIDLTest(parser, harness):
harness.ok(threw, "HTMLConstructor can't be used on a callback interface")
# Test HTMLConstructor and Constructor
# Test HTMLConstructor and constructor operation
parser = parser.reset()
threw = False
try:
parser.parse("""
[Constructor,
HTMLConstructor]
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
constructor();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Can't have both a Constructor and a HTMLConstructor")
harness.ok(threw, "Can't have both a constructor and a HTMLConstructor")
parser = parser.reset()
threw = False
try:
parser.parse("""
[HTMLConstructor,
Constructor]
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
[Throws]
constructor();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Can't have both a HTMLConstructor and a Constructor")
harness.ok(threw,
"Can't have both a throwing constructor and a HTMLConstructor")
parser = parser.reset()
threw = False
try:
parser.parse("""
[HTMLConstructor,
Constructor(DOMString a)]
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Can't have both a HTMLConstructor and a Constructor")
harness.ok(threw,
"Can't have both a HTMLConstructor and a constructor operation")
parser = parser.reset()
threw = False
try:
parser.parse("""
[Constructor(DOMString a),
HTMLConstructor]
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
};
""")
except:
threw = True
harness.ok(threw, "Can't have both a HTMLConstructor and a Constructor")
# Test HTMLConstructor and ChromeConstructor
parser = parser.reset()
threw = False
try:
parser.parse("""
[ChromeConstructor,
HTMLConstructor]
interface TestHTMLConstructorAndChromeConstructor {
[Throws]
constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Can't have both a HTMLConstructor and a ChromeConstructor")
harness.ok(threw,
"Can't have both a HTMLConstructor and a throwing constructor "
"operation")
# Test HTMLConstructor and [ChromeOnly] constructor operation
parser = parser.reset()
threw = False
try:
parser.parse("""
[HTMLConstructor,
ChromeConstructor]
interface TestHTMLConstructorAndChromeConstructor {
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
[ChromeOnly]
constructor();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Can't have both a HTMLConstructor and a ChromeConstructor")
harness.ok(threw,
"Can't have both a ChromeOnly constructor and a HTMLConstructor")
parser = parser.reset()
threw = False
try:
parser.parse("""
[ChromeConstructor(DOMString a),
HTMLConstructor]
interface TestHTMLConstructorAndChromeConstructor {
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
[Throws, ChromeOnly]
constructor();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Can't have both a throwing chromeonly constructor and a "
"HTMLConstructor")
parser = parser.reset()
threw = False
try:
parser.parse("""
[HTMLConstructor,
ChromeConstructor(DOMString a)]
interface TestHTMLConstructorAndChromeConstructor {
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
[ChromeOnly]
constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Can't have both a HTMLConstructor and a ChromeConstructor")
harness.ok(threw,
"Can't have both a HTMLConstructor and a chromeonly constructor "
"operation")
parser = parser.reset()
threw = False
try:
parser.parse("""
[HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
[Throws, ChromeOnly]
constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Can't have both a HTMLConstructor and a throwing chromeonly "
"constructor operation")
parser = parser.reset()
threw = False
try:
parser.parse("""
[NoInterfaceObject]
interface InterfaceWithoutInterfaceObject {
constructor();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Can't have a constructor operation on a [NoInterfaceObject] "
"interface")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface InterfaceWithPartial {
};
partial interface InterfaceWithPartial {
constructor();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Can't have a constructor operation on a partial interface")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface InterfaceWithMixin {
};
interface mixin Mixin {
constructor();
};
InterfaceWithMixin includes Mixin
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Can't have a constructor operation on a mixin")

View file

@ -2,23 +2,9 @@ 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]
[Global]
interface TestConstructorGlobal {
constructor();
};
""")

View file

@ -2,23 +2,9 @@ def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
[Constructor, NoInterfaceObject]
interface TestConstructorNoInterfaceObject {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
parser = parser.reset()
threw = False
try:
parser.parse("""
[NoInterfaceObject, Constructor]
[NoInterfaceObject]
interface TestConstructorNoInterfaceObject {
constructor();
};
""")

View file

@ -320,14 +320,36 @@ def WebIDLTest(parser, harness):
dictionary A {
};
interface X {
void doFoo(optional A? arg1);
void doFoo(optional A? arg1 = {});
};
""")
results = parser.finish()
except:
threw = True
except Exception as x:
threw = x
harness.ok(threw, "Dictionary arg must not be nullable")
harness.ok(threw, "Optional dictionary arg must not be nullable")
harness.ok("nullable" in str(threw),
"Must have the expected exception for optional nullable dictionary arg")
parser = parser.reset()
threw = False
try:
parser.parse("""
dictionary A {
required long x;
};
interface X {
void doFoo(A? arg1);
};
""")
results = parser.finish()
except Exception as x:
threw = x
harness.ok(threw, "Required dictionary arg must not be nullable")
harness.ok("nullable" in str(threw),
"Must have the expected exception for required nullable "
"dictionary arg")
parser = parser.reset()
threw = False
@ -336,14 +358,54 @@ def WebIDLTest(parser, harness):
dictionary A {
};
interface X {
void doFoo(optional (A or long)? arg1);
void doFoo(optional (A or long)? arg1 = {});
};
""")
results = parser.finish()
except Exception as x:
threw = x
harness.ok(threw, "Dictionary arg must not be in an optional nullable union")
harness.ok("nullable" in str(threw),
"Must have the expected exception for optional nullable union "
"arg containing dictionary")
parser = parser.reset()
threw = False
try:
parser.parse("""
dictionary A {
required long x;
};
interface X {
void doFoo((A or long)? arg1);
};
""")
results = parser.finish()
except Exception as x:
threw = x
harness.ok(threw, "Dictionary arg must not be in a required nullable union")
harness.ok("nullable" in str(threw),
"Must have the expected exception for required nullable union "
"arg containing dictionary")
parser = parser.reset()
threw = False
try:
parser.parse("""
dictionary A {
};
interface X {
void doFoo(sequence<A?> arg1);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Dictionary arg must not be in a nullable union")
harness.ok(not threw,
"Nullable union should be allowed in a sequence argument")
parser = parser.reset()
threw = False

View file

@ -166,7 +166,7 @@ def WebIDLTest(parser, harness):
"record<ByteString, long>",
"Date", "Date?", "any",
"Promise<any>", "Promise<any>?",
"USVString", "ArrayBuffer", "ArrayBufferView", "SharedArrayBuffer",
"USVString", "JSString", "ArrayBuffer", "ArrayBufferView", "SharedArrayBuffer",
"Uint8Array", "Uint16Array",
"(long or Callback)", "(long or Dict)",
]
@ -183,7 +183,7 @@ def WebIDLTest(parser, harness):
primitives = numerics + booleans
nonNumerics = allBut(argTypes, numerics + unions)
nonBooleans = allBut(argTypes, booleans)
strings = [ "DOMString", "ByteString", "Enum", "Enum2", "USVString" ]
strings = [ "DOMString", "ByteString", "Enum", "Enum2", "USVString", "JSString" ]
nonStrings = allBut(argTypes, strings)
nonObjects = primitives + strings
objects = allBut(argTypes, nonObjects )
@ -202,7 +202,7 @@ def WebIDLTest(parser, harness):
notRelatedInterfaces = (nonObjects + ["UnrelatedInterface"] +
otherObjects + dates + sequences + bufferSourceTypes + sharedBufferSourceTypes)
records = [ "record<DOMString, object>", "record<USVString, Dict>",
"record<ByteString, long>" ]
"record<ByteString, long>" ] # JSString not supported in records
# Build a representation of the distinguishability table as a dict
# of dicts, holding True values where needed, holes elsewhere.
@ -222,6 +222,7 @@ def WebIDLTest(parser, harness):
setDistinguishable("DOMString", nonStrings)
setDistinguishable("ByteString", nonStrings)
setDistinguishable("USVString", nonStrings)
setDistinguishable("JSString", nonStrings)
setDistinguishable("Enum", nonStrings)
setDistinguishable("Enum2", nonStrings)
setDistinguishable("Interface", notRelatedInterfaces)
@ -244,6 +245,7 @@ def WebIDLTest(parser, harness):
allBut(argTypes, sequences + ["object"]))
setDistinguishable("record<DOMString, object>", nonUserObjects)
setDistinguishable("record<USVString, Dict>", nonUserObjects)
# JSString not supported in records
setDistinguishable("record<ByteString, long>", nonUserObjects)
setDistinguishable("Date", allBut(argTypes, dates + ["object"]))
setDistinguishable("Date?", allBut(argTypes, dates + nullables + ["object"]))

View file

@ -189,12 +189,12 @@ def WebIDLTest(parser, harness):
parser = parser.reset()
parser.parse("""
[Constructor(long arg)]
interface A {
constructor();
constructor(long arg);
readonly attribute boolean x;
void foo();
};
[Constructor]
partial interface A {
readonly attribute boolean y;
void foo(long arg);
@ -219,13 +219,13 @@ def WebIDLTest(parser, harness):
parser = parser.reset()
parser.parse("""
[Constructor]
partial interface A {
readonly attribute boolean y;
void foo(long arg);
};
[Constructor(long arg)]
interface A {
constructor();
constructor(long arg);
readonly attribute boolean x;
void foo();
};

View file

@ -264,18 +264,18 @@ def WebIDLTest(parser, harness):
shouldPass("JS Implemented maplike interface",
"""
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
Constructor()]
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
constructor();
setlike<long>;
};
""", setRWChromeMembers)
shouldPass("JS Implemented maplike interface",
"""
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
Constructor()]
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
constructor();
maplike<long, long>;
};
""", mapRWChromeMembers)
@ -655,9 +655,9 @@ def WebIDLTest(parser, harness):
shouldPass("JS Implemented read-only interface with readonly allowable overrides",
"""
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
Constructor()]
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
constructor();
readonly setlike<long>;
readonly attribute boolean clear;
};
@ -665,9 +665,9 @@ def WebIDLTest(parser, harness):
shouldFail("JS Implemented read-write interface with non-readwrite allowable overrides",
"""
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
Constructor()]
[JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
constructor();
setlike<long>;
readonly attribute boolean clear;
};