mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-25 00:54:32 +00:00
LibJS: Return Optional<T> from Completion::{value,target}(), not T
In the end this is a nicer API than having separate has_{value,target}()
and having to check those first, and then making another Optional from
the unwrapped value:
completion.has_value() ? completion.value() : Optional<Value> {}
// ^^^^^^^^^^^^^^^^^^
// Implicit creation of non-empty Optional<Value>
This way we need to unwrap the optional ourselves, but can easily pass
it to something else as well.
This is in anticipation of the AST using completions :^)
This commit is contained in:
@@ -246,23 +246,23 @@ ThrowCompletionOr<Object*> ECMAScriptFunctionObject::internal_construct(MarkedVa
|
||||
if (result.type() == Completion::Type::Return) {
|
||||
// FIXME: This is leftover from untangling the call/construct mess - doesn't belong here in any way, but removing it breaks derived classes.
|
||||
// Likely fixed by making ClassDefinitionEvaluation fully spec compliant.
|
||||
if (kind == ConstructorKind::Derived && result.value().is_object()) {
|
||||
if (kind == ConstructorKind::Derived && result.value()->is_object()) {
|
||||
auto prototype = TRY(new_target.get(vm.names.prototype));
|
||||
if (prototype.is_object())
|
||||
TRY(result.value().as_object().internal_set_prototype_of(&prototype.as_object()));
|
||||
TRY(result.value()->as_object().internal_set_prototype_of(&prototype.as_object()));
|
||||
}
|
||||
// EOF (End of FIXME)
|
||||
|
||||
// a. If Type(result.[[Value]]) is Object, return NormalCompletion(result.[[Value]]).
|
||||
if (result.value().is_object())
|
||||
return &result.value().as_object();
|
||||
if (result.value()->is_object())
|
||||
return &result.value()->as_object();
|
||||
|
||||
// b. If kind is base, return NormalCompletion(thisArgument).
|
||||
if (kind == ConstructorKind::Base)
|
||||
return this_argument;
|
||||
|
||||
// c. If result.[[Value]] is not undefined, throw a TypeError exception.
|
||||
if (!result.value().is_undefined())
|
||||
if (!result.value()->is_undefined())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::DerivedConstructorReturningInvalidValue);
|
||||
}
|
||||
// 11. Else, ReturnIfAbrupt(result).
|
||||
@@ -788,7 +788,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
||||
|
||||
VERIFY(result_and_frame.frame != nullptr);
|
||||
if (result_and_frame.value.is_error()) {
|
||||
vm.throw_exception(bytecode_interpreter->global_object(), result_and_frame.value.release_error().value());
|
||||
vm.throw_exception(bytecode_interpreter->global_object(), *result_and_frame.value.release_error().value());
|
||||
return throw_completion(vm.exception()->value());
|
||||
}
|
||||
auto result = result_and_frame.value.release_value();
|
||||
@@ -844,7 +844,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
||||
// 4. Else,
|
||||
else {
|
||||
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « declResult.[[Value]] »).
|
||||
MUST(call(global_object(), promise_capability.reject, js_undefined(), declaration_result.throw_completion().value()));
|
||||
MUST(call(global_object(), promise_capability.reject, js_undefined(), *declaration_result.throw_completion().value()));
|
||||
}
|
||||
|
||||
// 5. Return Completion { [[Type]]: return, [[Value]]: promiseCapability.[[Promise]], [[Target]]: empty }.
|
||||
|
||||
Reference in New Issue
Block a user