Repository navigation
fix: serialize DataView subviews with correct byte offset and length - #166
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: b50f85c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
elliott-with-the-longest-name-on-github
force-pushed
the
fix/dataview-subview
branch
from
July 15, 2026 19:51
cb69e2d to
a2d484d
Compare
A DataView subview (created with a byteOffset/byteLength) was serialized incorrectly in two code paths: - uneval used a nonexistent `startOffset` property, which is `undefined` and coerces to 0 on revival, silently placing the view at the wrong offset. - stringify reused the typed-array branch and emitted `.length`, which is `undefined` for a DataView, producing invalid JSON that fails to parse. Both now emit `byteOffset,byteLength`, matching the `new DataView(buffer, byteOffset, byteLength)` constructor. Adds regression fixtures for both an inline and a named (deduplicated) DataView subview.
elliott-with-the-longest-name-on-github
force-pushed
the
fix/dataview-subview
branch
from
July 15, 2026 19:54
a2d484d to
b50f85c
Compare
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
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.
Problem
Serializing a
DataViewthat is a subview of its buffer (created withnew DataView(buffer, byteOffset, byteLength)) produced incorrect output in two separate code paths:unevalreferencedthing.startOffset— a property that does not exist onDataView. It evaluates toundefined, so the output wasnew DataView(..., undefined, 4). On revival,undefinedcoerces to0, silently placing the view at the wrong offset with no error.stringifyreused the shared typed-array branch and emittedtypedArray.length.DataViewhas no.lengthproperty, so the output was["DataView", 1, 2, undefined]— invalid JSON that throws onparse.Full-buffer DataViews were unaffected (the offset/length arguments are only emitted for subviews), which is why this went unnoticed.
Fix
Both paths now emit
byteOffset, byteLength, matching thenew DataView(buffer, byteOffset, byteLength)constructor signature. Instringify, the shared typed-array/DataView branch now selectsbyteLengthfor DataViews (a byte count) andlengthfor typed arrays (an element count).Tests
Adds regression fixtures for both an inline and a named (deduplicated) DataView subview. Verified that each fixture fails against the unfixed code for the right reason:
unevalfix →uneval: basics "DataView subview"fails with...,undefined,4)vs expected...,2,4).stringifyfix → 6 fixtures acrossstringify/stringifyAsync/stringifyAsync round-tripfail with["DataView",1,2,undefined]vs expected["DataView",1,2,4].With both fixes in place, the full suite passes.