Changeset 286149 in webkit


Ignore:
Timestamp:
Nov 24, 2021 7:45:40 AM (8 months ago)
Author:
commit-queue@webkit.org
Message:

[JSC] Implement Date.prototype.toTemporalInstant()
https://bugs.webkit.org/show_bug.cgi?id=232075

Patch by Aditi Singh <asingh@igalia.com> on 2021-11-24
Reviewed by Yusuke Suzuki.

JSTests:

  • stress/date-to-temporal-instant.js: Added.

(shouldBe):
(shouldThrow):

Source/JavaScriptCore:

  • runtime/CommonIdentifiers.h:
  • runtime/DatePrototype.cpp:

(JSC::DatePrototype::finishCreation):
(JSC::JSC_DEFINE_HOST_FUNCTION):

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r286092 r286149  
     12021-11-24  Aditi Singh  <asingh@igalia.com>
     2
     3        [JSC] Implement Date.prototype.toTemporalInstant()
     4        https://bugs.webkit.org/show_bug.cgi?id=232075
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/date-to-temporal-instant.js: Added.
     9        (shouldBe):
     10        (shouldThrow):
     11
    1122021-11-19  Asumu Takikawa  <asumu@igalia.com>
    213
  • trunk/Source/JavaScriptCore/ChangeLog

    r286138 r286149  
     12021-11-24  Aditi Singh  <asingh@igalia.com>
     2
     3        [JSC] Implement Date.prototype.toTemporalInstant()
     4        https://bugs.webkit.org/show_bug.cgi?id=232075
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * runtime/CommonIdentifiers.h:
     9        * runtime/DatePrototype.cpp:
     10        (JSC::DatePrototype::finishCreation):
     11        (JSC::JSC_DEFINE_HOST_FUNCTION):
     12
    1132021-11-23  Don Olmstead  <don.olmstead@sony.com>
    214
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r285418 r286149  
    252252    macro(toPrecision) \
    253253    macro(toString) \
     254    macro(toTemporalInstant) \
    254255    macro(trailingZeroDisplay) \
    255256    macro(type) \
  • trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp

    r270861 r286149  
    3535#include "JSObject.h"
    3636#include "JSString.h"
     37#include "TemporalInstant.h"
    3738#include <wtf/Assertions.h>
    3839
     
    8081static JSC_DECLARE_HOST_FUNCTION(dateProtoFuncToISOString);
    8182static JSC_DECLARE_HOST_FUNCTION(dateProtoFuncToJSON);
     83static JSC_DECLARE_HOST_FUNCTION(dateProtoFuncToTemporalInstant);
    8284
    8385}
     
    283285    putDirectWithoutTransition(vm, vm.propertyNames->toPrimitiveSymbol, toPrimitiveFunction, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
    284286
     287    if (Options::useTemporal()) {
     288        Identifier toTemporalInstantName = Identifier::fromString(vm, "toTemporalInstant"_s);
     289        JSFunction* toTemporalInstantFunction = JSFunction::create(vm, globalObject, 0, toTemporalInstantName.string(), dateProtoFuncToTemporalInstant);
     290        putDirectWithoutTransition(vm, toTemporalInstantName, toTemporalInstantFunction, static_cast<unsigned>(PropertyAttribute::DontEnum));
     291    }
    285292    // The constructor will be added later, after DateConstructor has been built.
    286293}
     
    905912}
    906913
     914JSC_DEFINE_HOST_FUNCTION(dateProtoFuncToTemporalInstant, (JSGlobalObject* globalObject, CallFrame* callFrame))
     915{
     916    VM& vm = globalObject->vm();
     917    auto scope = DECLARE_THROW_SCOPE(vm);
     918    JSValue thisValue = callFrame->thisValue();
     919    auto* thisDateObj = jsDynamicCast<DateInstance*>(vm, thisValue);
     920    if (UNLIKELY(!thisDateObj))
     921        return throwVMTypeError(globalObject, scope);
     922
     923    double epochMilliseconds = thisDateObj->internalNumber();
     924    if (!isInteger(epochMilliseconds))
     925        return throwVMError(globalObject, scope, createRangeError(globalObject, "Invalid integer number of Epoch Millseconds"_s));
     926
     927    ASSERT(epochMilliseconds >= std::numeric_limits<int64_t>::min() && epochMilliseconds <= std::numeric_limits<int64_t>::max());
     928    ISO8601::ExactTime exactTime = ISO8601::ExactTime::fromEpochMilliseconds(epochMilliseconds);
     929    return JSValue::encode(TemporalInstant::create(vm, globalObject->instantStructure(), exactTime));
     930}
     931
    907932} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.