LibJS: Make Completion.[[Value]] non-optional

Instead, just use js_undefined() whenever the [[Value]] field is unused.
This avoids a whole bunch of presence checks.
This commit is contained in:
Andreas Kling 2025-04-04 18:11:45 +02:00 committed by Andreas Kling
commit de424d6879
Notes: github-actions[bot] 2025-04-05 09:21:48 +00:00
65 changed files with 225 additions and 250 deletions

View file

@ -2516,9 +2516,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(GC::Ref<HTML::CustomElement
set_custom_element_state(CustomElementState::Precustomized);
// 3. Let constructResult be the result of constructing C, with no arguments.
auto construct_result_optional = TRY(WebIDL::construct(constructor));
VERIFY(construct_result_optional.has_value());
auto construct_result = construct_result_optional.release_value();
auto construct_result = TRY(WebIDL::construct(constructor));
// 4. If SameValue(constructResult, element) is false, then throw a TypeError.
if (!JS::same_value(construct_result, this))

View file

@ -581,10 +581,10 @@ WebIDL::ExceptionOr<GC::Ref<Element>> create_element(Document& document, FlyStri
auto result = TRY(WebIDL::construct(constructor));
// NOTE: IDL does not currently convert the object for us, so we will have to do it here.
if (!result.has_value() || !result->is_object() || !is<HTML::HTMLElement>(result->as_object()))
if (!result.is_object() || !is<HTML::HTMLElement>(result.as_object()))
return JS::throw_completion(JS::TypeError::create(realm, "Custom element constructor must return an object that implements HTMLElement"_string));
GC::Ref<HTML::HTMLElement> element = as<HTML::HTMLElement>(result->as_object());
GC::Ref<HTML::HTMLElement> element = as<HTML::HTMLElement>(result.as_object());
// FIXME: 3. Assert: results custom element state and custom element definition are initialized.

View file

@ -97,7 +97,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<GC::Root<DOM::DOMEventLi
if (result.is_error()) {
// 1. Report exception for listeners callbacks corresponding JavaScript objects associated realms global object.
auto& window_or_worker = as<HTML::WindowOrWorkerGlobalScopeMixin>(global);
window_or_worker.report_an_exception(*result.release_error().value());
window_or_worker.report_an_exception(result.release_error().value());
// 2. Set legacyOutputDidListenersThrowFlag if given. (Only used by IndexedDB currently)
legacy_output_did_listeners_throw = true;

View file

@ -715,7 +715,7 @@ JS::ThrowCompletionOr<void> EventTarget::process_event_handler_for_event(FlyStri
return return_value_or_error.release_error();
// FIXME: Ideally, invoke_callback would convert JS::Value to the appropriate return type for us as per the spec, but it doesn't currently.
auto return_value = *return_value_or_error.value();
auto return_value = return_value_or_error.value();
auto is_beforeunload = event.type() == HTML::EventNames::beforeunload;

View file

@ -178,7 +178,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> NodeIterator::filter(Node& node)
m_active = false;
// 8. Return result.
auto result_value = TRY(result.value()->to_i32(vm()));
auto result_value = TRY(result.value().to_i32(vm()));
return static_cast<NodeFilter::Result>(result_value);
}

View file

@ -283,7 +283,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
m_active = false;
// 8. Return result.
auto result_value = TRY(result.value()->to_i32(vm()));
auto result_value = TRY(result.value().to_i32(vm()));
return static_cast<NodeFilter::Result>(result_value);
}