mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 08:36:15 +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:
@@ -53,7 +53,7 @@ ThrowCompletionOr<Object*> ArrayBufferConstructor::construct(FunctionObject& new
|
||||
auto byte_length_or_error = vm.argument(0).to_index(global_object());
|
||||
if (byte_length_or_error.is_error()) {
|
||||
auto error = byte_length_or_error.release_error();
|
||||
if (error.value().is_object() && is<RangeError>(error.value().as_object())) {
|
||||
if (error.value()->is_object() && is<RangeError>(error.value()->as_object())) {
|
||||
// Re-throw more specific RangeError
|
||||
vm.clear_exception();
|
||||
return vm.throw_completion<RangeError>(global_object(), ErrorType::InvalidLength, "array buffer");
|
||||
|
||||
Reference in New Issue
Block a user