From c30c8557fcf4aebba74b0445eb3af6d98aed4ec1 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 8 Nov 2024 11:34:37 -0800 Subject: [PATCH 1/2] Polyfill: Make Date.prototype.toTemporalInstant not a constructor A test for this was recently added to test262. Per the spec text, Date.prototype.toTemporalInstant should not be contstructible. However, the previous implementation did allow it to be called as a constructor. --- polyfill/lib/legacydate.mjs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/polyfill/lib/legacydate.mjs b/polyfill/lib/legacydate.mjs index 4f668396c..4a3232aff 100644 --- a/polyfill/lib/legacydate.mjs +++ b/polyfill/lib/legacydate.mjs @@ -5,7 +5,18 @@ import { Instant } from './instant.mjs'; import bigInt from 'big-integer'; -export function toTemporalInstant() { - const epochNanoseconds = bigInt(ES.Call(DatePrototypeValueOf, this, [])).multiply(1e6); - return new Instant(ES.BigIntIfAvailable(epochNanoseconds)); +// By default, a plain function can be called as a constructor. A method such as +// Date.prototype.toTemporalInstant should not be able to. We could check +// new.target in the body of toTemporalInstant, but that is not sufficient for +// preventing construction when passing it as the newTarget parameter of +// Reflect.construct. So we create it as a method of an otherwise unused class, +// and monkeypatch it onto Date.prototype. + +class LegacyDateImpl { + toTemporalInstant() { + const epochNanoseconds = bigInt(ES.Call(DatePrototypeValueOf, this, [])).multiply(1e6); + return new Instant(ES.BigIntIfAvailable(epochNanoseconds)); + } } + +export const toTemporalInstant = LegacyDateImpl.prototype.toTemporalInstant; From 68099c8882a8d223f7814641dce919eaedd30b28 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 7 Nov 2024 12:23:03 -0800 Subject: [PATCH 2/2] Update test262 --- polyfill/test/expected-failures.txt | 3 +++ polyfill/test262 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/polyfill/test/expected-failures.txt b/polyfill/test/expected-failures.txt index b5f1d0a4b..4da4db4d7 100644 --- a/polyfill/test/expected-failures.txt +++ b/polyfill/test/expected-failures.txt @@ -19,3 +19,6 @@ intl402/DateTimeFormat/proto-from-ctor-realm.js # https://github.com/tc39/ecma402/issues/402 intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js + +# Fails until CLDR 46 (released 2024-10-24) makes its way into a Node.js release +staging/Intl402/Temporal/old/non-iso-calendars.js diff --git a/polyfill/test262 b/polyfill/test262 index e2f2f9248..26a396da1 160000 --- a/polyfill/test262 +++ b/polyfill/test262 @@ -1 +1 @@ -Subproject commit e2f2f9248605906d818d90b26cd0ac8de8466ed0 +Subproject commit 26a396da146c2928b31ee5750f733af5b0dbf023