Move ThrowTypeError to error.rs.

This commit is contained in:
Ms2ger 2014-04-28 16:50:53 +02:00
parent bfde816da0
commit 7ff9fff421
3 changed files with 32 additions and 30 deletions

View file

@ -4329,7 +4329,6 @@ 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}',
@ -4341,6 +4340,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::codegen::UnionTypes::*',
'dom::bindings::error::{FailureUnknown, Fallible, Error, ErrorResult}',
'dom::bindings::error::{throw_method_failed_with_details}',
'dom::bindings::error::ThrowTypeError',
'script_task::JSPageInfo',
'dom::bindings::proxyhandler',
'dom::bindings::proxyhandler::{_obj_toString, defineProperty}',

View file

@ -4,9 +4,12 @@
use js::jsapi::{JSContext, JSBool};
use js::jsapi::{JS_IsExceptionPending};
use js::jsapi::{JS_ReportErrorNumber, JSErrorFormatString, struct_JSErrorFormatString, JSEXN_TYPEERR};
use js::glue::{ReportError};
use libc;
use std::ptr;
#[deriving(Show)]
pub enum Error {
IndexSize,
@ -44,3 +47,30 @@ pub fn throw_not_in_union(cx: *JSContext, names: &'static str) -> JSBool {
});
return 0;
}
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);
});
}

View file

@ -38,7 +38,6 @@ 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};
@ -369,33 +368,6 @@ 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;