diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 3 | ||||
-rw-r--r-- | components/script/dom/bindings/proxyhandler.rs | 34 | ||||
-rw-r--r-- | components/script/dom/bindings/str.rs | 2 |
3 files changed, 14 insertions, 25 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 2241f49aad5..03efd2b59f5 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -3901,8 +3901,7 @@ class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod): JSString* jsresult; return xpc_qsStringToJsstring(cx, result, &jsresult) ? jsresult : NULL;""" - return """let s = "%s".to_c_str(); - _obj_toString(cx, s.as_ptr())""" % self.descriptor.name + return """_obj_toString(cx, "%s")""" % self.descriptor.name def definition_body(self): return CGGeneric(self.getBody()) diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index d6a4726ba4d..bbfb7118b76 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -6,8 +6,8 @@ use dom::bindings::conversions::is_dom_proxy; use dom::bindings::utils::delete_property_by_id; -use js::jsapi::{JSContext, jsid, JSPropertyDescriptor, JSObject, JSString, jschar}; -use js::jsapi::{JS_GetPropertyDescriptorById, JS_NewUCString, JS_malloc, JS_free}; +use js::jsapi::{JSContext, jsid, JSPropertyDescriptor, JSObject, JSString}; +use js::jsapi::{JS_GetPropertyDescriptorById, JS_NewStringCopyN}; use js::jsapi::{JS_DefinePropertyById, JS_NewObjectWithGivenProto}; use js::jsapi::{JS_ReportErrorFlagsAndNumber, JS_StrictPropertyStub}; use js::jsapi::{JSREPORT_WARNING, JSREPORT_STRICT, JSREPORT_STRICT_MODE_ERROR}; @@ -21,8 +21,6 @@ use js::{JSPROP_GETTER, JSPROP_ENUMERATE, JSPROP_READONLY, JSRESOLVE_QUALIFIED}; use libc; use std::mem; use std::ptr; -use std::string; -use std::mem::size_of; static JSPROXYSLOT_EXPANDO: u32 = 0; @@ -82,27 +80,17 @@ pub unsafe extern fn delete_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, return delete_property_by_id(cx, expando, id, &mut *bp); } -pub fn _obj_toString(cx: *mut JSContext, className: *const libc::c_char) -> *mut JSString { - unsafe { - let name = string::raw::from_buf(className as *const i8 as *const u8); - let nchars = "[object ]".len() + name.len(); - let chars: *mut jschar = JS_malloc(cx, (nchars + 1) as libc::size_t * (size_of::<jschar>() as libc::size_t)) as *mut jschar; - if chars.is_null() { - return ptr::null_mut(); - } +pub fn _obj_toString(cx: *mut JSContext, name: &str) -> *mut JSString { + unsafe { + let result = format!("[object {}]", name); - let result = format!("[object {}]", name); - let result = result.as_slice(); - for (i, c) in result.chars().enumerate() { - *chars.offset(i as int) = c as jschar; - } - *chars.offset(nchars as int) = 0; - let jsstr = JS_NewUCString(cx, chars, nchars as libc::size_t); - if jsstr.is_null() { - JS_free(cx, chars as *mut libc::c_void); + let chars = result.as_ptr() as *const libc::c_char; + let length = result.len() as libc::size_t; + + let string = JS_NewStringCopyN(cx, chars, length); + assert!(string.is_not_null()); + return string; } - jsstr - } } pub fn GetExpandoObject(obj: *mut JSObject) -> *mut JSObject { diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 0882b3538e2..19cf7bc2084 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#![deny(missing_docs)] + //! The `ByteString` struct. use std::hash::{Hash, sip}; |