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:
Ms2ger 2014-08-05 16:23:45 +02:00
commit 6b6857ae2e
2 changed files with 37 additions and 33 deletions

View file

@ -101,12 +101,14 @@ 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()}
"codeOnFailure": CGIndenter(CGGeneric(codeOnFailure), 4).define(),
}
def __str__(self):
return string.Template(
@ -117,20 +119,6 @@ class CastableObjectUnwrapper():
}
}""").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

View file

@ -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