mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
codegen: Throw on an invalid enum value when appropiate
This commit is contained in:
parent
093f5c01e4
commit
e50d4b7624
5 changed files with 56 additions and 10 deletions
|
@ -662,12 +662,17 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
'%s' % (firstCap(sourceDescription), exceptionCode))),
|
'%s' % (firstCap(sourceDescription), exceptionCode))),
|
||||||
post="\n")
|
post="\n")
|
||||||
|
|
||||||
|
def onFailureInvalidEnumValue(failureCode):
|
||||||
|
return CGGeneric(
|
||||||
|
failureCode or
|
||||||
|
('throw_type_error(cx, "%s is not a valid enum value."); %s'
|
||||||
|
% (firstCap(sourceDescription), exceptionCode)))
|
||||||
|
|
||||||
def onFailureNotCallable(failureCode):
|
def onFailureNotCallable(failureCode):
|
||||||
return CGWrapper(
|
return CGGeneric(
|
||||||
CGGeneric(
|
|
||||||
failureCode or
|
failureCode or
|
||||||
('throw_type_error(cx, \"%s is not callable.\");\n'
|
('throw_type_error(cx, \"%s is not callable.\");\n'
|
||||||
'%s' % (firstCap(sourceDescription), exceptionCode))))
|
'%s' % (firstCap(sourceDescription), exceptionCode)))
|
||||||
|
|
||||||
# A helper function for handling null default values. Checks that the
|
# A helper function for handling null default values. Checks that the
|
||||||
# default value, if it exists, is null.
|
# default value, if it exists, is null.
|
||||||
|
@ -868,7 +873,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
"yet")
|
"yet")
|
||||||
enum = type.inner.identifier.name
|
enum = type.inner.identifier.name
|
||||||
if invalidEnumValueFatal:
|
if invalidEnumValueFatal:
|
||||||
handleInvalidEnumValueCode = exceptionCode
|
handleInvalidEnumValueCode = onFailureInvalidEnumValue(failureCode).define()
|
||||||
else:
|
else:
|
||||||
handleInvalidEnumValueCode = "return true;"
|
handleInvalidEnumValueCode = "return true;"
|
||||||
|
|
||||||
|
|
|
@ -11,3 +11,4 @@
|
||||||
|
|
||||||
[Using special character in fileName]
|
[Using special character in fileName]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,41 @@
|
||||||
[DOMParser-parseFromString-xml.html]
|
[DOMParser-parseFromString-xml.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: TIMEOUT
|
|
||||||
[Should return an error document for XML wellformedness errors in type text/xml]
|
[Should return an error document for XML wellformedness errors in type text/xml]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Should parse correctly in type application/xml]
|
[Should parse correctly in type application/xml]
|
||||||
expected: TIMEOUT
|
expected: FAIL
|
||||||
|
|
||||||
|
[XMLDocument interface for correctly parsed document with type application/xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[Should return an error document for XML wellformedness errors in type application/xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[XMLDocument interface for incorrectly parsed document with type application/xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[Should parse correctly in type application/xhtml+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[XMLDocument interface for correctly parsed document with type application/xhtml+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[Should return an error document for XML wellformedness errors in type application/xhtml+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[XMLDocument interface for incorrectly parsed document with type application/xhtml+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[Should parse correctly in type image/svg+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[XMLDocument interface for correctly parsed document with type image/svg+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[Should return an error document for XML wellformedness errors in type image/svg+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[XMLDocument interface for incorrectly parsed document with type image/svg+xml]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
[Document-defaultView.html]
|
[Document-defaultView.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: TIMEOUT
|
|
||||||
[Document created with the Document constructor]
|
[Document created with the Document constructor]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -11,5 +10,8 @@
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Document created with XML DOMParser]
|
[Document created with XML DOMParser]
|
||||||
expected: TIMEOUT
|
expected: FAIL
|
||||||
|
|
||||||
|
[Document created with HTML DOMParser]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -61,4 +61,10 @@ test(function() {
|
||||||
assert_equals(htmldoc.documentElement.localName, "html");
|
assert_equals(htmldoc.documentElement.localName, "html");
|
||||||
assert_equals(htmldoc.documentElement.namespaceURI, "http://www.w3.org/1999/xhtml");
|
assert_equals(htmldoc.documentElement.namespaceURI, "http://www.w3.org/1999/xhtml");
|
||||||
}, "DOMParser parses HTML tag soup with no problems");
|
}, "DOMParser parses HTML tag soup with no problems");
|
||||||
|
|
||||||
|
test(function() {
|
||||||
|
assert_throws(new TypeError(), function() {
|
||||||
|
new DOMParser().parseFromString("", "text/foo-this-is-invalid");
|
||||||
|
})
|
||||||
|
}, "DOMParser throws on an invalid enum value")
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue