Commit 9fa4bb66 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ
parent c123ef99
......@@ -228,14 +228,6 @@ TO_BE_IMPLEMENTED(TemporalDurationPrototypeToJSON)
/* Temporal.Instant */
/* Temporal #sec-temporal.instant.from */
TO_BE_IMPLEMENTED(TemporalInstantFrom)
/* Temporal #sec-temporal.instant.fromepochseconds */
TO_BE_IMPLEMENTED(TemporalInstantFromEpochSeconds)
/* Temporal #sec-temporal.instant.fromepochmilliseconds */
TO_BE_IMPLEMENTED(TemporalInstantFromEpochMilliseconds)
/* Temporal #sec-temporal.instant.fromepochmicroseconds */
TO_BE_IMPLEMENTED(TemporalInstantFromEpochMicroseconds)
/* Temporal #sec-temporal.instant.fromepochnanoseconds */
TO_BE_IMPLEMENTED(TemporalInstantFromEpochNanoseconds)
/* Temporal #sec-temporal.instant.compare */
TO_BE_IMPLEMENTED(TemporalInstantCompare)
/* Temporal #sec-temporal.instant.prototype.add */
......@@ -479,6 +471,14 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToLocaleString)
return Smi::FromInt(obj->field()); \
}
#define TEMPORAL_METHOD1(T, METHOD) \
BUILTIN(Temporal##T##METHOD) { \
HandleScope scope(isolate); \
RETURN_RESULT_OR_FAILURE( \
isolate, \
JSTemporal##T ::METHOD(isolate, args.atOrUndefined(isolate, 1))); \
}
#define TEMPORAL_GET(T, METHOD, field) \
BUILTIN(Temporal##T##Prototype##METHOD) { \
HandleScope scope(isolate); \
......@@ -791,6 +791,10 @@ TEMPORAL_VALUE_OF(Duration)
// Instant
TEMPORAL_CONSTRUCTOR1(Instant)
TEMPORAL_METHOD1(Instant, FromEpochSeconds)
TEMPORAL_METHOD1(Instant, FromEpochMilliseconds)
TEMPORAL_METHOD1(Instant, FromEpochMicroseconds)
TEMPORAL_METHOD1(Instant, FromEpochNanoseconds)
TEMPORAL_VALUE_OF(Instant)
TEMPORAL_GET(Instant, EpochNanoseconds, nanoseconds)
TEMPORAL_GET_NUMBER_AFTER_DIVID(Instant, EpochSeconds, nanoseconds, 1000000000,
......
......@@ -5496,5 +5496,92 @@ MaybeHandle<JSTemporalInstant> JSTemporalInstant::Constructor(
epoch_nanoseconds);
}
namespace {
// The logic in Temporal.Instant.fromEpochSeconds and fromEpochMilliseconds,
// are the same except a scaling factor, code all of them into the follow
// function.
MaybeHandle<JSTemporalInstant> ScaleNumberToNanosecondsVerifyAndMake(
Isolate* isolate, Handle<BigInt> bigint, uint32_t scale) {
TEMPORAL_ENTER_FUNC();
DCHECK(scale == 1 || scale == 1000 || scale == 1000000 ||
scale == 1000000000);
// 2. Let epochNanoseconds be epochXseconds × scaleℤ.
Handle<BigInt> epoch_nanoseconds;
if (scale == 1) {
epoch_nanoseconds = bigint;
} else {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, epoch_nanoseconds,
BigInt::Multiply(isolate, BigInt::FromUint64(isolate, scale), bigint),
JSTemporalInstant);
}
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a
// RangeError exception.
if (!IsValidEpochNanoseconds(isolate, epoch_nanoseconds)) {
THROW_NEW_ERROR(isolate, NEW_TEMPORAL_INVALD_ARG_RANGE_ERROR(),
JSTemporalInstant);
}
return temporal::CreateTemporalInstant(isolate, epoch_nanoseconds);
}
MaybeHandle<JSTemporalInstant> ScaleNumberToNanosecondsVerifyAndMake(
Isolate* isolate, Handle<Object> epoch_Xseconds, uint32_t scale) {
TEMPORAL_ENTER_FUNC();
// 1. Set epochXseconds to ? ToNumber(epochXseconds).
ASSIGN_RETURN_ON_EXCEPTION(isolate, epoch_Xseconds,
Object::ToNumber(isolate, epoch_Xseconds),
JSTemporalInstant);
// 2. Set epochMilliseconds to ? NumberToBigInt(epochMilliseconds).
Handle<BigInt> bigint;
ASSIGN_RETURN_ON_EXCEPTION(isolate, bigint,
BigInt::FromNumber(isolate, epoch_Xseconds),
JSTemporalInstant);
return ScaleNumberToNanosecondsVerifyAndMake(isolate, bigint, scale);
}
MaybeHandle<JSTemporalInstant> ScaleToNanosecondsVerifyAndMake(
Isolate* isolate, Handle<Object> epoch_Xseconds, uint32_t scale) {
TEMPORAL_ENTER_FUNC();
// 1. Set epochMicroseconds to ? ToBigInt(epochMicroseconds).
Handle<BigInt> bigint;
ASSIGN_RETURN_ON_EXCEPTION(isolate, bigint,
BigInt::FromObject(isolate, epoch_Xseconds),
JSTemporalInstant);
return ScaleNumberToNanosecondsVerifyAndMake(isolate, bigint, scale);
}
} // namespace
// #sec-temporal.instant.fromepochseconds
MaybeHandle<JSTemporalInstant> JSTemporalInstant::FromEpochSeconds(
Isolate* isolate, Handle<Object> epoch_seconds) {
TEMPORAL_ENTER_FUNC();
return ScaleNumberToNanosecondsVerifyAndMake(isolate, epoch_seconds,
1000000000);
}
// #sec-temporal.instant.fromepochmilliseconds
MaybeHandle<JSTemporalInstant> JSTemporalInstant::FromEpochMilliseconds(
Isolate* isolate, Handle<Object> epoch_milliseconds) {
TEMPORAL_ENTER_FUNC();
return ScaleNumberToNanosecondsVerifyAndMake(isolate, epoch_milliseconds,
1000000);
}
// #sec-temporal.instant.fromepochmicroseconds
MaybeHandle<JSTemporalInstant> JSTemporalInstant::FromEpochMicroseconds(
Isolate* isolate, Handle<Object> epoch_microseconds) {
TEMPORAL_ENTER_FUNC();
return ScaleToNanosecondsVerifyAndMake(isolate, epoch_microseconds, 1000);
}
// #sec-temporal.instant.fromepochnanoeconds
MaybeHandle<JSTemporalInstant> JSTemporalInstant::FromEpochNanoseconds(
Isolate* isolate, Handle<Object> epoch_nanoseconds) {
TEMPORAL_ENTER_FUNC();
return ScaleToNanosecondsVerifyAndMake(isolate, epoch_nanoseconds, 1);
}
} // namespace internal
} // namespace v8
......@@ -103,6 +103,19 @@ class JSTemporalInstant
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> Now(
Isolate* isolate);
// #sec-temporal.instant.fromepochseconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant> FromEpochSeconds(
Isolate* isolate, Handle<Object> epoch_seconds);
// #sec-temporal.instant.fromepochmilliseconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant>
FromEpochMilliseconds(Isolate* isolate, Handle<Object> epoch_milliseconds);
// #sec-temporal.instant.fromepochmicroseconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant>
FromEpochMicroseconds(Isolate* isolate, Handle<Object> epoch_microseconds);
// #sec-temporal.instant.fromepochnanoeconds
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalInstant>
FromEpochNanoseconds(Isolate* isolate, Handle<Object> epoch_nanoseconds);
DECL_PRINTER(JSTemporalInstant)
TQ_OBJECT_CONSTRUCTORS(JSTemporalInstant)
......
......@@ -813,14 +813,6 @@
'built-ins/Temporal/Instant/compare/instant-string': [FAIL],
'built-ins/Temporal/Instant/compare/instant-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Instant/from/argument-zoneddatetime': [FAIL],
'built-ins/Temporal/Instant/fromEpochMicroseconds/basic': [FAIL],
'built-ins/Temporal/Instant/fromEpochMicroseconds/subclassing-ignored': [FAIL],
'built-ins/Temporal/Instant/fromEpochMilliseconds/basic': [FAIL],
'built-ins/Temporal/Instant/fromEpochMilliseconds/subclassing-ignored': [FAIL],
'built-ins/Temporal/Instant/fromEpochNanoseconds/basic': [FAIL],
'built-ins/Temporal/Instant/fromEpochNanoseconds/subclassing-ignored': [FAIL],
'built-ins/Temporal/Instant/fromEpochSeconds/basic': [FAIL],
'built-ins/Temporal/Instant/fromEpochSeconds/subclassing-ignored': [FAIL],
'built-ins/Temporal/Instant/from/instant-string': [FAIL],
'built-ins/Temporal/Instant/from/instant-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Instant/from/subclassing-ignored': [FAIL],
......
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