diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index a585513e56..50338db90a 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling - * Copyright (c) 2020-2022, Linus Groh + * Copyright (c) 2020-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -184,7 +184,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) auto error = vm.throw_completion(ErrorType::ArrayMaxSize); // 2. Return ? IteratorClose(iteratorRecord, error). - return TRY(iterator_close(vm, iterator, move(error))); + return *TRY(iterator_close(vm, iterator, move(error))); } // ii. Let Pk be ! ToString(𝔽(k)). @@ -214,7 +214,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) // 2. IfAbruptCloseIterator(mappedValue, iteratorRecord). if (mapped_value_or_error.is_error()) - return TRY(iterator_close(vm, iterator, mapped_value_or_error.release_error())); + return *TRY(iterator_close(vm, iterator, mapped_value_or_error.release_error())); mapped_value = mapped_value_or_error.release_value(); } // vii. Else, let mappedValue be nextValue. @@ -227,7 +227,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) // IfAbruptCloseIterator(defineStatus, iteratorRecord). if (result_or_error.is_error()) - return TRY(iterator_close(vm, iterator, result_or_error.release_error())); + return *TRY(iterator_close(vm, iterator, result_or_error.release_error())); // x. Set k to k + 1. } diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index 6e3b64dc40..d7671c40ce 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -274,23 +274,23 @@ class [[nodiscard]] ThrowCompletionOr { public: ThrowCompletionOr() requires(IsSame) - : m_value(Empty {}) + : m_value_or_throw_completion(Empty {}) { } // Not `explicit` on purpose so that `return vm.throw_completion(...);` is possible. ThrowCompletionOr(Completion throw_completion) - : m_throw_completion(move(throw_completion)) + : m_value_or_throw_completion(move(throw_completion)) { - VERIFY(m_throw_completion->is_error()); + VERIFY(m_value_or_throw_completion.template get().is_error()); } // Not `explicit` on purpose so that `return value;` is possible. ThrowCompletionOr(ValueType value) - : m_value(move(value)) + : m_value_or_throw_completion(move(value)) { if constexpr (IsSame) - VERIFY(!m_value->is_empty()); + VERIFY(!m_value_or_throw_completion.template get().is_empty()); } ThrowCompletionOr(ThrowCompletionOr const&) = default; @@ -299,7 +299,7 @@ public: ThrowCompletionOr& operator=(ThrowCompletionOr&&) = default; ThrowCompletionOr(OptionalNone value) - : m_value(ValueType { value }) + : m_value_or_throw_completion(ValueType { value }) { } @@ -309,28 +309,28 @@ public: template ThrowCompletionOr(WrappedValueType const& value) requires(!IsPOD) - : m_value(value) + : m_value_or_throw_completion(ValueType { value }) { } - [[nodiscard]] bool is_throw_completion() const { return m_throw_completion.has_value(); } - Completion const& throw_completion() const { return *m_throw_completion; } + [[nodiscard]] bool is_throw_completion() const { return m_value_or_throw_completion.template has(); } + Completion const& throw_completion() const { return m_value_or_throw_completion.template get(); } [[nodiscard]] bool has_value() const requires(!IsSame) { - return m_value.has_value(); + return m_value_or_throw_completion.template has(); } [[nodiscard]] ValueType const& value() const requires(!IsSame) { - return *m_value; + return m_value_or_throw_completion.template get(); } // These are for compatibility with the TRY() macro in AK. - [[nodiscard]] bool is_error() const { return m_throw_completion.has_value(); } - [[nodiscard]] ValueType release_value() { return m_value.release_value(); } - Completion release_error() { return m_throw_completion.release_value(); } + [[nodiscard]] bool is_error() const { return m_value_or_throw_completion.template has(); } + [[nodiscard]] ValueType release_value() { return move(m_value_or_throw_completion.template get()); } + Completion release_error() { return move(m_value_or_throw_completion.template get()); } ValueType release_allocated_value_but_fixme_should_propagate_errors() { @@ -339,8 +339,7 @@ public: } private: - Optional m_throw_completion; - Optional m_value; + Variant m_value_or_throw_completion; }; template<> diff --git a/Userland/Libraries/LibJS/Runtime/DisposableStackPrototype.cpp b/Userland/Libraries/LibJS/Runtime/DisposableStackPrototype.cpp index 77a0f707e3..2ad775b24e 100644 --- a/Userland/Libraries/LibJS/Runtime/DisposableStackPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DisposableStackPrototype.cpp @@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::dispose) disposable_stack->set_disposed(); // 5. Return DisposeResources(disposableStack, NormalCompletion(undefined)). - return TRY(dispose_resources(vm, disposable_stack->disposable_resource_stack(), Completion { js_undefined() })); + return *TRY(dispose_resources(vm, disposable_stack->disposable_resource_stack(), Completion { js_undefined() })); } // 11.3.3.3 DisposableStack.prototype.use( value ), https://tc39.es/proposal-explicit-resource-management/#sec-disposablestack.prototype.use diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 6c04dd0d02..42376b9500 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Stephan Unverwerth - * Copyright (c) 2020-2022, Linus Groh + * Copyright (c) 2020-2023, Linus Groh * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause @@ -183,7 +183,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::internal_call(Value this_argu // 8. If result.[[Type]] is return, return result.[[Value]]. if (result.type() == Completion::Type::Return) - return result.value(); + return *result.value(); // 9. ReturnIfAbrupt(result). if (result.is_abrupt()) { diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index db28e6527d..14d40369ea 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -558,7 +558,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields) auto completion = vm.throw_completion(ErrorType::TemporalInvalidCalendarFieldValue, TRY_OR_THROW_OOM(vm, next_value.to_string_without_side_effects())); // 2. Return ? IteratorClose(iteratorRecord, completion). - return TRY(iterator_close(vm, iterator_record, move(completion))); + return *TRY(iterator_close(vm, iterator_record, move(completion))); } auto next_value_string = TRY(next_value.as_string().utf8_string()); @@ -569,7 +569,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields) auto completion = vm.throw_completion(ErrorType::TemporalDuplicateCalendarField, next_value_string); // 2. Return ? IteratorClose(iteratorRecord, completion). - return TRY(iterator_close(vm, iterator_record, move(completion))); + return *TRY(iterator_close(vm, iterator_record, move(completion))); } // iv. If nextValue is not one of "year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", then @@ -578,7 +578,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields) auto completion = vm.throw_completion(ErrorType::TemporalInvalidCalendarFieldName, next_value_string); // 2. Return ? IteratorClose(iteratorRecord, completion). - return TRY(iterator_close(vm, iterator_record, move(completion))); + return *TRY(iterator_close(vm, iterator_record, move(completion))); } // v. Append nextValue to the end of the List fieldNames. diff --git a/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp b/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp index 52555b0c45..6ef03666ff 100644 --- a/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp @@ -186,7 +186,7 @@ JS::ThrowCompletionOr cross_origin_get(JS::VM& vm, JS::Object const& // 3. If IsDataDescriptor(desc) is true, then return desc.[[Value]]. if (descriptor->is_data_descriptor()) - return descriptor->value; + return *descriptor->value; // 4. Assert: IsAccessorDescriptor(desc) is true. VERIFY(descriptor->is_accessor_descriptor());