CanGc fixes in errorevent.rs (#33960)

* CanGc fixes in errorevent.rs

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Allow too_many_arguments to avoid lint error

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

---------

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-22 15:38:55 +05:30 committed by GitHub
parent 575e885529
commit 7015e0fb5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 79 additions and 51 deletions

View file

@ -44,7 +44,12 @@ use crate::script_runtime::CanGc;
use crate::script_thread::Documents; use crate::script_thread::Documents;
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn handle_evaluate_js(global: &GlobalScope, eval: String, reply: IpcSender<EvaluateJSReply>) { pub fn handle_evaluate_js(
global: &GlobalScope,
eval: String,
reply: IpcSender<EvaluateJSReply>,
can_gc: CanGc,
) {
// global.get_cx() returns a valid `JSContext` pointer, so this is safe. // global.get_cx() returns a valid `JSContext` pointer, so this is safe.
let result = unsafe { let result = unsafe {
let cx = GlobalScope::get_cx(); let cx = GlobalScope::get_cx();
@ -58,6 +63,7 @@ pub fn handle_evaluate_js(global: &GlobalScope, eval: String, reply: IpcSender<E
1, 1,
ScriptFetchOptions::default_classic_script(global), ScriptFetchOptions::default_classic_script(global),
global.api_base_url(), global.api_base_url(),
can_gc,
); );
if rval.is_undefined() { if rval.is_undefined() {

View file

@ -27,7 +27,7 @@ use crate::dom::bindings::utils::AsCCharPtrPtr;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::realms::{enter_realm, InRealm}; use crate::realms::{enter_realm, InRealm};
use crate::script_runtime::JSContext; use crate::script_runtime::{CanGc, JSContext};
/// The exception handling used for a call. /// The exception handling used for a call.
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
@ -271,7 +271,7 @@ impl Drop for CallSetup {
LeaveRealm(*self.cx, self.old_realm); LeaveRealm(*self.cx, self.old_realm);
if self.handling == ExceptionHandling::Report { if self.handling == ExceptionHandling::Report {
let ar = enter_realm(&*self.exception_global); let ar = enter_realm(&*self.exception_global);
report_pending_exception(*self.cx, true, InRealm::Entered(&ar)); report_pending_exception(*self.cx, true, InRealm::Entered(&ar), CanGc::note());
} }
drop(self.incumbent_script.take()); drop(self.incumbent_script.take());
drop(self.entry_script.take().unwrap()); drop(self.entry_script.take().unwrap());

View file

@ -29,7 +29,7 @@ use crate::dom::bindings::str::USVString;
use crate::dom::domexception::{DOMErrorName, DOMException}; use crate::dom::domexception::{DOMErrorName, DOMException};
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::realms::InRealm; use crate::realms::InRealm;
use crate::script_runtime::JSContext as SafeJSContext; use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
#[cfg(feature = "js_backtrace")] #[cfg(feature = "js_backtrace")]
thread_local! { thread_local! {
@ -267,7 +267,12 @@ impl ErrorInfo {
/// ///
/// The `dispatch_event` argument is temporary and non-standard; passing false /// The `dispatch_event` argument is temporary and non-standard; passing false
/// prevents dispatching the `error` event. /// prevents dispatching the `error` event.
pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool, realm: InRealm) { pub unsafe fn report_pending_exception(
cx: *mut JSContext,
dispatch_event: bool,
realm: InRealm,
can_gc: CanGc,
) {
if !JS_IsExceptionPending(cx) { if !JS_IsExceptionPending(cx) {
return; return;
} }
@ -299,7 +304,7 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool,
} }
if dispatch_event { if dispatch_event {
GlobalScope::from_context(cx, realm).report_an_error(error_info, value.handle()); GlobalScope::from_context(cx, realm).report_an_error(error_info, value.handle(), can_gc);
} }
} }

View file

@ -168,7 +168,7 @@ fn create_html_element(
unsafe { unsafe {
let ar = enter_realm(&*global); let ar = enter_realm(&*global);
throw_dom_exception(cx, &global, error); throw_dom_exception(cx, &global, error);
report_pending_exception(*cx, true, InRealm::Entered(&ar)); report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
} }
// Step 6.1.2 // Step 6.1.2

View file

@ -844,7 +844,7 @@ pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Elemen
unsafe { unsafe {
let ar = enter_realm(&*global); let ar = enter_realm(&*global);
throw_dom_exception(cx, &global, error); throw_dom_exception(cx, &global, error);
report_pending_exception(*cx, true, InRealm::Entered(&ar)); report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
} }
return; return;

View file

@ -544,7 +544,7 @@ impl DedicatedWorkerGlobalScope {
match msg { match msg {
MixedMessage::Devtools(msg) => match msg { MixedMessage::Devtools(msg) => match msg {
DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) => { DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) => {
devtools::handle_evaluate_js(self.upcast(), string, sender) devtools::handle_evaluate_js(self.upcast(), string, sender, can_gc)
}, },
DevtoolScriptControlMsg::WantsLiveNotifications(_pipe_id, bool_val) => { DevtoolScriptControlMsg::WantsLiveNotifications(_pipe_id, bool_val) => {
devtools::handle_wants_live_notifications(self.upcast(), bool_val) devtools::handle_wants_live_notifications(self.upcast(), bool_val)
@ -583,13 +583,14 @@ impl DedicatedWorkerGlobalScope {
error_info.lineno, error_info.lineno,
error_info.column, error_info.column,
HandleValue::null(), HandleValue::null(),
CanGc::note(),
); );
let event_status = let event_status =
event.upcast::<Event>().fire(worker.upcast::<EventTarget>()); event.upcast::<Event>().fire(worker.upcast::<EventTarget>());
// Step 2. // Step 2.
if event_status == EventStatus::NotCanceled { if event_status == EventStatus::NotCanceled {
global.report_an_error(error_info, HandleValue::null()); global.report_an_error(error_info, HandleValue::null(), CanGc::note());
} }
})); }));
self.parent_sender self.parent_sender

View file

@ -3097,13 +3097,13 @@ impl Document {
} }
/// <https://drafts.csswg.org/resize-observer/#deliver-resize-loop-error-notification> /// <https://drafts.csswg.org/resize-observer/#deliver-resize-loop-error-notification>
pub(crate) fn deliver_resize_loop_error_notification(&self) { pub(crate) fn deliver_resize_loop_error_notification(&self, can_gc: CanGc) {
let global_scope = self.window.upcast::<GlobalScope>(); let global_scope = self.window.upcast::<GlobalScope>();
let error_info: ErrorInfo = crate::dom::bindings::error::ErrorInfo { let error_info: ErrorInfo = crate::dom::bindings::error::ErrorInfo {
message: "ResizeObserver loop completed with undelivered notifications.".to_string(), message: "ResizeObserver loop completed with undelivered notifications.".to_string(),
..Default::default() ..Default::default()
}; };
global_scope.report_an_error(error_info, HandleValue::null()); global_scope.report_an_error(error_info, HandleValue::null(), can_gc);
} }
pub(crate) fn status_code(&self) -> Option<u16> { pub(crate) fn status_code(&self) -> Option<u16> {

View file

@ -66,19 +66,11 @@ impl ErrorEvent {
lineno: u32, lineno: u32,
colno: u32, colno: u32,
error: HandleValue, error: HandleValue,
can_gc: CanGc,
) -> DomRoot<ErrorEvent> { ) -> DomRoot<ErrorEvent> {
Self::new_with_proto( Self::new_with_proto(
global, global, None, type_, bubbles, cancelable, message, filename, lineno, colno, error,
None, can_gc,
type_,
bubbles,
cancelable,
message,
filename,
lineno,
colno,
error,
CanGc::note(),
) )
} }

View file

@ -486,7 +486,7 @@ impl EventTarget {
&self, &self,
handler: InternalRawUncompiledHandler, handler: InternalRawUncompiledHandler,
ty: &Atom, ty: &Atom,
_can_gc: CanGc, can_gc: CanGc,
) -> Option<CommonEventHandler> { ) -> Option<CommonEventHandler> {
// Step 3.1 // Step 3.1
let element = self.downcast::<Element>(); let element = self.downcast::<Element>();
@ -568,7 +568,7 @@ impl EventTarget {
unsafe { unsafe {
let ar = enter_realm(self); let ar = enter_realm(self);
// FIXME(#13152): dispatch error event. // FIXME(#13152): dispatch error event.
report_pending_exception(*cx, false, InRealm::Entered(&ar)); report_pending_exception(*cx, false, InRealm::Entered(&ar), can_gc);
} }
return None; return None;
} }

View file

@ -2453,7 +2453,7 @@ impl GlobalScope {
} }
/// <https://html.spec.whatwg.org/multipage/#report-the-error> /// <https://html.spec.whatwg.org/multipage/#report-the-error>
pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue) { pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue, can_gc: CanGc) {
// Step 1. // Step 1.
if self.in_error_reporting_mode.get() { if self.in_error_reporting_mode.get() {
return; return;
@ -2474,6 +2474,7 @@ impl GlobalScope {
error_info.lineno, error_info.lineno,
error_info.column, error_info.column,
value, value,
can_gc,
); );
// Step 7. // Step 7.
@ -2613,6 +2614,7 @@ impl GlobalScope {
rval: MutableHandleValue, rval: MutableHandleValue,
fetch_options: ScriptFetchOptions, fetch_options: ScriptFetchOptions,
script_base_url: ServoUrl, script_base_url: ServoUrl,
can_gc: CanGc,
) -> bool { ) -> bool {
let source_code = SourceCode::Text(Rc::new(DOMString::from_string((*code).to_string()))); let source_code = SourceCode::Text(Rc::new(DOMString::from_string((*code).to_string())));
self.evaluate_script_on_global_with_result( self.evaluate_script_on_global_with_result(
@ -2622,11 +2624,13 @@ impl GlobalScope {
1, 1,
fetch_options, fetch_options,
script_base_url, script_base_url,
can_gc,
) )
} }
/// Evaluate a JS script on this global scope. /// Evaluate a JS script on this global scope.
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[allow(clippy::too_many_arguments)]
pub fn evaluate_script_on_global_with_result( pub fn evaluate_script_on_global_with_result(
&self, &self,
code: &SourceCode, code: &SourceCode,
@ -2635,6 +2639,7 @@ impl GlobalScope {
line_number: u32, line_number: u32,
fetch_options: ScriptFetchOptions, fetch_options: ScriptFetchOptions,
script_base_url: ServoUrl, script_base_url: ServoUrl,
can_gc: CanGc,
) -> bool { ) -> bool {
let metadata = profile_time::TimerMetadata { let metadata = profile_time::TimerMetadata {
url: if filename.is_empty() { url: if filename.is_empty() {
@ -2671,7 +2676,7 @@ impl GlobalScope {
if compiled_script.is_null() { if compiled_script.is_null() {
debug!("error compiling Dom string"); debug!("error compiling Dom string");
report_pending_exception(*cx, true, InRealm::Entered(&ar)); report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
return false; return false;
} }
}, },
@ -2720,7 +2725,7 @@ impl GlobalScope {
if !result { if !result {
debug!("error evaluating Dom string"); debug!("error evaluating Dom string");
report_pending_exception(*cx, true, InRealm::Entered(&ar)); report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
} }
maybe_resume_unwind(); maybe_resume_unwind();

View file

@ -159,7 +159,7 @@ impl HTMLIFrameElement {
// TODO: check according to https://w3c.github.io/webappsec-csp/#should-block-navigation-request // TODO: check according to https://w3c.github.io/webappsec-csp/#should-block-navigation-request
if ScriptThread::check_load_origin(&load_data.load_origin, &document.url().origin()) if ScriptThread::check_load_origin(&load_data.load_origin, &document.url().origin())
{ {
ScriptThread::eval_js_url(&window_proxy.global(), &mut load_data); ScriptThread::eval_js_url(&window_proxy.global(), &mut load_data, can_gc);
} }
} }
} }

View file

@ -1016,12 +1016,12 @@ impl HTMLScriptElement {
match script.type_ { match script.type_ {
ScriptType::Classic => { ScriptType::Classic => {
self.run_a_classic_script(&script); self.run_a_classic_script(&script, CanGc::note());
document.set_current_script(old_script.as_deref()); document.set_current_script(old_script.as_deref());
}, },
ScriptType::Module => { ScriptType::Module => {
assert!(document.GetCurrentScript().is_none()); assert!(document.GetCurrentScript().is_none());
self.run_a_module_script(&script, false); self.run_a_module_script(&script, false, CanGc::note());
}, },
} }
@ -1037,7 +1037,7 @@ impl HTMLScriptElement {
} }
// https://html.spec.whatwg.org/multipage/#run-a-classic-script // https://html.spec.whatwg.org/multipage/#run-a-classic-script
pub fn run_a_classic_script(&self, script: &ScriptOrigin) { pub fn run_a_classic_script(&self, script: &ScriptOrigin, can_gc: CanGc) {
// TODO use a settings object rather than this element's document/window // TODO use a settings object rather than this element's document/window
// Step 2 // Step 2
let document = document_from_node(self); let document = document_from_node(self);
@ -1061,12 +1061,13 @@ impl HTMLScriptElement {
line_number, line_number,
script.fetch_options.clone(), script.fetch_options.clone(),
script.url.clone(), script.url.clone(),
can_gc,
); );
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
/// <https://html.spec.whatwg.org/multipage/#run-a-module-script> /// <https://html.spec.whatwg.org/multipage/#run-a-module-script>
pub fn run_a_module_script(&self, script: &ScriptOrigin, _rethrow_errors: bool) { pub fn run_a_module_script(&self, script: &ScriptOrigin, _rethrow_errors: bool, can_gc: CanGc) {
// TODO use a settings object rather than this element's document/window // TODO use a settings object rather than this element's document/window
// Step 2 // Step 2
let document = document_from_node(self); let document = document_from_node(self);
@ -1095,7 +1096,7 @@ impl HTMLScriptElement {
let module_error = module_tree.get_rethrow_error().borrow(); let module_error = module_tree.get_rethrow_error().borrow();
let network_error = module_tree.get_network_error().borrow(); let network_error = module_tree.get_network_error().borrow();
if module_error.is_some() && network_error.is_none() { if module_error.is_some() && network_error.is_none() {
module_tree.report_error(global); module_tree.report_error(global, can_gc);
return; return;
} }
} }
@ -1113,7 +1114,7 @@ impl HTMLScriptElement {
if let Err(exception) = evaluated { if let Err(exception) = evaluated {
module_tree.set_rethrow_error(exception); module_tree.set_rethrow_error(exception);
module_tree.report_error(global); module_tree.report_error(global, can_gc);
} }
} }
} }

View file

@ -414,7 +414,7 @@ impl ServiceWorkerGlobalScope {
match msg { match msg {
MixedMessage::Devtools(msg) => match msg { MixedMessage::Devtools(msg) => match msg {
DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) => { DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) => {
devtools::handle_evaluate_js(self.upcast(), string, sender) devtools::handle_evaluate_js(self.upcast(), string, sender, can_gc)
}, },
DevtoolScriptControlMsg::WantsLiveNotifications(_pipe_id, bool_val) => { DevtoolScriptControlMsg::WantsLiveNotifications(_pipe_id, bool_val) => {
devtools::handle_wants_live_notifications(self.upcast(), bool_val) devtools::handle_wants_live_notifications(self.upcast(), bool_val)

View file

@ -17,6 +17,7 @@ use crate::dom::htmlheadelement::HTMLHeadElement;
use crate::dom::htmlscriptelement::SourceCode; use crate::dom::htmlscriptelement::SourceCode;
use crate::dom::node::document_from_node; use crate::dom::node::document_from_node;
use crate::script_module::ScriptFetchOptions; use crate::script_module::ScriptFetchOptions;
use crate::script_runtime::CanGc;
pub fn load_script(head: &HTMLHeadElement) { pub fn load_script(head: &HTMLHeadElement) {
let doc = document_from_node(head); let doc = document_from_node(head);
@ -54,6 +55,7 @@ pub fn load_script(head: &HTMLHeadElement) {
1, 1,
ScriptFetchOptions::default_classic_script(global), ScriptFetchOptions::default_classic_script(global),
global.api_base_url(), global.api_base_url(),
CanGc::note(),
); );
} }
})); }));

View file

@ -467,7 +467,7 @@ impl WorkerGlobalScope {
println!("evaluate_script failed"); println!("evaluate_script failed");
unsafe { unsafe {
let ar = enter_realm(self); let ar = enter_realm(self);
report_pending_exception(cx, true, InRealm::Entered(&ar)); report_pending_exception(cx, true, InRealm::Entered(&ar), CanGc::note());
} }
} }
}, },

View file

@ -546,10 +546,10 @@ impl WorkletThread {
// try to become the cold backup. // try to become the cold backup.
if self.role.is_cold_backup { if self.role.is_cold_backup {
if let Some(control) = self.control_buffer.take() { if let Some(control) = self.control_buffer.take() {
self.process_control(control); self.process_control(control, CanGc::note());
} }
while let Ok(control) = self.control_receiver.try_recv() { while let Ok(control) = self.control_receiver.try_recv() {
self.process_control(control); self.process_control(control, CanGc::note());
} }
self.gc(); self.gc();
} else if self.control_buffer.is_none() { } else if self.control_buffer.is_none() {
@ -638,6 +638,7 @@ impl WorkletThread {
credentials: RequestCredentials, credentials: RequestCredentials,
pending_tasks_struct: PendingTasksStruct, pending_tasks_struct: PendingTasksStruct,
promise: TrustedPromise, promise: TrustedPromise,
can_gc: CanGc,
) { ) {
debug!("Fetching from {}.", script_url); debug!("Fetching from {}.", script_url);
// Step 1. // Step 1.
@ -672,7 +673,7 @@ impl WorkletThread {
// to the main script thread. // to the main script thread.
// https://github.com/w3c/css-houdini-drafts/issues/407 // https://github.com/w3c/css-houdini-drafts/issues/407
let ok = script let ok = script
.map(|script| global_scope.evaluate_js(&script)) .map(|script| global_scope.evaluate_js(&script, can_gc))
.unwrap_or(false); .unwrap_or(false);
if !ok { if !ok {
@ -707,7 +708,7 @@ impl WorkletThread {
} }
/// Process a control message. /// Process a control message.
fn process_control(&mut self, control: WorkletControl) { fn process_control(&mut self, control: WorkletControl, can_gc: CanGc) {
match control { match control {
WorkletControl::ExitWorklet(worklet_id) => { WorkletControl::ExitWorklet(worklet_id) => {
self.global_scopes.remove(&worklet_id); self.global_scopes.remove(&worklet_id);
@ -733,6 +734,7 @@ impl WorkletThread {
credentials, credentials,
pending_tasks_struct, pending_tasks_struct,
promise, promise,
can_gc,
) )
}, },
} }

View file

@ -27,7 +27,7 @@ use crate::dom::paintworkletglobalscope::{PaintWorkletGlobalScope, PaintWorkletT
use crate::dom::testworkletglobalscope::{TestWorkletGlobalScope, TestWorkletTask}; use crate::dom::testworkletglobalscope::{TestWorkletGlobalScope, TestWorkletTask};
use crate::dom::worklet::WorkletExecutor; use crate::dom::worklet::WorkletExecutor;
use crate::script_module::ScriptFetchOptions; use crate::script_module::ScriptFetchOptions;
use crate::script_runtime::JSContext; use crate::script_runtime::{CanGc, JSContext};
use crate::script_thread::MainThreadScriptMsg; use crate::script_thread::MainThreadScriptMsg;
#[dom_struct] #[dom_struct]
@ -114,7 +114,7 @@ impl WorkletGlobalScope {
} }
/// Evaluate a JS script in this global. /// Evaluate a JS script in this global.
pub fn evaluate_js(&self, script: &str) -> bool { pub fn evaluate_js(&self, script: &str, can_gc: CanGc) -> bool {
debug!("Evaluating Dom in a worklet."); debug!("Evaluating Dom in a worklet.");
rooted!(in (*GlobalScope::get_cx()) let mut rval = UndefinedValue()); rooted!(in (*GlobalScope::get_cx()) let mut rval = UndefinedValue());
self.globalscope.evaluate_js_on_global_with_result( self.globalscope.evaluate_js_on_global_with_result(
@ -122,6 +122,7 @@ impl WorkletGlobalScope {
rval.handle_mut(), rval.handle_mut(),
ScriptFetchOptions::default_classic_script(&self.globalscope), ScriptFetchOptions::default_classic_script(&self.globalscope),
self.globalscope.api_base_url(), self.globalscope.api_base_url(),
can_gc,
) )
} }

View file

@ -541,7 +541,7 @@ impl ModuleTree {
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn report_error(&self, global: &GlobalScope) { pub fn report_error(&self, global: &GlobalScope, can_gc: CanGc) {
let module_error = self.rethrow_error.borrow(); let module_error = self.rethrow_error.borrow();
if let Some(exception) = &*module_error { if let Some(exception) = &*module_error {
@ -552,7 +552,12 @@ impl ModuleTree {
exception.handle(), exception.handle(),
ExceptionStackBehavior::Capture, ExceptionStackBehavior::Capture,
); );
report_pending_exception(*GlobalScope::get_cx(), true, InRealm::Entered(&ar)); report_pending_exception(
*GlobalScope::get_cx(),
true,
InRealm::Entered(&ar),
can_gc,
);
} }
} }
} }

View file

@ -1028,7 +1028,7 @@ impl ScriptThread {
// TODO: check according to https://w3c.github.io/webappsec-csp/#should-block-navigation-request // TODO: check according to https://w3c.github.io/webappsec-csp/#should-block-navigation-request
if let Some(window) = trusted_global.root().downcast::<Window>() { if let Some(window) = trusted_global.root().downcast::<Window>() {
if ScriptThread::check_load_origin(&load_data.load_origin, &window.get_url().origin()) { if ScriptThread::check_load_origin(&load_data.load_origin, &window.get_url().origin()) {
ScriptThread::eval_js_url(&trusted_global.root(), &mut load_data); ScriptThread::eval_js_url(&trusted_global.root(), &mut load_data, CanGc::note());
sender sender
.send((pipeline_id, ScriptMsg::LoadUrl(load_data, replace))) .send((pipeline_id, ScriptMsg::LoadUrl(load_data, replace)))
.unwrap(); .unwrap();
@ -1738,7 +1738,7 @@ impl ScriptThread {
} }
if document.has_skipped_resize_observations() { if document.has_skipped_resize_observations() {
document.deliver_resize_loop_error_notification(); document.deliver_resize_loop_error_notification(can_gc);
} }
// TODO(#31870): Implement step 17: if the focused area of doc is not a focusable area, // TODO(#31870): Implement step 17: if the focused area of doc is not a focusable area,
@ -2578,7 +2578,7 @@ impl ScriptThread {
Some(window) => { Some(window) => {
let global = window.upcast::<GlobalScope>(); let global = window.upcast::<GlobalScope>();
let _aes = AutoEntryScript::new(global); let _aes = AutoEntryScript::new(global);
devtools::handle_evaluate_js(global, s, reply) devtools::handle_evaluate_js(global, s, reply, can_gc)
}, },
None => warn!("Message sent to closed pipeline {}.", id), None => warn!("Message sent to closed pipeline {}.", id),
}, },
@ -2660,11 +2660,13 @@ impl ScriptThread {
match msg { match msg {
WebDriverScriptCommand::ExecuteScript(script, reply) => { WebDriverScriptCommand::ExecuteScript(script, reply) => {
let window = self.documents.borrow().find_window(pipeline_id); let window = self.documents.borrow().find_window(pipeline_id);
return webdriver_handlers::handle_execute_script(window, script, reply); return webdriver_handlers::handle_execute_script(window, script, reply, can_gc);
}, },
WebDriverScriptCommand::ExecuteAsyncScript(script, reply) => { WebDriverScriptCommand::ExecuteAsyncScript(script, reply) => {
let window = self.documents.borrow().find_window(pipeline_id); let window = self.documents.borrow().find_window(pipeline_id);
return webdriver_handlers::handle_execute_async_script(window, script, reply); return webdriver_handlers::handle_execute_async_script(
window, script, reply, can_gc,
);
}, },
_ => (), _ => (),
} }
@ -4007,7 +4009,7 @@ impl ScriptThread {
/// Turn javascript: URL into JS code to eval, according to the steps in /// Turn javascript: URL into JS code to eval, according to the steps in
/// <https://html.spec.whatwg.org/multipage/#javascript-protocol> /// <https://html.spec.whatwg.org/multipage/#javascript-protocol>
pub fn eval_js_url(global_scope: &GlobalScope, load_data: &mut LoadData) { pub fn eval_js_url(global_scope: &GlobalScope, load_data: &mut LoadData, can_gc: CanGc) {
// This slice of the URLs serialization is equivalent to (5.) to (7.): // This slice of the URLs serialization is equivalent to (5.) to (7.):
// Start with the scheme data of the parsed URL; // Start with the scheme data of the parsed URL;
// append question mark and query component, if any; // append question mark and query component, if any;
@ -4025,6 +4027,7 @@ impl ScriptThread {
jsval.handle_mut(), jsval.handle_mut(),
ScriptFetchOptions::default_classic_script(global_scope), ScriptFetchOptions::default_classic_script(global_scope),
global_scope.api_base_url(), global_scope.api_base_url(),
can_gc,
); );
load_data.js_eval_result = if jsval.get().is_string() { load_data.js_eval_result = if jsval.get().is_string() {

View file

@ -558,6 +558,7 @@ impl JsTimerTask {
rval.handle_mut(), rval.handle_mut(),
ScriptFetchOptions::default_classic_script(&global), ScriptFetchOptions::default_classic_script(&global),
global.api_base_url(), global.api_base_url(),
CanGc::note(),
); );
}, },
InternalTimerCallback::FunctionTimerCallback(ref function, ref arguments) => { InternalTimerCallback::FunctionTimerCallback(ref function, ref arguments) => {

View file

@ -289,6 +289,7 @@ pub fn handle_execute_script(
window: Option<DomRoot<Window>>, window: Option<DomRoot<Window>>,
eval: String, eval: String,
reply: IpcSender<WebDriverJSResult>, reply: IpcSender<WebDriverJSResult>,
can_gc: CanGc,
) { ) {
match window { match window {
Some(window) => { Some(window) => {
@ -301,6 +302,7 @@ pub fn handle_execute_script(
rval.handle_mut(), rval.handle_mut(),
ScriptFetchOptions::default_classic_script(global), ScriptFetchOptions::default_classic_script(global),
global.api_base_url(), global.api_base_url(),
can_gc,
); );
jsval_to_webdriver(*cx, window.upcast::<GlobalScope>(), rval.handle()) jsval_to_webdriver(*cx, window.upcast::<GlobalScope>(), rval.handle())
}; };
@ -319,6 +321,7 @@ pub fn handle_execute_async_script(
window: Option<DomRoot<Window>>, window: Option<DomRoot<Window>>,
eval: String, eval: String,
reply: IpcSender<WebDriverJSResult>, reply: IpcSender<WebDriverJSResult>,
can_gc: CanGc,
) { ) {
match window { match window {
Some(window) => { Some(window) => {
@ -331,6 +334,7 @@ pub fn handle_execute_async_script(
rval.handle_mut(), rval.handle_mut(),
ScriptFetchOptions::default_classic_script(global), ScriptFetchOptions::default_classic_script(global),
global.api_base_url(), global.api_base_url(),
can_gc,
); );
}, },
None => { None => {