script: Return a Result from GlobalScope::evaluate_script_on_global_with_result (#38549)

Make GlobalScope::evaluate_script_on_global_with_result return a Result
instead of a boolean. This is the first step to resolve issue #37810.

Testing: Should not break or fix any existing tests

---------

Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
This commit is contained in:
Rodion Borovyk 2025-08-10 18:51:46 +02:00 committed by GitHub
parent 86c37a380b
commit 4f8731d562
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 45 additions and 28 deletions

View file

@ -6,6 +6,7 @@ use base::id::PipelineId;
use constellation_traits::ScriptToConstellationChan;
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
use dom_struct::dom_struct;
use embedder_traits::JavaScriptEvaluationError;
use embedder_traits::resources::{self, Resource};
use ipc_channel::ipc::IpcSender;
use js::jsval::UndefinedValue;
@ -104,7 +105,7 @@ impl DebuggerGlobalScope {
GlobalScope::get_cx()
}
fn evaluate_js(&self, script: &str, can_gc: CanGc) -> bool {
fn evaluate_js(&self, script: &str, can_gc: CanGc) -> Result<(), JavaScriptEvaluationError> {
rooted!(in (*Self::get_cx()) let mut rval = UndefinedValue());
self.global_scope.evaluate_js_on_global_with_result(
script,
@ -117,7 +118,10 @@ impl DebuggerGlobalScope {
}
pub(crate) fn execute(&self, can_gc: CanGc) {
if !self.evaluate_js(&resources::read_string(Resource::DebuggerJS), can_gc) {
if self
.evaluate_js(&resources::read_string(Resource::DebuggerJS), can_gc)
.is_err()
{
let ar = enter_realm(self);
report_pending_exception(Self::get_cx(), true, InRealm::Entered(&ar), can_gc);
}