From 4db5406d6234bad17d34fe8a0b461dea766271e6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 8 Feb 2022 15:37:36 +0100 Subject: LibWeb: Support passing more parameter types to HTML::report_exception() We now allow any JS::ThrowCompletion, as well as JS::Completion directly (although we'll VERIFY() that it's a throw completion.) --- Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.cpp | 7 ++++--- Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.h | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.cpp index 8135cb98d9..c5e4802cdd 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.cpp @@ -12,12 +12,13 @@ namespace Web::HTML { // https://html.spec.whatwg.org/#report-the-exception -void report_exception(JS::ThrowCompletionOr const& result) +void report_exception(JS::Completion const& throw_completion) { // FIXME: This is just old code, and does not strictly follow the spec of report an exception. // FIXME: We should probably also report these exceptions to the JS console. - VERIFY(result.throw_completion().value().has_value()); - auto thrown_value = *result.throw_completion().value(); + VERIFY(throw_completion.type() == JS::Completion::Type::Throw); + VERIFY(throw_completion.value().has_value()); + auto thrown_value = *throw_completion.value(); if (thrown_value.is_object()) { auto& object = thrown_value.as_object(); auto& vm = object.vm(); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.h b/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.h index a931ca4575..dc4aad44c8 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ExceptionReporter.h @@ -10,6 +10,13 @@ namespace Web::HTML { -void report_exception(JS::ThrowCompletionOr const& value); +void report_exception(JS::Completion const&); + +template +inline void report_exception(JS::ThrowCompletionOr const& result) +{ + VERIFY(result.is_throw_completion()); + report_exception(result.throw_completion()); +} } -- cgit v1.2.3