diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-20 21:16:30 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-21 09:02:23 +0100 |
commit | 5832de62fe5e2de4f9a65485246df6550aece33f (patch) | |
tree | 485f847a4dedebdcb2b11902bbe0256fa98518ed /Userland/Libraries/LibWeb/Bindings | |
parent | 0881f8160fd81d8e25b7cc2eff2d64f2aed7ed53 (diff) | |
download | serenity-5832de62fe5e2de4f9a65485246df6550aece33f.zip |
LibJS: Convert NativeFunction::{call,construct}() to ThrowCompletionOr
Both at the same time because many of them call construct() in call()
and I'm not keen on adding a bunch of temporary plumbing to turn
exceptions into throw completions.
Also changes the return value of construct() to Object* instead of Value
as it always needs to return an object; allowing an arbitrary Value is a
massive foot gun.
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/ImageConstructor.h | 4 |
2 files changed, 7 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index 3260bba7cc..9acff1182c 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -33,26 +33,25 @@ ImageConstructor::~ImageConstructor() { } -JS::Value ImageConstructor::call() +JS::ThrowCompletionOr<JS::Value> ImageConstructor::call() { - vm().throw_exception<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Image"); - return {}; + return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Image"); } // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-image -JS::Value ImageConstructor::construct(FunctionObject&) +JS::ThrowCompletionOr<JS::Object*> ImageConstructor::construct(FunctionObject&) { auto& window = static_cast<WindowObject&>(global_object()); auto& document = window.impl().associated_document(); auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML); if (vm().argument_count() > 0) { - u32 width = TRY_OR_DISCARD(vm().argument(0).to_u32(global_object())); + u32 width = TRY(vm().argument(0).to_u32(global_object())); image_element->set_attribute(HTML::AttributeNames::width, String::formatted("{}", width)); } if (vm().argument_count() > 1) { - u32 height = TRY_OR_DISCARD(vm().argument(1).to_u32(global_object())); + u32 height = TRY(vm().argument(1).to_u32(global_object())); image_element->set_attribute(HTML::AttributeNames::height, String::formatted("{}", height)); } diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.h b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.h index 54959d0cab..b516216cfd 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.h +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.h @@ -16,8 +16,8 @@ public: virtual void initialize(JS::GlobalObject&) override; virtual ~ImageConstructor() override; - virtual JS::Value call() override; - virtual JS::Value construct(JS::FunctionObject& new_target) override; + virtual JS::ThrowCompletionOr<JS::Value> call() override; + virtual JS::ThrowCompletionOr<JS::Object*> construct(JS::FunctionObject& new_target) override; private: virtual bool has_constructor() const override { return true; } |