Commit 600cebb4 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add Date.prototype.toTemporalInstant

Spec Text:
https://tc39.es/proposal-temporal/#sec-date.prototype.totemporalinstant

Bug: v8:11544
Change-Id: I65315152333291f76edc05cc41a528912a185d02
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3609214
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80755}
parent 06d61bd5
......@@ -9,11 +9,13 @@
#include "src/date/dateparser-inl.h"
#include "src/logging/counters.h"
#include "src/numbers/conversions.h"
#include "src/objects/objects-inl.h"
#include "src/objects/bigint.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/intl-objects.h"
#include "src/objects/js-date-time-format.h"
#endif
#include "src/objects/js-temporal-objects-inl.h"
#include "src/objects/objects-inl.h"
#include "src/strings/string-stream.h"
namespace v8 {
......@@ -868,5 +870,23 @@ BUILTIN(DatePrototypeToJson) {
}
}
// Temporal #sec-date.prototype.totemporalinstant
BUILTIN(DatePrototypeToTemporalInstant) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSDate, date, "Date.prototype.toTemporalInstant");
// 1. Let t be ? thisTimeValue(this value).
Handle<BigInt> t;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, t,
BigInt::FromNumber(isolate, Handle<Object>(date->value(), isolate)));
// 2. Let ns be ? NumberToBigInt(t) × 10^6.
Handle<BigInt> ns;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, ns,
BigInt::Multiply(isolate, t, BigInt::FromInt64(isolate, 1000000)));
// 3. Return ! CreateTemporalInstant(ns).
return *temporal::CreateTemporalInstant(isolate, ns).ToHandleChecked();
}
} // namespace internal
} // namespace v8
......@@ -1676,6 +1676,8 @@ namespace internal {
CPP(TemporalCalendarPrototypeToString) \
/* Temporal #sec-temporal.calendar.prototype.tojson */ \
CPP(TemporalCalendarPrototypeToJSON) \
/* Temporal #sec-date.prototype.totemporalinstant */ \
CPP(DatePrototypeToTemporalInstant) \
\
/* "Private" (created but not exposed) Bulitins needed by Temporal */ \
TFJ(StringFixedArrayFromIterable, kJSArgcReceiverSlots, kIterable) \
......
......@@ -5355,6 +5355,18 @@ void Genesis::InitializeGlobal_harmony_temporal() {
#undef INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE
#undef INSTALL_TEMPORAL_FUNC
{ // -- D a t e
// #sec-date.prototype.totemporalinstant
Handle<JSFunction> date_func(native_context()->date_function(), isolate());
// Setup %DatePrototype%.
Handle<JSObject> date_prototype(
JSObject::cast(date_func->instance_prototype()), isolate());
// Install the Date.prototype.toTemporalInstant().
SimpleInstallFunction(isolate_, date_prototype, "toTemporalInstant",
Builtin::kDatePrototypeToTemporalInstant, 0, false);
}
// The StringListFromIterable functions is created but not
// exposed, as it is used internally by CalendarFields.
{
......
......@@ -112,6 +112,7 @@ const funcs = [
"get Temporal.ZonedDateTime.prototype.timeZone",
"get Temporal.ZonedDateTime.prototype.weekOfYear",
"get Temporal.ZonedDateTime.prototype.year",
"Date.prototype.toTemporalInstant ( )",
"Temporal.Calendar.from ( _item_ )",
"Temporal.Calendar ( _id_ )",
"Temporal.Calendar.prototype.dateAdd ( _date_, _duration_ [ , _options_ ] )",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment