From d159938acc68dd51e80af1f9c89250062b45fa86 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 19 Jul 2021 00:20:34 +0100 Subject: [PATCH] LibJS: Reflect recent editorial changes in the Temporal proposal See: - https://github.com/tc39/proposal-temporal/commit/2148441 - https://github.com/tc39/proposal-temporal/commit/08c04cc - https://github.com/tc39/proposal-temporal/commit/b77da58 --- Userland/Libraries/LibJS/Runtime/DatePrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp | 6 +++++- .../LibJS/Runtime/Temporal/InstantConstructor.cpp | 10 +++++----- .../LibJS/Runtime/Temporal/InstantPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 09e7ed8bbf..ffe3b0e22f 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -874,7 +874,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant) return {}; ns = js_bigint(vm.heap(), ns->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 })); - // 3. Return ? CreateTemporalInstant(ns). + // 3. Return ! CreateTemporalInstant(ns). return Temporal::create_temporal_instant(global_object, *ns); } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp index d4b1c3b6e7..af1d00abdd 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp @@ -96,6 +96,7 @@ Instant* to_temporal_instant(GlobalObject& global_object, Value item) if (vm.exception()) return {}; + // 4. Return ! CreateTemporalInstant(ℤ(epochNanoseconds)). return create_temporal_instant(global_object, *epoch_nanoseconds); } @@ -186,7 +187,10 @@ BigInt* round_temporal_instant(GlobalObject& global_object, BigInt const& nanose } // 7. Else, else { - // a. Let incrementNs be increment. + // a. Assert: unit is "nanosecond". + VERIFY(unit == "nanosecond"); + + // b. Let incrementNs be increment. increment_nanoseconds = increment; } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp index fcc21a45d4..c078f93923 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp @@ -76,7 +76,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from) // 1. If Type(item) is Object and item has an [[InitializedTemporalInstant]] internal slot, then if (item.is_object() && is(item.as_object())) { - // a. Return ? CreateTemporalInstant(item.[[Nanoseconds]]). + // a. Return ! CreateTemporalInstant(item.[[Nanoseconds]]). return create_temporal_instant(global_object, *js_bigint(vm.heap(), static_cast(item.as_object()).nanoseconds().big_integer())); } @@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds) return {}; } - // 5. Return ? CreateTemporalInstant(epochNanoseconds). + // 5. Return ! CreateTemporalInstant(epochNanoseconds). return create_temporal_instant(global_object, *epoch_nanoseconds); } @@ -132,7 +132,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds) return {}; } - // 5. Return ? CreateTemporalInstant(epochNanoseconds). + // 5. Return ! CreateTemporalInstant(epochNanoseconds). return create_temporal_instant(global_object, *epoch_nanoseconds); } @@ -153,7 +153,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds) return {}; } - // 4. Return ? CreateTemporalInstant(epochNanoseconds). + // 4. Return ! CreateTemporalInstant(epochNanoseconds). return create_temporal_instant(global_object, *epoch_nanoseconds); } @@ -171,7 +171,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_nanoseconds) return {}; } - // 3. Return ? CreateTemporalInstant(epochNanoseconds). + // 3. Return ! CreateTemporalInstant(epochNanoseconds). return create_temporal_instant(global_object, *epoch_nanoseconds); } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 583030de93..5341da3d94 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -200,7 +200,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round) if (vm.exception()) return {}; - // 15. Return ? CreateTemporalInstant(roundedNs). + // 15. Return ! CreateTemporalInstant(roundedNs). return create_temporal_instant(global_object, *rounded_ns); } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp index 043af0cafd..fcb44b895a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp @@ -33,14 +33,14 @@ void Now::initialize(GlobalObject& global_object) // 2.1.1 Temporal.now.timeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.timezone JS_DEFINE_NATIVE_FUNCTION(Now::time_zone) { - // 1. Return ? SystemTimeZone(). + // 1. Return ! SystemTimeZone(). return system_time_zone(global_object); } // 2.1.2 Temporal.now.instant ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.instant JS_DEFINE_NATIVE_FUNCTION(Now::instant) { - // 1. Return ? SystemInstant(). + // 1. Return ! SystemInstant(). return system_instant(global_object); } @@ -50,7 +50,7 @@ TimeZone* system_time_zone(GlobalObject& global_object) // 1. Let identifier be ! DefaultTimeZone(). auto identifier = default_time_zone(); - // 2. Return ? CreateTemporalTimeZone(identifier). + // 2. Return ! CreateTemporalTimeZone(identifier). return create_temporal_time_zone(global_object, identifier); } @@ -83,7 +83,7 @@ Instant* system_instant(GlobalObject& global_object) // 1. Let ns be ! SystemUTCEpochNanoseconds(). auto* ns = system_utc_epoch_nanoseconds(global_object); - // 2. Return ? CreateTemporalInstant(ns). + // 2. Return ! CreateTemporalInstant(ns). return create_temporal_instant(global_object, *ns); }