Skip to content

Expand ECMAScript implementation: Add integer conversions and fundamental operations #12687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 31, 2025

This PR significantly expands the oxc_ecmascript crate by implementing missing ECMAScript abstract operations essential for JavaScript tooling.

What's Added

Integer Conversion Operations (9 total):

  • ToUint32, ToUint16 - Unsigned integer conversions for bitwise operations
  • ToInt8, ToInt16 - Signed integer conversions completing the family
  • ToUint8, ToUint8Clamp - 8-bit conversions for typed arrays (ToUint8Clamp uses banker's rounding)
  • ToLength - Array/string length conversion with MAX_SAFE_INTEGER clamping

Mathematical Operations:

  • MathAbs, MathFloor, MathCeil, MathRound - Core mathematical functions
  • MathMax, MathMin - Comparison operations with helper functions

String Operations:

  • StringSlice - String.prototype.slice with Unicode support
  • StringIncludes - String.prototype.includes with position parameter
  • StringStartsWith, StringEndsWith - String matching operations
  • StringRepeat - String.prototype.repeat with error handling
  • StringTrim, StringTrimStart, StringTrimEnd - Whitespace trimming

Fundamental Operations:

  • SameValue - Strict equality (distinguishes +0/-0, treats NaN as equal to itself)
  • SameValueZero - Like SameValue but treats +0 and -0 as equal

Implementation Details

All operations follow the ECMAScript specification precisely:

  • Proper handling of edge cases (NaN, Infinity, -0/+0)
  • Comprehensive test coverage (32 tests total)
  • Support for multiple numeric types (f64, i32, u32)
  • Unicode-aware string operations
  • Banker's rounding for ToUint8Clamp per specification

This brings oxc_ecmascript much closer to a complete implementation of core ECMAScript abstract operations, making it significantly more useful for JavaScript tooling that needs spec-compliant behavior.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor

graphite-app bot commented Jul 31, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copilot AI and others added 2 commits July 31, 2025 16:33
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
…perations

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
@Boshen
Copy link
Member

Boshen commented Aug 1, 2025

@copilot please continue

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 1, 2025

@copilot please continue

I've continued expanding the ECMAScript implementation by adding 5 more fundamental operations:

New Integer Conversions:

  • ToInt8 and ToInt16 - Complete the signed integer conversion family
  • ToUint8 and ToUint8Clamp - 8-bit unsigned conversions (ToUint8Clamp uses banker's rounding for typed arrays)

Fundamental Operations:

  • ToLength - Array/string length conversion with MAX_SAFE_INTEGER clamping
  • SameValue and SameValueZero - Strict equality comparisons (key difference: SameValue distinguishes +0/-0)

All 32 tests pass, bringing the total from 23 to 32 test functions. These operations are essential building blocks for JavaScript tooling and complete the core integer conversion family used throughout the ECMAScript specification.

ff16191

@Copilot Copilot AI changed the title [WIP] @oxc-project/oxc/files/crates/oxc_ecmascript implements the javascript specification, it contains javascript methods and constant evaluation. Add missing functionalities from the specification. Expand ECMAScript implementation: Add integer conversions and fundamental operations Aug 1, 2025
Copilot finished work on behalf of Boshen August 1, 2025 07:37
Copy link

codspeed-hq bot commented Aug 1, 2025

CodSpeed Instrumentation Performance Report

Merging #12687 will not alter performance

Comparing copilot/fix-9ac53b94-2a10-431e-99dc-59cb76b39b00 (7fd3324) with main (ce5876d)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (e9b9488) during the generation of this report, so ce5876d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants