LibJS: Return a GC::Ref from Temporal::get_options_object

The Object returned here is always non-null.
This commit is contained in:
Timothy Flynn 2024-11-18 10:36:03 -05:00 committed by Tim Flynn
commit e4e05837e1
Notes: github-actions[bot] 2024-11-21 00:06:36 +00:00
7 changed files with 12 additions and 11 deletions

View file

@ -13,20 +13,20 @@
namespace JS::Temporal {
// 14.4.1.1 GetOptionsObject ( options ), https://tc39.es/proposal-temporal/#sec-getoptionsobject
ThrowCompletionOr<Object*> get_options_object(VM& vm, Value options)
ThrowCompletionOr<GC::Ref<Object>> get_options_object(VM& vm, Value options)
{
auto& realm = *vm.current_realm();
// 1. If options is undefined, then
if (options.is_undefined()) {
// a. Return OrdinaryObjectCreate(null).
return Object::create(realm, nullptr).ptr();
return Object::create(realm, nullptr);
}
// 2. If options is an Object, then
if (options.is_object()) {
// a. Return options.
return &options.as_object();
return options.as_object();
}
// 3. Throw a TypeError exception.

View file

@ -9,6 +9,7 @@
#pragma once
#include <AK/Variant.h>
#include <LibGC/Ptr.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/VM.h>
@ -39,7 +40,7 @@ enum class OptionType {
struct DefaultRequired { };
using OptionDefault = Variant<DefaultRequired, Empty, bool, StringView, double>;
ThrowCompletionOr<Object*> get_options_object(VM&, Value options);
ThrowCompletionOr<GC::Ref<Object>> get_options_object(VM&, Value options);
ThrowCompletionOr<Value> get_option(VM&, Object const& options, PropertyKey const& property, OptionType type, ReadonlySpan<StringView> values, OptionDefault const&);
template<size_t Size>