mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
script: Use the new C string literal in the DOM bindings (#32741)
* simple conversion to cstrings using as_ptr() Signed-off-by: Bum Kim <bumcrystlbum@gmail.com> * replaced byte strings with c strings using new helper functions Signed-off-by: Bum Kim <bumcrystlbum@gmail.com> * changed &[u8] type parameters to &CStr Signed-off-by: Bum Kim <bumcrystlbum@gmail.com> --------- Signed-off-by: Bum Kim <bumcrystlbum@gmail.com>
This commit is contained in:
parent
3e163bfcdb
commit
c6cb7ee981
6 changed files with 60 additions and 63 deletions
|
@ -5,6 +5,7 @@
|
|||
//! Machinery to initialise interface prototype objects and interface objects.
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::ffi::CStr;
|
||||
use std::ptr;
|
||||
|
||||
use js::error::throw_type_error;
|
||||
|
@ -215,7 +216,7 @@ pub fn create_callback_interface_object(
|
|||
cx: SafeJSContext,
|
||||
global: HandleObject,
|
||||
constants: &[Guard<&[ConstantSpec]>],
|
||||
name: &[u8],
|
||||
name: &CStr,
|
||||
mut rval: MutableHandleObject,
|
||||
) {
|
||||
assert!(!constants.is_empty());
|
||||
|
@ -238,7 +239,7 @@ pub fn create_interface_prototype_object(
|
|||
regular_methods: &[Guard<&'static [JSFunctionSpec]>],
|
||||
regular_properties: &[Guard<&'static [JSPropertySpec]>],
|
||||
constants: &[Guard<&[ConstantSpec]>],
|
||||
unscopable_names: &[&[u8]],
|
||||
unscopable_names: &[&CStr],
|
||||
rval: MutableHandleObject,
|
||||
) {
|
||||
create_object(
|
||||
|
@ -284,9 +285,9 @@ pub fn create_noncallback_interface_object(
|
|||
static_properties: &[Guard<&'static [JSPropertySpec]>],
|
||||
constants: &[Guard<&[ConstantSpec]>],
|
||||
interface_prototype_object: HandleObject,
|
||||
name: &[u8],
|
||||
name: &CStr,
|
||||
length: u32,
|
||||
legacy_window_alias_names: &[&[u8]],
|
||||
legacy_window_alias_names: &[&CStr],
|
||||
rval: MutableHandleObject,
|
||||
) {
|
||||
create_object(
|
||||
|
@ -321,22 +322,14 @@ pub fn create_noncallback_interface_object(
|
|||
pub fn create_named_constructors(
|
||||
cx: SafeJSContext,
|
||||
global: HandleObject,
|
||||
named_constructors: &[(ConstructorClassHook, &[u8], u32)],
|
||||
named_constructors: &[(ConstructorClassHook, &CStr, u32)],
|
||||
interface_prototype_object: HandleObject,
|
||||
) {
|
||||
rooted!(in(*cx) let mut constructor = ptr::null_mut::<JSObject>());
|
||||
|
||||
for &(native, name, arity) in named_constructors {
|
||||
assert_eq!(*name.last().unwrap(), b'\0');
|
||||
|
||||
unsafe {
|
||||
let fun = JS_NewFunction(
|
||||
*cx,
|
||||
Some(native),
|
||||
arity,
|
||||
JSFUN_CONSTRUCTOR,
|
||||
name.as_ptr() as *const libc::c_char,
|
||||
);
|
||||
let fun = JS_NewFunction(*cx, Some(native), arity, JSFUN_CONSTRUCTOR, name.as_ptr());
|
||||
assert!(!fun.is_null());
|
||||
constructor.set(JS_GetFunctionObject(fun));
|
||||
assert!(!constructor.is_null());
|
||||
|
@ -436,15 +429,14 @@ pub fn is_exposed_in(object: HandleObject, globals: Globals) -> bool {
|
|||
pub fn define_on_global_object(
|
||||
cx: SafeJSContext,
|
||||
global: HandleObject,
|
||||
name: &[u8],
|
||||
name: &CStr,
|
||||
obj: HandleObject,
|
||||
) {
|
||||
assert_eq!(*name.last().unwrap(), b'\0');
|
||||
unsafe {
|
||||
assert!(JS_DefineProperty3(
|
||||
*cx,
|
||||
global,
|
||||
name.as_ptr() as *const libc::c_char,
|
||||
name.as_ptr(),
|
||||
obj,
|
||||
JSPROP_RESOLVING
|
||||
));
|
||||
|
@ -477,18 +469,17 @@ unsafe extern "C" fn fun_to_string_hook(
|
|||
ret
|
||||
}
|
||||
|
||||
fn create_unscopable_object(cx: SafeJSContext, names: &[&[u8]], mut rval: MutableHandleObject) {
|
||||
fn create_unscopable_object(cx: SafeJSContext, names: &[&CStr], mut rval: MutableHandleObject) {
|
||||
assert!(!names.is_empty());
|
||||
assert!(rval.is_null());
|
||||
unsafe {
|
||||
rval.set(JS_NewPlainObject(*cx));
|
||||
assert!(!rval.is_null());
|
||||
for &name in names {
|
||||
assert_eq!(*name.last().unwrap(), b'\0');
|
||||
assert!(JS_DefineProperty(
|
||||
*cx,
|
||||
rval.handle(),
|
||||
name.as_ptr() as *const libc::c_char,
|
||||
name.as_ptr(),
|
||||
HandleValue::from_raw(TrueHandleValue),
|
||||
JSPROP_READONLY as u32,
|
||||
));
|
||||
|
@ -496,10 +487,9 @@ fn create_unscopable_object(cx: SafeJSContext, names: &[&[u8]], mut rval: Mutabl
|
|||
}
|
||||
}
|
||||
|
||||
fn define_name(cx: SafeJSContext, obj: HandleObject, name: &[u8]) {
|
||||
assert_eq!(*name.last().unwrap(), b'\0');
|
||||
fn define_name(cx: SafeJSContext, obj: HandleObject, name: &CStr) {
|
||||
unsafe {
|
||||
rooted!(in(*cx) let name = JS_AtomizeAndPinString(*cx, name.as_ptr() as *const libc::c_char));
|
||||
rooted!(in(*cx) let name = JS_AtomizeAndPinString(*cx, name.as_ptr()));
|
||||
assert!(!name.is_null());
|
||||
assert!(JS_DefineProperty4(
|
||||
*cx,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue