LibJS: Read user options in some Temporal toString methods sooner

This is a normative change in the Temporal proposal. See:
3eaaadf
This commit is contained in:
Timothy Flynn 2025-08-28 15:21:19 -04:00 committed by Jelle Raaijmakers
commit 355589a89e
Notes: github-actions[bot] 2025-08-28 23:15:42 +00:00
2 changed files with 10 additions and 10 deletions

View file

@ -268,16 +268,16 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_string)
// 7. Let smallestUnit be ? GetTemporalUnitValuedOption(resolvedOptions, "smallestUnit", UNSET).
auto smallest_unit = TRY(get_temporal_unit_valued_option(vm, resolved_options, vm.names.smallestUnit, Unset {}));
// 8. Perform ? ValidateTemporalUnitValue(smallestUnit, TIME).
// 8. Let timeZone be ? Get(resolvedOptions, "timeZone").
auto time_zone_value = TRY(resolved_options->get(vm.names.timeZone));
// 9. Perform ? ValidateTemporalUnitValue(smallestUnit, TIME).
TRY(validate_temporal_unit_value(vm, vm.names.smallestUnit, smallest_unit, UnitGroup::Time));
// 9. If smallestUnit is HOUR, throw a RangeError exception.
// 10. If smallestUnit is HOUR, throw a RangeError exception.
if (auto const* unit = smallest_unit.get_pointer<Unit>(); unit && *unit == Unit::Hour)
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, temporal_unit_to_string(*unit), vm.names.smallestUnit);
// 10. Let timeZone be ? Get(resolvedOptions, "timeZone").
auto time_zone_value = TRY(resolved_options->get(vm.names.timeZone));
String time_zone_buffer;
Optional<StringView> time_zone;

View file

@ -776,16 +776,16 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_string)
// 9. Let smallestUnit be ? GetTemporalUnitValuedOption(resolvedOptions, "smallestUnit", UNSET).
auto smallest_unit = TRY(get_temporal_unit_valued_option(vm, resolved_options, vm.names.smallestUnit, Unset {}));
// 10. Perform ? ValidateTemporalUnitValue(smallestUnit, TIME).
// 10. Let showTimeZone be ? GetTemporalShowTimeZoneNameOption(resolvedOptions).
auto show_time_zone = TRY(get_temporal_show_time_zone_name_option(vm, resolved_options));
// 11. Perform ? ValidateTemporalUnitValue(smallestUnit, TIME).
TRY(validate_temporal_unit_value(vm, vm.names.smallestUnit, smallest_unit, UnitGroup::Time));
// 11. If smallestUnit is HOUR, throw a RangeError exception.
// 12. If smallestUnit is HOUR, throw a RangeError exception.
if (auto const* unit = smallest_unit.get_pointer<Unit>(); unit && *unit == Unit::Hour)
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, temporal_unit_to_string(*unit), vm.names.smallestUnit);
// 12. Let showTimeZone be ? GetTemporalShowTimeZoneNameOption(resolvedOptions).
auto show_time_zone = TRY(get_temporal_show_time_zone_name_option(vm, resolved_options));
// 13. Let precision be ToSecondsStringPrecisionRecord(smallestUnit, digits).
auto precision = to_seconds_string_precision_record(smallest_unit, digits);