Throw a TypeError when too few arguments are passed.

This commit is contained in:
Ms2ger 2014-04-19 23:25:43 +02:00
parent 9f742a9462
commit bfde816da0
3 changed files with 33 additions and 4 deletions

View file

@ -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}',

View file

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