1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

LibJS: Port to_temporal_overflow() to String

This commit is contained in:
Linus Groh 2023-01-26 12:07:38 +00:00
parent 1044844307
commit b8759e86ee
2 changed files with 7 additions and 6 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021-2022, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -8,6 +8,7 @@
#include <AK/CharacterTypes.h>
#include <AK/DateTimeLexer.h>
#include <AK/String.h>
#include <AK/TypeCasts.h>
#include <AK/Variant.h>
#include <LibJS/Runtime/AbstractOperations.h>
@ -155,17 +156,17 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
}
// 13.4 ToTemporalOverflow ( options ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaloverflow
ThrowCompletionOr<DeprecatedString> to_temporal_overflow(VM& vm, Object const* options)
ThrowCompletionOr<String> to_temporal_overflow(VM& vm, Object const* options)
{
// 1. If options is undefined, return "constrain".
if (options == nullptr)
return "constrain"sv;
return TRY_OR_THROW_OOM(vm, String::from_utf8("constrain"sv));
// 2. Return ? GetOption(options, "overflow", "string", « "constrain", "reject" », "constrain").
auto option = TRY(get_option(vm, *options, vm.names.overflow, OptionType::String, { "constrain"sv, "reject"sv }, "constrain"sv));
VERIFY(option.is_string());
return TRY(option.as_string().deprecated_string());
return option.as_string().utf8_string();
}
// 13.5 ToTemporalDisambiguation ( options ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldisambiguation

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -135,7 +135,7 @@ using TemporalUnitDefault = Variant<TemporalUnitRequired, Optional<StringView>>;
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(VM&, Value items, Vector<OptionType> const& element_types);
ThrowCompletionOr<Object*> get_options_object(VM&, Value options);
ThrowCompletionOr<Value> get_option(VM&, Object const& options, PropertyKey const& property, OptionType type, Span<StringView const> values, OptionDefault const&);
ThrowCompletionOr<DeprecatedString> to_temporal_overflow(VM&, Object const* options);
ThrowCompletionOr<String> to_temporal_overflow(VM&, Object const* options);
ThrowCompletionOr<DeprecatedString> to_temporal_disambiguation(VM&, Object const* options);
ThrowCompletionOr<DeprecatedString> to_temporal_rounding_mode(VM&, Object const& normalized_options, DeprecatedString const& fallback);
StringView negate_temporal_rounding_mode(DeprecatedString const& rounding_mode);