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:
minghuaw 2025-08-09 19:50:14 +08:00 committed by GitHub
parent a3e0a34802
commit ad18638534
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 49 additions and 81 deletions

View file

@ -17,6 +17,7 @@ use headers::{HeaderMapExt, ReferrerPolicy as ReferrerPolicyHeader};
use html5ever::local_name;
use hyper_serde::Serde;
use indexmap::{IndexMap, IndexSet};
use js::conversions::jsstr_to_string;
use js::jsapi::{
CompileModule1, ExceptionStackBehavior, FinishDynamicModuleImport, GetModuleRequestSpecifier,
GetModuleResolveHook, GetRequestedModuleSpecifier, GetRequestedModulesCount,
@ -50,7 +51,6 @@ use uuid::Uuid;
use crate::document_loader::LoadType;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
use crate::dom::bindings::conversions::jsstring_to_str;
use crate::dom::bindings::error::{
Error, ErrorToJsval, report_pending_exception, throw_dom_exception,
};
@ -630,11 +630,10 @@ impl ModuleTree {
let length = GetRequestedModulesCount(*cx, module_object);
for index in 0..length {
let specifier = jsstring_to_str(
*cx,
ptr::NonNull::new(GetRequestedModuleSpecifier(*cx, module_object, index))
.unwrap(),
);
let jsstr =
std::ptr::NonNull::new(GetRequestedModuleSpecifier(*cx, module_object, index))
.unwrap();
let specifier = DOMString::from_string(jsstr_to_string(*cx, jsstr));
rooted!(in(*cx) let mut private = UndefinedValue());
JS_GetModulePrivate(module_object.get(), private.handle_mut());
@ -1519,10 +1518,8 @@ fn fetch_an_import_module_script_graph(
// Step 1.
let cx = GlobalScope::get_cx();
let specifier = unsafe {
jsstring_to_str(
*cx,
ptr::NonNull::new(GetModuleRequestSpecifier(*cx, module_request)).unwrap(),
)
let jsstr = std::ptr::NonNull::new(GetModuleRequestSpecifier(*cx, module_request)).unwrap();
DOMString::from_string(jsstr_to_string(*cx, jsstr))
};
let mut options = ScriptFetchOptions::default_classic_script(global);
let module_data = unsafe { module_script_from_reference_private(&reference_private) };
@ -1594,10 +1591,8 @@ unsafe extern "C" fn HostResolveImportedModule(
// Step 5.
let module_data = module_script_from_reference_private(&reference_private);
let specifier = jsstring_to_str(
cx,
ptr::NonNull::new(GetModuleRequestSpecifier(cx, specifier)).unwrap(),
);
let jsstr = std::ptr::NonNull::new(GetModuleRequestSpecifier(cx, specifier)).unwrap();
let specifier = DOMString::from_string(jsstr_to_string(cx, jsstr));
let url =
ModuleTree::resolve_module_specifier(&global_scope, module_data, specifier, CanGc::note());