mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Merge pull request #3003 from Ms2ger/interface-unwrap-failure
Throw a TypeError when unwrapping an interface fails; r=Manishearth+jdm
This commit is contained in:
commit
6b6857ae2e
2 changed files with 37 additions and 33 deletions
|
@ -101,36 +101,24 @@ class CastableObjectUnwrapper():
|
|||
codeOnFailure is the code to run if unwrapping fails.
|
||||
"""
|
||||
def __init__(self, descriptor, source, codeOnFailure):
|
||||
self.substitution = { "type" : descriptor.nativeType,
|
||||
self.substitution = {
|
||||
"type": descriptor.nativeType,
|
||||
"depth": descriptor.interface.inheritanceDepth(),
|
||||
"prototype": "PrototypeList::id::" + descriptor.name,
|
||||
"protoID" : "PrototypeList::id::" + descriptor.name + " as uint",
|
||||
"source" : source,
|
||||
"codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define()}
|
||||
"protoID": "PrototypeList::id::" + descriptor.name + " as uint",
|
||||
"source": source,
|
||||
"codeOnFailure": CGIndenter(CGGeneric(codeOnFailure), 4).define(),
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return string.Template(
|
||||
"""match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) {
|
||||
Ok(val) => val,
|
||||
Err(()) => {
|
||||
${codeOnFailure}
|
||||
${codeOnFailure}
|
||||
}
|
||||
}""").substitute(self.substitution)
|
||||
|
||||
#"""{
|
||||
# nsresult rv = UnwrapObject<${protoID}, ${type}>(cx, ${source}, ${target});
|
||||
# if (NS_FAILED(rv)) {
|
||||
#${codeOnFailure}
|
||||
# }
|
||||
#}""").substitute(self.substitution)
|
||||
|
||||
class FailureFatalCastableObjectUnwrapper(CastableObjectUnwrapper):
|
||||
"""
|
||||
As CastableObjectUnwrapper, but defaulting to throwing if unwrapping fails
|
||||
"""
|
||||
def __init__(self, descriptor, source):
|
||||
CastableObjectUnwrapper.__init__(self, descriptor, source,
|
||||
"return 0; //XXXjdm return Throw(cx, rv);")
|
||||
|
||||
class CGThing():
|
||||
"""
|
||||
|
@ -597,15 +585,23 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
|||
raise TypeError("Consequential interface %s being used as an "
|
||||
"argument" % descriptor.interface.identifier.name)
|
||||
|
||||
if failureCode is not None:
|
||||
if failureCode is None:
|
||||
substitutions = {
|
||||
"sourceDescription": sourceDescription,
|
||||
"interface": descriptor.interface.identifier.name,
|
||||
"exceptionCode": exceptionCode,
|
||||
}
|
||||
unwrapFailureCode = string.Template(
|
||||
'throw_type_error(cx, "${sourceDescription} does not '
|
||||
'implement interface ${interface}.");\n'
|
||||
'${exceptionCode}').substitute(substitutions)
|
||||
else:
|
||||
unwrapFailureCode = failureCode
|
||||
|
||||
templateBody = str(CastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"(${val}).to_object()",
|
||||
failureCode))
|
||||
else:
|
||||
templateBody = str(FailureFatalCastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"(${val}).to_object()"))
|
||||
unwrapFailureCode))
|
||||
|
||||
declType = CGGeneric(descriptorType)
|
||||
if type.nullable():
|
||||
|
@ -2381,7 +2377,10 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
|
|||
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
|
||||
|
||||
if unwrapFailureCode is None:
|
||||
self.unwrapFailureCode = "return 0; //XXXjdm return Throw(cx, rv);"
|
||||
self.unwrapFailureCode = (
|
||||
'throw_type_error(cx, "\\"this\\" object does not '
|
||||
'implement interface %s.");\n'
|
||||
'return 0;' % descriptor.interface.identifier.name)
|
||||
else:
|
||||
self.unwrapFailureCode = unwrapFailureCode
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
[Node-insertBefore.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[Calling insertBefore with a non-Node first argument must throw TypeError.]
|
||||
expected: TIMEOUT
|
||||
[If the context node is a document, inserting a document or text node should throw a HierarchyRequestError.]
|
||||
expected: FAIL
|
||||
|
||||
[If the context node is a DocumentFragment, inserting a document or a doctype should throw a HierarchyRequestError.]
|
||||
expected: FAIL
|
||||
|
||||
[If the context node is an element, inserting a document or a doctype should throw a HierarchyRequestError.]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue