Skip to content

Truly independent web browser

LibWeb: Include the error name in reported error messages

Andreas Klingf1da17a9deeb
diff --git a/Libraries/LibWeb/HTML/ErrorInformation.cpp b/Libraries/LibWeb/HTML/ErrorInformation.cpp
index ce365474151..0cfc9ecbda4 100644
--- a/Libraries/LibWeb/HTML/ErrorInformation.cpp
+++ b/Libraries/LibWeb/HTML/ErrorInformation.cpp
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/HTML/ErrorInformation.h>
@@ -24,8 +25,20 @@ ErrorInformation extract_error_information(JS::VM& vm, JS::Value exception)
attributes.message = [&] {
if (auto object = exception.as_if<JS::Object>()) {
if (MUST(object->has_own_property(vm.names.message))) {
- auto message = object->get_without_side_effects(vm.names.message);
- return message.to_utf16_string_without_side_effects();
+ auto message = object->get_without_side_effects(vm.names.message).to_utf16_string_without_side_effects();
+
+ // NB: The message of an Error object is prefixed with its name, as Error.prototype.toString() does.
+ if (is<JS::Error>(*object)) {
+ auto name = object->get_without_side_effects(vm.names.name);
+ if (name.is_string()) {
+ auto name_string = name.to_utf16_string_without_side_effects();
+ if (message.is_empty())
+ return name_string;
+ if (!name_string.is_empty())
+ return Utf16String::formatted("{}: {}", name_string, message);
+ }
+ }
+ return message;
}
}
diff --git a/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt b/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt
index fd01ab4ca8c..31d6eccde64 100644
--- a/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt
+++ b/Tests/LibWeb/Text/expected/HTML/WindowOrWorkerGlobalScope-reportError.txt
@@ -1,4 +1,4 @@
-message = Reporting an Error!
+message = Error: Reporting an Error!
lineno = 19
colno = 28
error = Error: Reporting an Error!
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-handler-throws.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-handler-throws.txt
index 9a10c0ce139..819d46107c2 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-handler-throws.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-handler-throws.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail event.intercept() should abort if the handler throws
\ No newline at end of file
+1 Pass
+Pass event.intercept() should abort if the handler throws
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.txt
index 863fb10fcdb..16555427987 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-multiple-times-reject.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail event.intercept() is called multiple times and one of the promises rejects
\ No newline at end of file
+1 Pass
+Pass event.intercept() is called multiple times and one of the promises rejects
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-reject.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-reject.txt
index 34b53d5bb7e..43eeec79ceb 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-reject.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/navigate-event/intercept-reject.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail event.intercept() should abort if the given promise rejects
\ No newline at end of file
+1 Pass
+Pass event.intercept() should abort if the given promise rejects
\ No newline at end of file