1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 05:58:13 +00:00

LibJS: Replace GlobalObject with VM in Temporal AOs [Part 2/19]

This commit is contained in:
Linus Groh 2022-08-20 08:52:42 +01:00
parent f9705eb2f4
commit 694f66b5ca
58 changed files with 1564 additions and 1600 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -454,8 +454,10 @@ ThrowCompletionOr<String> Console::value_vector_to_string(MarkedVector<Value> co
ThrowCompletionOr<String> Console::format_time_since(Core::ElapsedTimer timer)
{
auto& vm = this->vm();
auto elapsed_ms = timer.elapsed_time().to_milliseconds();
auto duration = TRY(Temporal::balance_duration(global_object(), 0, 0, 0, 0, elapsed_ms, 0, "0"_sbigint, "year"));
auto duration = TRY(Temporal::balance_duration(vm, 0, 0, 0, 0, elapsed_ms, 0, "0"_sbigint, "year"));
auto append = [&](StringBuilder& builder, auto format, auto... number) {
if (!builder.is_empty())

View file

@ -1184,7 +1184,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant)
ns = js_bigint(vm, ns->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }));
// 3. Return ! CreateTemporalInstant(ns).
return MUST(Temporal::create_temporal_instant(global_object, *ns));
return MUST(Temporal::create_temporal_instant(vm, *ns));
}
// 21.4.4.42 Date.prototype.toTimeString ( ), https://tc39.es/ecma262/#sec-date.prototype.totimestring

View file

@ -569,13 +569,12 @@ Vector<String> best_fit_supported_locales(Vector<String> const& requested_locale
ThrowCompletionOr<Array*> supported_locales(VM& vm, Vector<String> const& requested_locales, Value options)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Set options to ? CoerceOptionsToObject(options).
auto* options_object = TRY(coerce_options_to_object(vm, options));
// 2. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *options_object, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv));
auto matcher = TRY(get_option(vm, *options_object, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv));
Vector<String> supported_locales;

View file

@ -27,7 +27,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
auto* options = TRY(coerce_options_to_object(vm, options_value));
// 3. Let usage be ? GetOption(options, "usage", "string", « "sort", "search" », "sort").
auto usage = TRY(get_option(global_object, *options, vm.names.usage, OptionType::String, { "sort"sv, "search"sv }, "sort"sv));
auto usage = TRY(get_option(vm, *options, vm.names.usage, OptionType::String, { "sort"sv, "search"sv }, "sort"sv));
// 4. Set collator.[[Usage]] to usage.
collator.set_usage(usage.as_string().string());
@ -41,13 +41,13 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
LocaleOptions opt {};
// 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *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));
// 9. Set opt.[[localeMatcher]] to matcher.
opt.locale_matcher = matcher;
// 10. Let collation be ? GetOption(options, "collation", "string", undefined, undefined).
auto collation = TRY(get_option(global_object, *options, vm.names.collation, OptionType::String, {}, Empty {}));
auto collation = TRY(get_option(vm, *options, vm.names.collation, OptionType::String, {}, Empty {}));
// 11. If collation is not undefined, then
if (!collation.is_undefined()) {
@ -60,7 +60,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
}
// 13. Let numeric be ? GetOption(options, "numeric", "boolean", undefined, undefined).
auto numeric = TRY(get_option(global_object, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {}));
auto numeric = TRY(get_option(vm, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {}));
// 14. If numeric is not undefined, then
// a. Let numeric be ! ToString(numeric).
@ -70,7 +70,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 16. Let caseFirst be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined).
// 17. Set opt.[[kf]] to caseFirst.
auto case_first = TRY(get_option(global_object, *options, vm.names.caseFirst, OptionType::String, { "upper"sv, "lower"sv, "false"sv }, Empty {}));
auto case_first = TRY(get_option(vm, *options, vm.names.caseFirst, OptionType::String, { "upper"sv, "lower"sv, "false"sv }, Empty {}));
if (!case_first.is_undefined())
opt.kf = case_first.as_string().string();
@ -101,7 +101,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
}
// 26. Let sensitivity be ? GetOption(options, "sensitivity", "string", « "base", "accent", "case", "variant" », undefined).
auto sensitivity = TRY(get_option(global_object, *options, vm.names.sensitivity, OptionType::String, { "base"sv, "accent"sv, "case"sv, "variant"sv }, Empty {}));
auto sensitivity = TRY(get_option(vm, *options, vm.names.sensitivity, OptionType::String, { "base"sv, "accent"sv, "case"sv, "variant"sv }, Empty {}));
// 27. If sensitivity is undefined, then
if (sensitivity.is_undefined()) {
@ -123,7 +123,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
collator.set_sensitivity(sensitivity.as_string().string());
// 29. Let ignorePunctuation be ? GetOption(options, "ignorePunctuation", "boolean", undefined, false).
auto ignore_punctuation = TRY(get_option(global_object, *options, vm.names.ignorePunctuation, OptionType::Boolean, {}, false));
auto ignore_punctuation = TRY(get_option(vm, *options, vm.names.ignorePunctuation, OptionType::Boolean, {}, false));
// 30. Set collator.[[IgnorePunctuation]] to ignorePunctuation.
collator.set_ignore_punctuation(ignore_punctuation.as_bool());

View file

@ -98,13 +98,13 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
LocaleOptions opt {};
// 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv));
auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv));
// 5. Set opt.[[localeMatcher]] to matcher.
opt.locale_matcher = matcher;
// 6. Let calendar be ? GetOption(options, "calendar", "string", undefined, undefined).
auto calendar = TRY(get_option(global_object, *options, vm.names.calendar, OptionType::String, {}, Empty {}));
auto calendar = TRY(get_option(vm, *options, vm.names.calendar, OptionType::String, {}, Empty {}));
// 7. If calendar is not undefined, then
if (!calendar.is_undefined()) {
@ -117,7 +117,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
}
// 9. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
// 10. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) {
@ -130,10 +130,10 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
}
// 12. Let hour12 be ? GetOption(options, "hour12", "boolean", undefined, undefined).
auto hour12 = TRY(get_option(global_object, *options, vm.names.hour12, OptionType::Boolean, {}, Empty {}));
auto hour12 = TRY(get_option(vm, *options, vm.names.hour12, OptionType::Boolean, {}, Empty {}));
// 13. Let hourCycle be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined).
auto hour_cycle = TRY(get_option(global_object, *options, vm.names.hourCycle, OptionType::String, AK::Array { "h11"sv, "h12"sv, "h23"sv, "h24"sv }, Empty {}));
auto hour_cycle = TRY(get_option(vm, *options, vm.names.hourCycle, OptionType::String, AK::Array { "h11"sv, "h12"sv, "h23"sv, "h24"sv }, Empty {}));
// 14. If hour12 is not undefined, then
if (!hour12.is_undefined()) {
@ -274,7 +274,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
else {
// i. Let values be a List whose elements are the strings given in the Values column of the row.
// ii. Let value be ? GetOption(options, prop, "string", values, undefined).
auto value = TRY(get_option(global_object, *options, property, OptionType::String, values, Empty {}));
auto value = TRY(get_option(vm, *options, property, OptionType::String, values, Empty {}));
// d. Set formatOptions.[[<prop>]] to value.
if (!value.is_undefined()) {
@ -290,17 +290,17 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
}));
// 37. Let matcher be ? GetOption(options, "formatMatcher", "string", « "basic", "best fit" », "best fit").
matcher = TRY(get_option(global_object, *options, vm.names.formatMatcher, OptionType::String, AK::Array { "basic"sv, "best fit"sv }, "best fit"sv));
matcher = TRY(get_option(vm, *options, vm.names.formatMatcher, OptionType::String, AK::Array { "basic"sv, "best fit"sv }, "best fit"sv));
// 38. Let dateStyle be ? GetOption(options, "dateStyle", "string", « "full", "long", "medium", "short" », undefined).
auto date_style = TRY(get_option(global_object, *options, vm.names.dateStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {}));
auto date_style = TRY(get_option(vm, *options, vm.names.dateStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {}));
// 39. Set dateTimeFormat.[[DateStyle]] to dateStyle.
if (!date_style.is_undefined())
date_time_format.set_date_style(date_style.as_string().string());
// 40. Let timeStyle be ? GetOption(options, "timeStyle", "string", « "full", "long", "medium", "short" », undefined).
auto time_style = TRY(get_option(global_object, *options, vm.names.timeStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {}));
auto time_style = TRY(get_option(vm, *options, vm.names.timeStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {}));
// 41. Set dateTimeFormat.[[TimeStyle]] to timeStyle.
if (!time_style.is_undefined())

View file

@ -63,7 +63,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "options"sv);
// 5. Set options to ? GetOptionsObject(options).
auto* options = TRY(Temporal::get_options_object(global_object, options_value));
auto* options = TRY(Temporal::get_options_object(vm, options_value));
// 6. Let opt be a new Record.
LocaleOptions opt {};
@ -71,7 +71,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
// 7. Let localeData be %DisplayNames%.[[LocaleData]].
// 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *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));
// 9. Set opt.[[localeMatcher]] to matcher.
opt.locale_matcher = matcher;
@ -80,13 +80,13 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
auto result = resolve_locale(requested_locales, opt, {});
// 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long").
auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "narrow"sv, "short"sv, "long"sv }, "long"sv));
auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "narrow"sv, "short"sv, "long"sv }, "long"sv));
// 12. Set displayNames.[[Style]] to style.
display_names->set_style(style.as_string().string());
// 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "calendar", "dateTimeField" », undefined).
auto type = TRY(get_option(global_object, *options, vm.names.type, OptionType::String, { "language"sv, "region"sv, "script"sv, "currency"sv, "calendar"sv, "dateTimeField"sv }, Empty {}));
auto type = TRY(get_option(vm, *options, vm.names.type, OptionType::String, { "language"sv, "region"sv, "script"sv, "currency"sv, "calendar"sv, "dateTimeField"sv }, Empty {}));
// 14. If type is undefined, throw a TypeError exception.
if (type.is_undefined())
@ -96,7 +96,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
display_names->set_type(type.as_string().string());
// 16. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
auto fallback = TRY(get_option(global_object, *options, vm.names.fallback, OptionType::String, { "code"sv, "none"sv }, "code"sv));
auto fallback = TRY(get_option(vm, *options, vm.names.fallback, OptionType::String, { "code"sv, "none"sv }, "code"sv));
// 17. Set displayNames.[[Fallback]] to fallback.
display_names->set_fallback(fallback.as_string().string());
@ -112,7 +112,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
// 22. Assert: types is a Record (see 12.4.3).
// 23. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect").
auto language_display = TRY(get_option(global_object, *options, vm.names.languageDisplay, OptionType::String, { "dialect"sv, "standard"sv }, "dialect"sv));
auto language_display = TRY(get_option(vm, *options, vm.names.languageDisplay, OptionType::String, { "dialect"sv, "standard"sv }, "dialect"sv));
// 24. Let typeFields be types.[[<type>]].
// 25. Assert: typeFields is a Record (see 12.4.3).

View file

@ -133,9 +133,6 @@ StringView DurationFormat::display_to_string(Display display)
// 1.1.3 ToDurationRecord ( input ), https://tc39.es/proposal-intl-duration-format/#sec-todurationrecord
ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value input)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If Type(input) is not Object, throw a TypeError exception.
if (!input.is_object())
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, input);
@ -164,7 +161,7 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value inp
// i. Set any to true.
any = true;
// ii. Set value to ? ToIntegerWithoutRounding(value).
value_number = TRY(Temporal::to_integer_without_rounding(global_object, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, unit, value));
value_number = TRY(Temporal::to_integer_without_rounding(vm, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, unit, value));
}
// e. Else,
else {
@ -242,11 +239,8 @@ bool is_valid_duration_record(Temporal::DurationRecord const& record)
// 1.1.6 GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle ), https://tc39.es/proposal-intl-duration-format/#sec-getdurationunitoptions
ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, String const& unit, Object const& options, StringView base_style, Span<StringView const> styles_list, StringView digital_base, Optional<String> const& previous_style)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let style be ? GetOption(options, unit, "string", stylesList, undefined).
auto style_value = TRY(get_option(global_object, options, unit, OptionType::String, styles_list, Empty {}));
auto style_value = TRY(get_option(vm, options, unit, OptionType::String, styles_list, Empty {}));
// 2. Let displayDefault be "always".
auto display_default = "always"sv;
@ -276,7 +270,7 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, String
auto display_field = String::formatted("{}Display", unit);
// 5. Let display be ? GetOption(options, displayField, "string", « "auto", "always" », displayDefault).
auto display = TRY(get_option(global_object, options, display_field, OptionType::String, { "auto"sv, "always"sv }, display_default));
auto display = TRY(get_option(vm, options, display_field, OptionType::String, { "auto"sv, "always"sv }, display_default));
// 6. If prevStyle is "numeric" or "2-digit", then
if (previous_style == "numeric"sv || previous_style == "2-digit"sv) {

View file

@ -56,13 +56,13 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject&
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));
// 4. Let options be ? GetOptionsObject(options).
auto* options = TRY(Temporal::get_options_object(global_object, 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").
auto matcher = TRY(get_option(global_object, *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));
// 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
// FIXME: Missing spec step - If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) {
@ -90,7 +90,7 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject&
duration_format->set_numbering_system(result.nu.release_value());
// 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long").
auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv, "digital"sv }, "long"sv));
auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv, "digital"sv }, "long"sv));
// 14. Set durationFormat.[[Style]] to style.
duration_format->set_style(style.as_string().string());

View file

@ -58,13 +58,13 @@ ThrowCompletionOr<Object*> ListFormatConstructor::construct(FunctionObject& new_
auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value));
// 4. Set options to ? GetOptionsObject(options).
auto* options = TRY(Temporal::get_options_object(global_object, options_value));
auto* options = TRY(Temporal::get_options_object(vm, options_value));
// 5. Let opt be a new Record.
LocaleOptions opt {};
// 6. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *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));
// 7. Set opt.[[localeMatcher]] to matcher.
opt.locale_matcher = matcher;
@ -78,13 +78,13 @@ ThrowCompletionOr<Object*> ListFormatConstructor::construct(FunctionObject& new_
list_format->set_locale(move(result.locale));
// 11. Let type be ? GetOption(options, "type", "string", « "conjunction", "disjunction", "unit" », "conjunction").
auto type = TRY(get_option(global_object, *options, vm.names.type, OptionType::String, { "conjunction"sv, "disjunction"sv, "unit"sv }, "conjunction"sv));
auto type = TRY(get_option(vm, *options, vm.names.type, OptionType::String, { "conjunction"sv, "disjunction"sv, "unit"sv }, "conjunction"sv));
// 12. Set listFormat.[[Type]] to type.
list_format->set_type(type.as_string().string());
// 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long").
auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv));
auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv));
// 14. Set listFormat.[[Style]] to style.
list_format->set_style(style.as_string().string());

View file

@ -28,10 +28,7 @@ struct LocaleAndKeys {
// Note: This is not an AO in the spec. This just serves to abstract very similar steps in ApplyOptionsToTag and the Intl.Locale constructor.
static ThrowCompletionOr<Optional<String>> get_string_option(VM& vm, Object const& options, PropertyKey const& property, Function<bool(StringView)> validator, Span<StringView const> values = {})
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
auto option = TRY(get_option(global_object, options, property, OptionType::String, values, Empty {}));
auto option = TRY(get_option(vm, options, property, OptionType::String, values, Empty {}));
if (option.is_undefined())
return Optional<String> {};
@ -311,7 +308,7 @@ ThrowCompletionOr<Object*> LocaleConstructor::construct(FunctionObject& new_targ
opt.kf = TRY(get_string_option(vm, *options, vm.names.caseFirst, nullptr, AK::Array { "upper"sv, "lower"sv, "false"sv }));
// 23. Let kn be ? GetOption(options, "numeric", "boolean", undefined, undefined).
auto kn = TRY(get_option(global_object, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {}));
auto kn = TRY(get_option(vm, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {}));
// 24. If kn is not undefined, set kn to ! ToString(kn).
// 25. Set opt.[[kn]] to kn.

View file

@ -83,9 +83,6 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatConstructor::supported_locales_of)
// 1.1.2 InitializeNumberFormat ( numberFormat, locales, options ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-initializenumberformat
ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat& number_format, Value locales_value, Value options_value)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value));
@ -96,13 +93,13 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat&
LocaleOptions opt {};
// 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *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));
// 5. Set opt.[[localeMatcher]] to matcher.
opt.locale_matcher = matcher;
// 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
// 7. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) {
@ -164,7 +161,7 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat&
}
// 18. Let notation be ? GetOption(options, "notation", "string", « "standard", "scientific", "engineering", "compact" », "standard").
auto notation = TRY(get_option(global_object, *options, vm.names.notation, OptionType::String, { "standard"sv, "scientific"sv, "engineering"sv, "compact"sv }, "standard"sv));
auto notation = TRY(get_option(vm, *options, vm.names.notation, OptionType::String, { "standard"sv, "scientific"sv, "engineering"sv, "compact"sv }, "standard"sv));
// 19. Set numberFormat.[[Notation]] to notation.
number_format.set_notation(notation.as_string().string());
@ -193,13 +190,13 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat&
number_format.set_rounding_increment(*rounding_increment);
// 26. Let trailingZeroDisplay be ? GetOption(options, "trailingZeroDisplay", "string", « "auto", "stripIfInteger" », "auto").
auto trailing_zero_display = TRY(get_option(global_object, *options, vm.names.trailingZeroDisplay, OptionType::String, { "auto"sv, "stripIfInteger"sv }, "auto"sv));
auto trailing_zero_display = TRY(get_option(vm, *options, vm.names.trailingZeroDisplay, OptionType::String, { "auto"sv, "stripIfInteger"sv }, "auto"sv));
// 27. Set numberFormat.[[TrailingZeroDisplay]] to trailingZeroDisplay.
number_format.set_trailing_zero_display(trailing_zero_display.as_string().string());
// 28. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
auto compact_display = TRY(get_option(global_object, *options, vm.names.compactDisplay, OptionType::String, { "short"sv, "long"sv }, "short"sv));
auto compact_display = TRY(get_option(vm, *options, vm.names.compactDisplay, OptionType::String, { "short"sv, "long"sv }, "short"sv));
// 29. Let defaultUseGrouping be "auto".
auto default_use_grouping = "auto"sv;
@ -220,13 +217,13 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat&
number_format.set_use_grouping(use_grouping);
// 33. Let signDisplay be ? GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero, "negative" », "auto").
auto sign_display = TRY(get_option(global_object, *options, vm.names.signDisplay, OptionType::String, { "auto"sv, "never"sv, "always"sv, "exceptZero"sv, "negative"sv }, "auto"sv));
auto sign_display = TRY(get_option(vm, *options, vm.names.signDisplay, OptionType::String, { "auto"sv, "never"sv, "always"sv, "exceptZero"sv, "negative"sv }, "auto"sv));
// 34. Set numberFormat.[[SignDisplay]] to signDisplay.
number_format.set_sign_display(sign_display.as_string().string());
// 35. Let roundingMode be ? GetOption(options, "roundingMode", "string", « "ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven" », "halfExpand").
auto rounding_mode = TRY(get_option(global_object, *options, vm.names.roundingMode, OptionType::String, { "ceil"sv, "floor"sv, "expand"sv, "trunc"sv, "halfCeil"sv, "halfFloor"sv, "halfExpand"sv, "halfTrunc"sv, "halfEven"sv }, "halfExpand"sv));
auto rounding_mode = TRY(get_option(vm, *options, vm.names.roundingMode, OptionType::String, { "ceil"sv, "floor"sv, "expand"sv, "trunc"sv, "halfCeil"sv, "halfFloor"sv, "halfExpand"sv, "halfTrunc"sv, "halfEven"sv }, "halfExpand"sv));
// 36. Set numberFormat.[[RoundingMode]] to roundingMode.
number_format.set_rounding_mode(rounding_mode.as_string().string());
@ -239,9 +236,6 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat&
// 1.1.1 SetNumberFormatDigitOptions ( intlObj, options, mnfdDefault, mxfdDefault, notation ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-setnfdigitoptions
ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase& intl_object, Object const& options, int default_min_fraction_digits, int default_max_fraction_digits, NumberFormat::Notation notation)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let mnid be ? GetNumberOption(options, "minimumIntegerDigits,", 1, 21, 1).
auto min_integer_digits = TRY(get_number_option(vm, options, vm.names.minimumIntegerDigits, 1, 21, 1));
@ -261,7 +255,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
intl_object.set_min_integer_digits(*min_integer_digits);
// 7. Let roundingPriority be ? GetOption(options, "roundingPriority", "string", « "auto", "morePrecision", "lessPrecision" », "auto").
auto rounding_priority = TRY(get_option(global_object, options, vm.names.roundingPriority, OptionType::String, { "auto"sv, "morePrecision"sv, "lessPrecision"sv }, "auto"sv));
auto rounding_priority = TRY(get_option(vm, options, vm.names.roundingPriority, OptionType::String, { "auto"sv, "morePrecision"sv, "lessPrecision"sv }, "auto"sv));
// 8. If mnsd is not undefined or mxsd is not undefined, then
// a. Let hasSd be true.
@ -403,20 +397,17 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
// 15.1.4 SetNumberFormatUnitOptions ( intlObj, options ), https://tc39.es/ecma402/#sec-setnumberformatunitoptions
ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& intl_object, Object const& options)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(intlObj) is Object.
// 2. Assert: Type(options) is Object.
// 3. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal").
auto style = TRY(get_option(global_object, options, vm.names.style, OptionType::String, { "decimal"sv, "percent"sv, "currency"sv, "unit"sv }, "decimal"sv));
auto style = TRY(get_option(vm, options, vm.names.style, OptionType::String, { "decimal"sv, "percent"sv, "currency"sv, "unit"sv }, "decimal"sv));
// 4. Set intlObj.[[Style]] to style.
intl_object.set_style(style.as_string().string());
// 5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
auto currency = TRY(get_option(global_object, options, vm.names.currency, OptionType::String, {}, Empty {}));
auto currency = TRY(get_option(vm, options, vm.names.currency, OptionType::String, {}, Empty {}));
// 6. If currency is undefined, then
if (currency.is_undefined()) {
@ -430,13 +421,13 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, currency, "currency"sv);
// 8. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol").
auto currency_display = TRY(get_option(global_object, options, vm.names.currencyDisplay, OptionType::String, { "code"sv, "symbol"sv, "narrowSymbol"sv, "name"sv }, "symbol"sv));
auto currency_display = TRY(get_option(vm, options, vm.names.currencyDisplay, OptionType::String, { "code"sv, "symbol"sv, "narrowSymbol"sv, "name"sv }, "symbol"sv));
// 9. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard").
auto currency_sign = TRY(get_option(global_object, options, vm.names.currencySign, OptionType::String, { "standard"sv, "accounting"sv }, "standard"sv));
auto currency_sign = TRY(get_option(vm, options, vm.names.currencySign, OptionType::String, { "standard"sv, "accounting"sv }, "standard"sv));
// 10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
auto unit = TRY(get_option(global_object, options, vm.names.unit, OptionType::String, {}, Empty {}));
auto unit = TRY(get_option(vm, options, vm.names.unit, OptionType::String, {}, Empty {}));
// 11. If unit is undefined, then
if (unit.is_undefined()) {
@ -450,7 +441,7 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, unit, "unit"sv);
// 13. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short").
auto unit_display = TRY(get_option(global_object, options, vm.names.unitDisplay, OptionType::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv));
auto unit_display = TRY(get_option(vm, options, vm.names.unitDisplay, OptionType::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv));
// 14. If style is "currency", then
if (intl_object.style() == NumberFormat::Style::Currency) {

View file

@ -76,9 +76,6 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesConstructor::supported_locales_of)
// 16.1.2 InitializePluralRules ( pluralRules, locales, options ), https://tc39.es/ecma402/#sec-initializepluralrules
ThrowCompletionOr<PluralRules*> initialize_plural_rules(VM& vm, PluralRules& plural_rules, Value locales_value, Value options_value)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value));
@ -89,13 +86,13 @@ ThrowCompletionOr<PluralRules*> initialize_plural_rules(VM& vm, PluralRules& plu
LocaleOptions opt {};
// 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv));
auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv));
// 5. Set opt.[[localeMatcher]] to matcher.
opt.locale_matcher = matcher;
// 6. Let t be ? GetOption(options, "type", "string", « "cardinal", "ordinal" », "cardinal").
auto type = TRY(get_option(global_object, *options, vm.names.type, OptionType::String, AK::Array { "cardinal"sv, "ordinal"sv }, "cardinal"sv));
auto type = TRY(get_option(vm, *options, vm.names.type, OptionType::String, AK::Array { "cardinal"sv, "ordinal"sv }, "cardinal"sv));
// 7. Set pluralRules.[[Type]] to t.
plural_rules.set_type(type.as_string().string());

View file

@ -92,13 +92,13 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
LocaleOptions opt {};
// 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv));
auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv));
// 5. Set opt.[[LocaleMatcher]] to matcher.
opt.locale_matcher = matcher;
// 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
// 7. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) {
@ -128,13 +128,13 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
relative_time_format.set_numbering_system(result.nu.release_value());
// 15. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long").
auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv));
auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv));
// 16. Set relativeTimeFormat.[[Style]] to style.
relative_time_format.set_style(style.as_string().string());
// 17. Let numeric be ? GetOption(options, "numeric", "string", « "always", "auto" », "always").
auto numeric = TRY(get_option(global_object, *options, vm.names.numeric, OptionType::String, { "always"sv, "auto"sv }, "always"sv));
auto numeric = TRY(get_option(vm, *options, vm.names.numeric, OptionType::String, { "always"sv, "auto"sv }, "always"sv));
// 18. Set relativeTimeFormat.[[Numeric]] to numeric.
relative_time_format.set_numeric(numeric.as_string().string());

View file

@ -58,13 +58,13 @@ ThrowCompletionOr<Object*> SegmenterConstructor::construct(FunctionObject& new_t
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));
// 5. Set options to ? GetOptionsObject(options).
auto* options = TRY(Temporal::get_options_object(global_object, options_value));
auto* options = TRY(Temporal::get_options_object(vm, options_value));
// 6. Let opt be a new Record.
LocaleOptions opt {};
// 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
auto matcher = TRY(get_option(global_object, *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));
// 8. Set opt.[[localeMatcher]] to matcher.
opt.locale_matcher = matcher;
@ -78,7 +78,7 @@ ThrowCompletionOr<Object*> SegmenterConstructor::construct(FunctionObject& new_t
segmenter->set_locale(move(result.locale));
// 12. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme").
auto granularity = TRY(get_option(global_object, *options, vm.names.granularity, OptionType::String, { "grapheme"sv, "word"sv, "sentence"sv }, "grapheme"sv));
auto granularity = TRY(get_option(vm, *options, vm.names.granularity, OptionType::String, { "grapheme"sv, "word"sv, "sentence"sv }, "grapheme"sv));
// 13. Set segmenter.[[SegmenterGranularity]] to granularity.
segmenter->set_segmenter_granularity(granularity.as_string().string());

View file

@ -39,16 +39,16 @@ static Optional<OptionType> to_option_type(Value value)
}
// 13.1 IterableToListOfType ( items, elementTypes ), https://tc39.es/proposal-temporal/#sec-iterabletolistoftype
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(GlobalObject& global_object, Value items, Vector<OptionType> const& element_types)
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(VM& vm, Value items, Vector<OptionType> const& element_types)
{
auto& vm = global_object.vm();
auto& heap = global_object.heap();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let iteratorRecord be ? GetIterator(items, sync).
auto iterator_record = TRY(get_iterator(global_object, items, IteratorHint::Sync));
// 2. Let values be a new empty List.
MarkedVector<Value> values(heap);
MarkedVector<Value> values(vm.heap());
// 3. Let next be true.
auto next = true;
@ -79,10 +79,9 @@ ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(GlobalObject& gl
}
// 13.2 GetOptionsObject ( options ), https://tc39.es/proposal-temporal/#sec-getoptionsobject
ThrowCompletionOr<Object*> get_options_object(GlobalObject& global_object, Value options)
ThrowCompletionOr<Object*> get_options_object(VM& vm, Value options)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. If options is undefined, then
if (options.is_undefined()) {
@ -101,11 +100,12 @@ ThrowCompletionOr<Object*> get_options_object(GlobalObject& global_object, Value
}
// 13.3 GetOption ( options, property, type, values, fallback ), https://tc39.es/proposal-temporal/#sec-getoption
ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& options, PropertyKey const& property, OptionType type, Span<StringView const> values, OptionDefault const& default_)
ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey const& property, OptionType type, Span<StringView const> values, OptionDefault const& default_)
{
VERIFY(property.is_string());
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let value be ? Get(options, property).
auto value = TRY(options.get(property));
@ -161,44 +161,38 @@ ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& o
}
// 13.4 ToTemporalOverflow ( options ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaloverflow
ThrowCompletionOr<String> to_temporal_overflow(GlobalObject& global_object, Object const* options)
ThrowCompletionOr<String> to_temporal_overflow(VM& vm, Object const* options)
{
auto& vm = global_object.vm();
// 1. If options is undefined, return "constrain".
if (options == nullptr)
return "constrain"sv;
// 2. Return ? GetOption(options, "overflow", "string", « "constrain", "reject" », "constrain").
auto option = TRY(get_option(global_object, *options, vm.names.overflow, OptionType::String, { "constrain"sv, "reject"sv }, "constrain"sv));
auto option = TRY(get_option(vm, *options, vm.names.overflow, OptionType::String, { "constrain"sv, "reject"sv }, "constrain"sv));
VERIFY(option.is_string());
return option.as_string().string();
}
// 13.5 ToTemporalDisambiguation ( options ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldisambiguation
ThrowCompletionOr<String> to_temporal_disambiguation(GlobalObject& global_object, Object const* options)
ThrowCompletionOr<String> to_temporal_disambiguation(VM& vm, Object const* options)
{
auto& vm = global_object.vm();
// 1. If options is undefined, return "compatible".
if (options == nullptr)
return "compatible"sv;
// 2. Return ? GetOption(options, "disambiguation", "string", « "compatible", "earlier", "later", "reject" », "compatible").
auto option = TRY(get_option(global_object, *options, vm.names.disambiguation, OptionType::String, { "compatible"sv, "earlier"sv, "later"sv, "reject"sv }, "compatible"sv));
auto option = TRY(get_option(vm, *options, vm.names.disambiguation, OptionType::String, { "compatible"sv, "earlier"sv, "later"sv, "reject"sv }, "compatible"sv));
VERIFY(option.is_string());
return option.as_string().string();
}
// 13.6 ToTemporalRoundingMode ( normalizedOptions, fallback ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalroundingmode
ThrowCompletionOr<String> to_temporal_rounding_mode(GlobalObject& global_object, Object const& normalized_options, String const& fallback)
ThrowCompletionOr<String> to_temporal_rounding_mode(VM& vm, Object const& normalized_options, String const& fallback)
{
auto& vm = global_object.vm();
// 1. Return ? GetOption(normalizedOptions, "roundingMode", "string", « "ceil", "floor", "trunc", "halfExpand" », fallback).
auto option = TRY(get_option(global_object, normalized_options, vm.names.roundingMode, OptionType::String, { "ceil"sv, "floor"sv, "trunc"sv, "halfExpand"sv }, fallback.view()));
auto option = TRY(get_option(vm, normalized_options, vm.names.roundingMode, OptionType::String, { "ceil"sv, "floor"sv, "trunc"sv, "halfExpand"sv }, fallback.view()));
VERIFY(option.is_string());
return option.as_string().string();
@ -220,62 +214,52 @@ StringView negate_temporal_rounding_mode(String const& rounding_mode)
}
// 13.8 ToTemporalOffset ( options, fallback ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaloffset
ThrowCompletionOr<String> to_temporal_offset(GlobalObject& global_object, Object const* options, String const& fallback)
ThrowCompletionOr<String> to_temporal_offset(VM& vm, Object const* options, String const& fallback)
{
auto& vm = global_object.vm();
// 1. If options is undefined, return fallback.
if (options == nullptr)
return fallback;
// 2. Return ? GetOption(options, "offset", "string", « "prefer", "use", "ignore", "reject" », fallback).
auto option = TRY(get_option(global_object, *options, vm.names.offset, OptionType::String, { "prefer"sv, "use"sv, "ignore"sv, "reject"sv }, fallback.view()));
auto option = TRY(get_option(vm, *options, vm.names.offset, OptionType::String, { "prefer"sv, "use"sv, "ignore"sv, "reject"sv }, fallback.view()));
VERIFY(option.is_string());
return option.as_string().string();
}
// 13.9 ToShowCalendarOption ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-toshowcalendaroption
ThrowCompletionOr<String> to_show_calendar_option(GlobalObject& global_object, Object const& normalized_options)
ThrowCompletionOr<String> to_show_calendar_option(VM& vm, Object const& normalized_options)
{
auto& vm = global_object.vm();
// 1. Return ? GetOption(normalizedOptions, "calendarName", "string", « "auto", "always", "never" », "auto").
auto option = TRY(get_option(global_object, normalized_options, vm.names.calendarName, OptionType::String, { "auto"sv, "always"sv, "never"sv }, "auto"sv));
auto option = TRY(get_option(vm, normalized_options, vm.names.calendarName, OptionType::String, { "auto"sv, "always"sv, "never"sv }, "auto"sv));
VERIFY(option.is_string());
return option.as_string().string();
}
// 13.10 ToShowTimeZoneNameOption ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-toshowtimezonenameoption
ThrowCompletionOr<String> to_show_time_zone_name_option(GlobalObject& global_object, Object const& normalized_options)
ThrowCompletionOr<String> to_show_time_zone_name_option(VM& vm, Object const& normalized_options)
{
auto& vm = global_object.vm();
// 1. Return ? GetOption(normalizedOptions, "timeZoneName", "string, « "auto", "never" », "auto").
auto option = TRY(get_option(global_object, normalized_options, vm.names.timeZoneName, OptionType::String, { "auto"sv, "never"sv }, "auto"sv));
auto option = TRY(get_option(vm, normalized_options, vm.names.timeZoneName, OptionType::String, { "auto"sv, "never"sv }, "auto"sv));
VERIFY(option.is_string());
return option.as_string().string();
}
// 13.11 ToShowOffsetOption ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-toshowoffsetoption
ThrowCompletionOr<String> to_show_offset_option(GlobalObject& global_object, Object const& normalized_options)
ThrowCompletionOr<String> to_show_offset_option(VM& vm, Object const& normalized_options)
{
auto& vm = global_object.vm();
// 1. Return ? GetOption(normalizedOptions, "offset", "string", « "auto", "never" », "auto").
auto option = TRY(get_option(global_object, normalized_options, vm.names.offset, OptionType::String, { "auto"sv, "never"sv }, "auto"sv));
auto option = TRY(get_option(vm, normalized_options, vm.names.offset, OptionType::String, { "auto"sv, "never"sv }, "auto"sv));
VERIFY(option.is_string());
return option.as_string().string();
}
// 13.12 ToTemporalRoundingIncrement ( normalizedOptions, dividend, inclusive ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalroundingincrement
ThrowCompletionOr<u64> to_temporal_rounding_increment(GlobalObject& global_object, Object const& normalized_options, Optional<double> dividend, bool inclusive)
ThrowCompletionOr<u64> to_temporal_rounding_increment(VM& vm, Object const& normalized_options, Optional<double> dividend, bool inclusive)
{
auto& vm = global_object.vm();
double maximum;
// 1. If dividend is undefined, then
if (!dividend.has_value()) {
@ -299,7 +283,7 @@ ThrowCompletionOr<u64> to_temporal_rounding_increment(GlobalObject& global_objec
}
// 5. Let increment be ? GetOption(normalizedOptions, "roundingIncrement", "number", undefined, 1𝔽).
auto increment_value = TRY(get_option(global_object, normalized_options, vm.names.roundingIncrement, OptionType::Number, {}, 1.0));
auto increment_value = TRY(get_option(vm, normalized_options, vm.names.roundingIncrement, OptionType::Number, {}, 1.0));
VERIFY(increment_value.is_number());
auto increment = increment_value.as_double();
@ -320,7 +304,7 @@ ThrowCompletionOr<u64> to_temporal_rounding_increment(GlobalObject& global_objec
}
// 13.13 ToTemporalDateTimeRoundingIncrement ( normalizedOptions, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetimeroundingincrement
ThrowCompletionOr<u64> to_temporal_date_time_rounding_increment(GlobalObject& global_object, Object const& normalized_options, StringView smallest_unit)
ThrowCompletionOr<u64> to_temporal_date_time_rounding_increment(VM& vm, Object const& normalized_options, StringView smallest_unit)
{
u16 maximum;
@ -337,16 +321,17 @@ ThrowCompletionOr<u64> to_temporal_date_time_rounding_increment(GlobalObject& gl
}
// 3. Return ? ToTemporalRoundingIncrement(normalizedOptions, maximum, false).
return to_temporal_rounding_increment(global_object, normalized_options, maximum, false);
return to_temporal_rounding_increment(vm, normalized_options, maximum, false);
}
// 13.14 ToSecondsStringPrecision ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-tosecondsstringprecision
ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(GlobalObject& global_object, Object const& normalized_options)
ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM& vm, Object const& normalized_options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let smallestUnit be ? GetTemporalUnit(normalizedOptions, "smallestUnit", time, undefined).
auto smallest_unit = TRY(get_temporal_unit(global_object, normalized_options, vm.names.smallestUnit, UnitGroup::Time, Optional<StringView> {}));
auto smallest_unit = TRY(get_temporal_unit(vm, normalized_options, vm.names.smallestUnit, UnitGroup::Time, Optional<StringView> {}));
// 2. If smallestUnit is "hour", throw a RangeError exception.
if (smallest_unit == "hour"sv)
@ -460,10 +445,8 @@ static Vector<TemporalUnit> temporal_units = {
};
// 13.15 GetTemporalUnit ( normalizedOptions, key, unitGroup, default [ , extraValues ] ), https://tc39.es/proposal-temporal/#sec-temporal-gettemporalunit
ThrowCompletionOr<Optional<String>> get_temporal_unit(GlobalObject& global_object, Object const& normalized_options, PropertyKey const& key, UnitGroup unit_group, TemporalUnitDefault const& default_, Vector<StringView> const& extra_values)
ThrowCompletionOr<Optional<String>> get_temporal_unit(VM& vm, Object const& normalized_options, PropertyKey const& key, UnitGroup unit_group, TemporalUnitDefault const& default_, Vector<StringView> const& extra_values)
{
auto& vm = global_object.vm();
// 1. Let singularNames be a new empty List.
Vector<StringView> singular_names;
@ -527,7 +510,7 @@ ThrowCompletionOr<Optional<String>> get_temporal_unit(GlobalObject& global_objec
// 8. NOTE: For each singular Temporal unit name that is contained within allowedValues, the corresponding plural name is also contained within it.
// 9. Let value be ? GetOption(normalizedOptions, key, "string", allowedValues, defaultValue).
auto option_value = TRY(get_option(global_object, normalized_options, key, OptionType::String, allowed_values.span(), default_value));
auto option_value = TRY(get_option(vm, normalized_options, key, OptionType::String, allowed_values.span(), default_value));
// 10. If value is undefined and default is required, throw a RangeError exception.
if (option_value.is_undefined() && default_.has<TemporalUnitRequired>())
@ -550,10 +533,10 @@ ThrowCompletionOr<Optional<String>> get_temporal_unit(GlobalObject& global_objec
}
// 13.16 ToRelativeTemporalObject ( options ), https://tc39.es/proposal-temporal/#sec-temporal-torelativetemporalobject
ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object, Object const& options)
ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& options)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(options) is Object.
@ -592,17 +575,17 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
auto& plain_date_time = static_cast<PlainDateTime&>(value_object);
// i. Return ? CreateTemporalDate(value.[[ISOYear]], value.[[ISOMonth]], value.[[ISODay]], 0, 0, 0, 0, 0, 0, value.[[Calendar]]).
return TRY(create_temporal_date(global_object, plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.calendar()));
return TRY(create_temporal_date(vm, plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.calendar()));
}
// c. Let calendar be ? GetTemporalCalendarWithISODefault(value).
calendar = TRY(get_temporal_calendar_with_iso_default(global_object, value_object));
calendar = TRY(get_temporal_calendar_with_iso_default(vm, value_object));
// d. Let fieldNames be ? CalendarFields(calendar, « "day", "hour", "microsecond", "millisecond", "minute", "month", "monthCode", "nanosecond", "second", "year" »).
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// e. Let fields be ? PrepareTemporalFields(value, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, value_object, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, value_object, field_names, Vector<StringView> {}));
// f. Let dateOptions be OrdinaryObjectCreate(null).
auto* date_options = Object::create(realm, nullptr);
@ -611,7 +594,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
MUST(date_options->create_data_property_or_throw(vm.names.overflow, js_string(vm, "constrain"sv)));
// h. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, dateOptions).
result = TRY(interpret_temporal_date_time_fields(global_object, *calendar, *fields, *date_options));
result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *date_options));
// i. Let offsetString be ? Get(value, "offset").
offset_string = TRY(value_object.get(vm.names.offset));
@ -622,7 +605,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
// k. If timeZone is not undefined, then
if (!time_zone.is_undefined()) {
// i. Set timeZone to ? ToTemporalTimeZone(timeZone).
time_zone = TRY(to_temporal_time_zone(global_object, time_zone));
time_zone = TRY(to_temporal_time_zone(vm, time_zone));
}
// l. If offsetString is undefined, then
@ -637,13 +620,13 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
auto string = TRY(value.to_string(global_object));
// b. Let result be ? ParseTemporalRelativeToString(string).
auto parsed_result = TRY(parse_temporal_relative_to_string(global_object, string));
auto parsed_result = TRY(parse_temporal_relative_to_string(vm, string));
// NOTE: The ISODateTime struct inside `parsed_result` will be moved into `result` at the end of this path to avoid mismatching names.
// Thus, all remaining references to `result` in this path actually refer to `parsed_result`.
// c. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
calendar = TRY(to_temporal_calendar_with_iso_default(global_object, parsed_result.date_time.calendar.has_value() ? js_string(vm, *parsed_result.date_time.calendar) : js_undefined()));
calendar = TRY(to_temporal_calendar_with_iso_default(vm, parsed_result.date_time.calendar.has_value() ? js_string(vm, *parsed_result.date_time.calendar) : js_undefined()));
// d. Let offsetString be result.[[TimeZoneOffsetString]].
offset_string = parsed_result.time_zone.offset_string.has_value() ? js_string(vm, *parsed_result.time_zone.offset_string) : js_undefined();
@ -664,7 +647,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
}
// ii. Let timeZone be ! CreateTemporalTimeZone(timeZoneName).
time_zone = MUST(create_temporal_time_zone(global_object, *time_zone_name));
time_zone = MUST(create_temporal_time_zone(vm, *time_zone_name));
}
// g. Else,
else {
@ -701,7 +684,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
auto actual_offset_string = TRY(offset_string.to_string(global_object));
// ii. Let offsetNs be ? ParseTimeZoneOffsetString(offsetString).
offset_ns = TRY(parse_time_zone_offset_string(global_object, actual_offset_string));
offset_ns = TRY(parse_time_zone_offset_string(vm, actual_offset_string));
}
// b. Else,
else {
@ -710,14 +693,14 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
}
// c. Let epochNanoseconds be ? InterpretISODateTimeOffset(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], offsetBehaviour, offsetNs, timeZone, "compatible", "reject", matchBehaviour).
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_ns, time_zone, "compatible"sv, "reject"sv, match_behavior));
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_ns, time_zone, "compatible"sv, "reject"sv, match_behavior));
// d. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, *epoch_nanoseconds, time_zone.as_object(), *calendar));
return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone.as_object(), *calendar));
}
// 9. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
return TRY(create_temporal_date(global_object, result.year, result.month, result.day, *calendar));
return TRY(create_temporal_date(vm, result.year, result.month, result.day, *calendar));
}
// 13.17 LargerOfTwoTemporalUnits ( u1, u2 ), https://tc39.es/proposal-temporal/#sec-temporal-largeroftwotemporalunits
@ -742,10 +725,10 @@ StringView larger_of_two_temporal_units(StringView unit1, StringView unit2)
}
// 13.18 MergeLargestUnitOption ( options, largestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-mergelargestunitoption
ThrowCompletionOr<Object*> merge_largest_unit_option(GlobalObject& global_object, Object const& options, String largest_unit)
ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& options, String largest_unit)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let merged be OrdinaryObjectCreate(null).
auto* merged = Object::create(realm, nullptr);
@ -800,10 +783,8 @@ Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit)
}
// 13.20 RejectObjectWithCalendarOrTimeZone ( object ), https://tc39.es/proposal-temporal/#sec-temporal-rejectobjectwithcalendarortimezone
ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(GlobalObject& global_object, Object& object)
ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(VM& vm, Object& object)
{
auto& vm = global_object.vm();
// 1. Assert: Type(object) is Object.
// 2. If object has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalTime]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
@ -1193,10 +1174,8 @@ Crypto::SignedBigInteger round_number_to_increment_as_if_positive(Crypto::Signed
}
// 13.28 ParseISODateTime ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parseisodatetime
ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object, ParseResult const& parse_result)
ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& parse_result)
{
auto& vm = global_object.vm();
// 1. Let parseResult be empty.
// 2. For each nonterminal goal of « TemporalDateTimeString, TemporalInstantString, TemporalMonthDayString, TemporalTimeString, TemporalYearMonthString, TemporalZonedDateTimeString », do
// a. If parseResult is not a Parse Node, set parseResult to ParseText(StringToCodePoints(isoString), goal).
@ -1340,20 +1319,18 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
}
// 13.29 ParseTemporalInstantString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalinstantstring
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. If ParseText(StringToCodePoints(isoString), TemporalInstantString) is a List of errors, throw a RangeError exception.
auto parse_result = parse_iso8601(Production::TemporalInstantString, iso_string);
if (!parse_result.has_value())
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidInstantString, iso_string);
// 2. Let result be ? ParseISODateTime(isoString).
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
auto result = TRY(parse_iso_date_time(vm, *parse_result));
// 3. Let timeZoneResult be ? ParseTemporalTimeZoneString(isoString).
auto time_zone_result = TRY(parse_temporal_time_zone_string(global_object, iso_string));
auto time_zone_result = TRY(parse_temporal_time_zone_string(vm, iso_string));
// 4. Let offsetString be timeZoneResult.[[OffsetString]].
auto offset_string = time_zone_result.offset_string;
@ -1372,20 +1349,18 @@ ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(GlobalObject& g
}
// 13.30 ParseTemporalZonedDateTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalzoneddatetimestring
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_zoned_date_time_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_zoned_date_time_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. If ParseText(StringToCodePoints(isoString), TemporalZonedDateTimeString) is a List of errors, throw a RangeError exception.
auto parse_result = parse_iso8601(Production::TemporalZonedDateTimeString, iso_string);
if (!parse_result.has_value())
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidZonedDateTimeString, iso_string);
// 2. Let result be ? ParseISODateTime(isoString).
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
auto result = TRY(parse_iso_date_time(vm, *parse_result));
// 3. Let timeZoneResult be ? ParseTemporalTimeZoneString(isoString).
auto time_zone_result = TRY(parse_temporal_time_zone_string(global_object, iso_string));
auto time_zone_result = TRY(parse_temporal_time_zone_string(vm, iso_string));
// 4. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[Hour]]: result.[[Hour]], [[Minute]]: result.[[Minute]], [[Second]]: result.[[Second]], [[Millisecond]]: result.[[Millisecond]], [[Microsecond]]: result.[[Microsecond]], [[Nanosecond]]: result.[[Nanosecond]], [[Calendar]]: result.[[Calendar]], [[TimeZoneZ]]: timeZoneResult.[[Z]], [[TimeZoneOffsetString]]: timeZoneResult.[[OffsetString]], [[TimeZoneName]]: timeZoneResult.[[Name]] }.
// NOTE: This returns the two structs together instead of separated to avoid a copy in ToTemporalZonedDateTime, as the spec tries to put the result of InterpretTemporalDateTimeFields and ParseTemporalZonedDateTimeString into the same `result` variable.
@ -1394,10 +1369,8 @@ ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_zoned_date_time_string(G
}
// 13.31 ParseTemporalCalendarString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalcalendarstring
ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Let parseResult be ParseText(StringToCodePoints(isoString), TemporalCalendarString).
auto parse_result = parse_iso8601(Production::TemporalCalendarString, iso_string);
@ -1419,20 +1392,18 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject& global_ob
}
// 13.32 ParseTemporalDateString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatestring
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(VM& vm, String const& iso_string)
{
// 1. Let parts be ? ParseTemporalDateTimeString(isoString).
auto parts = TRY(parse_temporal_date_time_string(global_object, iso_string));
auto parts = TRY(parse_temporal_date_time_string(vm, iso_string));
// 2. Return the Record { [[Year]]: parts.[[Year]], [[Month]]: parts.[[Month]], [[Day]]: parts.[[Day]], [[Calendar]]: parts.[[Calendar]] }.
return TemporalDate { .year = parts.year, .month = parts.month, .day = parts.day, .calendar = move(parts.calendar) };
}
// 13.33 ParseTemporalDateTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatetimestring
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Let parseResult be ParseText(StringToCodePoints(isoString), TemporalDateTimeString).
auto parse_result = parse_iso8601(Production::TemporalDateTimeString, iso_string);
@ -1445,14 +1416,12 @@ ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(GlobalObject& glo
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDateTimeStringUTCDesignator, iso_string);
// 4. Return ? ParseISODateTime(isoString).
return parse_iso_date_time(global_object, *parse_result);
return parse_iso_date_time(vm, *parse_result);
}
// 13.34 ParseTemporalDurationString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldurationstring
ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Let duration be ParseText(StringToCodePoints(isoString), TemporalDurationString).
auto parse_result = parse_iso8601(Production::TemporalDurationString, iso_string);
@ -1585,14 +1554,12 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
}
// 20. Return ? CreateDurationRecord(yearsMV × factor, monthsMV × factor, weeksMV × factor, daysMV × factor, hoursMV × factor, floor(minutesMV) × factor, floor(secondsMV) × factor, floor(millisecondsMV) × factor, floor(microsecondsMV) × factor, floor(nanosecondsMV) × factor).
return create_duration_record(global_object, years * factor, months * factor, weeks * factor, days * factor, hours * factor, floor(minutes) * factor, floor(seconds) * factor, floor(milliseconds) * factor, floor(microseconds) * factor, floor(nanoseconds) * factor);
return create_duration_record(vm, years * factor, months * factor, weeks * factor, days * factor, hours * factor, floor(minutes) * factor, floor(seconds) * factor, floor(milliseconds) * factor, floor(microseconds) * factor, floor(nanoseconds) * factor);
}
// 13.35 ParseTemporalMonthDayString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalmonthdaystring
ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Let parseResult be ParseText(StringToCodePoints(isoString), TemporalMonthDayString).
auto parse_result = parse_iso8601(Production::TemporalMonthDayString, iso_string);
@ -1605,7 +1572,7 @@ ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(GlobalObject
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidMonthDayStringUTCDesignator, iso_string);
// 4. Let result be ? ParseISODateTime(isoString).
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
auto result = TRY(parse_iso_date_time(vm, *parse_result));
// 5. Let year be result.[[Year]].
Optional<i32> year = result.year;
@ -1621,17 +1588,15 @@ ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(GlobalObject
}
// 13.36 ParseTemporalRelativeToString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalrelativetostring
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. If ParseText(StringToCodePoints(isoString), TemporalDateTimeString) is a List of errors, throw a RangeError exception.
auto parse_result = parse_iso8601(Production::TemporalDateTimeString, iso_string);
if (!parse_result.has_value())
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDateTimeString, iso_string);
// 2. Let result be ? ParseISODateTime(isoString).
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
auto result = TRY(parse_iso_date_time(vm, *parse_result));
bool z;
Optional<String> offset_string;
@ -1641,7 +1606,7 @@ ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(Globa
parse_result = parse_iso8601(Production::TemporalZonedDateTimeString, iso_string);
if (parse_result.has_value()) {
// a. Let timeZoneResult be ! ParseTemporalTimeZoneString(isoString).
auto time_zone_result = MUST(parse_temporal_time_zone_string(global_object, iso_string));
auto time_zone_result = MUST(parse_temporal_time_zone_string(vm, iso_string));
// b. Let z be timeZoneResult.[[Z]].
z = time_zone_result.z;
@ -1666,10 +1631,8 @@ ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(Globa
}
// 13.37 ParseTemporalTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimestring
ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalTime> parse_temporal_time_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Let parseResult be ParseText(StringToCodePoints(isoString), TemporalTimeString).
auto parse_result = parse_iso8601(Production::TemporalTimeString, iso_string);
@ -1682,17 +1645,15 @@ ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject& global_
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeStringUTCDesignator, iso_string);
// 4. Let result be ? ParseISODateTime(isoString).
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
auto result = TRY(parse_iso_date_time(vm, *parse_result));
// 5. Return the Record { [[Hour]]: result.[[Hour]], [[Minute]]: result.[[Minute]], [[Second]]: result.[[Second]], [[Millisecond]]: result.[[Millisecond]], [[Microsecond]]: result.[[Microsecond]], [[Nanosecond]]: result.[[Nanosecond]], [[Calendar]]: result.[[Calendar]] }.
return TemporalTime { .hour = result.hour, .minute = result.minute, .second = result.second, .millisecond = result.millisecond, .microsecond = result.microsecond, .nanosecond = result.nanosecond, .calendar = move(result.calendar) };
}
// 13.38 ParseTemporalTimeZoneString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimezonestring
ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Let parseResult be ParseText(StringToCodePoints(isoString), TemporalTimeZoneString).
auto parse_result = parse_iso8601(Production::TemporalTimeZoneString, iso_string);
@ -1728,10 +1689,8 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject
}
// 13.39 ParseTemporalYearMonthString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalyearmonthstring
ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Let parseResult be ParseText(StringToCodePoints(isoString), TemporalYearMonthString).
auto parse_result = parse_iso8601(Production::TemporalYearMonthString, iso_string);
@ -1744,19 +1703,17 @@ ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObje
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidYearMonthStringUTCDesignator, iso_string);
// 4. Let result be ? ParseISODateTime(isoString).
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
auto result = TRY(parse_iso_date_time(vm, *parse_result));
// 5. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[Calendar]]: result.[[Calendar]] }.
return TemporalYearMonth { .year = result.year, .month = result.month, .day = result.day, .calendar = move(result.calendar) };
}
// 13.40 ToPositiveInteger ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-topositiveinteger
ThrowCompletionOr<double> to_positive_integer(GlobalObject& global_object, Value argument)
ThrowCompletionOr<double> to_positive_integer(VM& vm, Value argument)
{
auto& vm = global_object.vm();
// 1. Let integer be ? ToIntegerThrowOnInfinity(argument).
auto integer = TRY(to_integer_throw_on_infinity(global_object, argument, ErrorType::TemporalPropertyMustBePositiveInteger));
auto integer = TRY(to_integer_throw_on_infinity(vm, argument, ErrorType::TemporalPropertyMustBePositiveInteger));
// 2. If integer ≤ 0, then
if (integer <= 0) {
@ -1769,10 +1726,10 @@ ThrowCompletionOr<double> to_positive_integer(GlobalObject& global_object, Value
}
// 13.43 PrepareTemporalFields ( fields, fieldNames, requiredFields ), https://tc39.es/proposal-temporal/#sec-temporal-preparetemporalfields
ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields)
ThrowCompletionOr<Object*> prepare_temporal_fields(VM& vm, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let result be OrdinaryObjectCreate(null).
auto* result = Object::create(realm, nullptr);
@ -1797,13 +1754,13 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object,
if (property.is_one_of("year"sv, "hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv, "eraYear"sv)) {
// a. Set value to ? ToIntegerThrowOnInfinity(value).
// b. Set value to 𝔽(value).
value = Value(TRY(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite)));
value = Value(TRY(to_integer_throw_on_infinity(vm, value, ErrorType::TemporalPropertyMustBeFinite)));
}
// 3. Else if Conversion is ToPositiveInteger, then
else if (property.is_one_of("month"sv, "day"sv)) {
// a. Set value to ? ToPositiveInteger(value).
// b. Set value to 𝔽(value).
value = Value(TRY(to_positive_integer(global_object, value)));
value = Value(TRY(to_positive_integer(vm, value)));
}
// 4. Else,
else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv)) {
@ -1845,15 +1802,13 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object,
}
// 13.44 GetDifferenceSettings ( operation, options, unitGroup, disallowedUnits, fallbackSmallestUnit, smallestLargestDefaultUnit ), https://tc39.es/proposal-temporal/#sec-temporal-getdifferencesettings
ThrowCompletionOr<DifferenceSettings> get_difference_settings(GlobalObject& global_object, DifferenceOperation operation, Value options_value, UnitGroup unit_group, Vector<StringView> const& disallowed_units, TemporalUnitDefault const& fallback_smallest_unit, StringView smallest_largest_default_unit)
ThrowCompletionOr<DifferenceSettings> get_difference_settings(VM& vm, DifferenceOperation operation, Value options_value, UnitGroup unit_group, Vector<StringView> const& disallowed_units, TemporalUnitDefault const& fallback_smallest_unit, StringView smallest_largest_default_unit)
{
auto& vm = global_object.vm();
// 1. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, options_value));
auto* options = TRY(get_options_object(vm, options_value));
// 2. Let smallestUnit be ? GetTemporalUnit(options, "smallestUnit", unitGroup, fallbackSmallestUnit).
auto smallest_unit = TRY(get_temporal_unit(global_object, *options, vm.names.smallestUnit, unit_group, fallback_smallest_unit));
auto smallest_unit = TRY(get_temporal_unit(vm, *options, vm.names.smallestUnit, unit_group, fallback_smallest_unit));
// 3. If disallowedUnits contains smallestUnit, throw a RangeError exception.
if (disallowed_units.contains_slow(*smallest_unit))
@ -1863,7 +1818,7 @@ ThrowCompletionOr<DifferenceSettings> get_difference_settings(GlobalObject& glob
auto default_largest_unit = larger_of_two_temporal_units(smallest_largest_default_unit, *smallest_unit);
// 5. Let largestUnit be ? GetTemporalUnit(options, "largestUnit", unitGroup, "auto").
auto largest_unit = TRY(get_temporal_unit(global_object, *options, vm.names.largestUnit, unit_group, { "auto"sv }));
auto largest_unit = TRY(get_temporal_unit(vm, *options, vm.names.largestUnit, unit_group, { "auto"sv }));
// 6. If disallowedUnits contains largestUnit, throw a RangeError exception.
if (disallowed_units.contains_slow(*largest_unit))
@ -1878,7 +1833,7 @@ ThrowCompletionOr<DifferenceSettings> get_difference_settings(GlobalObject& glob
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidUnitRange, *smallest_unit, *largest_unit);
// 9. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *options, "trunc"sv));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *options, "trunc"sv));
// 10. If operation is since, then
if (operation == DifferenceOperation::Since) {
@ -1890,7 +1845,7 @@ ThrowCompletionOr<DifferenceSettings> get_difference_settings(GlobalObject& glob
auto maximum = maximum_temporal_duration_rounding_increment(*smallest_unit);
// 12. Let roundingIncrement be ? ToTemporalRoundingIncrement(options, maximum, false).
auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *options, Optional<double> { maximum }, false));
auto rounding_increment = TRY(to_temporal_rounding_increment(vm, *options, Optional<double> { maximum }, false));
// 13. Return the Record { [[SmallestUnit]]: smallestUnit, [[LargestUnit]]: largestUnit, [[RoundingMode]]: roundingMode, [[RoundingIncrement]]: roundingIncrement, [[Options]]: options }.
return DifferenceSettings {

View file

@ -136,26 +136,26 @@ struct GetOptionRequired { };
using OptionDefault = Variant<GetOptionRequired, Empty, bool, StringView, double>;
using TemporalUnitDefault = Variant<TemporalUnitRequired, Optional<StringView>>;
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(GlobalObject&, Value items, Vector<OptionType> const& element_types);
ThrowCompletionOr<Object*> get_options_object(GlobalObject&, Value options);
ThrowCompletionOr<Value> get_option(GlobalObject&, Object const& options, PropertyKey const& property, OptionType type, Span<StringView const> values, OptionDefault const&);
ThrowCompletionOr<String> to_temporal_overflow(GlobalObject&, Object const* options);
ThrowCompletionOr<String> to_temporal_disambiguation(GlobalObject&, Object const* options);
ThrowCompletionOr<String> to_temporal_rounding_mode(GlobalObject&, Object const& normalized_options, String const& fallback);
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<String> to_temporal_overflow(VM&, Object const* options);
ThrowCompletionOr<String> to_temporal_disambiguation(VM&, Object const* options);
ThrowCompletionOr<String> to_temporal_rounding_mode(VM&, Object const& normalized_options, String const& fallback);
StringView negate_temporal_rounding_mode(String const& rounding_mode);
ThrowCompletionOr<String> to_temporal_offset(GlobalObject&, Object const* options, String const& fallback);
ThrowCompletionOr<String> to_show_calendar_option(GlobalObject&, Object const& normalized_options);
ThrowCompletionOr<String> to_show_time_zone_name_option(GlobalObject&, Object const& normalized_options);
ThrowCompletionOr<String> to_show_offset_option(GlobalObject&, Object const& normalized_options);
ThrowCompletionOr<u64> to_temporal_rounding_increment(GlobalObject&, Object const& normalized_options, Optional<double> dividend, bool inclusive);
ThrowCompletionOr<u64> to_temporal_date_time_rounding_increment(GlobalObject&, Object const& normalized_options, StringView smallest_unit);
ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(GlobalObject&, Object const& normalized_options);
ThrowCompletionOr<Optional<String>> get_temporal_unit(GlobalObject&, Object const& normalized_options, PropertyKey const&, UnitGroup, TemporalUnitDefault const& default_, Vector<StringView> const& extra_values = {});
ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject&, Object const& options);
ThrowCompletionOr<String> to_temporal_offset(VM&, Object const* options, String const& fallback);
ThrowCompletionOr<String> to_show_calendar_option(VM&, Object const& normalized_options);
ThrowCompletionOr<String> to_show_time_zone_name_option(VM&, Object const& normalized_options);
ThrowCompletionOr<String> to_show_offset_option(VM&, Object const& normalized_options);
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);
ThrowCompletionOr<Optional<String>> get_temporal_unit(VM&, Object const& normalized_options, PropertyKey const&, UnitGroup, TemporalUnitDefault const& default_, Vector<StringView> const& extra_values = {});
ThrowCompletionOr<Value> to_relative_temporal_object(VM&, Object const& options);
StringView larger_of_two_temporal_units(StringView, StringView);
ThrowCompletionOr<Object*> merge_largest_unit_option(GlobalObject&, Object const& options, String largest_unit);
ThrowCompletionOr<Object*> merge_largest_unit_option(VM&, Object const& options, String largest_unit);
Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit);
ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(GlobalObject&, Object&);
ThrowCompletionOr<void> reject_object_with_calendar_or_time_zone(VM&, Object&);
String format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision);
double sign(double);
double sign(Crypto::SignedBigInteger const&);
@ -165,33 +165,34 @@ Crypto::SignedBigInteger apply_unsigned_rounding_mode(Crypto::SignedDivisionResu
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);
Crypto::SignedBigInteger round_number_to_increment_as_if_positive(Crypto::SignedBigInteger const&, u64 increment, StringView rounding_mode);
ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject&, ParseResult const& parse_result);
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_zoned_date_time_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<double> to_positive_integer(GlobalObject&, Value argument);
ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject&, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields);
ThrowCompletionOr<DifferenceSettings> get_difference_settings(GlobalObject&, DifferenceOperation, Value options_value, UnitGroup unit_group, Vector<StringView> const& disallowed_units, TemporalUnitDefault const& fallback_smallest_unit, StringView smallest_largest_default_unit);
ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM&, ParseResult const& parse_result);
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM&, String const& iso_string);
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_zoned_date_time_string(VM&, String const& iso_string);
ThrowCompletionOr<String> parse_temporal_calendar_string(VM&, String const& iso_string);
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(VM&, String const& iso_string);
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(VM&, String const& iso_string);
ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM&, String const& iso_string);
ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(VM&, String const& iso_string);
ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(VM&, String const& iso_string);
ThrowCompletionOr<TemporalTime> parse_temporal_time_string(VM&, String const& iso_string);
ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(VM&, String const& iso_string);
ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(VM&, String const& iso_string);
ThrowCompletionOr<double> to_positive_integer(VM&, Value argument);
ThrowCompletionOr<Object*> prepare_temporal_fields(VM&, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields);
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);
template<size_t Size>
ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& options, PropertyKey const& property, OptionType type, StringView const (&values)[Size], OptionDefault const& default_)
ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey const& property, OptionType type, StringView const (&values)[Size], OptionDefault const& default_)
{
return get_option(global_object, options, property, type, Span<StringView const> { values }, default_);
return get_option(vm, options, property, type, Span<StringView const> { values }, default_);
}
// 13.40 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity
template<typename... Args>
ThrowCompletionOr<double> to_integer_throw_on_infinity(GlobalObject& global_object, Value argument, ErrorType error_type, Args... args)
ThrowCompletionOr<double> to_integer_throw_on_infinity(VM& vm, Value argument, ErrorType error_type, Args... args)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let integer be ? ToIntegerOrInfinity(argument).
auto integer = TRY(argument.to_integer_or_infinity(global_object));
@ -208,9 +209,10 @@ ThrowCompletionOr<double> to_integer_throw_on_infinity(GlobalObject& global_obje
// 13.41 ToIntegerWithoutRounding ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerwithoutrounding
template<typename... Args>
ThrowCompletionOr<double> to_integer_without_rounding(GlobalObject& global_object, Value argument, ErrorType error_type, Args... args)
ThrowCompletionOr<double> to_integer_without_rounding(VM& vm, Value argument, ErrorType error_type, Args... args)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let number be ? ToNumber(argument).
auto number = TRY(argument.to_number(global_object));

View file

@ -61,8 +61,11 @@ Span<StringView const> available_calendars()
}
// 12.2.1 CreateTemporalCalendar ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalcalendar
ThrowCompletionOr<Calendar*> create_temporal_calendar(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, String const& identifier, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: IsBuiltinCalendar(identifier) is true.
VERIFY(is_builtin_calendar(identifier));
@ -79,30 +82,28 @@ ThrowCompletionOr<Calendar*> create_temporal_calendar(GlobalObject& global_objec
}
// 12.2.2 GetBuiltinCalendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal-getbuiltincalendar
ThrowCompletionOr<Calendar*> get_builtin_calendar(GlobalObject& global_object, String const& identifier)
ThrowCompletionOr<Calendar*> get_builtin_calendar(VM& vm, String const& identifier)
{
auto& vm = global_object.vm();
// 1. If IsBuiltinCalendar(id) is false, throw a RangeError exception.
if (!is_builtin_calendar(identifier))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarIdentifier, identifier);
// 2. Return ! CreateTemporalCalendar(id).
return MUST(create_temporal_calendar(global_object, identifier));
return MUST(create_temporal_calendar(vm, identifier));
}
// 12.2.3 GetISO8601Calendar ( ), https://tc39.es/proposal-temporal/#sec-temporal-getiso8601calendar
Calendar* get_iso8601_calendar(GlobalObject& global_object)
Calendar* get_iso8601_calendar(VM& vm)
{
// 1. Return ! GetBuiltinCalendar("iso8601").
return MUST(get_builtin_calendar(global_object, "iso8601"));
return MUST(get_builtin_calendar(vm, "iso8601"));
}
// 12.2.4 CalendarFields ( calendar, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarfields
ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject& global_object, Object& calendar, Vector<StringView> const& field_names)
ThrowCompletionOr<Vector<String>> calendar_fields(VM& vm, Object& calendar, Vector<StringView> const& field_names)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let fields be ? GetMethod(calendar, "fields").
auto fields = TRY(Value(&calendar).get_method(global_object, vm.names.fields));
@ -120,7 +121,7 @@ ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject& global_object, O
}
// 4. Return ? IterableToListOfType(fieldsArray, « String »).
auto list = TRY(iterable_to_list_of_type(global_object, fields_array, { OptionType::String }));
auto list = TRY(iterable_to_list_of_type(vm, fields_array, { OptionType::String }));
Vector<String> result;
for (auto& value : list)
@ -129,9 +130,10 @@ ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject& global_object, O
}
// 12.2.5 CalendarMergeFields ( calendar, fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmergefields
ThrowCompletionOr<Object*> calendar_merge_fields(GlobalObject& global_object, Object& calendar, Object& fields, Object& additional_fields)
ThrowCompletionOr<Object*> calendar_merge_fields(VM& vm, Object& calendar, Object& fields, Object& additional_fields)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let mergeFields be ? GetMethod(calendar, "mergeFields").
auto* merge_fields = TRY(Value(&calendar).get_method(global_object, vm.names.mergeFields));
@ -139,7 +141,7 @@ ThrowCompletionOr<Object*> calendar_merge_fields(GlobalObject& global_object, Ob
// 2. If mergeFields is undefined, then
if (!merge_fields) {
// a. Return ? DefaultMergeCalendarFields(fields, additionalFields).
return TRY(default_merge_calendar_fields(global_object, fields, additional_fields));
return TRY(default_merge_calendar_fields(vm, fields, additional_fields));
}
// 3. Let result be ? Call(mergeFields, calendar, « fields, additionalFields »).
@ -154,10 +156,11 @@ ThrowCompletionOr<Object*> calendar_merge_fields(GlobalObject& global_object, Ob
}
// 12.2.6 CalendarDateAdd ( calendar, date, duration [ , options [ , dateAdd ] ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateadd
ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject& global_object, Object& calendar, Value date, Duration& duration, Object* options, FunctionObject* date_add)
ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value date, Duration& duration, Object* options, FunctionObject* date_add)
{
// NOTE: `date` is a `Value` because we sometimes need to pass a PlainDate, sometimes a PlainDateTime, and sometimes undefined.
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. If options is not present, set options to undefined.
@ -180,9 +183,10 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject& global_object, Obj
}
// 12.2.7 CalendarDateUntil ( calendar, one, two, options [ , dateUntil ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateuntil
ThrowCompletionOr<Duration*> calendar_date_until(GlobalObject& global_object, Object& calendar, Value one, Value two, Object& options, FunctionObject* date_until)
ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value one, Value two, Object& options, FunctionObject* date_until)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
@ -203,9 +207,11 @@ ThrowCompletionOr<Duration*> calendar_date_until(GlobalObject& global_object, Ob
}
// 12.2.8 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
ThrowCompletionOr<double> calendar_year(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<double> calendar_year(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Let result be ? Invoke(calendar, "year", « dateLike »).
@ -216,13 +222,15 @@ ThrowCompletionOr<double> calendar_year(GlobalObject& global_object, Object& cal
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.undefined.as_string());
// 4. Return ? ToIntegerThrowOnInfinity(result).
return TRY(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string()));
return TRY(to_integer_throw_on_infinity(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string()));
}
// 12.2.9 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth
ThrowCompletionOr<double> calendar_month(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<double> calendar_month(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Let result be ? Invoke(calendar, "month", « dateLike »).
@ -233,13 +241,15 @@ ThrowCompletionOr<double> calendar_month(GlobalObject& global_object, Object& ca
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.month.as_string(), vm.names.undefined.as_string());
// 3. Return ? ToPositiveInteger(result).
return TRY(to_positive_integer(global_object, result));
return TRY(to_positive_integer(vm, result));
}
// 12.2.10 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode
ThrowCompletionOr<String> calendar_month_code(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<String> calendar_month_code(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Let result be ? Invoke(calendar, "monthCode", « dateLike »).
@ -254,9 +264,11 @@ ThrowCompletionOr<String> calendar_month_code(GlobalObject& global_object, Objec
}
// 12.2.11 CalendarDay ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarday
ThrowCompletionOr<double> calendar_day(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<double> calendar_day(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Let result be ? Invoke(calendar, "day", « dateLike »).
@ -267,13 +279,15 @@ ThrowCompletionOr<double> calendar_day(GlobalObject& global_object, Object& cale
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.day.as_string(), vm.names.undefined.as_string());
// 3. Return ? ToPositiveInteger(result).
return TRY(to_positive_integer(global_object, result));
return TRY(to_positive_integer(vm, result));
}
// 12.2.12 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek
ThrowCompletionOr<Value> calendar_day_of_week(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_day_of_week(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "dayOfWeek", « dateLike »).
@ -281,9 +295,11 @@ ThrowCompletionOr<Value> calendar_day_of_week(GlobalObject& global_object, Objec
}
// 12.2.13 CalendarDayOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofyear
ThrowCompletionOr<Value> calendar_day_of_year(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_day_of_year(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "dayOfYear", « dateLike »).
@ -291,9 +307,11 @@ ThrowCompletionOr<Value> calendar_day_of_year(GlobalObject& global_object, Objec
}
// 12.2.14 CalendarWeekOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarweekofyear
ThrowCompletionOr<Value> calendar_week_of_year(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_week_of_year(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "weekOfYear", « dateLike »).
@ -301,9 +319,11 @@ ThrowCompletionOr<Value> calendar_week_of_year(GlobalObject& global_object, Obje
}
// 12.2.14 CalendarDaysInWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinweek
ThrowCompletionOr<Value> calendar_days_in_week(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_days_in_week(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "daysInWeek", « dateLike »).
@ -311,9 +331,11 @@ ThrowCompletionOr<Value> calendar_days_in_week(GlobalObject& global_object, Obje
}
// 12.2.16 CalendarDaysInMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinmonth
ThrowCompletionOr<Value> calendar_days_in_month(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_days_in_month(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "daysInMonth", « dateLike »).
@ -321,9 +343,11 @@ ThrowCompletionOr<Value> calendar_days_in_month(GlobalObject& global_object, Obj
}
// 12.2.17 CalendarDaysInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinyear
ThrowCompletionOr<Value> calendar_days_in_year(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_days_in_year(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "daysInYear", « dateLike »).
@ -331,9 +355,11 @@ ThrowCompletionOr<Value> calendar_days_in_year(GlobalObject& global_object, Obje
}
// 12.2.18 CalendarMonthsInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthsinyear
ThrowCompletionOr<Value> calendar_months_in_year(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_months_in_year(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "monthsInYear", « dateLike »).
@ -341,9 +367,11 @@ ThrowCompletionOr<Value> calendar_months_in_year(GlobalObject& global_object, Ob
}
// 12.2.29 CalendarInLeapYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarinleapyear
ThrowCompletionOr<Value> calendar_in_leap_year(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_in_leap_year(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
// 2. Return ? Invoke(calendar, "inLeapYear", « dateLike »).
@ -351,9 +379,10 @@ ThrowCompletionOr<Value> calendar_in_leap_year(GlobalObject& global_object, Obje
}
// 15.6.1.1 CalendarEra ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarera
ThrowCompletionOr<Value> calendar_era(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_era(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
@ -369,9 +398,10 @@ ThrowCompletionOr<Value> calendar_era(GlobalObject& global_object, Object& calen
}
// 15.6.1.2 CalendarEraYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarerayear
ThrowCompletionOr<Value> calendar_era_year(GlobalObject& global_object, Object& calendar, Object& date_like)
ThrowCompletionOr<Value> calendar_era_year(VM& vm, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(calendar) is Object.
@ -380,16 +410,17 @@ ThrowCompletionOr<Value> calendar_era_year(GlobalObject& global_object, Object&
// 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result).
if (!result.is_undefined())
result = Value(TRY(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)));
result = Value(TRY(to_integer_throw_on_infinity(vm, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)));
// 4. Return result.
return result;
}
// 12.2.20 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
ThrowCompletionOr<Object*> to_temporal_calendar(GlobalObject& global_object, Value temporal_calendar_like)
ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If Type(temporalCalendarLike) is Object, then
if (temporal_calendar_like.is_object()) {
@ -427,7 +458,7 @@ ThrowCompletionOr<Object*> to_temporal_calendar(GlobalObject& global_object, Val
// 3. If IsBuiltinCalendar(identifier) is false, then
if (!is_builtin_calendar(identifier)) {
// a. Set identifier to ? ParseTemporalCalendarString(identifier).
identifier = TRY(parse_temporal_calendar_string(global_object, identifier));
identifier = TRY(parse_temporal_calendar_string(vm, identifier));
// b. If IsBuiltinCalendar(identifier) is false, throw a RangeError exception.
if (!is_builtin_calendar(identifier))
@ -435,26 +466,24 @@ ThrowCompletionOr<Object*> to_temporal_calendar(GlobalObject& global_object, Val
}
// 4. Return ! CreateTemporalCalendar(identifier).
return MUST(create_temporal_calendar(global_object, identifier));
return MUST(create_temporal_calendar(vm, identifier));
}
// 12.2.21 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
ThrowCompletionOr<Object*> to_temporal_calendar_with_iso_default(GlobalObject& global_object, Value temporal_calendar_like)
ThrowCompletionOr<Object*> to_temporal_calendar_with_iso_default(VM& vm, Value temporal_calendar_like)
{
// 1. If temporalCalendarLike is undefined, then
if (temporal_calendar_like.is_undefined()) {
// a. Return ! GetISO8601Calendar().
return get_iso8601_calendar(global_object);
return get_iso8601_calendar(vm);
}
// 2. Return ? ToTemporalCalendar(temporalCalendarLike).
return to_temporal_calendar(global_object, temporal_calendar_like);
return to_temporal_calendar(vm, temporal_calendar_like);
}
// 12.2.22 GetTemporalCalendarWithISODefault ( item ), https://tc39.es/proposal-temporal/#sec-temporal-gettemporalcalendarwithisodefault
ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(GlobalObject& global_object, Object& item)
ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(VM& vm, Object& item)
{
auto& vm = global_object.vm();
// 1. If item has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalTime]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
// a. Return item.[[Calendar]].
if (is<PlainDate>(item))
@ -474,13 +503,14 @@ ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(GlobalObject&
auto calendar_like = TRY(item.get(vm.names.calendar));
// 3. Return ? ToTemporalCalendarWithISODefault(calendarLike).
return to_temporal_calendar_with_iso_default(global_object, calendar_like);
return to_temporal_calendar_with_iso_default(vm, calendar_like);
}
// 12.2.23 CalendarDateFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardatefromfields
ThrowCompletionOr<PlainDate*> calendar_date_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options)
ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
@ -497,9 +527,10 @@ ThrowCompletionOr<PlainDate*> calendar_date_from_fields(GlobalObject& global_obj
}
// 12.2.24 CalendarYearMonthFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearmonthfromfields
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options)
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
@ -516,9 +547,10 @@ ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(GlobalObject&
}
// 12.2.25 CalendarMonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthdayfromfields
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options)
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
@ -553,8 +585,11 @@ String format_calendar_annotation(StringView id, StringView show_calendar)
}
// 12.2.27 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
ThrowCompletionOr<bool> calendar_equals(GlobalObject& global_object, Object& one, Object& two)
ThrowCompletionOr<bool> calendar_equals(VM& vm, Object& one, Object& two)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If one and two are the same Object value, return true.
if (&one == &two)
return true;
@ -574,9 +609,11 @@ ThrowCompletionOr<bool> calendar_equals(GlobalObject& global_object, Object& one
}
// 12.2.28 ConsolidateCalendars ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-consolidatecalendars
ThrowCompletionOr<Object*> consolidate_calendars(GlobalObject& global_object, Object& one, Object& two)
ThrowCompletionOr<Object*> consolidate_calendars(VM& vm, Object& one, Object& two)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If one and two are the same Object value, return two.
if (&one == &two)
return &two;
@ -667,9 +704,10 @@ String build_iso_month_code(u8 month)
}
// 12.2.32 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth
ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object const& fields)
ThrowCompletionOr<double> resolve_iso_month(VM& vm, Object const& fields)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: fields is an ordinary object with no more and no less than the own data properties listed in Table 13.
@ -730,17 +768,15 @@ ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object
}
// 12.2.33 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
ThrowCompletionOr<ISODateRecord> iso_date_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM& vm, Object const& fields, Object const& options)
{
auto& vm = global_object.vm();
// 1. Assert: Type(fields) is Object.
// 2. Let overflow be ? ToTemporalOverflow(options).
auto overflow = TRY(to_temporal_overflow(global_object, &options));
auto overflow = TRY(to_temporal_overflow(vm, &options));
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "year", "day" »).
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day", "month", "monthCode", "year" }, Vector<StringView> { "year"sv, "day"sv }));
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields, { "day", "month", "monthCode", "year" }, Vector<StringView> { "year"sv, "day"sv }));
// 4. Let year be ! Get(fields, "year").
auto year = MUST(prepared_fields->get(vm.names.year));
@ -749,7 +785,7 @@ ThrowCompletionOr<ISODateRecord> iso_date_from_fields(GlobalObject& global_objec
VERIFY(year.is_number());
// 6. Let month be ? ResolveISOMonth(fields).
auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
auto month = TRY(resolve_iso_month(vm, *prepared_fields));
// 7. Let day be ! Get(fields, "day").
auto day = MUST(prepared_fields->get(vm.names.day));
@ -758,21 +794,19 @@ ThrowCompletionOr<ISODateRecord> iso_date_from_fields(GlobalObject& global_objec
VERIFY(day.is_number());
// 9. Return ? RegulateISODate((year), month, (day), overflow).
return regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow);
return regulate_iso_date(vm, year.as_double(), month, day.as_double(), overflow);
}
// 12.2.34 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields
ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM& vm, Object const& fields, Object const& options)
{
auto& vm = global_object.vm();
// 1. Assert: Type(fields) is Object.
// 2. Let overflow be ? ToTemporalOverflow(options).
auto overflow = TRY(to_temporal_overflow(global_object, &options));
auto overflow = TRY(to_temporal_overflow(vm, &options));
// 3. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », « "year" »).
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "month"sv, "monthCode"sv, "year"sv }, Vector<StringView> { "year"sv }));
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields, { "month"sv, "monthCode"sv, "year"sv }, Vector<StringView> { "year"sv }));
// 4. Let year be ! Get(fields, "year").
auto year = MUST(prepared_fields->get(vm.names.year));
@ -781,27 +815,25 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_
VERIFY(year.is_number());
// 6. Let month be ? ResolveISOMonth(fields).
auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
auto month = TRY(resolve_iso_month(vm, *prepared_fields));
// 7. Let result be ? RegulateISOYearMonth((year), month, overflow).
auto result = TRY(regulate_iso_year_month(global_object, year.as_double(), month, overflow));
auto result = TRY(regulate_iso_year_month(vm, year.as_double(), month, overflow));
// 8. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[ReferenceISODay]]: 1 }.
return ISOYearMonth { .year = result.year, .month = result.month, .reference_iso_day = 1 };
}
// 12.2.35 ISOMonthDayFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields
ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(VM& vm, Object const& fields, Object const& options)
{
auto& vm = global_object.vm();
// 1. Assert: Type(fields) is Object.
// 2. Let overflow be ? ToTemporalOverflow(options).
auto overflow = TRY(to_temporal_overflow(global_object, &options));
auto overflow = TRY(to_temporal_overflow(vm, &options));
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, Vector<StringView> { "day"sv }));
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, Vector<StringView> { "day"sv }));
// 4. Let month be ! Get(fields, "month").
auto month_value = MUST(prepared_fields->get(vm.names.month));
@ -819,7 +851,7 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_ob
}
// 8. Set month to ? ResolveISOMonth(fields).
auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
auto month = TRY(resolve_iso_month(vm, *prepared_fields));
// 9. Let day be ! Get(fields, "day").
auto day = MUST(prepared_fields->get(vm.names.day));
@ -838,12 +870,12 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_ob
VERIFY(year.is_number());
// b. Let result be ? RegulateISODate((year), month, (day), overflow).
result = TRY(regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow));
result = TRY(regulate_iso_date(vm, year.as_double(), month, day.as_double(), overflow));
}
// 13. Else,
else {
// a. Let result be ? RegulateISODate(referenceISOYear, month, (day), overflow).
result = TRY(regulate_iso_date(global_object, reference_iso_year, month, day.as_double(), overflow));
result = TRY(regulate_iso_date(vm, reference_iso_year, month, day.as_double(), overflow));
}
// 14. Return the Record { [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[ReferenceISOYear]]: referenceISOYear }.
@ -923,10 +955,10 @@ u8 iso_day(Object& temporal_object)
}
// 12.2.40 DefaultMergeCalendarFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergecalendarfields
ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject& global_object, Object const& fields, Object const& additional_fields)
ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& fields, Object const& additional_fields)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let merged be OrdinaryObjectCreate(%Object.prototype%).
auto* merged = Object::create(realm, global_object.object_prototype());

View file

@ -32,47 +32,47 @@ private:
bool is_builtin_calendar(String const& identifier);
Span<StringView const> available_calendars();
ThrowCompletionOr<Calendar*> create_temporal_calendar(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<Calendar*> get_builtin_calendar(GlobalObject&, String const& identifier);
Calendar* get_iso8601_calendar(GlobalObject&);
ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject&, Object& calendar, Vector<StringView> const& field_names);
ThrowCompletionOr<Object*> calendar_merge_fields(GlobalObject&, Object& calendar, Object& fields, Object& additional_fields);
ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject&, Object& calendar, Value date, Duration&, Object* options = nullptr, FunctionObject* date_add = nullptr);
ThrowCompletionOr<Duration*> calendar_date_until(GlobalObject&, Object& calendar, Value one, Value two, Object& options, FunctionObject* date_until = nullptr);
ThrowCompletionOr<double> calendar_year(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<double> calendar_month(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<String> calendar_month_code(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<double> calendar_day(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_day_of_week(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_day_of_year(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_week_of_year(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_days_in_week(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_days_in_month(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_days_in_year(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_months_in_year(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_in_leap_year(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_era(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_era_year(GlobalObject&, Object& calendar, Object& date_like);
ThrowCompletionOr<Object*> to_temporal_calendar(GlobalObject&, Value);
ThrowCompletionOr<Object*> to_temporal_calendar_with_iso_default(GlobalObject&, Value);
ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(GlobalObject&, Object&);
ThrowCompletionOr<PlainDate*> calendar_date_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const* options = nullptr);
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const* options = nullptr);
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const* options = nullptr);
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM&, String const& identifier, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<Calendar*> get_builtin_calendar(VM&, String const& identifier);
Calendar* get_iso8601_calendar(VM&);
ThrowCompletionOr<Vector<String>> calendar_fields(VM&, Object& calendar, Vector<StringView> const& field_names);
ThrowCompletionOr<Object*> calendar_merge_fields(VM&, Object& calendar, Object& fields, Object& additional_fields);
ThrowCompletionOr<PlainDate*> calendar_date_add(VM&, Object& calendar, Value date, Duration&, Object* options = nullptr, FunctionObject* date_add = nullptr);
ThrowCompletionOr<Duration*> calendar_date_until(VM&, Object& calendar, Value one, Value two, Object& options, FunctionObject* date_until = nullptr);
ThrowCompletionOr<double> calendar_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<double> calendar_month(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<String> calendar_month_code(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<double> calendar_day(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_day_of_week(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_day_of_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_week_of_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_days_in_week(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_days_in_month(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_days_in_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_months_in_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_in_leap_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_era(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Value> calendar_era_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<Object*> to_temporal_calendar(VM&, Value);
ThrowCompletionOr<Object*> to_temporal_calendar_with_iso_default(VM&, Value);
ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(VM&, Object&);
ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
String format_calendar_annotation(StringView id, StringView show_calendar);
ThrowCompletionOr<bool> calendar_equals(GlobalObject&, Object& one, Object& two);
ThrowCompletionOr<Object*> consolidate_calendars(GlobalObject&, Object& one, Object& two);
ThrowCompletionOr<bool> calendar_equals(VM&, Object& one, Object& two);
ThrowCompletionOr<Object*> consolidate_calendars(VM&, Object& one, Object& two);
u8 iso_days_in_month(i32 year, u8 month);
u8 to_iso_week_of_year(i32 year, u8 month, u8 day);
String build_iso_month_code(u8 month);
ThrowCompletionOr<double> resolve_iso_month(GlobalObject&, Object const& fields);
ThrowCompletionOr<ISODateRecord> iso_date_from_fields(GlobalObject&, Object const& fields, Object const& options);
ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject&, Object const& fields, Object const& options);
ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject&, Object const& fields, Object const& options);
ThrowCompletionOr<double> resolve_iso_month(VM&, Object const& fields);
ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM&, Object const& fields, Object const& options);
ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM&, Object const& fields, Object const& options);
ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(VM&, Object const& fields, Object const& options);
i32 iso_year(Object& temporal_object);
u8 iso_month(Object& temporal_object);
String iso_month_code(Object& temporal_object);
u8 iso_day(Object& temporal_object);
ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject&, Object const& fields, Object const& additional_fields);
ThrowCompletionOr<Object*> default_merge_calendar_fields(VM&, Object const& fields, Object const& additional_fields);
}

View file

@ -57,7 +57,7 @@ ThrowCompletionOr<Object*> CalendarConstructor::construct(FunctionObject& new_ta
}
// 4. Return ? CreateTemporalCalendar(id, NewTarget).
return TRY(create_temporal_calendar(global_object, identifier, &new_target));
return TRY(create_temporal_calendar(vm, identifier, &new_target));
}
// 12.3.2 Temporal.Calendar.from ( calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.from
@ -66,7 +66,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarConstructor::from)
auto calendar_like = vm.argument(0);
// 1. Return ? ToTemporalCalendar(calendarLike).
return TRY(to_temporal_calendar(global_object, calendar_like));
return TRY(to_temporal_calendar(vm, calendar_like));
}
}

View file

@ -90,13 +90,13 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_from_fields)
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, fields.to_string_without_side_effects());
// 5. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
auto const* options = TRY(get_options_object(vm, vm.argument(1)));
// 6. Let result be ? ISODateFromFields(fields, options).
auto result = TRY(iso_date_from_fields(global_object, fields.as_object(), *options));
auto result = TRY(iso_date_from_fields(vm, fields.as_object(), *options));
// 7. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
return TRY(create_temporal_date(global_object, result.year, result.month, result.day, *calendar));
return TRY(create_temporal_date(vm, result.year, result.month, result.day, *calendar));
}
// 12.4.5 Temporal.Calendar.prototype.yearMonthFromFields ( fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.yearmonthfromfields
@ -116,13 +116,13 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::year_month_from_fields)
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, fields.to_string_without_side_effects());
// 5. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
auto const* options = TRY(get_options_object(vm, vm.argument(1)));
// 6. Let result be ? ISOYearMonthFromFields(fields, options).
auto result = TRY(iso_year_month_from_fields(global_object, fields.as_object(), *options));
auto result = TRY(iso_year_month_from_fields(vm, fields.as_object(), *options));
// 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]).
return TRY(create_temporal_year_month(global_object, result.year, result.month, *calendar, result.reference_iso_day));
return TRY(create_temporal_year_month(vm, result.year, result.month, *calendar, result.reference_iso_day));
}
// 12.4.6 Temporal.Calendar.prototype.monthDayFromFields ( fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.monthdayfromfields
@ -142,13 +142,13 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::month_day_from_fields)
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, fields.to_string_without_side_effects());
// 5. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
auto const* options = TRY(get_options_object(vm, vm.argument(1)));
// 6. Let result be ? ISOMonthDayFromFields(fields, options).
auto result = TRY(iso_month_day_from_fields(global_object, fields.as_object(), *options));
auto result = TRY(iso_month_day_from_fields(vm, fields.as_object(), *options));
// 7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
return TRY(create_temporal_month_day(global_object, result.month, result.day, *calendar, result.reference_iso_year));
return TRY(create_temporal_month_day(vm, result.month, result.day, *calendar, result.reference_iso_year));
}
// 12.4.7 Temporal.Calendar.prototype.dateAdd ( date, duration [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dateadd
@ -163,26 +163,26 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_add)
VERIFY(calendar->identifier() == "iso8601"sv);
// 4. Set date to ? ToTemporalDate(date).
auto* date = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* date = TRY(to_temporal_date(vm, vm.argument(0)));
// 5. Set duration to ? ToTemporalDuration(duration).
auto* duration = TRY(to_temporal_duration(global_object, vm.argument(1)));
auto* duration = TRY(to_temporal_duration(vm, vm.argument(1)));
// 6. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(2)));
auto const* options = TRY(get_options_object(vm, vm.argument(2)));
// 7. Let overflow be ? ToTemporalOverflow(options).
auto overflow = TRY(to_temporal_overflow(global_object, options));
auto overflow = TRY(to_temporal_overflow(vm, options));
// 8. Let balanceResult be ? BalanceDuration(duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "day").
// FIXME: Narrowing conversion from 'double' to 'i64'
auto balance_result = TRY(balance_duration(global_object, duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), Crypto::SignedBigInteger::create_from(duration->nanoseconds()), "day"sv));
auto balance_result = TRY(balance_duration(vm, duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), Crypto::SignedBigInteger::create_from(duration->nanoseconds()), "day"sv));
// 9. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], balanceResult.[[Days]], overflow).
auto result = TRY(add_iso_date(global_object, date->iso_year(), date->iso_month(), date->iso_day(), duration->years(), duration->months(), duration->weeks(), balance_result.days, overflow));
auto result = TRY(add_iso_date(vm, date->iso_year(), date->iso_month(), date->iso_day(), duration->years(), duration->months(), duration->weeks(), balance_result.days, overflow));
// 10. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
return TRY(create_temporal_date(global_object, result.year, result.month, result.day, *calendar));
return TRY(create_temporal_date(vm, result.year, result.month, result.day, *calendar));
}
// 12.4.8 Temporal.Calendar.prototype.dateUntil ( one, two [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dateuntil
@ -197,26 +197,26 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_until)
VERIFY(calendar->identifier() == "iso8601"sv);
// 4. Set one to ? ToTemporalDate(one).
auto* one = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_date(vm, vm.argument(0)));
// 5. Set two to ? ToTemporalDate(two).
auto* two = TRY(to_temporal_date(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_date(vm, vm.argument(1)));
// 6. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(2)));
auto const* options = TRY(get_options_object(vm, vm.argument(2)));
// 7. Let largestUnit be ? GetTemporalUnit(options, "largestUnit", date, "auto").
auto largest_unit = TRY(get_temporal_unit(global_object, *options, vm.names.largestUnit, UnitGroup::Date, { "auto"sv }));
auto largest_unit = TRY(get_temporal_unit(vm, *options, vm.names.largestUnit, UnitGroup::Date, { "auto"sv }));
// 8. If largestUnit is "auto", set largestUnit to "day".
if (largest_unit == "auto")
largest_unit = "day"sv;
// 9. Let result be DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit).
auto result = difference_iso_date(global_object, one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day(), *largest_unit);
auto result = difference_iso_date(vm, one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day(), *largest_unit);
// 10. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0).
return MUST(create_temporal_duration(global_object, result.years, result.months, result.weeks, result.days, 0, 0, 0, 0, 0, 0));
return MUST(create_temporal_duration(vm, result.years, result.months, result.weeks, result.days, 0, 0, 0, 0, 0, 0));
}
// 12.4.9 Temporal.Calendar.prototype.year ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.year
@ -234,7 +234,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::year)
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 5. Return ! ISOYear(temporalDateLike).
@ -263,7 +263,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::month)
// 5. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 6. Return ! ISOMonth(temporalDateLike).
@ -285,7 +285,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::month_code)
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainMonthDay>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 5. Return ! ISOMonthCode(temporalDateLike).
@ -307,7 +307,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::day)
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]] or [[InitializedTemporalMonthDay]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainMonthDay>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 5. Return ! ISODay(temporalDateLike).
@ -326,7 +326,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::day_of_week)
VERIFY(calendar->identifier() == "iso8601"sv);
// 4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
auto* temporal_date = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* temporal_date = TRY(to_temporal_date(vm, vm.argument(0)));
// 5. Let epochDays be MakeDay(𝔽(temporalDate.[[ISOYear]]), 𝔽(temporalDate.[[ISOMonth]] - 1), 𝔽(temporalDate.[[ISODay]])).
auto epoch_days = make_day(temporal_date->iso_year(), temporal_date->iso_month() - 1, temporal_date->iso_day());
@ -357,7 +357,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::day_of_year)
VERIFY(calendar->identifier() == "iso8601"sv);
// 4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
auto* temporal_date = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* temporal_date = TRY(to_temporal_date(vm, vm.argument(0)));
// 5. Let epochDays be MakeDay(𝔽(temporalDate.[[ISOYear]]), 𝔽(temporalDate.[[ISOMonth]] - 1), 𝔽(temporalDate.[[ISODay]])).
auto epoch_days = make_day(temporal_date->iso_year(), temporal_date->iso_month() - 1, temporal_date->iso_day());
@ -381,7 +381,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::week_of_year)
VERIFY(calendar->identifier() == "iso8601"sv);
// 4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
auto* temporal_date = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* temporal_date = TRY(to_temporal_date(vm, vm.argument(0)));
// 5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
return Value(to_iso_week_of_year(temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day()));
@ -399,7 +399,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::days_in_week)
VERIFY(calendar->identifier() == "iso8601"sv);
// 4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
[[maybe_unused]] auto* temporal_date = TRY(to_temporal_date(global_object, vm.argument(0)));
[[maybe_unused]] auto* temporal_date = TRY(to_temporal_date(vm, vm.argument(0)));
// 5. Return 7𝔽.
return Value(7);
@ -420,7 +420,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::days_in_month)
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slots, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])).
@ -442,7 +442,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::days_in_year)
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 5. Return DaysInYear(𝔽(temporalDateLike.[[ISOYear]])).
@ -464,7 +464,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::months_in_year)
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Perform ? ToTemporalDate(temporalDateLike).
(void)TRY(to_temporal_date(global_object, temporal_date_like));
(void)TRY(to_temporal_date(vm, temporal_date_like));
}
// 5. Return 12𝔽.
@ -486,7 +486,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::in_leap_year)
// 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 5. If InLeapYear(TimeFromYear(𝔽(temporalDateLike.[[ISOYear]]))) is 1𝔽, return true.
@ -584,7 +584,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::merge_fields)
VERIFY(calendar->identifier() == "iso8601"sv);
// 6. Return ? DefaultMergeCalendarFields(fields, additionalFields).
return TRY(default_merge_calendar_fields(global_object, *fields, *additional_fields));
return TRY(default_merge_calendar_fields(vm, *fields, *additional_fields));
}
// 12.4.23 Temporal.Calendar.prototype.toString ( ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.tostring
@ -621,7 +621,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::era)
// 3. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 4. If calendar.[[Identifier]] is "iso8601", then
@ -649,7 +649,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::era_year)
// 3. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like));
}
// 4. If calendar.[[Identifier]] is "iso8601", then

View file

@ -78,10 +78,8 @@ DurationRecord create_duration_record(double years, double months, double weeks,
}
// 7.5.5 CreateDurationRecord ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-createdurationrecord
ThrowCompletionOr<DurationRecord> create_duration_record(GlobalObject& global_object, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds)
ThrowCompletionOr<DurationRecord> create_duration_record(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds)
{
auto& vm = global_object.vm();
// 1. If ! IsValidDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) is false, throw a RangeError exception.
if (!is_valid_duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDuration);
@ -101,10 +99,8 @@ DateDurationRecord create_date_duration_record(double years, double months, doub
}
// 7.5.6 CreateDateDurationRecord ( years, months, weeks, days ), https://tc39.es/proposal-temporal/#sec-temporal-createdatedurationrecord
ThrowCompletionOr<DateDurationRecord> create_date_duration_record(GlobalObject& global_object, double years, double months, double weeks, double days)
ThrowCompletionOr<DateDurationRecord> create_date_duration_record(VM& vm, double years, double months, double weeks, double days)
{
auto& vm = global_object.vm();
// 1. If ! IsValidDuration(years, months, weeks, days, 0, 0, 0, 0, 0, 0) is false, throw a RangeError exception.
if (!is_valid_duration(years, months, weeks, days, 0, 0, 0, 0, 0, 0))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDuration);
@ -114,10 +110,8 @@ ThrowCompletionOr<DateDurationRecord> create_date_duration_record(GlobalObject&
}
// 7.5.7 CreateTimeDurationRecord ( days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-createtimedurationrecord
ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(GlobalObject& global_object, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds)
ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(VM& vm, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds)
{
auto& vm = global_object.vm();
// 1. If ! IsValidDuration(0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) is false, throw a RangeError exception.
if (!is_valid_duration(0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDuration);
@ -127,7 +121,7 @@ ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(GlobalObject&
}
// 7.5.8 ToTemporalDuration ( item ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalduration
ThrowCompletionOr<Duration*> to_temporal_duration(GlobalObject& global_object, Value item)
ThrowCompletionOr<Duration*> to_temporal_duration(VM& vm, Value item)
{
// 1. If Type(item) is Object and item has an [[InitializedTemporalDuration]] internal slot, then
if (item.is_object() && is<Duration>(item.as_object())) {
@ -136,16 +130,17 @@ ThrowCompletionOr<Duration*> to_temporal_duration(GlobalObject& global_object, V
}
// 2. Let result be ? ToTemporalDurationRecord(item).
auto result = TRY(to_temporal_duration_record(global_object, item));
auto result = TRY(to_temporal_duration_record(vm, item));
// 3. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
return MUST(create_temporal_duration(vm, result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
}
// 7.5.9 ToTemporalDurationRecord ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject& global_object, Value temporal_duration_like)
ThrowCompletionOr<DurationRecord> to_temporal_duration_record(VM& vm, Value temporal_duration_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If Type(temporalDurationLike) is not Object, then
if (!temporal_duration_like.is_object()) {
@ -153,7 +148,7 @@ ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject& glob
auto string = TRY(temporal_duration_like.to_string(global_object));
// b. Return ? ParseTemporalDurationString(string).
return parse_temporal_duration_string(global_object, string);
return parse_temporal_duration_string(vm, string);
}
// 2. If temporalDurationLike has an [[InitializedTemporalDuration]] internal slot, then
@ -168,7 +163,7 @@ ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject& glob
auto result = DurationRecord {};
// 4. Let partial be ? ToTemporalPartialDurationRecord(temporalDurationLike).
auto partial = TRY(to_temporal_partial_duration_record(global_object, temporal_duration_like));
auto partial = TRY(to_temporal_partial_duration_record(vm, temporal_duration_like));
auto duration_record_fields = temporal_duration_record_fields<DurationRecord, double>(vm);
auto partial_duration_record_fields = temporal_duration_record_fields<PartialDurationRecord, Optional<double>>(vm);
@ -286,10 +281,8 @@ StringView default_temporal_largest_unit(double years, double months, double wee
}
// 7.5.13 ToTemporalPartialDurationRecord ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalpartialdurationrecord
ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(GlobalObject& global_object, Value temporal_duration_like)
ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(VM& vm, Value temporal_duration_like)
{
auto& vm = global_object.vm();
// 1. If Type(temporalDurationLike) is not Object, then
if (!temporal_duration_like.is_object()) {
// a. Throw a TypeError exception.
@ -315,7 +308,7 @@ ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(Glo
any = true;
// ii. Set value to ? ToIntegerWithoutRounding(value).
auto value_integer = TRY(to_integer_without_rounding(global_object, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, property.as_string(), value.to_string_without_side_effects()));
auto value_integer = TRY(to_integer_without_rounding(vm, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, property.as_string(), value.to_string_without_side_effects()));
// iii. Let fieldName be the Field Name value of the current row.
// iv. Set the field of result whose name is fieldName to value.
@ -334,9 +327,10 @@ ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(Glo
}
// 7.5.14 CreateTemporalDuration ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalduration
ThrowCompletionOr<Duration*> create_temporal_duration(GlobalObject& global_object, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target)
ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If ! IsValidDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) is false, throw a RangeError exception.
if (!is_valid_duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds))
@ -364,14 +358,14 @@ ThrowCompletionOr<Duration*> create_temporal_duration(GlobalObject& global_objec
}
// 7.5.15 CreateNegatedTemporalDuration ( duration ), https://tc39.es/proposal-temporal/#sec-temporal-createnegatedtemporalduration
Duration* create_negated_temporal_duration(GlobalObject& global_object, Duration const& duration)
Duration* create_negated_temporal_duration(VM& vm, Duration const& duration)
{
// 1. Return ! CreateTemporalDuration(-duration.[[Years]], -duration.[[Months]], -duration.[[Weeks]], -duration.[[Days]], -duration.[[Hours]], -duration.[[Minutes]], -duration.[[Seconds]], -duration.[[Milliseconds]], -duration.[[Microseconds]], -duration.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, -duration.years(), -duration.months(), -duration.weeks(), -duration.days(), -duration.hours(), -duration.minutes(), -duration.seconds(), -duration.milliseconds(), -duration.microseconds(), -duration.nanoseconds()));
return MUST(create_temporal_duration(vm, -duration.years(), -duration.months(), -duration.weeks(), -duration.days(), -duration.hours(), -duration.minutes(), -duration.seconds(), -duration.milliseconds(), -duration.microseconds(), -duration.nanoseconds()));
}
// 7.5.16 CalculateOffsetShift ( relativeTo, y, mon, w, d ), https://tc39.es/proposal-temporal/#sec-temporal-calculateoffsetshift
ThrowCompletionOr<double> calculate_offset_shift(GlobalObject& global_object, Value relative_to_value, double years, double months, double weeks, double days)
ThrowCompletionOr<double> calculate_offset_shift(VM& vm, Value relative_to_value, double years, double months, double weeks, double days)
{
// 1. If Type(relativeTo) is not Object or relativeTo does not have an [[InitializedTemporalZonedDateTime]] internal slot, return 0.
if (!relative_to_value.is_object() || !is<ZonedDateTime>(relative_to_value.as_object()))
@ -380,19 +374,19 @@ ThrowCompletionOr<double> calculate_offset_shift(GlobalObject& global_object, Va
auto& relative_to = static_cast<ZonedDateTime&>(relative_to_value.as_object());
// 2. Let instant be ! CreateTemporalInstant(relativeTo.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, relative_to.nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, relative_to.nanoseconds()));
// 3. Let offsetBefore be ? GetOffsetNanosecondsFor(relativeTo.[[TimeZone]], instant).
auto offset_before = TRY(get_offset_nanoseconds_for(global_object, &relative_to.time_zone(), *instant));
auto offset_before = TRY(get_offset_nanoseconds_for(vm, &relative_to.time_zone(), *instant));
// 4. Let after be ? AddZonedDateTime(relativeTo.[[Nanoseconds]], relativeTo.[[TimeZone]], relativeTo.[[Calendar]], y, mon, w, d, 0, 0, 0, 0, 0, 0).
auto* after = TRY(add_zoned_date_time(global_object, relative_to.nanoseconds(), &relative_to.time_zone(), relative_to.calendar(), years, months, weeks, days, 0, 0, 0, 0, 0, 0));
auto* after = TRY(add_zoned_date_time(vm, relative_to.nanoseconds(), &relative_to.time_zone(), relative_to.calendar(), years, months, weeks, days, 0, 0, 0, 0, 0, 0));
// 5. Let instantAfter be ! CreateTemporalInstant(after).
auto* instant_after = MUST(create_temporal_instant(global_object, *after));
auto* instant_after = MUST(create_temporal_instant(vm, *after));
// 6. Let offsetAfter be ? GetOffsetNanosecondsFor(relativeTo.[[TimeZone]], instantAfter).
auto offset_after = TRY(get_offset_nanoseconds_for(global_object, &relative_to.time_zone(), *instant_after));
auto offset_after = TRY(get_offset_nanoseconds_for(vm, &relative_to.time_zone(), *instant_after));
// 7. Return offsetAfter - offsetBefore.
return offset_after - offset_before;
@ -428,7 +422,7 @@ Crypto::SignedBigInteger total_duration_nanoseconds(double days, double hours, d
}
// 7.5.18 BalanceDuration ( days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, largestUnit [ , relativeTo ] ), https://tc39.es/proposal-temporal/#sec-temporal-balanceduration
ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject& global_object, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, Crypto::SignedBigInteger const& nanoseconds, String const& largest_unit, Object* relative_to)
ThrowCompletionOr<TimeDurationRecord> balance_duration(VM& vm, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, Crypto::SignedBigInteger const& nanoseconds, String const& largest_unit, Object* relative_to)
{
// 1. If relativeTo is not present, set relativeTo to undefined.
@ -438,7 +432,7 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject& global_obje
auto& relative_to_zoned_date_time = static_cast<ZonedDateTime&>(*relative_to);
// a. Let endNs be ? AddZonedDateTime(relativeTo.[[Nanoseconds]], relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
auto* end_ns = TRY(add_zoned_date_time(global_object, relative_to_zoned_date_time.nanoseconds(), &relative_to_zoned_date_time.time_zone(), relative_to_zoned_date_time.calendar(), 0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds.to_double()));
auto* end_ns = TRY(add_zoned_date_time(vm, relative_to_zoned_date_time.nanoseconds(), &relative_to_zoned_date_time.time_zone(), relative_to_zoned_date_time.calendar(), 0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds.to_double()));
// b. Set nanoseconds to (endNs - relativeTo.[[Nanoseconds]]).
total_nanoseconds = end_ns->big_integer().minus(relative_to_zoned_date_time.nanoseconds().big_integer());
@ -452,7 +446,7 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject& global_obje
// 4. If largestUnit is one of "year", "month", "week", or "day", then
if (largest_unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv)) {
// a. Let result be ? NanosecondsToDays(nanoseconds, relativeTo).
auto result = TRY(nanoseconds_to_days(global_object, total_nanoseconds, relative_to ?: js_undefined()));
auto result = TRY(nanoseconds_to_days(vm, total_nanoseconds, relative_to ?: js_undefined()));
// b. Set days to result.[[Days]].
days = result.days;
@ -565,14 +559,14 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject& global_obje
VERIFY(largest_unit == "nanosecond"sv);
}
// 15. Return ? CreateTimeDurationRecord(days, hours × sign, minutes × sign, seconds × sign, milliseconds × sign, microseconds × sign, nanoseconds × sign).
return create_time_duration_record(global_object, days, hours * sign, minutes * sign, seconds * sign, milliseconds * sign, microseconds * sign, result_nanoseconds * sign);
return create_time_duration_record(vm, days, hours * sign, minutes * sign, seconds * sign, milliseconds * sign, microseconds * sign, result_nanoseconds * sign);
}
// 7.5.19 UnbalanceDurationRelative ( years, months, weeks, days, largestUnit, relativeTo ), https://tc39.es/proposal-temporal/#sec-temporal-unbalancedurationrelative
ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject& global_object, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to)
ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If largestUnit is "year", or years, months, weeks, and days are all 0, then
if (largest_unit == "year"sv || (years == 0 && months == 0 && weeks == 0 && days == 0)) {
@ -587,20 +581,20 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
VERIFY(sign != 0);
// 4. Let oneYear be ! CreateTemporalDuration(sign, 0, 0, 0, 0, 0, 0, 0, 0, 0).
auto* one_year = MUST(create_temporal_duration(global_object, sign, 0, 0, 0, 0, 0, 0, 0, 0, 0));
auto* one_year = MUST(create_temporal_duration(vm, sign, 0, 0, 0, 0, 0, 0, 0, 0, 0));
// 5. Let oneMonth be ! CreateTemporalDuration(0, sign, 0, 0, 0, 0, 0, 0, 0, 0).
auto* one_month = MUST(create_temporal_duration(global_object, 0, sign, 0, 0, 0, 0, 0, 0, 0, 0));
auto* one_month = MUST(create_temporal_duration(vm, 0, sign, 0, 0, 0, 0, 0, 0, 0, 0));
// 6. Let oneWeek be ! CreateTemporalDuration(0, 0, sign, 0, 0, 0, 0, 0, 0, 0).
auto* one_week = MUST(create_temporal_duration(global_object, 0, 0, sign, 0, 0, 0, 0, 0, 0, 0));
auto* one_week = MUST(create_temporal_duration(vm, 0, 0, sign, 0, 0, 0, 0, 0, 0, 0));
Object* calendar;
// 7. If relativeTo is not undefined, then
if (!relative_to.is_undefined()) {
// a. Set relativeTo to ? ToTemporalDate(relativeTo).
auto* relative_to_plain_date = TRY(to_temporal_date(global_object, relative_to));
auto* relative_to_plain_date = TRY(to_temporal_date(vm, relative_to));
relative_to = relative_to_plain_date;
// b. Let calendar be relativeTo.[[Calendar]].
@ -629,7 +623,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// d. Repeat, while years ≠ 0,
while (years != 0) {
// i. Let newRelativeTo be ? CalendarDateAdd(calendar, relativeTo, oneYear, undefined, dateAdd).
auto* new_relative_to = TRY(calendar_date_add(global_object, *calendar, relative_to, *one_year, nullptr, date_add));
auto* new_relative_to = TRY(calendar_date_add(vm, *calendar, relative_to, *one_year, nullptr, date_add));
// ii. Let untilOptions be OrdinaryObjectCreate(null).
auto* until_options = Object::create(realm, nullptr);
@ -638,7 +632,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
// iv. Let untilResult be ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
auto* until_result = TRY(calendar_date_until(global_object, *calendar, relative_to, new_relative_to, *until_options, date_until));
auto* until_result = TRY(calendar_date_until(vm, *calendar, relative_to, new_relative_to, *until_options, date_until));
// v. Let oneYearMonths be untilResult.[[Months]].
auto one_year_months = until_result->months();
@ -664,7 +658,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// b. Repeat, while years ≠ 0,
while (years != 0) {
// i. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneYear).
auto move_result = TRY(move_relative_date(global_object, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_year));
auto move_result = TRY(move_relative_date(vm, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_year));
// ii. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -679,7 +673,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// c. Repeat, while months ≠ 0,
while (months != 0) {
// i. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneMonth).
auto move_result = TRY(move_relative_date(global_object, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_month));
auto move_result = TRY(move_relative_date(vm, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_month));
// ii. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -704,7 +698,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// ii. Repeat, while years ≠ 0,
while (years != 0) {
// 1. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneYear).
auto move_result = TRY(move_relative_date(global_object, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_year));
auto move_result = TRY(move_relative_date(vm, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_year));
// 2. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -719,7 +713,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// iii. Repeat, while months ≠ 0,
while (months != 0) {
// 1. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneMonth).
auto move_result = TRY(move_relative_date(global_object, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_month));
auto move_result = TRY(move_relative_date(vm, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_month));
// 2. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -734,7 +728,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// iv. Repeat, while weeks ≠ 0,
while (weeks != 0) {
// 1. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneWeek).
auto move_result = TRY(move_relative_date(global_object, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_week));
auto move_result = TRY(move_relative_date(vm, *calendar, verify_cast<PlainDate>(relative_to.as_object()), *one_week));
// 2. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -749,14 +743,14 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
}
// 12. Return ? CreateDateDurationRecord(years, months, weeks, days).
return create_date_duration_record(global_object, years, months, weeks, days);
return create_date_duration_record(vm, years, months, weeks, days);
}
// 7.5.20 BalanceDurationRelative ( years, months, weeks, days, largestUnit, relativeTo ), https://tc39.es/proposal-temporal/#sec-temporal-balancedurationrelative
ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& global_object, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to_value)
ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to_value)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If largestUnit is not one of "year", "month", or "week", or years, months, weeks, and days are all 0, then
if (!largest_unit.is_one_of("year"sv, "month"sv, "week"sv) || (years == 0 && months == 0 && weeks == 0 && days == 0)) {
@ -777,16 +771,16 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
VERIFY(sign != 0);
// 5. Let oneYear be ! CreateTemporalDuration(sign, 0, 0, 0, 0, 0, 0, 0, 0, 0).
auto* one_year = MUST(create_temporal_duration(global_object, sign, 0, 0, 0, 0, 0, 0, 0, 0, 0));
auto* one_year = MUST(create_temporal_duration(vm, sign, 0, 0, 0, 0, 0, 0, 0, 0, 0));
// 6. Let oneMonth be ! CreateTemporalDuration(0, sign, 0, 0, 0, 0, 0, 0, 0, 0).
auto* one_month = MUST(create_temporal_duration(global_object, 0, sign, 0, 0, 0, 0, 0, 0, 0, 0));
auto* one_month = MUST(create_temporal_duration(vm, 0, sign, 0, 0, 0, 0, 0, 0, 0, 0));
// 7. Let oneWeek be ! CreateTemporalDuration(0, 0, sign, 0, 0, 0, 0, 0, 0, 0).
auto* one_week = MUST(create_temporal_duration(global_object, 0, 0, sign, 0, 0, 0, 0, 0, 0, 0));
auto* one_week = MUST(create_temporal_duration(vm, 0, 0, sign, 0, 0, 0, 0, 0, 0, 0));
// 8. Set relativeTo to ? ToTemporalDate(relativeTo).
auto* relative_to = TRY(to_temporal_date(global_object, relative_to_value));
auto* relative_to = TRY(to_temporal_date(vm, relative_to_value));
// 9. Let calendar be relativeTo.[[Calendar]].
auto& calendar = relative_to->calendar();
@ -794,7 +788,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
// 10. If largestUnit is "year", then
if (largest_unit == "year"sv) {
// a. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneYear).
auto move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_year));
auto move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_year));
// b. Let newRelativeTo be moveResult.[[RelativeTo]].
auto* new_relative_to = move_result.relative_to.cell();
@ -814,7 +808,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
relative_to = new_relative_to;
// iv. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneYear).
move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_year));
move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_year));
// v. Set newRelativeTo to moveResult.[[RelativeTo]].
new_relative_to = move_result.relative_to.cell();
@ -824,7 +818,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
}
// e. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneMonth).
move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_month));
move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_month));
// f. Set newRelativeTo to moveResult.[[RelativeTo]].
new_relative_to = move_result.relative_to.cell();
@ -844,7 +838,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
relative_to = new_relative_to;
// iv. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneMonth).
move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_month));
move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_month));
// v. Set newRelativeTo to moveResult.[[RelativeTo]].
new_relative_to = move_result.relative_to.cell();
@ -857,7 +851,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
auto* date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
// j. Set newRelativeTo to ? CalendarDateAdd(calendar, relativeTo, oneYear, undefined, dateAdd).
new_relative_to = TRY(calendar_date_add(global_object, calendar, relative_to, *one_year, nullptr, date_add));
new_relative_to = TRY(calendar_date_add(vm, calendar, relative_to, *one_year, nullptr, date_add));
// k. Let dateUntil be ? GetMethod(calendar, "dateUntil").
auto* date_until = TRY(Value(&calendar).get_method(global_object, vm.names.dateUntil));
@ -869,7 +863,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
// n. Let untilResult be ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
auto* until_result = TRY(calendar_date_until(global_object, calendar, relative_to, new_relative_to, *until_options, date_until));
auto* until_result = TRY(calendar_date_until(vm, calendar, relative_to, new_relative_to, *until_options, date_until));
// o. Let oneYearMonths be untilResult.[[Months]].
auto one_year_months = until_result->months();
@ -886,7 +880,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
relative_to = new_relative_to;
// iv. Set newRelativeTo to ? CalendarDateAdd(calendar, relativeTo, oneYear, undefined, dateAdd).
new_relative_to = TRY(calendar_date_add(global_object, calendar, relative_to, *one_year, nullptr, date_add));
new_relative_to = TRY(calendar_date_add(vm, calendar, relative_to, *one_year, nullptr, date_add));
// v. Set untilOptions to OrdinaryObjectCreate(null).
until_options = Object::create(realm, nullptr);
@ -895,7 +889,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
// vii. Set untilResult to ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
until_result = TRY(calendar_date_until(global_object, calendar, relative_to, new_relative_to, *until_options, date_until));
until_result = TRY(calendar_date_until(vm, calendar, relative_to, new_relative_to, *until_options, date_until));
// viii. Set oneYearMonths to untilResult.[[Months]].
one_year_months = until_result->months();
@ -904,7 +898,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
// 11. Else if largestUnit is "month", then
else if (largest_unit == "month"sv) {
// a. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneMonth).
auto move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_month));
auto move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_month));
// b. Let newRelativeTo be moveResult.[[RelativeTo]].
auto* new_relative_to = move_result.relative_to.cell();
@ -924,7 +918,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
relative_to = new_relative_to;
// iv. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneMonth).
move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_month));
move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_month));
// v. Set newRelativeTo to moveResult.[[RelativeTo]].
new_relative_to = move_result.relative_to.cell();
@ -939,7 +933,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
VERIFY(largest_unit == "week"sv);
// b. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneWeek).
auto move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_week));
auto move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_week));
// c. Let newRelativeTo be moveResult.[[RelativeTo]].
auto* new_relative_to = move_result.relative_to.cell();
@ -959,7 +953,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
relative_to = new_relative_to;
// iv. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneWeek).
move_result = TRY(move_relative_date(global_object, calendar, *relative_to, *one_week));
move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_week));
// v. Set newRelativeTo to moveResult.[[RelativeTo]].
new_relative_to = move_result.relative_to.cell();
@ -974,10 +968,10 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
}
// 7.5.21 AddDuration ( y1, mon1, w1, d1, h1, min1, s1, ms1, mus1, ns1, y2, mon2, w2, d2, h2, min2, s2, ms2, mus2, ns2, relativeTo ), https://tc39.es/proposal-temporal/#sec-temporal-addduration
ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, double years1, double months1, double weeks1, double days1, double hours1, double minutes1, double seconds1, double milliseconds1, double microseconds1, double nanoseconds1, double years2, double months2, double weeks2, double days2, double hours2, double minutes2, double seconds2, double milliseconds2, double microseconds2, double nanoseconds2, Value relative_to_value)
ThrowCompletionOr<DurationRecord> add_duration(VM& vm, double years1, double months1, double weeks1, double days1, double hours1, double minutes1, double seconds1, double milliseconds1, double microseconds1, double nanoseconds1, double years2, double months2, double weeks2, double days2, double hours2, double minutes2, double seconds2, double milliseconds2, double microseconds2, double nanoseconds2, Value relative_to_value)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
VERIFY(all_of(AK::Array { years1, months1, weeks1, days1, hours1, minutes1, seconds1, milliseconds1, microseconds1, nanoseconds1, years2, months2, weeks2, days2, hours2, minutes2, seconds2, milliseconds2, microseconds2, nanoseconds2 }, [](auto value) { return value == trunc(value); }));
@ -1000,10 +994,10 @@ ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, doub
// b. Let result be ? BalanceDuration(d1 + d2, h1 + h2, min1 + min2, s1 + s2, ms1 + ms2, mus1 + mus2, ns1 + ns2, largestUnit).
// FIXME: Narrowing conversion from 'double' to 'i64'
auto result = TRY(balance_duration(global_object, days1 + days2, hours1 + hours2, minutes1 + minutes2, seconds1 + seconds2, milliseconds1 + milliseconds2, microseconds1 + microseconds2, Crypto::SignedBigInteger::create_from(nanoseconds1 + nanoseconds2), largest_unit));
auto result = TRY(balance_duration(vm, days1 + days2, hours1 + hours2, minutes1 + minutes2, seconds1 + seconds2, milliseconds1 + milliseconds2, microseconds1 + microseconds2, Crypto::SignedBigInteger::create_from(nanoseconds1 + nanoseconds2), largest_unit));
// c. Return ! CreateDurationRecord(0, 0, 0, result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
return MUST(create_duration_record(global_object, 0, 0, 0, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
return MUST(create_duration_record(vm, 0, 0, 0, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
}
// 5. If relativeTo has an [[InitializedTemporalDate]] internal slot, then
@ -1014,19 +1008,19 @@ ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, doub
auto& calendar = relative_to.calendar();
// b. Let dateDuration1 be ! CreateTemporalDuration(y1, mon1, w1, d1, 0, 0, 0, 0, 0, 0).
auto* date_duration1 = MUST(create_temporal_duration(global_object, years1, months1, weeks1, days1, 0, 0, 0, 0, 0, 0));
auto* date_duration1 = MUST(create_temporal_duration(vm, years1, months1, weeks1, days1, 0, 0, 0, 0, 0, 0));
// c. Let dateDuration2 be ! CreateTemporalDuration(y2, mon2, w2, d2, 0, 0, 0, 0, 0, 0).
auto* date_duration2 = MUST(create_temporal_duration(global_object, years2, months2, weeks2, days2, 0, 0, 0, 0, 0, 0));
auto* date_duration2 = MUST(create_temporal_duration(vm, years2, months2, weeks2, days2, 0, 0, 0, 0, 0, 0));
// d. Let dateAdd be ? GetMethod(calendar, "dateAdd").
auto* date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
// e. Let intermediate be ? CalendarDateAdd(calendar, relativeTo, dateDuration1, undefined, dateAdd).
auto* intermediate = TRY(calendar_date_add(global_object, calendar, &relative_to, *date_duration1, nullptr, date_add));
auto* intermediate = TRY(calendar_date_add(vm, calendar, &relative_to, *date_duration1, nullptr, date_add));
// f. Let end be ? CalendarDateAdd(calendar, intermediate, dateDuration2, undefined, dateAdd).
auto* end = TRY(calendar_date_add(global_object, calendar, intermediate, *date_duration2, nullptr, date_add));
auto* end = TRY(calendar_date_add(vm, calendar, intermediate, *date_duration2, nullptr, date_add));
// g. Let dateLargestUnit be ! LargerOfTwoTemporalUnits("day", largestUnit).
auto date_largest_unit = larger_of_two_temporal_units("day"sv, largest_unit);
@ -1038,14 +1032,14 @@ ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, doub
MUST(difference_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, date_largest_unit)));
// j. Let dateDifference be ? CalendarDateUntil(calendar, relativeTo, end, differenceOptions).
auto* date_difference = TRY(calendar_date_until(global_object, calendar, &relative_to, end, *difference_options));
auto* date_difference = TRY(calendar_date_until(vm, calendar, &relative_to, end, *difference_options));
// k. Let result be ? BalanceDuration(dateDifference.[[Days]], h1 + h2, min1 + min2, s1 + s2, ms1 + ms2, mus1 + mus2, ns1 + ns2, largestUnit).
// FIXME: Narrowing conversion from 'double' to 'i64'
auto result = TRY(balance_duration(global_object, date_difference->days(), hours1 + hours2, minutes1 + minutes2, seconds1 + seconds2, milliseconds1 + milliseconds2, microseconds1 + microseconds2, Crypto::SignedBigInteger::create_from(nanoseconds1 + nanoseconds2), largest_unit));
auto result = TRY(balance_duration(vm, date_difference->days(), hours1 + hours2, minutes1 + minutes2, seconds1 + seconds2, milliseconds1 + milliseconds2, microseconds1 + microseconds2, Crypto::SignedBigInteger::create_from(nanoseconds1 + nanoseconds2), largest_unit));
// l. Return ? CreateDurationRecord(dateDifference.[[Years]], dateDifference.[[Months]], dateDifference.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
return MUST(create_duration_record(global_object, date_difference->years(), date_difference->months(), date_difference->weeks(), result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
return MUST(create_duration_record(vm, date_difference->years(), date_difference->months(), date_difference->weeks(), result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
}
// 6. Assert: relativeTo has an [[InitializedTemporalZonedDateTime]] internal slot.
@ -1058,34 +1052,34 @@ ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, doub
auto& calendar = relative_to.calendar();
// 9. Let intermediateNs be ? AddZonedDateTime(relativeTo.[[Nanoseconds]], timeZone, calendar, y1, mon1, w1, d1, h1, min1, s1, ms1, mus1, ns1).
auto* intermediate_ns = TRY(add_zoned_date_time(global_object, relative_to.nanoseconds(), &time_zone, calendar, years1, months1, weeks1, days1, hours1, minutes1, seconds1, milliseconds1, microseconds1, nanoseconds1));
auto* intermediate_ns = TRY(add_zoned_date_time(vm, relative_to.nanoseconds(), &time_zone, calendar, years1, months1, weeks1, days1, hours1, minutes1, seconds1, milliseconds1, microseconds1, nanoseconds1));
// 10. Let endNs be ? AddZonedDateTime(intermediateNs, timeZone, calendar, y2, mon2, w2, d2, h2, min2, s2, ms2, mus2, ns2).
auto* end_ns = TRY(add_zoned_date_time(global_object, *intermediate_ns, &time_zone, calendar, years2, months2, weeks2, days2, hours2, minutes2, seconds2, milliseconds2, microseconds2, nanoseconds2));
auto* end_ns = TRY(add_zoned_date_time(vm, *intermediate_ns, &time_zone, calendar, years2, months2, weeks2, days2, hours2, minutes2, seconds2, milliseconds2, microseconds2, nanoseconds2));
// 11. If largestUnit is not one of "year", "month", "week", or "day", then
if (!largest_unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv)) {
// a. Let diffNs be ! DifferenceInstant(relativeTo.[[Nanoseconds]], endNs, 1, "nanosecond", "halfExpand").
auto* diff_ns = difference_instant(global_object, relative_to.nanoseconds(), *end_ns, 1, "nanosecond"sv, "halfExpand"sv);
auto* diff_ns = difference_instant(vm, relative_to.nanoseconds(), *end_ns, 1, "nanosecond"sv, "halfExpand"sv);
// b. Assert: The following steps cannot fail due to overflow in the Number domain because abs(diffNs) ≤ 2 × nsMaxInstant.
// c. Let result be ! BalanceDuration(0, 0, 0, 0, 0, 0, diffNs, largestUnit).
auto result = MUST(balance_duration(global_object, 0, 0, 0, 0, 0, 0, diff_ns->big_integer(), largest_unit));
auto result = MUST(balance_duration(vm, 0, 0, 0, 0, 0, 0, diff_ns->big_integer(), largest_unit));
// d. Return ? CreateDurationRecord(0, 0, 0, 0, result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
return create_duration_record(global_object, 0, 0, 0, 0, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds);
return create_duration_record(vm, 0, 0, 0, 0, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds);
}
// 12. Return ? DifferenceZonedDateTime(relativeTo.[[Nanoseconds]], endNs, timeZone, calendar, largestUnit, OrdinaryObjectCreate(null)).
return difference_zoned_date_time(global_object, relative_to.nanoseconds(), *end_ns, time_zone, calendar, largest_unit, *Object::create(realm, nullptr));
return difference_zoned_date_time(vm, relative_to.nanoseconds(), *end_ns, time_zone, calendar, largest_unit, *Object::create(realm, nullptr));
}
// 7.5.23 MoveRelativeDate ( calendar, relativeTo, duration ), https://tc39.es/proposal-temporal/#sec-temporal-moverelativedate
ThrowCompletionOr<MoveRelativeDateResult> move_relative_date(GlobalObject& global_object, Object& calendar, PlainDate& relative_to, Duration& duration)
ThrowCompletionOr<MoveRelativeDateResult> move_relative_date(VM& vm, Object& calendar, PlainDate& relative_to, Duration& duration)
{
// 1. Let newDate be ? CalendarDateAdd(calendar, relativeTo, duration, options).
auto* new_date = TRY(calendar_date_add(global_object, calendar, &relative_to, duration));
auto* new_date = TRY(calendar_date_add(vm, calendar, &relative_to, duration));
// 2. Let days be DaysUntil(relativeTo, newDate).
auto days = days_until(relative_to, *new_date);
@ -1095,20 +1089,20 @@ ThrowCompletionOr<MoveRelativeDateResult> move_relative_date(GlobalObject& globa
}
// 7.5.24 MoveRelativeZonedDateTime ( zonedDateTime, years, months, weeks, days ), https://tc39.es/proposal-temporal/#sec-temporal-moverelativezoneddatetime
ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(GlobalObject& global_object, ZonedDateTime& zoned_date_time, double years, double months, double weeks, double days)
ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(VM& vm, ZonedDateTime& zoned_date_time, double years, double months, double weeks, double days)
{
// 1. Let intermediateNs be ? AddZonedDateTime(zonedDateTime.[[Nanoseconds]], zonedDateTime.[[TimeZone]], zonedDateTime.[[Calendar]], years, months, weeks, days, 0, 0, 0, 0, 0, 0).
auto* intermediate_ns = TRY(add_zoned_date_time(global_object, zoned_date_time.nanoseconds(), &zoned_date_time.time_zone(), zoned_date_time.calendar(), years, months, weeks, days, 0, 0, 0, 0, 0, 0));
auto* intermediate_ns = TRY(add_zoned_date_time(vm, zoned_date_time.nanoseconds(), &zoned_date_time.time_zone(), zoned_date_time.calendar(), years, months, weeks, days, 0, 0, 0, 0, 0, 0));
// 2. Return ! CreateTemporalZonedDateTime(intermediateNs, zonedDateTime.[[TimeZone]], zonedDateTime.[[Calendar]]).
return MUST(create_temporal_zoned_date_time(global_object, *intermediate_ns, zoned_date_time.time_zone(), zoned_date_time.calendar()));
return MUST(create_temporal_zoned_date_time(vm, *intermediate_ns, zoned_date_time.time_zone(), zoned_date_time.calendar()));
}
// 7.5.25 RoundDuration ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, increment, unit, roundingMode [ , relativeTo ] ), https://tc39.es/proposal-temporal/#sec-temporal-roundduration
ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object)
ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
Object* calendar = nullptr;
double fractional_seconds = 0;
@ -1140,7 +1134,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
zoned_relative_to = relative_to_zoned_date_time;
// ii. Set relativeTo to ? ToTemporalDate(relativeTo).
relative_to = TRY(to_temporal_date(global_object, relative_to_object));
relative_to = TRY(to_temporal_date(vm, relative_to_object));
}
// b. Else,
else {
@ -1167,11 +1161,11 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
// c. If zonedRelativeTo is not undefined, then
if (zoned_relative_to) {
// i. Let intermediate be ? MoveRelativeZonedDateTime(zonedRelativeTo, years, months, weeks, days).
intermediate = TRY(move_relative_zoned_date_time(global_object, *zoned_relative_to, years, months, weeks, days));
intermediate = TRY(move_relative_zoned_date_time(vm, *zoned_relative_to, years, months, weeks, days));
}
// d. Let result be ? NanosecondsToDays(nanoseconds, intermediate).
auto result = TRY(nanoseconds_to_days(global_object, nanoseconds_bigint, intermediate));
auto result = TRY(nanoseconds_to_days(vm, nanoseconds_bigint, intermediate));
// e. Set days to days + result.[[Days]] + result.[[Nanoseconds]] / result.[[DayLength]].
auto nanoseconds_division_result = result.nanoseconds.divided_by(Crypto::UnsignedBigInteger::create_from((u64)result.day_length));
@ -1199,19 +1193,19 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
VERIFY(relative_to);
// a. Let yearsDuration be ! CreateTemporalDuration(years, 0, 0, 0, 0, 0, 0, 0, 0, 0).
auto* years_duration = MUST(create_temporal_duration(global_object, years, 0, 0, 0, 0, 0, 0, 0, 0, 0));
auto* years_duration = MUST(create_temporal_duration(vm, years, 0, 0, 0, 0, 0, 0, 0, 0, 0));
// b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
auto* date_add = TRY(Value(calendar).get_method(global_object, vm.names.dateAdd));
// c. Let yearsLater be ? CalendarDateAdd(calendar, relativeTo, yearsDuration, undefined, dateAdd).
auto* years_later = TRY(calendar_date_add(global_object, *calendar, relative_to, *years_duration, nullptr, date_add));
auto* years_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_duration, nullptr, date_add));
// d. Let yearsMonthsWeeks be ! CreateTemporalDuration(years, months, weeks, 0, 0, 0, 0, 0, 0, 0).
auto* years_months_weeks = MUST(create_temporal_duration(global_object, years, months, weeks, 0, 0, 0, 0, 0, 0, 0));
auto* years_months_weeks = MUST(create_temporal_duration(vm, years, months, weeks, 0, 0, 0, 0, 0, 0, 0));
// e. Let yearsMonthsWeeksLater be ? CalendarDateAdd(calendar, relativeTo, yearsMonthsWeeks, undefined, dateAdd).
auto* years_months_weeks_later = TRY(calendar_date_add(global_object, *calendar, relative_to, *years_months_weeks, nullptr, date_add));
auto* years_months_weeks_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_months_weeks, nullptr, date_add));
// f. Let monthsWeeksInDays be DaysUntil(yearsLater, yearsMonthsWeeksLater).
auto months_weeks_in_days = days_until(*years_later, *years_months_weeks_later);
@ -1223,10 +1217,10 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
days += months_weeks_in_days;
// i. Let daysDuration be ? CreateTemporalDuration(0, 0, 0, days, 0, 0, 0, 0, 0, 0).
auto* days_duration = TRY(create_temporal_duration(global_object, 0, 0, 0, days, 0, 0, 0, 0, 0, 0));
auto* days_duration = TRY(create_temporal_duration(vm, 0, 0, 0, days, 0, 0, 0, 0, 0, 0));
// j. Let daysLater be ? CalendarDateAdd(calendar, relativeTo, daysDuration, undefined, dateAdd).
auto* days_later = TRY(calendar_date_add(global_object, *calendar, relative_to, *days_duration, nullptr, date_add));
auto* days_later = TRY(calendar_date_add(vm, *calendar, relative_to, *days_duration, nullptr, date_add));
// k. Let untilOptions be OrdinaryObjectCreate(null).
auto* until_options = Object::create(realm, nullptr);
@ -1235,7 +1229,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "year"sv)));
// m. Let timePassed be ? CalendarDateUntil(calendar, relativeTo, daysLater, untilOptions).
auto* time_passed = TRY(calendar_date_until(global_object, *calendar, relative_to, days_later, *until_options));
auto* time_passed = TRY(calendar_date_until(vm, *calendar, relative_to, days_later, *until_options));
// n. Let yearsPassed be timePassed.[[Years]].
auto years_passed = time_passed->years();
@ -1247,10 +1241,10 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
auto* old_relative_to = relative_to;
// q. Let yearsDuration be ! CreateTemporalDuration(yearsPassed, 0, 0, 0, 0, 0, 0, 0, 0, 0).
years_duration = MUST(create_temporal_duration(global_object, years_passed, 0, 0, 0, 0, 0, 0, 0, 0, 0));
years_duration = MUST(create_temporal_duration(vm, years_passed, 0, 0, 0, 0, 0, 0, 0, 0, 0));
// r. Set relativeTo to ? CalendarDateAdd(calendar, relativeTo, yearsDuration, undefined, dateAdd).
relative_to = TRY(calendar_date_add(global_object, *calendar, relative_to, *years_duration, nullptr, date_add));
relative_to = TRY(calendar_date_add(vm, *calendar, relative_to, *years_duration, nullptr, date_add));
// s. Let daysPassed be DaysUntil(oldRelativeTo, relativeTo).
auto days_passed = days_until(*old_relative_to, *relative_to);
@ -1262,10 +1256,10 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
auto sign = days < 0 ? -1 : 1;
// v. Let oneYear be ! CreateTemporalDuration(sign, 0, 0, 0, 0, 0, 0, 0, 0, 0).
auto* one_year = MUST(create_temporal_duration(global_object, sign, 0, 0, 0, 0, 0, 0, 0, 0, 0));
auto* one_year = MUST(create_temporal_duration(vm, sign, 0, 0, 0, 0, 0, 0, 0, 0, 0));
// w. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneYear).
auto move_result = TRY(move_relative_date(global_object, *calendar, *relative_to, *one_year));
auto move_result = TRY(move_relative_date(vm, *calendar, *relative_to, *one_year));
// x. Let oneYearDays be moveResult.[[Days]].
auto one_year_days = move_result.days;
@ -1289,19 +1283,19 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
VERIFY(relative_to);
// a. Let yearsMonths be ! CreateTemporalDuration(years, months, 0, 0, 0, 0, 0, 0, 0, 0).
auto* years_months = MUST(create_temporal_duration(global_object, years, months, 0, 0, 0, 0, 0, 0, 0, 0));
auto* years_months = MUST(create_temporal_duration(vm, years, months, 0, 0, 0, 0, 0, 0, 0, 0));
// b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
auto* date_add = TRY(Value(calendar).get_method(global_object, vm.names.dateAdd));
// c. Let yearsMonthsLater be ? CalendarDateAdd(calendar, relativeTo, yearsMonths, undefined, dateAdd).
auto* years_months_later = TRY(calendar_date_add(global_object, *calendar, relative_to, *years_months, nullptr, date_add));
auto* years_months_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_months, nullptr, date_add));
// d. Let yearsMonthsWeeks be ! CreateTemporalDuration(years, months, weeks, 0, 0, 0, 0, 0, 0, 0).
auto* years_months_weeks = MUST(create_temporal_duration(global_object, years, months, weeks, 0, 0, 0, 0, 0, 0, 0));
auto* years_months_weeks = MUST(create_temporal_duration(vm, years, months, weeks, 0, 0, 0, 0, 0, 0, 0));
// e. Let yearsMonthsWeeksLater be ? CalendarDateAdd(calendar, relativeTo, yearsMonthsWeeks, undefined, dateAdd).
auto* years_months_weeks_later = TRY(calendar_date_add(global_object, *calendar, relative_to, *years_months_weeks, nullptr, date_add));
auto* years_months_weeks_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_months_weeks, nullptr, date_add));
// f. Let weeksInDays be DaysUntil(yearsMonthsLater, yearsMonthsWeeksLater).
auto weeks_in_days = days_until(*years_months_later, *years_months_weeks_later);
@ -1316,10 +1310,10 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
auto sign = days < 0 ? -1 : 1;
// j. Let oneMonth be ! CreateTemporalDuration(0, sign, 0, 0, 0, 0, 0, 0, 0, 0).
auto* one_month = MUST(create_temporal_duration(global_object, 0, sign, 0, 0, 0, 0, 0, 0, 0, 0));
auto* one_month = MUST(create_temporal_duration(vm, 0, sign, 0, 0, 0, 0, 0, 0, 0, 0));
// k. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneMonth).
auto move_result = TRY(move_relative_date(global_object, *calendar, *relative_to, *one_month));
auto move_result = TRY(move_relative_date(vm, *calendar, *relative_to, *one_month));
// l. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -1336,7 +1330,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
days -= one_month_days;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneMonth).
move_result = TRY(move_relative_date(global_object, *calendar, *relative_to, *one_month));
move_result = TRY(move_relative_date(vm, *calendar, *relative_to, *one_month));
// iv. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -1366,10 +1360,10 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
auto sign = days < 0 ? -1 : 1;
// b. Let oneWeek be ! CreateTemporalDuration(0, 0, sign, 0, 0, 0, 0, 0, 0, 0).
auto* one_week = MUST(create_temporal_duration(global_object, 0, 0, sign, 0, 0, 0, 0, 0, 0, 0));
auto* one_week = MUST(create_temporal_duration(vm, 0, 0, sign, 0, 0, 0, 0, 0, 0, 0));
// c. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneWeek).
auto move_result = TRY(move_relative_date(global_object, *calendar, *relative_to, *one_week));
auto move_result = TRY(move_relative_date(vm, *calendar, *relative_to, *one_week));
// d. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -1386,7 +1380,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
days -= one_week_days;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneWeek).
move_result = TRY(move_relative_date(global_object, *calendar, *relative_to, *one_week));
move_result = TRY(move_relative_date(vm, *calendar, *relative_to, *one_week));
// iv. Set relativeTo to moveResult.[[RelativeTo]].
relative_to = move_result.relative_to.cell();
@ -1511,17 +1505,15 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
}
// 19. Let duration be ? CreateDurationRecord(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
auto duration = TRY(create_duration_record(global_object, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
auto duration = TRY(create_duration_record(vm, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
// 20. Return the Record { [[DurationRecord]]: duration, [[Remainder]]: remainder }.
return RoundedDuration { .duration_record = duration, .remainder = remainder };
}
// 7.5.26 AdjustRoundedDurationDays ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, increment, unit, roundingMode, relativeTo ), https://tc39.es/proposal-temporal/#sec-temporal-adjustroundeddurationdays
ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(GlobalObject& global_object, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object)
ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object)
{
auto& vm = global_object.vm();
// 1. If Type(relativeTo) is not Object; or relativeTo does not have an [[InitializedTemporalZonedDateTime]] internal slot; or unit is one of "year", "month", "week", or "day"; or unit is "nanosecond" and increment is 1, then
if (relative_to_object == nullptr || !is<ZonedDateTime>(relative_to_object) || unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv) || (unit == "nanosecond"sv && increment == 1)) {
// a. Return ! CreateDurationRecord(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
@ -1546,10 +1538,10 @@ ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(GlobalObject& glo
direction = 1;
// 6. Let dayStart be ? AddZonedDateTime(relativeTo.[[Nanoseconds]], relativeTo.[[TimeZone]], relativeTo.[[Calendar]], years, months, weeks, days, 0, 0, 0, 0, 0, 0).
auto* day_start = TRY(add_zoned_date_time(global_object, relative_to.nanoseconds(), &relative_to.time_zone(), relative_to.calendar(), years, months, weeks, days, 0, 0, 0, 0, 0, 0));
auto* day_start = TRY(add_zoned_date_time(vm, relative_to.nanoseconds(), &relative_to.time_zone(), relative_to.calendar(), years, months, weeks, days, 0, 0, 0, 0, 0, 0));
// 7. Let dayEnd be ? AddZonedDateTime(dayStart, relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, direction, 0, 0, 0, 0, 0, 0).
auto* day_end = TRY(add_zoned_date_time(global_object, *day_start, &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, direction, 0, 0, 0, 0, 0, 0));
auto* day_end = TRY(add_zoned_date_time(vm, *day_start, &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, direction, 0, 0, 0, 0, 0, 0));
// 8. Let dayLengthNs be (dayEnd - dayStart).
auto day_length_ns = day_end->big_integer().minus(day_start->big_integer());
@ -1561,13 +1553,13 @@ ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(GlobalObject& glo
}
// 10. Set timeRemainderNs to ! RoundTemporalInstant((timeRemainderNs - dayLengthNs), increment, unit, roundingMode).
time_remainder_ns = round_temporal_instant(global_object, *js_bigint(vm, time_remainder_ns.minus(day_length_ns)), increment, unit, rounding_mode)->big_integer();
time_remainder_ns = round_temporal_instant(vm, *js_bigint(vm, time_remainder_ns.minus(day_length_ns)), increment, unit, rounding_mode)->big_integer();
// 11. Let adjustedDateDuration be ? AddDuration(years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, relativeTo).
auto adjusted_date_duration = TRY(add_duration(global_object, years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, &relative_to));
auto adjusted_date_duration = TRY(add_duration(vm, years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, &relative_to));
// 12. Let adjustedTimeDuration be ? BalanceDuration(0, 0, 0, 0, 0, 0, timeRemainderNs, "hour").
auto adjusted_time_duration = TRY(balance_duration(global_object, 0, 0, 0, 0, 0, 0, time_remainder_ns, "hour"sv));
auto adjusted_time_duration = TRY(balance_duration(vm, 0, 0, 0, 0, 0, 0, time_remainder_ns, "hour"sv));
// 13. Return ! CreateDurationRecord(adjustedDateDuration.[[Years]], adjustedDateDuration.[[Months]], adjustedDateDuration.[[Weeks]], adjustedDateDuration.[[Days]], adjustedTimeDuration.[[Hours]], adjustedTimeDuration.[[Minutes]], adjustedTimeDuration.[[Seconds]], adjustedTimeDuration.[[Milliseconds]], adjustedTimeDuration.[[Microseconds]], adjustedTimeDuration.[[Nanoseconds]]).
return create_duration_record(adjusted_date_duration.years, adjusted_date_duration.months, adjusted_date_duration.weeks, adjusted_date_duration.days, adjusted_time_duration.hours, adjusted_time_duration.minutes, adjusted_time_duration.seconds, adjusted_time_duration.milliseconds, adjusted_time_duration.microseconds, adjusted_time_duration.nanoseconds);
@ -1712,25 +1704,25 @@ String temporal_duration_to_string(double years, double months, double weeks, do
}
// 7.5.28 AddDurationToOrSubtractDurationFromDuration ( operation, duration, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoorsubtractdurationfromduration
ThrowCompletionOr<Duration*> add_duration_to_or_subtract_duration_from_duration(GlobalObject& global_object, ArithmeticOperation operation, Duration const& duration, Value other_value, Value options_value)
ThrowCompletionOr<Duration*> add_duration_to_or_subtract_duration_from_duration(VM& vm, ArithmeticOperation operation, Duration const& duration, Value other_value, Value options_value)
{
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == ArithmeticOperation::Subtract ? -1 : 1;
// 2. Set other to ? ToTemporalDurationRecord(other).
auto other = TRY(to_temporal_duration_record(global_object, other_value));
auto other = TRY(to_temporal_duration_record(vm, other_value));
// 3. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, options_value));
auto const* options = TRY(get_options_object(vm, options_value));
// 4. Let relativeTo be ? ToRelativeTemporalObject(options).
auto relative_to = TRY(to_relative_temporal_object(global_object, *options));
auto relative_to = TRY(to_relative_temporal_object(vm, *options));
// 5. Let result be ? AddDuration(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], sign × other.[[Years]], sign × other.[[Months]], sign × other.[[Weeks]], sign × other.[[Days]], sign × other.[[Hours]], sign × other.[[Minutes]], sign × other.[[Seconds]], sign × other.[[Milliseconds]], sign × other.[[Microseconds]], sign × other.[[Nanoseconds]], relativeTo).
auto result = TRY(add_duration(global_object, duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds(), sign * other.years, sign * other.months, sign * other.weeks, sign * other.days, sign * other.hours, sign * other.minutes, sign * other.seconds, sign * other.milliseconds, sign * other.microseconds, sign * other.nanoseconds, relative_to));
auto result = TRY(add_duration(vm, duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds(), sign * other.years, sign * other.months, sign * other.weeks, sign * other.days, sign * other.hours, sign * other.minutes, sign * other.seconds, sign * other.milliseconds, sign * other.microseconds, sign * other.nanoseconds, relative_to));
// 6. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
return MUST(create_temporal_duration(vm, result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
}
}

View file

@ -135,30 +135,30 @@ auto temporal_duration_record_fields = [](VM& vm) {
};
DurationRecord create_duration_record(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
ThrowCompletionOr<DurationRecord> create_duration_record(GlobalObject&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
ThrowCompletionOr<DurationRecord> create_duration_record(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
DateDurationRecord create_date_duration_record(double years, double months, double weeks, double days);
ThrowCompletionOr<DateDurationRecord> create_date_duration_record(GlobalObject&, double years, double months, double weeks, double days);
ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(GlobalObject&, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
ThrowCompletionOr<Duration*> to_temporal_duration(GlobalObject&, Value item);
ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject&, Value temporal_duration_like);
ThrowCompletionOr<DateDurationRecord> create_date_duration_record(VM&, double years, double months, double weeks, double days);
ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(VM&, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
ThrowCompletionOr<Duration*> to_temporal_duration(VM&, Value item);
ThrowCompletionOr<DurationRecord> to_temporal_duration_record(VM&, Value temporal_duration_like);
i8 duration_sign(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
bool is_valid_duration(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
StringView default_temporal_largest_unit(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds);
ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(GlobalObject&, Value temporal_duration_like);
ThrowCompletionOr<Duration*> create_temporal_duration(GlobalObject&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target = nullptr);
Duration* create_negated_temporal_duration(GlobalObject& global_object, Duration const& duration);
ThrowCompletionOr<double> calculate_offset_shift(GlobalObject&, Value relative_to_value, double years, double months, double weeks, double days);
ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(VM&, Value temporal_duration_like);
ThrowCompletionOr<Duration*> create_temporal_duration(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target = nullptr);
Duration* create_negated_temporal_duration(VM&, Duration const& duration);
ThrowCompletionOr<double> calculate_offset_shift(VM&, Value relative_to_value, double years, double months, double weeks, double days);
Crypto::SignedBigInteger total_duration_nanoseconds(double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, Crypto::SignedBigInteger const& nanoseconds, double offset_shift);
ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject&, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, Crypto::SignedBigInteger const& nanoseconds, String const& largest_unit, Object* relative_to = nullptr);
ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to);
ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject&, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to);
ThrowCompletionOr<DurationRecord> add_duration(GlobalObject&, double years1, double months1, double weeks1, double days1, double hours1, double minutes1, double seconds1, double milliseconds1, double microseconds1, double nanoseconds1, double years2, double months2, double weeks2, double days2, double hours2, double minutes2, double seconds2, double milliseconds2, double microseconds2, double nanoseconds2, Value relative_to_value);
ThrowCompletionOr<MoveRelativeDateResult> move_relative_date(GlobalObject&, Object& calendar, PlainDate& relative_to, Duration& duration);
ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(GlobalObject&, ZonedDateTime&, double years, double months, double weeks, double days);
ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object = nullptr);
ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(GlobalObject& global_object, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object);
ThrowCompletionOr<TimeDurationRecord> balance_duration(VM&, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, Crypto::SignedBigInteger const& nanoseconds, String const& largest_unit, Object* relative_to = nullptr);
ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM&, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to);
ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM&, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to);
ThrowCompletionOr<DurationRecord> add_duration(VM&, double years1, double months1, double weeks1, double days1, double hours1, double minutes1, double seconds1, double milliseconds1, double microseconds1, double nanoseconds1, double years2, double months2, double weeks2, double days2, double hours2, double minutes2, double seconds2, double milliseconds2, double microseconds2, double nanoseconds2, Value relative_to_value);
ThrowCompletionOr<MoveRelativeDateResult> move_relative_date(VM&, Object& calendar, PlainDate& relative_to, Duration& duration);
ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(VM&, ZonedDateTime&, double years, double months, double weeks, double days);
ThrowCompletionOr<RoundedDuration> round_duration(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object = nullptr);
ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object);
String temporal_duration_to_string(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Variant<StringView, u8> const& precision);
ThrowCompletionOr<Duration*> add_duration_to_or_subtract_duration_from_duration(GlobalObject&, ArithmeticOperation, Duration const&, Value other_value, Value options_value);
ThrowCompletionOr<Duration*> add_duration_to_or_subtract_duration_from_duration(VM&, ArithmeticOperation, Duration const&, Value other_value, Value options_value);
// 7.5.22 DaysUntil ( earlier, later ), https://tc39.es/proposal-temporal/#sec-temporal-daysuntil
template<typename EarlierObjectType, typename LaterObjectType>

View file

@ -49,40 +49,39 @@ ThrowCompletionOr<Value> DurationConstructor::call()
ThrowCompletionOr<Object*> DurationConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
// 2. Let y be ? ToIntegerWithoutRounding(years).
auto y = TRY(to_integer_without_rounding(global_object, vm.argument(0), ErrorType::TemporalInvalidDuration));
auto y = TRY(to_integer_without_rounding(vm, vm.argument(0), ErrorType::TemporalInvalidDuration));
// 3. Let mo be ? ToIntegerWithoutRounding(months).
auto mo = TRY(to_integer_without_rounding(global_object, vm.argument(1), ErrorType::TemporalInvalidDuration));
auto mo = TRY(to_integer_without_rounding(vm, vm.argument(1), ErrorType::TemporalInvalidDuration));
// 4. Let w be ? ToIntegerWithoutRounding(weeks).
auto w = TRY(to_integer_without_rounding(global_object, vm.argument(2), ErrorType::TemporalInvalidDuration));
auto w = TRY(to_integer_without_rounding(vm, vm.argument(2), ErrorType::TemporalInvalidDuration));
// 5. Let d be ? ToIntegerWithoutRounding(days).
auto d = TRY(to_integer_without_rounding(global_object, vm.argument(3), ErrorType::TemporalInvalidDuration));
auto d = TRY(to_integer_without_rounding(vm, vm.argument(3), ErrorType::TemporalInvalidDuration));
// 6. Let h be ? ToIntegerWithoutRounding(hours).
auto h = TRY(to_integer_without_rounding(global_object, vm.argument(4), ErrorType::TemporalInvalidDuration));
auto h = TRY(to_integer_without_rounding(vm, vm.argument(4), ErrorType::TemporalInvalidDuration));
// 7. Let m be ? ToIntegerWithoutRounding(minutes).
auto m = TRY(to_integer_without_rounding(global_object, vm.argument(5), ErrorType::TemporalInvalidDuration));
auto m = TRY(to_integer_without_rounding(vm, vm.argument(5), ErrorType::TemporalInvalidDuration));
// 8. Let s be ? ToIntegerWithoutRounding(seconds).
auto s = TRY(to_integer_without_rounding(global_object, vm.argument(6), ErrorType::TemporalInvalidDuration));
auto s = TRY(to_integer_without_rounding(vm, vm.argument(6), ErrorType::TemporalInvalidDuration));
// 9. Let ms be ? ToIntegerWithoutRounding(milliseconds).
auto ms = TRY(to_integer_without_rounding(global_object, vm.argument(7), ErrorType::TemporalInvalidDuration));
auto ms = TRY(to_integer_without_rounding(vm, vm.argument(7), ErrorType::TemporalInvalidDuration));
// 10. Let mis be ? ToIntegerWithoutRounding(microseconds).
auto mis = TRY(to_integer_without_rounding(global_object, vm.argument(8), ErrorType::TemporalInvalidDuration));
auto mis = TRY(to_integer_without_rounding(vm, vm.argument(8), ErrorType::TemporalInvalidDuration));
// 11. Let ns be ? ToIntegerWithoutRounding(nanoseconds).
auto ns = TRY(to_integer_without_rounding(global_object, vm.argument(9), ErrorType::TemporalInvalidDuration));
auto ns = TRY(to_integer_without_rounding(vm, vm.argument(9), ErrorType::TemporalInvalidDuration));
// 12. Return ? CreateTemporalDuration(y, mo, w, d, h, m, s, ms, mis, ns, NewTarget).
return TRY(create_temporal_duration(global_object, y, mo, w, d, h, m, s, ms, mis, ns, &new_target));
return TRY(create_temporal_duration(vm, y, mo, w, d, h, m, s, ms, mis, ns, &new_target));
}
// 7.2.2 Temporal.Duration.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.duration.from
@ -95,33 +94,33 @@ JS_DEFINE_NATIVE_FUNCTION(DurationConstructor::from)
auto& duration = static_cast<Duration&>(item.as_object());
// a. Return ! CreateTemporalDuration(item.[[Years]], item.[[Months]], item.[[Weeks]], item.[[Days]], item.[[Hours]], item.[[Minutes]], item.[[Seconds]], item.[[Milliseconds]], item.[[Microseconds]], item.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds()));
return MUST(create_temporal_duration(vm, duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds()));
}
// 2. Return ? ToTemporalDuration(item).
return TRY(to_temporal_duration(global_object, item));
return TRY(to_temporal_duration(vm, item));
}
// 7.2.3 Temporal.Duration.compare ( one, two [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration.compare
JS_DEFINE_NATIVE_FUNCTION(DurationConstructor::compare)
{
// 1. Set one to ? ToTemporalDuration(one).
auto* one = TRY(to_temporal_duration(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_duration(vm, vm.argument(0)));
// 2. Set two to ? ToTemporalDuration(two).
auto* two = TRY(to_temporal_duration(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_duration(vm, vm.argument(1)));
// 3. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(2)));
auto const* options = TRY(get_options_object(vm, vm.argument(2)));
// 4. Let relativeTo be ? ToRelativeTemporalObject(options).
auto relative_to = TRY(to_relative_temporal_object(global_object, *options));
auto relative_to = TRY(to_relative_temporal_object(vm, *options));
// 5. Let shift1 be ? CalculateOffsetShift(relativeTo, one.[[Years]], one.[[Months]], one.[[Weeks]], one.[[Days]]).
auto shift1 = TRY(calculate_offset_shift(global_object, relative_to, one->years(), one->months(), one->weeks(), one->days()));
auto shift1 = TRY(calculate_offset_shift(vm, relative_to, one->years(), one->months(), one->weeks(), one->days()));
// 6. Let shift2 be ? CalculateOffsetShift(relativeTo, two.[[Years]], two.[[Months]], two.[[Weeks]], two.[[Days]]).
auto shift2 = TRY(calculate_offset_shift(global_object, relative_to, two->years(), two->months(), two->weeks(), two->days()));
auto shift2 = TRY(calculate_offset_shift(vm, relative_to, two->years(), two->months(), two->weeks(), two->days()));
double days1;
double days2;
@ -129,10 +128,10 @@ JS_DEFINE_NATIVE_FUNCTION(DurationConstructor::compare)
// 7. If any of one.[[Years]], two.[[Years]], one.[[Months]], two.[[Months]], one.[[Weeks]], or two.[[Weeks]] are not 0, then
if (one->years() != 0 || two->years() != 0 || one->months() != 0 || two->months() != 0 || one->weeks() != 0 || two->weeks() != 0) {
// a. Let unbalanceResult1 be ? UnbalanceDurationRelative(one.[[Years]], one.[[Months]], one.[[Weeks]], one.[[Days]], "day", relativeTo).
auto unbalance_result1 = TRY(unbalance_duration_relative(global_object, one->years(), one->months(), one->weeks(), one->days(), "day", relative_to));
auto unbalance_result1 = TRY(unbalance_duration_relative(vm, one->years(), one->months(), one->weeks(), one->days(), "day", relative_to));
// b. Let unbalanceResult2 be ? UnbalanceDurationRelative(two.[[Years]], two.[[Months]], two.[[Weeks]], two.[[Days]], "day", relativeTo).
auto unbalance_result2 = TRY(unbalance_duration_relative(global_object, two->years(), two->months(), two->weeks(), two->days(), "day", relative_to));
auto unbalance_result2 = TRY(unbalance_duration_relative(vm, two->years(), two->months(), two->weeks(), two->days(), "day", relative_to));
// c. Let days1 be unbalanceResult1.[[Days]].
days1 = unbalance_result1.days;

View file

@ -203,7 +203,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::with)
auto* duration = TRY(typed_this_object(global_object));
// 3. Let temporalDurationLike be ? ToTemporalPartialDurationRecord(temporalDurationLike).
auto temporal_duration_like = TRY(to_temporal_partial_duration_record(global_object, vm.argument(0)));
auto temporal_duration_like = TRY(to_temporal_partial_duration_record(vm, vm.argument(0)));
// 4. If temporalDurationLike.[[Years]] is not undefined, then
// a. Let years be temporalDurationLike.[[Years]].
@ -266,7 +266,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::with)
auto nanoseconds = temporal_duration_like.nanoseconds.value_or(duration->nanoseconds());
// 24. Return ? CreateTemporalDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
return TRY(create_temporal_duration(global_object, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
return TRY(create_temporal_duration(vm, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
}
// 7.3.16 Temporal.Duration.prototype.negated ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.negated
@ -277,7 +277,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::negated)
auto* duration = TRY(typed_this_object(global_object));
// 3. Return ! CreateNegatedTemporalDuration(duration).
return create_negated_temporal_duration(global_object, *duration);
return create_negated_temporal_duration(vm, *duration);
}
// 7.3.17 Temporal.Duration.prototype.abs ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.abs
@ -288,7 +288,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::abs)
auto* duration = TRY(typed_this_object(global_object));
// 3. Return ! CreateTemporalDuration(abs(duration.[[Years]]), abs(duration.[[Months]]), abs(duration.[[Weeks]]), abs(duration.[[Days]]), abs(duration.[[Hours]]), abs(duration.[[Minutes]]), abs(duration.[[Seconds]]), abs(duration.[[Milliseconds]]), abs(duration.[[Microseconds]]), abs(duration.[[Nanoseconds]])).
return TRY(create_temporal_duration(global_object, fabs(duration->years()), fabs(duration->months()), fabs(duration->weeks()), fabs(duration->days()), fabs(duration->hours()), fabs(duration->minutes()), fabs(duration->seconds()), fabs(duration->milliseconds()), fabs(duration->microseconds()), fabs(duration->nanoseconds())));
return TRY(create_temporal_duration(vm, fabs(duration->years()), fabs(duration->months()), fabs(duration->weeks()), fabs(duration->days()), fabs(duration->hours()), fabs(duration->minutes()), fabs(duration->seconds()), fabs(duration->milliseconds()), fabs(duration->microseconds()), fabs(duration->nanoseconds())));
}
// 7.3.18 Temporal.Duration.prototype.add ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.add
@ -302,7 +302,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::add)
auto* duration = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromDuration(add, duration, other, options).
return TRY(add_duration_to_or_subtract_duration_from_duration(global_object, ArithmeticOperation::Add, *duration, other, options));
return TRY(add_duration_to_or_subtract_duration_from_duration(vm, ArithmeticOperation::Add, *duration, other, options));
}
// 7.3.19 Temporal.Duration.prototype.subtract ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.subtract
@ -316,7 +316,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::subtract)
auto* duration = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromDuration(subtract, duration, other, options).
return TRY(add_duration_to_or_subtract_duration_from_duration(global_object, ArithmeticOperation::Subtract, *duration, other, options));
return TRY(add_duration_to_or_subtract_duration_from_duration(vm, ArithmeticOperation::Subtract, *duration, other, options));
}
// 7.3.20 Temporal.Duration.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.round
@ -349,7 +349,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
// 5. Else,
else {
// a. Set roundTo to ? GetOptionsObject(roundTo).
round_to = TRY(get_options_object(global_object, vm.argument(0)));
round_to = TRY(get_options_object(vm, vm.argument(0)));
}
// 6. Let smallestUnitPresent be true.
@ -359,7 +359,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
bool largest_unit_present = true;
// 8. Let smallestUnit be ? GetTemporalUnit(roundTo, "smallestUnit", datetime, undefined).
auto smallest_unit = TRY(get_temporal_unit(global_object, *round_to, vm.names.smallestUnit, UnitGroup::DateTime, Optional<StringView> {}));
auto smallest_unit = TRY(get_temporal_unit(vm, *round_to, vm.names.smallestUnit, UnitGroup::DateTime, Optional<StringView> {}));
// 9. If smallestUnit is undefined, then
if (!smallest_unit.has_value()) {
@ -377,7 +377,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
default_largest_unit = larger_of_two_temporal_units(default_largest_unit, *smallest_unit);
// 12. Let largestUnit be ? GetTemporalUnit(roundTo, "largestUnit", datetime, undefined, « "auto" »).
auto largest_unit = TRY(get_temporal_unit(global_object, *round_to, vm.names.largestUnit, UnitGroup::DateTime, Optional<StringView> {}, { "auto"sv }));
auto largest_unit = TRY(get_temporal_unit(vm, *round_to, vm.names.largestUnit, UnitGroup::DateTime, Optional<StringView> {}, { "auto"sv }));
// 13. If largestUnit is undefined, then
if (!largest_unit.has_value()) {
@ -404,43 +404,43 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidUnitRange, *smallest_unit, *largest_unit);
// 17. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *round_to, "halfExpand"sv));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *round_to, "halfExpand"sv));
// 18. Let maximum be ! MaximumTemporalDurationRoundingIncrement(smallestUnit).
auto maximum = maximum_temporal_duration_rounding_increment(*smallest_unit);
// 19. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo, maximum, false).
auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *round_to, Optional<double>(maximum), false));
auto rounding_increment = TRY(to_temporal_rounding_increment(vm, *round_to, Optional<double>(maximum), false));
// 20. Let relativeTo be ? ToRelativeTemporalObject(roundTo).
auto relative_to = TRY(to_relative_temporal_object(global_object, *round_to));
auto relative_to = TRY(to_relative_temporal_object(vm, *round_to));
// 21. Let unbalanceResult be ? UnbalanceDurationRelative(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], largestUnit, relativeTo).
auto unbalance_result = TRY(unbalance_duration_relative(global_object, duration->years(), duration->months(), duration->weeks(), duration->days(), *largest_unit, relative_to));
auto unbalance_result = TRY(unbalance_duration_relative(vm, duration->years(), duration->months(), duration->weeks(), duration->days(), *largest_unit, relative_to));
// 22. Let roundResult be (? RoundDuration(unbalanceResult.[[Years]], unbalanceResult.[[Months]], unbalanceResult.[[Weeks]], unbalanceResult.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], roundingIncrement, smallestUnit, roundingMode, relativeTo)).[[DurationRecord]].
auto round_result = TRY(round_duration(global_object, unbalance_result.years, unbalance_result.months, unbalance_result.weeks, unbalance_result.days, duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), rounding_increment, *smallest_unit, rounding_mode, relative_to.is_object() ? &relative_to.as_object() : nullptr)).duration_record;
auto round_result = TRY(round_duration(vm, unbalance_result.years, unbalance_result.months, unbalance_result.weeks, unbalance_result.days, duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), rounding_increment, *smallest_unit, rounding_mode, relative_to.is_object() ? &relative_to.as_object() : nullptr)).duration_record;
// 23. Let adjustResult be ? AdjustRoundedDurationDays(roundResult.[[Years]], roundResult.[[Months]], roundResult.[[Weeks]], roundResult.[[Days]], roundResult.[[Hours]], roundResult.[[Minutes]], roundResult.[[Seconds]], roundResult.[[Milliseconds]], roundResult.[[Microseconds]], roundResult.[[Nanoseconds]], roundingIncrement, smallestUnit, roundingMode, relativeTo).
auto adjust_result = TRY(adjust_rounded_duration_days(global_object, round_result.years, round_result.months, round_result.weeks, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, round_result.nanoseconds, rounding_increment, *smallest_unit, rounding_mode, relative_to.is_object() ? &relative_to.as_object() : nullptr));
auto adjust_result = TRY(adjust_rounded_duration_days(vm, round_result.years, round_result.months, round_result.weeks, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, round_result.nanoseconds, rounding_increment, *smallest_unit, rounding_mode, relative_to.is_object() ? &relative_to.as_object() : nullptr));
// 24. Let balanceResult be ? BalanceDurationRelative(adjustResult.[[Years]], adjustResult.[[Months]], adjustResult.[[Weeks]], adjustResult.[[Days]], largestUnit, relativeTo).
auto balance_result = TRY(balance_duration_relative(global_object, adjust_result.years, adjust_result.months, adjust_result.weeks, adjust_result.days, *largest_unit, relative_to));
auto balance_result = TRY(balance_duration_relative(vm, adjust_result.years, adjust_result.months, adjust_result.weeks, adjust_result.days, *largest_unit, relative_to));
// 25. If Type(relativeTo) is Object and relativeTo has an [[InitializedTemporalZonedDateTime]] internal slot, then
if (relative_to.is_object() && is<ZonedDateTime>(relative_to.as_object())) {
auto& relative_to_zoned_date_time = static_cast<ZonedDateTime&>(relative_to.as_object());
// a. Set relativeTo to ? MoveRelativeZonedDateTime(relativeTo, balanceResult.[[Years]], balanceResult.[[Months]], balanceResult.[[Weeks]], 0).
relative_to = TRY(move_relative_zoned_date_time(global_object, relative_to_zoned_date_time, balance_result.years, balance_result.months, balance_result.weeks, 0));
relative_to = TRY(move_relative_zoned_date_time(vm, relative_to_zoned_date_time, balance_result.years, balance_result.months, balance_result.weeks, 0));
}
// 26. Let result be ? BalanceDuration(balanceResult.[[Days]], adjustResult.[[Hours]], adjustResult.[[Minutes]], adjustResult.[[Seconds]], adjustResult.[[Milliseconds]], adjustResult.[[Microseconds]], adjustResult.[[Nanoseconds]], largestUnit, relativeTo).
// FIXME: Narrowing conversion from 'double' to 'i64'
auto result = TRY(balance_duration(global_object, balance_result.days, adjust_result.hours, adjust_result.minutes, adjust_result.seconds, adjust_result.milliseconds, adjust_result.microseconds, Crypto::SignedBigInteger::create_from(adjust_result.nanoseconds), *largest_unit, relative_to.is_object() ? &relative_to.as_object() : nullptr));
auto result = TRY(balance_duration(vm, balance_result.days, adjust_result.hours, adjust_result.minutes, adjust_result.seconds, adjust_result.milliseconds, adjust_result.microseconds, Crypto::SignedBigInteger::create_from(adjust_result.nanoseconds), *largest_unit, relative_to.is_object() ? &relative_to.as_object() : nullptr));
// 27. Return ! CreateTemporalDuration(balanceResult.[[Years]], balanceResult.[[Months]], balanceResult.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, balance_result.years, balance_result.months, balance_result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
return MUST(create_temporal_duration(vm, balance_result.years, balance_result.months, balance_result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
}
// 7.3.21 Temporal.Duration.prototype.total ( totalOf ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.total
@ -471,17 +471,17 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
// 5. Else,
else {
// a. Set totalOf to ? GetOptionsObject(totalOf).
total_of = TRY(get_options_object(global_object, vm.argument(0)));
total_of = TRY(get_options_object(vm, vm.argument(0)));
}
// 6. Let relativeTo be ? ToRelativeTemporalObject(totalOf).
auto relative_to = TRY(to_relative_temporal_object(global_object, *total_of));
auto relative_to = TRY(to_relative_temporal_object(vm, *total_of));
// 7. Let unit be ? GetTemporalUnit(totalOf, "unit", datetime, required).
auto unit = TRY(get_temporal_unit(global_object, *total_of, vm.names.unit, UnitGroup::DateTime, TemporalUnitRequired {}));
auto unit = TRY(get_temporal_unit(vm, *total_of, vm.names.unit, UnitGroup::DateTime, TemporalUnitRequired {}));
// 8. Let unbalanceResult be ? UnbalanceDurationRelative(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], unit, relativeTo).
auto unbalance_result = TRY(unbalance_duration_relative(global_object, duration->years(), duration->months(), duration->weeks(), duration->days(), *unit, relative_to));
auto unbalance_result = TRY(unbalance_duration_relative(vm, duration->years(), duration->months(), duration->weeks(), duration->days(), *unit, relative_to));
// 9. Let intermediate be undefined.
ZonedDateTime* intermediate = nullptr;
@ -491,14 +491,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
auto& relative_to_zoned_date_time = static_cast<ZonedDateTime&>(relative_to.as_object());
// a. Set intermediate to ? MoveRelativeZonedDateTime(relativeTo, unbalanceResult.[[Years]], unbalanceResult.[[Months]], unbalanceResult.[[Weeks]], 0).
intermediate = TRY(move_relative_zoned_date_time(global_object, relative_to_zoned_date_time, unbalance_result.years, unbalance_result.months, unbalance_result.weeks, 0));
intermediate = TRY(move_relative_zoned_date_time(vm, relative_to_zoned_date_time, unbalance_result.years, unbalance_result.months, unbalance_result.weeks, 0));
}
// 11. Let balanceResult be ? BalanceDuration(unbalanceResult.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], unit, intermediate).
auto balance_result = TRY(balance_duration(global_object, unbalance_result.days, duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), Crypto::SignedBigInteger::create_from(duration->nanoseconds()), *unit, intermediate));
auto balance_result = TRY(balance_duration(vm, unbalance_result.days, duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), Crypto::SignedBigInteger::create_from(duration->nanoseconds()), *unit, intermediate));
// 12. Let roundRecord be ? RoundDuration(unbalanceResult.[[Years]], unbalanceResult.[[Months]], unbalanceResult.[[Weeks]], balanceResult.[[Days]], balanceResult.[[Hours]], balanceResult.[[Minutes]], balanceResult.[[Seconds]], balanceResult.[[Milliseconds]], balanceResult.[[Microseconds]], balanceResult.[[Nanoseconds]], 1, unit, "trunc", relativeTo).
auto round_record = TRY(round_duration(global_object, unbalance_result.years, unbalance_result.months, unbalance_result.weeks, balance_result.days, balance_result.hours, balance_result.minutes, balance_result.seconds, balance_result.milliseconds, balance_result.microseconds, balance_result.nanoseconds, 1, *unit, "trunc"sv, relative_to.is_object() ? &relative_to.as_object() : nullptr));
auto round_record = TRY(round_duration(vm, unbalance_result.years, unbalance_result.months, unbalance_result.weeks, balance_result.days, balance_result.hours, balance_result.minutes, balance_result.seconds, balance_result.milliseconds, balance_result.microseconds, balance_result.nanoseconds, 1, *unit, "trunc"sv, relative_to.is_object() ? &relative_to.as_object() : nullptr));
// 13. Let roundResult be roundRecord.[[DurationRecord]].
auto& round_result = round_record.duration_record;
@ -571,20 +571,20 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::to_string)
auto* duration = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(0)));
auto const* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let precision be ? ToSecondsStringPrecision(options).
auto precision = TRY(to_seconds_string_precision(global_object, *options));
auto precision = TRY(to_seconds_string_precision(vm, *options));
// 5. If precision.[[Unit]] is "minute", throw a RangeError exception.
if (precision.unit == "minute"sv)
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, "minute"sv, "smallestUnit"sv);
// 6. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *options, "trunc"sv));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *options, "trunc"sv));
// 7. Let result be (? RoundDuration(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], precision.[[Increment]], precision.[[Unit]], roundingMode)).[[DurationRecord]].
auto result = TRY(round_duration(global_object, duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), precision.increment, precision.unit, rounding_mode)).duration_record;
auto result = TRY(round_duration(vm, duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), precision.increment, precision.unit, rounding_mode)).duration_record;
// 8. Return ! TemporalDurationToString(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]], precision.[[Precision]]).
return js_string(vm, temporal_duration_to_string(result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds, precision.precision));

View file

@ -50,8 +50,11 @@ bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds)
}
// 8.5.2 CreateTemporalInstant ( epochNanoseconds [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalinstant
ThrowCompletionOr<Instant*> create_temporal_instant(GlobalObject& global_object, BigInt const& epoch_nanoseconds, FunctionObject const* new_target)
ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_nanoseconds, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(epochNanoseconds) is BigInt.
// 2. Assert: ! IsValidEpochNanoseconds(epochNanoseconds) is true.
@ -70,8 +73,11 @@ ThrowCompletionOr<Instant*> create_temporal_instant(GlobalObject& global_object,
}
// 8.5.3 ToTemporalInstant ( item ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalinstant
ThrowCompletionOr<Instant*> to_temporal_instant(GlobalObject& global_object, Value item)
ThrowCompletionOr<Instant*> to_temporal_instant(VM& vm, Value item)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If Type(item) is Object, then
if (item.is_object()) {
// a. If item has an [[InitializedTemporalInstant]] internal slot, then
@ -85,7 +91,7 @@ ThrowCompletionOr<Instant*> to_temporal_instant(GlobalObject& global_object, Val
auto& zoned_date_time = static_cast<ZonedDateTime&>(item.as_object());
// i. Return ! CreateTemporalInstant(item.[[Nanoseconds]]).
return create_temporal_instant(global_object, zoned_date_time.nanoseconds());
return create_temporal_instant(vm, zoned_date_time.nanoseconds());
}
}
@ -93,21 +99,19 @@ ThrowCompletionOr<Instant*> to_temporal_instant(GlobalObject& global_object, Val
auto string = TRY(item.to_string(global_object));
// 3. Let epochNanoseconds be ? ParseTemporalInstant(string).
auto* epoch_nanoseconds = TRY(parse_temporal_instant(global_object, string));
auto* epoch_nanoseconds = TRY(parse_temporal_instant(vm, string));
// 4. Return ! CreateTemporalInstant((epochNanoseconds)).
return create_temporal_instant(global_object, *epoch_nanoseconds);
return create_temporal_instant(vm, *epoch_nanoseconds);
}
// 8.5.4 ParseTemporalInstant ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalinstant
ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, String const& iso_string)
ThrowCompletionOr<BigInt*> parse_temporal_instant(VM& vm, String const& iso_string)
{
auto& vm = global_object.vm();
// 1. Assert: Type(isoString) is String.
// 2. Let result be ? ParseTemporalInstantString(isoString).
auto result = TRY(parse_temporal_instant_string(global_object, iso_string));
auto result = TRY(parse_temporal_instant_string(vm, iso_string));
// 3. Let offsetString be result.[[TimeZoneOffsetString]].
auto& offset_string = result.time_zone_offset;
@ -116,10 +120,10 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, S
VERIFY(offset_string.has_value());
// 5. Let utc be GetEpochFromISOParts(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
auto* utc = get_epoch_from_iso_parts(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond);
auto* utc = get_epoch_from_iso_parts(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond);
// 6. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(offsetString).
auto offset_nanoseconds = TRY(parse_time_zone_offset_string(global_object, *offset_string));
auto offset_nanoseconds = TRY(parse_time_zone_offset_string(vm, *offset_string));
// 7. Let result be utc - (offsetNanoseconds).
auto* result_ns = js_bigint(vm, utc->big_integer().minus(Crypto::SignedBigInteger::create_from(offset_nanoseconds)));
@ -150,10 +154,8 @@ i32 compare_epoch_nanoseconds(BigInt const& epoch_nanoseconds_one, BigInt const&
}
// 8.5.6 AddInstant ( epochNanoseconds, hours, minutes, seconds, milliseconds, microseconds, nanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-addinstant
ThrowCompletionOr<BigInt*> add_instant(GlobalObject& global_object, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds)
ThrowCompletionOr<BigInt*> add_instant(VM& vm, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds)
{
auto& vm = global_object.vm();
VERIFY(hours == trunc(hours) && minutes == trunc(minutes) && seconds == trunc(seconds) && milliseconds == trunc(milliseconds) && microseconds == trunc(microseconds) && nanoseconds == trunc(nanoseconds));
// 1. Let result be epochNanoseconds + (nanoseconds) + (microseconds) × 1000 + (milliseconds) × 10^6 + (seconds) × 10^9 + (minutes) × 60 × 10^9 + (hours) × 3600 × 10^9.
@ -176,22 +178,18 @@ ThrowCompletionOr<BigInt*> add_instant(GlobalObject& global_object, BigInt const
}
// 8.5.7 DifferenceInstant ( ns1, ns2, roundingIncrement, smallestUnit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-differenceinstant
BigInt* difference_instant(GlobalObject& global_object, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode)
BigInt* difference_instant(VM& vm, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode)
{
auto& vm = global_object.vm();
// 1. Assert: Type(ns1) is BigInt.
// 2. Assert: Type(ns2) is BigInt.
// 3. Return ! RoundTemporalInstant(ns2 - ns1, roundingIncrement, smallestUnit, roundingMode).
return round_temporal_instant(global_object, *js_bigint(vm, nanoseconds2.big_integer().minus(nanoseconds1.big_integer())), rounding_increment, smallest_unit, rounding_mode);
return round_temporal_instant(vm, *js_bigint(vm, nanoseconds2.big_integer().minus(nanoseconds1.big_integer())), rounding_increment, smallest_unit, rounding_mode);
}
// 8.5.8 RoundTemporalInstant ( ns, increment, unit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-roundtemporalinstant
BigInt* round_temporal_instant(GlobalObject& global_object, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode)
BigInt* round_temporal_instant(VM& vm, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode)
{
auto& vm = global_object.vm();
// 1. Assert: Type(ns) is BigInt.
u64 increment_nanoseconds;
@ -234,7 +232,7 @@ BigInt* round_temporal_instant(GlobalObject& global_object, BigInt const& nanose
}
// 8.5.9 TemporalInstantToString ( instant, timeZone, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring
ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject& global_object, Instant& instant, Value time_zone, Variant<StringView, u8> const& precision)
ThrowCompletionOr<String> temporal_instant_to_string(VM& vm, Instant& instant, Value time_zone, Variant<StringView, u8> const& precision)
{
// 1. Assert: Type(instant) is Object.
// 2. Assert: instant has an [[InitializedTemporalInstant]] internal slot.
@ -245,17 +243,17 @@ ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject& global_object
// 4. If outputTimeZone is undefined, then
if (output_time_zone.is_undefined()) {
// a. Set outputTimeZone to ! CreateTemporalTimeZone("UTC").
output_time_zone = MUST(create_temporal_time_zone(global_object, "UTC"sv));
output_time_zone = MUST(create_temporal_time_zone(vm, "UTC"sv));
}
// 5. Let isoCalendar be ! GetISO8601Calendar().
auto* iso_calendar = get_iso8601_calendar(global_object);
auto* iso_calendar = get_iso8601_calendar(vm);
// 6. Let dateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(outputTimeZone, instant, isoCalendar).
auto* date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, output_time_zone, instant, *iso_calendar));
auto* date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, output_time_zone, instant, *iso_calendar));
// 7. Let dateTimeString be ? TemporalDateTimeToString(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], undefined, precision, "never").
auto date_time_string = TRY(temporal_date_time_to_string(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), js_undefined(), precision, "never"sv));
auto date_time_string = TRY(temporal_date_time_to_string(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), js_undefined(), precision, "never"sv));
String time_zone_string;
@ -267,7 +265,7 @@ ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject& global_object
// 9. Else,
else {
// a. Let offsetNs be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_ns = TRY(get_offset_nanoseconds_for(global_object, time_zone, instant));
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
// b. Let timeZoneString be ! FormatISOTimeZoneOffsetString(offsetNs).
time_zone_string = format_iso_time_zone_offset_string(offset_ns);
@ -278,39 +276,37 @@ ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject& global_object
}
// 8.5.10 DifferenceTemporalInstant ( operation, instant, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalinstant
ThrowCompletionOr<Duration*> difference_temporal_instant(GlobalObject& global_object, DifferenceOperation operation, Instant const& instant, Value other_value, Value options_value)
ThrowCompletionOr<Duration*> difference_temporal_instant(VM& vm, DifferenceOperation operation, Instant const& instant, Value other_value, Value options_value)
{
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
// 2. Set other to ? ToTemporalInstant(other).
auto* other = TRY(to_temporal_instant(global_object, other_value));
auto* other = TRY(to_temporal_instant(vm, other_value));
// 3. Let settings be ? GetDifferenceSettings(operation, options, time, « », "nanosecond", "second").
auto settings = TRY(get_difference_settings(global_object, operation, options_value, UnitGroup::Time, {}, { "nanosecond"sv }, "second"sv));
auto settings = TRY(get_difference_settings(vm, operation, options_value, UnitGroup::Time, {}, { "nanosecond"sv }, "second"sv));
// 4. Let roundedNs be ! DifferenceInstant(instant.[[Nanoseconds]], other.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]]).
auto* rounded_ns = difference_instant(global_object, instant.nanoseconds(), other->nanoseconds(), settings.rounding_increment, settings.smallest_unit, settings.rounding_mode);
auto* rounded_ns = difference_instant(vm, instant.nanoseconds(), other->nanoseconds(), settings.rounding_increment, settings.smallest_unit, settings.rounding_mode);
// 5. Assert: The following steps cannot fail due to overflow in the Number domain because abs(roundedNs) ≤ 2 × nsMaxInstant.
// 6. Let result be ! BalanceDuration(0, 0, 0, 0, 0, 0, roundedNs, settings.[[LargestUnit]]).
auto result = MUST(balance_duration(global_object, 0, 0, 0, 0, 0, 0, rounded_ns->big_integer(), settings.largest_unit));
auto result = MUST(balance_duration(vm, 0, 0, 0, 0, 0, 0, rounded_ns->big_integer(), settings.largest_unit));
// 7. Return ! CreateTemporalDuration(0, 0, 0, 0, sign × result.[[Hours]], sign × result.[[Minutes]], sign × result.[[Seconds]], sign × result.[[Milliseconds]], sign × result.[[Microseconds]], sign × result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, 0, 0, 0, 0, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
return MUST(create_temporal_duration(vm, 0, 0, 0, 0, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
}
// 8.5.11 AddDurationToOrSubtractDurationFromInstant ( operation, instant, temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoorsubtractdurationfrominstant
ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(GlobalObject& global_object, ArithmeticOperation operation, Instant const& instant, Value temporal_duration_like)
ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(VM& vm, ArithmeticOperation operation, Instant const& instant, Value temporal_duration_like)
{
auto& vm = global_object.vm();
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == ArithmeticOperation::Subtract ? -1 : 1;
// 2. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
auto duration = TRY(to_temporal_duration_record(vm, temporal_duration_like));
// 3. If duration.[[Days]] is not 0, throw a RangeError exception.
if (duration.days != 0)
@ -329,10 +325,10 @@ ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(Gl
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationPropertyValueNonZero, "years", duration.years);
// 7. Let ns be ? AddInstant(instant.[[Nanoseconds]], sign × duration.[[Hours]], sign × duration.[[Minutes]], sign × duration.[[Seconds]], sign × duration.[[Milliseconds]], sign × duration.[[Microseconds]], sign × duration.[[Nanoseconds]]).
auto* ns = TRY(add_instant(global_object, instant.nanoseconds(), sign * duration.hours, sign * duration.minutes, sign * duration.seconds, sign * duration.milliseconds, sign * duration.microseconds, sign * duration.nanoseconds));
auto* ns = TRY(add_instant(vm, instant.nanoseconds(), sign * duration.hours, sign * duration.minutes, sign * duration.seconds, sign * duration.milliseconds, sign * duration.microseconds, sign * duration.nanoseconds));
// 8. Return ! CreateTemporalInstant(ns).
return MUST(create_temporal_instant(global_object, *ns));
return MUST(create_temporal_instant(vm, *ns));
}
}

View file

@ -41,15 +41,15 @@ static auto const ns_max_instant = "8640000000000000000000"_sbigint;
static auto const ns_min_instant = "-8640000000000000000000"_sbigint;
bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds);
ThrowCompletionOr<Instant*> create_temporal_instant(GlobalObject&, BigInt const& nanoseconds, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<Instant*> to_temporal_instant(GlobalObject&, Value item);
ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject&, String const& iso_string);
ThrowCompletionOr<Instant*> create_temporal_instant(VM&, BigInt const& nanoseconds, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<Instant*> to_temporal_instant(VM&, Value item);
ThrowCompletionOr<BigInt*> parse_temporal_instant(VM&, String const& iso_string);
i32 compare_epoch_nanoseconds(BigInt const&, BigInt const&);
ThrowCompletionOr<BigInt*> add_instant(GlobalObject&, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
BigInt* difference_instant(GlobalObject&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode);
BigInt* round_temporal_instant(GlobalObject&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode);
ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
ThrowCompletionOr<Duration*> difference_temporal_instant(GlobalObject&, DifferenceOperation, Instant const&, Value other, Value options);
ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(GlobalObject&, ArithmeticOperation, Instant const&, Value temporal_duration_like);
ThrowCompletionOr<BigInt*> add_instant(VM&, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
BigInt* difference_instant(VM&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode);
BigInt* round_temporal_instant(VM&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode);
ThrowCompletionOr<String> temporal_instant_to_string(VM&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
ThrowCompletionOr<Duration*> difference_temporal_instant(VM&, DifferenceOperation, Instant const&, Value other, Value options);
ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(VM&, ArithmeticOperation, Instant const&, Value temporal_duration_like);
}

View file

@ -62,7 +62,7 @@ ThrowCompletionOr<Object*> InstantConstructor::construct(FunctionObject& new_tar
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 4. Return ? CreateTemporalInstant(epochNanoseconds, NewTarget).
return TRY(create_temporal_instant(global_object, *epoch_nanoseconds, &new_target));
return TRY(create_temporal_instant(vm, *epoch_nanoseconds, &new_target));
}
// 8.2.2 Temporal.Instant.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.instant.from
@ -73,11 +73,11 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from)
// 1. If Type(item) is Object and item has an [[InitializedTemporalInstant]] internal slot, then
if (item.is_object() && is<Instant>(item.as_object())) {
// a. Return ! CreateTemporalInstant(item.[[Nanoseconds]]).
return MUST(create_temporal_instant(global_object, *js_bigint(vm, static_cast<Instant&>(item.as_object()).nanoseconds().big_integer())));
return MUST(create_temporal_instant(vm, *js_bigint(vm, static_cast<Instant&>(item.as_object()).nanoseconds().big_integer())));
}
// 2. Return ? ToTemporalInstant(item).
return TRY(to_temporal_instant(global_object, item));
return TRY(to_temporal_instant(vm, item));
}
// 8.2.3 Temporal.Instant.fromEpochSeconds ( epochSeconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochseconds
@ -97,7 +97,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 5. Return ! CreateTemporalInstant(epochNanoseconds).
return MUST(create_temporal_instant(global_object, *epoch_nanoseconds));
return MUST(create_temporal_instant(vm, *epoch_nanoseconds));
}
// 8.2.4 Temporal.Instant.fromEpochMilliseconds ( epochMilliseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmilliseconds
@ -117,7 +117,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 5. Return ! CreateTemporalInstant(epochNanoseconds).
return MUST(create_temporal_instant(global_object, *epoch_nanoseconds));
return MUST(create_temporal_instant(vm, *epoch_nanoseconds));
}
// 8.2.5 Temporal.Instant.fromEpochMicroseconds ( epochMicroseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmicroseconds
@ -134,7 +134,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 4. Return ! CreateTemporalInstant(epochNanoseconds).
return MUST(create_temporal_instant(global_object, *epoch_nanoseconds));
return MUST(create_temporal_instant(vm, *epoch_nanoseconds));
}
// 8.2.6 Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochnanoseconds
@ -148,17 +148,17 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_nanoseconds)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 3. Return ! CreateTemporalInstant(epochNanoseconds).
return MUST(create_temporal_instant(global_object, *epoch_nanoseconds));
return MUST(create_temporal_instant(vm, *epoch_nanoseconds));
}
// 8.2.7 Temporal.Instant.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.instant.compare
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::compare)
{
// 1. Set one to ? ToTemporalInstant(one).
auto* one = TRY(to_temporal_instant(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_instant(vm, vm.argument(0)));
// 2. Set two to ? ToTemporalInstant(two).
auto* two = TRY(to_temporal_instant(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_instant(vm, vm.argument(1)));
// 3. Return 𝔽(! CompareEpochNanoseconds(one.[[Nanoseconds]], two.[[Nanoseconds]])).
return Value(compare_epoch_nanoseconds(one->nanoseconds(), two->nanoseconds()));

View file

@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::add)
auto* instant = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromInstant(add, instant, temporalDurationLike).
return TRY(add_duration_to_or_subtract_duration_from_instant(global_object, ArithmeticOperation::Add, *instant, temporal_duration_like));
return TRY(add_duration_to_or_subtract_duration_from_instant(vm, ArithmeticOperation::Add, *instant, temporal_duration_like));
}
// 8.3.8 Temporal.Instant.prototype.subtract ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.subtract
@ -141,7 +141,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::subtract)
auto* instant = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromInstant(subtract, instant, temporalDurationLike).
return TRY(add_duration_to_or_subtract_duration_from_instant(global_object, ArithmeticOperation::Subtract, *instant, temporal_duration_like));
return TRY(add_duration_to_or_subtract_duration_from_instant(vm, ArithmeticOperation::Subtract, *instant, temporal_duration_like));
}
// 8.3.9 Temporal.Instant.prototype.until ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.until
@ -155,7 +155,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::until)
auto* instant = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalInstant(until, instant, other, options).
return TRY(difference_temporal_instant(global_object, DifferenceOperation::Until, *instant, other, options));
return TRY(difference_temporal_instant(vm, DifferenceOperation::Until, *instant, other, options));
}
// 8.3.10 Temporal.Instant.prototype.since ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.since
@ -169,7 +169,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::since)
auto* instant = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalInstant(since, instant, other, options).
return TRY(difference_temporal_instant(global_object, DifferenceOperation::Since, *instant, other, options));
return TRY(difference_temporal_instant(vm, DifferenceOperation::Since, *instant, other, options));
}
// 8.3.11 Temporal.Instant.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.round
@ -202,11 +202,11 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round)
// 5. Else,
else {
// a. Set roundTo to ? GetOptionsObject(roundTo).
round_to = TRY(get_options_object(global_object, vm.argument(0)));
round_to = TRY(get_options_object(vm, vm.argument(0)));
}
// 6. Let smallestUnit be ? GetTemporalUnit(roundTo, "smallestUnit", time, required).
auto smallest_unit_value = TRY(get_temporal_unit(global_object, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}));
auto smallest_unit_value = TRY(get_temporal_unit(vm, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}));
// 6. If smallestUnit is undefined, throw a RangeError exception.
if (!smallest_unit_value.has_value())
@ -216,7 +216,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round)
auto& smallest_unit = *smallest_unit_value;
// 7. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *round_to, "halfExpand"));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *round_to, "halfExpand"));
double maximum;
// 8. If smallestUnit is "hour", then
@ -253,13 +253,13 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round)
}
// 14. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo, maximum, true).
auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *round_to, maximum, true));
auto rounding_increment = TRY(to_temporal_rounding_increment(vm, *round_to, maximum, true));
// 15. Let roundedNs be ! RoundTemporalInstant(instant.[[Nanoseconds]], roundingIncrement, smallestUnit, roundingMode).
auto* rounded_ns = round_temporal_instant(global_object, instant->nanoseconds(), rounding_increment, smallest_unit, rounding_mode);
auto* rounded_ns = round_temporal_instant(vm, instant->nanoseconds(), rounding_increment, smallest_unit, rounding_mode);
// 16. Return ! CreateTemporalInstant(roundedNs).
return MUST(create_temporal_instant(global_object, *rounded_ns));
return MUST(create_temporal_instant(vm, *rounded_ns));
}
// 8.3.12 Temporal.Instant.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.equals
@ -270,7 +270,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::equals)
auto* instant = TRY(typed_this_object(global_object));
// 3. Set other to ? ToTemporalInstant(other).
auto other = TRY(to_temporal_instant(global_object, vm.argument(0)));
auto other = TRY(to_temporal_instant(vm, vm.argument(0)));
// 4. If instant.[[Nanoseconds]] ≠ other.[[Nanoseconds]], return false.
if (instant->nanoseconds().big_integer() != other->nanoseconds().big_integer())
@ -288,7 +288,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_string)
auto* instant = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(0)));
auto const* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let timeZone be ? Get(options, "timeZone").
auto time_zone = TRY(options->get(vm.names.timeZone));
@ -296,23 +296,23 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_string)
// 5. If timeZone is not undefined, then
if (!time_zone.is_undefined()) {
// a. Set timeZone to ? ToTemporalTimeZone(timeZone).
time_zone = TRY(to_temporal_time_zone(global_object, time_zone));
time_zone = TRY(to_temporal_time_zone(vm, time_zone));
}
// 6. Let precision be ? ToSecondsStringPrecision(options).
auto precision = TRY(to_seconds_string_precision(global_object, *options));
auto precision = TRY(to_seconds_string_precision(vm, *options));
// 7. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *options, "trunc"sv));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *options, "trunc"sv));
// 8. Let roundedNs be ! RoundTemporalInstant(instant.[[Nanoseconds]], precision.[[Increment]], precision.[[Unit]], roundingMode).
auto* rounded_ns = round_temporal_instant(global_object, instant->nanoseconds(), precision.increment, precision.unit, rounding_mode);
auto* rounded_ns = round_temporal_instant(vm, instant->nanoseconds(), precision.increment, precision.unit, rounding_mode);
// 9. Let roundedInstant be ! CreateTemporalInstant(roundedNs).
auto* rounded_instant = MUST(create_temporal_instant(global_object, *rounded_ns));
auto* rounded_instant = MUST(create_temporal_instant(vm, *rounded_ns));
// 10. Return ? TemporalInstantToString(roundedInstant, timeZone, precision.[[Precision]]).
return js_string(vm, TRY(temporal_instant_to_string(global_object, *rounded_instant, time_zone, precision.precision)));
return js_string(vm, TRY(temporal_instant_to_string(vm, *rounded_instant, time_zone, precision.precision)));
}
// 8.3.14 Temporal.Instant.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tolocalestring
@ -324,7 +324,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_locale_string)
auto* instant = TRY(typed_this_object(global_object));
// 3. Return ? TemporalInstantToString(instant, undefined, "auto").
return js_string(vm, TRY(temporal_instant_to_string(global_object, *instant, js_undefined(), "auto"sv)));
return js_string(vm, TRY(temporal_instant_to_string(vm, *instant, js_undefined(), "auto"sv)));
}
// 8.3.15 Temporal.Instant.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tojson
@ -335,7 +335,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_json)
auto* instant = TRY(typed_this_object(global_object));
// 3. Return ? TemporalInstantToString(instant, undefined, "auto").
return js_string(vm, TRY(temporal_instant_to_string(global_object, *instant, js_undefined(), "auto"sv)));
return js_string(vm, TRY(temporal_instant_to_string(vm, *instant, js_undefined(), "auto"sv)));
}
// 8.3.16 Temporal.Instant.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.valueof
@ -370,7 +370,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time)
}
// 6. Let calendar be ? ToTemporalCalendar(calendarLike).
auto* calendar = TRY(to_temporal_calendar(global_object, calendar_like));
auto* calendar = TRY(to_temporal_calendar(vm, calendar_like));
// 7. Let temporalTimeZoneLike be ? Get(item, "timeZone").
auto temporal_time_zone_like = TRY(item.as_object().get(vm.names.timeZone));
@ -382,10 +382,10 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time)
}
// 9. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
auto* time_zone = TRY(to_temporal_time_zone(global_object, temporal_time_zone_like));
auto* time_zone = TRY(to_temporal_time_zone(vm, temporal_time_zone_like));
// 10. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, calendar).
return TRY(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), *time_zone, *calendar));
return TRY(create_temporal_zoned_date_time(vm, instant->nanoseconds(), *time_zone, *calendar));
}
// 8.3.18 Temporal.Instant.prototype.toZonedDateTimeISO ( item ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tozoneddatetimeiso
@ -410,13 +410,13 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time_iso)
}
// 4. Let timeZone be ? ToTemporalTimeZone(item).
auto* time_zone = TRY(to_temporal_time_zone(global_object, item));
auto* time_zone = TRY(to_temporal_time_zone(vm, item));
// 5. Let calendar be ! GetISO8601Calendar().
auto* calendar = get_iso8601_calendar(global_object);
auto* calendar = get_iso8601_calendar(vm);
// 6. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, calendar).
return TRY(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), *time_zone, *calendar));
return TRY(create_temporal_zoned_date_time(vm, instant->nanoseconds(), *time_zone, *calendar));
}
}

View file

@ -50,14 +50,14 @@ void Now::initialize(Realm& realm)
JS_DEFINE_NATIVE_FUNCTION(Now::time_zone)
{
// 1. Return ! SystemTimeZone().
return system_time_zone(global_object);
return system_time_zone(vm);
}
// 2.2.2 Temporal.Now.instant ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.instant
JS_DEFINE_NATIVE_FUNCTION(Now::instant)
{
// 1. Return ! SystemInstant().
return system_instant(global_object);
return system_instant(vm);
}
// 2.2.3 Temporal.Now.plainDateTime ( calendarLike [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindatetime
@ -67,7 +67,7 @@ JS_DEFINE_NATIVE_FUNCTION(Now::plain_date_time)
auto temporal_time_zone_like = vm.argument(1);
// 1. Return ? SystemDateTime(temporalTimeZoneLike, calendarLike).
return TRY(system_date_time(global_object, temporal_time_zone_like, calendar_like));
return TRY(system_date_time(vm, temporal_time_zone_like, calendar_like));
}
// 2.2.4 Temporal.Now.plainDateTimeISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindatetimeiso
@ -76,10 +76,10 @@ JS_DEFINE_NATIVE_FUNCTION(Now::plain_date_time_iso)
auto temporal_time_zone_like = vm.argument(0);
// 1, Let calendar be ! GetISO8601Calendar().
auto* calendar = get_iso8601_calendar(global_object);
auto* calendar = get_iso8601_calendar(vm);
// 2. Return ? SystemDateTime(temporalTimeZoneLike, calendar).
return TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
return TRY(system_date_time(vm, temporal_time_zone_like, calendar));
}
// 2.2.5 Temporal.Now.zonedDateTime ( calendarLike [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.zoneddatetime
@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(Now::zoned_date_time)
auto temporal_time_zone_like = vm.argument(1);
// 1. Return ? SystemZonedDateTime(temporalTimeZoneLike, calendarLike).
return TRY(system_zoned_date_time(global_object, temporal_time_zone_like, calendar_like));
return TRY(system_zoned_date_time(vm, temporal_time_zone_like, calendar_like));
}
// 2.2.6 Temporal.Now.zonedDateTimeISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.zoneddatetimeiso
@ -98,10 +98,10 @@ JS_DEFINE_NATIVE_FUNCTION(Now::zoned_date_time_iso)
auto temporal_time_zone_like = vm.argument(0);
// 1, Let calendar be ! GetISO8601Calendar().
auto* calendar = get_iso8601_calendar(global_object);
auto* calendar = get_iso8601_calendar(vm);
// 2. Return ? SystemZonedDateTime(temporalTimeZoneLike, calendar).
return TRY(system_zoned_date_time(global_object, temporal_time_zone_like, calendar));
return TRY(system_zoned_date_time(vm, temporal_time_zone_like, calendar));
}
// 2.2.7 Temporal.Now.plainDate ( calendarLike [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindate
@ -111,10 +111,10 @@ JS_DEFINE_NATIVE_FUNCTION(Now::plain_date)
auto temporal_time_zone_like = vm.argument(1);
// 1. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendarLike).
auto* date_time = TRY(system_date_time(global_object, temporal_time_zone_like, calendar_like));
auto* date_time = TRY(system_date_time(vm, temporal_time_zone_like, calendar_like));
// 2. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[Calendar]]).
return MUST(create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
return MUST(create_temporal_date(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
}
// 2.2.8 Temporal.Now.plainDateISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindateiso
@ -123,13 +123,13 @@ JS_DEFINE_NATIVE_FUNCTION(Now::plain_date_iso)
auto temporal_time_zone_like = vm.argument(0);
// 1. Let calendar be ! GetISO8601Calendar().
auto* calendar = get_iso8601_calendar(global_object);
auto* calendar = get_iso8601_calendar(vm);
// 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
auto* date_time = TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
auto* date_time = TRY(system_date_time(vm, temporal_time_zone_like, calendar));
// 3. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[Calendar]]).
return MUST(create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
return MUST(create_temporal_date(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
}
// 2.2.9 Temporal.Now.plainTimeISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaintimeiso
@ -138,27 +138,27 @@ JS_DEFINE_NATIVE_FUNCTION(Now::plain_time_iso)
auto temporal_time_zone_like = vm.argument(0);
// 1. Let calendar be ! GetISO8601Calendar().
auto* calendar = get_iso8601_calendar(global_object);
auto* calendar = get_iso8601_calendar(vm);
// 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
auto* date_time = TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
auto* date_time = TRY(system_date_time(vm, temporal_time_zone_like, calendar));
// 3. Return ! CreateTemporalTime(dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
return MUST(create_temporal_time(global_object, date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond()));
return MUST(create_temporal_time(vm, date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond()));
}
// 2.3.1 SystemTimeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemtimezone
TimeZone* system_time_zone(GlobalObject& global_object)
TimeZone* system_time_zone(VM& vm)
{
// 1. Let identifier be ! DefaultTimeZone().
auto identifier = default_time_zone();
// 2. Return ! CreateTemporalTimeZone(identifier).
return MUST(create_temporal_time_zone(global_object, identifier));
return MUST(create_temporal_time_zone(vm, identifier));
}
// 2.3.2 SystemUTCEpochNanoseconds ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemutcepochnanoseconds
BigInt* system_utc_epoch_nanoseconds(GlobalObject& global_object)
BigInt* system_utc_epoch_nanoseconds(VM& vm)
{
// 1. Let ns be the approximate current UTC date and time, in nanoseconds since the epoch.
auto now = Time::now_realtime().to_nanoseconds();
@ -169,69 +169,69 @@ BigInt* system_utc_epoch_nanoseconds(GlobalObject& global_object)
// if an overflow occurs during seconds -> nanoseconds conversion.
// 3. Return (ns).
return js_bigint(global_object.heap(), move(ns));
return js_bigint(vm, move(ns));
}
// 2.3.3 SystemInstant ( ), https://tc39.es/proposal-temporal/#sec-temporal-systeminstant
Instant* system_instant(GlobalObject& global_object)
Instant* system_instant(VM& vm)
{
// 1. Let ns be ! SystemUTCEpochNanoseconds().
auto* ns = system_utc_epoch_nanoseconds(global_object);
auto* ns = system_utc_epoch_nanoseconds(vm);
// 2. Return ! CreateTemporalInstant(ns).
return MUST(create_temporal_instant(global_object, *ns));
return MUST(create_temporal_instant(vm, *ns));
}
// 2.3.4 SystemDateTime ( temporalTimeZoneLike, calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-systemdatetime
ThrowCompletionOr<PlainDateTime*> system_date_time(GlobalObject& global_object, Value temporal_time_zone_like, Value calendar_like)
ThrowCompletionOr<PlainDateTime*> system_date_time(VM& vm, Value temporal_time_zone_like, Value calendar_like)
{
Object* time_zone;
// 1. If temporalTimeZoneLike is undefined, then
if (temporal_time_zone_like.is_undefined()) {
// a. Let timeZone be ! SystemTimeZone().
time_zone = system_time_zone(global_object);
time_zone = system_time_zone(vm);
}
// 2. Else,
else {
// a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
time_zone = TRY(to_temporal_time_zone(global_object, temporal_time_zone_like));
time_zone = TRY(to_temporal_time_zone(vm, temporal_time_zone_like));
}
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
auto* calendar = TRY(to_temporal_calendar(global_object, calendar_like));
auto* calendar = TRY(to_temporal_calendar(vm, calendar_like));
// 4. Let instant be ! SystemInstant().
auto* instant = system_instant(global_object);
auto* instant = system_instant(vm);
// 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
return builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar);
return builtin_time_zone_get_plain_date_time_for(vm, time_zone, *instant, *calendar);
}
// 2.3.5 SystemZonedDateTime ( temporalTimeZoneLike, calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-systemzoneddatetime
ThrowCompletionOr<ZonedDateTime*> system_zoned_date_time(GlobalObject& global_object, Value temporal_time_zone_like, Value calendar_like)
ThrowCompletionOr<ZonedDateTime*> system_zoned_date_time(VM& vm, Value temporal_time_zone_like, Value calendar_like)
{
Object* time_zone;
// 1. If temporalTimeZoneLike is undefined, then
if (temporal_time_zone_like.is_undefined()) {
// a. Let timeZone be ! SystemTimeZone().
time_zone = system_time_zone(global_object);
time_zone = system_time_zone(vm);
}
// 2. Else,
else {
// a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
time_zone = TRY(to_temporal_time_zone(global_object, temporal_time_zone_like));
time_zone = TRY(to_temporal_time_zone(vm, temporal_time_zone_like));
}
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
auto* calendar = TRY(to_temporal_calendar(global_object, calendar_like));
auto* calendar = TRY(to_temporal_calendar(vm, calendar_like));
// 4. Let ns be ! SystemUTCEpochNanoseconds().
auto* ns = system_utc_epoch_nanoseconds(global_object);
auto* ns = system_utc_epoch_nanoseconds(vm);
// 5. Return ? CreateTemporalZonedDateTime(ns, timeZone, calendar).
return create_temporal_zoned_date_time(global_object, *ns, *time_zone, *calendar);
return create_temporal_zoned_date_time(vm, *ns, *time_zone, *calendar);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -31,10 +31,10 @@ private:
JS_DECLARE_NATIVE_FUNCTION(plain_time_iso);
};
TimeZone* system_time_zone(GlobalObject&);
BigInt* system_utc_epoch_nanoseconds(GlobalObject&);
Instant* system_instant(GlobalObject&);
ThrowCompletionOr<PlainDateTime*> system_date_time(GlobalObject&, Value temporal_time_zone_like, Value calendar_like);
ThrowCompletionOr<ZonedDateTime*> system_zoned_date_time(GlobalObject&, Value temporal_time_zone_like, Value calendar_like);
TimeZone* system_time_zone(VM&);
BigInt* system_utc_epoch_nanoseconds(VM&);
Instant* system_instant(VM&);
ThrowCompletionOr<PlainDateTime*> system_date_time(VM&, Value temporal_time_zone_like, Value calendar_like);
ThrowCompletionOr<ZonedDateTime*> system_zoned_date_time(VM&, Value temporal_time_zone_like, Value calendar_like);
}

View file

@ -48,9 +48,10 @@ ISODateRecord create_iso_date_record(i32 year, u8 month, u8 day)
}
// 3.5.1 CreateTemporalDate ( isoYear, isoMonth, isoDay, calendar [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaldate
ThrowCompletionOr<PlainDate*> create_temporal_date(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target)
ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoYear is an integer.
// 2. Assert: isoMonth is an integer.
@ -62,7 +63,7 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(GlobalObject& global_object,
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainDate);
// 6. If ISODateTimeWithinLimits(isoYear, isoMonth, isoDay, 12, 0, 0, 0, 0, 0) is false, throw a RangeError exception.
if (!iso_date_time_within_limits(global_object, iso_year, iso_month, iso_day, 12, 0, 0, 0, 0, 0))
if (!iso_date_time_within_limits(vm, iso_year, iso_month, iso_day, 12, 0, 0, 0, 0, 0))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainDate);
// 7. If newTarget is not present, set newTarget to %Temporal.PlainDate%.
@ -80,9 +81,10 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(GlobalObject& global_object,
}
// 3.5.2 ToTemporalDate ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldate
ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject& global_object, Value item, Object const* options)
ThrowCompletionOr<PlainDate*> to_temporal_date(VM& vm, Value item, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
// 2. Assert: Type(options) is Object or Undefined.
@ -101,16 +103,16 @@ ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject& global_object, Valu
auto& zoned_date_time = static_cast<ZonedDateTime&>(item_object);
// i. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// ii. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds()).release_value();
auto* instant = create_temporal_instant(vm, zoned_date_time.nanoseconds()).release_value();
// iii. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]).
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
// iv. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]], plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], plainDateTime.[[Calendar]]).
return create_temporal_date(global_object, plain_date_time->iso_year(), plain_date_time->iso_month(), plain_date_time->iso_day(), plain_date_time->calendar());
return create_temporal_date(vm, plain_date_time->iso_year(), plain_date_time->iso_month(), plain_date_time->iso_day(), plain_date_time->calendar());
}
// c. If item has an [[InitializedTemporalDateTime]] internal slot, then
@ -118,46 +120,46 @@ ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject& global_object, Valu
auto& date_time_item = static_cast<PlainDateTime&>(item_object);
// i. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// ii. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[Calendar]]).
return create_temporal_date(global_object, date_time_item.iso_year(), date_time_item.iso_month(), date_time_item.iso_day(), date_time_item.calendar());
return create_temporal_date(vm, date_time_item.iso_year(), date_time_item.iso_month(), date_time_item.iso_day(), date_time_item.calendar());
}
// d. Let calendar be ? GetTemporalCalendarWithISODefault(item).
auto* calendar = TRY(get_temporal_calendar_with_iso_default(global_object, item_object));
auto* calendar = TRY(get_temporal_calendar_with_iso_default(vm, item_object));
// e. Let fieldNames be ? CalendarFields(calendar, « "day", "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> {}));
// g. Return ? CalendarDateFromFields(calendar, fields, options).
return calendar_date_from_fields(global_object, *calendar, *fields, options);
return calendar_date_from_fields(vm, *calendar, *fields, options);
}
// 4. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// 5. Let string be ? ToString(item).
auto string = TRY(item.to_string(global_object));
// 6. Let result be ? ParseTemporalDateString(string).
auto result = TRY(parse_temporal_date_string(global_object, string));
auto result = TRY(parse_temporal_date_string(vm, string));
// 7. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
// 8. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
// 9. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
return create_temporal_date(global_object, result.year, result.month, result.day, *calendar);
return create_temporal_date(vm, result.year, result.month, result.day, *calendar);
}
// 3.5.3 DifferenceISODate ( y1, m1, d1, y2, m2, d2, largestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-differenceisodate
DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2, StringView largest_unit)
DateDurationRecord difference_iso_date(VM& vm, i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2, StringView largest_unit)
{
VERIFY(largest_unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv));
@ -180,7 +182,7 @@ DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u
double years = end.year - start.year;
// f. Let mid be ! AddISODate(y1, m1, d1, years, 0, 0, 0, "constrain").
auto mid = MUST(add_iso_date(global_object, year1, month1, day1, years, 0, 0, 0, "constrain"sv));
auto mid = MUST(add_iso_date(vm, year1, month1, day1, years, 0, 0, 0, "constrain"sv));
// g. Let midSign be -(! CompareISODate(mid.[[Year]], mid.[[Month]], mid.[[Day]], y2, m2, d2)).
auto mid_sign = -compare_iso_date(mid.year, mid.month, mid.day, year2, month2, day2);
@ -208,7 +210,7 @@ DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u
}
// k. Set mid to ! AddISODate(y1, m1, d1, years, months, 0, 0, "constrain").
mid = MUST(add_iso_date(global_object, year1, month1, day1, years, months, 0, 0, "constrain"sv));
mid = MUST(add_iso_date(vm, year1, month1, day1, years, months, 0, 0, "constrain"sv));
// l. Set midSign to -(! CompareISODate(mid.[[Year]], mid.[[Month]], mid.[[Day]], y2, m2, d2)).
mid_sign = -compare_iso_date(mid.year, mid.month, mid.day, year2, month2, day2);
@ -238,7 +240,7 @@ DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u
}
// iii. Set mid to ! AddISODate(y1, m1, d1, years, months, 0, 0, "constrain").
mid = MUST(add_iso_date(global_object, year1, month1, day1, years, months, 0, 0, "constrain"sv));
mid = MUST(add_iso_date(vm, year1, month1, day1, years, months, 0, 0, "constrain"sv));
}
double days;
@ -310,10 +312,8 @@ DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u
}
// 3.5.4 RegulateISODate ( year, month, day, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisodate
ThrowCompletionOr<ISODateRecord> regulate_iso_date(GlobalObject& global_object, double year, double month, double day, StringView overflow)
ThrowCompletionOr<ISODateRecord> regulate_iso_date(VM& vm, double year, double month, double day, StringView overflow)
{
auto& vm = global_object.vm();
VERIFY(year == trunc(year) && month == trunc(month) && day == trunc(day));
// 1. If overflow is "constrain", then
@ -417,8 +417,11 @@ String pad_iso_year(i32 y)
}
// 3.5.8 TemporalDateToString ( temporalDate, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetostring
ThrowCompletionOr<String> temporal_date_to_string(GlobalObject& global_object, PlainDate& temporal_date, StringView show_calendar)
ThrowCompletionOr<String> temporal_date_to_string(VM& vm, PlainDate& temporal_date, StringView show_calendar)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(temporalDate) is Object.
// 2. Assert: temporalDate has an [[InitializedTemporalDate]] internal slot.
@ -442,7 +445,7 @@ ThrowCompletionOr<String> temporal_date_to_string(GlobalObject& global_object, P
}
// 3.5.9 AddISODate ( year, month, day, years, months, weeks, days, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-addisodate
ThrowCompletionOr<ISODateRecord> add_iso_date(GlobalObject& global_object, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow)
ThrowCompletionOr<ISODateRecord> add_iso_date(VM& vm, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow)
{
// 1. Assert: year, month, day, years, months, weeks, and days are integers.
VERIFY(years == trunc(years) && months == trunc(months) && weeks == trunc(weeks) && days == trunc(days));
@ -454,7 +457,7 @@ ThrowCompletionOr<ISODateRecord> add_iso_date(GlobalObject& global_object, i32 y
auto intermediate_year_month = balance_iso_year_month(year + years, month + months);
// 4. Let intermediate be ? RegulateISODate(intermediate.[[Year]], intermediate.[[Month]], day, overflow).
auto intermediate = TRY(regulate_iso_date(global_object, intermediate_year_month.year, intermediate_year_month.month, day, overflow));
auto intermediate = TRY(regulate_iso_date(vm, intermediate_year_month.year, intermediate_year_month.month, day, overflow));
// 5. Set days to days + 7 × weeks.
days += 7 * weeks;
@ -500,39 +503,37 @@ i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2
}
// 3.5.11 DifferenceTemporalPlainDate ( operation, temporalDate, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplaindate
ThrowCompletionOr<Duration*> difference_temporal_plain_date(GlobalObject& global_object, DifferenceOperation operation, PlainDate& temporal_date, Value other_value, Value options_value)
ThrowCompletionOr<Duration*> difference_temporal_plain_date(VM& vm, DifferenceOperation operation, PlainDate& temporal_date, Value other_value, Value options_value)
{
auto& vm = global_object.vm();
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
// 2. Set other to ? ToTemporalDate(other).
auto* other = TRY(to_temporal_date(global_object, other_value));
auto* other = TRY(to_temporal_date(vm, other_value));
// 3. If ? CalendarEquals(temporalDate.[[Calendar]], other.[[Calendar]]) is false, throw a RangeError exception.
if (!TRY(calendar_equals(global_object, temporal_date.calendar(), other->calendar())))
if (!TRY(calendar_equals(vm, temporal_date.calendar(), other->calendar())))
return vm.throw_completion<RangeError>(ErrorType::TemporalDifferentCalendars);
// 4. Let settings be ? GetDifferenceSettings(operation, options, date, « », "day", "day").
auto settings = TRY(get_difference_settings(global_object, operation, options_value, UnitGroup::Date, {}, { "day"sv }, "day"sv));
auto settings = TRY(get_difference_settings(vm, operation, options_value, UnitGroup::Date, {}, { "day"sv }, "day"sv));
// 5. Let untilOptions be ? MergeLargestUnitOption(settings.[[Options]], settings.[[LargestUnit]]).
auto* until_options = TRY(merge_largest_unit_option(global_object, settings.options, settings.largest_unit));
auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, settings.largest_unit));
// 6. Let result be ? CalendarDateUntil(temporalDate.[[Calendar]], temporalDate, other, untilOptions).
auto* duration = TRY(calendar_date_until(global_object, temporal_date.calendar(), &temporal_date, other, *until_options));
auto* duration = TRY(calendar_date_until(vm, temporal_date.calendar(), &temporal_date, other, *until_options));
auto result = DurationRecord { duration->years(), duration->months(), duration->weeks(), duration->days(), 0, 0, 0, 0, 0, 0 };
// 7. If settings.[[SmallestUnit]] is not "day" or settings.[[RoundingIncrement]] ≠ 1, then
if (settings.smallest_unit != "day"sv || settings.rounding_increment != 1) {
// a. Set result to (? RoundDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0, settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]], temporalDate)).[[DurationRecord]].
result = TRY(round_duration(global_object, result.years, result.months, result.weeks, result.days, 0, 0, 0, 0, 0, 0, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, &temporal_date)).duration_record;
result = TRY(round_duration(vm, result.years, result.months, result.weeks, result.days, 0, 0, 0, 0, 0, 0, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, &temporal_date)).duration_record;
}
// 16. Return ! CreateTemporalDuration(sign × result.[[Years]], sign × result.[[Months]], sign × result.[[Weeks]], sign × result.[[Days]], 0, 0, 0, 0, 0, 0).
return TRY(create_temporal_duration(global_object, sign * result.years, sign * result.months, sign * result.weeks, sign * result.days, 0, 0, 0, 0, 0, 0));
return TRY(create_temporal_duration(vm, sign * result.years, sign * result.months, sign * result.weeks, sign * result.days, 0, 0, 0, 0, 0, 0));
}
}

View file

@ -45,16 +45,16 @@ struct ISODateRecord {
};
ISODateRecord create_iso_date_record(i32 year, u8 month, u8 day);
ThrowCompletionOr<PlainDate*> create_temporal_date(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject&, Value item, Object const* options = nullptr);
DateDurationRecord difference_iso_date(GlobalObject&, i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2, StringView largest_unit);
ThrowCompletionOr<ISODateRecord> regulate_iso_date(GlobalObject&, double year, double month, double day, StringView overflow);
ThrowCompletionOr<PlainDate*> create_temporal_date(VM&, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<PlainDate*> to_temporal_date(VM&, Value item, Object const* options = nullptr);
DateDurationRecord difference_iso_date(VM&, i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2, StringView largest_unit);
ThrowCompletionOr<ISODateRecord> regulate_iso_date(VM&, double year, double month, double day, StringView overflow);
bool is_valid_iso_date(i32 year, u8 month, u8 day);
ISODateRecord balance_iso_date(double year, double month, double day);
String pad_iso_year(i32 y);
ThrowCompletionOr<String> temporal_date_to_string(GlobalObject&, PlainDate&, StringView show_calendar);
ThrowCompletionOr<ISODateRecord> add_iso_date(GlobalObject&, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow);
ThrowCompletionOr<String> temporal_date_to_string(VM&, PlainDate&, StringView show_calendar);
ThrowCompletionOr<ISODateRecord> add_iso_date(VM&, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow);
i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2);
ThrowCompletionOr<Duration*> difference_temporal_plain_date(GlobalObject&, DifferenceOperation, PlainDate&, Value other, Value options);
ThrowCompletionOr<Duration*> difference_temporal_plain_date(VM&, DifferenceOperation, PlainDate&, Value other, Value options);
}

View file

@ -49,19 +49,18 @@ ThrowCompletionOr<Value> PlainDateConstructor::call()
ThrowCompletionOr<Object*> PlainDateConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
// 2. Let y be ? ToIntegerThrowOnInfinity(isoYear).
auto y = TRY(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDate));
auto y = TRY(to_integer_throw_on_infinity(vm, vm.argument(0), ErrorType::TemporalInvalidPlainDate));
// 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = TRY(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDate));
auto m = TRY(to_integer_throw_on_infinity(vm, vm.argument(1), ErrorType::TemporalInvalidPlainDate));
// 4. Let d be ? ToIntegerThrowOnInfinity(isoDay).
auto d = TRY(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDate));
auto d = TRY(to_integer_throw_on_infinity(vm, vm.argument(2), ErrorType::TemporalInvalidPlainDate));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, vm.argument(3)));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, vm.argument(3)));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalDate will immediately check that these values are valid
@ -70,38 +69,38 @@ ThrowCompletionOr<Object*> PlainDateConstructor::construct(FunctionObject& new_t
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainDate);
// 6. Return ? CreateTemporalDate(y, m, d, calendar, NewTarget).
return TRY(create_temporal_date(global_object, y, m, d, *calendar, &new_target));
return TRY(create_temporal_date(vm, y, m, d, *calendar, &new_target));
}
// 3.2.2 Temporal.PlainDate.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.from
JS_DEFINE_NATIVE_FUNCTION(PlainDateConstructor::from)
{
// 1. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
auto const* options = TRY(get_options_object(vm, vm.argument(1)));
auto item = vm.argument(0);
// 2. If Type(item) is Object and item has an [[InitializedTemporalDate]] internal slot, then
if (item.is_object() && is<PlainDate>(item.as_object())) {
auto& plain_date_item = static_cast<PlainDate&>(item.as_object());
// a. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// b. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[Calendar]]).
return MUST(create_temporal_date(global_object, plain_date_item.iso_year(), plain_date_item.iso_month(), plain_date_item.iso_day(), plain_date_item.calendar()));
return MUST(create_temporal_date(vm, plain_date_item.iso_year(), plain_date_item.iso_month(), plain_date_item.iso_day(), plain_date_item.calendar()));
}
// 3. Return ? ToTemporalDate(item, options).
return TRY(to_temporal_date(global_object, item, options));
return TRY(to_temporal_date(vm, item, options));
}
// 3.2.3 Temporal.PlainDate.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.compare
JS_DEFINE_NATIVE_FUNCTION(PlainDateConstructor::compare)
{
// 1. Set one to ? ToTemporalDate(one).
auto* one = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_date(vm, vm.argument(0)));
// 2. Set two to ? ToTemporalDate(two).
auto* two = TRY(to_temporal_date(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_date(vm, vm.argument(1)));
// 3. Return 𝔽(! CompareISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]])).
return Value(compare_iso_date(one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day()));

View file

@ -91,7 +91,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::year_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarYear(calendar, temporalDate).
return Value(TRY(calendar_year(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_year(vm, calendar, *temporal_date)));
}
// 3.3.5 get Temporal.PlainDate.prototype.month, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.month
@ -105,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::month_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarMonth(calendar, temporalDate).
return Value(TRY(calendar_month(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_month(vm, calendar, *temporal_date)));
}
// 3.3.6 get Temporal.PlainDate.prototype.monthCode, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.monthCode
@ -119,7 +119,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::month_code_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarMonthCode(calendar, temporalDate).
return js_string(vm, TRY(calendar_month_code(global_object, calendar, *temporal_date)));
return js_string(vm, TRY(calendar_month_code(vm, calendar, *temporal_date)));
}
// 3.3.7 get Temporal.PlainDate.prototype.day, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.day
@ -133,7 +133,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::day_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarDay(calendar, temporalDate).
return Value(TRY(calendar_day(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_day(vm, calendar, *temporal_date)));
}
// 3.3.8 get Temporal.PlainDate.prototype.dayOfWeek, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.dayofweek
@ -147,7 +147,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::day_of_week_getter)
auto& calendar = temporal_date->calendar();
// Return ? CalendarDayOfWeek(calendar, temporalDate).
return Value(TRY(calendar_day_of_week(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_day_of_week(vm, calendar, *temporal_date)));
}
// 3.3.9 get Temporal.PlainDate.prototype.dayOfYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.dayofyear
@ -161,7 +161,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::day_of_year_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarDayOfYear(calendar, temporalDate).
return Value(TRY(calendar_day_of_year(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_day_of_year(vm, calendar, *temporal_date)));
}
// 3.3.10 get Temporal.PlainDate.prototype.weekOfYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.weekofyear
@ -175,7 +175,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::week_of_year_getter)
auto& calendar = temporal_date->calendar();
// Return ? CalendarWeekOfYear(calendar, temporalDate).
return Value(TRY(calendar_week_of_year(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_week_of_year(vm, calendar, *temporal_date)));
}
// 3.3.11 get Temporal.PlainDate.prototype.daysInWeek, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.daysinweek
@ -189,7 +189,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::days_in_week_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarDaysInWeek(calendar, temporalDate).
return Value(TRY(calendar_days_in_week(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_days_in_week(vm, calendar, *temporal_date)));
}
// 3.3.12 get Temporal.PlainDate.prototype.daysInMonth, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.daysinmonth
@ -203,7 +203,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::days_in_month_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarDaysInMonth(calendar, temporalDate).
return Value(TRY(calendar_days_in_month(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_days_in_month(vm, calendar, *temporal_date)));
}
// 3.3.13 get Temporal.PlainDate.prototype.daysInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.daysinyear
@ -217,7 +217,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::days_in_year_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarDaysInYear(calendar, temporalDate).
return Value(TRY(calendar_days_in_year(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_days_in_year(vm, calendar, *temporal_date)));
}
// 3.3.14 get Temporal.PlainDate.prototype.monthsInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.monthsinyear
@ -231,7 +231,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::months_in_year_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarMonthsInYear(calendar, temporalDate).
return Value(TRY(calendar_months_in_year(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_months_in_year(vm, calendar, *temporal_date)));
}
// 3.3.15 get Temporal.PlainDate.prototype.inLeapYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.inleapyear
@ -245,7 +245,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::in_leap_year_getter)
auto& calendar = temporal_date->calendar();
// 4. Return ? CalendarInLeapYear(calendar, temporalDate).
return Value(TRY(calendar_in_leap_year(global_object, calendar, *temporal_date)));
return Value(TRY(calendar_in_leap_year(vm, calendar, *temporal_date)));
}
// 15.6.5.2 get Temporal.PlainDate.prototype.era, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.era
@ -259,7 +259,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::era_getter)
auto& calendar = plain_date->calendar();
// 4. Return ? CalendarEra(calendar, plainDate).
return TRY(calendar_era(global_object, calendar, *plain_date));
return TRY(calendar_era(vm, calendar, *plain_date));
}
// 15.6.5.3 get Temporal.PlainDate.prototype.eraYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.erayear
@ -273,7 +273,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::era_year_getter)
auto& calendar = plain_date->calendar();
// 4. Return ? CalendarEraYear(calendar, plainDate).
return TRY(calendar_era_year(global_object, calendar, *plain_date));
return TRY(calendar_era_year(vm, calendar, *plain_date));
}
// 3.3.16 Temporal.PlainDate.prototype.toPlainYearMonth ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.toplainyearmonth
@ -287,13 +287,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_year_month)
auto& calendar = temporal_date->calendar();
// 4. Let fieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "monthCode"sv, "year"sv }));
// 5. Let fields be ? PrepareTemporalFields(temporalDate, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *temporal_date, field_names, Vector<StringView> {}));
// 6. Return ? CalendarYearMonthFromFields(calendar, fields).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields));
return TRY(calendar_year_month_from_fields(vm, calendar, *fields));
}
// 3.3.17 Temporal.PlainDate.prototype.toPlainMonthDay ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.toplainmonthday
@ -307,13 +307,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_month_day)
auto& calendar = temporal_date->calendar();
// 4. Let fieldNames be ? CalendarFields(calendar, « "day", "monthCode" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "monthCode"sv }));
// 5. Let fields be ? PrepareTemporalFields(temporalDate, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *temporal_date, field_names, Vector<StringView> {}));
// 6. Return ? CalendarMonthDayFromFields(calendar, fields).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields));
return TRY(calendar_month_day_from_fields(vm, calendar, *fields));
}
// 3.3.18 Temporal.PlainDate.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.getisofields
@ -352,13 +352,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::add)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Let duration be ? ToTemporalDuration(temporalDurationLike).
auto* duration = TRY(to_temporal_duration(global_object, vm.argument(0)));
auto* duration = TRY(to_temporal_duration(vm, vm.argument(0)));
// 4. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 5. Return ? CalendarDateAdd(temporalDate.[[Calendar]], temporalDate, duration, options).
return TRY(calendar_date_add(global_object, temporal_date->calendar(), temporal_date, *duration, options));
return TRY(calendar_date_add(vm, temporal_date->calendar(), temporal_date, *duration, options));
}
// 3.3.20 Temporal.PlainDate.prototype.subtract ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.subtract
@ -369,16 +369,16 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::subtract)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Let duration be ? ToTemporalDuration(temporalDurationLike).
auto* duration = TRY(to_temporal_duration(global_object, vm.argument(0)));
auto* duration = TRY(to_temporal_duration(vm, vm.argument(0)));
// 4. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 5. Let negatedDuration be ! CreateNegatedTemporalDuration(duration).
auto* negated_duration = create_negated_temporal_duration(global_object, *duration);
auto* negated_duration = create_negated_temporal_duration(vm, *duration);
// 6. Return ? CalendarDateAdd(temporalDate.[[Calendar]], temporalDate, negatedDuration, options).
return TRY(calendar_date_add(global_object, temporal_date->calendar(), temporal_date, *negated_duration, options));
return TRY(calendar_date_add(vm, temporal_date->calendar(), temporal_date, *negated_duration, options));
}
// 3.3.21 Temporal.PlainDate.prototype.with ( temporalDateLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.with
@ -397,31 +397,31 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::with)
}
// 4. Perform ? RejectObjectWithCalendarOrTimeZone(temporalDateLike).
TRY(reject_object_with_calendar_or_time_zone(global_object, temporal_date_like.as_object()));
TRY(reject_object_with_calendar_or_time_zone(vm, temporal_date_like.as_object()));
// 5. Let calendar be temporalDate.[[Calendar]].
auto& calendar = temporal_date->calendar();
// 6. Let fieldNames be ? CalendarFields(calendar, « "day", "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// 7. Let partialDate be ? PrepareTemporalFields(temporalDateLike, fieldNames, partial).
auto* partial_date = TRY(prepare_temporal_fields(global_object, temporal_date_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
auto* partial_date = TRY(prepare_temporal_fields(vm, temporal_date_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
auto const* options = TRY(get_options_object(vm, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(temporalDate, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *temporal_date, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialDate).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_date));
fields = TRY(calendar_merge_fields(vm, calendar, *fields, *partial_date));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
fields = TRY(prepare_temporal_fields(vm, *fields, field_names, Vector<StringView> {}));
// 12. Return ? CalendarDateFromFields(calendar, fields, options).
return TRY(calendar_date_from_fields(global_object, calendar, *fields, options));
return TRY(calendar_date_from_fields(vm, calendar, *fields, options));
}
// 3.3.22 Temporal.PlainDate.prototype.withCalendar ( calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.withcalendar
@ -434,10 +434,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::with_calendar)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
auto* calendar = TRY(to_temporal_calendar(global_object, calendar_like));
auto* calendar = TRY(to_temporal_calendar(vm, calendar_like));
// 4. Return ! CreateTemporalDate(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], calendar).
return MUST(create_temporal_date(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), *calendar));
return MUST(create_temporal_date(vm, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), *calendar));
}
// 3.3.23 Temporal.PlainDate.prototype.until ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.until
@ -451,7 +451,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::until)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainDate(until, temporalDate, other, options).
return TRY(difference_temporal_plain_date(global_object, DifferenceOperation::Until, *temporal_date, other, options));
return TRY(difference_temporal_plain_date(vm, DifferenceOperation::Until, *temporal_date, other, options));
}
// 3.3.24 Temporal.PlainDate.prototype.since ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.since
@ -465,7 +465,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::since)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainDate(since, temporalDate, other, options).
return TRY(difference_temporal_plain_date(global_object, DifferenceOperation::Since, *temporal_date, other, options));
return TRY(difference_temporal_plain_date(vm, DifferenceOperation::Since, *temporal_date, other, options));
}
// 3.3.25 Temporal.PlainDate.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.equals
@ -476,7 +476,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::equals)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Set other to ? ToTemporalDate(other).
auto* other = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* other = TRY(to_temporal_date(vm, vm.argument(0)));
// 4. If temporalDate.[[ISOYear]] ≠ other.[[ISOYear]], return false.
if (temporal_date->iso_year() != other->iso_year())
@ -488,7 +488,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::equals)
if (temporal_date->iso_day() != other->iso_day())
return Value(false);
// 7. Return ? CalendarEquals(temporalDate.[[Calendar]], other.[[Calendar]]).
return Value(TRY(calendar_equals(global_object, temporal_date->calendar(), other->calendar())));
return Value(TRY(calendar_equals(vm, temporal_date->calendar(), other->calendar())));
}
// 3.3.26 Temporal.PlainDate.prototype.toPlainDateTime ( [ temporalTime ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.toplaindatetime
@ -501,14 +501,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_date_time)
// 3. If temporalTime is undefined, then
if (vm.argument(0).is_undefined()) {
// a. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], 0, 0, 0, 0, 0, 0, temporalDate.[[Calendar]]).
return TRY(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), 0, 0, 0, 0, 0, 0, temporal_date->calendar()));
return TRY(create_temporal_date_time(vm, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), 0, 0, 0, 0, 0, 0, temporal_date->calendar()));
}
// 4. Set temporalTime to ? ToTemporalTime(temporalTime).
auto* temporal_time = TRY(to_temporal_time(global_object, vm.argument(0)));
auto* temporal_time = TRY(to_temporal_time(vm, vm.argument(0)));
// 5. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
return TRY(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
return TRY(create_temporal_date_time(vm, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
}
// 3.3.27 Temporal.PlainDate.prototype.toZonedDateTime ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.tozoneddatetime
@ -531,14 +531,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_zoned_date_time)
// b. If timeZoneLike is undefined, then
if (time_zone_like.is_undefined()) {
// i. Let timeZone be ? ToTemporalTimeZone(item).
time_zone = TRY(to_temporal_time_zone(global_object, item));
time_zone = TRY(to_temporal_time_zone(vm, item));
// ii. Let temporalTime be undefined.
}
// c. Else,
else {
// i. Let timeZone be ? ToTemporalTimeZone(timeZoneLike).
time_zone = TRY(to_temporal_time_zone(global_object, time_zone_like));
time_zone = TRY(to_temporal_time_zone(vm, time_zone_like));
// ii. Let temporalTime be ? Get(item, "plainTime").
temporal_time_value = TRY(item.as_object().get(vm.names.plainTime));
@ -547,7 +547,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_zoned_date_time)
// 4. Else,
else {
// a. Let timeZone be ? ToTemporalTimeZone(item).
time_zone = TRY(to_temporal_time_zone(global_object, item));
time_zone = TRY(to_temporal_time_zone(vm, item));
// b. Let temporalTime be undefined.
}
@ -557,22 +557,22 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_zoned_date_time)
// 5. If temporalTime is undefined, then
if (temporal_time_value.is_undefined()) {
// a. Let temporalDateTime be ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], 0, 0, 0, 0, 0, 0, temporalDate.[[Calendar]]).
temporal_date_time = TRY(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), 0, 0, 0, 0, 0, 0, temporal_date->calendar()));
temporal_date_time = TRY(create_temporal_date_time(vm, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), 0, 0, 0, 0, 0, 0, temporal_date->calendar()));
}
// 6. Else,
else {
// a. Set temporalTime to ? ToTemporalTime(temporalTime).
auto* temporal_time = TRY(to_temporal_time(global_object, temporal_time_value));
auto* temporal_time = TRY(to_temporal_time(vm, temporal_time_value));
// b. Let temporalDateTime be ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
temporal_date_time = TRY(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_time->calendar()));
temporal_date_time = TRY(create_temporal_date_time(vm, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_time->calendar()));
}
// 7. Let instant be ? BuiltinTimeZoneGetInstantFor(timeZone, temporalDateTime, "compatible").
auto* instant = TRY(builtin_time_zone_get_instant_for(global_object, time_zone, *temporal_date_time, "compatible"sv));
auto* instant = TRY(builtin_time_zone_get_instant_for(vm, time_zone, *temporal_date_time, "compatible"sv));
// 8. Return ! CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, temporalDate.[[Calendar]]).
return MUST(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), *time_zone, temporal_date->calendar()));
return MUST(create_temporal_zoned_date_time(vm, instant->nanoseconds(), *time_zone, temporal_date->calendar()));
}
// 3.3.28 Temporal.PlainDate.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.tostring
@ -583,13 +583,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_string)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(0)));
auto* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let showCalendar be ? ToShowCalendarOption(options).
auto show_calendar = TRY(to_show_calendar_option(global_object, *options));
auto show_calendar = TRY(to_show_calendar_option(vm, *options));
// 5. Return ? TemporalDateToString(temporalDate, showCalendar).
return js_string(vm, TRY(temporal_date_to_string(global_object, *temporal_date, show_calendar)));
return js_string(vm, TRY(temporal_date_to_string(vm, *temporal_date, show_calendar)));
}
// 3.3.29 Temporal.PlainDate.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.tolocalestring
@ -601,7 +601,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_locale_string)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Return ? TemporalDateToString(temporalDate, "auto").
return js_string(vm, TRY(temporal_date_to_string(global_object, *temporal_date, "auto"sv)));
return js_string(vm, TRY(temporal_date_to_string(vm, *temporal_date, "auto"sv)));
}
// 3.3.30 Temporal.PlainDate.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.tojson
@ -612,7 +612,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_json)
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Return ? TemporalDateToString(temporalDate, "auto").
return js_string(vm, TRY(temporal_date_to_string(global_object, *temporal_date, "auto"sv)));
return js_string(vm, TRY(temporal_date_to_string(vm, *temporal_date, "auto"sv)));
}
// 3.3.31 Temporal.PlainDate.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.valueof

View file

@ -45,10 +45,8 @@ void PlainDateTime::visit_edges(Visitor& visitor)
}
// 5.5.1 GetEpochFromISOParts ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-getepochfromisoparts
BigInt* get_epoch_from_iso_parts(GlobalObject& global_object, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
BigInt* get_epoch_from_iso_parts(VM& vm, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
{
auto& vm = global_object.vm();
// 1. Assert: IsValidISODate(year, month, day) is true.
VERIFY(is_valid_iso_date(year, month, day));
@ -74,13 +72,13 @@ auto const DATETIME_NANOSECONDS_MIN = "-8640000086400000000000"_sbigint;
auto const DATETIME_NANOSECONDS_MAX = "8640000086400000000000"_sbigint;
// 5.5.2 ISODateTimeWithinLimits ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetimewithinlimits
bool iso_date_time_within_limits(GlobalObject& global_object, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
bool iso_date_time_within_limits(VM& vm, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
{
// 1. Assert: IsValidISODate(year, month, day) is true.
VERIFY(is_valid_iso_date(year, month, day));
// 2. Let ns be (GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond)).
auto ns = get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond)->big_integer();
auto ns = get_epoch_from_iso_parts(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond)->big_integer();
// 3. If ns ≤ nsMinInstant - nsPerDay, then
if (ns <= DATETIME_NANOSECONDS_MIN) {
@ -98,19 +96,19 @@ bool iso_date_time_within_limits(GlobalObject& global_object, i32 year, u8 month
}
// 5.5.3 InterpretTemporalDateTimeFields ( calendar, fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-interprettemporaldatetimefields
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(GlobalObject& global_object, Object& calendar, Object& fields, Object const& options)
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(VM& vm, Object& calendar, Object& fields, Object const& options)
{
// 1. Let timeResult be ? ToTemporalTimeRecord(fields).
auto unregulated_time_result = TRY(to_temporal_time_record(global_object, fields));
auto unregulated_time_result = TRY(to_temporal_time_record(vm, fields));
// 2. Let overflow be ? ToTemporalOverflow(options).
auto overflow = TRY(to_temporal_overflow(global_object, &options));
auto overflow = TRY(to_temporal_overflow(vm, &options));
// 3. Let temporalDate be ? CalendarDateFromFields(calendar, fields, options).
auto* temporal_date = TRY(calendar_date_from_fields(global_object, calendar, fields, &options));
auto* temporal_date = TRY(calendar_date_from_fields(vm, calendar, fields, &options));
// 4. Let timeResult be ? RegulateTime(timeResult.[[Hour]], timeResult.[[Minute]], timeResult.[[Second]], timeResult.[[Millisecond]], timeResult.[[Microsecond]], timeResult.[[Nanosecond]], overflow).
auto time_result = TRY(regulate_time(global_object, *unregulated_time_result.hour, *unregulated_time_result.minute, *unregulated_time_result.second, *unregulated_time_result.millisecond, *unregulated_time_result.microsecond, *unregulated_time_result.nanosecond, overflow));
auto time_result = TRY(regulate_time(vm, *unregulated_time_result.hour, *unregulated_time_result.minute, *unregulated_time_result.second, *unregulated_time_result.millisecond, *unregulated_time_result.microsecond, *unregulated_time_result.nanosecond, overflow));
// 5. Return the Record { [[Year]]: temporalDate.[[ISOYear]], [[Month]]: temporalDate.[[ISOMonth]], [[Day]]: temporalDate.[[ISODay]], [[Hour]]: timeResult.[[Hour]], [[Minute]]: timeResult.[[Minute]], [[Second]]: timeResult.[[Second]], [[Millisecond]]: timeResult.[[Millisecond]], [[Microsecond]]: timeResult.[[Microsecond]], [[Nanosecond]]: timeResult.[[Nanosecond]] }.
return ISODateTime {
@ -127,9 +125,10 @@ ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(GlobalObject&
}
// 5.5.4 ToTemporalDateTime ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetime
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_object, Value item, Object const* options)
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(VM& vm, Value item, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
// 2. Assert: Type(options) is Object or Undefined.
@ -152,13 +151,13 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_obj
auto& zoned_date_time = static_cast<ZonedDateTime&>(item_object);
// i. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// ii. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds()).release_value();
auto* instant = create_temporal_instant(vm, zoned_date_time.nanoseconds()).release_value();
// iii. Return ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]).
return builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar());
return builtin_time_zone_get_plain_date_time_for(vm, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar());
}
// c. If item has an [[InitializedTemporalDate]] internal slot, then
@ -166,34 +165,34 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_obj
auto& plain_date = static_cast<PlainDate&>(item_object);
// i. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// ii. Return ? CreateTemporalDateTime(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], 0, 0, 0, 0, 0, 0, item.[[Calendar]]).
return create_temporal_date_time(global_object, plain_date.iso_year(), plain_date.iso_month(), plain_date.iso_day(), 0, 0, 0, 0, 0, 0, plain_date.calendar());
return create_temporal_date_time(vm, plain_date.iso_year(), plain_date.iso_month(), plain_date.iso_day(), 0, 0, 0, 0, 0, 0, plain_date.calendar());
}
// d. Let calendar be ? GetTemporalCalendarWithISODefault(item).
calendar = TRY(get_temporal_calendar_with_iso_default(global_object, item_object));
calendar = TRY(get_temporal_calendar_with_iso_default(vm, item_object));
// e. Let fieldNames be ? CalendarFields(calendar, « "day", "hour", "microsecond", "millisecond", "minute", "month", "monthCode", "nanosecond", "second", "year" »).
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> {}));
// g. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
result = TRY(interpret_temporal_date_time_fields(global_object, *calendar, *fields, *options));
result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *options));
}
// 4. Else,
else {
// a. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// b. Let string be ? ToString(item).
auto string = TRY(item.to_string(global_object));
// c. Let result be ? ParseTemporalDateTimeString(string).
result = TRY(parse_temporal_date_time_string(global_object, string));
result = TRY(parse_temporal_date_time_string(vm, string));
// d. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
@ -202,11 +201,11 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_obj
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
// f. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
calendar = TRY(to_temporal_calendar_with_iso_default(global_object, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
calendar = TRY(to_temporal_calendar_with_iso_default(vm, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
}
// 5. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], calendar).
return create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, *calendar);
return create_temporal_date_time(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, *calendar);
}
// 5.5.5 BalanceISODateTime ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-balanceisodatetime
@ -229,9 +228,10 @@ ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute
}
// 5.5.6 CreateTemporalDateTime ( isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaldatetime
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target)
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
// 2. Assert: Type(calendar) is Object.
@ -245,7 +245,7 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(GlobalObject& global
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainDateTime);
// 5. If ISODateTimeWithinLimits(isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond) is false, then
if (!iso_date_time_within_limits(global_object, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond)) {
if (!iso_date_time_within_limits(vm, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond)) {
// a. Throw a RangeError exception.
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainDateTime);
}
@ -272,8 +272,11 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(GlobalObject& global
}
// 5.5.7 TemporalDateTimeToString ( isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar, precision, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetimetostring
ThrowCompletionOr<String> temporal_date_time_to_string(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar)
ThrowCompletionOr<String> temporal_date_time_to_string(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
// 2. Let year be ! PadISOYear(isoYear).
@ -314,34 +317,34 @@ i8 compare_iso_date_time(i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8
}
// 5.5.9 AddDateTime ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, options ), https://tc39.es/proposal-temporal/#sec-temporal-adddatetime
ThrowCompletionOr<TemporalPlainDateTime> add_date_time(GlobalObject& global_object, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options)
ThrowCompletionOr<TemporalPlainDateTime> add_date_time(VM& vm, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options)
{
// 1. Assert: ISODateTimeWithinLimits(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond) is true.
VERIFY(iso_date_time_within_limits(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
VERIFY(iso_date_time_within_limits(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
// 2. Let timeResult be ! AddTime(hour, minute, second, millisecond, microsecond, nanosecond, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
auto time_result = add_time(hour, minute, second, millisecond, microsecond, nanosecond, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
// 3. Let datePart be ! CreateTemporalDate(year, month, day, calendar).
auto* date_part = MUST(create_temporal_date(global_object, year, month, day, calendar));
auto* date_part = MUST(create_temporal_date(vm, year, month, day, calendar));
// 4. Let dateDuration be ? CreateTemporalDuration(years, months, weeks, days + timeResult.[[Days]], 0, 0, 0, 0, 0, 0).
auto* date_duration = TRY(create_temporal_duration(global_object, years, months, weeks, days + time_result.days, 0, 0, 0, 0, 0, 0));
auto* date_duration = TRY(create_temporal_duration(vm, years, months, weeks, days + time_result.days, 0, 0, 0, 0, 0, 0));
// 5. Let addedDate be ? CalendarDateAdd(calendar, datePart, dateDuration, options).
auto* added_date = TRY(calendar_date_add(global_object, calendar, date_part, *date_duration, options));
auto* added_date = TRY(calendar_date_add(vm, calendar, date_part, *date_duration, options));
// 6. Return the Record { [[Year]]: addedDate.[[ISOYear]], [[Month]]: addedDate.[[ISOMonth]], [[Day]]: addedDate.[[ISODay]], [[Hour]]: timeResult.[[Hour]], [[Minute]]: timeResult.[[Minute]], [[Second]]: timeResult.[[Second]], [[Millisecond]]: timeResult.[[Millisecond]], [[Microsecond]]: timeResult.[[Microsecond]], [[Nanosecond]]: timeResult.[[Nanosecond]] }.
return TemporalPlainDateTime { .year = added_date->iso_year(), .month = added_date->iso_month(), .day = added_date->iso_day(), .hour = time_result.hour, .minute = time_result.minute, .second = time_result.second, .millisecond = time_result.millisecond, .microsecond = time_result.microsecond, .nanosecond = time_result.nanosecond };
}
// 5.5.10 RoundISODateTime ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, increment, unit, roundingMode [ , dayLength ] ), https://tc39.es/proposal-temporal/#sec-temporal-roundisodatetime
ISODateTime round_iso_date_time(GlobalObject& global_object, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length)
ISODateTime round_iso_date_time(VM& vm, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length)
{
// 1. Assert: year, month, day, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
// 2. Assert: ISODateTimeWithinLimits(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond) is true.
VERIFY(iso_date_time_within_limits(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
VERIFY(iso_date_time_within_limits(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
// 3. If dayLength is not present, set dayLength to nsPerDay.
if (!day_length.has_value())
@ -358,16 +361,16 @@ ISODateTime round_iso_date_time(GlobalObject& global_object, i32 year, u8 month,
}
// 5.5.11 DifferenceISODateTime ( y1, mon1, d1, h1, min1, s1, ms1, mus1, ns1, y2, mon2, d2, h2, min2, s2, ms2, mus2, ns2, calendar, largestUnit, options ), https://tc39.es/proposal-temporal/#sec-temporal-differenceisodatetime
ThrowCompletionOr<DurationRecord> difference_iso_date_time(GlobalObject& global_object, i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2, Object& calendar, StringView largest_unit, Object const& options)
ThrowCompletionOr<DurationRecord> difference_iso_date_time(VM& vm, i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2, Object& calendar, StringView largest_unit, Object const& options)
{
// 1. Assert: ISODateTimeWithinLimits(y1, mon1, d1, h1, min1, s1, ms1, mus1, ns1) is true.
VERIFY(iso_date_time_within_limits(global_object, year1, month1, day1, hour1, minute1, second1, millisecond1, microsecond1, nanosecond1));
VERIFY(iso_date_time_within_limits(vm, year1, month1, day1, hour1, minute1, second1, millisecond1, microsecond1, nanosecond1));
// 2. Assert: ISODateTimeWithinLimits(y2, mon2, d2, h2, min2, s2, ms2, mus2, ns2) is true.
VERIFY(iso_date_time_within_limits(global_object, year2, month2, day2, hour2, minute2, second2, millisecond2, microsecond2, nanosecond2));
VERIFY(iso_date_time_within_limits(vm, year2, month2, day2, hour2, minute2, second2, millisecond2, microsecond2, nanosecond2));
// 3. Let timeDifference be ! DifferenceTime(h1, min1, s1, ms1, mus1, ns1, h2, min2, s2, ms2, mus2, ns2).
auto time_difference = difference_time(global_object, hour1, minute1, second1, millisecond1, microsecond1, nanosecond1, hour2, minute2, second2, millisecond2, microsecond2, nanosecond2);
auto time_difference = difference_time(vm, hour1, minute1, second1, millisecond1, microsecond1, nanosecond1, hour2, minute2, second2, millisecond2, microsecond2, nanosecond2);
// 4. Let timeSign be ! DurationSign(0, 0, 0, 0, timeDifference.[[Hours]], timeDifference.[[Minutes]], timeDifference.[[Seconds]], timeDifference.[[Milliseconds]], timeDifference.[[Microseconds]], timeDifference.[[Nanoseconds]]).
auto time_sign = duration_sign(0, 0, 0, 0, time_difference.hours, time_difference.minutes, time_difference.seconds, time_difference.milliseconds, time_difference.microseconds, time_difference.nanoseconds);
@ -384,80 +387,78 @@ ThrowCompletionOr<DurationRecord> difference_iso_date_time(GlobalObject& global_
adjusted_date = balance_iso_date(adjusted_date.year, adjusted_date.month, adjusted_date.day - time_sign);
// b. Set timeDifference to ! BalanceDuration(-timeSign, timeDifference.[[Hours]], timeDifference.[[Minutes]], timeDifference.[[Seconds]], timeDifference.[[Milliseconds]], timeDifference.[[Microseconds]], timeDifference.[[Nanoseconds]], largestUnit).
time_difference = MUST(balance_duration(global_object, -time_sign, time_difference.hours, time_difference.minutes, time_difference.seconds, time_difference.milliseconds, time_difference.microseconds, Crypto::SignedBigInteger { (i32)time_difference.nanoseconds }, largest_unit));
time_difference = MUST(balance_duration(vm, -time_sign, time_difference.hours, time_difference.minutes, time_difference.seconds, time_difference.milliseconds, time_difference.microseconds, Crypto::SignedBigInteger { (i32)time_difference.nanoseconds }, largest_unit));
}
// 8. Let date1 be ! CreateTemporalDate(adjustedDate.[[Year]], adjustedDate.[[Month]], adjustedDate.[[Day]], calendar).
auto* date1 = MUST(create_temporal_date(global_object, adjusted_date.year, adjusted_date.month, adjusted_date.day, calendar));
auto* date1 = MUST(create_temporal_date(vm, adjusted_date.year, adjusted_date.month, adjusted_date.day, calendar));
// 9. Let date2 be ! CreateTemporalDate(y2, mon2, d2, calendar).
auto* date2 = MUST(create_temporal_date(global_object, year2, month2, day2, calendar));
auto* date2 = MUST(create_temporal_date(vm, year2, month2, day2, calendar));
// 10. Let dateLargestUnit be ! LargerOfTwoTemporalUnits("day", largestUnit).
auto date_largest_unit = larger_of_two_temporal_units("day"sv, largest_unit);
// 11. Let untilOptions be ? MergeLargestUnitOption(options, dateLargestUnit).
auto* until_options = TRY(merge_largest_unit_option(global_object, options, date_largest_unit));
auto* until_options = TRY(merge_largest_unit_option(vm, options, date_largest_unit));
// 12. Let dateDifference be ? CalendarDateUntil(calendar, date1, date2, untilOptions).
auto* date_difference = TRY(calendar_date_until(global_object, calendar, date1, date2, *until_options));
auto* date_difference = TRY(calendar_date_until(vm, calendar, date1, date2, *until_options));
// 13. Let balanceResult be ? BalanceDuration(dateDifference.[[Days]], timeDifference.[[Hours]], timeDifference.[[Minutes]], timeDifference.[[Seconds]], timeDifference.[[Milliseconds]], timeDifference.[[Microseconds]], timeDifference.[[Nanoseconds]], largestUnit).
auto balance_result = TRY(balance_duration(global_object, date_difference->days(), time_difference.hours, time_difference.minutes, time_difference.seconds, time_difference.milliseconds, time_difference.microseconds, Crypto::SignedBigInteger { (i32)time_difference.nanoseconds }, largest_unit));
auto balance_result = TRY(balance_duration(vm, date_difference->days(), time_difference.hours, time_difference.minutes, time_difference.seconds, time_difference.milliseconds, time_difference.microseconds, Crypto::SignedBigInteger { (i32)time_difference.nanoseconds }, largest_unit));
// 14. Return ! CreateDurationRecord(dateDifference.[[Years]], dateDifference.[[Months]], dateDifference.[[Weeks]], balanceResult.[[Days]], balanceResult.[[Hours]], balanceResult.[[Minutes]], balanceResult.[[Seconds]], balanceResult.[[Milliseconds]], balanceResult.[[Microseconds]], balanceResult.[[Nanoseconds]]).
return create_duration_record(date_difference->years(), date_difference->months(), date_difference->weeks(), balance_result.days, balance_result.hours, balance_result.minutes, balance_result.seconds, balance_result.milliseconds, balance_result.microseconds, balance_result.nanoseconds);
}
// 5.5.12 DifferenceTemporalPlainDateTime ( operation, dateTime, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplaindatetime
ThrowCompletionOr<Duration*> difference_temporal_plain_date_time(GlobalObject& global_object, DifferenceOperation operation, PlainDateTime& date_time, Value other_value, Value options_value)
ThrowCompletionOr<Duration*> difference_temporal_plain_date_time(VM& vm, DifferenceOperation operation, PlainDateTime& date_time, Value other_value, Value options_value)
{
auto& vm = global_object.vm();
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
// 2. Set other to ? ToTemporalDateTime(other).
auto* other = TRY(to_temporal_date_time(global_object, other_value));
auto* other = TRY(to_temporal_date_time(vm, other_value));
// 3. If ? CalendarEquals(dateTime.[[Calendar]], other.[[Calendar]]) is false, throw a RangeError exception.
if (!TRY(calendar_equals(global_object, date_time.calendar(), other->calendar())))
if (!TRY(calendar_equals(vm, date_time.calendar(), other->calendar())))
return vm.throw_completion<RangeError>(ErrorType::TemporalDifferentCalendars);
// 4. Let settings be ? GetDifferenceSettings(operation, options, datetime, « », "nanosecond", "day").
auto settings = TRY(get_difference_settings(global_object, operation, options_value, UnitGroup::DateTime, {}, { "nanosecond"sv }, "day"sv));
auto settings = TRY(get_difference_settings(vm, operation, options_value, UnitGroup::DateTime, {}, { "nanosecond"sv }, "day"sv));
// 5. Let diff be ? DifferenceISODateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], other.[[ISOYear]], other.[[ISOMonth]], other.[[ISODay]], other.[[ISOHour]], other.[[ISOMinute]], other.[[ISOSecond]], other.[[ISOMillisecond]], other.[[ISOMicrosecond]], other.[[ISONanosecond]], dateTime.[[Calendar]], settings.[[LargestUnit]], settings.[[Options]]).
auto diff = TRY(difference_iso_date_time(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), other->iso_year(), other->iso_month(), other->iso_day(), other->iso_hour(), other->iso_minute(), other->iso_second(), other->iso_millisecond(), other->iso_microsecond(), other->iso_nanosecond(), date_time.calendar(), settings.largest_unit, settings.options));
auto diff = TRY(difference_iso_date_time(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), other->iso_year(), other->iso_month(), other->iso_day(), other->iso_hour(), other->iso_minute(), other->iso_second(), other->iso_millisecond(), other->iso_microsecond(), other->iso_nanosecond(), date_time.calendar(), settings.largest_unit, settings.options));
// 6. Let relativeTo be ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[Calendar]]).
auto* relative_to = MUST(create_temporal_date(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.calendar()));
auto* relative_to = MUST(create_temporal_date(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.calendar()));
// 7. Let roundResult be (? RoundDuration(diff.[[Years]], diff.[[Months]], diff.[[Weeks]], diff.[[Days]], diff.[[Hours]], diff.[[Minutes]], diff.[[Seconds]], diff.[[Milliseconds]], diff.[[Microseconds]], diff.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]], relativeTo)).[[DurationRecord]].
auto round_result = TRY(round_duration(global_object, diff.years, diff.months, diff.weeks, diff.days, diff.hours, diff.minutes, diff.seconds, diff.milliseconds, diff.microseconds, diff.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, relative_to)).duration_record;
auto round_result = TRY(round_duration(vm, diff.years, diff.months, diff.weeks, diff.days, diff.hours, diff.minutes, diff.seconds, diff.milliseconds, diff.microseconds, diff.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, relative_to)).duration_record;
// 8. Let result be ? BalanceDuration(roundResult.[[Days]], roundResult.[[Hours]], roundResult.[[Minutes]], roundResult.[[Seconds]], roundResult.[[Milliseconds]], roundResult.[[Microseconds]], roundResult.[[Nanoseconds]], settings.[[LargestUnit]]).
// FIXME: Narrowing conversion from 'double' to 'i64'
auto result = MUST(balance_duration(global_object, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, Crypto::SignedBigInteger::create_from((i64)round_result.nanoseconds), settings.largest_unit));
auto result = MUST(balance_duration(vm, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, Crypto::SignedBigInteger::create_from((i64)round_result.nanoseconds), settings.largest_unit));
// 9. Return ! CreateTemporalDuration(sign × roundResult.[[Years]], sign × roundResult.[[Months]], sign × roundResult.[[Weeks]], sign × result.[[Days]], sign × result.[[Hours]], sign × result.[[Minutes]], sign × result.[[Seconds]], sign × result.[[Milliseconds]], sign × result.[[Microseconds]], sign × result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, sign * round_result.years, sign * round_result.months, sign * round_result.weeks, sign * result.days, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
return MUST(create_temporal_duration(vm, sign * round_result.years, sign * round_result.months, sign * round_result.weeks, sign * result.days, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
}
// 5.5.13 AddDurationToOrSubtractDurationFromPlainDateTime ( operation, dateTime, temporalDurationLike, options ), https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoorsubtractdurationfromplaindatetime
ThrowCompletionOr<PlainDateTime*> add_duration_to_or_subtract_duration_from_plain_date_time(GlobalObject& global_object, ArithmeticOperation operation, PlainDateTime& date_time, Value temporal_duration_like, Value options_value)
ThrowCompletionOr<PlainDateTime*> add_duration_to_or_subtract_duration_from_plain_date_time(VM& vm, ArithmeticOperation operation, PlainDateTime& date_time, Value temporal_duration_like, Value options_value)
{
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == ArithmeticOperation::Subtract ? -1 : 1;
// 2. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
auto duration = TRY(to_temporal_duration_record(vm, temporal_duration_like));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, options_value));
auto* options = TRY(get_options_object(vm, options_value));
// 4. Let result be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], sign × duration.[[Years]], sign × duration.[[Months]], sign × duration.[[Weeks]], sign × duration.[[Days]], sign × duration.[[Hours]], sign × duration.[[Minutes]], sign × duration.[[Seconds]], sign × duration.[[Milliseconds]], sign × duration.[[Microseconds]], sign × duration.[[Nanoseconds]], options).
auto result = TRY(add_date_time(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), sign * duration.years, sign * duration.months, sign * duration.weeks, sign * duration.days, sign * duration.hours, sign * duration.minutes, sign * duration.seconds, sign * duration.milliseconds, sign * duration.microseconds, sign * duration.nanoseconds, options));
auto result = TRY(add_date_time(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), sign * duration.years, sign * duration.months, sign * duration.weeks, sign * duration.days, sign * duration.hours, sign * duration.minutes, sign * duration.seconds, sign * duration.milliseconds, sign * duration.microseconds, sign * duration.nanoseconds, options));
// 5. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
@ -466,7 +467,7 @@ ThrowCompletionOr<PlainDateTime*> add_duration_to_or_subtract_duration_from_plai
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
// 7. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], dateTime.[[Calendar]]).
return create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, date_time.calendar());
return create_temporal_date_time(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, date_time.calendar());
}
}

View file

@ -63,18 +63,18 @@ struct TemporalPlainDateTime {
u16 nanosecond;
};
BigInt* get_epoch_from_iso_parts(GlobalObject&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
bool iso_date_time_within_limits(GlobalObject&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(GlobalObject&, Object& calendar, Object& fields, Object const& options);
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject&, Value item, Object const* options = nullptr);
BigInt* get_epoch_from_iso_parts(VM&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
bool iso_date_time_within_limits(VM&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(VM&, Object& calendar, Object& fields, Object const& options);
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(VM&, Value item, Object const* options = nullptr);
ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, i64 nanosecond);
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_date_time_to_string(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar);
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_date_time_to_string(VM&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar);
i8 compare_iso_date_time(i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
ThrowCompletionOr<TemporalPlainDateTime> add_date_time(GlobalObject&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options);
ISODateTime round_iso_date_time(GlobalObject&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length = {});
ThrowCompletionOr<DurationRecord> difference_iso_date_time(GlobalObject&, i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2, Object& calendar, StringView largest_unit, Object const& options);
ThrowCompletionOr<Duration*> difference_temporal_plain_date_time(GlobalObject&, DifferenceOperation, PlainDateTime&, Value other, Value options);
ThrowCompletionOr<PlainDateTime*> add_duration_to_or_subtract_duration_from_plain_date_time(GlobalObject&, ArithmeticOperation, PlainDateTime&, Value temporal_duration_like, Value options_value);
ThrowCompletionOr<TemporalPlainDateTime> add_date_time(VM&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options);
ISODateTime round_iso_date_time(VM&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length = {});
ThrowCompletionOr<DurationRecord> difference_iso_date_time(VM&, i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2, Object& calendar, StringView largest_unit, Object const& options);
ThrowCompletionOr<Duration*> difference_temporal_plain_date_time(VM&, DifferenceOperation, PlainDateTime&, Value other, Value options);
ThrowCompletionOr<PlainDateTime*> add_duration_to_or_subtract_duration_from_plain_date_time(VM&, ArithmeticOperation, PlainDateTime&, Value temporal_duration_like, Value options_value);
}

View file

@ -49,37 +49,36 @@ ThrowCompletionOr<Value> PlainDateTimeConstructor::call()
ThrowCompletionOr<Object*> PlainDateTimeConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
// 2. Let isoYear be ? ToIntegerThrowOnInfinity(isoYear).
auto iso_year = TRY(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime));
auto iso_year = TRY(to_integer_throw_on_infinity(vm, vm.argument(0), ErrorType::TemporalInvalidPlainDateTime));
// 3. Let isoMonth be ? ToIntegerThrowOnInfinity(isoMonth).
auto iso_month = TRY(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime));
auto iso_month = TRY(to_integer_throw_on_infinity(vm, vm.argument(1), ErrorType::TemporalInvalidPlainDateTime));
// 4. Let isoDay be ? ToIntegerThrowOnInfinity(isoDay).
auto iso_day = TRY(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime));
auto iso_day = TRY(to_integer_throw_on_infinity(vm, vm.argument(2), ErrorType::TemporalInvalidPlainDateTime));
// 5. Let hour be ? ToIntegerThrowOnInfinity(hour).
auto hour = TRY(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime));
auto hour = TRY(to_integer_throw_on_infinity(vm, vm.argument(3), ErrorType::TemporalInvalidPlainDateTime));
// 6. Let minute be ? ToIntegerThrowOnInfinity(minute).
auto minute = TRY(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime));
auto minute = TRY(to_integer_throw_on_infinity(vm, vm.argument(4), ErrorType::TemporalInvalidPlainDateTime));
// 7. Let second be ? ToIntegerThrowOnInfinity(second).
auto second = TRY(to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime));
auto second = TRY(to_integer_throw_on_infinity(vm, vm.argument(5), ErrorType::TemporalInvalidPlainDateTime));
// 8. Let millisecond be ? ToIntegerThrowOnInfinity(millisecond).
auto millisecond = TRY(to_integer_throw_on_infinity(global_object, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime));
auto millisecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(6), ErrorType::TemporalInvalidPlainDateTime));
// 9. Let microsecond be ? ToIntegerThrowOnInfinity(microsecond).
auto microsecond = TRY(to_integer_throw_on_infinity(global_object, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime));
auto microsecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(7), ErrorType::TemporalInvalidPlainDateTime));
// 10. Let nanosecond be ? ToIntegerThrowOnInfinity(nanosecond).
auto nanosecond = TRY(to_integer_throw_on_infinity(global_object, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime));
auto nanosecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(8), ErrorType::TemporalInvalidPlainDateTime));
// 11. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, vm.argument(9)));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, vm.argument(9)));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalDateTime will immediately check that these values are valid
@ -89,7 +88,7 @@ ThrowCompletionOr<Object*> PlainDateTimeConstructor::construct(FunctionObject& n
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainDateTime);
// 12. Return ? CreateTemporalDateTime(isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar, NewTarget).
return TRY(create_temporal_date_time(global_object, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, *calendar, &new_target));
return TRY(create_temporal_date_time(vm, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, *calendar, &new_target));
}
// 5.2.2 Temporal.PlainDateTime.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.from
@ -98,31 +97,31 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimeConstructor::from)
auto item = vm.argument(0);
// 1. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 2. If Type(item) is Object and item has an [[InitializedTemporalDateTime]] internal slot, then
if (item.is_object() && is<PlainDateTime>(item.as_object())) {
auto& plain_date_time = static_cast<PlainDateTime&>(item.as_object());
// a. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// b. Return ! CreateTemporalDateTime(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[ISOHour]], item.[[ISOMinute]], item.[[ISOSecond]], item.[[ISOMillisecond]], item.[[ISOMicrosecond]], item.[[ISONanosecond]], item.[[Calendar]]).
return MUST(create_temporal_date_time(global_object, plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond(), plain_date_time.calendar()));
return MUST(create_temporal_date_time(vm, plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond(), plain_date_time.calendar()));
}
// 3. Return ? ToTemporalDateTime(item, options).
return TRY(to_temporal_date_time(global_object, item, options));
return TRY(to_temporal_date_time(vm, item, options));
}
// 5.2.3 Temporal.PlainDateTime.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.compare
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimeConstructor::compare)
{
// 1. Set one to ? ToTemporalDateTime(one).
auto* one = TRY(to_temporal_date_time(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_date_time(vm, vm.argument(0)));
// 2. Set two to ? ToTemporalDateTime(two).
auto* two = TRY(to_temporal_date_time(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_date_time(vm, vm.argument(1)));
// 3. Return 𝔽(! CompareISODateTime(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], one.[[ISOHour]], one.[[ISOMinute]], one.[[ISOSecond]], one.[[ISOMillisecond]], one.[[ISOMicrosecond]], one.[[ISONanosecond]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], two.[[ISOHour]], two.[[ISOMinute]], two.[[ISOSecond]], two.[[ISOMillisecond]], two.[[ISOMicrosecond]], two.[[ISONanosecond]])).
return Value(compare_iso_date_time(one->iso_year(), one->iso_month(), one->iso_day(), one->iso_hour(), one->iso_minute(), one->iso_second(), one->iso_millisecond(), one->iso_microsecond(), one->iso_nanosecond(), two->iso_year(), two->iso_month(), two->iso_day(), two->iso_hour(), two->iso_minute(), two->iso_second(), two->iso_millisecond(), two->iso_microsecond(), two->iso_nanosecond()));

View file

@ -102,7 +102,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::year_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarYear(calendar, dateTime).
return Value(TRY(calendar_year(global_object, calendar, *date_time)));
return Value(TRY(calendar_year(vm, calendar, *date_time)));
}
// 5.3.5 get Temporal.PlainDateTime.prototype.month, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.month
@ -116,7 +116,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::month_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarMonth(calendar, dateTime).
return Value(TRY(calendar_month(global_object, calendar, *date_time)));
return Value(TRY(calendar_month(vm, calendar, *date_time)));
}
// 5.3.6 get Temporal.PlainDateTime.prototype.monthCode, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.monthcode
@ -130,7 +130,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::month_code_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarMonthCode(calendar, dateTime).
return js_string(vm, TRY(calendar_month_code(global_object, calendar, *date_time)));
return js_string(vm, TRY(calendar_month_code(vm, calendar, *date_time)));
}
// 5.3.7 get Temporal.PlainDateTime.prototype.day, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.day
@ -144,7 +144,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarDay(calendar, dateTime).
return Value(TRY(calendar_day(global_object, calendar, *date_time)));
return Value(TRY(calendar_day(vm, calendar, *date_time)));
}
// 5.3.8 get Temporal.PlainDateTime.prototype.hour, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.hour
@ -224,7 +224,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_of_week_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarDayOfWeek(calendar, dateTime).
return TRY(calendar_day_of_week(global_object, calendar, *date_time));
return TRY(calendar_day_of_week(vm, calendar, *date_time));
}
// 5.3.15 get Temporal.PlainDateTime.prototype.dayOfYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.dayofyear
@ -238,7 +238,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_of_year_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarDayOfYear(calendar, dateTime).
return TRY(calendar_day_of_year(global_object, calendar, *date_time));
return TRY(calendar_day_of_year(vm, calendar, *date_time));
}
// 5.3.16 get Temporal.PlainDateTime.prototype.weekOfYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.weekofyear
@ -252,7 +252,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::week_of_year_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarWeekOfYear(calendar, dateTime).
return TRY(calendar_week_of_year(global_object, calendar, *date_time));
return TRY(calendar_week_of_year(vm, calendar, *date_time));
}
// 5.3.17 get Temporal.PlainDateTime.prototype.daysInWeek, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.daysinweek
@ -266,7 +266,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_week_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarDaysInWeek(calendar, dateTime).
return TRY(calendar_days_in_week(global_object, calendar, *date_time));
return TRY(calendar_days_in_week(vm, calendar, *date_time));
}
// 5.3.18 get Temporal.PlainDateTime.prototype.daysInMonth, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.daysinmonth
@ -280,7 +280,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_month_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarDaysInMonth(calendar, dateTime).
return TRY(calendar_days_in_month(global_object, calendar, *date_time));
return TRY(calendar_days_in_month(vm, calendar, *date_time));
}
// 5.3.19 get Temporal.PlainDateTime.prototype.daysInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.daysinyear
@ -294,7 +294,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_year_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarDaysInYear(calendar, dateTime).
return TRY(calendar_days_in_year(global_object, calendar, *date_time));
return TRY(calendar_days_in_year(vm, calendar, *date_time));
}
// 5.3.20 get Temporal.PlainDateTime.prototype.monthsInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.monthsinyear
@ -308,7 +308,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::months_in_year_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarMonthsInYear(calendar, dateTime).
return TRY(calendar_months_in_year(global_object, calendar, *date_time));
return TRY(calendar_months_in_year(vm, calendar, *date_time));
}
// 5.3.21 get Temporal.PlainDateTime.prototype.inLeapYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.inleapyear
@ -322,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::in_leap_year_getter)
auto& calendar = date_time->calendar();
// 4. Return ? CalendarInLeapYear(calendar, dateTime).
return TRY(calendar_in_leap_year(global_object, calendar, *date_time));
return TRY(calendar_in_leap_year(vm, calendar, *date_time));
}
// 15.6.6.2 get Temporal.PlainDateTime.prototype.era, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.era
@ -336,7 +336,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::era_getter)
auto& calendar = plain_date_time->calendar();
// 4. Return ? CalendarEra(calendar, plainDateTime).
return TRY(calendar_era(global_object, calendar, *plain_date_time));
return TRY(calendar_era(vm, calendar, *plain_date_time));
}
// 15.6.6.3 get Temporal.PlainDateTime.prototype.eraYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.erayear
@ -350,7 +350,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::era_year_getter)
auto& calendar = plain_date_time->calendar();
// 4. Return ? CalendarEraYear(calendar, plainDateTime).
return TRY(calendar_era_year(global_object, calendar, *plain_date_time));
return TRY(calendar_era_year(vm, calendar, *plain_date_time));
}
// 5.3.22 Temporal.PlainDateTime.prototype.with ( temporalDateTimeLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.with
@ -369,31 +369,31 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with)
}
// 4. Perform ? RejectObjectWithCalendarOrTimeZone(temporalDateTimeLike).
TRY(reject_object_with_calendar_or_time_zone(global_object, temporal_date_time_like.as_object()));
TRY(reject_object_with_calendar_or_time_zone(vm, temporal_date_time_like.as_object()));
// 5. Let calendar be dateTime.[[Calendar]].
auto& calendar = date_time->calendar();
// 6. Let fieldNames be ? CalendarFields(calendar, « "day", "hour", "microsecond", "millisecond", "minute", "month", "monthCode", "nanosecond", "second", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// 7. Let partialDateTime be ? PrepareTemporalFields(temporalDateTimeLike, fieldNames, partial).
auto* partial_date_time = TRY(prepare_temporal_fields(global_object, temporal_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
auto* partial_date_time = TRY(prepare_temporal_fields(vm, temporal_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(dateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *date_time, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialDateTime).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_date_time));
fields = TRY(calendar_merge_fields(vm, calendar, *fields, *partial_date_time));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
fields = TRY(prepare_temporal_fields(vm, *fields, field_names, Vector<StringView> {}));
// 12. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
auto result = TRY(interpret_temporal_date_time_fields(global_object, calendar, *fields, *options));
auto result = TRY(interpret_temporal_date_time_fields(vm, calendar, *fields, *options));
// 13. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
@ -402,7 +402,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with)
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
// 15. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], calendar).
return TRY(create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar));
return TRY(create_temporal_date_time(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar));
}
// 5.3.23 Temporal.PlainDateTime.prototype.withPlainTime ( [ plainTimeLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.withplaintime
@ -415,14 +415,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_plain_time)
// 3. If plainTimeLike is undefined, then
if (vm.argument(0).is_undefined()) {
// a. Return ? CreateTemporalDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], 0, 0, 0, 0, 0, 0, dateTime.[[Calendar]]).
return TRY(create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), 0, 0, 0, 0, 0, 0, date_time->calendar()));
return TRY(create_temporal_date_time(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), 0, 0, 0, 0, 0, 0, date_time->calendar()));
}
// 4. Let plainTime be ? ToTemporalTime(plainTimeLike).
auto* plain_time = TRY(to_temporal_time(global_object, vm.argument(0)));
auto* plain_time = TRY(to_temporal_time(vm, vm.argument(0)));
// 5. Return ? CreateTemporalDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], plainTime.[[ISOHour]], plainTime.[[ISOMinute]], plainTime.[[ISOSecond]], plainTime.[[ISOMillisecond]], plainTime.[[ISOMicrosecond]], plainTime.[[ISONanosecond]], dateTime.[[Calendar]]).
return TRY(create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), plain_time->iso_hour(), plain_time->iso_minute(), plain_time->iso_second(), plain_time->iso_millisecond(), plain_time->iso_microsecond(), plain_time->iso_nanosecond(), date_time->calendar()));
return TRY(create_temporal_date_time(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), plain_time->iso_hour(), plain_time->iso_minute(), plain_time->iso_second(), plain_time->iso_millisecond(), plain_time->iso_microsecond(), plain_time->iso_nanosecond(), date_time->calendar()));
}
// 5.3.24 Temporal.PlainDateTime.prototype.withPlainDate ( plainDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.withplaindate
@ -433,13 +433,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_plain_date)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Let plainDate be ? ToTemporalDate(plainDateLike).
auto* plain_date = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* plain_date = TRY(to_temporal_date(vm, vm.argument(0)));
// 4. Let calendar be ? ConsolidateCalendars(dateTime.[[Calendar]], plainDate.[[Calendar]]).
auto* calendar = TRY(consolidate_calendars(global_object, date_time->calendar(), plain_date->calendar()));
auto* calendar = TRY(consolidate_calendars(vm, date_time->calendar(), plain_date->calendar()));
// 5. Return ? CreateTemporalDateTime(plainDate.[[ISOYear]], plainDate.[[ISOMonth]], plainDate.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], calendar).
return TRY(create_temporal_date_time(global_object, plain_date->iso_year(), plain_date->iso_month(), plain_date->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar));
return TRY(create_temporal_date_time(vm, plain_date->iso_year(), plain_date->iso_month(), plain_date->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar));
}
// 5.3.25 Temporal.PlainDateTime.prototype.withCalendar ( calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.withcalendar
@ -452,10 +452,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_calendar)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
auto* calendar = TRY(to_temporal_calendar(global_object, calendar_like));
auto* calendar = TRY(to_temporal_calendar(vm, calendar_like));
// 4. Return ? CreateTemporalDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], calendar).
return TRY(create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar));
return TRY(create_temporal_date_time(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar));
}
// 5.3.26 Temporal.PlainDateTime.prototype.add ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.add
@ -469,7 +469,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::add)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromPlainDateTime(add, dateTime, temporalDurationLike, options).
return TRY(add_duration_to_or_subtract_duration_from_plain_date_time(global_object, ArithmeticOperation::Add, *date_time, temporal_duration_like, options));
return TRY(add_duration_to_or_subtract_duration_from_plain_date_time(vm, ArithmeticOperation::Add, *date_time, temporal_duration_like, options));
}
// 5.3.27 Temporal.PlainDateTime.prototype.subtract ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.subtract
@ -483,7 +483,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::subtract)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromPlainDateTime(subtract, dateTime, temporalDurationLike, options).
return TRY(add_duration_to_or_subtract_duration_from_plain_date_time(global_object, ArithmeticOperation::Subtract, *date_time, temporal_duration_like, options));
return TRY(add_duration_to_or_subtract_duration_from_plain_date_time(vm, ArithmeticOperation::Subtract, *date_time, temporal_duration_like, options));
}
// 5.3.28 Temporal.PlainDateTime.prototype.until ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.since
@ -497,7 +497,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::until)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainDateTime(until, dateTime, other, options).
return TRY(difference_temporal_plain_date_time(global_object, DifferenceOperation::Until, *date_time, other, options));
return TRY(difference_temporal_plain_date_time(vm, DifferenceOperation::Until, *date_time, other, options));
}
// 5.3.29 Temporal.PlainDateTime.prototype.since ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.since
@ -511,7 +511,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::since)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainDateTime(since, dateTime, other, options).
return TRY(difference_temporal_plain_date_time(global_object, DifferenceOperation::Since, *date_time, other, options));
return TRY(difference_temporal_plain_date_time(vm, DifferenceOperation::Since, *date_time, other, options));
}
// 5.3.30 Temporal.PlainDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.round
@ -544,23 +544,23 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::round)
// 5. Else,
else {
// a. Set roundTo to ? GetOptionsObject(roundTo).
round_to = TRY(get_options_object(global_object, vm.argument(0)));
round_to = TRY(get_options_object(vm, vm.argument(0)));
}
// 6. Let smallestUnit be ? GetTemporalUnit(roundTo, "smallestUnit", time, required, « "day" »).
auto smallest_unit = TRY(get_temporal_unit(global_object, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}, { "day"sv }));
auto smallest_unit = TRY(get_temporal_unit(vm, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}, { "day"sv }));
// 7. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *round_to, "halfExpand"));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *round_to, "halfExpand"));
// 8. Let roundingIncrement be ? ToTemporalDateTimeRoundingIncrement(roundTo, smallestUnit).
auto rounding_increment = TRY(to_temporal_date_time_rounding_increment(global_object, *round_to, *smallest_unit));
auto rounding_increment = TRY(to_temporal_date_time_rounding_increment(vm, *round_to, *smallest_unit));
// 9. Let result be ! RoundISODateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode).
auto result = round_iso_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), rounding_increment, *smallest_unit, rounding_mode);
auto result = round_iso_date_time(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), rounding_increment, *smallest_unit, rounding_mode);
// 10. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], dateTime.[[Calendar]]).
return TRY(create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, date_time->calendar()));
return TRY(create_temporal_date_time(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, date_time->calendar()));
}
// 5.3.31 Temporal.PlainDateTime.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.equals
@ -571,7 +571,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::equals)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Set other to ? ToTemporalDateTime(other).
auto* other = TRY(to_temporal_date_time(global_object, vm.argument(0)));
auto* other = TRY(to_temporal_date_time(vm, vm.argument(0)));
// 4. Let result be ! CompareISODateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], other.[[ISOYear]], other.[[ISOMonth]], other.[[ISODay]], other.[[ISOHour]], other.[[ISOMinute]], other.[[ISOSecond]], other.[[ISOMillisecond]], other.[[ISOMicrosecond]], other.[[ISONanosecond]]).
auto result = compare_iso_date_time(date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), other->iso_year(), other->iso_month(), other->iso_day(), other->iso_hour(), other->iso_minute(), other->iso_second(), other->iso_millisecond(), other->iso_microsecond(), other->iso_nanosecond());
@ -581,7 +581,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::equals)
return Value(false);
// 6. Return ? CalendarEquals(dateTime.[[Calendar]], other.[[Calendar]]).
return Value(TRY(calendar_equals(global_object, date_time->calendar(), other->calendar())));
return Value(TRY(calendar_equals(vm, date_time->calendar(), other->calendar())));
}
// 5.3.32 Temporal.PlainDateTime.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.tostring
@ -592,22 +592,22 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_string)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(0)));
auto* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let precision be ? ToSecondsStringPrecision(options).
auto precision = TRY(to_seconds_string_precision(global_object, *options));
auto precision = TRY(to_seconds_string_precision(vm, *options));
// 5. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *options, "trunc"sv));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *options, "trunc"sv));
// 6. Let showCalendar be ? ToShowCalendarOption(options).
auto show_calendar = TRY(to_show_calendar_option(global_object, *options));
auto show_calendar = TRY(to_show_calendar_option(vm, *options));
// 7. Let result be ! RoundISODateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], precision.[[Increment]], precision.[[Unit]], roundingMode).
auto result = round_iso_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), precision.increment, precision.unit, rounding_mode);
auto result = round_iso_date_time(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), precision.increment, precision.unit, rounding_mode);
// 8. Return ? TemporalDateTimeToString(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], dateTime.[[Calendar]], precision.[[Precision]], showCalendar).
return js_string(vm, TRY(temporal_date_time_to_string(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, &date_time->calendar(), precision.precision, show_calendar)));
return js_string(vm, TRY(temporal_date_time_to_string(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, &date_time->calendar(), precision.precision, show_calendar)));
}
// 5.3.33 Temporal.PlainDateTime.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.tolocalestring
@ -619,7 +619,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_locale_string)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ? TemporalDateTimeToString(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], "auto", "auto").
return js_string(vm, TRY(temporal_date_time_to_string(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), &date_time->calendar(), "auto"sv, "auto"sv)));
return js_string(vm, TRY(temporal_date_time_to_string(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), &date_time->calendar(), "auto"sv, "auto"sv)));
}
// 5.3.34 Temporal.PlainDateTime.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.tojson
@ -630,7 +630,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_json)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ? TemporalDateTimeToString(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], "auto", "auto").
return js_string(vm, TRY(temporal_date_time_to_string(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), &date_time->calendar(), "auto"sv, "auto"sv)));
return js_string(vm, TRY(temporal_date_time_to_string(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), &date_time->calendar(), "auto"sv, "auto"sv)));
}
// 5.3.35 Temporal.PlainDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.valueof
@ -648,19 +648,19 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_zoned_date_time)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
auto* time_zone = TRY(to_temporal_time_zone(global_object, vm.argument(0)));
auto* time_zone = TRY(to_temporal_time_zone(vm, vm.argument(0)));
// 4. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 5. Let disambiguation be ? ToTemporalDisambiguation(options).
auto disambiguation = TRY(to_temporal_disambiguation(global_object, options));
auto disambiguation = TRY(to_temporal_disambiguation(vm, options));
// 6. Let instant be ? BuiltinTimeZoneGetInstantFor(timeZone, dateTime, disambiguation).
auto* instant = TRY(builtin_time_zone_get_instant_for(global_object, time_zone, *date_time, disambiguation));
auto* instant = TRY(builtin_time_zone_get_instant_for(vm, time_zone, *date_time, disambiguation));
// 7. Return ! CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, dateTime.[[Calendar]]).
return MUST(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), *time_zone, date_time->calendar()));
return MUST(create_temporal_zoned_date_time(vm, instant->nanoseconds(), *time_zone, date_time->calendar()));
}
// 5.3.37 Temporal.PlainDateTime.prototype.toPlainDate ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.toplaindate
@ -671,7 +671,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_date)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[Calendar]]).
return MUST(create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
return MUST(create_temporal_date(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
}
// 5.3.38 Temporal.PlainDateTime.prototype.toPlainYearMonth ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.toplainyearmonth
@ -685,13 +685,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_year_month)
auto& calendar = date_time->calendar();
// 4. Let fieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "monthCode"sv, "year"sv }));
// 5. Let fields be ? PrepareTemporalFields(dateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *date_time, field_names, Vector<StringView> {}));
// 6. Return ? CalendarYearMonthFromFields(calendar, fields).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields));
return TRY(calendar_year_month_from_fields(vm, calendar, *fields));
}
// 5.3.39 Temporal.PlainDateTime.prototype.toPlainMonthDay ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.toplainmonthday
@ -705,13 +705,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_month_day)
auto& calendar = date_time->calendar();
// 4. Let fieldNames be ? CalendarFields(calendar, « "day", "monthCode" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "monthCode"sv }));
// 5. Let fields be ? PrepareTemporalFields(dateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *date_time, field_names, Vector<StringView> {}));
// 6. Return ? CalendarMonthDayFromFields(calendar, fields).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields));
return TRY(calendar_month_day_from_fields(vm, calendar, *fields));
}
// 5.3.40 Temporal.PlainDateTime.prototype.toPlainTime ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.toplaintime
@ -722,7 +722,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_time)
auto* date_time = TRY(typed_this_object(global_object));
// 3. Return ! CreateTemporalTime(dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
return MUST(create_temporal_time(global_object, date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond()));
return MUST(create_temporal_time(vm, date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond()));
}
// 5.3.41 Temporal.PlainDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.getisofields

View file

@ -34,9 +34,10 @@ void PlainMonthDay::visit_edges(Visitor& visitor)
}
// 10.5.1 ToTemporalMonthDay ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalmonthday
ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject& global_object, Value item, Object const* options)
ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(VM& vm, Value item, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
// 2. Assert: Type(options) is Object or Undefined.
@ -89,14 +90,14 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject& global_obj
calendar_absent = calendar_like.is_undefined();
// iv. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
calendar = TRY(to_temporal_calendar_with_iso_default(global_object, calendar_like));
calendar = TRY(to_temporal_calendar_with_iso_default(vm, calendar_like));
}
// d. Let fieldNames be ? CalendarFields(calendar, « "day", "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// e. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> {}));
// f. Let month be ? Get(fields, "month").
auto month = TRY(fields->get(vm.names.month));
@ -114,39 +115,40 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject& global_obj
}
// j. Return ? CalendarMonthDayFromFields(calendar, fields, options).
return calendar_month_day_from_fields(global_object, *calendar, *fields, options);
return calendar_month_day_from_fields(vm, *calendar, *fields, options);
}
// 5. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// 6. Let string be ? ToString(item).
auto string = TRY(item.to_string(global_object));
// 7. Let result be ? ParseTemporalMonthDayString(string).
auto result = TRY(parse_temporal_month_day_string(global_object, string));
auto result = TRY(parse_temporal_month_day_string(vm, string));
// 8. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, result.calendar.has_value() ? js_string(vm, move(*result.calendar)) : js_undefined()));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, result.calendar.has_value() ? js_string(vm, move(*result.calendar)) : js_undefined()));
// 9. If result.[[Year]] is undefined, then
if (!result.year.has_value()) {
// a. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, referenceISOYear).
return TRY(create_temporal_month_day(global_object, result.month, result.day, *calendar, reference_iso_year));
return TRY(create_temporal_month_day(vm, result.month, result.day, *calendar, reference_iso_year));
}
// 10. Set result to ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, referenceISOYear).
auto* plain_month_day = TRY(create_temporal_month_day(global_object, result.month, result.day, *calendar, reference_iso_year));
auto* plain_month_day = TRY(create_temporal_month_day(vm, result.month, result.day, *calendar, reference_iso_year));
// 11. NOTE: The following operation is called without options, in order for the calendar to store a canonical value in the [[ISOYear]] internal slot of the result.
// 12. Return ? CalendarMonthDayFromFields(calendar, result).
return TRY(calendar_month_day_from_fields(global_object, *calendar, *plain_month_day));
return TRY(calendar_month_day_from_fields(vm, *calendar, *plain_month_day));
}
// 10.5.2 CreateTemporalMonthDay ( isoMonth, isoDay, calendar, referenceISOYear [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalmonthday
ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(GlobalObject& global_object, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target)
ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoMonth, isoDay, and referenceISOYear are integers.
// 2. Assert: Type(calendar) is Object.
@ -156,7 +158,7 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(GlobalObject& global
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainMonthDay);
// 4. If ISODateTimeWithinLimits(referenceISOYear, isoMonth, isoDay, 12, 0, 0, 0, 0, 0) is false, throw a RangeError exception.
if (!iso_date_time_within_limits(global_object, reference_iso_year, iso_month, iso_day, 12, 0, 0, 0, 0, 0))
if (!iso_date_time_within_limits(vm, reference_iso_year, iso_month, iso_day, 12, 0, 0, 0, 0, 0))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainMonthDay);
// 5. If newTarget is not present, set newTarget to %Temporal.PlainMonthDay%.
@ -175,8 +177,11 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(GlobalObject& global
}
// 10.5.3 TemporalMonthDayToString ( monthDay, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalmonthdaytostring
ThrowCompletionOr<String> temporal_month_day_to_string(GlobalObject& global_object, PlainMonthDay& month_day, StringView show_calendar)
ThrowCompletionOr<String> temporal_month_day_to_string(VM& vm, PlainMonthDay& month_day, StringView show_calendar)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(monthDay) is Object.
// 2. Assert: monthDay has an [[InitializedTemporalMonthDay]] internal slot.

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -39,8 +39,8 @@ struct ISOMonthDay {
i32 reference_iso_year;
};
ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject&, Value item, Object const* options = nullptr);
ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(GlobalObject&, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_month_day_to_string(GlobalObject&, PlainMonthDay&, StringView show_calendar);
ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(VM&, Value item, Object const* options = nullptr);
ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM&, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_month_day_to_string(VM&, PlainMonthDay&, StringView show_calendar);
}

View file

@ -47,7 +47,6 @@ ThrowCompletionOr<Value> PlainMonthDayConstructor::call()
ThrowCompletionOr<Object*> PlainMonthDayConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto iso_month = vm.argument(0);
auto iso_day = vm.argument(1);
@ -61,16 +60,16 @@ ThrowCompletionOr<Object*> PlainMonthDayConstructor::construct(FunctionObject& n
}
// 3. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = TRY(to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainMonthDay));
auto m = TRY(to_integer_throw_on_infinity(vm, iso_month, ErrorType::TemporalInvalidPlainMonthDay));
// 4. Let d be ? ToIntegerThrowOnInfinity(isoDay).
auto d = TRY(to_integer_throw_on_infinity(global_object, iso_day, ErrorType::TemporalInvalidPlainMonthDay));
auto d = TRY(to_integer_throw_on_infinity(vm, iso_day, ErrorType::TemporalInvalidPlainMonthDay));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, calendar_like));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, calendar_like));
// 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISOYear).
auto ref = TRY(to_integer_throw_on_infinity(global_object, reference_iso_year, ErrorType::TemporalInvalidPlainMonthDay));
auto ref = TRY(to_integer_throw_on_infinity(vm, reference_iso_year, ErrorType::TemporalInvalidPlainMonthDay));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalMonthDay will immediately check that these values are valid
@ -79,7 +78,7 @@ ThrowCompletionOr<Object*> PlainMonthDayConstructor::construct(FunctionObject& n
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainMonthDay);
// 7. Return ? CreateTemporalMonthDay(m, d, calendar, ref, NewTarget).
return TRY(create_temporal_month_day(global_object, m, d, *calendar, ref, &new_target));
return TRY(create_temporal_month_day(vm, m, d, *calendar, ref, &new_target));
}
// 10.2.2 Temporal.PlainMonthDay.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.from
@ -88,21 +87,21 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayConstructor::from)
auto item = vm.argument(0);
// 1. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
auto const* options = TRY(get_options_object(vm, vm.argument(1)));
// 2. If Type(item) is Object and item has an [[InitializedTemporalMonthDay]] internal slot, then
if (item.is_object() && is<PlainMonthDay>(item.as_object())) {
// a. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
auto& plain_month_day_object = static_cast<PlainMonthDay&>(item.as_object());
// b. Return ! CreateTemporalMonthDay(item.[[ISOMonth]], item.[[ISODay]], item.[[Calendar]], item.[[ISOYear]]).
return MUST(create_temporal_month_day(global_object, plain_month_day_object.iso_month(), plain_month_day_object.iso_day(), plain_month_day_object.calendar(), plain_month_day_object.iso_year()));
return MUST(create_temporal_month_day(vm, plain_month_day_object.iso_month(), plain_month_day_object.iso_day(), plain_month_day_object.calendar(), plain_month_day_object.iso_year()));
}
// 3. Return ? ToTemporalMonthDay(item, options).
return TRY(to_temporal_month_day(global_object, item, options));
return TRY(to_temporal_month_day(vm, item, options));
}
}

View file

@ -66,7 +66,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::month_code_getter)
auto& calendar = month_day->calendar();
// 4. Return ? CalendarMonthCode(calendar, monthDay).
return js_string(vm, TRY(calendar_month_code(global_object, calendar, *month_day)));
return js_string(vm, TRY(calendar_month_code(vm, calendar, *month_day)));
}
// 10.3.5 get Temporal.PlainMonthDay.prototype.day, https://tc39.es/proposal-temporal/#sec-get-temporal.plainmonthday.prototype.day
@ -80,7 +80,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::day_getter)
auto& calendar = month_day->calendar();
// 4. Return 𝔽(? CalendarDay(calendar, monthDay)).
return Value(TRY(calendar_day(global_object, calendar, *month_day)));
return Value(TRY(calendar_day(vm, calendar, *month_day)));
}
// 10.3.6 Temporal.PlainMonthDay.prototype.with ( temporalMonthDayLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.with
@ -99,31 +99,31 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::with)
}
// 4. Perform ? RejectObjectWithCalendarOrTimeZone(temporalMonthDayLike).
TRY(reject_object_with_calendar_or_time_zone(global_object, temporal_month_day_like.as_object()));
TRY(reject_object_with_calendar_or_time_zone(vm, temporal_month_day_like.as_object()));
// 5. Let calendar be monthDay.[[Calendar]].
auto& calendar = month_day->calendar();
// 6. Let fieldNames be ? CalendarFields(calendar, « "day", "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// 7. Let partialMonthDay be ? PrepareTemporalFields(temporalMonthDayLike, fieldNames, partial).
auto* partial_month_day = TRY(prepare_temporal_fields(global_object, temporal_month_day_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
auto* partial_month_day = TRY(prepare_temporal_fields(vm, temporal_month_day_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(monthDay, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *month_day, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *month_day, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialMonthDay).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_month_day));
fields = TRY(calendar_merge_fields(vm, calendar, *fields, *partial_month_day));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
fields = TRY(prepare_temporal_fields(vm, *fields, field_names, Vector<StringView> {}));
// 12. Return ? CalendarMonthDayFromFields(calendar, fields, options).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields, options));
return TRY(calendar_month_day_from_fields(vm, calendar, *fields, options));
}
// 10.3.7 Temporal.PlainMonthDay.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.equals
@ -134,7 +134,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::equals)
auto* month_day = TRY(typed_this_object(global_object));
// 3. Set other to ? ToTemporalMonthDay(other).
auto* other = TRY(to_temporal_month_day(global_object, vm.argument(0)));
auto* other = TRY(to_temporal_month_day(vm, vm.argument(0)));
// 4. If monthDay.[[ISOMonth]] ≠ other.[[ISOMonth]], return false.
if (month_day->iso_month() != other->iso_month())
@ -149,7 +149,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::equals)
return Value(false);
// 7. Return ? CalendarEquals(monthDay.[[Calendar]], other.[[Calendar]]).
return Value(TRY(calendar_equals(global_object, month_day->calendar(), other->calendar())));
return Value(TRY(calendar_equals(vm, month_day->calendar(), other->calendar())));
}
// 10.3.8 Temporal.PlainMonthDay.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.tostring
@ -160,13 +160,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_string)
auto* month_day = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(0)));
auto* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let showCalendar be ? ToShowCalendarOption(options).
auto show_calendar = TRY(to_show_calendar_option(global_object, *options));
auto show_calendar = TRY(to_show_calendar_option(vm, *options));
// 5. Return ? TemporalMonthDayToString(monthDay, showCalendar).
return js_string(vm, TRY(temporal_month_day_to_string(global_object, *month_day, show_calendar)));
return js_string(vm, TRY(temporal_month_day_to_string(vm, *month_day, show_calendar)));
}
// 10.3.9 Temporal.PlainMonthDay.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.tolocalestring
@ -178,7 +178,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_locale_string)
auto* month_day = TRY(typed_this_object(global_object));
// 3. Return ? TemporalMonthDayToString(monthDay, "auto").
return js_string(vm, TRY(temporal_month_day_to_string(global_object, *month_day, "auto"sv)));
return js_string(vm, TRY(temporal_month_day_to_string(vm, *month_day, "auto"sv)));
}
// 10.3.10 Temporal.PlainMonthDay.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.tojson
@ -189,7 +189,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_json)
auto* month_day = TRY(typed_this_object(global_object));
// 3. Return ? TemporalMonthDayToString(monthDay, "auto").
return js_string(vm, TRY(temporal_month_day_to_string(global_object, *month_day, "auto"sv)));
return js_string(vm, TRY(temporal_month_day_to_string(vm, *month_day, "auto"sv)));
}
// 10.3.11 Temporal.PlainMonthDay.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.valueof
@ -220,25 +220,25 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
auto& calendar = month_day->calendar();
// 5. Let receiverFieldNames be ? CalendarFields(calendar, « "day", "monthCode" »).
auto receiver_field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
auto receiver_field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "monthCode"sv }));
// 6. Let fields be ? PrepareTemporalFields(monthDay, receiverFieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *month_day, receiver_field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *month_day, receiver_field_names, Vector<StringView> {}));
// 7. Let inputFieldNames be ? CalendarFields(calendar, « "year" »).
auto input_field_names = TRY(calendar_fields(global_object, calendar, { "year"sv }));
auto input_field_names = TRY(calendar_fields(vm, calendar, { "year"sv }));
// 8. Let inputFields be ? PrepareTemporalFields(item, inputFieldNames, «»).
auto* input_fields = TRY(prepare_temporal_fields(global_object, item.as_object(), input_field_names, Vector<StringView> {}));
auto* input_fields = TRY(prepare_temporal_fields(vm, item.as_object(), input_field_names, Vector<StringView> {}));
// 9. Let mergedFields be ? CalendarMergeFields(calendar, fields, inputFields).
auto* merged_fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *input_fields));
auto* merged_fields = TRY(calendar_merge_fields(vm, calendar, *fields, *input_fields));
// 10. Let mergedFieldNames be MergeLists(receiverFieldNames, inputFieldNames).
auto merged_field_names = merge_lists(receiver_field_names, input_field_names);
// 11. Set mergedFields to ? PrepareTemporalFields(mergedFields, mergedFieldNames, «»).
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
merged_fields = TRY(prepare_temporal_fields(vm, *merged_fields, merged_field_names, Vector<StringView> {}));
// 12. Let options be OrdinaryObjectCreate(null).
auto* options = Object::create(realm, nullptr);
@ -247,7 +247,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
MUST(options->create_data_property_or_throw(vm.names.overflow, js_string(vm, vm.names.reject.as_string())));
// 14. Return ? CalendarDateFromFields(calendar, mergedFields, options).
return TRY(calendar_date_from_fields(global_object, calendar, *merged_fields, options));
return TRY(calendar_date_from_fields(vm, calendar, *merged_fields, options));
}
// 10.3.13 Temporal.PlainMonthDay.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.getisofields

View file

@ -41,7 +41,7 @@ void PlainTime::visit_edges(Visitor& visitor)
}
// 4.5.1 DifferenceTime ( h1, min1, s1, ms1, mus1, ns1, h2, min2, s2, ms2, mus2, ns2 ), https://tc39.es/proposal-temporal/#sec-temporal-differencetime
TimeDurationRecord difference_time(GlobalObject& global_object, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2)
TimeDurationRecord difference_time(VM& vm, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2)
{
// 1. Let hours be h2 - h1.
auto hours = hour2 - hour1;
@ -71,13 +71,14 @@ TimeDurationRecord difference_time(GlobalObject& global_object, u8 hour1, u8 min
VERIFY(bt.days == 0);
// 10. Return ! CreateTimeDurationRecord(0, bt.[[Hour]] × sign, bt.[[Minute]] × sign, bt.[[Second]] × sign, bt.[[Millisecond]] × sign, bt.[[Microsecond]] × sign, bt.[[Nanosecond]] × sign).
return MUST(create_time_duration_record(global_object, 0, static_cast<double>(bt.hour * sign), static_cast<double>(bt.minute * sign), static_cast<double>(bt.second * sign), static_cast<double>(bt.millisecond * sign), static_cast<double>(bt.microsecond * sign), static_cast<double>(bt.nanosecond * sign)));
return MUST(create_time_duration_record(vm, 0, static_cast<double>(bt.hour * sign), static_cast<double>(bt.minute * sign), static_cast<double>(bt.second * sign), static_cast<double>(bt.millisecond * sign), static_cast<double>(bt.microsecond * sign), static_cast<double>(bt.nanosecond * sign)));
}
// 4.5.2 ToTemporalTime ( item [ , overflow ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltime
ThrowCompletionOr<PlainTime*> to_temporal_time(GlobalObject& global_object, Value item, Optional<StringView> overflow)
ThrowCompletionOr<PlainTime*> to_temporal_time(VM& vm, Value item, Optional<StringView> overflow)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If overflow is not present, set overflow to "constrain".
if (!overflow.has_value())
@ -101,23 +102,26 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(GlobalObject& global_object, Valu
// b. If item has an [[InitializedTemporalZonedDateTime]] internal slot, then
if (is<ZonedDateTime>(item_object)) {
auto& zoned_date_time = static_cast<ZonedDateTime&>(item_object);
// i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds()).release_value();
auto* instant = create_temporal_instant(vm, zoned_date_time.nanoseconds()).release_value();
// ii. Set plainDateTime to ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]).
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
// iii. Return ! CreateTemporalTime(plainDateTime.[[ISOHour]], plainDateTime.[[ISOMinute]], plainDateTime.[[ISOSecond]], plainDateTime.[[ISOMillisecond]], plainDateTime.[[ISOMicrosecond]], plainDateTime.[[ISONanosecond]]).
return TRY(create_temporal_time(global_object, plain_date_time->iso_hour(), plain_date_time->iso_minute(), plain_date_time->iso_second(), plain_date_time->iso_millisecond(), plain_date_time->iso_microsecond(), plain_date_time->iso_nanosecond()));
return TRY(create_temporal_time(vm, plain_date_time->iso_hour(), plain_date_time->iso_minute(), plain_date_time->iso_second(), plain_date_time->iso_millisecond(), plain_date_time->iso_microsecond(), plain_date_time->iso_nanosecond()));
}
// c. If item has an [[InitializedTemporalDateTime]] internal slot, then
if (is<PlainDateTime>(item_object)) {
auto& plain_date_time = static_cast<PlainDateTime&>(item_object);
// i. Return ! CreateTemporalTime(item.[[ISOHour]], item.[[ISOMinute]], item.[[ISOSecond]], item.[[ISOMillisecond]], item.[[ISOMicrosecond]], item.[[ISONanosecond]]).
return TRY(create_temporal_time(global_object, plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond()));
return TRY(create_temporal_time(vm, plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond()));
}
// d. Let calendar be ? GetTemporalCalendarWithISODefault(item).
auto* calendar = TRY(get_temporal_calendar_with_iso_default(global_object, item_object));
auto* calendar = TRY(get_temporal_calendar_with_iso_default(vm, item_object));
// e. If ? ToString(calendar) is not "iso8601", then
auto calendar_identifier = TRY(Value(calendar).to_string(global_object));
@ -127,10 +131,10 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(GlobalObject& global_object, Valu
}
// f. Let result be ? ToTemporalTimeRecord(item).
auto unregulated_result = TRY(to_temporal_time_record(global_object, item_object));
auto unregulated_result = TRY(to_temporal_time_record(vm, item_object));
// g. Set result to ? RegulateTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], overflow).
result = TRY(regulate_time(global_object, *unregulated_result.hour, *unregulated_result.minute, *unregulated_result.second, *unregulated_result.millisecond, *unregulated_result.microsecond, *unregulated_result.nanosecond, *overflow));
result = TRY(regulate_time(vm, *unregulated_result.hour, *unregulated_result.minute, *unregulated_result.second, *unregulated_result.millisecond, *unregulated_result.microsecond, *unregulated_result.nanosecond, *overflow));
}
// 4. Else,
else {
@ -138,7 +142,7 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(GlobalObject& global_object, Valu
auto string = TRY(item.to_string(global_object));
// b. Let result be ? ParseTemporalTimeString(string).
result = TRY(parse_temporal_time_string(global_object, string));
result = TRY(parse_temporal_time_string(vm, string));
// c. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
VERIFY(is_valid_time(result->hour, result->minute, result->second, result->millisecond, result->microsecond, result->nanosecond));
@ -151,14 +155,12 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(GlobalObject& global_object, Valu
}
// 5. Return ! CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
return MUST(create_temporal_time(global_object, result->hour, result->minute, result->second, result->millisecond, result->microsecond, result->nanosecond));
return MUST(create_temporal_time(vm, result->hour, result->minute, result->second, result->millisecond, result->microsecond, result->nanosecond));
}
// 4.5.3 RegulateTime ( hour, minute, second, millisecond, microsecond, nanosecond, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulatetime
ThrowCompletionOr<TemporalTime> regulate_time(GlobalObject& global_object, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond, StringView overflow)
ThrowCompletionOr<TemporalTime> regulate_time(VM& vm, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond, StringView overflow)
{
auto& vm = global_object.vm();
// 1. Assert: hour, minute, second, millisecond, microsecond and nanosecond are integers.
VERIFY(trunc(hour) == hour && trunc(minute) == minute && trunc(second) == second && trunc(millisecond) == millisecond && trunc(microsecond) == microsecond && trunc(nanosecond) == nanosecond);
@ -309,9 +311,10 @@ TemporalTime constrain_time(double hour, double minute, double second, double mi
}
// 4.5.7 CreateTemporalTime ( hour, minute, second, millisecond, microsecond, nanosecond [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaltime
ThrowCompletionOr<PlainTime*> create_temporal_time(GlobalObject& global_object, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, FunctionObject const* new_target)
ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: hour, minute, second, millisecond, microsecond and nanosecond are integers.
@ -331,21 +334,19 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(GlobalObject& global_object,
// 9. Set object.[[ISOMicrosecond]] to microsecond.
// 10. Set object.[[ISONanosecond]] to nanosecond.
// 11. Set object.[[Calendar]] to ! GetISO8601Calendar().
auto* object = TRY(ordinary_create_from_constructor<PlainTime>(global_object, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(global_object)));
auto* object = TRY(ordinary_create_from_constructor<PlainTime>(global_object, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(vm)));
// 12. Return object.
return object;
}
// 4.5.8 ToTemporalTimeRecord ( temporalTimeLike [ , completeness ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimerecord
ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(GlobalObject& global_object, Object const& temporal_time_like, ToTemporalTimeRecordCompleteness completeness)
ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(VM& vm, Object const& temporal_time_like, ToTemporalTimeRecordCompleteness completeness)
{
auto& vm = global_object.vm();
// 1. If completeness is not present, set completeness to complete.
// 2. Let partial be ? PrepareTemporalFields(temporalTimeLike, « "hour", "microsecond", "millisecond", "minute", "nanosecond", "second" », partial).
auto* partial = TRY(prepare_temporal_fields(global_object, temporal_time_like, { "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "nanosecond"sv, "second"sv }, PrepareTemporalFieldsPartial {}));
auto* partial = TRY(prepare_temporal_fields(vm, temporal_time_like, { "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "nanosecond"sv, "second"sv }, PrepareTemporalFieldsPartial {}));
// 3. Let result be a new TemporalTimeLike Record with each field set to undefined.
auto result = TemporalTimeLikeRecord {};
@ -579,38 +580,38 @@ DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 micro
}
// 4.5.13 DifferenceTemporalPlainTime ( operation, temporalTime, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplaintime
ThrowCompletionOr<Duration*> difference_temporal_plain_time(GlobalObject& global_object, DifferenceOperation operation, PlainTime const& temporal_time, Value other_value, Value options_value)
ThrowCompletionOr<Duration*> difference_temporal_plain_time(VM& vm, DifferenceOperation operation, PlainTime const& temporal_time, Value other_value, Value options_value)
{
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
// 2. Set other to ? ToTemporalTime(other).
auto* other = TRY(to_temporal_time(global_object, other_value));
auto* other = TRY(to_temporal_time(vm, other_value));
// 3. Let settings be ? GetDifferenceSettings(operation, options, time, « », "nanosecond", "hour").
auto settings = TRY(get_difference_settings(global_object, operation, options_value, UnitGroup::Time, {}, { "nanosecond"sv }, "hour"sv));
auto settings = TRY(get_difference_settings(vm, operation, options_value, UnitGroup::Time, {}, { "nanosecond"sv }, "hour"sv));
// 4. Let result be ! DifferenceTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], other.[[ISOHour]], other.[[ISOMinute]], other.[[ISOSecond]], other.[[ISOMillisecond]], other.[[ISOMicrosecond]], other.[[ISONanosecond]]).
auto result = difference_time(global_object, temporal_time.iso_hour(), temporal_time.iso_minute(), temporal_time.iso_second(), temporal_time.iso_millisecond(), temporal_time.iso_microsecond(), temporal_time.iso_nanosecond(), other->iso_hour(), other->iso_minute(), other->iso_second(), other->iso_millisecond(), other->iso_microsecond(), other->iso_nanosecond());
auto result = difference_time(vm, temporal_time.iso_hour(), temporal_time.iso_minute(), temporal_time.iso_second(), temporal_time.iso_millisecond(), temporal_time.iso_microsecond(), temporal_time.iso_nanosecond(), other->iso_hour(), other->iso_minute(), other->iso_second(), other->iso_millisecond(), other->iso_microsecond(), other->iso_nanosecond());
// 5. Set result to (! RoundDuration(0, 0, 0, 0, result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]])).[[DurationRecord]].
auto rounded_result = MUST(round_duration(global_object, 0, 0, 0, 0, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode)).duration_record;
auto rounded_result = MUST(round_duration(vm, 0, 0, 0, 0, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode)).duration_record;
// 6. Set result to ! BalanceDuration(0, result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]], settings.[[LargestUnit]]).
result = MUST(balance_duration(global_object, 0, rounded_result.hours, rounded_result.minutes, rounded_result.seconds, rounded_result.milliseconds, rounded_result.microseconds, Crypto::SignedBigInteger { (i32)rounded_result.nanoseconds }, settings.largest_unit));
result = MUST(balance_duration(vm, 0, rounded_result.hours, rounded_result.minutes, rounded_result.seconds, rounded_result.milliseconds, rounded_result.microseconds, Crypto::SignedBigInteger { (i32)rounded_result.nanoseconds }, settings.largest_unit));
// 7. Return ! CreateTemporalDuration(0, 0, 0, 0, sign × result.[[Hours]], sign × result.[[Minutes]], sign × result.[[Seconds]], sign × result.[[Milliseconds]], sign × result.[[Microseconds]], sign × result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, 0, 0, 0, 0, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
return MUST(create_temporal_duration(vm, 0, 0, 0, 0, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
}
// 4.5.14 AddDurationToOrSubtractDurationFromPlainTime ( operation, temporalTime, temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoorsubtractdurationfromplaintime
ThrowCompletionOr<PlainTime*> add_duration_to_or_subtract_duration_from_plain_time(GlobalObject& global_object, ArithmeticOperation operation, PlainTime const& temporal_time, Value temporal_duration_like)
ThrowCompletionOr<PlainTime*> add_duration_to_or_subtract_duration_from_plain_time(VM& vm, ArithmeticOperation operation, PlainTime const& temporal_time, Value temporal_duration_like)
{
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == ArithmeticOperation::Subtract ? -1 : 1;
// 2. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
auto duration = TRY(to_temporal_duration_record(vm, temporal_duration_like));
// 3. Let result be ! AddTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], sign × duration.[[Hours]], sign × duration.[[Minutes]], sign × duration.[[Seconds]], sign × duration.[[Milliseconds]], sign × duration.[[Microseconds]], sign × duration.[[Nanoseconds]]).
auto result = add_time(temporal_time.iso_hour(), temporal_time.iso_minute(), temporal_time.iso_second(), temporal_time.iso_millisecond(), temporal_time.iso_microsecond(), temporal_time.iso_nanosecond(), sign * duration.hours, sign * duration.minutes, sign * duration.seconds, sign * duration.milliseconds, sign * duration.microseconds, sign * duration.nanoseconds);
@ -619,7 +620,7 @@ ThrowCompletionOr<PlainTime*> add_duration_to_or_subtract_duration_from_plain_ti
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
// 5. Return ! CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
return MUST(create_temporal_time(global_object, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
return MUST(create_temporal_time(vm, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
}
}

View file

@ -89,19 +89,19 @@ enum class ToTemporalTimeRecordCompleteness {
Complete,
};
TimeDurationRecord difference_time(GlobalObject&, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
ThrowCompletionOr<PlainTime*> to_temporal_time(GlobalObject&, Value item, Optional<StringView> overflow = {});
ThrowCompletionOr<TemporalTime> regulate_time(GlobalObject&, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond, StringView overflow);
TimeDurationRecord difference_time(VM&, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
ThrowCompletionOr<PlainTime*> to_temporal_time(VM&, Value item, Optional<StringView> overflow = {});
ThrowCompletionOr<TemporalTime> regulate_time(VM&, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond, StringView overflow);
bool is_valid_time(double hour, double minute, double second, double millisecond, double microsecond, double nanosecond);
DaysAndTime balance_time(double hour, double minute, double second, double millisecond, double microsecond, double nanosecond);
TemporalTime constrain_time(double hour, double minute, double second, double millisecond, double microsecond, double nanosecond);
ThrowCompletionOr<PlainTime*> create_temporal_time(GlobalObject&, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(GlobalObject&, Object const& temporal_time_like, ToTemporalTimeRecordCompleteness = ToTemporalTimeRecordCompleteness::Complete);
ThrowCompletionOr<PlainTime*> create_temporal_time(VM&, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(VM&, Object const& temporal_time_like, ToTemporalTimeRecordCompleteness = ToTemporalTimeRecordCompleteness::Complete);
String temporal_time_to_string(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision);
i8 compare_temporal_time(u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
DaysAndTime add_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length_ns = {});
ThrowCompletionOr<Duration*> difference_temporal_plain_time(GlobalObject&, DifferenceOperation, PlainTime const&, Value other, Value options);
ThrowCompletionOr<PlainTime*> add_duration_to_or_subtract_duration_from_plain_time(GlobalObject&, ArithmeticOperation, PlainTime const&, Value temporal_duration_like);
ThrowCompletionOr<Duration*> difference_temporal_plain_time(VM&, DifferenceOperation, PlainTime const&, Value other, Value options);
ThrowCompletionOr<PlainTime*> add_duration_to_or_subtract_duration_from_plain_time(VM&, ArithmeticOperation, PlainTime const&, Value temporal_duration_like);
}

View file

@ -47,25 +47,24 @@ ThrowCompletionOr<Value> PlainTimeConstructor::call()
ThrowCompletionOr<Object*> PlainTimeConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
// 2. Let hour be ? ToIntegerThrowOnInfinity(hour).
auto hour = TRY(to_integer_throw_on_infinity(global_object, vm.argument(0), ErrorType::TemporalInvalidPlainTime));
auto hour = TRY(to_integer_throw_on_infinity(vm, vm.argument(0), ErrorType::TemporalInvalidPlainTime));
// 3. Let minute be ? ToIntegerThrowOnInfinity(hour).
auto minute = TRY(to_integer_throw_on_infinity(global_object, vm.argument(1), ErrorType::TemporalInvalidPlainTime));
auto minute = TRY(to_integer_throw_on_infinity(vm, vm.argument(1), ErrorType::TemporalInvalidPlainTime));
// 4. Let second be ? ToIntegerThrowOnInfinity(hour).
auto second = TRY(to_integer_throw_on_infinity(global_object, vm.argument(2), ErrorType::TemporalInvalidPlainTime));
auto second = TRY(to_integer_throw_on_infinity(vm, vm.argument(2), ErrorType::TemporalInvalidPlainTime));
// 5. Let millisecond be ? ToIntegerThrowOnInfinity(hour).
auto millisecond = TRY(to_integer_throw_on_infinity(global_object, vm.argument(3), ErrorType::TemporalInvalidPlainTime));
auto millisecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(3), ErrorType::TemporalInvalidPlainTime));
// 6. Let microsecond be ? ToIntegerThrowOnInfinity(hour).
auto microsecond = TRY(to_integer_throw_on_infinity(global_object, vm.argument(4), ErrorType::TemporalInvalidPlainTime));
auto microsecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(4), ErrorType::TemporalInvalidPlainTime));
// 7. Let nanosecond be ? ToIntegerThrowOnInfinity(hour).
auto nanosecond = TRY(to_integer_throw_on_infinity(global_object, vm.argument(5), ErrorType::TemporalInvalidPlainTime));
auto nanosecond = TRY(to_integer_throw_on_infinity(vm, vm.argument(5), ErrorType::TemporalInvalidPlainTime));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalTime will immediately check that these values are valid
@ -75,17 +74,17 @@ ThrowCompletionOr<Object*> PlainTimeConstructor::construct(FunctionObject& new_t
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainTime);
// 8. Return ? CreateTemporalTime(hour, minute, second, millisecond, microsecond, nanosecond, NewTarget).
return TRY(create_temporal_time(global_object, hour, minute, second, millisecond, microsecond, nanosecond, &new_target));
return TRY(create_temporal_time(vm, hour, minute, second, millisecond, microsecond, nanosecond, &new_target));
}
// 4.2.2 Temporal.PlainTime.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.from
JS_DEFINE_NATIVE_FUNCTION(PlainTimeConstructor::from)
{
// 1. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 2. Let overflow be ? ToTemporalOverflow(options).
auto overflow = TRY(to_temporal_overflow(global_object, options));
auto overflow = TRY(to_temporal_overflow(vm, options));
auto item = vm.argument(0);
@ -93,21 +92,21 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimeConstructor::from)
if (item.is_object() && is<PlainTime>(item.as_object())) {
auto& plain_time = static_cast<PlainTime&>(item.as_object());
// a. Return ! CreateTemporalTime(item.[[ISOHour]], item.[[ISOMinute]], item.[[ISOSecond]], item.[[ISOMillisecond]], item.[[ISOMicrosecond]], item.[[ISONanosecond]]).
return MUST(create_temporal_time(global_object, plain_time.iso_hour(), plain_time.iso_minute(), plain_time.iso_second(), plain_time.iso_millisecond(), plain_time.iso_microsecond(), plain_time.iso_nanosecond()));
return MUST(create_temporal_time(vm, plain_time.iso_hour(), plain_time.iso_minute(), plain_time.iso_second(), plain_time.iso_millisecond(), plain_time.iso_microsecond(), plain_time.iso_nanosecond()));
}
// 4. Return ? ToTemporalTime(item, overflow).
return TRY(to_temporal_time(global_object, item, overflow));
return TRY(to_temporal_time(vm, item, overflow));
}
// 4.2.3 Temporal.PlainTime.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.compare
JS_DEFINE_NATIVE_FUNCTION(PlainTimeConstructor::compare)
{
// 1. Set one to ? ToTemporalTime(one).
auto* one = TRY(to_temporal_time(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_time(vm, vm.argument(0)));
// 2. Set two to ? ToTemporalTime(two).
auto* two = TRY(to_temporal_time(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_time(vm, vm.argument(1)));
// 3. Return 𝔽(! CompareTemporalTime(one.[[ISOHour]], one.[[ISOMinute]], one.[[ISOSecond]], one.[[ISOMillisecond]], one.[[ISOMicrosecond]], one.[[ISONanosecond]], two.[[ISOHour]], two.[[ISOMinute]], two.[[ISOSecond]], two.[[ISOMillisecond]], two.[[ISOMicrosecond]], two.[[ISONanosecond]])).
return Value(compare_temporal_time(one->iso_hour(), one->iso_minute(), one->iso_second(), one->iso_millisecond(), one->iso_microsecond(), one->iso_nanosecond(), two->iso_hour(), two->iso_minute(), two->iso_second(), two->iso_millisecond(), two->iso_microsecond(), two->iso_nanosecond()));

View file

@ -146,7 +146,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::add)
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromPlainTime(add, temporalTime, temporalDurationLike).
return TRY(add_duration_to_or_subtract_duration_from_plain_time(global_object, ArithmeticOperation::Add, *temporal_time, temporal_duration_like));
return TRY(add_duration_to_or_subtract_duration_from_plain_time(vm, ArithmeticOperation::Add, *temporal_time, temporal_duration_like));
}
// 4.3.11 Temporal.PlainTime.prototype.subtract ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.subtract
@ -159,7 +159,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::subtract)
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromPlainTime(subtract, temporalTime, temporalDurationLike).
return TRY(add_duration_to_or_subtract_duration_from_plain_time(global_object, ArithmeticOperation::Subtract, *temporal_time, temporal_duration_like));
return TRY(add_duration_to_or_subtract_duration_from_plain_time(vm, ArithmeticOperation::Subtract, *temporal_time, temporal_duration_like));
}
// 4.3.12 Temporal.PlainTime.prototype.with ( temporalTimeLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.with
@ -180,16 +180,16 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with)
auto& temporal_time_like = temporal_time_like_argument.as_object();
// 4. Perform ? RejectObjectWithCalendarOrTimeZone(temporalTimeLike).
TRY(reject_object_with_calendar_or_time_zone(global_object, temporal_time_like));
TRY(reject_object_with_calendar_or_time_zone(vm, temporal_time_like));
// 5. Let partialTime be ? ToTemporalTimeRecord(temporalTimeLike, partial).
auto partial_time = TRY(to_temporal_time_record(global_object, temporal_time_like, ToTemporalTimeRecordCompleteness::Partial));
auto partial_time = TRY(to_temporal_time_record(vm, temporal_time_like, ToTemporalTimeRecordCompleteness::Partial));
// 6. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 7. Let overflow be ? ToTemporalOverflow(options).
auto overflow = TRY(to_temporal_overflow(global_object, options));
auto overflow = TRY(to_temporal_overflow(vm, options));
// 8. If partialTime.[[Hour]] is not undefined, then
// a. Let hour be partialTime.[[Hour]].
@ -228,10 +228,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with)
auto nanosecond = partial_time.nanosecond.value_or(temporal_time->iso_nanosecond());
// 20. Let result be ? RegulateTime(hour, minute, second, millisecond, microsecond, nanosecond, overflow).
auto result = TRY(regulate_time(global_object, hour, minute, second, millisecond, microsecond, nanosecond, overflow));
auto result = TRY(regulate_time(vm, hour, minute, second, millisecond, microsecond, nanosecond, overflow));
// 21. Return ! CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
return MUST(create_temporal_time(global_object, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
return MUST(create_temporal_time(vm, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
}
// 4.3.13 Temporal.PlainTime.prototype.until ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.until
@ -245,7 +245,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::until)
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainTime(until, temporalTime, other, options).
return TRY(difference_temporal_plain_time(global_object, DifferenceOperation::Until, *temporal_time, other, options));
return TRY(difference_temporal_plain_time(vm, DifferenceOperation::Until, *temporal_time, other, options));
}
// 4.3.14 Temporal.PlainTime.prototype.since ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.since
@ -259,7 +259,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::since)
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainTime(since, temporalTime, other, options).
return TRY(difference_temporal_plain_time(global_object, DifferenceOperation::Since, *temporal_time, other, options));
return TRY(difference_temporal_plain_time(vm, DifferenceOperation::Since, *temporal_time, other, options));
}
// 4.3.15 Temporal.PlainTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.round
@ -292,26 +292,26 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round)
// 5. Else,
else {
// a. Set roundTo to ? GetOptionsObject(roundTo).
round_to = TRY(get_options_object(global_object, vm.argument(0)));
round_to = TRY(get_options_object(vm, vm.argument(0)));
}
// 6. Let smallestUnit be ? GetTemporalUnit(roundTo, "smallestUnit", time, required).
auto smallest_unit = TRY(get_temporal_unit(global_object, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}));
auto smallest_unit = TRY(get_temporal_unit(vm, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}));
// 7. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *round_to, "halfExpand"));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *round_to, "halfExpand"));
// 8. Let maximum be ! MaximumTemporalDurationRoundingIncrement(smallestUnit).
auto maximum = maximum_temporal_duration_rounding_increment(*smallest_unit);
// 9. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo, maximum, false).
auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *round_to, *maximum, false));
auto rounding_increment = TRY(to_temporal_rounding_increment(vm, *round_to, *maximum, false));
// 10. Let result be ! RoundTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode).
auto result = round_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), rounding_increment, *smallest_unit, rounding_mode);
// 11. Return ! CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
return MUST(create_temporal_time(global_object, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
return MUST(create_temporal_time(vm, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
}
// 4.3.16 Temporal.PlainTime.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.equals
@ -322,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::equals)
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Set other to ? ToTemporalTime(other).
auto* other = TRY(to_temporal_time(global_object, vm.argument(0)));
auto* other = TRY(to_temporal_time(vm, vm.argument(0)));
// 4. If temporalTime.[[ISOHour]] ≠ other.[[ISOHour]], return false.
if (temporal_time->iso_hour() != other->iso_hour())
@ -360,10 +360,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_plain_date_time)
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Set temporalDate to ? ToTemporalDate(temporalDate).
auto* temporal_date = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* temporal_date = TRY(to_temporal_date(vm, vm.argument(0)));
// 4. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
return TRY(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
return TRY(create_temporal_date_time(vm, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
}
// 4.3.18 Temporal.PlainTime.prototype.toZonedDateTime ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.tozoneddatetime
@ -391,7 +391,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_zoned_date_time)
}
// 6. Let temporalDate be ? ToTemporalDate(temporalDateLike).
auto* temporal_date = TRY(to_temporal_date(global_object, temporal_date_like));
auto* temporal_date = TRY(to_temporal_date(vm, temporal_date_like));
// 7. Let temporalTimeZoneLike be ? Get(item, "timeZone").
auto temporal_time_zone_like = TRY(item.as_object().get(vm.names.timeZone));
@ -403,16 +403,16 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_zoned_date_time)
}
// 9. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
auto* time_zone = TRY(to_temporal_time_zone(global_object, temporal_time_zone_like));
auto* time_zone = TRY(to_temporal_time_zone(vm, temporal_time_zone_like));
// 10. Let temporalDateTime be ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
auto* temporal_date_time = TRY(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
auto* temporal_date_time = TRY(create_temporal_date_time(vm, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
// 11. Let instant be ? BuiltinTimeZoneGetInstantFor(timeZone, temporalDateTime, "compatible").
auto* instant = TRY(builtin_time_zone_get_instant_for(global_object, time_zone, *temporal_date_time, "compatible"sv));
auto* instant = TRY(builtin_time_zone_get_instant_for(vm, time_zone, *temporal_date_time, "compatible"sv));
// 12. Return ! CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, temporalDate.[[Calendar]]).
return MUST(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), *time_zone, temporal_date->calendar()));
return MUST(create_temporal_zoned_date_time(vm, instant->nanoseconds(), *time_zone, temporal_date->calendar()));
}
// 4.3.19 Temporal.PlainTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.getisofields
@ -460,13 +460,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_string)
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(0)));
auto* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let precision be ? ToSecondsStringPrecision(options).
auto precision = TRY(to_seconds_string_precision(global_object, *options));
auto precision = TRY(to_seconds_string_precision(vm, *options));
// 5. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *options, "trunc"sv));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *options, "trunc"sv));
// 6. Let roundResult be ! RoundTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], precision.[[Increment]], precision.[[Unit]], roundingMode).
auto round_result = round_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), precision.increment, precision.unit, rounding_mode);

View file

@ -33,9 +33,10 @@ void PlainYearMonth::visit_edges(Visitor& visitor)
}
// 9.5.1 ToTemporalYearMonth ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalyearmonth
ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(GlobalObject& global_object, Value item, Object const* options)
ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(VM& vm, Value item, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
// 2. Assert: Type(options) is Object or Undefined.
@ -51,43 +52,41 @@ ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(GlobalObject& global_o
}
// b. Let calendar be ? GetTemporalCalendarWithISODefault(item).
auto* calendar = TRY(get_temporal_calendar_with_iso_default(global_object, item_object));
auto* calendar = TRY(get_temporal_calendar_with_iso_default(vm, item_object));
// c. Let fieldNames be ? CalendarFields(calendar, « "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, *calendar, { "month"sv, "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, *calendar, { "month"sv, "monthCode"sv, "year"sv }));
// d. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> {}));
// e. Return ? CalendarYearMonthFromFields(calendar, fields, options).
return calendar_year_month_from_fields(global_object, *calendar, *fields, options);
return calendar_year_month_from_fields(vm, *calendar, *fields, options);
}
// 4. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// 5. Let string be ? ToString(item).
auto string = TRY(item.to_string(global_object));
// 6. Let result be ? ParseTemporalYearMonthString(string).
auto result = TRY(parse_temporal_year_month_string(global_object, string));
auto result = TRY(parse_temporal_year_month_string(vm, string));
// 7. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
// 8. Set result to ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[Day]]).
auto* creation_result = TRY(create_temporal_year_month(global_object, result.year, result.month, *calendar, result.day));
auto* creation_result = TRY(create_temporal_year_month(vm, result.year, result.month, *calendar, result.day));
// 9. NOTE: The following operation is called without options, in order for the calendar to store a canonical value in the [[ISODay]] internal slot of the result.
// 10. Return ? CalendarYearMonthFromFields(calendar, result).
return calendar_year_month_from_fields(global_object, *calendar, *creation_result);
return calendar_year_month_from_fields(vm, *calendar, *creation_result);
}
// 9.5.2 RegulateISOYearMonth ( year, month, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisoyearmonth
ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(GlobalObject& global_object, double year, double month, StringView overflow)
ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(VM& vm, double year, double month, StringView overflow)
{
auto& vm = global_object.vm();
// 1. Assert: year and month are integers.
VERIFY(year == trunc(year) && month == trunc(month));
@ -187,9 +186,10 @@ ISOYearMonth balance_iso_year_month(double year, double month)
}
// 9.5.6 CreateTemporalYearMonth ( isoYear, isoMonth, calendar, referenceISODay [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalyearmonth
ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(GlobalObject& global_object, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target)
ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoYear, isoMonth, and referenceISODay are integers.
// 2. Assert: Type(calendar) is Object.
@ -218,8 +218,11 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(GlobalObject& glob
}
// 9.5.7 TemporalYearMonthToString ( yearMonth, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalyearmonthtostring
ThrowCompletionOr<String> temporal_year_month_to_string(GlobalObject& global_object, PlainYearMonth& year_month, StringView show_calendar)
ThrowCompletionOr<String> temporal_year_month_to_string(VM& vm, PlainYearMonth& year_month, StringView show_calendar)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(yearMonth) is Object.
// 2. Assert: yearMonth has an [[InitializedTemporalYearMonth]] internal slot.
@ -247,94 +250,92 @@ ThrowCompletionOr<String> temporal_year_month_to_string(GlobalObject& global_obj
}
// 9.5.8 DifferenceTemporalPlainYearMonth ( operation, yearMonth, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplainyearmonth
ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject& global_object, DifferenceOperation operation, PlainYearMonth& year_month, Value other_value, Value options_value)
ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(VM& vm, DifferenceOperation operation, PlainYearMonth& year_month, Value other_value, Value options_value)
{
auto& vm = global_object.vm();
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
// 2. Set other to ? ToTemporalYearMonth(other).
auto* other = TRY(to_temporal_year_month(global_object, other_value));
auto* other = TRY(to_temporal_year_month(vm, other_value));
// 3. Let calendar be yearMonth.[[Calendar]].
auto& calendar = year_month.calendar();
// 4. If ? CalendarEquals(calendar, other.[[Calendar]]) is false, throw a RangeError exception.
if (!TRY(calendar_equals(global_object, calendar, other->calendar())))
if (!TRY(calendar_equals(vm, calendar, other->calendar())))
return vm.throw_completion<RangeError>(ErrorType::TemporalDifferentCalendars);
// 5. Let settings be ? GetDifferenceSettings(operation, options, date, « "week", "day" », "month", "year").
auto settings = TRY(get_difference_settings(global_object, operation, options_value, UnitGroup::Date, { "week"sv, "day"sv }, { "month"sv }, "year"sv));
auto settings = TRY(get_difference_settings(vm, operation, options_value, UnitGroup::Date, { "week"sv, "day"sv }, { "month"sv }, "year"sv));
// 6. Let fieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "monthCode"sv, "year"sv }));
// 7. Let otherFields be ? PrepareTemporalFields(other, fieldNames, «»).
auto* other_fields = TRY(prepare_temporal_fields(global_object, *other, field_names, Vector<StringView> {}));
auto* other_fields = TRY(prepare_temporal_fields(vm, *other, field_names, Vector<StringView> {}));
// 8. Perform ! CreateDataPropertyOrThrow(otherFields, "day", 1𝔽).
MUST(other_fields->create_data_property_or_throw(vm.names.day, Value(1)));
// 9. Let otherDate be ? CalendarDateFromFields(calendar, otherFields).
auto* other_date = TRY(calendar_date_from_fields(global_object, calendar, *other_fields));
auto* other_date = TRY(calendar_date_from_fields(vm, calendar, *other_fields));
// 10. Let thisFields be ? PrepareTemporalFields(yearMonth, fieldNames, «»).
auto* this_fields = TRY(prepare_temporal_fields(global_object, year_month, field_names, Vector<StringView> {}));
auto* this_fields = TRY(prepare_temporal_fields(vm, year_month, field_names, Vector<StringView> {}));
// 11. Perform ! CreateDataPropertyOrThrow(thisFields, "day", 1𝔽).
MUST(this_fields->create_data_property_or_throw(vm.names.day, Value(1)));
// 12. Let thisDate be ? CalendarDateFromFields(calendar, thisFields).
auto* this_date = TRY(calendar_date_from_fields(global_object, calendar, *this_fields));
auto* this_date = TRY(calendar_date_from_fields(vm, calendar, *this_fields));
// 13. Let untilOptions be ? MergeLargestUnitOption(settings.[[Options]], settings.[[LargestUnit]]).
auto* until_options = TRY(merge_largest_unit_option(global_object, settings.options, settings.largest_unit));
auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, settings.largest_unit));
// 14. Let result be ? CalendarDateUntil(calendar, thisDate, otherDate, untilOptions).
auto* duration = TRY(calendar_date_until(global_object, calendar, this_date, other_date, *until_options));
auto* duration = TRY(calendar_date_until(vm, calendar, this_date, other_date, *until_options));
auto result = DurationRecord { duration->years(), duration->months(), 0, 0, 0, 0, 0, 0, 0, 0 };
// 15. If settings.[[SmallestUnit]] is not "month" or settings.[[RoundingIncrement]] ≠ 1, then
if (settings.smallest_unit != "month"sv || settings.rounding_increment != 1) {
// a. Set result to (? RoundDuration(result.[[Years]], result.[[Months]], 0, 0, 0, 0, 0, 0, 0, 0, settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]], thisDate)).[[DurationRecord]].
result = TRY(round_duration(global_object, result.years, result.months, 0, 0, 0, 0, 0, 0, 0, 0, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, this_date)).duration_record;
result = TRY(round_duration(vm, result.years, result.months, 0, 0, 0, 0, 0, 0, 0, 0, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, this_date)).duration_record;
}
// 16. Return ! CreateTemporalDuration(sign × result.[[Years]], sign × result.[[Months]], 0, 0, 0, 0, 0, 0, 0, 0).
return MUST(create_temporal_duration(global_object, sign * result.years, sign * result.months, 0, 0, 0, 0, 0, 0, 0, 0));
return MUST(create_temporal_duration(vm, sign * result.years, sign * result.months, 0, 0, 0, 0, 0, 0, 0, 0));
}
// 9.5.9 AddDurationToOrSubtractDurationFromPlainYearMonth ( operation, yearMonth, temporalDurationLike, options ), https://tc39.es/proposal-temporal/#sec-temporal-addtemporalplainyearmonth
ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(GlobalObject& global_object, ArithmeticOperation operation, PlainYearMonth& year_month, Value temporal_duration_like, Value options_value)
ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(VM& vm, ArithmeticOperation operation, PlainYearMonth& year_month, Value temporal_duration_like, Value options_value)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let duration be ? ToTemporalDuration(temporalDurationLike).
auto* duration = TRY(to_temporal_duration(global_object, temporal_duration_like));
auto* duration = TRY(to_temporal_duration(vm, temporal_duration_like));
// 2. If operation is subtract, then
if (operation == ArithmeticOperation::Subtract) {
// a. Set duration to ! CreateNegatedTemporalDuration(duration).
duration = create_negated_temporal_duration(global_object, *duration);
duration = create_negated_temporal_duration(vm, *duration);
}
// 3. Let balanceResult be ? BalanceDuration(duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "day").
auto balance_result = TRY(balance_duration(global_object, duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), Crypto::SignedBigInteger::create_from((i64)duration->nanoseconds()), "day"sv));
auto balance_result = TRY(balance_duration(vm, duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), Crypto::SignedBigInteger::create_from((i64)duration->nanoseconds()), "day"sv));
// 4. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, options_value));
auto* options = TRY(get_options_object(vm, options_value));
// 5. Let calendar be yearMonth.[[Calendar]].
auto& calendar = year_month.calendar();
// 6. Let fieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "monthCode"sv, "year"sv }));
// 7. Let fields be ? PrepareTemporalFields(yearMonth, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, year_month, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, year_month, field_names, Vector<StringView> {}));
// 8. Set sign to ! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], balanceResult.[[Days]], 0, 0, 0, 0, 0, 0).
auto sign = duration_sign(duration->years(), duration->months(), duration->weeks(), balance_result.days, 0, 0, 0, 0, 0, 0);
@ -344,10 +345,10 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
// 9. If sign < 0, then
if (sign < 0) {
// a. Let dayFromCalendar be ? CalendarDaysInMonth(calendar, yearMonth).
auto day_from_calendar = TRY(calendar_days_in_month(global_object, calendar, year_month));
auto day_from_calendar = TRY(calendar_days_in_month(vm, calendar, year_month));
// b. Let day be ? ToPositiveInteger(dayFromCalendar).
day = TRY(to_positive_integer(global_object, day_from_calendar));
day = TRY(to_positive_integer(vm, day_from_calendar));
}
// 10. Else,
else {
@ -359,10 +360,10 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
MUST(fields->create_data_property_or_throw(vm.names.day, Value(day)));
// 12. Let date be ? CalendarDateFromFields(calendar, fields).
auto* date = TRY(calendar_date_from_fields(global_object, calendar, *fields));
auto* date = TRY(calendar_date_from_fields(vm, calendar, *fields));
// 13. Let durationToAdd be ! CreateTemporalDuration(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], balanceResult.[[Days]], 0, 0, 0, 0, 0, 0).
auto* duration_to_add = MUST(create_temporal_duration(global_object, duration->years(), duration->months(), duration->weeks(), balance_result.days, 0, 0, 0, 0, 0, 0));
auto* duration_to_add = MUST(create_temporal_duration(vm, duration->years(), duration->months(), duration->weeks(), balance_result.days, 0, 0, 0, 0, 0, 0));
// 14. Let optionsCopy be OrdinaryObjectCreate(null).
auto* options_copy = Object::create(realm, nullptr);
@ -380,13 +381,13 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
}
// 17. Let addedDate be ? CalendarDateAdd(calendar, date, durationToAdd, options).
auto* added_date = TRY(calendar_date_add(global_object, calendar, date, *duration_to_add, options));
auto* added_date = TRY(calendar_date_add(vm, calendar, date, *duration_to_add, options));
// 18. Let addedDateFields be ? PrepareTemporalFields(addedDate, fieldNames, «»).
auto* added_date_fields = TRY(prepare_temporal_fields(global_object, *added_date, field_names, Vector<StringView> {}));
auto* added_date_fields = TRY(prepare_temporal_fields(vm, *added_date, field_names, Vector<StringView> {}));
// 19. Return ? CalendarYearMonthFromFields(calendar, addedDateFields, optionsCopy).
return calendar_year_month_from_fields(global_object, calendar, *added_date_fields, options_copy);
return calendar_year_month_from_fields(vm, calendar, *added_date_fields, options_copy);
}
}

View file

@ -40,14 +40,14 @@ struct ISOYearMonth {
u8 reference_iso_day;
};
ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(GlobalObject& global_object, Value item, Object const* options = nullptr);
ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(GlobalObject&, double year, double month, StringView overflow);
ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(VM&, Value item, Object const* options = nullptr);
ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(VM&, double year, double month, StringView overflow);
bool is_valid_iso_month(u8 month);
bool iso_year_month_within_limits(i32 year, u8 month);
ISOYearMonth balance_iso_year_month(double year, double month);
ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(GlobalObject&, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_year_month_to_string(GlobalObject&, PlainYearMonth&, StringView show_calendar);
ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject&, DifferenceOperation, PlainYearMonth&, Value other, Value options);
ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(GlobalObject&, ArithmeticOperation, PlainYearMonth&, Value temporal_duration_like, Value options_value);
ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM&, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_year_month_to_string(VM&, PlainYearMonth&, StringView show_calendar);
ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(VM&, DifferenceOperation, PlainYearMonth&, Value other, Value options);
ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(VM&, ArithmeticOperation, PlainYearMonth&, Value temporal_duration_like, Value options_value);
}

View file

@ -49,7 +49,6 @@ ThrowCompletionOr<Value> PlainYearMonthConstructor::call()
ThrowCompletionOr<Object*> PlainYearMonthConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto iso_year = vm.argument(0);
auto iso_month = vm.argument(1);
@ -63,16 +62,16 @@ ThrowCompletionOr<Object*> PlainYearMonthConstructor::construct(FunctionObject&
}
// 3. Let y be ? ToIntegerThrowOnInfinity(isoYear).
auto y = TRY(to_integer_throw_on_infinity(global_object, iso_year, ErrorType::TemporalInvalidPlainYearMonth));
auto y = TRY(to_integer_throw_on_infinity(vm, iso_year, ErrorType::TemporalInvalidPlainYearMonth));
// 4. Let m be ? ToIntegerThrowOnInfinity(isoMonth).
auto m = TRY(to_integer_throw_on_infinity(global_object, iso_month, ErrorType::TemporalInvalidPlainYearMonth));
auto m = TRY(to_integer_throw_on_infinity(vm, iso_month, ErrorType::TemporalInvalidPlainYearMonth));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, calendar_like));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, calendar_like));
// 6. Let ref be ? ToIntegerThrowOnInfinity(referenceISODay).
auto ref = TRY(to_integer_throw_on_infinity(global_object, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth));
auto ref = TRY(to_integer_throw_on_infinity(vm, reference_iso_day, ErrorType::TemporalInvalidPlainYearMonth));
// IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
// This does not change the exposed behavior as the call to CreateTemporalYearMonth will immediately check that these values are valid
@ -81,40 +80,40 @@ ThrowCompletionOr<Object*> PlainYearMonthConstructor::construct(FunctionObject&
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainYearMonth);
// 7. Return ? CreateTemporalYearMonth(y, m, calendar, ref, NewTarget).
return TRY(create_temporal_year_month(global_object, y, m, *calendar, ref, &new_target));
return TRY(create_temporal_year_month(vm, y, m, *calendar, ref, &new_target));
}
// 9.2.2 Temporal.PlainYearMonth.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.from
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthConstructor::from)
{
// 1. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
auto item = vm.argument(0);
// 2. If Type(item) is Object and item has an [[InitializedTemporalYearMonth]] internal slot, then
if (item.is_object() && is<PlainYearMonth>(item.as_object())) {
// a. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
auto& plain_year_month_object = static_cast<PlainYearMonth&>(item.as_object());
// b. Return ! CreateTemporalYearMonth(item.[[ISOYear]], item.[[ISOMonth]], item.[[Calendar]], item.[[ISODay]]).
return MUST(create_temporal_year_month(global_object, plain_year_month_object.iso_year(), plain_year_month_object.iso_month(), plain_year_month_object.calendar(), plain_year_month_object.iso_day()));
return MUST(create_temporal_year_month(vm, plain_year_month_object.iso_year(), plain_year_month_object.iso_month(), plain_year_month_object.calendar(), plain_year_month_object.iso_day()));
}
// 3. Return ? ToTemporalYearMonth(item, options).
return TRY(to_temporal_year_month(global_object, item, options));
return TRY(to_temporal_year_month(vm, item, options));
}
// 9.2.3 Temporal.PlainYearMonth.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.compare
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthConstructor::compare)
{
// 1. Set one to ? ToTemporalYearMonth(one).
auto* one = TRY(to_temporal_year_month(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_year_month(vm, vm.argument(0)));
// 2. Set two to ? ToTemporalYearMonth(one).
auto* two = TRY(to_temporal_year_month(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_year_month(vm, vm.argument(1)));
// 3. Return 𝔽(! CompareISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]])).
return Value(compare_iso_date(one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day()));

View file

@ -79,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::year_getter)
auto& calendar = year_month->calendar();
// 4. Return 𝔽(? CalendarYear(calendar, yearMonth)).
return Value(TRY(calendar_year(global_object, calendar, *year_month)));
return Value(TRY(calendar_year(vm, calendar, *year_month)));
}
// 9.3.5 get Temporal.PlainYearMonth.prototype.month, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.month
@ -93,7 +93,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::month_getter)
auto& calendar = year_month->calendar();
// 4. Return 𝔽(? CalendarMonth(calendar, yearMonth)).
return Value(TRY(calendar_month(global_object, calendar, *year_month)));
return Value(TRY(calendar_month(vm, calendar, *year_month)));
}
// 9.3.6 get Temporal.PlainYearMonth.prototype.monthCode, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.monthCode
@ -107,7 +107,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::month_code_getter)
auto& calendar = year_month->calendar();
// 4. Return ? CalendarMonthCode(calendar, yearMonth).
return js_string(vm, TRY(calendar_month_code(global_object, calendar, *year_month)));
return js_string(vm, TRY(calendar_month_code(vm, calendar, *year_month)));
}
// 9.3.7 get Temporal.PlainYearMonth.prototype.daysInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.daysinyear
@ -121,7 +121,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::days_in_year_getter)
auto& calendar = year_month->calendar();
// 4. Return ? CalendarDaysInYear(calendar, yearMonth).
return Value(TRY(calendar_days_in_year(global_object, calendar, *year_month)));
return Value(TRY(calendar_days_in_year(vm, calendar, *year_month)));
}
// 9.3.8 get Temporal.PlainYearMonth.prototype.daysInMonth, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.daysinmonth
@ -135,7 +135,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::days_in_month_getter)
auto& calendar = year_month->calendar();
// 4. Return ? CalendarDaysInMonth(calendar, yearMonth).
return Value(TRY(calendar_days_in_month(global_object, calendar, *year_month)));
return Value(TRY(calendar_days_in_month(vm, calendar, *year_month)));
}
// 9.3.9 get Temporal.PlainYearMonth.prototype.monthsInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.monthsinyear
@ -149,7 +149,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::months_in_year_getter)
auto& calendar = year_month->calendar();
// 4. Return ? CalendarMonthsInYear(calendar, yearMonth).
return Value(TRY(calendar_months_in_year(global_object, calendar, *year_month)));
return Value(TRY(calendar_months_in_year(vm, calendar, *year_month)));
}
// 9.3.10 get Temporal.PlainYearMonth.prototype.inLeapYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.inleapyear
@ -163,7 +163,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::in_leap_year_getter)
auto& calendar = year_month->calendar();
// 4. Return ? CalendarInLeapYear(calendar, yearMonth).
return Value(TRY(calendar_in_leap_year(global_object, calendar, *year_month)));
return Value(TRY(calendar_in_leap_year(vm, calendar, *year_month)));
}
// 15.6.9.2 get Temporal.PlainYearMonth.prototype.era, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.era
@ -177,7 +177,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::era_getter)
auto& calendar = plain_year_month->calendar();
// 4. Return ? CalendarEra(calendar, plainYearMonth).
return TRY(calendar_era(global_object, calendar, *plain_year_month));
return TRY(calendar_era(vm, calendar, *plain_year_month));
}
// 15.6.9.3 get Temporal.PlainYearMonth.prototype.eraYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.erayear
@ -191,7 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::era_year_getter)
auto& calendar = plain_year_month->calendar();
// 4. Return ? CalendarEraYear(calendar, plainYearMonth).
return TRY(calendar_era_year(global_object, calendar, *plain_year_month));
return TRY(calendar_era_year(vm, calendar, *plain_year_month));
}
// 9.3.11 Temporal.PlainYearMonth.prototype.with ( temporalYearMonthLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.with
@ -210,31 +210,31 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::with)
}
// 4. Perform ? RejectObjectWithCalendarOrTimeZone(temporalYearMonthLike).
TRY(reject_object_with_calendar_or_time_zone(global_object, temporal_year_month_like.as_object()));
TRY(reject_object_with_calendar_or_time_zone(vm, temporal_year_month_like.as_object()));
// 5. Let calendar be yearMonth.[[Calendar]].
auto& calendar = year_month->calendar();
// 6. Let fieldNames be ? CalendarFields(calendar, « "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "month"sv, "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "month"sv, "monthCode"sv, "year"sv }));
// 7. Let partialYearMonth be ? PrepareTemporalFields(temporalYearMonthLike, fieldNames, partial).
auto* partial_year_month = TRY(prepare_temporal_fields(global_object, temporal_year_month_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
auto* partial_year_month = TRY(prepare_temporal_fields(vm, temporal_year_month_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(yearMonth, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *year_month, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *year_month, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialYearMonth).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_year_month));
fields = TRY(calendar_merge_fields(vm, calendar, *fields, *partial_year_month));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
fields = TRY(prepare_temporal_fields(vm, *fields, field_names, Vector<StringView> {}));
// 12. Return ? CalendarYearMonthFromFields(calendar, fields, options).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields, options));
return TRY(calendar_year_month_from_fields(vm, calendar, *fields, options));
}
// 9.3.12 Temporal.PlainYearMonth.prototype.add ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.add
@ -248,7 +248,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::add)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromPlainYearMonth(add, yearMonth, temporalDurationLike, options).
return TRY(add_duration_to_or_subtract_duration_from_plain_year_month(global_object, ArithmeticOperation::Add, *year_month, temporal_duration_like, options));
return TRY(add_duration_to_or_subtract_duration_from_plain_year_month(vm, ArithmeticOperation::Add, *year_month, temporal_duration_like, options));
}
// 9.3.13 Temporal.PlainYearMonth.prototype.subtract ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.subtract
@ -262,7 +262,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::subtract)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromPlainYearMonth(add, yearMonth, temporalDurationLike, options).
return TRY(add_duration_to_or_subtract_duration_from_plain_year_month(global_object, ArithmeticOperation::Subtract, *year_month, temporal_duration_like, options));
return TRY(add_duration_to_or_subtract_duration_from_plain_year_month(vm, ArithmeticOperation::Subtract, *year_month, temporal_duration_like, options));
}
// 9.3.14 Temporal.PlainYearMonth.prototype.until ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.until
@ -276,7 +276,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::until)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainYearMonth(until, yearMonth, other, options).
return TRY(difference_temporal_plain_year_month(global_object, DifferenceOperation::Until, *year_month, other, options));
return TRY(difference_temporal_plain_year_month(vm, DifferenceOperation::Until, *year_month, other, options));
}
// 9.3.15 Temporal.PlainYearMonth.prototype.since ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.since
@ -290,7 +290,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::since)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalPlainYearMonth(since, yearMonth, other, options).
return TRY(difference_temporal_plain_year_month(global_object, DifferenceOperation::Since, *year_month, other, options));
return TRY(difference_temporal_plain_year_month(vm, DifferenceOperation::Since, *year_month, other, options));
}
// 9.3.16 Temporal.PlainYearMonth.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.equals
@ -301,7 +301,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::equals)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Set other to ? ToTemporalYearMonth(other).
auto* other = TRY(to_temporal_year_month(global_object, vm.argument(0)));
auto* other = TRY(to_temporal_year_month(vm, vm.argument(0)));
// 4. If yearMonth.[[ISOYear]] ≠ other.[[ISOYear]], return false.
if (year_month->iso_year() != other->iso_year())
@ -316,7 +316,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::equals)
return Value(false);
// 7. Return ? CalendarEquals(yearMonth.[[Calendar]], other.[[Calendar]]).
return Value(TRY(calendar_equals(global_object, year_month->calendar(), other->calendar())));
return Value(TRY(calendar_equals(vm, year_month->calendar(), other->calendar())));
}
// 9.3.17 Temporal.PlainYearMonth.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.tostring
@ -327,13 +327,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_string)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(0)));
auto* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let showCalendar be ? ToShowCalendarOption(options).
auto show_calendar = TRY(to_show_calendar_option(global_object, *options));
auto show_calendar = TRY(to_show_calendar_option(vm, *options));
// 5. Return ? TemporalYearMonthToString(yearMonth, showCalendar).
return js_string(vm, TRY(temporal_year_month_to_string(global_object, *year_month, show_calendar)));
return js_string(vm, TRY(temporal_year_month_to_string(vm, *year_month, show_calendar)));
}
// 9.3.18 Temporal.PlainYearMonth.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.tolocalestring
@ -345,7 +345,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_locale_string)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Return ? TemporalYearMonthToString(yearMonth, "auto").
return js_string(vm, TRY(temporal_year_month_to_string(global_object, *year_month, "auto"sv)));
return js_string(vm, TRY(temporal_year_month_to_string(vm, *year_month, "auto"sv)));
}
// 9.3.19 Temporal.PlainYearMonth.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.tojson
@ -356,7 +356,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_json)
auto* year_month = TRY(typed_this_object(global_object));
// 3. Return ? TemporalYearMonthToString(yearMonth, "auto").
return js_string(vm, TRY(temporal_year_month_to_string(global_object, *year_month, "auto"sv)));
return js_string(vm, TRY(temporal_year_month_to_string(vm, *year_month, "auto"sv)));
}
// 9.3.20 Temporal.PlainYearMonth.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.valueof
@ -387,25 +387,25 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
auto& calendar = year_month->calendar();
// 5. Let receiverFieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
auto receiver_field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
auto receiver_field_names = TRY(calendar_fields(vm, calendar, { "monthCode"sv, "year"sv }));
// 6. Let fields be ? PrepareTemporalFields(yearMonth, receiverFieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *year_month, receiver_field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *year_month, receiver_field_names, Vector<StringView> {}));
// 7. Let inputFieldNames be ? CalendarFields(calendar, « "day" »).
auto input_field_names = TRY(calendar_fields(global_object, calendar, { "day"sv }));
auto input_field_names = TRY(calendar_fields(vm, calendar, { "day"sv }));
// 8. Let inputFields be ? PrepareTemporalFields(item, inputFieldNames, «»).
auto* input_fields = TRY(prepare_temporal_fields(global_object, item.as_object(), input_field_names, Vector<StringView> {}));
auto* input_fields = TRY(prepare_temporal_fields(vm, item.as_object(), input_field_names, Vector<StringView> {}));
// 9. Let mergedFields be ? CalendarMergeFields(calendar, fields, inputFields).
auto* merged_fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *input_fields));
auto* merged_fields = TRY(calendar_merge_fields(vm, calendar, *fields, *input_fields));
// 10. Let mergedFieldNames be MergeLists(receiverFieldNames, inputFieldNames).
auto merged_field_names = merge_lists(receiver_field_names, input_field_names);
// 11. Set mergedFields to ? PrepareTemporalFields(mergedFields, mergedFieldNames, «»).
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
merged_fields = TRY(prepare_temporal_fields(vm, *merged_fields, merged_field_names, Vector<StringView> {}));
// 12. Let options be OrdinaryObjectCreate(null).
auto* options = Object::create(realm, nullptr);
@ -414,7 +414,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
MUST(options->create_data_property_or_throw(vm.names.overflow, js_string(vm, vm.names.reject.as_string())));
// 14. Return ? CalendarDateFromFields(calendar, mergedFields, options).
return TRY(calendar_date_from_fields(global_object, calendar, *merged_fields, options));
return TRY(calendar_date_from_fields(vm, calendar, *merged_fields, options));
}
// 9.3.22 Temporal.PlainYearMonth.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.getisofields

View file

@ -63,8 +63,11 @@ String default_time_zone()
}
// 11.6.1 CreateTemporalTimeZone ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaltimezone
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, String const& identifier, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%.
if (!new_target)
new_target = global_object.temporal_time_zone_constructor();
@ -73,7 +76,7 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_obje
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype));
// 3. Let offsetNanosecondsResult be Completion(ParseTimeZoneOffsetString(identifier)).
auto offset_nanoseconds_result = parse_time_zone_offset_string(global_object, identifier);
auto offset_nanoseconds_result = parse_time_zone_offset_string(vm, identifier);
// 4. If offsetNanosecondsResult is an abrupt completion, then
if (offset_nanoseconds_result.is_throw_completion()) {
@ -100,10 +103,8 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_obje
}
// 11.6.2 GetISOPartsFromEpoch ( epochNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-getisopartsfromepoch
ISODateTime get_iso_parts_from_epoch(GlobalObject& global_object, Crypto::SignedBigInteger const& epoch_nanoseconds)
ISODateTime get_iso_parts_from_epoch(VM& vm, Crypto::SignedBigInteger const& epoch_nanoseconds)
{
auto& vm = global_object.vm();
// 1. Assert: ! IsValidEpochNanoseconds((epochNanoseconds)) is true.
VERIFY(is_valid_epoch_nanoseconds(*js_bigint(vm, epoch_nanoseconds)));
@ -150,7 +151,7 @@ ISODateTime get_iso_parts_from_epoch(GlobalObject& global_object, Crypto::Signed
}
// 11.6.3 GetIANATimeZoneEpochValue ( timeZoneIdentifier, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneepochvalue
MarkedVector<BigInt*> get_iana_time_zone_epoch_value(GlobalObject& global_object, [[maybe_unused]] StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
MarkedVector<BigInt*> get_iana_time_zone_epoch_value(VM& vm, [[maybe_unused]] StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
{
// The implementation-defined abstract operation GetIANATimeZoneEpochValue takes arguments timeZoneIdentifier (a String), year (an integer), month (an integer between 1 and 12 inclusive), day (an integer between 1 and 31 inclusive), hour (an integer between 0 and 23 inclusive), minute (an integer between 0 and 59 inclusive), second (an integer between 0 and 59 inclusive), millisecond (an integer between 0 and 999 inclusive), microsecond (an integer between 0 and 999 inclusive), and nanosecond (an integer between 0 and 999 inclusive) and returns a List of BigInts.
// Each value in the returned List represents a number of nanoseconds since the Unix epoch in UTC that corresponds to the given ISO 8601 calendar date and wall-clock time in the IANA time zone identified by timeZoneIdentifier.
@ -158,9 +159,8 @@ MarkedVector<BigInt*> get_iana_time_zone_epoch_value(GlobalObject& global_object
// It is an error to call GetIANATimeZoneEpochValue with arguments such that IsValidISODate(year, month, day) is false.
// FIXME: Implement this properly for non-UTC timezones.
auto& vm = global_object.vm();
auto list = MarkedVector<BigInt*> { vm.heap() };
list.append(get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
list.append(get_epoch_from_iso_parts(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
return list;
}
@ -197,7 +197,7 @@ i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, Strin
}
// 11.6.5 GetIANATimeZoneNextTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezonenexttransition
BigInt* get_iana_time_zone_next_transition(GlobalObject&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
BigInt* get_iana_time_zone_next_transition(VM&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
{
// The implementation-defined abstract operation GetIANATimeZoneNextTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null.
// The returned value t represents the number of nanoseconds since the Unix epoch in UTC that corresponds to the first time zone transition after epochNanoseconds in the IANA time zone identified by timeZoneIdentifier. The operation returns null if no such transition exists for which t ≤ (nsMaxInstant).
@ -208,7 +208,7 @@ BigInt* get_iana_time_zone_next_transition(GlobalObject&, [[maybe_unused]] BigIn
}
// 11.6.6 GetIANATimeZonePreviousTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneprevioustransition
BigInt* get_iana_time_zone_previous_transition(GlobalObject&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
BigInt* get_iana_time_zone_previous_transition(VM&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
{
// The implementation-defined abstract operation GetIANATimeZonePreviousTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null.
// The returned value t represents the number of nanoseconds since the Unix epoch in UTC that corresponds to the last time zone transition before epochNanoseconds in the IANA time zone identified by timeZoneIdentifier. The operation returns null if no such transition exists for which t ≥ (nsMinInstant).
@ -262,10 +262,8 @@ bool is_valid_time_zone_numeric_utc_offset_syntax(String const& offset_string)
}
// 11.6.7 ParseTimeZoneOffsetString ( offsetString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetimezoneoffsetstring
ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject& global_object, String const& offset_string)
ThrowCompletionOr<double> parse_time_zone_offset_string(VM& vm, String const& offset_string)
{
auto& vm = global_object.vm();
// 1. Let parseResult be ParseText(StringToCodePoints(offsetString), TimeZoneNumericUTCOffset).
auto parse_result = parse_iso8601(Production::TimeZoneNumericUTCOffset, offset_string);
@ -418,9 +416,10 @@ String format_iso_time_zone_offset_string(double offset_nanoseconds)
}
// 11.6.10 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone
ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Value temporal_time_zone_like)
ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zone_like)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If Type(temporalTimeZoneLike) is Object, then
if (temporal_time_zone_like.is_object()) {
@ -448,7 +447,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
auto identifier = TRY(temporal_time_zone_like.to_string(global_object));
// 3. Let parseResult be ? ParseTemporalTimeZoneString(identifier).
auto parse_result = TRY(parse_temporal_time_zone_string(global_object, identifier));
auto parse_result = TRY(parse_temporal_time_zone_string(vm, identifier));
// 4. If parseResult.[[Name]] is not undefined, then
if (parse_result.name.has_value()) {
@ -466,21 +465,22 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
}
// c. Return ! CreateTemporalTimeZone(name).
return MUST(create_temporal_time_zone(global_object, name));
return MUST(create_temporal_time_zone(vm, name));
}
// 5. If parseResult.[[Z]] is true, return ! CreateTemporalTimeZone("UTC").
if (parse_result.z)
return MUST(create_temporal_time_zone(global_object, "UTC"sv));
return MUST(create_temporal_time_zone(vm, "UTC"sv));
// 6. Return ! CreateTemporalTimeZone(parseResult.[[OffsetString]]).
return MUST(create_temporal_time_zone(global_object, *parse_result.offset_string));
return MUST(create_temporal_time_zone(vm, *parse_result.offset_string));
}
// 11.6.11 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor
ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject& global_object, Value time_zone, Instant& instant)
ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, Instant& instant)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let getOffsetNanosecondsFor be ? GetMethod(timeZone, "getOffsetNanosecondsFor").
auto* get_offset_nanoseconds_for = TRY(time_zone.get_method(global_object, vm.names.getOffsetNanosecondsFor));
@ -508,50 +508,48 @@ ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject& global_object
}
// 11.6.12 BuiltinTimeZoneGetOffsetStringFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetoffsetstringfor
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(GlobalObject& global_object, Value time_zone, Instant& instant)
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM& vm, Value time_zone, Instant& instant)
{
// 1. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, time_zone, instant));
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
// 2. Return ! FormatTimeZoneOffsetString(offsetNanoseconds).
return format_time_zone_offset_string(offset_nanoseconds);
}
// 11.6.13 BuiltinTimeZoneGetPlainDateTimeFor ( timeZone, instant, calendar ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetplaindatetimefor
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(GlobalObject& global_object, Value time_zone, Instant& instant, Object& calendar)
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM& vm, Value time_zone, Instant& instant, Object& calendar)
{
// 1. Assert: instant has an [[InitializedTemporalInstant]] internal slot.
// 2. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, time_zone, instant));
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
// 3. Let result be ! GetISOPartsFromEpoch((instant.[[Nanoseconds]])).
auto result = get_iso_parts_from_epoch(global_object, instant.nanoseconds().big_integer());
auto result = get_iso_parts_from_epoch(vm, instant.nanoseconds().big_integer());
// 4. Set result to BalanceISODateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]] + offsetNanoseconds).
result = balance_iso_date_time(result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond + offset_nanoseconds);
// 5. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], calendar).
return create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar);
return create_temporal_date_time(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar);
}
// 11.6.14 BuiltinTimeZoneGetInstantFor ( timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetinstantfor
ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(GlobalObject& global_object, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(VM& vm, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
{
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
// 2. Let possibleInstants be ? GetPossibleInstantsFor(timeZone, dateTime).
auto possible_instants = TRY(get_possible_instants_for(global_object, time_zone, date_time));
auto possible_instants = TRY(get_possible_instants_for(vm, time_zone, date_time));
// 3. Return ? DisambiguatePossibleInstants(possibleInstants, timeZone, dateTime, disambiguation).
return disambiguate_possible_instants(global_object, possible_instants, time_zone, date_time, disambiguation);
return disambiguate_possible_instants(vm, possible_instants, time_zone, date_time, disambiguation);
}
// 11.6.15 DisambiguatePossibleInstants ( possibleInstants, timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-disambiguatepossibleinstants
ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_object, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM& vm, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
{
auto& vm = global_object.vm();
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
// 2. Let n be possibleInstants's length.
@ -594,7 +592,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
}
// 7. Let epochNanoseconds be GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
auto* epoch_nanoseconds = get_epoch_from_iso_parts(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
// 8. Let dayBeforeNs be epochNanoseconds - (nsPerDay).
auto* day_before_ns = js_bigint(vm, epoch_nanoseconds->big_integer().minus(ns_per_day_bigint));
@ -604,7 +602,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 10. Let dayBefore be ! CreateTemporalInstant(dayBeforeNs).
auto* day_before = MUST(create_temporal_instant(global_object, *day_before_ns));
auto* day_before = MUST(create_temporal_instant(vm, *day_before_ns));
// 11. Let dayAfterNs be epochNanoseconds + (nsPerDay).
auto* day_after_ns = js_bigint(vm, epoch_nanoseconds->big_integer().plus(ns_per_day_bigint));
@ -614,13 +612,13 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 13. Let dayAfter be ! CreateTemporalInstant(dayAfterNs).
auto* day_after = MUST(create_temporal_instant(global_object, *day_after_ns));
auto* day_after = MUST(create_temporal_instant(vm, *day_after_ns));
// 14. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore).
auto offset_before = TRY(get_offset_nanoseconds_for(global_object, time_zone, *day_before));
auto offset_before = TRY(get_offset_nanoseconds_for(vm, time_zone, *day_before));
// 15. Let offsetAfter be ? GetOffsetNanosecondsFor(timeZone, dayAfter).
auto offset_after = TRY(get_offset_nanoseconds_for(global_object, time_zone, *day_after));
auto offset_after = TRY(get_offset_nanoseconds_for(vm, time_zone, *day_after));
// 16. Let nanoseconds be offsetAfter - offsetBefore.
auto nanoseconds = offset_after - offset_before;
@ -628,13 +626,13 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
// 17. If disambiguation is "earlier", then
if (disambiguation == "earlier"sv) {
// a. Let earlier be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, undefined).
auto earlier = TRY(add_date_time(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, nullptr));
auto earlier = TRY(add_date_time(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, nullptr));
// b. Let earlierDateTime be ! CreateTemporalDateTime(earlier.[[Year]], earlier.[[Month]], earlier.[[Day]], earlier.[[Hour]], earlier.[[Minute]], earlier.[[Second]], earlier.[[Millisecond]], earlier.[[Microsecond]], earlier.[[Nanosecond]], dateTime.[[Calendar]]).
auto* earlier_date_time = MUST(create_temporal_date_time(global_object, earlier.year, earlier.month, earlier.day, earlier.hour, earlier.minute, earlier.second, earlier.millisecond, earlier.microsecond, earlier.nanosecond, date_time.calendar()));
auto* earlier_date_time = MUST(create_temporal_date_time(vm, earlier.year, earlier.month, earlier.day, earlier.hour, earlier.minute, earlier.second, earlier.millisecond, earlier.microsecond, earlier.nanosecond, date_time.calendar()));
// c. Set possibleInstants to ? GetPossibleInstantsFor(timeZone, earlierDateTime).
auto possible_instants_ = TRY(get_possible_instants_for(global_object, time_zone, *earlier_date_time));
auto possible_instants_ = TRY(get_possible_instants_for(vm, time_zone, *earlier_date_time));
// d. If possibleInstants is empty, throw a RangeError exception.
if (possible_instants_.is_empty())
@ -648,13 +646,13 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
VERIFY(disambiguation.is_one_of("compatible"sv, "later"sv));
// 19. Let later be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], 0, 0, 0, 0, 0, 0, 0, 0, 0, nanoseconds, undefined).
auto later = TRY(add_date_time(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, nanoseconds, nullptr));
auto later = TRY(add_date_time(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, nanoseconds, nullptr));
// 20. Let laterDateTime be ! CreateTemporalDateTime(later.[[Year]], later.[[Month]], later.[[Day]], later.[[Hour]], later.[[Minute]], later.[[Second]], later.[[Millisecond]], later.[[Microsecond]], later.[[Nanosecond]], dateTime.[[Calendar]]).
auto* later_date_time = MUST(create_temporal_date_time(global_object, later.year, later.month, later.day, later.hour, later.minute, later.second, later.millisecond, later.microsecond, later.nanosecond, date_time.calendar()));
auto* later_date_time = MUST(create_temporal_date_time(vm, later.year, later.month, later.day, later.hour, later.minute, later.second, later.millisecond, later.microsecond, later.nanosecond, date_time.calendar()));
// 21. Set possibleInstants to ? GetPossibleInstantsFor(timeZone, laterDateTime).
auto possible_instants_ = TRY(get_possible_instants_for(global_object, time_zone, *later_date_time));
auto possible_instants_ = TRY(get_possible_instants_for(vm, time_zone, *later_date_time));
// 22. Set n to possibleInstants's length.
n = possible_instants_.size();
@ -668,9 +666,10 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
}
// 11.6.16 GetPossibleInstantsFor ( timeZone, dateTime ), https://tc39.es/proposal-temporal/#sec-temporal-getpossibleinstantsfor
ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(GlobalObject& global_object, Value time_zone, PlainDateTime& date_time)
ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Value time_zone, PlainDateTime& date_time)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
@ -715,8 +714,11 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(GlobalObject
}
// 11.6.17 TimeZoneEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-timezoneequals
ThrowCompletionOr<bool> time_zone_equals(GlobalObject& global_object, Object& one, Object& two)
ThrowCompletionOr<bool> time_zone_equals(VM& vm, Object& one, Object& two)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If one and two are the same Object value, return true.
if (&one == &two)
return true;

View file

@ -38,23 +38,23 @@ private:
bool is_valid_time_zone_name(String const& time_zone);
String canonicalize_time_zone_name(String const& time_zone);
String default_time_zone();
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr);
ISODateTime get_iso_parts_from_epoch(GlobalObject&, Crypto::SignedBigInteger const& epoch_nanoseconds);
MarkedVector<BigInt*> get_iana_time_zone_epoch_value(GlobalObject&, StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM&, String const& identifier, FunctionObject const* new_target = nullptr);
ISODateTime get_iso_parts_from_epoch(VM&, Crypto::SignedBigInteger const& epoch_nanoseconds);
MarkedVector<BigInt*> get_iana_time_zone_epoch_value(VM&, StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier);
BigInt* get_iana_time_zone_next_transition(GlobalObject&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier);
BigInt* get_iana_time_zone_previous_transition(GlobalObject&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier);
ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject&, String const&);
BigInt* get_iana_time_zone_next_transition(VM&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier);
BigInt* get_iana_time_zone_previous_transition(VM&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier);
ThrowCompletionOr<double> parse_time_zone_offset_string(VM&, String const&);
String format_time_zone_offset_string(double offset_nanoseconds);
String format_iso_time_zone_offset_string(double offset_nanoseconds);
ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject&, Value temporal_time_zone_like);
ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject&, Value time_zone, Instant&);
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(GlobalObject&, Value time_zone, Instant&);
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(GlobalObject&, Value time_zone, Instant&, Object& calendar);
ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(GlobalObject&, Value time_zone, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject&, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(GlobalObject&, Value time_zone, PlainDateTime&);
ThrowCompletionOr<bool> time_zone_equals(GlobalObject&, Object& one, Object& two);
ThrowCompletionOr<Object*> to_temporal_time_zone(VM&, Value temporal_time_zone_like);
ThrowCompletionOr<double> get_offset_nanoseconds_for(VM&, Value time_zone, Instant&);
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM&, Value time_zone, Instant&);
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM&, Value time_zone, Instant&, Object& calendar);
ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(VM&, Value time_zone, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM&, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM&, Value time_zone, PlainDateTime&);
ThrowCompletionOr<bool> time_zone_equals(VM&, Object& one, Object& two);
bool is_valid_time_zone_numeric_utc_offset_syntax(String const&);

View file

@ -64,7 +64,7 @@ ThrowCompletionOr<Object*> TimeZoneConstructor::construct(FunctionObject& new_ta
}
// 5. Return ? CreateTemporalTimeZone(identifier, NewTarget).
return TRY(create_temporal_time_zone(global_object, identifier, &new_target));
return TRY(create_temporal_time_zone(vm, identifier, &new_target));
}
// 11.3.2 Temporal.TimeZone.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.from
@ -73,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZoneConstructor::from)
auto item = vm.argument(0);
// 1. Return ? ToTemporalTimeZone(item).
return TRY(to_temporal_time_zone(global_object, item));
return TRY(to_temporal_time_zone(vm, item));
}
}

View file

@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_nanoseconds_for)
auto* time_zone = TRY(typed_this_object(global_object));
// 3. Set instant to ? ToTemporalInstant(instant).
auto* instant = TRY(to_temporal_instant(global_object, vm.argument(0)));
auto* instant = TRY(to_temporal_instant(vm, vm.argument(0)));
// 4. If timeZone.[[OffsetNanoseconds]] is not undefined, return 𝔽(timeZone.[[OffsetNanoseconds]]).
if (time_zone->offset_nanoseconds().has_value())
@ -81,10 +81,10 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_string_for)
auto* time_zone = TRY(typed_this_object(global_object));
// 3. Set instant to ? ToTemporalInstant(instant).
auto* instant = TRY(to_temporal_instant(global_object, vm.argument(0)));
auto* instant = TRY(to_temporal_instant(vm, vm.argument(0)));
// 4. Return ? BuiltinTimeZoneGetOffsetStringFor(timeZone, instant).
auto offset_string = TRY(builtin_time_zone_get_offset_string_for(global_object, time_zone, *instant));
auto offset_string = TRY(builtin_time_zone_get_offset_string_for(vm, time_zone, *instant));
return js_string(vm, move(offset_string));
}
@ -96,13 +96,13 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_plain_date_time_for)
auto* time_zone = TRY(typed_this_object(global_object));
// 3. Set instant to ? ToTemporalInstant(instant).
auto* instant = TRY(to_temporal_instant(global_object, vm.argument(0)));
auto* instant = TRY(to_temporal_instant(vm, vm.argument(0)));
// 4. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, vm.argument(1)));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, vm.argument(1)));
// 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
return TRY(builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar));
return TRY(builtin_time_zone_get_plain_date_time_for(vm, time_zone, *instant, *calendar));
}
// 11.4.7 Temporal.TimeZone.prototype.getInstantFor ( dateTime [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getinstantfor
@ -113,16 +113,16 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_instant_for)
auto* time_zone = TRY(typed_this_object(global_object));
// 3. Set dateTime to ? ToTemporalDateTime(dateTime).
auto* date_time = TRY(to_temporal_date_time(global_object, vm.argument(0)));
auto* date_time = TRY(to_temporal_date_time(vm, vm.argument(0)));
// 4. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 5. Let disambiguation be ? ToTemporalDisambiguation(options).
auto disambiguation = TRY(to_temporal_disambiguation(global_object, options));
auto disambiguation = TRY(to_temporal_disambiguation(vm, options));
// 6. Return ? BuiltinTimeZoneGetInstantFor(timeZone, dateTime, disambiguation).
return TRY(builtin_time_zone_get_instant_for(global_object, time_zone, *date_time, disambiguation));
return TRY(builtin_time_zone_get_instant_for(vm, time_zone, *date_time, disambiguation));
}
// 11.4.8 Temporal.TimeZone.prototype.getPossibleInstantsFor ( dateTime ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getpossibleinstantsfor
@ -135,14 +135,14 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
auto* time_zone = TRY(typed_this_object(global_object));
// 3. Set dateTime to ? ToTemporalDateTime(dateTime).
auto* date_time = TRY(to_temporal_date_time(global_object, vm.argument(0)));
auto* date_time = TRY(to_temporal_date_time(vm, vm.argument(0)));
auto possible_epoch_nanoseconds = MarkedVector<BigInt*> { vm.heap() };
// 4. If timeZone.[[OffsetNanoseconds]] is not undefined, then
if (time_zone->offset_nanoseconds().has_value()) {
// a. Let epochNanoseconds be GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond());
auto* epoch_nanoseconds = get_epoch_from_iso_parts(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond());
// b. Let possibleEpochNanoseconds be « epochNanoseconds - (timeZone.[[OffsetNanoseconds]]) ».
// FIXME: Narrowing conversion from 'double' to 'i64'
@ -151,7 +151,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
// 5. Else,
else {
// a. Let possibleEpochNanoseconds be GetIANATimeZoneEpochValue(timeZone.[[Identifier]], dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
possible_epoch_nanoseconds = get_iana_time_zone_epoch_value(global_object, time_zone->identifier(), date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond());
possible_epoch_nanoseconds = get_iana_time_zone_epoch_value(vm, time_zone->identifier(), date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond());
}
// 6. Let possibleInstants be a new empty List.
@ -164,7 +164,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// b. Let instant be ! CreateTemporalInstant(epochNanoseconds).
auto* instant = MUST(create_temporal_instant(global_object, *epoch_nanoseconds));
auto* instant = MUST(create_temporal_instant(vm, *epoch_nanoseconds));
// c. Append instant to possibleInstants.
possible_instants.append(instant);
@ -182,21 +182,21 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_next_transition)
auto* time_zone = TRY(typed_this_object(global_object));
// 3. Set startingPoint to ? ToTemporalInstant(startingPoint).
auto* starting_point = TRY(to_temporal_instant(global_object, vm.argument(0)));
auto* starting_point = TRY(to_temporal_instant(vm, vm.argument(0)));
// 4. If timeZone.[[OffsetNanoseconds]] is not undefined, return null.
if (!time_zone->offset_nanoseconds().has_value())
return js_null();
// 5. Let transition be GetIANATimeZoneNextTransition(startingPoint.[[Nanoseconds]], timeZone.[[Identifier]]).
auto* transition = get_iana_time_zone_next_transition(global_object, starting_point->nanoseconds(), time_zone->identifier());
auto* transition = get_iana_time_zone_next_transition(vm, starting_point->nanoseconds(), time_zone->identifier());
// 6. If transition is null, return null.
if (!transition)
return js_null();
// 7. Return ! CreateTemporalInstant(transition).
return MUST(create_temporal_instant(global_object, *transition));
return MUST(create_temporal_instant(vm, *transition));
}
// 11.4.10 Temporal.TimeZone.prototype.getPreviousTransition ( startingPoint ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getprevioustransition
@ -207,21 +207,21 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_previous_transition)
auto* time_zone = TRY(typed_this_object(global_object));
// 3. Set startingPoint to ? ToTemporalInstant(startingPoint).
auto* starting_point = TRY(to_temporal_instant(global_object, vm.argument(0)));
auto* starting_point = TRY(to_temporal_instant(vm, vm.argument(0)));
// 4. If timeZone.[[OffsetNanoseconds]] is not undefined, return null.
if (!time_zone->offset_nanoseconds().has_value())
return js_null();
// 5. Let transition be GetIANATimeZonePreviousTransition(startingPoint.[[Nanoseconds]], timeZone.[[Identifier]]).
auto* transition = get_iana_time_zone_previous_transition(global_object, starting_point->nanoseconds(), time_zone->identifier());
auto* transition = get_iana_time_zone_previous_transition(vm, starting_point->nanoseconds(), time_zone->identifier());
// 6. If transition is null, return null.
if (!transition)
return js_null();
// 7. Return ! CreateTemporalInstant(transition).
return MUST(create_temporal_instant(global_object, *transition));
return MUST(create_temporal_instant(vm, *transition));
}
// 11.4.11 Temporal.TimeZone.prototype.toString ( ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.tostring

View file

@ -38,20 +38,18 @@ void ZonedDateTime::visit_edges(Cell::Visitor& visitor)
}
// 6.5.1 InterpretISODateTimeOffset ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, offsetBehaviour, offsetNanoseconds, timeZone, disambiguation, offsetOption, matchBehaviour ), https://tc39.es/proposal-temporal/#sec-temporal-interpretisodatetimeoffset
ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject& global_object, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, OffsetBehavior offset_behavior, double offset_nanoseconds, Value time_zone, StringView disambiguation, StringView offset_option, MatchBehavior match_behavior)
ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(VM& vm, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, OffsetBehavior offset_behavior, double offset_nanoseconds, Value time_zone, StringView disambiguation, StringView offset_option, MatchBehavior match_behavior)
{
auto& vm = global_object.vm();
// 1. Let calendar be ! GetISO8601Calendar().
auto* calendar = get_iso8601_calendar(global_object);
auto* calendar = get_iso8601_calendar(vm);
// 2. Let dateTime be ? CreateTemporalDateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar).
auto* date_time = TRY(create_temporal_date_time(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, *calendar));
auto* date_time = TRY(create_temporal_date_time(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, *calendar));
// 3. If offsetBehaviour is wall or offsetOption is "ignore", then
if (offset_behavior == OffsetBehavior::Wall || offset_option == "ignore"sv) {
// a. Let instant be ? BuiltinTimeZoneGetInstantFor(timeZone, dateTime, disambiguation).
auto* instant = TRY(builtin_time_zone_get_instant_for(global_object, time_zone, *date_time, disambiguation));
auto* instant = TRY(builtin_time_zone_get_instant_for(vm, time_zone, *date_time, disambiguation));
// b. Return instant.[[Nanoseconds]].
return &instant->nanoseconds();
@ -60,7 +58,7 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject& gl
// 4. If offsetBehaviour is exact or offsetOption is "use", then
if (offset_behavior == OffsetBehavior::Exact || offset_option == "use"sv) {
// a. Let epochNanoseconds be GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
auto* epoch_nanoseconds = get_epoch_from_iso_parts(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
// b. Set epochNanoseconds to epochNanoseconds - (offsetNanoseconds).
// FIXME: Narrowing conversion from 'double' to 'i64'
@ -82,12 +80,12 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject& gl
VERIFY(offset_option.is_one_of("prefer"sv, "reject"sv));
// 7. Let possibleInstants be ? GetPossibleInstantsFor(timeZone, dateTime).
auto possible_instants = TRY(get_possible_instants_for(global_object, time_zone, *date_time));
auto possible_instants = TRY(get_possible_instants_for(vm, time_zone, *date_time));
// 8. For each element candidate of possibleInstants, do
for (auto* candidate : possible_instants) {
// a. Let candidateNanoseconds be ? GetOffsetNanosecondsFor(timeZone, candidate).
auto candidate_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, time_zone, *candidate));
auto candidate_nanoseconds = TRY(get_offset_nanoseconds_for(vm, time_zone, *candidate));
// b. If candidateNanoseconds = offsetNanoseconds, then
if (candidate_nanoseconds == offset_nanoseconds) {
@ -113,16 +111,17 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject& gl
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidZonedDateTimeOffset);
// 10. Let instant be ? DisambiguatePossibleInstants(possibleInstants, timeZone, dateTime, disambiguation).
auto* instant = TRY(disambiguate_possible_instants(global_object, possible_instants, time_zone, *date_time, disambiguation));
auto* instant = TRY(disambiguate_possible_instants(vm, possible_instants, time_zone, *date_time, disambiguation));
// 11. Return instant.[[Nanoseconds]].
return &instant->nanoseconds();
}
// 6.5.2 ToTemporalZonedDateTime ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalzoneddatetime
ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& global_object, Value item, Object const* options)
ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item, Object const* options)
{
auto& vm = global_object.vm();
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If options is not present, set options to undefined.
// 2. Assert: Type(options) is Object or Undefined.
@ -149,10 +148,10 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
}
// b. Let calendar be ? GetTemporalCalendarWithISODefault(item).
calendar = TRY(get_temporal_calendar_with_iso_default(global_object, item_object));
calendar = TRY(get_temporal_calendar_with_iso_default(vm, item_object));
// c. Let fieldNames be ? CalendarFields(calendar, « "day", "hour", "microsecond", "millisecond", "minute", "month", "monthCode", "nanosecond", "second", "year" »).
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// d. Append "timeZone" to fieldNames.
field_names.append("timeZone");
@ -161,13 +160,13 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
field_names.append("offset");
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, « "timeZone" »).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> { "timeZone"sv }));
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> { "timeZone"sv }));
// g. Let timeZone be ! Get(fields, "timeZone").
auto time_zone_value = MUST(fields->get(vm.names.timeZone));
// h. Set timeZone to ? ToTemporalTimeZone(timeZone).
time_zone = TRY(to_temporal_time_zone(global_object, time_zone_value));
time_zone = TRY(to_temporal_time_zone(vm, time_zone_value));
// i. Let offsetString be ! Get(fields, "offset").
auto offset_string_value = MUST(fields->get(vm.names.offset));
@ -184,18 +183,18 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
}
// l. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
result = TRY(interpret_temporal_date_time_fields(global_object, *calendar, *fields, *options));
result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *options));
}
// 6. Else,
else {
// a. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// b. Let string be ? ToString(item).
auto string = TRY(item.to_string(global_object));
// c. Let result be ? ParseTemporalZonedDateTimeString(string).
auto parsed_result = TRY(parse_temporal_zoned_date_time_string(global_object, string));
auto parsed_result = TRY(parse_temporal_zoned_date_time_string(vm, string));
// NOTE: The ISODateTime struct inside parsed_result will be moved into `result` at the end of this path to avoid mismatching names.
// Thus, all remaining references to `result` in this path actually refers to `parsed_result`.
@ -231,13 +230,13 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
}
// j. Let timeZone be ! CreateTemporalTimeZone(timeZoneName).
time_zone = MUST(create_temporal_time_zone(global_object, *time_zone_name));
time_zone = MUST(create_temporal_time_zone(vm, *time_zone_name));
// k. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
auto temporal_calendar_like = parsed_result.date_time.calendar.has_value()
? js_string(vm, parsed_result.date_time.calendar.value())
: js_undefined();
calendar = TRY(to_temporal_calendar_with_iso_default(global_object, temporal_calendar_like));
calendar = TRY(to_temporal_calendar_with_iso_default(vm, temporal_calendar_like));
// l. Set matchBehaviour to match minutes.
match_behavior = MatchBehavior::MatchMinutes;
@ -252,25 +251,28 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
// 8. If offsetBehaviour is option, then
if (offset_behavior == OffsetBehavior::Option) {
// a. Set offsetNanoseconds to ? ParseTimeZoneOffsetString(offsetString).
offset_nanoseconds = TRY(parse_time_zone_offset_string(global_object, *offset_string));
offset_nanoseconds = TRY(parse_time_zone_offset_string(vm, *offset_string));
}
// 9. Let disambiguation be ? ToTemporalDisambiguation(options).
auto disambiguation = TRY(to_temporal_disambiguation(global_object, options));
auto disambiguation = TRY(to_temporal_disambiguation(vm, options));
// 10. Let offsetOption be ? ToTemporalOffset(options, "reject").
auto offset_option = TRY(to_temporal_offset(global_object, options, "reject"));
auto offset_option = TRY(to_temporal_offset(vm, options, "reject"));
// 11. Let epochNanoseconds be ? InterpretISODateTimeOffset(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], offsetBehaviour, offsetNanoseconds, timeZone, disambiguation, offsetOption, matchBehaviour).
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_nanoseconds, time_zone, disambiguation, offset_option, match_behavior));
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_nanoseconds, time_zone, disambiguation, offset_option, match_behavior));
// 12. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, *epoch_nanoseconds, *time_zone, *calendar));
return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, *time_zone, *calendar));
}
// 6.5.3 CreateTemporalZonedDateTime ( epochNanoseconds, timeZone, calendar [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalzoneddatetime
ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(GlobalObject& global_object, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target)
ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM& vm, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: ! IsValidEpochNanoseconds(epochNanoseconds) is true.
VERIFY(is_valid_epoch_nanoseconds(epoch_nanoseconds));
@ -289,8 +291,11 @@ ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(GlobalObject&
}
// 6.5.4 TemporalZonedDateTimeToString ( zonedDateTime, precision, showCalendar, showTimeZone, showOffset [ , increment, unit, roundingMode ] ), https://tc39.es/proposal-temporal/#sec-temporal-temporalzoneddatetimetostring
ThrowCompletionOr<String> temporal_zoned_date_time_to_string(GlobalObject& global_object, ZonedDateTime& zoned_date_time, Variant<StringView, u8> const& precision, StringView show_calendar, StringView show_time_zone, StringView show_offset, Optional<u64> increment, Optional<StringView> unit, Optional<StringView> rounding_mode)
ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM& vm, ZonedDateTime& zoned_date_time, Variant<StringView, u8> const& precision, StringView show_calendar, StringView show_time_zone, StringView show_offset, Optional<u64> increment, Optional<StringView> unit, Optional<StringView> rounding_mode)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If increment is not present, set increment to 1.
if (!increment.has_value())
increment = 1;
@ -304,22 +309,22 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(GlobalObject& globa
rounding_mode = "trunc"sv;
// 4. Let ns be ! RoundTemporalInstant(zonedDateTime.[[Nanoseconds]], increment, unit, roundingMode).
auto* ns = round_temporal_instant(global_object, zoned_date_time.nanoseconds(), *increment, *unit, *rounding_mode);
auto* ns = round_temporal_instant(vm, zoned_date_time.nanoseconds(), *increment, *unit, *rounding_mode);
// 5. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time.time_zone();
// 6. Let instant be ! CreateTemporalInstant(ns).
auto* instant = MUST(create_temporal_instant(global_object, *ns));
auto* instant = MUST(create_temporal_instant(vm, *ns));
// 7. Let isoCalendar be ! GetISO8601Calendar().
auto* iso_calendar = get_iso8601_calendar(global_object);
auto* iso_calendar = get_iso8601_calendar(vm);
// 8. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, isoCalendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, *iso_calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, *iso_calendar));
// 9. Let dateTimeString be ? TemporalDateTimeToString(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]], isoCalendar, precision, "never").
auto date_time_string = TRY(temporal_date_time_to_string(global_object, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), iso_calendar, precision, "never"sv));
auto date_time_string = TRY(temporal_date_time_to_string(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), iso_calendar, precision, "never"sv));
String offset_string;
@ -331,7 +336,7 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(GlobalObject& globa
// 11. Else,
else {
// a. Let offsetNs be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_ns = TRY(get_offset_nanoseconds_for(global_object, &time_zone, *instant));
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, &time_zone, *instant));
// b. Let offsetString be ! FormatISOTimeZoneOffsetString(offsetNs).
offset_string = format_iso_time_zone_offset_string(offset_ns);
@ -364,7 +369,7 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(GlobalObject& globa
}
// 6.5.5 AddZonedDateTime ( epochNanoseconds, timeZone, calendar, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-addzoneddatetime
ThrowCompletionOr<BigInt*> add_zoned_date_time(GlobalObject& global_object, BigInt const& epoch_nanoseconds, Value time_zone, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options)
ThrowCompletionOr<BigInt*> add_zoned_date_time(VM& vm, BigInt const& epoch_nanoseconds, Value time_zone, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options)
{
// 1. If options is not present, set options to undefined.
// 2. Assert: Type(options) is Object or Undefined.
@ -372,36 +377,36 @@ ThrowCompletionOr<BigInt*> add_zoned_date_time(GlobalObject& global_object, BigI
// 3. If all of years, months, weeks, and days are 0, then
if (years == 0 && months == 0 && weeks == 0 && days == 0) {
// a. Return ? AddInstant(epochNanoseconds, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
return add_instant(global_object, epoch_nanoseconds, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
return add_instant(vm, epoch_nanoseconds, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
// 4. Let instant be ! CreateTemporalInstant(epochNanoseconds).
auto* instant = MUST(create_temporal_instant(global_object, epoch_nanoseconds));
auto* instant = MUST(create_temporal_instant(vm, epoch_nanoseconds));
// 5. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, time_zone, *instant, calendar));
// 6. Let datePart be ! CreateTemporalDate(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], calendar).
auto* date_part = MUST(create_temporal_date(global_object, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), calendar));
auto* date_part = MUST(create_temporal_date(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), calendar));
// 7. Let dateDuration be ! CreateTemporalDuration(years, months, weeks, days, 0, 0, 0, 0, 0, 0).
auto* date_duration = MUST(create_temporal_duration(global_object, years, months, weeks, days, 0, 0, 0, 0, 0, 0));
auto* date_duration = MUST(create_temporal_duration(vm, years, months, weeks, days, 0, 0, 0, 0, 0, 0));
// 8. Let addedDate be ? CalendarDateAdd(calendar, datePart, dateDuration, options).
auto* added_date = TRY(calendar_date_add(global_object, calendar, date_part, *date_duration, options));
auto* added_date = TRY(calendar_date_add(vm, calendar, date_part, *date_duration, options));
// 9. Let intermediateDateTime be ? CreateTemporalDateTime(addedDate.[[ISOYear]], addedDate.[[ISOMonth]], addedDate.[[ISODay]], temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]], calendar).
auto* intermediate_date_time = TRY(create_temporal_date_time(global_object, added_date->iso_year(), added_date->iso_month(), added_date->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), calendar));
auto* intermediate_date_time = TRY(create_temporal_date_time(vm, added_date->iso_year(), added_date->iso_month(), added_date->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), calendar));
// 10. Let intermediateInstant be ? BuiltinTimeZoneGetInstantFor(timeZone, intermediateDateTime, "compatible").
auto* intermediate_instant = TRY(builtin_time_zone_get_instant_for(global_object, time_zone, *intermediate_date_time, "compatible"sv));
auto* intermediate_instant = TRY(builtin_time_zone_get_instant_for(vm, time_zone, *intermediate_date_time, "compatible"sv));
// 11. Return ? AddInstant(intermediateInstant.[[Nanoseconds]], hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
return add_instant(global_object, intermediate_instant->nanoseconds(), hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
return add_instant(vm, intermediate_instant->nanoseconds(), hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
// 6.5.6 DifferenceZonedDateTime ( ns1, ns2, timeZone, calendar, largestUnit, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencezoneddatetime
ThrowCompletionOr<DurationRecord> difference_zoned_date_time(GlobalObject& global_object, BigInt const& nanoseconds1, BigInt const& nanoseconds2, Object& time_zone, Object& calendar, StringView largest_unit, Object const& options)
ThrowCompletionOr<DurationRecord> difference_zoned_date_time(VM& vm, BigInt const& nanoseconds1, BigInt const& nanoseconds2, Object& time_zone, Object& calendar, StringView largest_unit, Object const& options)
{
// 1. If ns1 is ns2, then
if (nanoseconds1.big_integer() == nanoseconds2.big_integer()) {
@ -410,44 +415,43 @@ ThrowCompletionOr<DurationRecord> difference_zoned_date_time(GlobalObject& globa
}
// 2. Let startInstant be ! CreateTemporalInstant(ns1).
auto* start_instant = MUST(create_temporal_instant(global_object, nanoseconds1));
auto* start_instant = MUST(create_temporal_instant(vm, nanoseconds1));
// 3. Let startDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, startInstant, calendar).
auto* start_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *start_instant, calendar));
auto* start_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *start_instant, calendar));
// 4. Let endInstant be ! CreateTemporalInstant(ns2).
auto* end_instant = MUST(create_temporal_instant(global_object, nanoseconds2));
auto* end_instant = MUST(create_temporal_instant(vm, nanoseconds2));
// 5. Let endDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, endInstant, calendar).
auto* end_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *end_instant, calendar));
auto* end_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *end_instant, calendar));
// 6. Let dateDifference be ? DifferenceISODateTime(startDateTime.[[ISOYear]], startDateTime.[[ISOMonth]], startDateTime.[[ISODay]], startDateTime.[[ISOHour]], startDateTime.[[ISOMinute]], startDateTime.[[ISOSecond]], startDateTime.[[ISOMillisecond]], startDateTime.[[ISOMicrosecond]], startDateTime.[[ISONanosecond]], endDateTime.[[ISOYear]], endDateTime.[[ISOMonth]], endDateTime.[[ISODay]], endDateTime.[[ISOHour]], endDateTime.[[ISOMinute]], endDateTime.[[ISOSecond]], endDateTime.[[ISOMillisecond]], endDateTime.[[ISOMicrosecond]], endDateTime.[[ISONanosecond]], calendar, largestUnit, options).
auto date_difference = TRY(difference_iso_date_time(global_object, start_date_time->iso_year(), start_date_time->iso_month(), start_date_time->iso_day(), start_date_time->iso_hour(), start_date_time->iso_minute(), start_date_time->iso_second(), start_date_time->iso_millisecond(), start_date_time->iso_microsecond(), start_date_time->iso_nanosecond(), end_date_time->iso_year(), end_date_time->iso_month(), end_date_time->iso_day(), end_date_time->iso_hour(), end_date_time->iso_minute(), end_date_time->iso_second(), end_date_time->iso_millisecond(), end_date_time->iso_microsecond(), end_date_time->iso_nanosecond(), calendar, largest_unit, options));
auto date_difference = TRY(difference_iso_date_time(vm, start_date_time->iso_year(), start_date_time->iso_month(), start_date_time->iso_day(), start_date_time->iso_hour(), start_date_time->iso_minute(), start_date_time->iso_second(), start_date_time->iso_millisecond(), start_date_time->iso_microsecond(), start_date_time->iso_nanosecond(), end_date_time->iso_year(), end_date_time->iso_month(), end_date_time->iso_day(), end_date_time->iso_hour(), end_date_time->iso_minute(), end_date_time->iso_second(), end_date_time->iso_millisecond(), end_date_time->iso_microsecond(), end_date_time->iso_nanosecond(), calendar, largest_unit, options));
// 7. Let intermediateNs be ? AddZonedDateTime(ns1, timeZone, calendar, dateDifference.[[Years]], dateDifference.[[Months]], dateDifference.[[Weeks]], 0, 0, 0, 0, 0, 0, 0).
auto* intermediate_ns = TRY(add_zoned_date_time(global_object, nanoseconds1, &time_zone, calendar, date_difference.years, date_difference.months, date_difference.weeks, 0, 0, 0, 0, 0, 0, 0));
auto* intermediate_ns = TRY(add_zoned_date_time(vm, nanoseconds1, &time_zone, calendar, date_difference.years, date_difference.months, date_difference.weeks, 0, 0, 0, 0, 0, 0, 0));
// 8. Let timeRemainderNs be ns2 - intermediateNs.
auto time_remainder_ns = nanoseconds2.big_integer().minus(intermediate_ns->big_integer());
// 9. Let intermediate be ! CreateTemporalZonedDateTime(intermediateNs, timeZone, calendar).
auto* intermediate = MUST(create_temporal_zoned_date_time(global_object, *intermediate_ns, time_zone, calendar));
auto* intermediate = MUST(create_temporal_zoned_date_time(vm, *intermediate_ns, time_zone, calendar));
// 10. Let result be ? NanosecondsToDays(timeRemainderNs, intermediate).
auto result = TRY(nanoseconds_to_days(global_object, time_remainder_ns, intermediate));
auto result = TRY(nanoseconds_to_days(vm, time_remainder_ns, intermediate));
// 11. Let timeDifference be ! BalanceDuration(0, 0, 0, 0, 0, 0, result.[[Nanoseconds]], "hour").
auto time_difference = MUST(balance_duration(global_object, 0, 0, 0, 0, 0, 0, result.nanoseconds, "hour"sv));
auto time_difference = MUST(balance_duration(vm, 0, 0, 0, 0, 0, 0, result.nanoseconds, "hour"sv));
// 12. Return ! CreateDurationRecord(dateDifference.[[Years]], dateDifference.[[Months]], dateDifference.[[Weeks]], result.[[Days]], timeDifference.[[Hours]], timeDifference.[[Minutes]], timeDifference.[[Seconds]], timeDifference.[[Milliseconds]], timeDifference.[[Microseconds]], timeDifference.[[Nanoseconds]]).
return create_duration_record(date_difference.years, date_difference.months, date_difference.weeks, result.days, time_difference.hours, time_difference.minutes, time_difference.seconds, time_difference.milliseconds, time_difference.microseconds, time_difference.nanoseconds);
}
// 6.5.7 NanosecondsToDays ( nanoseconds, relativeTo ), https://tc39.es/proposal-temporal/#sec-temporal-nanosecondstodays
ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& global_object, Crypto::SignedBigInteger nanoseconds, Value relative_to_value)
ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::SignedBigInteger nanoseconds, Value relative_to_value)
{
auto& vm = global_object.vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let dayLengthNs be nsPerDay.
auto day_length_ns = ns_per_day_bigint;
@ -477,10 +481,10 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
auto& start_ns = relative_to.nanoseconds().big_integer();
// 6. Let startInstant be ! CreateTemporalInstant((startNs)).
auto* start_instant = MUST(create_temporal_instant(global_object, *js_bigint(vm, start_ns)));
auto* start_instant = MUST(create_temporal_instant(vm, *js_bigint(vm, start_ns)));
// 7. Let startDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], startInstant, relativeTo.[[Calendar]]).
auto* start_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &relative_to.time_zone(), *start_instant, relative_to.calendar()));
auto* start_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &relative_to.time_zone(), *start_instant, relative_to.calendar()));
// 8. Let endNs be startNs + nanoseconds.
auto end_ns = start_ns.plus(nanoseconds);
@ -492,19 +496,19 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 10. Let endInstant be ! CreateTemporalInstant((endNs)).
auto* end_instant = MUST(create_temporal_instant(global_object, *end_ns_bigint));
auto* end_instant = MUST(create_temporal_instant(vm, *end_ns_bigint));
// 11. Let endDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], endInstant, relativeTo.[[Calendar]]).
auto* end_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &relative_to.time_zone(), *end_instant, relative_to.calendar()));
auto* end_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &relative_to.time_zone(), *end_instant, relative_to.calendar()));
// 12. Let dateDifference be ? DifferenceISODateTime(startDateTime.[[ISOYear]], startDateTime.[[ISOMonth]], startDateTime.[[ISODay]], startDateTime.[[ISOHour]], startDateTime.[[ISOMinute]], startDateTime.[[ISOSecond]], startDateTime.[[ISOMillisecond]], startDateTime.[[ISOMicrosecond]], startDateTime.[[ISONanosecond]], endDateTime.[[ISOYear]], endDateTime.[[ISOMonth]], endDateTime.[[ISODay]], endDateTime.[[ISOHour]], endDateTime.[[ISOMinute]], endDateTime.[[ISOSecond]], endDateTime.[[ISOMillisecond]], endDateTime.[[ISOMicrosecond]], endDateTime.[[ISONanosecond]], relativeTo.[[Calendar]], "day", OrdinaryObjectCreate(null)).
auto date_difference = TRY(difference_iso_date_time(global_object, start_date_time->iso_year(), start_date_time->iso_month(), start_date_time->iso_day(), start_date_time->iso_hour(), start_date_time->iso_minute(), start_date_time->iso_second(), start_date_time->iso_millisecond(), start_date_time->iso_microsecond(), start_date_time->iso_nanosecond(), end_date_time->iso_year(), end_date_time->iso_month(), end_date_time->iso_day(), end_date_time->iso_hour(), end_date_time->iso_minute(), end_date_time->iso_second(), end_date_time->iso_millisecond(), end_date_time->iso_microsecond(), end_date_time->iso_nanosecond(), relative_to.calendar(), "day"sv, *Object::create(realm, nullptr)));
auto date_difference = TRY(difference_iso_date_time(vm, start_date_time->iso_year(), start_date_time->iso_month(), start_date_time->iso_day(), start_date_time->iso_hour(), start_date_time->iso_minute(), start_date_time->iso_second(), start_date_time->iso_millisecond(), start_date_time->iso_microsecond(), start_date_time->iso_nanosecond(), end_date_time->iso_year(), end_date_time->iso_month(), end_date_time->iso_day(), end_date_time->iso_hour(), end_date_time->iso_minute(), end_date_time->iso_second(), end_date_time->iso_millisecond(), end_date_time->iso_microsecond(), end_date_time->iso_nanosecond(), relative_to.calendar(), "day"sv, *Object::create(realm, nullptr)));
// 13. Let days be dateDifference.[[Days]].
auto days = date_difference.days;
// 14. Let intermediateNs be (? AddZonedDateTime((startNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, 0, 0, 0, 0, 0, 0)).
auto intermediate_ns = TRY(add_zoned_date_time(global_object, *js_bigint(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
auto intermediate_ns = TRY(add_zoned_date_time(vm, *js_bigint(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
// 15. If sign is 1, then
if (sign == 1) {
@ -514,7 +518,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
days--;
// ii. Set intermediateNs to (? AddZonedDateTime((startNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, 0, 0, 0, 0, 0, 0)).
intermediate_ns = TRY(add_zoned_date_time(global_object, *js_bigint(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
intermediate_ns = TRY(add_zoned_date_time(vm, *js_bigint(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
}
}
@ -525,7 +529,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
// 18. Repeat, while done is false,
while (true) {
// a. Let oneDayFartherNs be (? AddZonedDateTime((intermediateNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, sign, 0, 0, 0, 0, 0, 0)).
auto one_day_farther_ns = TRY(add_zoned_date_time(global_object, *js_bigint(vm, intermediate_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, sign, 0, 0, 0, 0, 0, 0))->big_integer();
auto one_day_farther_ns = TRY(add_zoned_date_time(vm, *js_bigint(vm, intermediate_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, sign, 0, 0, 0, 0, 0, 0))->big_integer();
// b. Set dayLengthNs to oneDayFartherNs - intermediateNs.
day_length_ns = one_day_farther_ns.minus(intermediate_ns);
@ -553,72 +557,70 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
}
// 6.5.8 DifferenceTemporalZonedDateTime ( operation, zonedDateTime, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalzoneddatetime
ThrowCompletionOr<Duration*> difference_temporal_zoned_date_time(GlobalObject& global_object, DifferenceOperation operation, ZonedDateTime& zoned_date_time, Value other_value, Value options_value)
ThrowCompletionOr<Duration*> difference_temporal_zoned_date_time(VM& vm, DifferenceOperation operation, ZonedDateTime& zoned_date_time, Value other_value, Value options_value)
{
auto& vm = global_object.vm();
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
// 2. Set other to ? ToTemporalZonedDateTime(other).
auto* other = TRY(to_temporal_zoned_date_time(global_object, other_value));
auto* other = TRY(to_temporal_zoned_date_time(vm, other_value));
// 3. If ? CalendarEquals(zonedDateTime.[[Calendar]], other.[[Calendar]]) is false, then
if (!TRY(calendar_equals(global_object, zoned_date_time.calendar(), other->calendar()))) {
if (!TRY(calendar_equals(vm, zoned_date_time.calendar(), other->calendar()))) {
// a. Throw a RangeError exception.
return vm.throw_completion<RangeError>(ErrorType::TemporalDifferentCalendars);
}
// 4. Let settings be ? GetDifferenceSettings(operation, options, datetime, « », "nanosecond", "hour").
auto settings = TRY(get_difference_settings(global_object, operation, options_value, UnitGroup::DateTime, {}, { "nanosecond"sv }, "hour"sv));
auto settings = TRY(get_difference_settings(vm, operation, options_value, UnitGroup::DateTime, {}, { "nanosecond"sv }, "hour"sv));
// 5. If settings.[[LargestUnit]] is not one of "year", "month", "week", or "day", then
if (!settings.largest_unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv)) {
// a. Let differenceNs be ! DifferenceInstant(zonedDateTime.[[Nanoseconds]], other.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]]).
auto* difference_ns = difference_instant(global_object, zoned_date_time.nanoseconds(), other->nanoseconds(), settings.rounding_increment, settings.smallest_unit, settings.rounding_mode);
auto* difference_ns = difference_instant(vm, zoned_date_time.nanoseconds(), other->nanoseconds(), settings.rounding_increment, settings.smallest_unit, settings.rounding_mode);
// b. Assert: The following steps cannot fail due to overflow in the Number domain because abs(differenceNs) ≤ 2 × nsMaxInstant.
// c. Let balanceResult be ! BalanceDuration(0, 0, 0, 0, 0, 0, differenceNs, settings.[[LargestUnit]]).
auto balance_result = MUST(balance_duration(global_object, 0, 0, 0, 0, 0, 0, difference_ns->big_integer(), settings.largest_unit));
auto balance_result = MUST(balance_duration(vm, 0, 0, 0, 0, 0, 0, difference_ns->big_integer(), settings.largest_unit));
// d. Return ! CreateTemporalDuration(0, 0, 0, 0, sign × balanceResult.[[Hours]], sign × balanceResult.[[Minutes]], sign × balanceResult.[[Seconds]], sign × balanceResult.[[Milliseconds]], sign × balanceResult.[[Microseconds]], sign × balanceResult.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, 0, 0, 0, 0, sign * balance_result.hours, sign * balance_result.minutes, sign * balance_result.seconds, sign * balance_result.milliseconds, sign * balance_result.microseconds, sign * balance_result.nanoseconds));
return MUST(create_temporal_duration(vm, 0, 0, 0, 0, sign * balance_result.hours, sign * balance_result.minutes, sign * balance_result.seconds, sign * balance_result.milliseconds, sign * balance_result.microseconds, sign * balance_result.nanoseconds));
}
// 6. If ? TimeZoneEquals(zonedDateTime.[[TimeZone]], other.[[TimeZone]]) is false, then
if (!TRY(time_zone_equals(global_object, zoned_date_time.time_zone(), other->time_zone()))) {
if (!TRY(time_zone_equals(vm, zoned_date_time.time_zone(), other->time_zone()))) {
// a. Throw a RangeError exception.
return vm.throw_completion<RangeError>(ErrorType::TemporalDifferentTimeZones);
}
// 7. Let untilOptions be ? MergeLargestUnitOption(settings.[[Options]], settings.[[LargestUnit]]).
auto* until_options = TRY(merge_largest_unit_option(global_object, settings.options, settings.largest_unit));
auto* until_options = TRY(merge_largest_unit_option(vm, settings.options, settings.largest_unit));
// 8. Let difference be ? DifferenceZonedDateTime(zonedDateTime.[[Nanoseconds]], other.[[Nanoseconds]], zonedDateTime.[[TimeZone]], zonedDateTime.[[Calendar]], settings.[[LargestUnit]], untilOptions).
auto difference = TRY(difference_zoned_date_time(global_object, zoned_date_time.nanoseconds(), other->nanoseconds(), zoned_date_time.time_zone(), zoned_date_time.calendar(), settings.largest_unit, *until_options));
auto difference = TRY(difference_zoned_date_time(vm, zoned_date_time.nanoseconds(), other->nanoseconds(), zoned_date_time.time_zone(), zoned_date_time.calendar(), settings.largest_unit, *until_options));
// 9. Let roundResult be (? RoundDuration(difference.[[Years]], difference.[[Months]], difference.[[Weeks]], difference.[[Days]], difference.[[Hours]], difference.[[Minutes]], difference.[[Seconds]], difference.[[Milliseconds]], difference.[[Microseconds]], difference.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]], zonedDateTime)).[[DurationRecord]].
auto round_result = TRY(round_duration(global_object, difference.years, difference.months, difference.weeks, difference.days, difference.hours, difference.minutes, difference.seconds, difference.milliseconds, difference.microseconds, difference.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, &zoned_date_time)).duration_record;
auto round_result = TRY(round_duration(vm, difference.years, difference.months, difference.weeks, difference.days, difference.hours, difference.minutes, difference.seconds, difference.milliseconds, difference.microseconds, difference.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, &zoned_date_time)).duration_record;
// 10. Let result be ? AdjustRoundedDurationDays(roundResult.[[Years]], roundResult.[[Months]], roundResult.[[Weeks]], roundResult.[[Days]], roundResult.[[Hours]], roundResult.[[Minutes]], roundResult.[[Seconds]], roundResult.[[Milliseconds]], roundResult.[[Microseconds]], roundResult.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]], zonedDateTime).
auto result = TRY(adjust_rounded_duration_days(global_object, round_result.years, round_result.months, round_result.weeks, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, round_result.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, &zoned_date_time));
auto result = TRY(adjust_rounded_duration_days(vm, round_result.years, round_result.months, round_result.weeks, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, round_result.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, &zoned_date_time));
// 11. Return ! CreateTemporalDuration(sign × result.[[Years]], sign × result.[[Months]], sign × result.[[Weeks]], sign × result.[[Days]], sign × result.[[Hours]], sign × result.[[Minutes]], sign × result.[[Seconds]], sign × result.[[Milliseconds]], sign × result.[[Microseconds]], sign × result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, sign * result.years, sign * result.months, sign * result.weeks, sign * result.days, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
return MUST(create_temporal_duration(vm, sign * result.years, sign * result.months, sign * result.weeks, sign * result.days, sign * result.hours, sign * result.minutes, sign * result.seconds, sign * result.milliseconds, sign * result.microseconds, sign * result.nanoseconds));
}
// 6.5.9 AddDurationToOrSubtractDurationFromZonedDateTime ( operation, zonedDateTime, temporalDurationLike, options ), https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoOrsubtractdurationfromzoneddatetime
ThrowCompletionOr<ZonedDateTime*> add_duration_to_or_subtract_duration_from_zoned_date_time(GlobalObject& global_object, ArithmeticOperation operation, ZonedDateTime& zoned_date_time, Value temporal_duration_like, Value options_value)
ThrowCompletionOr<ZonedDateTime*> add_duration_to_or_subtract_duration_from_zoned_date_time(VM& vm, ArithmeticOperation operation, ZonedDateTime& zoned_date_time, Value temporal_duration_like, Value options_value)
{
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == ArithmeticOperation::Subtract ? -1 : 1;
// 2. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
auto duration = TRY(to_temporal_duration_record(vm, temporal_duration_like));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, options_value));
auto* options = TRY(get_options_object(vm, options_value));
// 4. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time.time_zone();
@ -627,10 +629,10 @@ ThrowCompletionOr<ZonedDateTime*> add_duration_to_or_subtract_duration_from_zone
auto& calendar = zoned_date_time.calendar();
// 6. Let epochNanoseconds be ? AddZonedDateTime(zonedDateTime.[[Nanoseconds]], timeZone, calendar, sign × duration.[[Years]], sign × duration.[[Months]], sign × duration.[[Weeks]], sign × duration.[[Days]], sign × duration.[[Hours]], sign × duration.[[Minutes]], sign × duration.[[Seconds]], sign × duration.[[Milliseconds]], sign × duration.[[Microseconds]], sign × duration.[[Nanoseconds]], options).
auto* epoch_nanoseconds = TRY(add_zoned_date_time(global_object, zoned_date_time.nanoseconds(), &time_zone, calendar, sign * duration.years, sign * duration.months, sign * duration.weeks, sign * duration.days, sign * duration.hours, sign * duration.minutes, sign * duration.seconds, sign * duration.milliseconds, sign * duration.microseconds, sign * duration.nanoseconds, options));
auto* epoch_nanoseconds = TRY(add_zoned_date_time(vm, zoned_date_time.nanoseconds(), &time_zone, calendar, sign * duration.years, sign * duration.months, sign * duration.weeks, sign * duration.days, sign * duration.hours, sign * duration.minutes, sign * duration.seconds, sign * duration.milliseconds, sign * duration.microseconds, sign * duration.nanoseconds, options));
// 7. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, *epoch_nanoseconds, time_zone, calendar));
return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone, calendar));
}
}

View file

@ -50,14 +50,14 @@ enum class MatchBehavior {
MatchMinutes,
};
ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, OffsetBehavior offset_behavior, double offset_nanoseconds, Value time_zone, StringView disambiguation, StringView offset_option, MatchBehavior match_behavior);
ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject&, Value item, Object const* options = nullptr);
ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(GlobalObject&, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_zoned_date_time_to_string(GlobalObject&, ZonedDateTime& zoned_date_time, Variant<StringView, u8> const& precision, StringView show_calendar, StringView show_time_zone, StringView show_offset, Optional<u64> increment = {}, Optional<StringView> unit = {}, Optional<StringView> rounding_mode = {});
ThrowCompletionOr<BigInt*> add_zoned_date_time(GlobalObject&, BigInt const& epoch_nanoseconds, Value time_zone, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options = nullptr);
ThrowCompletionOr<DurationRecord> difference_zoned_date_time(GlobalObject&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, Object& time_zone, Object& calendar, StringView largest_unit, Object const& options);
ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject&, Crypto::SignedBigInteger nanoseconds, Value relative_to);
ThrowCompletionOr<Duration*> difference_temporal_zoned_date_time(GlobalObject&, DifferenceOperation, ZonedDateTime&, Value other, Value options);
ThrowCompletionOr<ZonedDateTime*> add_duration_to_or_subtract_duration_from_zoned_date_time(GlobalObject&, ArithmeticOperation, ZonedDateTime&, Value temporal_duration_like, Value options_value);
ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(VM&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, OffsetBehavior offset_behavior, double offset_nanoseconds, Value time_zone, StringView disambiguation, StringView offset_option, MatchBehavior match_behavior);
ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM&, Value item, Object const* options = nullptr);
ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM&, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM&, ZonedDateTime& zoned_date_time, Variant<StringView, u8> const& precision, StringView show_calendar, StringView show_time_zone, StringView show_offset, Optional<u64> increment = {}, Optional<StringView> unit = {}, Optional<StringView> rounding_mode = {});
ThrowCompletionOr<BigInt*> add_zoned_date_time(VM&, BigInt const& epoch_nanoseconds, Value time_zone, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options = nullptr);
ThrowCompletionOr<DurationRecord> difference_zoned_date_time(VM&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, Object& time_zone, Object& calendar, StringView largest_unit, Object const& options);
ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM&, Crypto::SignedBigInteger nanoseconds, Value relative_to);
ThrowCompletionOr<Duration*> difference_temporal_zoned_date_time(VM&, DifferenceOperation, ZonedDateTime&, Value other, Value options);
ThrowCompletionOr<ZonedDateTime*> add_duration_to_or_subtract_duration_from_zoned_date_time(VM&, ArithmeticOperation, ZonedDateTime&, Value temporal_duration_like, Value options_value);
}

View file

@ -61,20 +61,20 @@ ThrowCompletionOr<Object*> ZonedDateTimeConstructor::construct(FunctionObject& n
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
// 4. Let timeZone be ? ToTemporalTimeZone(timeZoneLike).
auto* time_zone = TRY(to_temporal_time_zone(global_object, vm.argument(1)));
auto* time_zone = TRY(to_temporal_time_zone(vm, vm.argument(1)));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, vm.argument(2)));
auto* calendar = TRY(to_temporal_calendar_with_iso_default(vm, vm.argument(2)));
// 6. Return ? CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar, NewTarget).
return TRY(create_temporal_zoned_date_time(global_object, *epoch_nanoseconds, *time_zone, *calendar, &new_target));
return TRY(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, *time_zone, *calendar, &new_target));
}
// 6.2.2 Temporal.ZonedDateTime.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.from
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimeConstructor::from)
{
// 1. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
auto const* options = TRY(get_options_object(vm, vm.argument(1)));
auto item = vm.argument(0);
@ -83,30 +83,30 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimeConstructor::from)
auto& item_object = static_cast<ZonedDateTime&>(item.as_object());
// a. Perform ? ToTemporalOverflow(options).
(void)TRY(to_temporal_overflow(global_object, options));
(void)TRY(to_temporal_overflow(vm, options));
// b. Perform ? ToTemporalDisambiguation(options).
(void)TRY(to_temporal_disambiguation(global_object, options));
(void)TRY(to_temporal_disambiguation(vm, options));
// c. Perform ? ToTemporalOffset(options, "reject").
(void)TRY(to_temporal_offset(global_object, options, "reject"));
(void)TRY(to_temporal_offset(vm, options, "reject"));
// d. Return ! CreateTemporalZonedDateTime(item.[[Nanoseconds]], item.[[TimeZone]], item.[[Calendar]]).
return MUST(create_temporal_zoned_date_time(global_object, item_object.nanoseconds(), item_object.time_zone(), item_object.calendar()));
return MUST(create_temporal_zoned_date_time(vm, item_object.nanoseconds(), item_object.time_zone(), item_object.calendar()));
}
// 3. Return ? ToTemporalZonedDateTime(item, options).
return TRY(to_temporal_zoned_date_time(global_object, item, options));
return TRY(to_temporal_zoned_date_time(vm, item, options));
}
// 6.2.3 Temporal.ZonedDateTime.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.compare
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimeConstructor::compare)
{
// 1. Set one to ? ToTemporalZonedDateTime(one).
auto* one = TRY(to_temporal_zoned_date_time(global_object, vm.argument(0)));
auto* one = TRY(to_temporal_zoned_date_time(vm, vm.argument(0)));
// 2. Set two to ? ToTemporalZonedDateTime(two).
auto* two = TRY(to_temporal_zoned_date_time(global_object, vm.argument(1)));
auto* two = TRY(to_temporal_zoned_date_time(vm, vm.argument(1)));
// 3. Return 𝔽(! CompareEpochNanoseconds(one.[[Nanoseconds]], two.[[Nanoseconds]])).
return Value(compare_epoch_nanoseconds(one->nanoseconds(), two->nanoseconds()));

View file

@ -123,16 +123,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::year_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarYear(calendar, temporalDateTime).
return Value(TRY(calendar_year(global_object, calendar, *temporal_date_time)));
return Value(TRY(calendar_year(vm, calendar, *temporal_date_time)));
}
// 6.3.6 get Temporal.ZonedDateTime.prototype.month, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.month
@ -146,16 +146,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::month_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarMonth(calendar, temporalDateTime).
return Value(TRY(calendar_month(global_object, calendar, *temporal_date_time)));
return Value(TRY(calendar_month(vm, calendar, *temporal_date_time)));
}
// 6.3.7 get Temporal.ZonedDateTime.prototype.monthCode, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.monthcode
@ -169,16 +169,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::month_code_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarMonthCode(calendar, temporalDateTime).
return js_string(vm, TRY(calendar_month_code(global_object, calendar, *temporal_date_time)));
return js_string(vm, TRY(calendar_month_code(vm, calendar, *temporal_date_time)));
}
// 6.3.8 get Temporal.ZonedDateTime.prototype.day, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.day
@ -192,16 +192,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::day_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarDay(calendar, temporalDateTime).
return Value(TRY(calendar_day(global_object, calendar, *temporal_date_time)));
return Value(TRY(calendar_day(vm, calendar, *temporal_date_time)));
}
// 6.3.9 get Temporal.ZonedDateTime.prototype.hour, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.hour
@ -215,13 +215,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::hour_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOHour]]).
return Value(temporal_date_time->iso_hour());
@ -238,13 +238,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::minute_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOMinute]]).
return Value(temporal_date_time->iso_minute());
@ -261,13 +261,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::second_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOSecond]]).
return Value(temporal_date_time->iso_second());
@ -284,13 +284,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::millisecond_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOMillisecond]]).
return Value(temporal_date_time->iso_millisecond());
@ -307,13 +307,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::microsecond_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOMicrosecond]]).
return Value(temporal_date_time->iso_microsecond());
@ -330,13 +330,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::nanosecond_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISONanosecond]]).
return Value(temporal_date_time->iso_nanosecond());
@ -415,16 +415,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::day_of_week_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarDayOfWeek(calendar, temporalDateTime).
return TRY(calendar_day_of_week(global_object, calendar, *temporal_date_time));
return TRY(calendar_day_of_week(vm, calendar, *temporal_date_time));
}
// 6.3.20 get Temporal.ZonedDateTime.prototype.dayOfYear, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.dayofyear
@ -438,16 +438,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::day_of_year_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarDayOfYear(calendar, temporalDateTime).
return TRY(calendar_day_of_year(global_object, calendar, *temporal_date_time));
return TRY(calendar_day_of_year(vm, calendar, *temporal_date_time));
}
// 6.3.21 get Temporal.ZonedDateTime.prototype.weekOfYear, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.weekofyear
@ -461,16 +461,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::week_of_year_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarWeekOfYear(calendar, temporalDateTime).
return TRY(calendar_week_of_year(global_object, calendar, *temporal_date_time));
return TRY(calendar_week_of_year(vm, calendar, *temporal_date_time));
}
// 6.3.22 get Temporal.ZonedDateTime.prototype.hoursInDay, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.hoursinday
@ -484,13 +484,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::hours_in_day_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let isoCalendar be ! GetISO8601Calendar().
auto* iso_calendar = get_iso8601_calendar(global_object);
auto* iso_calendar = get_iso8601_calendar(vm);
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, isoCalendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, *iso_calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, *iso_calendar));
// 7. Let year be temporalDateTime.[[ISOYear]].
auto year = temporal_date_time->iso_year();
@ -502,19 +502,19 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::hours_in_day_getter)
auto day = temporal_date_time->iso_day();
// 10. Let today be ? CreateTemporalDateTime(year, month, day, 0, 0, 0, 0, 0, 0, isoCalendar).
auto* today = TRY(create_temporal_date_time(global_object, year, month, day, 0, 0, 0, 0, 0, 0, *iso_calendar));
auto* today = TRY(create_temporal_date_time(vm, year, month, day, 0, 0, 0, 0, 0, 0, *iso_calendar));
// 11. Let tomorrowFields be BalanceISODate(year, month, day + 1).
auto tomorrow_fields = balance_iso_date(year, month, day + 1);
// 12. Let tomorrow be ? CreateTemporalDateTime(tomorrowFields.[[Year]], tomorrowFields.[[Month]], tomorrowFields.[[Day]], 0, 0, 0, 0, 0, 0, isoCalendar).
auto* tomorrow = TRY(create_temporal_date_time(global_object, tomorrow_fields.year, tomorrow_fields.month, tomorrow_fields.day, 0, 0, 0, 0, 0, 0, *iso_calendar));
auto* tomorrow = TRY(create_temporal_date_time(vm, tomorrow_fields.year, tomorrow_fields.month, tomorrow_fields.day, 0, 0, 0, 0, 0, 0, *iso_calendar));
// 13. Let todayInstant be ? BuiltinTimeZoneGetInstantFor(timeZone, today, "compatible").
auto* today_instant = TRY(builtin_time_zone_get_instant_for(global_object, &time_zone, *today, "compatible"sv));
auto* today_instant = TRY(builtin_time_zone_get_instant_for(vm, &time_zone, *today, "compatible"sv));
// 14. Let tomorrowInstant be ? BuiltinTimeZoneGetInstantFor(timeZone, tomorrow, "compatible").
auto* tomorrow_instant = TRY(builtin_time_zone_get_instant_for(global_object, &time_zone, *tomorrow, "compatible"sv));
auto* tomorrow_instant = TRY(builtin_time_zone_get_instant_for(vm, &time_zone, *tomorrow, "compatible"sv));
// 15. Let diffNs be tomorrowInstant.[[Nanoseconds]] - todayInstant.[[Nanoseconds]].
auto diff_ns = tomorrow_instant->nanoseconds().big_integer().minus(today_instant->nanoseconds().big_integer());
@ -535,16 +535,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::days_in_week_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarDaysInWeek(calendar, temporalDateTime).
return TRY(calendar_days_in_week(global_object, calendar, *temporal_date_time));
return TRY(calendar_days_in_week(vm, calendar, *temporal_date_time));
}
// 6.3.24 get Temporal.ZonedDateTime.prototype.daysInMonth, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.daysinmonth
@ -558,16 +558,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::days_in_month_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarDaysInMonth(calendar, temporalDateTime).
return TRY(calendar_days_in_month(global_object, calendar, *temporal_date_time));
return TRY(calendar_days_in_month(vm, calendar, *temporal_date_time));
}
// 6.3.25 get Temporal.ZonedDateTime.prototype.daysInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.daysinyear
@ -581,16 +581,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::days_in_year_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarDaysInYear(calendar, temporalDateTime).
return TRY(calendar_days_in_year(global_object, calendar, *temporal_date_time));
return TRY(calendar_days_in_year(vm, calendar, *temporal_date_time));
}
// 6.3.26 get Temporal.ZonedDateTime.prototype.monthsInYear, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.monthsinyear
@ -604,16 +604,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::months_in_year_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarMonthsInYear(calendar, temporalDateTime).
return TRY(calendar_months_in_year(global_object, calendar, *temporal_date_time));
return TRY(calendar_months_in_year(vm, calendar, *temporal_date_time));
}
// 6.3.27 get Temporal.ZonedDateTime.prototype.inLeapYear, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.inleapyear
@ -627,16 +627,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::in_leap_year_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarInLeapYear(calendar, temporalDateTime).
return TRY(calendar_in_leap_year(global_object, calendar, *temporal_date_time));
return TRY(calendar_in_leap_year(vm, calendar, *temporal_date_time));
}
// 6.3.28 get Temporal.ZonedDateTime.prototype.offsetNanoseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.offsetnanoseconds
@ -650,10 +650,10 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::offset_nanoseconds_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Return 𝔽(? GetOffsetNanosecondsFor(timeZone, instant)).
return Value(TRY(get_offset_nanoseconds_for(global_object, &time_zone, *instant)));
return Value(TRY(get_offset_nanoseconds_for(vm, &time_zone, *instant)));
}
// 6.3.29 get Temporal.ZonedDateTime.prototype.offset, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.offset
@ -664,10 +664,10 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::offset_getter)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 4. Return ? BuiltinTimeZoneGetOffsetStringFor(zonedDateTime.[[TimeZone]], instant).
auto offset_string = TRY(builtin_time_zone_get_offset_string_for(global_object, &zoned_date_time->time_zone(), *instant));
auto offset_string = TRY(builtin_time_zone_get_offset_string_for(vm, &zoned_date_time->time_zone(), *instant));
return js_string(vm, move(offset_string));
}
@ -682,16 +682,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::era_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarEra(calendar, plainDateTime).
return TRY(calendar_era(global_object, calendar, *plain_date_time));
return TRY(calendar_era(vm, calendar, *plain_date_time));
}
// 15.6.10.3 get Temporal.ZonedDateTime.prototype.eraYear, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.erayear
@ -705,16 +705,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::era_year_getter)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ? CalendarEraYear(calendar, plainDateTime).
return TRY(calendar_era_year(global_object, calendar, *plain_date_time));
return TRY(calendar_era_year(vm, calendar, *plain_date_time));
}
// 6.3.30 Temporal.ZonedDateTime.prototype.with ( temporalZonedDateTimeLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.with
@ -733,28 +733,28 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
}
// 4. Perform ? RejectObjectWithCalendarOrTimeZone(temporalZonedDateTimeLike).
TRY(reject_object_with_calendar_or_time_zone(global_object, temporal_zoned_date_time_like.as_object()));
TRY(reject_object_with_calendar_or_time_zone(vm, temporal_zoned_date_time_like.as_object()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let fieldNames be ? CalendarFields(calendar, « "day", "hour", "microsecond", "millisecond", "minute", "month", "monthCode", "nanosecond", "second", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// 7. Append "offset" to fieldNames.
field_names.append("offset"sv);
// 8. Let partialZonedDateTime be ? PrepareTemporalFields(temporalZonedDateTimeLike, fieldNames, partial).
auto* partial_zoned_date_time = TRY(prepare_temporal_fields(global_object, temporal_zoned_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
auto* partial_zoned_date_time = TRY(prepare_temporal_fields(vm, temporal_zoned_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 9. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
auto* options = TRY(get_options_object(vm, vm.argument(1)));
// 10. Let disambiguation be ? ToTemporalDisambiguation(options).
auto disambiguation = TRY(to_temporal_disambiguation(global_object, options));
auto disambiguation = TRY(to_temporal_disambiguation(vm, options));
// 11. Let offset be ? ToTemporalOffset(options, "prefer").
auto offset = TRY(to_temporal_offset(global_object, options, "prefer"sv));
auto offset = TRY(to_temporal_offset(vm, options, "prefer"sv));
// 12. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time->time_zone();
@ -763,13 +763,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
field_names.append("timeZone"sv);
// 14. Let fields be ? PrepareTemporalFields(zonedDateTime, fieldNames, « "timeZone", "offset" »).
auto* fields = TRY(prepare_temporal_fields(global_object, *zoned_date_time, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
auto* fields = TRY(prepare_temporal_fields(vm, *zoned_date_time, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
// 15. Set fields to ? CalendarMergeFields(calendar, fields, partialZonedDateTime).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_zoned_date_time));
fields = TRY(calendar_merge_fields(vm, calendar, *fields, *partial_zoned_date_time));
// 16. Set fields to ? PrepareTemporalFields(fields, fieldNames, « "timeZone", "offset" »).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
fields = TRY(prepare_temporal_fields(vm, *fields, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
// 17. Let offsetString be ! Get(fields, "offset").
auto offset_string = MUST(fields->get(vm.names.offset));
@ -778,16 +778,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
VERIFY(offset_string.is_string());
// 19. Let dateTimeResult be ? InterpretTemporalDateTimeFields(calendar, fields, options).
auto date_time_result = TRY(interpret_temporal_date_time_fields(global_object, calendar, *fields, *options));
auto date_time_result = TRY(interpret_temporal_date_time_fields(vm, calendar, *fields, *options));
// 20. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(offsetString).
auto offset_nanoseconds = TRY(parse_time_zone_offset_string(global_object, offset_string.as_string().string()));
auto offset_nanoseconds = TRY(parse_time_zone_offset_string(vm, offset_string.as_string().string()));
// 21. Let epochNanoseconds be ? InterpretISODateTimeOffset(dateTimeResult.[[Year]], dateTimeResult.[[Month]], dateTimeResult.[[Day]], dateTimeResult.[[Hour]], dateTimeResult.[[Minute]], dateTimeResult.[[Second]], dateTimeResult.[[Millisecond]], dateTimeResult.[[Microsecond]], dateTimeResult.[[Nanosecond]], option, offsetNanoseconds, timeZone, disambiguation, offset, match exactly).
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(global_object, date_time_result.year, date_time_result.month, date_time_result.day, date_time_result.hour, date_time_result.minute, date_time_result.second, date_time_result.millisecond, date_time_result.microsecond, date_time_result.nanosecond, OffsetBehavior::Option, offset_nanoseconds, &time_zone, disambiguation, offset, MatchBehavior::MatchExactly));
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, date_time_result.year, date_time_result.month, date_time_result.day, date_time_result.hour, date_time_result.minute, date_time_result.second, date_time_result.millisecond, date_time_result.microsecond, date_time_result.nanosecond, OffsetBehavior::Option, offset_nanoseconds, &time_zone, disambiguation, offset, MatchBehavior::MatchExactly));
// 22. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, *epoch_nanoseconds, time_zone, calendar));
return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone, calendar));
}
// 6.3.31 Temporal.ZonedDateTime.prototype.withPlainTime ( [ plainTimeLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.withplaintime
@ -802,34 +802,34 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with_plain_time)
// 3. If plainTimeLike is undefined, then
if (vm.argument(0).is_undefined()) {
// a. Let plainTime be ! CreateTemporalTime(0, 0, 0, 0, 0, 0).
plain_time = MUST(create_temporal_time(global_object, 0, 0, 0, 0, 0, 0));
plain_time = MUST(create_temporal_time(vm, 0, 0, 0, 0, 0, 0));
}
// 4. Else,
else {
// a. Let plainTime be ? ToTemporalTime(plainTimeLike).
plain_time = TRY(to_temporal_time(global_object, vm.argument(0)));
plain_time = TRY(to_temporal_time(vm, vm.argument(0)));
}
// 5. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time->time_zone();
// 6. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 7. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 8. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 9. Let resultPlainDateTime be ? CreateTemporalDateTime(plainDateTime.[[ISOYear]], plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], plainTime.[[ISOHour]], plainTime.[[ISOMinute]], plainTime.[[ISOSecond]], plainTime.[[ISOMillisecond]], plainTime.[[ISOMicrosecond]], plainTime.[[ISONanosecond]], calendar).
auto* result_plain_date_time = TRY(create_temporal_date_time(global_object, plain_date_time->iso_year(), plain_date_time->iso_month(), plain_date_time->iso_day(), plain_time->iso_hour(), plain_time->iso_minute(), plain_time->iso_second(), plain_time->iso_millisecond(), plain_time->iso_microsecond(), plain_time->iso_nanosecond(), calendar));
auto* result_plain_date_time = TRY(create_temporal_date_time(vm, plain_date_time->iso_year(), plain_date_time->iso_month(), plain_date_time->iso_day(), plain_time->iso_hour(), plain_time->iso_minute(), plain_time->iso_second(), plain_time->iso_millisecond(), plain_time->iso_microsecond(), plain_time->iso_nanosecond(), calendar));
// 10. Set instant to ? BuiltinTimeZoneGetInstantFor(timeZone, resultPlainDateTime, "compatible").
instant = TRY(builtin_time_zone_get_instant_for(global_object, &time_zone, *result_plain_date_time, "compatible"sv));
instant = TRY(builtin_time_zone_get_instant_for(vm, &time_zone, *result_plain_date_time, "compatible"sv));
// 11. Return ! CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), time_zone, calendar));
return MUST(create_temporal_zoned_date_time(vm, instant->nanoseconds(), time_zone, calendar));
}
// 6.3.32 Temporal.ZonedDateTime.prototype.withPlainDate ( plainDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.withplaindate
@ -840,28 +840,28 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with_plain_date)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Let plainDate be ? ToTemporalDate(plainDateLike).
auto* plain_date = TRY(to_temporal_date(global_object, vm.argument(0)));
auto* plain_date = TRY(to_temporal_date(vm, vm.argument(0)));
// 4. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time->time_zone();
// 5. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 6. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, zonedDateTime.[[Calendar]]).
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, zoned_date_time->calendar()));
auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, zoned_date_time->calendar()));
// 7. Let calendar be ? ConsolidateCalendars(zonedDateTime.[[Calendar]], plainDate.[[Calendar]]).
auto* calendar = TRY(consolidate_calendars(global_object, zoned_date_time->calendar(), plain_date->calendar()));
auto* calendar = TRY(consolidate_calendars(vm, zoned_date_time->calendar(), plain_date->calendar()));
// 8. Let resultPlainDateTime be ? CreateTemporalDateTime(plainDate.[[ISOYear]], plainDate.[[ISOMonth]], plainDate.[[ISODay]], plainDateTime.[[ISOHour]], plainDateTime.[[ISOMinute]], plainDateTime.[[ISOSecond]], plainDateTime.[[ISOMillisecond]], plainDateTime.[[ISOMicrosecond]], plainDateTime.[[ISONanosecond]], calendar).
auto* result_plain_date_time = TRY(create_temporal_date_time(global_object, plain_date->iso_year(), plain_date->iso_month(), plain_date->iso_day(), plain_date_time->iso_hour(), plain_date_time->iso_minute(), plain_date_time->iso_second(), plain_date_time->iso_millisecond(), plain_date_time->iso_microsecond(), plain_date_time->iso_nanosecond(), *calendar));
auto* result_plain_date_time = TRY(create_temporal_date_time(vm, plain_date->iso_year(), plain_date->iso_month(), plain_date->iso_day(), plain_date_time->iso_hour(), plain_date_time->iso_minute(), plain_date_time->iso_second(), plain_date_time->iso_millisecond(), plain_date_time->iso_microsecond(), plain_date_time->iso_nanosecond(), *calendar));
// 9. Set instant to ? BuiltinTimeZoneGetInstantFor(timeZone, resultPlainDateTime, "compatible").
instant = TRY(builtin_time_zone_get_instant_for(global_object, &time_zone, *result_plain_date_time, "compatible"sv));
instant = TRY(builtin_time_zone_get_instant_for(vm, &time_zone, *result_plain_date_time, "compatible"sv));
// 10. Return ! CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), time_zone, *calendar));
return MUST(create_temporal_zoned_date_time(vm, instant->nanoseconds(), time_zone, *calendar));
}
// 6.3.33 Temporal.ZonedDateTime.prototype.withTimeZone ( timeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.withtimezone
@ -872,10 +872,10 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with_time_zone)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Let timeZone be ? ToTemporalTimeZone(timeZoneLike).
auto* time_zone = TRY(to_temporal_time_zone(global_object, vm.argument(0)));
auto* time_zone = TRY(to_temporal_time_zone(vm, vm.argument(0)));
// 4. Return ! CreateTemporalZonedDateTime(zonedDateTime.[[Nanoseconds]], timeZone, zonedDateTime.[[Calendar]]).
return MUST(create_temporal_zoned_date_time(global_object, zoned_date_time->nanoseconds(), *time_zone, zoned_date_time->calendar()));
return MUST(create_temporal_zoned_date_time(vm, zoned_date_time->nanoseconds(), *time_zone, zoned_date_time->calendar()));
}
// 6.3.34 Temporal.ZonedDateTime.prototype.withCalendar ( calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.withcalendar
@ -886,10 +886,10 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with_calendar)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
auto* calendar = TRY(to_temporal_calendar(global_object, vm.argument(0)));
auto* calendar = TRY(to_temporal_calendar(vm, vm.argument(0)));
// 4. Return ! CreateTemporalZonedDateTime(zonedDateTime.[[Nanoseconds]], zonedDateTime.[[TimeZone]], calendar).
return MUST(create_temporal_zoned_date_time(global_object, zoned_date_time->nanoseconds(), zoned_date_time->time_zone(), *calendar));
return MUST(create_temporal_zoned_date_time(vm, zoned_date_time->nanoseconds(), zoned_date_time->time_zone(), *calendar));
}
// 6.3.35 Temporal.ZonedDateTime.prototype.add ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.add
@ -903,7 +903,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::add)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromZonedDateTime(add, zonedDateTime, temporalDurationLike, options).
return TRY(add_duration_to_or_subtract_duration_from_zoned_date_time(global_object, ArithmeticOperation::Add, *zoned_date_time, temporal_duration_like, options));
return TRY(add_duration_to_or_subtract_duration_from_zoned_date_time(vm, ArithmeticOperation::Add, *zoned_date_time, temporal_duration_like, options));
}
// 6.3.36 Temporal.ZonedDateTime.prototype.subtract ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.subtract
@ -917,7 +917,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::subtract)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Return ? AddDurationToOrSubtractDurationFromZonedDateTime(subtract, zonedDateTime, temporalDurationLike, options).
return TRY(add_duration_to_or_subtract_duration_from_zoned_date_time(global_object, ArithmeticOperation::Subtract, *zoned_date_time, temporal_duration_like, options));
return TRY(add_duration_to_or_subtract_duration_from_zoned_date_time(vm, ArithmeticOperation::Subtract, *zoned_date_time, temporal_duration_like, options));
}
// 6.3.37 Temporal.ZonedDateTime.prototype.until ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.until
@ -931,7 +931,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::until)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalZonedDateTime(until, zonedDateTime, other, options).
return TRY(difference_temporal_zoned_date_time(global_object, DifferenceOperation::Until, *zoned_date_time, other, options));
return TRY(difference_temporal_zoned_date_time(vm, DifferenceOperation::Until, *zoned_date_time, other, options));
}
// 6.3.38 Temporal.ZonedDateTime.prototype.since ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.since
@ -945,7 +945,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::since)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Return ? DifferenceTemporalZonedDateTime(since, zonedDateTime, other, options).
return TRY(difference_temporal_zoned_date_time(global_object, DifferenceOperation::Since, *zoned_date_time, other, options));
return TRY(difference_temporal_zoned_date_time(vm, DifferenceOperation::Since, *zoned_date_time, other, options));
}
// 6.3.39 Temporal.ZonedDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.round
@ -978,44 +978,44 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
// 5. Else,
else {
// a. Set roundTo to ? GetOptionsObject(roundTo).
round_to = TRY(get_options_object(global_object, vm.argument(0)));
round_to = TRY(get_options_object(vm, vm.argument(0)));
}
// 6. Let smallestUnit be ? GetTemporalUnit(roundTo, "smallestUnit", time, required, « "day" »).
auto smallest_unit = TRY(get_temporal_unit(global_object, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}, { "day"sv }));
auto smallest_unit = TRY(get_temporal_unit(vm, *round_to, vm.names.smallestUnit, UnitGroup::Time, TemporalUnitRequired {}, { "day"sv }));
// 7. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *round_to, "halfExpand"sv));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *round_to, "halfExpand"sv));
// 8. Let roundingIncrement be ? ToTemporalDateTimeRoundingIncrement(options, smallestUnit).
auto rounding_increment = TRY(to_temporal_date_time_rounding_increment(global_object, *round_to, *smallest_unit));
auto rounding_increment = TRY(to_temporal_date_time_rounding_increment(vm, *round_to, *smallest_unit));
// 9. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time->time_zone();
// 10. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 11. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 12. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 13. Let isoCalendar be ! GetISO8601Calendar().
auto* iso_calendar = get_iso8601_calendar(global_object);
auto* iso_calendar = get_iso8601_calendar(vm);
// 14. Let dtStart be ? CreateTemporalDateTime(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], 0, 0, 0, 0, 0, 0, isoCalendar).
auto* dt_start = TRY(create_temporal_date_time(global_object, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), 0, 0, 0, 0, 0, 0, *iso_calendar));
auto* dt_start = TRY(create_temporal_date_time(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), 0, 0, 0, 0, 0, 0, *iso_calendar));
// 15. Let instantStart be ? BuiltinTimeZoneGetInstantFor(timeZone, dtStart, "compatible").
auto* instant_start = TRY(builtin_time_zone_get_instant_for(global_object, &time_zone, *dt_start, "compatible"sv));
auto* instant_start = TRY(builtin_time_zone_get_instant_for(vm, &time_zone, *dt_start, "compatible"sv));
// 16. Let startNs be instantStart.[[Nanoseconds]].
auto& start_ns = instant_start->nanoseconds();
// 17. Let endNs be ? AddZonedDateTime(startNs, timeZone, calendar, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0).
auto* end_ns = TRY(add_zoned_date_time(global_object, start_ns, &time_zone, calendar, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0));
auto* end_ns = TRY(add_zoned_date_time(vm, start_ns, &time_zone, calendar, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0));
// 18. Let dayLengthNs be (endNs - startNs).
auto day_length_ns = end_ns->big_integer().minus(start_ns.big_integer()).to_double();
@ -1027,16 +1027,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
}
// 20. Let roundResult be ! RoundISODateTime(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode, dayLengthNs).
auto round_result = round_iso_date_time(global_object, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), rounding_increment, *smallest_unit, rounding_mode, day_length_ns);
auto round_result = round_iso_date_time(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), rounding_increment, *smallest_unit, rounding_mode, day_length_ns);
// 21. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, &time_zone, *instant));
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(vm, &time_zone, *instant));
// 22. Let epochNanoseconds be ? InterpretISODateTimeOffset(roundResult.[[Year]], roundResult.[[Month]], roundResult.[[Day]], roundResult.[[Hour]], roundResult.[[Minute]], roundResult.[[Second]], roundResult.[[Millisecond]], roundResult.[[Microsecond]], roundResult.[[Nanosecond]], option, offsetNanoseconds, timeZone, "compatible", "prefer", match exactly).
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(global_object, round_result.year, round_result.month, round_result.day, round_result.hour, round_result.minute, round_result.second, round_result.millisecond, round_result.microsecond, round_result.nanosecond, OffsetBehavior::Option, offset_nanoseconds, &time_zone, "compatible"sv, "prefer"sv, MatchBehavior::MatchExactly));
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, round_result.year, round_result.month, round_result.day, round_result.hour, round_result.minute, round_result.second, round_result.millisecond, round_result.microsecond, round_result.nanosecond, OffsetBehavior::Option, offset_nanoseconds, &time_zone, "compatible"sv, "prefer"sv, MatchBehavior::MatchExactly));
// 23. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, *epoch_nanoseconds, time_zone, calendar));
return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone, calendar));
}
// 6.3.40 Temporal.ZonedDateTime.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.equals
@ -1047,18 +1047,18 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::equals)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Set other to ? ToTemporalZonedDateTime(other).
auto* other = TRY(to_temporal_zoned_date_time(global_object, vm.argument(0)));
auto* other = TRY(to_temporal_zoned_date_time(vm, vm.argument(0)));
// 4. If zonedDateTime.[[Nanoseconds]] ≠ other.[[Nanoseconds]], return false.
if (zoned_date_time->nanoseconds().big_integer() != other->nanoseconds().big_integer())
return Value(false);
// 5. If ? TimeZoneEquals(zonedDateTime.[[TimeZone]], other.[[TimeZone]]) is false, return false.
if (!TRY(time_zone_equals(global_object, zoned_date_time->time_zone(), other->time_zone())))
if (!TRY(time_zone_equals(vm, zoned_date_time->time_zone(), other->time_zone())))
return Value(false);
// 6. Return ? CalendarEquals(zonedDateTime.[[Calendar]], other.[[Calendar]]).
return Value(TRY(calendar_equals(global_object, zoned_date_time->calendar(), other->calendar())));
return Value(TRY(calendar_equals(vm, zoned_date_time->calendar(), other->calendar())));
}
// 6.3.41 Temporal.ZonedDateTime.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.tostring
@ -1069,25 +1069,25 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_string)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(0)));
auto* options = TRY(get_options_object(vm, vm.argument(0)));
// 4. Let precision be ? ToSecondsStringPrecision(options).
auto precision = TRY(to_seconds_string_precision(global_object, *options));
auto precision = TRY(to_seconds_string_precision(vm, *options));
// 5. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *options, "trunc"));
auto rounding_mode = TRY(to_temporal_rounding_mode(vm, *options, "trunc"));
// 6. Let showCalendar be ? ToShowCalendarOption(options).
auto show_calendar = TRY(to_show_calendar_option(global_object, *options));
auto show_calendar = TRY(to_show_calendar_option(vm, *options));
// 7. Let showTimeZone be ? ToShowTimeZoneNameOption(options).
auto show_time_zone = TRY(to_show_time_zone_name_option(global_object, *options));
auto show_time_zone = TRY(to_show_time_zone_name_option(vm, *options));
// 8. Let showOffset be ? ToShowOffsetOption(options).
auto show_offset = TRY(to_show_offset_option(global_object, *options));
auto show_offset = TRY(to_show_offset_option(vm, *options));
// 9. Return ? TemporalZonedDateTimeToString(zonedDateTime, precision.[[Precision]], showCalendar, showTimeZone, showOffset, precision.[[Increment]], precision.[[Unit]], roundingMode).
return js_string(vm, TRY(temporal_zoned_date_time_to_string(global_object, *zoned_date_time, precision.precision, show_calendar, show_time_zone, show_offset, precision.increment, precision.unit, rounding_mode)));
return js_string(vm, TRY(temporal_zoned_date_time_to_string(vm, *zoned_date_time, precision.precision, show_calendar, show_time_zone, show_offset, precision.increment, precision.unit, rounding_mode)));
}
// 6.3.42 Temporal.ZonedDateTime.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.tolocalestring
@ -1099,7 +1099,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_locale_string)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Return ? TemporalZonedDateTimeToString(zonedDateTime, "auto", "auto", "auto", "auto").
return js_string(vm, TRY(temporal_zoned_date_time_to_string(global_object, *zoned_date_time, "auto"sv, "auto"sv, "auto"sv, "auto"sv)));
return js_string(vm, TRY(temporal_zoned_date_time_to_string(vm, *zoned_date_time, "auto"sv, "auto"sv, "auto"sv, "auto"sv)));
}
// 6.3.43 Temporal.ZonedDateTime.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.tojson
@ -1110,7 +1110,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_json)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Return ? TemporalZonedDateTimeToString(zonedDateTime, "auto", "auto", "auto", "auto").
return js_string(vm, TRY(temporal_zoned_date_time_to_string(global_object, *zoned_date_time, "auto"sv, "auto"sv, "auto"sv, "auto"sv)));
return js_string(vm, TRY(temporal_zoned_date_time_to_string(vm, *zoned_date_time, "auto"sv, "auto"sv, "auto"sv, "auto"sv)));
}
// 6.3.44 Temporal.ZonedDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.valueof
@ -1134,19 +1134,19 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::start_of_day)
auto& calendar = zoned_date_time->calendar();
// 5. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Let startDateTime be ? CreateTemporalDateTime(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], 0, 0, 0, 0, 0, 0, calendar).
auto* start_date_time = TRY(create_temporal_date_time(global_object, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), 0, 0, 0, 0, 0, 0, calendar));
auto* start_date_time = TRY(create_temporal_date_time(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), 0, 0, 0, 0, 0, 0, calendar));
// 8. Let startInstant be ? BuiltinTimeZoneGetInstantFor(timeZone, startDateTime, "compatible").
auto* start_instant = TRY(builtin_time_zone_get_instant_for(global_object, &time_zone, *start_date_time, "compatible"sv));
auto* start_instant = TRY(builtin_time_zone_get_instant_for(vm, &time_zone, *start_date_time, "compatible"sv));
// 9. Return ! CreateTemporalZonedDateTime(startInstant.[[Nanoseconds]], timeZone, calendar).
return MUST(create_temporal_zoned_date_time(global_object, start_instant->nanoseconds(), time_zone, calendar));
return MUST(create_temporal_zoned_date_time(vm, start_instant->nanoseconds(), time_zone, calendar));
}
// 6.3.46 Temporal.ZonedDateTime.prototype.toInstant ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toinstant
@ -1157,7 +1157,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_instant)
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Return ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
return MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
return MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
}
// 6.3.47 Temporal.ZonedDateTime.prototype.toPlainDate ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplaindate
@ -1171,16 +1171,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_date)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ! CreateTemporalDate(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], calendar).
return MUST(create_temporal_date(global_object, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), calendar));
return MUST(create_temporal_date(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), calendar));
}
// 6.3.48 Temporal.ZonedDateTime.prototype.toPlainTime ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplaintime
@ -1194,16 +1194,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_time)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, zonedDateTime.[[Calendar]]).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Return ! CreateTemporalTime(temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]]).
return MUST(create_temporal_time(global_object, temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond()));
return MUST(create_temporal_time(vm, temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond()));
}
// 6.3.49 Temporal.ZonedDateTime.prototype.toPlainDateTime ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplaindatetime
@ -1217,10 +1217,10 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_date_time)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, zonedDateTime.[[Calendar]]).
return TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, zoned_date_time->calendar()));
return TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, zoned_date_time->calendar()));
}
// 6.3.50 Temporal.ZonedDateTime.prototype.toPlainYearMonth ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplainyearmonth
@ -1234,22 +1234,22 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_year_month)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Let fieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "monthCode"sv, "year"sv }));
// 8. Let fields be ? PrepareTemporalFields(temporalDateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date_time, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *temporal_date_time, field_names, Vector<StringView> {}));
// 9. Return ? CalendarYearMonthFromFields(calendar, fields).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields));
return TRY(calendar_year_month_from_fields(vm, calendar, *fields));
}
// 6.3.51 Temporal.ZonedDateTime.prototype.toPlainMonthDay ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplainmonthday
@ -1263,22 +1263,22 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_month_day)
auto& time_zone = zoned_date_time->time_zone();
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 5. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* temporal_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 7. Let fieldNames be ? CalendarFields(calendar, « "day", "monthCode" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "monthCode"sv }));
// 8. Let fields be ? PrepareTemporalFields(temporalDateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date_time, field_names, Vector<StringView> {}));
auto* fields = TRY(prepare_temporal_fields(vm, *temporal_date_time, field_names, Vector<StringView> {}));
// 9. Return ? CalendarMonthDayFromFields(calendar, fields).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields));
return TRY(calendar_month_day_from_fields(vm, calendar, *fields));
}
// 6.3.52 Temporal.ZonedDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.getisofields
@ -1297,16 +1297,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields)
auto& time_zone = zoned_date_time->time_zone();
// 5. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(global_object, zoned_date_time->nanoseconds()));
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
// 6. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 7. Let dateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
auto* date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
auto* date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &time_zone, *instant, calendar));
// 8. Let offset be ? BuiltinTimeZoneGetOffsetStringFor(timeZone, instant).
auto offset = TRY(builtin_time_zone_get_offset_string_for(global_object, &time_zone, *instant));
auto offset = TRY(builtin_time_zone_get_offset_string_for(vm, &time_zone, *instant));
// 9. Perform ! CreateDataPropertyOrThrow(fields, "calendar", calendar).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&calendar)));