feat: add CanGc argument to Error::to_jsval (#36014)

* feat: add CanGc argument to Error::to_jsval

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

* feat: pass CanGc to gen_type_error

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

* fix: linting issues

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

---------

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>
This commit is contained in:
Arya Nair 2025-03-18 03:59:41 +05:30 committed by GitHub
parent 6807a6e532
commit 94d12de7fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 45 additions and 24 deletions

View file

@ -76,9 +76,9 @@ use crate::realms::{AlreadyInRealm, InRealm, enter_realm};
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
use crate::task::TaskBox;
fn gen_type_error(global: &GlobalScope, string: String) -> RethrowError {
fn gen_type_error(global: &GlobalScope, string: String, can_gc: CanGc) -> RethrowError {
rooted!(in(*GlobalScope::get_cx()) let mut thrown = UndefinedValue());
Error::Type(string).to_jsval(GlobalScope::get_cx(), global, thrown.handle_mut());
Error::Type(string).to_jsval(GlobalScope::get_cx(), global, thrown.handle_mut(), can_gc);
RethrowError(RootedTraceableBox::from_box(Heap::boxed(thrown.get())))
}
@ -463,7 +463,7 @@ impl ModuleTree {
options: ScriptFetchOptions,
mut module_script: RustMutableHandleObject,
inline: bool,
_can_gc: CanGc,
can_gc: CanGc,
) -> Result<(), RethrowError> {
let cx = GlobalScope::get_cx();
let _ac = JSAutoRealm::new(*cx, *global.reflector().get_jsobject());
@ -509,6 +509,7 @@ impl ModuleTree {
global,
module_script.handle().into_handle(),
url,
can_gc,
)
.map(|_| ())
}
@ -612,6 +613,7 @@ impl ModuleTree {
global: &GlobalScope,
module_object: HandleObject,
base_url: &ServoUrl,
can_gc: CanGc,
) -> Result<IndexSet<ServoUrl>, RethrowError> {
let cx = GlobalScope::get_cx();
let _ac = JSAutoRealm::new(*cx, *global.reflector().get_jsobject());
@ -634,7 +636,7 @@ impl ModuleTree {
if url.is_err() {
let specifier_error =
gen_type_error(global, "Wrong module specifier".to_owned());
gen_type_error(global, "Wrong module specifier".to_owned(), can_gc);
return Err(specifier_error);
}
@ -768,6 +770,7 @@ impl ModuleTree {
&global,
raw_record.handle(),
&self.url,
can_gc,
),
}
};
@ -1045,7 +1048,7 @@ impl ModuleOwner {
// Ensure any failures related to importing this dynamic module are immediately reported.
match (network_error, existing_rethrow_error) {
(Some(_), _) => unsafe {
let err = gen_type_error(&global, "Dynamic import failed".to_owned());
let err = gen_type_error(&global, "Dynamic import failed".to_owned(), can_gc);
JS_SetPendingException(*cx, err.handle(), ExceptionStackBehavior::Capture);
},
(None, Some(rethrow_error)) => unsafe {
@ -1430,7 +1433,7 @@ fn fetch_an_import_module_script_graph(
// Step 2.
if url.is_err() {
let specifier_error = gen_type_error(global, "Wrong module specifier".to_owned());
let specifier_error = gen_type_error(global, "Wrong module specifier".to_owned(), can_gc);
return Err(specifier_error);
}