mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
This is required to publish script_bindings, since all files used during codegen need to be there. It might also be possible to generate the bindings ahead of time and vendor them in-tree, but this seems painful to setup from a CI perspective. Since there don't seem to be any other users in-tree we can just vendor into the script-bindings directory. `ply` is licensed under the BSD 3 clause, and WebIDL under MPL-2.0, with the licenses available in our cargo package. Both tools won't end up in `servo` since they are build-time dependencies, so I believe we don't need to adjust the crate license, or configure `about.toml`. Testing: Should be covered by existing tests. We don't test if this allows vendored builds or published builds. Fixes: Partial fix for #43145 --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
197 lines
4.8 KiB
Python
197 lines
4.8 KiB
Python
import WebIDL
|
|
|
|
|
|
def WebIDLTest(parser, harness):
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier;
|
|
};
|
|
"""
|
|
)
|
|
|
|
results = parser.finish()
|
|
|
|
harness.ok(
|
|
isinstance(results[0].members[0], WebIDL.IDLMethod),
|
|
"Stringifer should be method",
|
|
)
|
|
|
|
parser = parser.reset()
|
|
|
|
threw = False
|
|
try:
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier;
|
|
stringifier;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
except WebIDL.WebIDLError:
|
|
threw = True
|
|
|
|
harness.ok(threw, "Should not allow two 'stringifier;'")
|
|
|
|
parser = parser.reset()
|
|
|
|
threw = False
|
|
try:
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier;
|
|
stringifier DOMString foo();
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
except WebIDL.WebIDLError:
|
|
threw = True
|
|
|
|
harness.ok(threw, "Should not allow a 'stringifier;' and a 'stringifier()'")
|
|
|
|
parser = parser.reset()
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier attribute DOMString foo;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
harness.ok(
|
|
isinstance(results[0].members[0], WebIDL.IDLAttribute),
|
|
"Stringifier attribute should be an attribute",
|
|
)
|
|
stringifier = results[0].members[1]
|
|
harness.ok(
|
|
isinstance(stringifier, WebIDL.IDLMethod),
|
|
"Stringifier attribute should insert a method",
|
|
)
|
|
harness.ok(stringifier.isStringifier(), "Inserted method should be a stringifier")
|
|
|
|
parser = parser.reset()
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {};
|
|
interface mixin TestStringifierMixin {
|
|
stringifier attribute DOMString foo;
|
|
};
|
|
TestStringifier includes TestStringifierMixin;
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
harness.ok(
|
|
isinstance(results[0].members[0], WebIDL.IDLAttribute),
|
|
"Stringifier attribute should be an attribute",
|
|
)
|
|
stringifier = results[0].members[1]
|
|
harness.ok(
|
|
isinstance(stringifier, WebIDL.IDLMethod),
|
|
"Stringifier attribute should insert a method",
|
|
)
|
|
harness.ok(stringifier.isStringifier(), "Inserted method should be a stringifier")
|
|
|
|
parser = parser.reset()
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier attribute USVString foo;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
stringifier = results[0].members[1]
|
|
harness.ok(
|
|
stringifier.signatures()[0][0].isUSVString(),
|
|
"Stringifier attributes should allow USVString",
|
|
)
|
|
|
|
parser = parser.reset()
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
[Throws, NeedsSubjectPrincipal]
|
|
stringifier attribute USVString foo;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
stringifier = results[0].members[1]
|
|
harness.ok(
|
|
stringifier.getExtendedAttribute("Throws"),
|
|
"Stringifier attributes should support [Throws]",
|
|
)
|
|
harness.ok(
|
|
stringifier.getExtendedAttribute("NeedsSubjectPrincipal"),
|
|
"Stringifier attributes should support [NeedsSubjectPrincipal]",
|
|
)
|
|
|
|
parser = parser.reset()
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier attribute UTF8String foo;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
stringifier = results[0].members[1]
|
|
harness.ok(
|
|
stringifier.signatures()[0][0].isUTF8String(),
|
|
"Stringifier attributes should allow UTF8String",
|
|
)
|
|
|
|
parser = parser.reset()
|
|
threw = False
|
|
try:
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier attribute ByteString foo;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
except WebIDL.WebIDLError:
|
|
threw = True
|
|
|
|
harness.ok(threw, "Should not allow ByteString")
|
|
|
|
parser = parser.reset()
|
|
threw = False
|
|
try:
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier;
|
|
stringifier attribute DOMString foo;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
except WebIDL.WebIDLError:
|
|
threw = True
|
|
|
|
harness.ok(threw, "Should not allow a 'stringifier;' and a stringifier attribute")
|
|
|
|
parser = parser.reset()
|
|
threw = False
|
|
try:
|
|
parser.parse(
|
|
"""
|
|
interface TestStringifier {
|
|
stringifier attribute DOMString foo;
|
|
stringifier attribute DOMString bar;
|
|
};
|
|
"""
|
|
)
|
|
results = parser.finish()
|
|
except WebIDL.WebIDLError:
|
|
threw = True
|
|
|
|
harness.ok(threw, "Should not allow multiple stringifier attributes")
|