mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
script_bindings: Remove jsstring_to_str
(#38527)
This PR removes `jsstring_to_str`, which is replaced with
`jsstr_to_string`, and updates `mozjs` to
6f3dcb99a7
.
Given that servo now always replaces unpaired surrogate since
https://github.com/servo/servo/pull/35381, the internal conversion
function `jsstring_to_str` is functionally the same as `jsstr_to_string`
from `mozjs`. This PR removes `jsstring_to_str` and replaces with
`jsstr_to_string` with conversions to `DOMString` where necessary.
Testing: Passes all unit test. No regression was found in WPT test (see
try run: https://github.com/minghuaw/servo/actions/runs/16821156583)
---------
Signed-off-by: minghuaw <wuminghua7@huawei.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
a3e0a34802
commit
ad18638534
10 changed files with 49 additions and 81 deletions
|
@ -10,6 +10,7 @@ use devtools_traits::{
|
|||
ConsoleMessage, ConsoleMessageArgument, ConsoleMessageBuilder, LogLevel,
|
||||
ScriptToDevtoolsControlMsg, StackFrame,
|
||||
};
|
||||
use js::conversions::jsstr_to_string;
|
||||
use js::jsapi::{self, ESClass, PropertyDescriptor};
|
||||
use js::jsval::{Int32Value, UndefinedValue};
|
||||
use js::rust::wrappers::{
|
||||
|
@ -22,7 +23,6 @@ use js::rust::{
|
|||
use script_bindings::conversions::get_dom_class;
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::ConsoleBinding::consoleMethods;
|
||||
use crate::dom::bindings::conversions::jsstring_to_str;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -127,7 +127,7 @@ unsafe fn handle_value_to_string(cx: *mut jsapi::JSContext, value: HandleValue)
|
|||
match std::ptr::NonNull::new(JS_ValueToSource(cx, value)) {
|
||||
Some(js_str) => {
|
||||
js_string.set(js_str.as_ptr());
|
||||
jsstring_to_str(cx, js_str)
|
||||
DOMString::from_string(jsstr_to_string(cx, js_str))
|
||||
},
|
||||
None => "<error converting value to string>".into(),
|
||||
}
|
||||
|
@ -140,8 +140,8 @@ fn console_argument_from_handle_value(
|
|||
) -> ConsoleMessageArgument {
|
||||
if handle_value.is_string() {
|
||||
let js_string = ptr::NonNull::new(handle_value.to_string()).unwrap();
|
||||
let dom_string = unsafe { jsstring_to_str(*cx, js_string) };
|
||||
return ConsoleMessageArgument::String(dom_string.into());
|
||||
let dom_string = unsafe { jsstr_to_string(*cx, js_string) };
|
||||
return ConsoleMessageArgument::String(dom_string);
|
||||
}
|
||||
|
||||
if handle_value.is_int32() {
|
||||
|
@ -164,7 +164,8 @@ fn stringify_handle_value(message: HandleValue) -> DOMString {
|
|||
let cx = GlobalScope::get_cx();
|
||||
unsafe {
|
||||
if message.is_string() {
|
||||
return jsstring_to_str(*cx, std::ptr::NonNull::new(message.to_string()).unwrap());
|
||||
let jsstr = std::ptr::NonNull::new(message.to_string()).unwrap();
|
||||
return DOMString::from_string(jsstr_to_string(*cx, jsstr));
|
||||
}
|
||||
unsafe fn stringify_object_from_handle_value(
|
||||
cx: *mut jsapi::JSContext,
|
||||
|
@ -297,7 +298,7 @@ fn maybe_stringify_dom_object(cx: JSContext, value: HandleValue) -> Option<DOMSt
|
|||
return Some("<error converting DOM object to string>".into());
|
||||
};
|
||||
let class_name = unsafe {
|
||||
jsstring_to_str(*cx, class_name)
|
||||
jsstr_to_string(*cx, class_name)
|
||||
.replace("[object ", "")
|
||||
.replace("]", "")
|
||||
};
|
||||
|
@ -493,7 +494,7 @@ fn get_js_stack(cx: *mut jsapi::JSContext) -> Vec<StackFrame> {
|
|||
);
|
||||
}
|
||||
let function_name = if let Some(nonnull_result) = ptr::NonNull::new(*result) {
|
||||
unsafe { jsstring_to_str(cx, nonnull_result) }.into()
|
||||
unsafe { jsstr_to_string(cx, nonnull_result) }
|
||||
} else {
|
||||
"<anonymous>".into()
|
||||
};
|
||||
|
@ -510,7 +511,7 @@ fn get_js_stack(cx: *mut jsapi::JSContext) -> Vec<StackFrame> {
|
|||
);
|
||||
}
|
||||
let filename = if let Some(nonnull_result) = ptr::NonNull::new(*result) {
|
||||
unsafe { jsstring_to_str(cx, nonnull_result) }.into()
|
||||
unsafe { jsstr_to_string(cx, nonnull_result) }
|
||||
} else {
|
||||
"<anonymous>".into()
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue