aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/interface.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-05-15 01:19:52 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-05-16 15:22:07 +0200
commit4af3e9028d28a5d47d9738afc70804665fd6075a (patch)
tree9de9e10f467e281eb0b0b7284a2f5bf14d3d1162 /components/script/dom/bindings/interface.rs
parent2c674d0397927ef6563feb70e54f46815af55600 (diff)
downloadservo-4af3e9028d28a5d47d9738afc70804665fd6075a.tar.gz
servo-4af3e9028d28a5d47d9738afc70804665fd6075a.zip
Use JS_NewStringCopyN for the representation of interface objects
This removes the need for the final null byte and we can make NonCallbackInterfaceObjectClass::new safe again I guess.
Diffstat (limited to 'components/script/dom/bindings/interface.rs')
-rw-r--r--components/script/dom/bindings/interface.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index 158dae4e075..9ce31b8bd36 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -12,10 +12,10 @@ use js::glue::UncheckedUnwrapObject;
use js::jsapi::{Class, ClassExtension, ClassSpec, GetGlobalForObjectCrossCompartment};
use js::jsapi::{HandleObject, HandleValue, JSClass, JSContext, JSFunctionSpec};
use js::jsapi::{JSNative, JSFUN_CONSTRUCTOR, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY};
-use js::jsapi::{JSPROP_RESOLVING, JSPropertySpec, JSString, JS_DefineProperty1, JS_DefineProperty2};
-use js::jsapi::{JS_AtomizeAndPinString, JS_DefineProperty4, JS_GetClass, JS_GetFunctionObject};
-use js::jsapi::{JS_GetPrototype, JS_LinkConstructorAndPrototype, JS_NewFunction, JS_NewObject};
-use js::jsapi::{JS_NewObjectWithUniqueType, JS_NewStringCopyZ, JS_DefineProperty};
+use js::jsapi::{JSPROP_RESOLVING, JSPropertySpec, JSString, JS_AtomizeAndPinString};
+use js::jsapi::{JS_DefineProperty, JS_DefineProperty1, JS_DefineProperty2, JS_DefineProperty4};
+use js::jsapi::{JS_GetClass, JS_GetFunctionObject, JS_GetPrototype, JS_LinkConstructorAndPrototype};
+use js::jsapi::{JS_NewFunction, JS_NewObject, JS_NewObjectWithUniqueType, JS_NewStringCopyN};
use js::jsapi::{MutableHandleObject, MutableHandleValue, ObjectOps, RootedObject, RootedString};
use js::jsapi::{RootedValue, Value};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UInt32Value};
@@ -87,9 +87,9 @@ unsafe extern "C" fn fun_to_string_hook(cx: *mut JSContext,
-> *mut JSString {
let js_class = JS_GetClass(obj.get());
assert!(!js_class.is_null());
- let object_class = &*(js_class as *const NonCallbackInterfaceObjectClass);
- assert!(object_class.representation.last() == Some(&0));
- let ret = JS_NewStringCopyZ(cx, object_class.representation.as_ptr() as *const libc::c_char);
+ let repr = (*(js_class as *const NonCallbackInterfaceObjectClass)).representation;
+ assert!(!repr.is_empty());
+ let ret = JS_NewStringCopyN(cx, repr.as_ptr() as *const libc::c_char, repr.len());
assert!(!ret.is_null());
ret
}
@@ -103,7 +103,7 @@ pub struct NonCallbackInterfaceObjectClass {
pub proto_id: PrototypeList::ID,
/// The prototype depth of that interface, used in the hasInstance hook.
pub proto_depth: u16,
- /// The string representation of the object (ends with '\0').
+ /// The string representation of the object.
pub representation: &'static [u8],
}
@@ -111,7 +111,7 @@ unsafe impl Sync for NonCallbackInterfaceObjectClass {}
impl NonCallbackInterfaceObjectClass {
/// Create a new `NonCallbackInterfaceObjectClass` structure.
- pub const unsafe fn new(
+ pub const fn new(
constructor_behavior: InterfaceConstructorBehavior,
string_rep: &'static [u8],
proto_id: PrototypeList::ID,