mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibJS: Return a GC::Ref from Temporal::get_options_object
The Object returned here is always non-null.
This commit is contained in:
parent
c8d2404230
commit
e4e05837e1
Notes:
github-actions[bot]
2024-11-21 00:06:36 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/e4e05837e18 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2431 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/shannonbooth ✅
7 changed files with 12 additions and 11 deletions
|
@ -64,7 +64,7 @@ ThrowCompletionOr<GC::Ref<Object>> DisplayNamesConstructor::construct(FunctionOb
|
||||||
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "options"sv);
|
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "options"sv);
|
||||||
|
|
||||||
// 5. Set options to ? GetOptionsObject(options).
|
// 5. Set options to ? GetOptionsObject(options).
|
||||||
auto* options = TRY(Temporal::get_options_object(vm, options_value));
|
auto options = TRY(Temporal::get_options_object(vm, options_value));
|
||||||
|
|
||||||
// 6. Let opt be a new Record.
|
// 6. Let opt be a new Record.
|
||||||
LocaleOptions opt {};
|
LocaleOptions opt {};
|
||||||
|
|
|
@ -59,7 +59,7 @@ ThrowCompletionOr<GC::Ref<Object>> DurationFormatConstructor::construct(Function
|
||||||
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));
|
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));
|
||||||
|
|
||||||
// 4. Let options be ? GetOptionsObject(options).
|
// 4. Let options be ? GetOptionsObject(options).
|
||||||
auto* options = TRY(Temporal::get_options_object(vm, options_value));
|
auto options = TRY(Temporal::get_options_object(vm, options_value));
|
||||||
|
|
||||||
// 5. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit").
|
// 5. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit").
|
||||||
auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv));
|
auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv));
|
||||||
|
|
|
@ -59,7 +59,7 @@ ThrowCompletionOr<GC::Ref<Object>> ListFormatConstructor::construct(FunctionObje
|
||||||
auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value));
|
auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value));
|
||||||
|
|
||||||
// 4. Set options to ? GetOptionsObject(options).
|
// 4. Set options to ? GetOptionsObject(options).
|
||||||
auto* options = TRY(Temporal::get_options_object(vm, options_value));
|
auto options = TRY(Temporal::get_options_object(vm, options_value));
|
||||||
|
|
||||||
// 5. Let opt be a new Record.
|
// 5. Let opt be a new Record.
|
||||||
LocaleOptions opt {};
|
LocaleOptions opt {};
|
||||||
|
|
|
@ -60,7 +60,7 @@ ThrowCompletionOr<GC::Ref<Object>> SegmenterConstructor::construct(FunctionObjec
|
||||||
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));
|
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));
|
||||||
|
|
||||||
// 5. Set options to ? GetOptionsObject(options).
|
// 5. Set options to ? GetOptionsObject(options).
|
||||||
auto* options = TRY(Temporal::get_options_object(vm, options_value));
|
auto options = TRY(Temporal::get_options_object(vm, options_value));
|
||||||
|
|
||||||
// 6. Let opt be a new Record.
|
// 6. Let opt be a new Record.
|
||||||
LocaleOptions opt {};
|
LocaleOptions opt {};
|
||||||
|
|
|
@ -13,20 +13,20 @@
|
||||||
namespace JS::Temporal {
|
namespace JS::Temporal {
|
||||||
|
|
||||||
// 14.4.1.1 GetOptionsObject ( options ), https://tc39.es/proposal-temporal/#sec-getoptionsobject
|
// 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();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 1. If options is undefined, then
|
// 1. If options is undefined, then
|
||||||
if (options.is_undefined()) {
|
if (options.is_undefined()) {
|
||||||
// a. Return OrdinaryObjectCreate(null).
|
// a. Return OrdinaryObjectCreate(null).
|
||||||
return Object::create(realm, nullptr).ptr();
|
return Object::create(realm, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. If options is an Object, then
|
// 2. If options is an Object, then
|
||||||
if (options.is_object()) {
|
if (options.is_object()) {
|
||||||
// a. Return options.
|
// a. Return options.
|
||||||
return &options.as_object();
|
return options.as_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Throw a TypeError exception.
|
// 3. Throw a TypeError exception.
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Variant.h>
|
#include <AK/Variant.h>
|
||||||
|
#include <LibGC/Ptr.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibJS/Runtime/Completion.h>
|
#include <LibJS/Runtime/Completion.h>
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
|
@ -39,7 +40,7 @@ enum class OptionType {
|
||||||
struct DefaultRequired { };
|
struct DefaultRequired { };
|
||||||
using OptionDefault = Variant<DefaultRequired, Empty, bool, StringView, double>;
|
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&);
|
ThrowCompletionOr<Value> get_option(VM&, Object const& options, PropertyKey const& property, OptionType type, ReadonlySpan<StringView> values, OptionDefault const&);
|
||||||
|
|
||||||
template<size_t Size>
|
template<size_t Size>
|
||||||
|
|
|
@ -87,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(Uint8ArrayPrototypeHelpers::to_base64)
|
||||||
auto typed_array = TRY(validate_uint8_array(vm));
|
auto typed_array = TRY(validate_uint8_array(vm));
|
||||||
|
|
||||||
// 3. Let opts be ? GetOptionsObject(options).
|
// 3. Let opts be ? GetOptionsObject(options).
|
||||||
auto* options = TRY(Temporal::get_options_object(vm, options_value));
|
auto options = TRY(Temporal::get_options_object(vm, options_value));
|
||||||
|
|
||||||
// 4. Let alphabet be ? Get(opts, "alphabet").
|
// 4. Let alphabet be ? Get(opts, "alphabet").
|
||||||
// 5. If alphabet is undefined, set alphabet to "base64".
|
// 5. If alphabet is undefined, set alphabet to "base64".
|
||||||
|
@ -159,7 +159,7 @@ JS_DEFINE_NATIVE_FUNCTION(Uint8ArrayConstructorHelpers::from_base64)
|
||||||
return vm.throw_completion<TypeError>(ErrorType::NotAString, string_value);
|
return vm.throw_completion<TypeError>(ErrorType::NotAString, string_value);
|
||||||
|
|
||||||
// 2. Let opts be ? GetOptionsObject(options).
|
// 2. Let opts be ? GetOptionsObject(options).
|
||||||
auto* options = TRY(Temporal::get_options_object(vm, options_value));
|
auto options = TRY(Temporal::get_options_object(vm, options_value));
|
||||||
|
|
||||||
// 3. Let alphabet be ? Get(opts, "alphabet").
|
// 3. Let alphabet be ? Get(opts, "alphabet").
|
||||||
// 4. If alphabet is undefined, set alphabet to "base64".
|
// 4. If alphabet is undefined, set alphabet to "base64".
|
||||||
|
@ -214,7 +214,7 @@ JS_DEFINE_NATIVE_FUNCTION(Uint8ArrayPrototypeHelpers::set_from_base64)
|
||||||
return vm.throw_completion<TypeError>(ErrorType::NotAString, string_value);
|
return vm.throw_completion<TypeError>(ErrorType::NotAString, string_value);
|
||||||
|
|
||||||
// 4. Let opts be ? GetOptionsObject(options).
|
// 4. Let opts be ? GetOptionsObject(options).
|
||||||
auto* options = TRY(Temporal::get_options_object(vm, options_value));
|
auto options = TRY(Temporal::get_options_object(vm, options_value));
|
||||||
|
|
||||||
// 5. Let alphabet be ? Get(opts, "alphabet").
|
// 5. Let alphabet be ? Get(opts, "alphabet").
|
||||||
// 6. If alphabet is undefined, set alphabet to "base64".
|
// 6. If alphabet is undefined, set alphabet to "base64".
|
||||||
|
|
Loading…
Reference in a new issue