mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:17:35 +00:00
LibWeb: Make factory method of DOM::ElementFactory fallible
This commit is contained in:
parent
a2381a672d
commit
ff92324fa5
15 changed files with 115 additions and 111 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/Bindings/AudioConstructor.h>
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/Bindings/HTMLAudioElementPrototype.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
|
@ -44,7 +45,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> AudioConstructor::construct(
|
|||
auto& document = window.associated_document();
|
||||
|
||||
// 2. Let audio be the result of creating an element given document, audio, and the HTML namespace.
|
||||
auto audio = DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML);
|
||||
auto audio = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML); }));
|
||||
|
||||
// 3. Set an attribute value for audio using "preload" and "auto".
|
||||
MUST(audio->set_attribute(HTML::AttributeNames::preload, "auto"sv));
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/Bindings/HTMLImageElementPrototype.h>
|
||||
#include <LibWeb/Bindings/ImageConstructor.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
|
@ -44,7 +45,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> ImageConstructor::construct(
|
|||
auto& document = window.associated_document();
|
||||
|
||||
// 2. Let img be the result of creating an element given document, img, and the HTML namespace.
|
||||
auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML);
|
||||
auto image_element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::img, Namespace::HTML); }));
|
||||
|
||||
// 3. If width is given, then set an attribute value for img using "width" and width.
|
||||
if (vm.argument_count() > 0) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/Bindings/HTMLOptionElementPrototype.h>
|
||||
#include <LibWeb/Bindings/OptionConstructor.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
|
@ -47,7 +48,8 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> OptionConstructor::construct
|
|||
auto& document = window.associated_document();
|
||||
|
||||
// 2. Let option be the result of creating an element given document, option, and the HTML namespace.
|
||||
JS::NonnullGCPtr<HTML::HTMLOptionElement> option_element = verify_cast<HTML::HTMLOptionElement>(*DOM::create_element(document, HTML::TagNames::option, Namespace::HTML));
|
||||
auto element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::option, Namespace::HTML); }));
|
||||
JS::NonnullGCPtr<HTML::HTMLOptionElement> option_element = verify_cast<HTML::HTMLOptionElement>(*element);
|
||||
|
||||
// 3. If text is not the empty string, then append to option a new Text node whose data is text.
|
||||
if (vm.argument_count() > 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue