aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/constant.rs
diff options
context:
space:
mode:
authorBumsoo Kim <8664183+abumsoo@users.noreply.github.com>2024-07-11 00:18:54 -0400
committerGitHub <noreply@github.com>2024-07-11 04:18:54 +0000
commitc6cb7ee98169ce1acb3b43b5071385d8f4f4adc2 (patch)
treeae9f86bb7bbac4b2200c88c5a080a58bdd5b0843 /components/script/dom/bindings/constant.rs
parent3e163bfcdbe093470dbdea5d2d9b18a7a0c31239 (diff)
downloadservo-c6cb7ee98169ce1acb3b43b5071385d8f4f4adc2.tar.gz
servo-c6cb7ee98169ce1acb3b43b5071385d8f4f4adc2.zip
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>
Diffstat (limited to 'components/script/dom/bindings/constant.rs')
-rw-r--r--components/script/dom/bindings/constant.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/components/script/dom/bindings/constant.rs b/components/script/dom/bindings/constant.rs
index cfb8373ad8e..ced01176aea 100644
--- a/components/script/dom/bindings/constant.rs
+++ b/components/script/dom/bindings/constant.rs
@@ -4,6 +4,8 @@
//! WebIDL constants.
+use std::ffi::CStr;
+
use js::jsapi::{JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UInt32Value};
use js::rust::wrappers::JS_DefineProperty;
@@ -15,7 +17,7 @@ use crate::script_runtime::JSContext;
#[derive(Clone)]
pub struct ConstantSpec {
/// name of the constant.
- pub name: &'static [u8],
+ pub name: &'static CStr,
/// value of the constant.
pub value: ConstantVal,
}
@@ -58,7 +60,7 @@ pub fn define_constants(cx: JSContext, obj: HandleObject, constants: &[ConstantS
assert!(JS_DefineProperty(
*cx,
obj,
- spec.name.as_ptr() as *const libc::c_char,
+ spec.name.as_ptr(),
value.handle(),
(JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) as u32
));