Truly independent web browser
LibWeb: Let an interrupt pass through calls that cannot fail
Andreas Klinga9ffdd3a05ff
diff --git a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp b/Libraries/LibWeb/Bindings/RustBindingsServices.cppindex 78de6fd8f2a..eb85a20c59a 100644--- a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp+++ b/Libraries/LibWeb/Bindings/RustBindingsServices.cpp@@ -294,7 +294,10 @@ void web_bindings_queue_a_microtask(void* realm, JSObject* function)GC::Ref<JS::FunctionObject> steps = as<JS::FunctionObject>(*JS::HostABI::object_from_abi(function));HTML::queue_a_microtask(nullptr, GC::create_function(GC::Heap::the(), [js_realm, steps] {HTML::TemporaryExecutionContext execution_context { js_realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };- MUST(JS::call(steps->vm(), *steps, JS::js_undefined()));+ // NB: The steps cannot fail, but they can run into the abort of the script that they call.+ auto& vm = steps->vm();+ auto result = JS::call(vm, *steps, JS::js_undefined());+ VERIFY(!result.is_error() || vm.interrupt_requested());}));}diff --git a/Libraries/LibWeb/DOM/AbortSignal.cpp b/Libraries/LibWeb/DOM/AbortSignal.cppindex 013c043cebb..eb92d8e9b36 100644--- a/Libraries/LibWeb/DOM/AbortSignal.cpp+++ b/Libraries/LibWeb/DOM/AbortSignal.cpp@@ -281,7 +281,10 @@ bool web_dom_abort_signal_add_algorithm(DOM::AbortSignal* signal, JSObject* func{GC::Ref<JS::FunctionObject> algorithm = as<JS::FunctionObject>(*JS::HostABI::object_from_abi(function));auto algorithm_id = signal->add_abort_algorithm([algorithm] {- MUST(JS::call(algorithm->vm(), *algorithm, JS::js_undefined()));+ // NB: The algorithm cannot fail, but it can run into the abort of the script that it calls.+ auto& vm = algorithm->vm();+ auto result = JS::call(vm, *algorithm, JS::js_undefined());+ VERIFY(!result.is_error() || vm.interrupt_requested());});if (!algorithm_id.has_value())return false;diff --git a/Libraries/LibWeb/Infra/JSON.cpp b/Libraries/LibWeb/Infra/JSON.cppindex eb22a4f43d4..0c43444278b 100644--- a/Libraries/LibWeb/Infra/JSON.cpp+++ b/Libraries/LibWeb/Infra/JSON.cpp@@ -154,9 +154,15 @@ String serialize_an_infra_value_to_a_json_string(JS::Realm& realm, JSONTopLevel// 2. Return ! Call(%JSON.stringify%, undefined, « jsValue »).// Spec Note: Since no additional arguments are passed to %JSON.stringify%, the resulting string will have no// whitespace inserted.- auto result = MUST(JS::call(vm, *realm.intrinsics().json_stringify_function(), JS::js_undefined(), js_value));- VERIFY(result.is_string());- return result.as_string().utf16_string_view().to_utf8_but_should_be_ported_to_utf16();+ // NB: Script can get in here through toJSON on a prototype, and the abort of that script is the one thing that stops+ // this. Whoever asked is about to be stopped as well, and nobody will look at the string.+ auto result = JS::call(vm, *realm.intrinsics().json_stringify_function(), JS::js_undefined(), js_value);+ if (result.is_error()) {+ VERIFY(vm.interrupt_requested());+ return {};+ }+ VERIFY(result.value().is_string());+ return result.value().as_string().utf16_string_view().to_utf8_but_should_be_ported_to_utf16();}// https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-json-bytes