diff options
author | Josh Matthews <josh@joshmatthews.net> | 2015-01-15 13:26:44 -0500 |
---|---|---|
committer | Glenn Watson <gw@intuitionlibrary.com> | 2015-01-28 10:16:49 +1000 |
commit | 95fc29fa0db21959df99d81cdbb9561226321d2f (patch) | |
tree | a48e171165ec155062ef13c550b2c0f72d127425 /components/script/dom/bindings/error.rs | |
parent | ff8cbff81016c157373c1675f3eee69dd70ae544 (diff) | |
download | servo-95fc29fa0db21959df99d81cdbb9561226321d2f.tar.gz servo-95fc29fa0db21959df99d81cdbb9561226321d2f.zip |
Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev.
Diffstat (limited to 'components/script/dom/bindings/error.rs')
-rw-r--r-- | components/script/dom/bindings/error.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index 2d02dc08ee9..71ac1837afb 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -18,10 +18,11 @@ use js::glue::{ReportError}; use js::rust::with_compartment; use libc; +use std::ffi::CString; use std::ptr; /// DOM exceptions that can be thrown by a native DOM method. -#[deriving(Show, Clone)] +#[derive(Show, Clone)] pub enum Error { /// IndexSizeError IndexSize, @@ -95,14 +96,13 @@ pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) { pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) -> JSBool { assert!(unsafe { JS_IsExceptionPending(cx) } == 0); let message = format!("argument could not be converted to any of: {}", names); - message.with_c_str(|string| { - unsafe { ReportError(cx, string) }; - }); + let string = CString::from_slice(message.as_bytes()); + unsafe { ReportError(cx, string.as_ptr()) }; return 0; } /// Format string used to throw `TypeError`s. -static ERROR_FORMAT_STRING_STRING: [libc::c_char, ..4] = [ +const ERROR_FORMAT_STRING_STRING: [libc::c_char; 4] = [ '{' as libc::c_char, '0' as libc::c_char, '}' as libc::c_char, @@ -110,7 +110,7 @@ static ERROR_FORMAT_STRING_STRING: [libc::c_char, ..4] = [ ]; /// Format string struct used to throw `TypeError`s. -static ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString { +const ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString { format: &ERROR_FORMAT_STRING_STRING as *const libc::c_char, argCount: 1, exnType: JSEXN_TYPEERR as i16, @@ -127,8 +127,12 @@ unsafe extern fn get_error_message(_user_ref: *mut libc::c_void, /// Throw a `TypeError` with the given message. pub fn throw_type_error(cx: *mut JSContext, error: &str) { - let error = error.to_c_str(); + let error = CString::from_slice(error.as_bytes()); unsafe { - JS_ReportErrorNumber(cx, Some(get_error_message), ptr::null_mut(), 0, error.as_ptr()); + JS_ReportErrorNumber(cx, + Some(get_error_message as + unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, + libc::c_uint) -> *const JSErrorFormatString), + ptr::null_mut(), 0, error.as_ptr()); } } |