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

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