mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Replace null-byte terminated string literals with C-string literals (#32716)
* simple conversion from byte string to c-string Signed-off-by: Bum Kim <bumcrystlbum@gmail.com> * convert byte strings to c-strings to c_char ptr Signed-off-by: Bum Kim <bumcrystlbum@gmail.com> --------- Signed-off-by: Bum Kim <bumcrystlbum@gmail.com>
This commit is contained in:
parent
59d0f1fe1a
commit
141a594e23
6 changed files with 29 additions and 29 deletions
|
@ -69,7 +69,7 @@ impl NonCallbackInterfaceObjectClass {
|
|||
) -> NonCallbackInterfaceObjectClass {
|
||||
NonCallbackInterfaceObjectClass {
|
||||
class: JSClass {
|
||||
name: b"Function\0" as *const _ as *const libc::c_char,
|
||||
name: c"Function".as_ptr(),
|
||||
flags: 0,
|
||||
cOps: &constructor_behavior.0,
|
||||
spec: 0 as *const _,
|
||||
|
@ -344,7 +344,7 @@ pub fn create_named_constructors(
|
|||
assert!(JS_DefineProperty3(
|
||||
*cx,
|
||||
constructor.handle(),
|
||||
b"prototype\0".as_ptr() as *const libc::c_char,
|
||||
c"prototype".as_ptr(),
|
||||
interface_prototype_object,
|
||||
(JSPROP_PERMANENT | JSPROP_READONLY) as u32
|
||||
));
|
||||
|
@ -504,7 +504,7 @@ fn define_name(cx: SafeJSContext, obj: HandleObject, name: &[u8]) {
|
|||
assert!(JS_DefineProperty4(
|
||||
*cx,
|
||||
obj,
|
||||
b"name\0".as_ptr() as *const libc::c_char,
|
||||
c"name".as_ptr(),
|
||||
name.handle(),
|
||||
JSPROP_READONLY as u32
|
||||
));
|
||||
|
@ -516,7 +516,7 @@ fn define_length(cx: SafeJSContext, obj: HandleObject, length: i32) {
|
|||
assert!(JS_DefineProperty5(
|
||||
*cx,
|
||||
obj,
|
||||
b"length\0".as_ptr() as *const libc::c_char,
|
||||
c"length".as_ptr(),
|
||||
length,
|
||||
JSPROP_READONLY as u32
|
||||
));
|
||||
|
@ -666,7 +666,7 @@ pub fn get_desired_proto(
|
|||
if !JS_GetProperty(
|
||||
*cx,
|
||||
original_new_target.handle().into(),
|
||||
b"prototype\0".as_ptr() as *const libc::c_char,
|
||||
c"prototype".as_ptr(),
|
||||
proto_val.handle_mut().into(),
|
||||
) {
|
||||
return Err(());
|
||||
|
|
|
@ -697,7 +697,7 @@ unsafe fn append_cross_origin_allowlisted_prop_keys(
|
|||
) {
|
||||
rooted!(in(*cx) let mut id: jsid);
|
||||
|
||||
let jsstring = JS_AtomizeAndPinString(*cx, b"then\0".as_ptr() as *const c_char);
|
||||
let jsstring = JS_AtomizeAndPinString(*cx, c"then".as_ptr());
|
||||
rooted!(in(*cx) let rooted = jsstring);
|
||||
RUST_INTERNED_STRING_TO_JSID(*cx, rooted.handle().get(), id.handle_mut());
|
||||
AppendToIdVector(props, id.handle());
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::cell::Cell;
|
||||
use std::collections::VecDeque;
|
||||
use std::ffi::CStr;
|
||||
use std::rc::Rc;
|
||||
use std::{mem, ptr};
|
||||
|
||||
|
@ -143,7 +144,7 @@ impl CustomElementRegistry {
|
|||
if !JS_GetProperty(
|
||||
*GlobalScope::get_cx(),
|
||||
constructor,
|
||||
b"prototype\0".as_ptr() as *const _,
|
||||
c"prototype".as_ptr(),
|
||||
prototype,
|
||||
) {
|
||||
return Err(Error::JSFailed);
|
||||
|
@ -168,10 +169,10 @@ impl CustomElementRegistry {
|
|||
|
||||
// Step 4
|
||||
Ok(LifecycleCallbacks {
|
||||
connected_callback: get_callback(cx, prototype, b"connectedCallback\0")?,
|
||||
disconnected_callback: get_callback(cx, prototype, b"disconnectedCallback\0")?,
|
||||
adopted_callback: get_callback(cx, prototype, b"adoptedCallback\0")?,
|
||||
attribute_changed_callback: get_callback(cx, prototype, b"attributeChangedCallback\0")?,
|
||||
connected_callback: get_callback(cx, prototype, c"connectedCallback")?,
|
||||
disconnected_callback: get_callback(cx, prototype, c"disconnectedCallback")?,
|
||||
adopted_callback: get_callback(cx, prototype, c"adoptedCallback")?,
|
||||
attribute_changed_callback: get_callback(cx, prototype, c"attributeChangedCallback")?,
|
||||
|
||||
form_associated_callback: None,
|
||||
form_disabled_callback: None,
|
||||
|
@ -191,11 +192,11 @@ impl CustomElementRegistry {
|
|||
let cx = self.window.get_cx();
|
||||
|
||||
callbacks.form_associated_callback =
|
||||
get_callback(cx, prototype, b"formAssociatedCallback\0")?;
|
||||
callbacks.form_reset_callback = get_callback(cx, prototype, b"formResetCallback\0")?;
|
||||
callbacks.form_disabled_callback = get_callback(cx, prototype, b"formDisabledCallback\0")?;
|
||||
get_callback(cx, prototype, c"formAssociatedCallback")?;
|
||||
callbacks.form_reset_callback = get_callback(cx, prototype, c"formResetCallback")?;
|
||||
callbacks.form_disabled_callback = get_callback(cx, prototype, c"formDisabledCallback")?;
|
||||
callbacks.form_state_restore_callback =
|
||||
get_callback(cx, prototype, b"formStateRestoreCallback\0")?;
|
||||
get_callback(cx, prototype, c"formStateRestoreCallback")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -208,7 +209,7 @@ impl CustomElementRegistry {
|
|||
!JS_GetProperty(
|
||||
*cx,
|
||||
constructor,
|
||||
b"observedAttributes\0".as_ptr() as *const _,
|
||||
c"observedAttributes".as_ptr(),
|
||||
observed_attributes.handle_mut(),
|
||||
)
|
||||
} {
|
||||
|
@ -243,7 +244,7 @@ impl CustomElementRegistry {
|
|||
!JS_GetProperty(
|
||||
*cx,
|
||||
constructor,
|
||||
b"formAssociated\0".as_ptr() as *const _,
|
||||
c"formAssociated".as_ptr(),
|
||||
form_associated_value.handle_mut(),
|
||||
)
|
||||
} {
|
||||
|
@ -273,7 +274,7 @@ impl CustomElementRegistry {
|
|||
!JS_GetProperty(
|
||||
*cx,
|
||||
constructor,
|
||||
b"disabledFeatures\0".as_ptr() as *const _,
|
||||
c"disabledFeatures".as_ptr(),
|
||||
disabled_features.handle_mut(),
|
||||
)
|
||||
} {
|
||||
|
@ -305,7 +306,7 @@ impl CustomElementRegistry {
|
|||
fn get_callback(
|
||||
cx: JSContext,
|
||||
prototype: HandleObject,
|
||||
name: &[u8],
|
||||
name: &CStr,
|
||||
) -> Fallible<Option<Rc<Function>>> {
|
||||
rooted!(in(*cx) let mut callback = UndefinedValue());
|
||||
unsafe {
|
||||
|
|
|
@ -519,13 +519,13 @@ impl EventTarget {
|
|||
let name = CString::new(format!("on{}", &**ty)).unwrap();
|
||||
|
||||
// Step 3.9, subsection ParameterList
|
||||
const ARG_NAMES: &[*const c_char] = &[b"event\0" as *const u8 as *const c_char];
|
||||
const ARG_NAMES: &[*const c_char] = &[c"event".as_ptr()];
|
||||
const ERROR_ARG_NAMES: &[*const c_char] = &[
|
||||
b"event\0" as *const u8 as *const c_char,
|
||||
b"source\0" as *const u8 as *const c_char,
|
||||
b"lineno\0" as *const u8 as *const c_char,
|
||||
b"colno\0" as *const u8 as *const c_char,
|
||||
b"error\0" as *const u8 as *const c_char,
|
||||
c"event".as_ptr(),
|
||||
c"source".as_ptr(),
|
||||
c"lineno".as_ptr(),
|
||||
c"colno".as_ptr(),
|
||||
c"error".as_ptr(),
|
||||
];
|
||||
let is_error = ty == &atom!("error") && self.is::<Window>();
|
||||
let args = if is_error { ERROR_ARG_NAMES } else { ARG_NAMES };
|
||||
|
|
|
@ -34,7 +34,6 @@ use crate::dom::bindings::conversions::root_from_object;
|
|||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::{DomObject, MutDomObject, Reflector};
|
||||
use crate::dom::bindings::settings_stack::AutoEntryScript;
|
||||
use crate::dom::bindings::utils::AsCCharPtrPtr;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::promisenativehandler::PromiseNativeHandler;
|
||||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
|
@ -67,7 +66,7 @@ impl PromiseHelper for Rc<Promise> {
|
|||
assert!(AddRawValueRoot(
|
||||
*cx,
|
||||
self.permanent_js_root.get_unsafe(),
|
||||
b"Promise::root\0".as_c_char_ptr()
|
||||
c"Promise::root".as_ptr(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,13 +215,13 @@ unsafe extern "C" fn is_extensible(
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern "C" fn class_name(_cx: *mut JSContext, _proxy: HandleObject) -> *const libc::c_char {
|
||||
&b"WindowProperties\0" as *const _ as *const _
|
||||
c"WindowProperties".as_ptr()
|
||||
}
|
||||
|
||||
// Maybe this should be a DOMJSClass. See https://bugzilla.mozilla.org/show_bug.cgi?id=787070
|
||||
#[allow(unsafe_code)]
|
||||
static CLASS: JSClass = JSClass {
|
||||
name: b"WindowProperties\0" as *const u8 as *const libc::c_char,
|
||||
name: c"WindowProperties".as_ptr(),
|
||||
flags: JSClass_NON_NATIVE |
|
||||
JSCLASS_IS_PROXY |
|
||||
JSCLASS_DELAY_METADATA_BUILDER |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue