mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 12:37:44 +00:00
LibJS: Remove extra property check from Instant#toZonedDateTimeISO
This is a normative change in the Temporal spec.
See: 7dfbd80
This commit is contained in:
parent
f7bb79d6d1
commit
707f12f927
2 changed files with 24 additions and 19 deletions
|
@ -388,34 +388,20 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time)
|
|||
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
|
||||
// 8.3.18 Temporal.Instant.prototype.toZonedDateTimeISO ( timeZone ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tozoneddatetimeiso
|
||||
JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time_iso)
|
||||
{
|
||||
auto item = vm.argument(0);
|
||||
|
||||
// 1. Let instant be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
|
||||
auto* instant = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. If Type(item) is Object, then
|
||||
if (item.is_object()) {
|
||||
// a. Let timeZoneProperty be ? Get(item, "timeZone").
|
||||
auto time_zone_property = TRY(item.as_object().get(vm.names.timeZone));
|
||||
// 3. Set timeZone to ? ToTemporalTimeZone(timeZone).
|
||||
auto* time_zone = TRY(to_temporal_time_zone(vm, vm.argument(0)));
|
||||
|
||||
// b. If timeZoneProperty is not undefined, then
|
||||
if (!time_zone_property.is_undefined()) {
|
||||
// i. Set item to timeZoneProperty.
|
||||
item = time_zone_property;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Let timeZone be ? ToTemporalTimeZone(item).
|
||||
auto* time_zone = TRY(to_temporal_time_zone(vm, item));
|
||||
|
||||
// 5. Let calendar be ! GetISO8601Calendar().
|
||||
// 4. Let calendar be ! GetISO8601Calendar().
|
||||
auto* calendar = get_iso8601_calendar(vm);
|
||||
|
||||
// 6. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, calendar).
|
||||
// 5. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, calendar).
|
||||
return TRY(create_temporal_zoned_date_time(vm, instant->nanoseconds(), *time_zone, *calendar));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,25 @@ describe("correct behavior", () => {
|
|||
const zonedDateTime = instant.toZonedDateTimeISO({ timeZone });
|
||||
expect(zonedDateTime.timeZone).toBe(timeZone);
|
||||
});
|
||||
|
||||
test("avoids extra timeZone property lookup", () => {
|
||||
const instant = new Temporal.Instant(1625614921123456789n);
|
||||
|
||||
let timesGetterCalled = 0;
|
||||
const timeZoneObject = {
|
||||
get timeZone() {
|
||||
timesGetterCalled++;
|
||||
return "UTC";
|
||||
},
|
||||
|
||||
toString() {
|
||||
return "UTC";
|
||||
},
|
||||
};
|
||||
|
||||
instant.toZonedDateTimeISO({ timeZone: timeZoneObject });
|
||||
expect(timesGetterCalled).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue