Skip to content

Commit

Permalink
Throw TypeErrors instead of uncatcheable exceptions in CodegenRust.py (
Browse files Browse the repository at this point in the history
…fixes #347, #3065).
  • Loading branch information
Pierre Louis Aublin authored and Ms2ger committed Sep 4, 2014
1 parent ff97135 commit cf734b0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -377,7 +377,8 @@ def pickFirstSignature(condition, filterLambda):
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'
Expand Down Expand Up @@ -520,15 +521,15 @@ def onFailureBadType(failureCode, typeName):
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")
def onFailureNotCallable(failureCode):
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")

Expand Down Expand Up @@ -2656,7 +2657,7 @@ def generate_code(self):
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,
Expand Down Expand Up @@ -4311,7 +4312,7 @@ def memberInit(memberInfo):
" } 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"
Expand Down
47 changes: 44 additions & 3 deletions src/test/wpt/metadata/XMLHttpRequest/interfaces.html.ini
@@ -1,6 +1,5 @@
[interfaces.html]
type: testharness
expected: TIMEOUT
[XMLHttpRequest interface: operation open(ByteString,DOMString)]
expected: FAIL

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

0 comments on commit cf734b0

Please sign in to comment.