/* * Copyright (c) 2021, Idan Horowitz * Copyright (c) 2021-2023, Linus Groh * Copyright (c) 2024, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace JS::Temporal { // 13.39 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral template ThrowCompletionOr to_integer_if_integral(VM& vm, Value argument, ErrorType error_type, Args&&... args) { // 1. Let number be ? ToNumber(argument). auto number = TRY(argument.to_number(vm)); // 2. If number is not an integral Number, throw a RangeError exception. if (!number.is_integral_number()) return vm.throw_completion(error_type, forward(args)...); // 3. Return ℝ(number). return number.as_double(); } enum class OptionType { Boolean, String, }; struct DefaultRequired { }; using OptionDefault = Variant; ThrowCompletionOr get_options_object(VM&, Value options); ThrowCompletionOr get_option(VM&, Object const& options, PropertyKey const& property, OptionType type, ReadonlySpan values, OptionDefault const&); template ThrowCompletionOr get_option(VM& vm, Object const& options, PropertyKey const& property, OptionType type, StringView const (&values)[Size], OptionDefault const& default_) { return get_option(vm, options, property, type, ReadonlySpan { values }, default_); } }