diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-10-16 00:29:35 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-16 13:40:21 +0200 |
commit | 707f12f9278ae023595d290980790f97d884136a (patch) | |
tree | 833e502c59e4a77d5327dd1bfa8fc663bddc2244 /Userland/Libraries/LibJS | |
parent | f7bb79d6d16588766fe42f032ca84048bf74bca2 (diff) | |
download | serenity-707f12f9278ae023595d290980790f97d884136a.zip |
LibJS: Remove extra property check from Instant#toZonedDateTimeISO
This is a normative change in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/7dfbd80
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp | 24 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js | 19 |
2 files changed, 24 insertions, 19 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 096b6a0f21..5d530b3aaa 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -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)); - - // 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)); + // 3. Set timeZone to ? ToTemporalTimeZone(timeZone). + auto* time_zone = TRY(to_temporal_time_zone(vm, vm.argument(0))); - // 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)); } diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js index 79fee23a76..956948fcf4 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js @@ -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", () => { |