mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibJS: Implement Temporal.Now
This commit is contained in:
parent
f1c3e3d71a
commit
f2c19f96f8
Notes:
github-actions[bot]
2024-11-25 12:33:55 +00:00
Author: https://github.com/trflynn89
Commit: f2c19f96f8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2557
Reviewed-by: https://github.com/shannonbooth ✅
12 changed files with 252 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <AK/ScopeGuard.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Time.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include <LibJS/Runtime/PromiseCapability.h>
|
||||
#include <LibJS/Runtime/Reference.h>
|
||||
#include <LibJS/Runtime/Symbol.h>
|
||||
#include <LibJS/Runtime/Temporal/Instant.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibJS/SourceTextModule.h>
|
||||
#include <LibJS/SyntheticModule.h>
|
||||
|
@ -181,6 +183,20 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
|
|||
return {};
|
||||
};
|
||||
|
||||
// 2.3.1 HostSystemUTCEpochNanoseconds ( global ), https://tc39.es/proposal-temporal/#sec-hostsystemutcepochnanoseconds
|
||||
host_system_utc_epoch_nanoseconds = [](Object const&) {
|
||||
// 1. Let ns be the approximate current UTC date and time, in nanoseconds since the epoch.
|
||||
Crypto::SignedBigInteger nanoseconds { AK::UnixDateTime::now().nanoseconds_since_epoch() };
|
||||
|
||||
// 2. Return the result of clamping ns between nsMinInstant and nsMaxInstant.
|
||||
if (nanoseconds < Temporal::NANOSECONDS_MIN_INSTANT)
|
||||
nanoseconds = Temporal::NANOSECONDS_MIN_INSTANT;
|
||||
if (nanoseconds > Temporal::NANOSECONDS_MAX_INSTANT)
|
||||
nanoseconds = Temporal::NANOSECONDS_MAX_INSTANT;
|
||||
|
||||
return nanoseconds;
|
||||
};
|
||||
|
||||
// AD-HOC: Inform the host that we received a date string we were unable to parse.
|
||||
host_unrecognized_date_string = [](StringView) {
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue