Skip to content

Truly independent web browser

LibWeb: Do not run Proxy traps to report an exception

Andreas Klingf24c131cf1fc
diff --git a/Libraries/LibWeb/HTML/ErrorInformation.cpp b/Libraries/LibWeb/HTML/ErrorInformation.cpp
index 97976679fbf..271aba022e9 100644
--- a/Libraries/LibWeb/HTML/ErrorInformation.cpp
+++ b/Libraries/LibWeb/HTML/ErrorInformation.cpp
@@ -38,7 +38,9 @@ ErrorInformation extract_error_information(JS::VM& vm, JS::Value exception)
if (auto const* dom_exception = Bindings::dom_exception_from_object(*object))
return prefix_with_name(dom_exception->name().to_utf16_string(), dom_exception->message().to_utf16_string());
- if (MUST(object->has_own_property(vm.names.message))) {
+ // NB: Whatever script threw must not get to run here, so stay away from the traps of a proxy. What is left is
+ // a module namespace object whose binding of that name is not initialized yet.
+ if (auto has_message = object->is_proxy() ? false : object->has_own_property(vm.names.message); !has_message.is_error() && has_message.value()) {
auto message = object->get_without_side_effects(vm.names.message).to_utf16_string_without_side_effects();
if (is<JS::Error>(*object)) {
auto name = object->get_without_side_effects(vm.names.name);
diff --git a/Tests/LibWeb/Text/expected/Workers/worker-reportError-proxy-trap-throws.txt b/Tests/LibWeb/Text/expected/Workers/worker-reportError-proxy-trap-throws.txt
new file mode 100644
index 00000000000..cdbd77e0633
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Workers/worker-reportError-proxy-trap-throws.txt
@@ -0,0 +1 @@
+reported
diff --git a/Tests/LibWeb/Text/input/Workers/worker-reportError-proxy-trap-throws.html b/Tests/LibWeb/Text/input/Workers/worker-reportError-proxy-trap-throws.html
new file mode 100644
index 00000000000..026e761504f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Workers/worker-reportError-proxy-trap-throws.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ const SCRIPT = `
+ onerror = () => true;
+ reportError(
+ new Proxy(
+ {},
+ {
+ getOwnPropertyDescriptor() {
+ throw new Error("thrown by the trap");
+ },
+ }
+ )
+ );
+ postMessage("reported");
+ `;
+
+ promiseTest(async () => {
+ const worker = new Worker(URL.createObjectURL(new Blob([SCRIPT], { type: "text/javascript" })));
+ println(await new Promise(resolve => (worker.onmessage = event => resolve(event.data))));
+ });
+</script>