mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibWeb: Fire error event when script has an execution error
We now use the "report an exception" AO when a script has an execution error. This has mostly replaced the older "report the exception" AO in various specifications. Using this newer AO ensures that `window.onerror` is invoked when a script has an execution error.
This commit is contained in:
parent
994457d7af
commit
579a289d3d
Notes:
github-actions[bot]
2024-09-27 11:03:15 +00:00
Author: https://github.com/tcl3
Commit: 579a289d3d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1548
6 changed files with 35 additions and 4 deletions
1
Tests/LibWeb/Text/expected/HTML/Window-onerror.txt
Normal file
1
Tests/LibWeb/Text/expected/HTML/Window-onerror.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
onerror event fired: Error: Uncaught error
|
16
Tests/LibWeb/Text/input/HTML/Window-onerror.html
Normal file
16
Tests/LibWeb/Text/input/HTML/Window-onerror.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
asyncTest(done => {
|
||||||
|
window.addEventListener("error", (event) => {
|
||||||
|
println(`onerror event fired: ${event.error}`);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw new Error("FAIL");
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
throw new Error("Uncaught error");
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -24,6 +24,7 @@
|
||||||
#include <LibWeb/HTML/HTMLSlotElement.h>
|
#include <LibWeb/HTML/HTMLSlotElement.h>
|
||||||
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
||||||
#include <LibWeb/HTML/Window.h>
|
#include <LibWeb/HTML/Window.h>
|
||||||
|
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
|
||||||
#include <LibWeb/UIEvents/MouseEvent.h>
|
#include <LibWeb/UIEvents/MouseEvent.h>
|
||||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||||
|
|
||||||
|
@ -91,8 +92,10 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<JS::Handle<DOM::DOMEvent
|
||||||
|
|
||||||
// If this throws an exception, then:
|
// If this throws an exception, then:
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
// 1. Report the exception.
|
// 1. Report exception for listener’s callback’s corresponding JavaScript object’s associated realm’s global object.
|
||||||
HTML::report_exception(result, realm);
|
auto* window_or_worker = dynamic_cast<HTML::WindowOrWorkerGlobalScopeMixin*>(&global);
|
||||||
|
VERIFY(window_or_worker);
|
||||||
|
window_or_worker->report_an_exception(*result.release_error().value());
|
||||||
|
|
||||||
// FIXME: 2. Set legacyOutputDidListenersThrowFlag if given. (Only used by IndexedDB currently)
|
// FIXME: 2. Set legacyOutputDidListenersThrowFlag if given. (Only used by IndexedDB currently)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||||
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
||||||
|
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
|
||||||
#include <LibWeb/WebIDL/DOMException.h>
|
#include <LibWeb/WebIDL/DOMException.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -126,8 +127,10 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, JS::GCPtr<JS::En
|
||||||
// 3. Otherwise, rethrow errors is false. Perform the following steps:
|
// 3. Otherwise, rethrow errors is false. Perform the following steps:
|
||||||
VERIFY(rethrow_errors == RethrowErrors::No);
|
VERIFY(rethrow_errors == RethrowErrors::No);
|
||||||
|
|
||||||
// 1. Report the exception given by evaluationStatus.[[Value]] for script.
|
// 1. Report an exception given by evaluationStatus.[[Value]] for script's settings object's global object.
|
||||||
report_exception(evaluation_status, settings_object().realm());
|
auto* window_or_worker = dynamic_cast<WindowOrWorkerGlobalScopeMixin*>(&settings.global_object());
|
||||||
|
VERIFY(window_or_worker);
|
||||||
|
window_or_worker->report_an_exception(*evaluation_status.value());
|
||||||
|
|
||||||
// 2. Clean up after running script with settings.
|
// 2. Clean up after running script with settings.
|
||||||
settings.clean_up_after_running_script();
|
settings.clean_up_after_running_script();
|
||||||
|
|
|
@ -746,6 +746,13 @@ JS::NonnullGCPtr<JS::Object> WindowOrWorkerGlobalScopeMixin::supported_entry_typ
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-reporterror
|
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-reporterror
|
||||||
void WindowOrWorkerGlobalScopeMixin::report_error(JS::Value e)
|
void WindowOrWorkerGlobalScopeMixin::report_error(JS::Value e)
|
||||||
|
{
|
||||||
|
// The reportError(e) method steps are to report an exception e for this.
|
||||||
|
report_an_exception(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/webappapis.html#report-an-exception
|
||||||
|
void WindowOrWorkerGlobalScopeMixin::report_an_exception(JS::Value const& e)
|
||||||
{
|
{
|
||||||
auto& target = static_cast<DOM::EventTarget&>(this_impl());
|
auto& target = static_cast<DOM::EventTarget&>(this_impl());
|
||||||
auto& realm = relevant_realm(target);
|
auto& realm = relevant_realm(target);
|
||||||
|
|
|
@ -77,6 +77,7 @@ public:
|
||||||
JS::NonnullGCPtr<IndexedDB::IDBFactory> indexed_db();
|
JS::NonnullGCPtr<IndexedDB::IDBFactory> indexed_db();
|
||||||
|
|
||||||
void report_error(JS::Value e);
|
void report_error(JS::Value e);
|
||||||
|
void report_an_exception(JS::Value const& e);
|
||||||
|
|
||||||
[[nodiscard]] JS::NonnullGCPtr<Crypto::Crypto> crypto();
|
[[nodiscard]] JS::NonnullGCPtr<Crypto::Crypto> crypto();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue