Merge pull request #3207 from Ms2ger/347-3065-typeerror

Throw TypeErrors instead of uncatcheable exceptions in CodegenRust.py (fixes #347, #3065).
This commit is contained in:
Josh Matthews 2014-09-04 17:16:44 -04:00
commit b940828a8a
2 changed files with 50 additions and 8 deletions

View file

@ -377,7 +377,8 @@ class CGMethodCall(CGThing):
overloadCGThings.append(
CGSwitch("argcount",
argCountCases,
CGGeneric("return 0; //XXXjdm throw stuff\n//return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, %s);\n" % methodName)))
CGGeneric("throw_type_error(cx, \"Not enough arguments to %s.\");\n"
"return 0;\n" % methodName)))
#XXXjdm Avoid unreachable statement warnings
#overloadCGThings.append(
# CGGeneric('fail!("We have an always-returning default case");\n'
@ -520,7 +521,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
return CGWrapper(
CGGeneric(
failureCode or
('//XXXjdm ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "%s", "%s")\n;'
('throw_type_error(cx, \"%s does not implement interface %s.\");\n'
'%s' % (firstCap(sourceDescription), typeName,
exceptionCode))),
post="\n")
@ -528,7 +529,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
return CGWrapper(
CGGeneric(
failureCode or
('//XXXjdm ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "%s");\n'
('throw_type_error(cx, \"%s is not callable.\");\n'
'%s' % (firstCap(sourceDescription), exceptionCode))),
post="\n")
@ -2656,7 +2657,7 @@ class CGStaticSetter(CGAbstractStaticBindingMethod):
checkForArg = CGGeneric(
"let argv = JS_ARGV(cx, vp);\n"
"if (argc == 0) {\n"
" // XXXjdmreturn ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, \"%s setter\");\n"
" throw_type_error(cx, \"Not enough arguments to %s setter.\");\n"
" return 0;\n"
"}\n" % self.attr.identifier.name)
call = CGSetterCall([], self.attr.type, nativeName, self.descriptor,
@ -4311,7 +4312,7 @@ class CGDictionary(CGThing):
" } else if val.is_object() {\n"
" val.to_object()\n"
" } else {\n"
" //XXXjdm throw properly here\n"
" throw_type_error(cx, \"Value not an object.\");\n"
" return Err(());\n"
" };\n"
" Ok(${selfName} {\n"

View file

@ -1,6 +1,5 @@
[interfaces.html]
type: testharness
expected: TIMEOUT
[XMLHttpRequest interface: operation open(ByteString,DOMString)]
expected: FAIL
@ -13,6 +12,48 @@
[XMLHttpRequest interface: operation overrideMimeType(DOMString)]
expected: FAIL
[XMLHttpRequest interface: calling open(ByteString,DOMString) on new XMLHttpRequest() with too few arguments must throw TypeError]
expected: TIMEOUT
[XMLHttpRequest interface: calling open(ByteString,DOMString,boolean,DOMString,DOMString) on new XMLHttpRequest() with too few arguments must throw TypeError]
expected: FAIL
[XMLHttpRequest interface: new XMLHttpRequest() must inherit property "statusText" with the proper type (16)]
expected: FAIL
[XMLHttpRequest interface: new XMLHttpRequest() must inherit property "overrideMimeType" with the proper type (19)]
expected: FAIL
[XMLHttpRequest interface: calling overrideMimeType(DOMString) on new XMLHttpRequest() with too few arguments must throw TypeError]
expected: FAIL
[FormData interface: existence and properties of interface object]
expected: FAIL
[FormData interface object length]
expected: FAIL
[FormData interface: operation append(DOMString,Blob,DOMString)]
expected: FAIL
[FormData interface: operation append(DOMString,DOMString)]
expected: FAIL
[FormData interface: operation getAll(DOMString)]
expected: FAIL
[FormData interface: operation set(DOMString,Blob,DOMString)]
expected: FAIL
[FormData interface: operation set(DOMString,DOMString)]
expected: FAIL
[FormData interface: new FormData() must inherit property "getAll" with the proper type (4)]
expected: FAIL
[FormData interface: calling getAll(DOMString) on new FormData() with too few arguments must throw TypeError]
expected: FAIL
[FormData interface: new FormData(form) must inherit property "getAll" with the proper type (4)]
expected: FAIL
[FormData interface: calling getAll(DOMString) on new FormData(form) with too few arguments must throw TypeError]
expected: FAIL