mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Throw a TypeError when too few arguments are passed.
This commit is contained in:
parent
9f742a9462
commit
bfde816da0
3 changed files with 33 additions and 4 deletions
|
@ -145,7 +145,7 @@ class CGMethodCall(CGThing):
|
||||||
def __init__(self, argsPre, nativeMethodName, static, descriptor, method):
|
def __init__(self, argsPre, nativeMethodName, static, descriptor, method):
|
||||||
CGThing.__init__(self)
|
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):
|
def requiredArgCount(signature):
|
||||||
arguments = signature[1]
|
arguments = signature[1]
|
||||||
|
@ -176,8 +176,8 @@ class CGMethodCall(CGThing):
|
||||||
if requiredArgs > 0:
|
if requiredArgs > 0:
|
||||||
code = (
|
code = (
|
||||||
"if argc < %d {\n"
|
"if argc < %d {\n"
|
||||||
" return 0; //XXXjdm throw exception\n"
|
" ThrowTypeError(cx, \"Not enough arguments to %s.\");\n"
|
||||||
" //return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, %s);\n"
|
" return 0;\n"
|
||||||
"}" % (requiredArgs, methodName))
|
"}" % (requiredArgs, methodName))
|
||||||
self.cgRoot.prepend(
|
self.cgRoot.prepend(
|
||||||
CGWrapper(CGIndenter(CGGeneric(code)), pre="\n", post="\n"))
|
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::{VoidVal, with_gc_disabled}',
|
||||||
'dom::bindings::utils::{with_gc_enabled}',
|
'dom::bindings::utils::{with_gc_enabled}',
|
||||||
'dom::bindings::utils::get_dictionary_property',
|
'dom::bindings::utils::get_dictionary_property',
|
||||||
|
'dom::bindings::utils::ThrowTypeError',
|
||||||
'dom::bindings::trace::JSTraceable',
|
'dom::bindings::trace::JSTraceable',
|
||||||
'dom::bindings::callback::{CallbackContainer,CallbackInterface}',
|
'dom::bindings::callback::{CallbackContainer,CallbackInterface}',
|
||||||
'dom::bindings::callback::{CallSetup,ExceptionHandling}',
|
'dom::bindings::callback::{CallSetup,ExceptionHandling}',
|
||||||
|
|
|
@ -38,6 +38,7 @@ use js::jsapi::{JSFunctionSpec, JSPropertySpec};
|
||||||
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
|
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
|
||||||
use js::jsapi::{JSString};
|
use js::jsapi::{JSString};
|
||||||
use js::jsapi::{JS_AllowGC, JS_InhibitGC};
|
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::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
||||||
use js::jsval::JSVal;
|
use js::jsval::JSVal;
|
||||||
use js::jsval::{PrivateValue, ObjectValue, NullValue, ObjectOrNullValue};
|
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 {
|
pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool {
|
||||||
//XXX should trigger exception here
|
//XXX should trigger exception here
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 46a6ae354fadc11a228c78b32e4365f6b6d8006d
|
Subproject commit 92d2979ff9656e6dcc018486bc3a7d1bcc63fd99
|
Loading…
Add table
Add a link
Reference in a new issue