diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2016-05-15 01:19:52 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2016-05-16 15:22:07 +0200 |
commit | 4af3e9028d28a5d47d9738afc70804665fd6075a (patch) | |
tree | 9de9e10f467e281eb0b0b7284a2f5bf14d3d1162 | |
parent | 2c674d0397927ef6563feb70e54f46815af55600 (diff) | |
download | servo-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.
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 7 | ||||
-rw-r--r-- | components/script/dom/bindings/interface.rs | 18 |
2 files changed, 12 insertions, 13 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 1e26bc68c2f..2b169ba7f8c 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1993,17 +1993,16 @@ class CGInterfaceObjectJSClass(CGThing): args = { "constructorBehavior": constructorBehavior, "id": name, - "representation": str_to_const_array("function %s() {\\n [native code]\\n}" % name), + "representation": 'b"function %s() {\\n [native code]\\n}"' % name, "depth": self.descriptor.prototypeDepth } return """\ -static InterfaceObjectClass: NonCallbackInterfaceObjectClass = unsafe { +static InterfaceObjectClass: NonCallbackInterfaceObjectClass = NonCallbackInterfaceObjectClass::new( %(constructorBehavior)s, %(representation)s, PrototypeList::ID::%(id)s, - %(depth)s) -}; + %(depth)s); """ % args 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, |