| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | /*
 | 
					
						
							|  |  |  |  |  * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-01-22 21:13:55 +00:00
										 |  |  |  |  * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma once
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  | #include <AK/DeprecatedString.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | #include <AK/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2021-08-31 00:15:36 +01:00
										 |  |  |  | #include <AK/Variant.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-18 21:44:05 +01:00
										 |  |  |  | #include <LibJS/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-15 23:03:38 +01:00
										 |  |  |  | #include <LibJS/Runtime/Completion.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | #include <LibJS/Runtime/GlobalObject.h>
 | 
					
						
							| 
									
										
										
										
											2021-11-19 18:04:50 +00:00
										 |  |  |  | #include <LibJS/Runtime/Temporal/ISO8601.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace JS::Temporal { | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 19:01:15 +02:00
										 |  |  |  | enum class ArithmeticOperation { | 
					
						
							|  |  |  |  |     Add, | 
					
						
							|  |  |  |  |     Subtract, | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 13:32:19 +02:00
										 |  |  |  | enum class DifferenceOperation { | 
					
						
							|  |  |  |  |     Since, | 
					
						
							|  |  |  |  |     Until, | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-24 18:26:13 +01:00
										 |  |  |  | enum class UnsignedRoundingMode { | 
					
						
							|  |  |  |  |     HalfEven, | 
					
						
							|  |  |  |  |     HalfInfinity, | 
					
						
							|  |  |  |  |     HalfZero, | 
					
						
							|  |  |  |  |     Infinity, | 
					
						
							|  |  |  |  |     Zero, | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-11 22:28:49 +03:00
										 |  |  |  | enum class OptionType { | 
					
						
							|  |  |  |  |     Boolean, | 
					
						
							|  |  |  |  |     String, | 
					
						
							|  |  |  |  |     Number | 
					
						
							|  |  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-07-18 21:41:29 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-09 22:42:42 +01:00
										 |  |  |  | enum class UnitGroup { | 
					
						
							|  |  |  |  |     Date, | 
					
						
							|  |  |  |  |     Time, | 
					
						
							|  |  |  |  |     DateTime, | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | struct TemporalInstant { | 
					
						
							|  |  |  |  |     i32 year; | 
					
						
							| 
									
										
										
										
											2021-07-26 16:48:47 +03:00
										 |  |  |  |     u8 month; | 
					
						
							|  |  |  |  |     u8 day; | 
					
						
							|  |  |  |  |     u8 hour; | 
					
						
							|  |  |  |  |     u8 minute; | 
					
						
							|  |  |  |  |     u8 second; | 
					
						
							|  |  |  |  |     u16 millisecond; | 
					
						
							|  |  |  |  |     u16 microsecond; | 
					
						
							|  |  |  |  |     u16 nanosecond; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     Optional<DeprecatedString> time_zone_offset; | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-07-18 21:41:29 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-21 22:17:40 +03:00
										 |  |  |  | struct TemporalDate { | 
					
						
							|  |  |  |  |     i32 year; | 
					
						
							| 
									
										
										
										
											2021-07-26 16:48:47 +03:00
										 |  |  |  |     u8 month; | 
					
						
							|  |  |  |  |     u8 day; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     Optional<DeprecatedString> calendar; | 
					
						
							| 
									
										
										
										
											2021-07-21 22:17:40 +03:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-27 18:02:37 +03:00
										 |  |  |  | struct TemporalTime { | 
					
						
							|  |  |  |  |     u8 hour; | 
					
						
							|  |  |  |  |     u8 minute; | 
					
						
							|  |  |  |  |     u8 second; | 
					
						
							|  |  |  |  |     u16 millisecond; | 
					
						
							|  |  |  |  |     u16 microsecond; | 
					
						
							|  |  |  |  |     u16 nanosecond; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     Optional<DeprecatedString> calendar = {}; | 
					
						
							| 
									
										
										
										
											2021-08-27 18:02:37 +03:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | struct TemporalTimeZone { | 
					
						
							|  |  |  |  |     bool z; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     Optional<DeprecatedString> offset_string; | 
					
						
							|  |  |  |  |     Optional<DeprecatedString> name; | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-07-18 21:41:29 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 06:27:55 +01:00
										 |  |  |  | struct TemporalYearMonth { | 
					
						
							|  |  |  |  |     i32 year; | 
					
						
							|  |  |  |  |     u8 month; | 
					
						
							|  |  |  |  |     u8 day; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     Optional<DeprecatedString> calendar = {}; | 
					
						
							| 
									
										
										
										
											2021-09-09 06:27:55 +01:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-10 22:28:27 +00:00
										 |  |  |  | struct TemporalMonthDay { | 
					
						
							|  |  |  |  |     Optional<i32> year; | 
					
						
							|  |  |  |  |     u8 month; | 
					
						
							|  |  |  |  |     u8 day; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     Optional<DeprecatedString> calendar = {}; | 
					
						
							| 
									
										
										
										
											2021-11-10 22:28:27 +00:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-15 03:32:18 +05:30
										 |  |  |  | struct ISODateTime { | 
					
						
							|  |  |  |  |     i32 year; | 
					
						
							|  |  |  |  |     u8 month; | 
					
						
							|  |  |  |  |     u8 day; | 
					
						
							|  |  |  |  |     u8 hour; | 
					
						
							|  |  |  |  |     u8 minute; | 
					
						
							|  |  |  |  |     u8 second; | 
					
						
							|  |  |  |  |     u16 millisecond; | 
					
						
							|  |  |  |  |     u16 microsecond; | 
					
						
							|  |  |  |  |     u16 nanosecond; | 
					
						
							|  |  |  |  |     TemporalTimeZone time_zone { .z = false, .offset_string = {}, .name = {} }; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     Optional<DeprecatedString> calendar = {}; | 
					
						
							| 
									
										
										
										
											2021-11-07 00:51:19 +00:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-31 00:15:36 +01:00
										 |  |  |  | struct SecondsStringPrecision { | 
					
						
							| 
									
										
										
										
											2021-09-08 21:29:20 +01:00
										 |  |  |  |     Variant<StringView, u8> precision; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     DeprecatedString unit; | 
					
						
							| 
									
										
										
										
											2021-08-31 00:15:36 +01:00
										 |  |  |  |     u32 increment; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-24 00:27:29 +01:00
										 |  |  |  | struct DifferenceSettings { | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  |     DeprecatedString smallest_unit; | 
					
						
							|  |  |  |  |     DeprecatedString largest_unit; | 
					
						
							|  |  |  |  |     DeprecatedString rounding_mode; | 
					
						
							| 
									
										
										
										
											2022-06-24 00:27:29 +01:00
										 |  |  |  |     u64 rounding_increment; | 
					
						
							|  |  |  |  |     Object& options; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-09 22:42:42 +01:00
										 |  |  |  | struct TemporalUnitRequired { }; | 
					
						
							| 
									
										
										
										
											2022-06-14 20:22:52 +01:00
										 |  |  |  | struct PrepareTemporalFieldsPartial { }; | 
					
						
							| 
									
										
										
										
											2022-06-14 23:03:25 +01:00
										 |  |  |  | struct GetOptionRequired { }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | using OptionDefault = Variant<GetOptionRequired, Empty, bool, StringView, double>; | 
					
						
							| 
									
										
										
										
											2022-06-24 00:27:29 +01:00
										 |  |  |  | using TemporalUnitDefault = Variant<TemporalUnitRequired, Optional<StringView>>; | 
					
						
							| 
									
										
										
										
											2022-06-09 22:42:42 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | 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&); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  | ThrowCompletionOr<DeprecatedString> 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); | 
					
						
							|  |  |  |  | ThrowCompletionOr<DeprecatedString> to_temporal_offset(VM&, Object const* options, DeprecatedString const& fallback); | 
					
						
							|  |  |  |  | ThrowCompletionOr<DeprecatedString> to_calendar_name_option(VM&, Object const& normalized_options); | 
					
						
							|  |  |  |  | ThrowCompletionOr<DeprecatedString> to_time_zone_name_option(VM&, Object const& normalized_options); | 
					
						
							|  |  |  |  | ThrowCompletionOr<DeprecatedString> to_show_offset_option(VM&, Object const& normalized_options); | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<u64> to_temporal_rounding_increment(VM&, Object const& normalized_options, Optional<double> dividend, bool inclusive); | 
					
						
							|  |  |  |  | ThrowCompletionOr<u64> to_temporal_date_time_rounding_increment(VM&, Object const& normalized_options, StringView smallest_unit); | 
					
						
							|  |  |  |  | ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM&, Object const& normalized_options); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  | ThrowCompletionOr<Optional<DeprecatedString>> get_temporal_unit(VM&, Object const& normalized_options, PropertyKey const&, UnitGroup, TemporalUnitDefault const& default_, Vector<StringView> const& extra_values = {}); | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<Value> to_relative_temporal_object(VM&, Object const& options); | 
					
						
							| 
									
										
										
										
											2021-11-29 18:59:07 -05:00
										 |  |  |  | StringView larger_of_two_temporal_units(StringView, StringView); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  | ThrowCompletionOr<Object*> merge_largest_unit_option(VM&, Object const& options, DeprecatedString largest_unit); | 
					
						
							| 
									
										
										
										
											2021-09-06 21:21:57 +03:00
										 |  |  |  | Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit); | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(VM&, Object&); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  | DeprecatedString format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision); | 
					
						
							| 
									
										
										
										
											2021-11-07 01:41:52 +00:00
										 |  |  |  | double sign(double); | 
					
						
							| 
									
										
										
										
											2021-11-23 22:30:27 +00:00
										 |  |  |  | double sign(Crypto::SignedBigInteger const&); | 
					
						
							| 
									
										
										
										
											2022-05-24 18:26:13 +01:00
										 |  |  |  | UnsignedRoundingMode get_unsigned_rounding_mode(StringView rounding_mode, bool is_negative); | 
					
						
							|  |  |  |  | double apply_unsigned_rounding_mode(double x, double r1, double r2, Optional<UnsignedRoundingMode> const&); | 
					
						
							|  |  |  |  | Crypto::SignedBigInteger apply_unsigned_rounding_mode(Crypto::SignedDivisionResult const&, Crypto::SignedBigInteger const& r1, Crypto::SignedBigInteger const& r2, Optional<UnsignedRoundingMode> const&, Crypto::UnsignedBigInteger const& increment); | 
					
						
							|  |  |  |  | double round_number_to_increment(double, u64 increment, StringView rounding_mode); | 
					
						
							|  |  |  |  | Crypto::SignedBigInteger round_number_to_increment(Crypto::SignedBigInteger const&, u64 increment, StringView rounding_mode); | 
					
						
							| 
									
										
										
										
											2022-06-15 00:58:04 +01:00
										 |  |  |  | Crypto::SignedBigInteger round_number_to_increment_as_if_positive(Crypto::SignedBigInteger const&, u64 increment, StringView rounding_mode); | 
					
						
							| 
									
										
										
										
											2022-08-30 17:43:27 +01:00
										 |  |  |  | ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM&, StringView iso_string); | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM&, ParseResult const& parse_result); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  | ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<ISODateTime> parse_temporal_zoned_date_time_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<DeprecatedString> parse_temporal_calendar_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<TemporalDate> parse_temporal_date_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<ISODateTime> parse_temporal_relative_to_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<TemporalTime> parse_temporal_time_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(VM&, DeprecatedString const& iso_string); | 
					
						
							|  |  |  |  | ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(VM&, DeprecatedString const& iso_string); | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<double> to_positive_integer(VM&, Value argument); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |  | ThrowCompletionOr<Object*> prepare_temporal_fields(VM&, Object const& fields, Vector<DeprecatedString> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields); | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<DifferenceSettings> get_difference_settings(VM&, DifferenceOperation, Value options_value, UnitGroup unit_group, Vector<StringView> const& disallowed_units, TemporalUnitDefault const& fallback_smallest_unit, StringView smallest_largest_default_unit); | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 23:03:25 +01:00
										 |  |  |  | template<size_t Size> | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey const& property, OptionType type, StringView const (&values)[Size], OptionDefault const& default_) | 
					
						
							| 
									
										
										
										
											2022-06-14 23:03:25 +01:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  |     return get_option(vm, options, property, type, Span<StringView const> { values }, default_); | 
					
						
							| 
									
										
										
										
											2022-06-14 23:03:25 +01:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 22:03:18 +01:00
										 |  |  |  | // 13.40 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity
 | 
					
						
							| 
									
										
										
										
											2021-08-17 20:17:12 +01:00
										 |  |  |  | template<typename... Args> | 
					
						
							| 
									
										
										
										
											2022-08-20 08:52:42 +01:00
										 |  |  |  | ThrowCompletionOr<double> to_integer_throw_on_infinity(VM& vm, Value argument, ErrorType error_type, Args... args) | 
					
						
							| 
									
										
										
										
											2021-08-17 20:17:12 +01:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     // 1. Let integer be ? ToIntegerOrInfinity(argument).
 | 
					
						
							| 
									
										
										
										
											2022-08-21 14:00:56 +01:00
										 |  |  |  |     auto integer = TRY(argument.to_integer_or_infinity(vm)); | 
					
						
							| 
									
										
										
										
											2021-08-17 20:17:12 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-29 21:09:10 +02:00
										 |  |  |  |     // 2. If integer is -∞ or +∞ , then
 | 
					
						
							| 
									
										
										
										
											2021-08-17 20:17:12 +01:00
										 |  |  |  |     if (Value(integer).is_infinity()) { | 
					
						
							|  |  |  |  |         // a. Throw a RangeError exception.
 | 
					
						
							| 
									
										
										
										
											2022-08-16 20:33:17 +01:00
										 |  |  |  |         return vm.template throw_completion<RangeError>(error_type, args...); | 
					
						
							| 
									
										
										
										
											2021-08-17 20:17:12 +01:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     // 3. Return integer.
 | 
					
						
							|  |  |  |  |     return integer; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-13 15:11:55 -06:00
										 |  |  |  | // 13.41 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral
 | 
					
						
							| 
									
										
										
										
											2021-11-17 22:20:59 +00:00
										 |  |  |  | template<typename... Args> | 
					
						
							| 
									
										
										
										
											2022-11-13 15:11:55 -06:00
										 |  |  |  | ThrowCompletionOr<double> to_integer_if_integral(VM& vm, Value argument, ErrorType error_type, Args... args) | 
					
						
							| 
									
										
										
										
											2021-11-17 22:20:59 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     // 1. Let number be ? ToNumber(argument).
 | 
					
						
							| 
									
										
										
										
											2022-08-21 14:00:56 +01:00
										 |  |  |  |     auto number = TRY(argument.to_number(vm)); | 
					
						
							| 
									
										
										
										
											2021-11-17 22:20:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 23:32:13 +01:00
										 |  |  |  |     // 2. If number is NaN, +0𝔽, or -0𝔽, return 0.
 | 
					
						
							| 
									
										
										
										
											2021-11-17 22:20:59 +00:00
										 |  |  |  |     if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero()) | 
					
						
							|  |  |  |  |         return 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 18:05:50 +01:00
										 |  |  |  |     // 3. If IsIntegralNumber(number) is false, throw a RangeError exception.
 | 
					
						
							| 
									
										
										
										
											2021-11-17 22:20:59 +00:00
										 |  |  |  |     if (!number.is_integral_number()) | 
					
						
							| 
									
										
										
										
											2022-08-16 20:33:17 +01:00
										 |  |  |  |         return vm.template throw_completion<RangeError>(error_type, args...); | 
					
						
							| 
									
										
										
										
											2021-11-17 22:20:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     // 4. Return ℝ(number).
 | 
					
						
							|  |  |  |  |     return number.as_double(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  | } |