diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 0912c6fdf96..5f0a7e01c79 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -145,7 +145,7 @@ class CGMethodCall(CGThing): def __init__(self, argsPre, nativeMethodName, static, descriptor, method): CGThing.__init__(self) - methodName = '"%s.%s"' % (descriptor.interface.identifier.name, method.identifier.name) + methodName = '\\"%s.%s\\"' % (descriptor.interface.identifier.name, method.identifier.name) def requiredArgCount(signature): arguments = signature[1] @@ -176,8 +176,8 @@ class CGMethodCall(CGThing): if requiredArgs > 0: code = ( "if argc < %d {\n" - " return 0; //XXXjdm throw exception\n" - " //return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, %s);\n" + " ThrowTypeError(cx, \"Not enough arguments to %s.\");\n" + " return 0;\n" "}" % (requiredArgs, methodName)) self.cgRoot.prepend( CGWrapper(CGIndenter(CGGeneric(code)), pre="\n", post="\n")) @@ -4329,6 +4329,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::utils::{VoidVal, with_gc_disabled}', 'dom::bindings::utils::{with_gc_enabled}', 'dom::bindings::utils::get_dictionary_property', + 'dom::bindings::utils::ThrowTypeError', 'dom::bindings::trace::JSTraceable', 'dom::bindings::callback::{CallbackContainer,CallbackInterface}', 'dom::bindings::callback::{CallSetup,ExceptionHandling}', diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 61e1e0213d9..994ecb65e5a 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -38,6 +38,7 @@ use js::jsapi::{JSFunctionSpec, JSPropertySpec}; use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses}; use js::jsapi::{JSString}; use js::jsapi::{JS_AllowGC, JS_InhibitGC}; +use js::jsapi::{JS_ReportErrorNumber, JSErrorFormatString, struct_JSErrorFormatString, JSEXN_TYPEERR}; use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType; use js::jsval::JSVal; use js::jsval::{PrivateValue, ObjectValue, NullValue, ObjectOrNullValue}; @@ -368,6 +369,33 @@ fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject, } } +static ErrorFormatStringString: [libc::c_char, ..4] = [ + '{' as libc::c_char, + '0' as libc::c_char, + '}' as libc::c_char, + 0 as libc::c_char, +]; + +static ErrorFormatString: JSErrorFormatString = struct_JSErrorFormatString { + format: &ErrorFormatStringString as *libc::c_char, + argCount: 1, + exnType: JSEXN_TYPEERR as i16, +}; + +extern fn GetErrorMessage(_user_ref: *mut libc::c_void, _locale: *libc::c_char, + aErrorNumber: libc::c_uint) -> *JSErrorFormatString +{ + assert_eq!(aErrorNumber, 0); + &ErrorFormatString as *JSErrorFormatString +} + +pub fn ThrowTypeError(cx: *JSContext, error: &str) { + let error = error.to_c_str(); + error.with_ref(|error| unsafe { + JS_ReportErrorNumber(cx, GetErrorMessage, ptr::null(), 0, error); + }); +} + pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool { //XXX should trigger exception here return 0; diff --git a/src/support/spidermonkey/rust-mozjs b/src/support/spidermonkey/rust-mozjs index 46a6ae354fa..92d2979ff96 160000 --- a/src/support/spidermonkey/rust-mozjs +++ b/src/support/spidermonkey/rust-mozjs @@ -1 +1 @@ -Subproject commit 46a6ae354fadc11a228c78b32e4365f6b6d8006d +Subproject commit 92d2979ff9656e6dcc018486bc3a7d1bcc63fd99