-
Notifications
You must be signed in to change notification settings - Fork 903
Implement ES2024 Resizable ArrayBuffer #2182
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
Open
anivar
wants to merge
7
commits into
mozilla:master
Choose a base branch
from
anivar:es2024-resizable-arraybuffer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds support for resizable ArrayBuffers as specified in ES2024.
Constructor accepts optional maxByteLength parameter:
new ArrayBuffer(length, { maxByteLength })
New resize() method allows in-place buffer resizing:
- Grows or shrinks buffer up to maxByteLength
- Preserves existing data, zeros new bytes
- Throws TypeError if not resizable or detached
- Throws RangeError if exceeds maxByteLength
New properties:
- resizable: true if buffer has maxByteLength
- maxByteLength: maximum size (equals byteLength for fixed-length)
Includes 22 comprehensive tests covering all functionality and edge cases.
All tests passing.
0bbd0a0 to
088d376
Compare
Removed resizable-arraybuffer from unsupported features list.
Updated test262.properties removing {unsupported: [resizable-arraybuffer]} markers from all passing tests.
gbrail
reviewed
Nov 30, 2025
Collaborator
gbrail
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this and for your patience as we ask lots of questions...
rhino/src/main/java/org/mozilla/javascript/typedarrays/NativeArrayBuffer.java
Outdated
Show resolved
Hide resolved
Address review feedback by using primitive int instead of boxed Integer for maxByteLength field. Uses -1 as sentinel value for fixed-length buffers instead of null. Benefits: - Better performance (no boxing/unboxing overhead) - Less memory usage (no object wrapper) - Follows Rhino coding conventions - More cache-friendly Changes: - NativeArrayBuffer.java: Changed field from Integer to int - Updated all null checks to use -1 sentinel value - All tests passing (Test262SuiteTest + ResizableArrayBuffer tests)
Add support for TypedArray views that dynamically track the length of resizable ArrayBuffers. When a TypedArray is constructed without an explicit length parameter, it now operates in auto-length mode where the length is recomputed based on the current buffer size. Implementation: - Added boolean isAutoLength field to track auto-length mode - Removed final modifier from length field to allow dynamic updates - Created updateLength() method that recomputes length for auto-length views - Length is computed as: floor((bufferByteLength - offset) / elementSize) - Returns 0 when view is out of bounds (offset > buffer length) - updateLength() is called in isTypedArrayOutOfBounds() before bounds checks This approach minimizes code changes while maintaining compatibility with existing code that directly accesses the length field. Per ES2025 specification section 10.4.5.3
- Fix auto-length logic to only apply to resizable ArrayBuffers - Add isResizable() public method to NativeArrayBuffer - Improve JavaDoc to follow Rhino's concise documentation style - Add helper method determineViewLength() for clearer logic - Update test262.properties: 32 additional tests now passing - Array: 4 tests (find family with resize callbacks) - TypedArray: 28 tests (from, of, and prototype methods)
- Updated js_at() to call validateAndGetLength() before accessing elements - Enhanced isTypedArrayOutOfBounds() to check if fixed-length TypedArrays on resizable buffers have gone out of bounds when buffer is resized - Properly throws TypeError when accessing out-of-bounds views per ES2024
TypedArray out-of-bounds checking improvements enable 58 more tests to pass. All return-abrupt-from-this-out-of-bounds tests now passing across TypedArray prototype methods. Fixed-length TypedArray property tests on resizable buffers also passing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements ES2024 Resizable ArrayBuffer and ES2025 auto-length TypedArray views.
ES2024 Resizable ArrayBuffer
Constructor accepts maxByteLength option:
Resizable buffers can grow/shrink in-place:
New properties:
resizable- true if buffer has maxByteLengthmaxByteLength- maximum allowed sizeES2025 Auto-length TypedArrays
TypedArrays on resizable buffers without explicit length track buffer size dynamically:
Fixed-length views throw TypeError when buffer resizes out of bounds:
Implementation
NativeArrayBuffer:
intprimitive for maxByteLength (-1 for fixed-length)NativeTypedArrayView:
isAutoLengthflag for auto-length viewsupdateLength()recalculates length for auto-length viewsisTypedArrayOutOfBounds()validates bounds on resized buffersvalidateAndGetLength()before accessErrors:
Test262 Results
59 tests now passing (227→169 TypedArray failures)
All
return-abrupt-from-this-out-of-boundstests now pass across TypedArray methods: at, copyWithin, entries, every, fill, filter, find, findIndex, findLast, findLastIndex, forEach, includes, indexOf, join, keys, lastIndexOf, map, reduce, reduceRight, reverse, set, slice, some, sort, toLocaleString, values.Fixed-length property tests (byteLength, byteOffset, length) on resizable buffers also passing.