Skip to content

Sync ecma262 editor updates to polyfill - #3333

Open
ptomato wants to merge 18 commits into
mainfrom
sync-ecma262-editor-updates-to-polyfill
Open

ptomato wants to merge 18 commits into
mainfrom
sync-ecma262-editor-updates-to-polyfill

Conversation

@ptomato

@ptomato ptomato commented Oct 22, 2026

Copy link
Copy Markdown
Member

These commits are refactors in the reference polyfill, which match refactors to the spec requested in round 1 of the editors review in tc39/ecma262#3759. I used this code to verify the spec refactors as I made them, and these edits have been sitting in my local git checkout for a couple of months; they probably belong here, rather than being lost.

@ptomato
ptomato requested a review from gibson042 October 22, 2026 20:17
@ptomato ptomato added the run snapshot tests Add this label to a PR if you want the snapshot tests to run on it. label Oct 22, 2026
@ptomato
ptomato force-pushed the sync-ecma262-editor-updates-to-polyfill branch from 06d012c to caeea69 Compare October 22, 2026 20:26
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.41%. Comparing base (e8cc03f) to head (55574ee).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3333      +/-   ##
==========================================
+ Coverage   98.39%   98.41%   +0.01%     
==========================================
  Files          22       22              
  Lines       10796    10883      +87     
  Branches     1875     1930      +55     
==========================================
+ Hits        10623    10710      +87     
  Misses        161      161              
  Partials       12       12              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ptomato
ptomato force-pushed the sync-ecma262-editor-updates-to-polyfill branch from caeea69 to d94c864 Compare November 10, 2026 00:52
@ptomato

ptomato commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

I removed a few of the commits that I originally included in this PR. I need to look at them some more.

This is in order to validate the spec refactor
Keep functions IsCalendarUnit, IsDateUnit, IsTimeUnit for "is a
(calendar/date/time) unit" respectively.
Also do some of ECMA-262's renames on the "ns1" and "ns2" parameters and
DifferenceInstant → DifferenceEpochNanoseconds.
The GetUTCEpochMilliseconds operation is not in the spec, but the spec's
new ISODateToEpochDays algorithm has comparable performance to the
optimized GetUTCEpochMilliseconds we already had, so we can just use
that.

We can also use it in GetUTCEpochNanoseconds directly, rather than
delegating to GetUTCEpochMilliseconds.
These assertions would previously always pass, because the value being
compared to undefined was always a number (should have been compared to
NaN.) That was a harmless bug but also made the assertions useless.

Not a spec bug.
Adjust expectations to cover expected failures in new tests, and new
passes that have been pulled in with a new Node.js version.
@ptomato
ptomato force-pushed the sync-ecma262-editor-updates-to-polyfill branch from d94c864 to 55574ee Compare November 10, 2026 01:09

@Ms2ger Ms2ger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Comment on lines +201 to +202
if (nonIntHandling === 'truncate') mv = MathTrunc(mv);
if (!IsIntegralNumber(mv)) throw new RangeErrorCtor(`'${property}' must be an integer, not ${arg}`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is written somewhat confusingly. I don't think there's edge cases where Math.trunc returns a non-integral number? But it matches the spec, so fine to keep it

Comment on lines -2827 to +2824
// In the spec, IsValidEpochNanoseconds returns a boolean and call sites are
// responsible for throwing. In the polyfill, ValidateEpochNanoseconds takes its
// place so that we can DRY the throwing code.
// In the spec, IsWithinEpochNanosecondsInterval returns a boolean and call
// sites are responsible for throwing. In the polyfill, ValidateEpochNanoseconds
// takes its place so that we can DRY the throwing code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please split this change into a separate commit rather than the CombineISODateAndTimeRecord one

Comment on lines +2793 to +2794
if (microsecond < 0 || microsecond > 999) return false;
return nanosecond >= 0 && nanosecond <= 999;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not generally a fan of if-return true-else-return false, but I think it'd look better here if the nanosecond check looked the same as the others

const NS_PER_TIME_UNIT = new MapCtor(
Call(ArrayPrototypeFlatMap, TEMPORAL_UNITS, [([, s, , l]) => (l ? [[s, l]] : [])])
);
const NS_PER_TIME_UNIT = new MapCtor(Call(ArrayPrototypeFlatMap, TEMPORAL_UNITS, [([, s, l]) => (l ? [[s, l]] : [])]));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the change, but this feels like a submission to an obfuscated code contest

},
[]
]);
const ALLOWED_UNITS = Call(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (to be changed separately): I don't think this should be in upper snake case

Comment on lines -756 to +769
return GetOption(options, 'overflow', ['constrain', 'reject'], 'constrain');
const value = options.overflow;
if (value === undefined) return 'constrain';
const stringValue = ToString(value);
validateStringValue('overflow', stringValue, ['constrain', 'reject']);
return stringValue;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:/

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run snapshot tests Add this label to a PR if you want the snapshot tests to run on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants