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:
Bumsoo Kim 2024-07-06 16:14:15 -04:00 committed by GitHub
parent 59d0f1fe1a
commit 141a594e23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 29 additions and 29 deletions

View file

@ -69,7 +69,7 @@ impl NonCallbackInterfaceObjectClass {
) -> NonCallbackInterfaceObjectClass { ) -> NonCallbackInterfaceObjectClass {
NonCallbackInterfaceObjectClass { NonCallbackInterfaceObjectClass {
class: JSClass { class: JSClass {
name: b"Function\0" as *const _ as *const libc::c_char, name: c"Function".as_ptr(),
flags: 0, flags: 0,
cOps: &constructor_behavior.0, cOps: &constructor_behavior.0,
spec: 0 as *const _, spec: 0 as *const _,
@ -344,7 +344,7 @@ pub fn create_named_constructors(
assert!(JS_DefineProperty3( assert!(JS_DefineProperty3(
*cx, *cx,
constructor.handle(), constructor.handle(),
b"prototype\0".as_ptr() as *const libc::c_char, c"prototype".as_ptr(),
interface_prototype_object, interface_prototype_object,
(JSPROP_PERMANENT | JSPROP_READONLY) as u32 (JSPROP_PERMANENT | JSPROP_READONLY) as u32
)); ));
@ -504,7 +504,7 @@ fn define_name(cx: SafeJSContext, obj: HandleObject, name: &[u8]) {
assert!(JS_DefineProperty4( assert!(JS_DefineProperty4(
*cx, *cx,
obj, obj,
b"name\0".as_ptr() as *const libc::c_char, c"name".as_ptr(),
name.handle(), name.handle(),
JSPROP_READONLY as u32 JSPROP_READONLY as u32
)); ));
@ -516,7 +516,7 @@ fn define_length(cx: SafeJSContext, obj: HandleObject, length: i32) {
assert!(JS_DefineProperty5( assert!(JS_DefineProperty5(
*cx, *cx,
obj, obj,
b"length\0".as_ptr() as *const libc::c_char, c"length".as_ptr(),
length, length,
JSPROP_READONLY as u32 JSPROP_READONLY as u32
)); ));
@ -666,7 +666,7 @@ pub fn get_desired_proto(
if !JS_GetProperty( if !JS_GetProperty(
*cx, *cx,
original_new_target.handle().into(), original_new_target.handle().into(),
b"prototype\0".as_ptr() as *const libc::c_char, c"prototype".as_ptr(),
proto_val.handle_mut().into(), proto_val.handle_mut().into(),
) { ) {
return Err(()); return Err(());

View file

@ -697,7 +697,7 @@ unsafe fn append_cross_origin_allowlisted_prop_keys(
) { ) {
rooted!(in(*cx) let mut id: jsid); 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); rooted!(in(*cx) let rooted = jsstring);
RUST_INTERNED_STRING_TO_JSID(*cx, rooted.handle().get(), id.handle_mut()); RUST_INTERNED_STRING_TO_JSID(*cx, rooted.handle().get(), id.handle_mut());
AppendToIdVector(props, id.handle()); AppendToIdVector(props, id.handle());

View file

@ -4,6 +4,7 @@
use std::cell::Cell; use std::cell::Cell;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::ffi::CStr;
use std::rc::Rc; use std::rc::Rc;
use std::{mem, ptr}; use std::{mem, ptr};
@ -143,7 +144,7 @@ impl CustomElementRegistry {
if !JS_GetProperty( if !JS_GetProperty(
*GlobalScope::get_cx(), *GlobalScope::get_cx(),
constructor, constructor,
b"prototype\0".as_ptr() as *const _, c"prototype".as_ptr(),
prototype, prototype,
) { ) {
return Err(Error::JSFailed); return Err(Error::JSFailed);
@ -168,10 +169,10 @@ impl CustomElementRegistry {
// Step 4 // Step 4
Ok(LifecycleCallbacks { Ok(LifecycleCallbacks {
connected_callback: get_callback(cx, prototype, b"connectedCallback\0")?, connected_callback: get_callback(cx, prototype, c"connectedCallback")?,
disconnected_callback: get_callback(cx, prototype, b"disconnectedCallback\0")?, disconnected_callback: get_callback(cx, prototype, c"disconnectedCallback")?,
adopted_callback: get_callback(cx, prototype, b"adoptedCallback\0")?, adopted_callback: get_callback(cx, prototype, c"adoptedCallback")?,
attribute_changed_callback: get_callback(cx, prototype, b"attributeChangedCallback\0")?, attribute_changed_callback: get_callback(cx, prototype, c"attributeChangedCallback")?,
form_associated_callback: None, form_associated_callback: None,
form_disabled_callback: None, form_disabled_callback: None,
@ -191,11 +192,11 @@ impl CustomElementRegistry {
let cx = self.window.get_cx(); let cx = self.window.get_cx();
callbacks.form_associated_callback = callbacks.form_associated_callback =
get_callback(cx, prototype, b"formAssociatedCallback\0")?; get_callback(cx, prototype, c"formAssociatedCallback")?;
callbacks.form_reset_callback = get_callback(cx, prototype, b"formResetCallback\0")?; callbacks.form_reset_callback = get_callback(cx, prototype, c"formResetCallback")?;
callbacks.form_disabled_callback = get_callback(cx, prototype, b"formDisabledCallback\0")?; callbacks.form_disabled_callback = get_callback(cx, prototype, c"formDisabledCallback")?;
callbacks.form_state_restore_callback = callbacks.form_state_restore_callback =
get_callback(cx, prototype, b"formStateRestoreCallback\0")?; get_callback(cx, prototype, c"formStateRestoreCallback")?;
Ok(()) Ok(())
} }
@ -208,7 +209,7 @@ impl CustomElementRegistry {
!JS_GetProperty( !JS_GetProperty(
*cx, *cx,
constructor, constructor,
b"observedAttributes\0".as_ptr() as *const _, c"observedAttributes".as_ptr(),
observed_attributes.handle_mut(), observed_attributes.handle_mut(),
) )
} { } {
@ -243,7 +244,7 @@ impl CustomElementRegistry {
!JS_GetProperty( !JS_GetProperty(
*cx, *cx,
constructor, constructor,
b"formAssociated\0".as_ptr() as *const _, c"formAssociated".as_ptr(),
form_associated_value.handle_mut(), form_associated_value.handle_mut(),
) )
} { } {
@ -273,7 +274,7 @@ impl CustomElementRegistry {
!JS_GetProperty( !JS_GetProperty(
*cx, *cx,
constructor, constructor,
b"disabledFeatures\0".as_ptr() as *const _, c"disabledFeatures".as_ptr(),
disabled_features.handle_mut(), disabled_features.handle_mut(),
) )
} { } {
@ -305,7 +306,7 @@ impl CustomElementRegistry {
fn get_callback( fn get_callback(
cx: JSContext, cx: JSContext,
prototype: HandleObject, prototype: HandleObject,
name: &[u8], name: &CStr,
) -> Fallible<Option<Rc<Function>>> { ) -> Fallible<Option<Rc<Function>>> {
rooted!(in(*cx) let mut callback = UndefinedValue()); rooted!(in(*cx) let mut callback = UndefinedValue());
unsafe { unsafe {

View file

@ -519,13 +519,13 @@ impl EventTarget {
let name = CString::new(format!("on{}", &**ty)).unwrap(); let name = CString::new(format!("on{}", &**ty)).unwrap();
// Step 3.9, subsection ParameterList // 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] = &[ const ERROR_ARG_NAMES: &[*const c_char] = &[
b"event\0" as *const u8 as *const c_char, c"event".as_ptr(),
b"source\0" as *const u8 as *const c_char, c"source".as_ptr(),
b"lineno\0" as *const u8 as *const c_char, c"lineno".as_ptr(),
b"colno\0" as *const u8 as *const c_char, c"colno".as_ptr(),
b"error\0" as *const u8 as *const c_char, c"error".as_ptr(),
]; ];
let is_error = ty == &atom!("error") && self.is::<Window>(); let is_error = ty == &atom!("error") && self.is::<Window>();
let args = if is_error { ERROR_ARG_NAMES } else { ARG_NAMES }; let args = if is_error { ERROR_ARG_NAMES } else { ARG_NAMES };

View file

@ -34,7 +34,6 @@ use crate::dom::bindings::conversions::root_from_object;
use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{DomObject, MutDomObject, Reflector}; use crate::dom::bindings::reflector::{DomObject, MutDomObject, Reflector};
use crate::dom::bindings::settings_stack::AutoEntryScript; use crate::dom::bindings::settings_stack::AutoEntryScript;
use crate::dom::bindings::utils::AsCCharPtrPtr;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::promisenativehandler::PromiseNativeHandler; use crate::dom::promisenativehandler::PromiseNativeHandler;
use crate::realms::{enter_realm, AlreadyInRealm, InRealm}; use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
@ -67,7 +66,7 @@ impl PromiseHelper for Rc<Promise> {
assert!(AddRawValueRoot( assert!(AddRawValueRoot(
*cx, *cx,
self.permanent_js_root.get_unsafe(), self.permanent_js_root.get_unsafe(),
b"Promise::root\0".as_c_char_ptr() c"Promise::root".as_ptr(),
)); ));
} }
} }

View file

@ -215,13 +215,13 @@ unsafe extern "C" fn is_extensible(
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe extern "C" fn class_name(_cx: *mut JSContext, _proxy: HandleObject) -> *const libc::c_char { 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 // Maybe this should be a DOMJSClass. See https://bugzilla.mozilla.org/show_bug.cgi?id=787070
#[allow(unsafe_code)] #[allow(unsafe_code)]
static CLASS: JSClass = JSClass { 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 | flags: JSClass_NON_NATIVE |
JSCLASS_IS_PROXY | JSCLASS_IS_PROXY |
JSCLASS_DELAY_METADATA_BUILDER | JSCLASS_DELAY_METADATA_BUILDER |