Bug 776685; throw TypeError exceptions from Azure canvas bindings. r=bz

This commit is contained in:
Nicholas Cameron 2012-07-26 14:31:26 +12:00
Родитель 497dabe033
Коммит f642f5c9cd
3 изменённых файлов: 112 добавлений и 33 удалений

Просмотреть файл

@ -3538,8 +3538,13 @@ var ctx = canvas.getContext('2d');
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.drawImage(null, 0, 0); ctx.drawImage(null, 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }
</script> </script>
@ -3715,17 +3720,39 @@ var ctx = canvas.getContext('2d');
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.drawImage(undefined, 0, 0); ctx.drawImage(undefined, 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.drawImage(0, 0, 0); ctx.drawImage(0, 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.drawImage("", 0, 0); ctx.drawImage("", 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.drawImage(document.createElement('p'), 0, 0); ctx.drawImage(document.createElement('p'), 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }
</script> </script>
@ -7696,7 +7723,12 @@ var ctx = canvas.getContext('2d');
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.createImageData(null); ctx.createImageData(null);
} catch (e) { _thrown = e }; todo(_thrown && _thrown instanceof TypeError, "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }
@ -9207,8 +9239,12 @@ var ctx = canvas.getContext('2d');
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.putImageData(null, 0, 0); ctx.putImageData(null, 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }
</script> </script>
@ -9319,13 +9355,31 @@ var ctx = canvas.getContext('2d');
var imgdata = { width: 1, height: 1, data: [255, 0, 0, 255] }; var imgdata = { width: 1, height: 1, data: [255, 0, 0, 255] };
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.putImageData(imgdata, 0, 0); ctx.putImageData(imgdata, 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.putImageData("cheese", 0, 0); ctx.putImageData("cheese", 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.putImageData(42, 0, 0); ctx.putImageData(42, 0, 0);
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }
@ -15131,7 +15185,12 @@ var ctx = canvas.getContext('2d');
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.createPattern(null, 'repeat'); ctx.createPattern(null, 'repeat');
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }
@ -15150,7 +15209,12 @@ var ctx = canvas.getContext('2d');
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.createPattern('image_red.png', 'repeat'); ctx.createPattern('image_red.png', 'repeat');
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }
@ -15169,7 +15233,12 @@ var ctx = canvas.getContext('2d');
var _thrown = undefined; try { var _thrown = undefined; try {
ctx.createPattern(undefined, 'repeat'); ctx.createPattern(undefined, 'repeat');
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError"); } catch (e) { _thrown = e };
if (IsAzureEnabled()) {
ok(_thrown && _thrown.name == "TypeError", "should throw TypeError");
} else {
todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
}
} }

Просмотреть файл

@ -1513,13 +1513,16 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
# Also, we should not have a defaultValue if we know we're an object # Also, we should not have a defaultValue if we know we're an object
assert(not isDefinitelyObject or defaultValue is None) assert(not isDefinitelyObject or defaultValue is None)
# A helper function for dealing with failures due to the JS value being the # Helper functions for dealing with failures due to the JS value being the
# wrong type of value # wrong type of value
def onFailure(failureCode, isWorker): def onFailureNotAnObject(failureCode):
return CGWrapper(CGGeneric( return CGWrapper(CGGeneric(
failureCode or failureCode or
"return Throw<%s>(cx, NS_ERROR_XPC_BAD_CONVERT_JS);" 'return ThrowErrorMessage(cx, MSG_NOT_OBJECT);'), post="\n")
% toStringBool(isWorker)), post="\n") def onFailureBadType(failureCode, typeName):
return CGWrapper(CGGeneric(
failureCode or
'return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "%s");' % typeName), post="\n")
# A helper function for handling default values. Takes a template # A helper function for handling default values. Takes a template
# body and the C++ code to set the default value and wraps the # body and the C++ code to set the default value and wraps the
@ -1547,7 +1550,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
# A helper function for wrapping up the template body for # A helper function for wrapping up the template body for
# possibly-nullable objecty stuff # possibly-nullable objecty stuff
def wrapObjectTemplate(templateBody, isDefinitelyObject, type, def wrapObjectTemplate(templateBody, isDefinitelyObject, type,
codeToSetNull, isWorker, failureCode=None): codeToSetNull, failureCode=None):
if not isDefinitelyObject: if not isDefinitelyObject:
# Handle the non-object cases by wrapping up the whole # Handle the non-object cases by wrapping up the whole
# thing in an if cascade. # thing in an if cascade.
@ -1560,7 +1563,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
" %s;\n" % codeToSetNull) " %s;\n" % codeToSetNull)
templateBody += ( templateBody += (
"} else {\n" + "} else {\n" +
CGIndenter(onFailure(failureCode, isWorker)).define() + CGIndenter(onFailureNotAnObject(failureCode)).define() +
"}") "}")
if type.nullable(): if type.nullable():
templateBody = handleDefaultNull(templateBody, codeToSetNull) templateBody = handleDefaultNull(templateBody, codeToSetNull)
@ -1646,8 +1649,7 @@ for (uint32_t i = 0; i < length; ++i) {
templateBody += "\n}" templateBody += "\n}"
templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject, templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject,
type, type,
"const_cast< %s & >(${declName}).SetNull()" % mutableTypeName.define(), "const_cast< %s & >(${declName}).SetNull()" % mutableTypeName.define())
descriptorProvider.workers)
return (templateBody, typeName, None, isOptional) return (templateBody, typeName, None, isOptional)
if type.isUnion(): if type.isUnion():
@ -1666,6 +1668,7 @@ for (uint32_t i = 0; i < length; ++i) {
unionArgumentObj += ".ref()" unionArgumentObj += ".ref()"
memberTypes = type.flatMemberTypes memberTypes = type.flatMemberTypes
names = []
interfaceMemberTypes = filter(lambda t: t.isNonCallbackInterface(), memberTypes) interfaceMemberTypes = filter(lambda t: t.isNonCallbackInterface(), memberTypes)
if len(interfaceMemberTypes) > 0: if len(interfaceMemberTypes) > 0:
@ -1676,6 +1679,7 @@ for (uint32_t i = 0; i < length; ++i) {
else: else:
name = memberType.name name = memberType.name
interfaceObject.append(CGGeneric("(failed = !%s.TrySetTo%s(cx, ${val}, ${valPtr}, tryNext)) || !tryNext" % (unionArgumentObj, name))) interfaceObject.append(CGGeneric("(failed = !%s.TrySetTo%s(cx, ${val}, ${valPtr}, tryNext)) || !tryNext" % (unionArgumentObj, name)))
names.append(name)
interfaceObject = CGWrapper(CGList(interfaceObject, " ||\n"), pre="done = ", post=";\n", reindent=True) interfaceObject = CGWrapper(CGList(interfaceObject, " ||\n"), pre="done = ", post=";\n", reindent=True)
else: else:
interfaceObject = None interfaceObject = None
@ -1692,6 +1696,7 @@ for (uint32_t i = 0; i < length; ++i) {
arrayObject = CGWrapper(CGIndenter(arrayObject), arrayObject = CGWrapper(CGIndenter(arrayObject),
pre="if (IsArrayLike(cx, &argObj)) {\n", pre="if (IsArrayLike(cx, &argObj)) {\n",
post="}") post="}")
names.append(name)
else: else:
arrayObject = None arrayObject = None
@ -1705,6 +1710,7 @@ for (uint32_t i = 0; i < length; ++i) {
dateObject = CGWrapper(CGIndenter(dateObject), dateObject = CGWrapper(CGIndenter(dateObject),
pre="if (JS_ObjectIsDate(cx, &argObj)) {\n", pre="if (JS_ObjectIsDate(cx, &argObj)) {\n",
post="\n}") post="\n}")
names.append(name)
else: else:
dateObject = None dateObject = None
@ -1714,6 +1720,7 @@ for (uint32_t i = 0; i < length; ++i) {
memberType = callbackMemberTypes[0] memberType = callbackMemberTypes[0]
name = memberType.name name = memberType.name
callbackObject = CGGeneric("done = (failed = !%s.TrySetTo%s(cx, ${val}, ${valPtr}, tryNext)) || !tryNext;" % (unionArgumentObj, name)) callbackObject = CGGeneric("done = (failed = !%s.TrySetTo%s(cx, ${val}, ${valPtr}, tryNext)) || !tryNext;" % (unionArgumentObj, name))
names.append(name)
else: else:
callbackObject = None callbackObject = None
@ -1783,6 +1790,7 @@ for (uint32_t i = 0; i < length; ++i) {
else: else:
name = memberType.name name = memberType.name
other = CGGeneric("done = (failed = !%s.TrySetTo%s(cx, ${val}, ${valPtr}, tryNext)) || !tryNext;" % (unionArgumentObj, name)) other = CGGeneric("done = (failed = !%s.TrySetTo%s(cx, ${val}, ${valPtr}, tryNext)) || !tryNext;" % (unionArgumentObj, name))
names.append(name)
if hasObjectTypes: if hasObjectTypes:
other = CGWrapper(CGIndenter(other), "{\n", post="\n}") other = CGWrapper(CGIndenter(other), "{\n", post="\n}")
if object: if object:
@ -1799,8 +1807,8 @@ for (uint32_t i = 0; i < length; ++i) {
" return false;\n" " return false;\n"
"}\n" "}\n"
"if (!done) {\n" "if (!done) {\n"
" return Throw<%s>(cx, NS_ERROR_XPC_BAD_CONVERT_JS);\n" " return ThrowErrorMessage(cx, MSG_NOT_IN_UNION, \"%s\");\n"
"}" % toStringBool(descriptorProvider.workers)) "}" % ", ".join(names))
templateBody = CGWrapper(CGIndenter(CGList([templateBody, throw], "\n")), pre="{\n", post="\n}") templateBody = CGWrapper(CGIndenter(CGList([templateBody, throw], "\n")), pre="{\n", post="\n}")
typeName = type.name typeName = type.name
@ -1939,8 +1947,8 @@ for (uint32_t i = 0; i < length; ++i) {
"jsval tmpVal = ${val};\n" + "jsval tmpVal = ${val};\n" +
typePtr + " tmp;\n" typePtr + " tmp;\n"
"if (NS_FAILED(xpc_qsUnwrapArg<" + typeName + ">(cx, ${val}, &tmp, static_cast<" + typeName + "**>(getter_AddRefs(${holderName})), &tmpVal))) {\n") "if (NS_FAILED(xpc_qsUnwrapArg<" + typeName + ">(cx, ${val}, &tmp, static_cast<" + typeName + "**>(getter_AddRefs(${holderName})), &tmpVal))) {\n")
templateBody += CGIndenter(onFailure(failureCode, templateBody += CGIndenter(onFailureBadType(failureCode,
descriptor.workers)).define() descriptor.interface.identifier.name)).define()
templateBody += ("}\n" templateBody += ("}\n"
"MOZ_ASSERT(tmp);\n") "MOZ_ASSERT(tmp);\n")
@ -1959,7 +1967,7 @@ for (uint32_t i = 0; i < length; ++i) {
templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject, templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject,
type, "${declName} = NULL", type, "${declName} = NULL",
descriptor.workers, failureCode) failureCode)
declType = CGGeneric(declType) declType = CGGeneric(declType)
if holderType is not None: if holderType is not None:
@ -1997,10 +2005,10 @@ for (uint32_t i = 0; i < length; ++i) {
template = ( template = (
"%s.%s(cx, &${val}.toObject());\n" "%s.%s(cx, &${val}.toObject());\n"
"if (!%s.%s().inited()) {\n" "if (!%s.%s().inited()) {\n"
"%s" # No newline here because onFailure() handles that "%s" # No newline here because onFailureBadType() handles that
"}\n" % "}\n" %
(constructLoc, constructMethod, constructLoc, constructInternal, (constructLoc, constructMethod, constructLoc, constructInternal,
CGIndenter(onFailure(failureCode, descriptorProvider.workers)).define())) CGIndenter(onFailureBadType(failureCode, type.name)).define()))
nullableTarget = "" nullableTarget = ""
if type.nullable(): if type.nullable():
if isOptional: if isOptional:
@ -2014,7 +2022,6 @@ for (uint32_t i = 0; i < length; ++i) {
template += "${declName} = ${holderName}.addr();" template += "${declName} = ${holderName}.addr();"
template = wrapObjectTemplate(template, isDefinitelyObject, type, template = wrapObjectTemplate(template, isDefinitelyObject, type,
"%s = NULL" % nullableTarget, "%s = NULL" % nullableTarget,
descriptorProvider.workers,
failureCode) failureCode)
if holderType is not None: if holderType is not None:
@ -2148,7 +2155,7 @@ for (uint32_t i = 0; i < length; ++i) {
template = wrapObjectTemplate("${declName} = &${val}.toObject();", template = wrapObjectTemplate("${declName} = &${val}.toObject();",
isDefinitelyObject, type, isDefinitelyObject, type,
"${declName} = NULL", "${declName} = NULL",
descriptorProvider.workers, failureCode) failureCode)
if type.nullable(): if type.nullable():
declType = CGGeneric("JSObject*") declType = CGGeneric("JSObject*")
else: else:

Просмотреть файл

@ -19,5 +19,8 @@
* be replaced with a string value when the error is reported. * be replaced with a string value when the error is reported.
*/ */
MSG_DEF(MSG_INVALID_ENUM_VALUE, 2, "Value '{0}' is not a valid value for enumeration '{1}'.") MSG_DEF(MSG_INVALID_ENUM_VALUE, 2, "Value '{0}' is not a valid value for enumeration {1}.")
MSG_DEF(MSG_MISSING_ARGUMENTS, 1, "Not enough arguments to {0}.") MSG_DEF(MSG_MISSING_ARGUMENTS, 1, "Not enough arguments to {0}.")
MSG_DEF(MSG_NOT_OBJECT, 0, "Value not an object.")
MSG_DEF(MSG_DOES_NOT_IMPLEMENT_INTERFACE, 1, "Value does not implement interface {0}.")
MSG_DEF(MSG_NOT_IN_UNION, 1, "Value could not be converted to any of: {0}.")