mirror of
https://github.com/servo/servo.git
synced 2025-10-17 08:49:21 +01:00
Move ThrowTypeError to error.rs.
This commit is contained in:
parent
bfde816da0
commit
7ff9fff421
3 changed files with 32 additions and 30 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue