From b0a4df76deec339cf20d16587eef4dcbf2112e36 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 28 Jan 2023 11:12:54 -0500 Subject: [PATCH] LibJS: Define Date constants such that translation units don't copy them Variables that are constexpr must be delcared inline in the global namespace to prevent copying them. The static keyword is meaningless on variables in headers in the global namespace. Declare the static bigint as extern and define it out-of-line instead. --- Userland/Libraries/LibJS/Runtime/Date.cpp | 2 ++ Userland/Libraries/LibJS/Runtime/Date.h | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 7a77a8f499..873671a633 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -21,6 +21,8 @@ static Crypto::SignedBigInteger const s_one_billion_bigint { 1'000'000'000 }; static Crypto::SignedBigInteger const s_one_million_bigint { 1'000'000 }; static Crypto::SignedBigInteger const s_one_thousand_bigint { 1'000 }; +Crypto::SignedBigInteger const ns_per_day_bigint { static_cast(ns_per_day) }; + NonnullGCPtr Date::create(Realm& realm, double date_value) { return realm.heap().allocate(realm, date_value, *realm.intrinsics().date_prototype()); diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h index 2757694c89..c1374e3ede 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.h +++ b/Userland/Libraries/LibJS/Runtime/Date.h @@ -31,22 +31,22 @@ private: }; // https://tc39.es/ecma262/#eqn-HoursPerDay -constexpr double hours_per_day = 24; +constexpr inline double hours_per_day = 24; // https://tc39.es/ecma262/#eqn-MinutesPerHour -constexpr double minutes_per_hour = 60; +constexpr inline double minutes_per_hour = 60; // https://tc39.es/ecma262/#eqn-SecondsPerMinute -constexpr double seconds_per_minute = 60; +constexpr inline double seconds_per_minute = 60; // https://tc39.es/ecma262/#eqn-msPerSecond -constexpr double ms_per_second = 1'000; +constexpr inline double ms_per_second = 1'000; // https://tc39.es/ecma262/#eqn-msPerMinute -constexpr double ms_per_minute = 60'000; +constexpr inline double ms_per_minute = 60'000; // https://tc39.es/ecma262/#eqn-msPerHour -constexpr double ms_per_hour = 3'600'000; +constexpr inline double ms_per_hour = 3'600'000; // https://tc39.es/ecma262/#eqn-msPerDay -constexpr double ms_per_day = 86'400'000; +constexpr inline double ms_per_day = 86'400'000; // https://tc39.es/proposal-temporal/#eqn-nsPerDay -constexpr double ns_per_day = 86'400'000'000'000; -static auto const ns_per_day_bigint = "86400000000000"_sbigint; +constexpr inline double ns_per_day = 86'400'000'000'000; +extern Crypto::SignedBigInteger const ns_per_day_bigint; u16 day_within_year(double); u8 date_from_time(double);