mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:07:34 +00:00
LibJS: Replace GlobalObject with VM in Value AOs [Part 4/19]
This is where the fun begins. :^)
This commit is contained in:
parent
f6c4a0f5d0
commit
a022e548b8
129 changed files with 1230 additions and 1325 deletions
|
@ -104,9 +104,6 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
{
|
||||
VERIFY(property.is_string());
|
||||
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let value be ? Get(options, property).
|
||||
auto value = TRY(options.get(property));
|
||||
|
||||
|
@ -133,7 +130,7 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
// 6. Else if type is "number", then
|
||||
else if (type == OptionType::Number) {
|
||||
// a. Set value to ? ToNumber(value).
|
||||
value = TRY(value.to_number(global_object));
|
||||
value = TRY(value.to_number(vm));
|
||||
|
||||
// b. If value is NaN, throw a RangeError exception.
|
||||
if (value.is_nan())
|
||||
|
@ -145,7 +142,7 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
VERIFY(type == OptionType::String);
|
||||
|
||||
// b. Set value to ? ToString(value).
|
||||
value = TRY(value.to_primitive_string(global_object));
|
||||
value = TRY(value.to_primitive_string(vm));
|
||||
}
|
||||
|
||||
// 8. If values is not undefined and values does not contain an element equal to value, throw a RangeError exception.
|
||||
|
@ -327,9 +324,6 @@ ThrowCompletionOr<u64> to_temporal_date_time_rounding_increment(VM& vm, Object c
|
|||
// 13.14 ToSecondsStringPrecision ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-tosecondsstringprecision
|
||||
ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM& vm, Object const& normalized_options)
|
||||
{
|
||||
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(vm, normalized_options, vm.names.smallestUnit, UnitGroup::Time, Optional<StringView> {}));
|
||||
|
||||
|
@ -378,7 +372,7 @@ ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM& vm, Ob
|
|||
// a. If fractionalDigitsVal is not undefined, then
|
||||
if (!fractional_digits_value.is_undefined()) {
|
||||
// i. If ? ToString(fractionalDigitsVal) is not "auto", throw a RangeError exception.
|
||||
if (TRY(fractional_digits_value.to_string(global_object)) != "auto"sv)
|
||||
if (TRY(fractional_digits_value.to_string(vm)) != "auto"sv)
|
||||
return vm.template throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, fractional_digits_value, "fractionalSecondDigits"sv);
|
||||
}
|
||||
|
||||
|
@ -536,7 +530,6 @@ ThrowCompletionOr<Optional<String>> get_temporal_unit(VM& vm, Object const& norm
|
|||
ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(options) is Object.
|
||||
|
||||
|
@ -617,7 +610,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
|
|||
// 7. Else,
|
||||
else {
|
||||
// a. Let string be ? ToString(value).
|
||||
auto string = TRY(value.to_string(global_object));
|
||||
auto string = TRY(value.to_string(vm));
|
||||
|
||||
// b. Let result be ? ParseTemporalRelativeToString(string).
|
||||
auto parsed_result = TRY(parse_temporal_relative_to_string(vm, string));
|
||||
|
@ -681,7 +674,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
|
|||
if (offset_behavior == OffsetBehavior::Option) {
|
||||
// i. Set offsetString to ? ToString(offsetString).
|
||||
// NOTE: offsetString is not used after this path, so we don't need to put this into the original offset_string which is of type JS::Value.
|
||||
auto actual_offset_string = TRY(offset_string.to_string(global_object));
|
||||
auto actual_offset_string = TRY(offset_string.to_string(vm));
|
||||
|
||||
// ii. Let offsetNs be ? ParseTimeZoneOffsetString(offsetString).
|
||||
offset_ns = TRY(parse_time_zone_offset_string(vm, actual_offset_string));
|
||||
|
@ -728,7 +721,6 @@ StringView larger_of_two_temporal_units(StringView unit1, StringView unit2)
|
|||
ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& options, String largest_unit)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let merged be OrdinaryObjectCreate(null).
|
||||
auto* merged = Object::create(realm, nullptr);
|
||||
|
@ -738,7 +730,7 @@ ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& optio
|
|||
|
||||
// 3. For each element nextKey of keys, do
|
||||
for (auto& key : keys) {
|
||||
auto next_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto next_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// a. Let propValue be ? Get(options, nextKey).
|
||||
auto prop_value = TRY(options.get(next_key));
|
||||
|
@ -1729,7 +1721,6 @@ ThrowCompletionOr<double> to_positive_integer(VM& vm, Value argument)
|
|||
ThrowCompletionOr<Object*> prepare_temporal_fields(VM& vm, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let result be OrdinaryObjectCreate(null).
|
||||
auto* result = Object::create(realm, nullptr);
|
||||
|
@ -1766,7 +1757,7 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(VM& vm, Object const& fields,
|
|||
else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv)) {
|
||||
// a. Assert: Conversion is ToString.
|
||||
// b. Set value to ? ToString(value).
|
||||
value = TRY(value.to_primitive_string(global_object));
|
||||
value = TRY(value.to_primitive_string(vm));
|
||||
}
|
||||
|
||||
// iii. Perform ! CreateDataPropertyOrThrow(result, property, value).
|
||||
|
|
|
@ -191,11 +191,8 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
|
|||
template<typename... Args>
|
||||
ThrowCompletionOr<double> to_integer_throw_on_infinity(VM& vm, Value argument, ErrorType error_type, Args... args)
|
||||
{
|
||||
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));
|
||||
auto integer = TRY(argument.to_integer_or_infinity(vm));
|
||||
|
||||
// 2. If integer is -∞ or +∞ , then
|
||||
if (Value(integer).is_infinity()) {
|
||||
|
@ -211,11 +208,8 @@ ThrowCompletionOr<double> to_integer_throw_on_infinity(VM& vm, Value argument, E
|
|||
template<typename... Args>
|
||||
ThrowCompletionOr<double> to_integer_without_rounding(VM& vm, Value argument, ErrorType error_type, Args... args)
|
||||
{
|
||||
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));
|
||||
auto number = TRY(argument.to_number(vm));
|
||||
|
||||
// 2. If number is NaN, +0𝔽, or -0𝔽, return 0.
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
|
|
|
@ -106,7 +106,7 @@ ThrowCompletionOr<Vector<String>> calendar_fields(VM& vm, Object& calendar, Vect
|
|||
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));
|
||||
auto fields = TRY(Value(&calendar).get_method(vm, vm.names.fields));
|
||||
|
||||
// 2. Let fieldsArray be CreateArrayFromList(fieldNames).
|
||||
auto field_names_values = MarkedVector<Value> { vm.heap() };
|
||||
|
@ -136,7 +136,7 @@ ThrowCompletionOr<Object*> calendar_merge_fields(VM& vm, Object& calendar, Objec
|
|||
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));
|
||||
auto* merge_fields = TRY(Value(&calendar).get_method(vm, vm.names.mergeFields));
|
||||
|
||||
// 2. If mergeFields is undefined, then
|
||||
if (!merge_fields) {
|
||||
|
@ -168,13 +168,13 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value
|
|||
|
||||
// 4. If dateAdd is not present, set dateAdd to ? GetMethod(calendar, "dateAdd").
|
||||
if (!date_add)
|
||||
date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
|
||||
date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// 5. Let addedDate be ? Call(dateAdd, calendar, « date, duration, options »).
|
||||
auto added_date = TRY(call(global_object, date_add ?: js_undefined(), &calendar, date, &duration, options ?: js_undefined()));
|
||||
|
||||
// 6. Perform ? RequireInternalSlot(addedDate, [[InitializedTemporalDate]]).
|
||||
auto* added_date_object = TRY(added_date.to_object(global_object));
|
||||
auto* added_date_object = TRY(added_date.to_object(vm));
|
||||
if (!is<PlainDate>(added_date_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainDate");
|
||||
|
||||
|
@ -192,13 +192,13 @@ ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value
|
|||
|
||||
// 2. If dateUntil is not present, set dateUntil to ? GetMethod(calendar, "dateUntil").
|
||||
if (!date_until)
|
||||
date_until = TRY(Value(&calendar).get_method(global_object, vm.names.dateUntil));
|
||||
date_until = TRY(Value(&calendar).get_method(vm, vm.names.dateUntil));
|
||||
|
||||
// 3. Let duration be ? Call(dateUntil, calendar, « one, two, options »).
|
||||
auto duration = TRY(call(global_object, date_until ?: js_undefined(), &calendar, one, two, &options));
|
||||
|
||||
// 4. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
||||
auto* duration_object = TRY(duration.to_object(global_object));
|
||||
auto* duration_object = TRY(duration.to_object(vm));
|
||||
if (!is<Duration>(duration_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.Duration");
|
||||
|
||||
|
@ -209,13 +209,10 @@ ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value
|
|||
// 12.2.8 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
|
||||
ThrowCompletionOr<double> calendar_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
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 »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.year, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.year, &date_like));
|
||||
|
||||
// 3. If result is undefined, throw a RangeError exception.
|
||||
if (result.is_undefined())
|
||||
|
@ -228,13 +225,10 @@ ThrowCompletionOr<double> calendar_year(VM& vm, Object& calendar, Object& date_l
|
|||
// 12.2.9 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth
|
||||
ThrowCompletionOr<double> calendar_month(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
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 »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.month, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.month, &date_like));
|
||||
|
||||
// NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
|
||||
if (result.is_undefined())
|
||||
|
@ -247,32 +241,26 @@ ThrowCompletionOr<double> calendar_month(VM& vm, Object& calendar, Object& date_
|
|||
// 12.2.10 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode
|
||||
ThrowCompletionOr<String> calendar_month_code(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
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 »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.monthCode, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.monthCode, &date_like));
|
||||
|
||||
// 3. If result is undefined, throw a RangeError exception.
|
||||
if (result.is_undefined())
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.monthCode.as_string(), vm.names.undefined.as_string());
|
||||
|
||||
// 4. Return ? ToString(result).
|
||||
return result.to_string(global_object);
|
||||
return result.to_string(vm);
|
||||
}
|
||||
|
||||
// 12.2.11 CalendarDay ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarday
|
||||
ThrowCompletionOr<double> calendar_day(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
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 »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.day, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.day, &date_like));
|
||||
|
||||
// NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
|
||||
if (result.is_undefined())
|
||||
|
@ -285,113 +273,86 @@ ThrowCompletionOr<double> calendar_day(VM& vm, Object& calendar, Object& date_li
|
|||
// 12.2.12 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek
|
||||
ThrowCompletionOr<Value> calendar_day_of_week(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "dayOfWeek", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.dayOfWeek, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.dayOfWeek, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.13 CalendarDayOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofyear
|
||||
ThrowCompletionOr<Value> calendar_day_of_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "dayOfYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.dayOfYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.dayOfYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.14 CalendarWeekOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarweekofyear
|
||||
ThrowCompletionOr<Value> calendar_week_of_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "weekOfYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.weekOfYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.weekOfYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.14 CalendarDaysInWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinweek
|
||||
ThrowCompletionOr<Value> calendar_days_in_week(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "daysInWeek", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.daysInWeek, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.daysInWeek, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.16 CalendarDaysInMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinmonth
|
||||
ThrowCompletionOr<Value> calendar_days_in_month(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "daysInMonth", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.daysInMonth, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.daysInMonth, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.17 CalendarDaysInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinyear
|
||||
ThrowCompletionOr<Value> calendar_days_in_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "daysInYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.daysInYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.daysInYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.18 CalendarMonthsInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthsinyear
|
||||
ThrowCompletionOr<Value> calendar_months_in_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "monthsInYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.monthsInYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.monthsInYear, &date_like));
|
||||
}
|
||||
|
||||
// 12.2.29 CalendarInLeapYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarinleapyear
|
||||
ThrowCompletionOr<Value> calendar_in_leap_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Return ? Invoke(calendar, "inLeapYear", « dateLike »).
|
||||
return TRY(Value(&calendar).invoke(global_object, vm.names.inLeapYear, &date_like));
|
||||
return TRY(Value(&calendar).invoke(vm, vm.names.inLeapYear, &date_like));
|
||||
}
|
||||
|
||||
// 15.6.1.1 CalendarEra ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarera
|
||||
ThrowCompletionOr<Value> calendar_era(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "era", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.era, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.era, &date_like));
|
||||
|
||||
// 3. If result is not undefined, set result to ? ToString(result).
|
||||
if (!result.is_undefined())
|
||||
result = js_string(vm, TRY(result.to_string(global_object)));
|
||||
result = js_string(vm, TRY(result.to_string(vm)));
|
||||
|
||||
// 4. Return result.
|
||||
return result;
|
||||
|
@ -400,13 +361,10 @@ ThrowCompletionOr<Value> calendar_era(VM& vm, Object& calendar, Object& date_lik
|
|||
// 15.6.1.2 CalendarEraYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarerayear
|
||||
ThrowCompletionOr<Value> calendar_era_year(VM& vm, Object& calendar, Object& date_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. Let result be ? Invoke(calendar, "eraYear", « dateLike »).
|
||||
auto result = TRY(Value(&calendar).invoke(global_object, vm.names.eraYear, &date_like));
|
||||
auto result = TRY(Value(&calendar).invoke(vm, vm.names.eraYear, &date_like));
|
||||
|
||||
// 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result).
|
||||
if (!result.is_undefined())
|
||||
|
@ -419,9 +377,6 @@ ThrowCompletionOr<Value> calendar_era_year(VM& vm, Object& calendar, Object& dat
|
|||
// 12.2.20 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
|
||||
ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_like)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If Type(temporalCalendarLike) is Object, then
|
||||
if (temporal_calendar_like.is_object()) {
|
||||
auto& temporal_calendar_like_object = temporal_calendar_like.as_object();
|
||||
|
@ -453,7 +408,7 @@ ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_
|
|||
}
|
||||
|
||||
// 2. Let identifier be ? ToString(temporalCalendarLike).
|
||||
auto identifier = TRY(temporal_calendar_like.to_string(global_object));
|
||||
auto identifier = TRY(temporal_calendar_like.to_string(vm));
|
||||
|
||||
// 3. If IsBuiltinCalendar(identifier) is false, then
|
||||
if (!is_builtin_calendar(identifier)) {
|
||||
|
@ -509,16 +464,13 @@ ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(VM& vm, Object
|
|||
// 12.2.23 CalendarDateFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardatefromfields
|
||||
ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
|
||||
// 2. Let date be ? Invoke(calendar, "dateFromFields", « fields, options »).
|
||||
auto date = TRY(Value(&calendar).invoke(global_object, vm.names.dateFromFields, &fields, options ?: js_undefined()));
|
||||
auto date = TRY(Value(&calendar).invoke(vm, vm.names.dateFromFields, &fields, options ?: js_undefined()));
|
||||
|
||||
// 3. Perform ? RequireInternalSlot(date, [[InitializedTemporalDate]]).
|
||||
auto* date_object = TRY(date.to_object(global_object));
|
||||
auto* date_object = TRY(date.to_object(vm));
|
||||
if (!is<PlainDate>(date_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainDate");
|
||||
|
||||
|
@ -529,16 +481,13 @@ ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM& vm, Object& calendar
|
|||
// 12.2.24 CalendarYearMonthFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearmonthfromfields
|
||||
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
|
||||
// 2. Let yearMonth be ? Invoke(calendar, "yearMonthFromFields", « fields, options »).
|
||||
auto year_month = TRY(Value(&calendar).invoke(global_object, vm.names.yearMonthFromFields, &fields, options ?: js_undefined()));
|
||||
auto year_month = TRY(Value(&calendar).invoke(vm, vm.names.yearMonthFromFields, &fields, options ?: js_undefined()));
|
||||
|
||||
// 3. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
||||
auto* year_month_object = TRY(year_month.to_object(global_object));
|
||||
auto* year_month_object = TRY(year_month.to_object(vm));
|
||||
if (!is<PlainYearMonth>(year_month_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainYearMonth");
|
||||
|
||||
|
@ -549,16 +498,13 @@ ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM& vm, Objec
|
|||
// 12.2.25 CalendarMonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthdayfromfields
|
||||
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(VM& vm, Object& calendar, Object const& fields, Object const* options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If options is not present, set options to undefined.
|
||||
|
||||
// 2. Let monthDay be ? Invoke(calendar, "monthDayFromFields", « fields, options »).
|
||||
auto month_day = TRY(Value(&calendar).invoke(global_object, vm.names.monthDayFromFields, &fields, options ?: js_undefined()));
|
||||
auto month_day = TRY(Value(&calendar).invoke(vm, vm.names.monthDayFromFields, &fields, options ?: js_undefined()));
|
||||
|
||||
// 3. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
||||
auto* month_day_object = TRY(month_day.to_object(global_object));
|
||||
auto* month_day_object = TRY(month_day.to_object(vm));
|
||||
if (!is<PlainMonthDay>(month_day_object))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Temporal.PlainMonthDay");
|
||||
|
||||
|
@ -587,18 +533,15 @@ 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(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;
|
||||
|
||||
// 2. Let calendarOne be ? ToString(one).
|
||||
auto calendar_one = TRY(Value(&one).to_string(global_object));
|
||||
auto calendar_one = TRY(Value(&one).to_string(vm));
|
||||
|
||||
// 3. Let calendarTwo be ? ToString(two).
|
||||
auto calendar_two = TRY(Value(&two).to_string(global_object));
|
||||
auto calendar_two = TRY(Value(&two).to_string(vm));
|
||||
|
||||
// 4. If calendarOne is calendarTwo, return true.
|
||||
if (calendar_one == calendar_two)
|
||||
|
@ -611,18 +554,15 @@ ThrowCompletionOr<bool> calendar_equals(VM& vm, Object& one, Object& two)
|
|||
// 12.2.28 ConsolidateCalendars ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-consolidatecalendars
|
||||
ThrowCompletionOr<Object*> consolidate_calendars(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 two.
|
||||
if (&one == &two)
|
||||
return &two;
|
||||
|
||||
// 2. Let calendarOne be ? ToString(one).
|
||||
auto calendar_one = TRY(Value(&one).to_string(global_object));
|
||||
auto calendar_one = TRY(Value(&one).to_string(vm));
|
||||
|
||||
// 3. Let calendarTwo be ? ToString(two).
|
||||
auto calendar_two = TRY(Value(&two).to_string(global_object));
|
||||
auto calendar_two = TRY(Value(&two).to_string(vm));
|
||||
|
||||
// 4. If calendarOne is calendarTwo, return two.
|
||||
if (calendar_one == calendar_two)
|
||||
|
@ -706,9 +646,6 @@ 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(VM& vm, Object const& fields)
|
||||
{
|
||||
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.
|
||||
|
||||
// 2. Let month be ! Get(fields, "month").
|
||||
|
@ -745,7 +682,7 @@ ThrowCompletionOr<double> resolve_iso_month(VM& vm, Object const& fields)
|
|||
auto number_part = month_code_string.substring(1);
|
||||
|
||||
// 9. Set numberPart to ! ToIntegerOrInfinity(numberPart).
|
||||
auto number_part_integer = MUST(Value(js_string(vm, move(number_part))).to_integer_or_infinity(global_object));
|
||||
auto number_part_integer = MUST(Value(js_string(vm, move(number_part))).to_integer_or_infinity(vm));
|
||||
|
||||
// 10. If numberPart < 1 or numberPart > 12, throw a RangeError exception.
|
||||
if (number_part_integer < 1 || number_part_integer > 12)
|
||||
|
@ -970,7 +907,7 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& f
|
|||
for (auto& key : fields_keys) {
|
||||
// a. If key is not "month" or "monthCode", then
|
||||
if (key.as_string().string() != vm.names.month.as_string() && key.as_string().string() != vm.names.monthCode.as_string()) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// i. Let propValue be ? Get(fields, key).
|
||||
auto prop_value = TRY(fields.get(property_key));
|
||||
|
@ -991,7 +928,7 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& f
|
|||
|
||||
// 5. For each element key of additionalFieldsKeys, do
|
||||
for (auto& key : additional_fields_keys) {
|
||||
auto property_key = MUST(PropertyKey::from_value(global_object, key));
|
||||
auto property_key = MUST(PropertyKey::from_value(vm, key));
|
||||
|
||||
// a. Let propValue be ? Get(additionalFields, key).
|
||||
auto prop_value = TRY(additional_fields.get(property_key));
|
||||
|
|
|
@ -45,10 +45,9 @@ ThrowCompletionOr<Value> CalendarConstructor::call()
|
|||
ThrowCompletionOr<Object*> CalendarConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Set id to ? ToString(id).
|
||||
auto identifier = TRY(vm.argument(0).to_string(global_object));
|
||||
auto identifier = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 3. If IsBuiltinCalendar(id) is false, then
|
||||
if (!is_builtin_calendar(identifier)) {
|
||||
|
|
|
@ -70,7 +70,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::id_getter)
|
|||
auto* calendar = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(calendar).
|
||||
return { js_string(vm, TRY(Value(calendar).to_string(global_object))) };
|
||||
return { js_string(vm, TRY(Value(calendar).to_string(vm))) };
|
||||
}
|
||||
|
||||
// 12.4.4 Temporal.Calendar.prototype.dateFromFields ( fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.datefromfields
|
||||
|
@ -575,10 +575,10 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::merge_fields)
|
|||
auto* calendar = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Set fields to ? ToObject(fields).
|
||||
auto* fields = TRY(vm.argument(0).to_object(global_object));
|
||||
auto* fields = TRY(vm.argument(0).to_object(vm));
|
||||
|
||||
// 4. Set additionalFields to ? ToObject(additionalFields).
|
||||
auto* additional_fields = TRY(vm.argument(1).to_object(global_object));
|
||||
auto* additional_fields = TRY(vm.argument(1).to_object(vm));
|
||||
|
||||
// 5. Assert: calendar.[[Identifier]] is "iso8601".
|
||||
VERIFY(calendar->identifier() == "iso8601"sv);
|
||||
|
@ -606,7 +606,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json)
|
|||
auto* calendar = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(calendar).
|
||||
return js_string(vm, TRY(Value(calendar).to_string(global_object)));
|
||||
return js_string(vm, TRY(Value(calendar).to_string(vm)));
|
||||
}
|
||||
|
||||
// 15.6.2.6 Temporal.Calendar.prototype.era ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.era
|
||||
|
|
|
@ -139,13 +139,10 @@ ThrowCompletionOr<Duration*> to_temporal_duration(VM& vm, Value item)
|
|||
// 7.5.9 ToTemporalDurationRecord ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
|
||||
ThrowCompletionOr<DurationRecord> to_temporal_duration_record(VM& vm, Value temporal_duration_like)
|
||||
{
|
||||
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()) {
|
||||
// a. Let string be ? ToString(temporalDurationLike).
|
||||
auto string = TRY(temporal_duration_like.to_string(global_object));
|
||||
auto string = TRY(temporal_duration_like.to_string(vm));
|
||||
|
||||
// b. Return ? ParseTemporalDurationString(string).
|
||||
return parse_temporal_duration_string(vm, string);
|
||||
|
@ -566,7 +563,6 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(VM& vm, double days, doub
|
|||
ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to)
|
||||
{
|
||||
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)) {
|
||||
|
@ -615,10 +611,10 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
|
|||
}
|
||||
|
||||
// b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
|
||||
auto* date_add = TRY(Value(calendar).get_method(global_object, vm.names.dateAdd));
|
||||
auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// c. Let dateUntil be ? GetMethod(calendar, "dateUntil").
|
||||
auto* date_until = TRY(Value(calendar).get_method(global_object, vm.names.dateUntil));
|
||||
auto* date_until = TRY(Value(calendar).get_method(vm, vm.names.dateUntil));
|
||||
|
||||
// d. Repeat, while years ≠ 0,
|
||||
while (years != 0) {
|
||||
|
@ -750,7 +746,6 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
|
|||
ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to_value)
|
||||
{
|
||||
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)) {
|
||||
|
@ -848,13 +843,13 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
|
|||
}
|
||||
|
||||
// i. Let dateAdd be ? GetMethod(calendar, "dateAdd").
|
||||
auto* date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
|
||||
auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// j. Set newRelativeTo to ? CalendarDateAdd(calendar, relativeTo, oneYear, undefined, dateAdd).
|
||||
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));
|
||||
auto* date_until = TRY(Value(&calendar).get_method(vm, vm.names.dateUntil));
|
||||
|
||||
// l. Let untilOptions be OrdinaryObjectCreate(null).
|
||||
auto* until_options = Object::create(realm, nullptr);
|
||||
|
@ -971,7 +966,6 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
|
|||
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& 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); }));
|
||||
|
||||
|
@ -1014,7 +1008,7 @@ ThrowCompletionOr<DurationRecord> add_duration(VM& vm, double years1, double mon
|
|||
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));
|
||||
auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// e. Let intermediate be ? CalendarDateAdd(calendar, relativeTo, dateDuration1, undefined, dateAdd).
|
||||
auto* intermediate = TRY(calendar_date_add(vm, calendar, &relative_to, *date_duration1, nullptr, date_add));
|
||||
|
@ -1102,7 +1096,6 @@ ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(VM& vm, ZonedDat
|
|||
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& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
Object* calendar = nullptr;
|
||||
double fractional_seconds = 0;
|
||||
|
@ -1196,7 +1189,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
|
|||
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));
|
||||
auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// c. Let yearsLater be ? CalendarDateAdd(calendar, relativeTo, yearsDuration, undefined, dateAdd).
|
||||
auto* years_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_duration, nullptr, date_add));
|
||||
|
@ -1286,7 +1279,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
|
|||
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));
|
||||
auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// c. Let yearsMonthsLater be ? CalendarDateAdd(calendar, relativeTo, yearsMonths, undefined, dateAdd).
|
||||
auto* years_months_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_months, nullptr, date_add));
|
||||
|
|
|
@ -75,9 +75,6 @@ ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_
|
|||
// 8.5.3 ToTemporalInstant ( item ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalinstant
|
||||
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
|
||||
|
@ -96,7 +93,7 @@ ThrowCompletionOr<Instant*> to_temporal_instant(VM& vm, Value item)
|
|||
}
|
||||
|
||||
// 2. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 3. Let epochNanoseconds be ? ParseTemporalInstant(string).
|
||||
auto* epoch_nanoseconds = TRY(parse_temporal_instant(vm, string));
|
||||
|
|
|
@ -52,10 +52,9 @@ ThrowCompletionOr<Value> InstantConstructor::call()
|
|||
ThrowCompletionOr<Object*> InstantConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Let epochNanoseconds be ? ToBigInt(epochNanoseconds).
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
||||
|
@ -84,7 +83,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds)
|
||||
{
|
||||
// 1. Set epochSeconds to ? ToNumber(epochSeconds).
|
||||
auto epoch_seconds_value = TRY(vm.argument(0).to_number(global_object));
|
||||
auto epoch_seconds_value = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 2. Set epochSeconds to ? NumberToBigInt(epochSeconds).
|
||||
auto* epoch_seconds = TRY(number_to_bigint(global_object, epoch_seconds_value));
|
||||
|
@ -104,7 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds)
|
||||
{
|
||||
// 1. Set epochMilliseconds to ? ToNumber(epochMilliseconds).
|
||||
auto epoch_milliseconds_value = TRY(vm.argument(0).to_number(global_object));
|
||||
auto epoch_milliseconds_value = TRY(vm.argument(0).to_number(vm));
|
||||
|
||||
// 2. Set epochMilliseconds to ? NumberToBigInt(epochMilliseconds).
|
||||
auto* epoch_milliseconds = TRY(number_to_bigint(global_object, epoch_milliseconds_value));
|
||||
|
@ -124,7 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds)
|
||||
{
|
||||
// 1. Set epochMicroseconds to ? ToBigInt(epochMicroseconds).
|
||||
auto* epoch_microseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_microseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 2. Let epochNanoseconds be epochMicroseconds × 1000ℤ.
|
||||
auto* epoch_nanoseconds = js_bigint(vm, epoch_microseconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000 }));
|
||||
|
@ -141,7 +140,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds)
|
|||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_nanoseconds)
|
||||
{
|
||||
// 1. Set epochNanoseconds to ? ToBigInt(epochNanoseconds).
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 2. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
||||
|
|
|
@ -83,9 +83,6 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_
|
|||
// 3.5.2 ToTemporalDate ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldate
|
||||
ThrowCompletionOr<PlainDate*> to_temporal_date(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
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.
|
||||
|
||||
|
@ -143,7 +140,7 @@ ThrowCompletionOr<PlainDate*> to_temporal_date(VM& vm, Value item, Object const*
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// 5. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 6. Let result be ? ParseTemporalDateString(string).
|
||||
auto result = TRY(parse_temporal_date_string(vm, string));
|
||||
|
@ -419,9 +416,6 @@ 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(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.
|
||||
|
||||
|
@ -435,7 +429,7 @@ ThrowCompletionOr<String> temporal_date_to_string(VM& vm, PlainDate& temporal_da
|
|||
auto day = String::formatted("{:02}", temporal_date.iso_day());
|
||||
|
||||
// 6. Let calendarID be ? ToString(temporalDate.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&temporal_date.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&temporal_date.calendar()).to_string(vm));
|
||||
|
||||
// 7. Let calendar be ! FormatCalendarAnnotation(calendarID, showCalendar).
|
||||
auto calendar = format_calendar_annotation(calendar_id, show_calendar);
|
||||
|
|
|
@ -127,9 +127,6 @@ ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(VM& vm, Objec
|
|||
// 5.5.4 ToTemporalDateTime ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetime
|
||||
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
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.
|
||||
|
||||
|
@ -189,7 +186,7 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(VM& vm, Value item, Obje
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// b. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// c. Let result be ? ParseTemporalDateTimeString(string).
|
||||
result = TRY(parse_temporal_date_time_string(vm, string));
|
||||
|
@ -274,9 +271,6 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year
|
|||
// 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(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).
|
||||
|
@ -289,7 +283,7 @@ ThrowCompletionOr<String> temporal_date_time_to_string(VM& vm, i32 iso_year, u8
|
|||
auto seconds = format_seconds_string_part(second, millisecond, microsecond, nanosecond, precision);
|
||||
|
||||
// 8. Let calendarID be ? ToString(calendar).
|
||||
auto calendar_id = TRY(calendar.to_string(global_object));
|
||||
auto calendar_id = TRY(calendar.to_string(vm));
|
||||
|
||||
// 9. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
|
||||
auto calendar_string = format_calendar_annotation(calendar_id, show_calendar);
|
||||
|
|
|
@ -36,9 +36,6 @@ 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(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
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.
|
||||
|
||||
|
@ -122,7 +119,7 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(VM& vm, Value item, Obje
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// 6. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 7. Let result be ? ParseTemporalMonthDayString(string).
|
||||
auto result = TRY(parse_temporal_month_day_string(vm, string));
|
||||
|
@ -179,9 +176,6 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month
|
|||
// 10.5.3 TemporalMonthDayToString ( monthDay, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalmonthdaytostring
|
||||
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.
|
||||
|
||||
|
@ -191,7 +185,7 @@ ThrowCompletionOr<String> temporal_month_day_to_string(VM& vm, PlainMonthDay& mo
|
|||
auto result = String::formatted("{:02}-{:02}", month_day.iso_month(), month_day.iso_day());
|
||||
|
||||
// 6. Let calendarID be ? ToString(monthDay.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&month_day.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&month_day.calendar()).to_string(vm));
|
||||
|
||||
// 7. If showCalendar is "always" or if calendarID is not "iso8601", then
|
||||
if (show_calendar == "always"sv || calendar_id != "iso8601"sv) {
|
||||
|
|
|
@ -77,9 +77,6 @@ TimeDurationRecord difference_time(VM& vm, u8 hour1, u8 minute1, u8 second1, u16
|
|||
// 4.5.2 ToTemporalTime ( item [ , overflow ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltime
|
||||
ThrowCompletionOr<PlainTime*> to_temporal_time(VM& vm, Value item, Optional<StringView> overflow)
|
||||
{
|
||||
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())
|
||||
overflow = "constrain"sv;
|
||||
|
@ -124,7 +121,7 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(VM& vm, Value item, Optional<Stri
|
|||
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));
|
||||
auto calendar_identifier = TRY(Value(calendar).to_string(vm));
|
||||
if (calendar_identifier != "iso8601"sv) {
|
||||
// i. Throw a RangeError exception.
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarIdentifier, calendar_identifier);
|
||||
|
@ -139,7 +136,7 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(VM& vm, Value item, Optional<Stri
|
|||
// 4. Else,
|
||||
else {
|
||||
// a. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// b. Let result be ? ParseTemporalTimeString(string).
|
||||
result = TRY(parse_temporal_time_string(vm, string));
|
||||
|
|
|
@ -35,9 +35,6 @@ 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(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
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.
|
||||
|
||||
|
@ -68,7 +65,7 @@ ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(VM& vm, Value item, Ob
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// 5. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// 6. Let result be ? ParseTemporalYearMonthString(string).
|
||||
auto result = TRY(parse_temporal_year_month_string(vm, string));
|
||||
|
@ -220,9 +217,6 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_ye
|
|||
// 9.5.7 TemporalYearMonthToString ( yearMonth, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalyearmonthtostring
|
||||
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.
|
||||
|
||||
|
@ -232,7 +226,7 @@ ThrowCompletionOr<String> temporal_year_month_to_string(VM& vm, PlainYearMonth&
|
|||
auto result = String::formatted("{}-{:02}", pad_iso_year(year_month.iso_year()), year_month.iso_month());
|
||||
|
||||
// 6. Let calendarID be ? ToString(yearMonth.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&year_month.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&year_month.calendar()).to_string(vm));
|
||||
|
||||
// 7. If showCalendar is "always" or if calendarID is not "iso8601", then
|
||||
if (show_calendar == "always"sv || calendar_id != "iso8601") {
|
||||
|
@ -311,7 +305,6 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(VM& vm, Differ
|
|||
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& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let duration be ? ToTemporalDuration(temporalDurationLike).
|
||||
auto* duration = TRY(to_temporal_duration(vm, temporal_duration_like));
|
||||
|
@ -373,7 +366,7 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
|
|||
|
||||
// 16. For each element entry of entries, do
|
||||
for (auto& entry : entries) {
|
||||
auto key = MUST(entry.as_array().get_without_side_effects(0).to_property_key(global_object));
|
||||
auto key = MUST(entry.as_array().get_without_side_effects(0).to_property_key(vm));
|
||||
auto value = entry.as_array().get_without_side_effects(1);
|
||||
|
||||
// a. Perform ! CreateDataPropertyOrThrow(optionsCopy, entry[0], entry[1]).
|
||||
|
|
|
@ -418,9 +418,6 @@ 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(VM& vm, Value temporal_time_zone_like)
|
||||
{
|
||||
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()) {
|
||||
// a. If temporalTimeZoneLike has an [[InitializedTemporalZonedDateTime]] internal slot, then
|
||||
|
@ -444,7 +441,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
|
|||
}
|
||||
|
||||
// 2. Let identifier be ? ToString(temporalTimeZoneLike).
|
||||
auto identifier = TRY(temporal_time_zone_like.to_string(global_object));
|
||||
auto identifier = TRY(temporal_time_zone_like.to_string(vm));
|
||||
|
||||
// 3. Let parseResult be ? ParseTemporalTimeZoneString(identifier).
|
||||
auto parse_result = TRY(parse_temporal_time_zone_string(vm, identifier));
|
||||
|
@ -483,7 +480,7 @@ ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, In
|
|||
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));
|
||||
auto* get_offset_nanoseconds_for = TRY(time_zone.get_method(vm, vm.names.getOffsetNanosecondsFor));
|
||||
|
||||
// 2. Let offsetNanoseconds be ? Call(getOffsetNanosecondsFor, timeZone, « instant »).
|
||||
auto offset_nanoseconds_value = TRY(call(global_object, get_offset_nanoseconds_for, time_zone, &instant));
|
||||
|
@ -674,7 +671,7 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu
|
|||
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
|
||||
|
||||
// 2. Let possibleInstants be ? Invoke(timeZone, "getPossibleInstantsFor", « dateTime »).
|
||||
auto possible_instants = TRY(time_zone.invoke(global_object, vm.names.getPossibleInstantsFor, &date_time));
|
||||
auto possible_instants = TRY(time_zone.invoke(vm, vm.names.getPossibleInstantsFor, &date_time));
|
||||
|
||||
// 3. Let iteratorRecord be ? GetIterator(possibleInstants, sync).
|
||||
auto iterator = TRY(get_iterator(global_object, possible_instants, IteratorHint::Sync));
|
||||
|
@ -716,18 +713,15 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu
|
|||
// 11.6.17 TimeZoneEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-timezoneequals
|
||||
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;
|
||||
|
||||
// 2. Let timeZoneOne be ? ToString(one).
|
||||
auto time_zone_one = TRY(Value(&one).to_string(global_object));
|
||||
auto time_zone_one = TRY(Value(&one).to_string(vm));
|
||||
|
||||
// 3. Let timeZoneTwo be ? ToString(two).
|
||||
auto time_zone_two = TRY(Value(&two).to_string(global_object));
|
||||
auto time_zone_two = TRY(Value(&two).to_string(vm));
|
||||
|
||||
// 4. If timeZoneOne is timeZoneTwo, return true.
|
||||
if (time_zone_one == time_zone_two)
|
||||
|
|
|
@ -45,10 +45,9 @@ ThrowCompletionOr<Value> TimeZoneConstructor::call()
|
|||
ThrowCompletionOr<Object*> TimeZoneConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Set identifier to ? ToString(identifier).
|
||||
auto identifier = TRY(vm.argument(0).to_string(global_object));
|
||||
auto identifier = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 3. Let parseResult be ParseText(StringToCodePoints(identifier), TimeZoneNumericUTCOffset).
|
||||
// 4. If parseResult is a List of errors, then
|
||||
|
|
|
@ -52,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::id_getter)
|
|||
auto* time_zone = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(timeZone).
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(global_object)));
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(vm)));
|
||||
}
|
||||
|
||||
// 11.4.4 Temporal.TimeZone.prototype.getOffsetNanosecondsFor ( instant ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getoffsetnanosecondsfor
|
||||
|
@ -243,7 +243,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_json)
|
|||
auto* time_zone = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return ? ToString(timeZone).
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(global_object)));
|
||||
return js_string(vm, TRY(Value(time_zone).to_string(vm)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -120,9 +120,6 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(VM& vm, i32 year
|
|||
// 6.5.2 ToTemporalZonedDateTime ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalzoneddatetime
|
||||
ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item, Object const* options)
|
||||
{
|
||||
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.
|
||||
|
||||
|
@ -179,7 +176,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
// k. Else,
|
||||
else {
|
||||
// i. Set offsetString to ? ToString(offsetString).
|
||||
offset_string = TRY(offset_string_value.to_string(global_object));
|
||||
offset_string = TRY(offset_string_value.to_string(vm));
|
||||
}
|
||||
|
||||
// l. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
|
||||
|
@ -191,7 +188,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
(void)TRY(to_temporal_overflow(vm, options));
|
||||
|
||||
// b. Let string be ? ToString(item).
|
||||
auto string = TRY(item.to_string(global_object));
|
||||
auto string = TRY(item.to_string(vm));
|
||||
|
||||
// c. Let result be ? ParseTemporalZonedDateTimeString(string).
|
||||
auto parsed_result = TRY(parse_temporal_zoned_date_time_string(vm, string));
|
||||
|
@ -293,9 +290,6 @@ ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM& vm, BigInt
|
|||
// 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(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;
|
||||
|
@ -352,14 +346,14 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM& vm, ZonedDateTi
|
|||
// 13. Else,
|
||||
else {
|
||||
// a. Let timeZoneID be ? ToString(timeZone).
|
||||
auto time_zone_id = TRY(Value(&time_zone).to_string(global_object));
|
||||
auto time_zone_id = TRY(Value(&time_zone).to_string(vm));
|
||||
|
||||
// b. Let timeZoneString be the string-concatenation of the code unit 0x005B (LEFT SQUARE BRACKET), timeZoneID, and the code unit 0x005D (RIGHT SQUARE BRACKET).
|
||||
time_zone_string = String::formatted("[{}]", time_zone_id);
|
||||
}
|
||||
|
||||
// 14. Let calendarID be ? ToString(zonedDateTime.[[Calendar]]).
|
||||
auto calendar_id = TRY(Value(&zoned_date_time.calendar()).to_string(global_object));
|
||||
auto calendar_id = TRY(Value(&zoned_date_time.calendar()).to_string(vm));
|
||||
|
||||
// 15. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
|
||||
auto calendar_string = format_calendar_annotation(calendar_id, show_calendar);
|
||||
|
|
|
@ -51,10 +51,9 @@ ThrowCompletionOr<Value> ZonedDateTimeConstructor::call()
|
|||
ThrowCompletionOr<Object*> ZonedDateTimeConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
// 2. Set epochNanoseconds to ? ToBigInt(epochNanoseconds).
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(global_object));
|
||||
auto* epoch_nanoseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||
|
||||
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue