diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-10-16 00:43:13 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-16 13:40:21 +0200 |
commit | 35c9e324b4248c8953b151cbb89497d5a5afb2ea (patch) | |
tree | 09fd3be70cac8f5e7c49d3ad6bbd895ddac5bdfd /Userland/Libraries/LibJS/Runtime | |
parent | 707f12f9278ae023595d290980790f97d884136a (diff) | |
download | serenity-35c9e324b4248c8953b151cbb89497d5a5afb2ea.zip |
LibJS: Add fast path TimeZone conversion to PlainDate#toZonedDateTime
This is a normative chane in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/fcab1af
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp index e2cbd780bf..2222b1eef1 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp @@ -525,23 +525,33 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_zoned_date_time) // 3. If Type(item) is Object, then if (item.is_object()) { - // a. Let timeZoneLike be ? Get(item, "timeZone"). - auto time_zone_like = TRY(item.as_object().get(vm.names.timeZone)); - - // 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(vm, item)); + // a. If item has an [[InitializedTemporalTimeZone]] internal slot, then + if (is<TimeZone>(item.as_object())) { + // i. Let timeZone be item. + time_zone = &item.as_object(); // ii. Let temporalTime be undefined. } - // c. Else, + // b. Else, else { - // i. Let timeZone be ? ToTemporalTimeZone(timeZoneLike). - 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)); + // i. Let timeZoneLike be ? Get(item, "timeZone"). + auto time_zone_like = TRY(item.as_object().get(vm.names.timeZone)); + + // ii. If timeZoneLike is undefined, then + if (time_zone_like.is_undefined()) { + // 1. Let timeZone be ? ToTemporalTimeZone(item). + time_zone = TRY(to_temporal_time_zone(vm, item)); + + // 2. Let temporalTime be undefined. + } + // iii. Else, + else { + // 1. Let timeZone be ? ToTemporalTimeZone(timeZoneLike). + time_zone = TRY(to_temporal_time_zone(vm, time_zone_like)); + + // 2. Let temporalTime be ? Get(item, "plainTime"). + temporal_time_value = TRY(item.as_object().get(vm.names.plainTime)); + } } } // 4. Else, |