fix(runtime): honor DataView offset and length in TextDecoder.decode#5172
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes TextDecoder.decode behavior for DataView inputs so decoding respects the view’s byteOffset/byteLength window (instead of decoding the full underlying ArrayBuffer), aligning behavior with the WHATWG Encoding spec and resolving #4767.
Changes:
- Apply
DataView’sbyteOffset+byteLengthslice when decoding inTextDecoder.decode. - Add checked conversion from
u64tousizeforDataViewoffset/length, returning aRangeErrorwhen values are not addressable on the platform. - Add a regression test validating that
new DataView(buffer, 1, 2)decodes only that slice (expects"CE").
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/runtime/src/text/mod.rs | Updates TextDecoder.decode to compute and apply the correct byte range for DataView inputs, with usize conversion checks. |
| core/runtime/src/text/tests.rs | Adds a regression test ensuring DataView offset/length are honored during decoding. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test262 conformance changes
Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5172 +/- ##
===========================================
+ Coverage 47.24% 59.72% +12.47%
===========================================
Files 476 580 +104
Lines 46892 63261 +16369
===========================================
+ Hits 22154 37782 +15628
- Misses 24738 25479 +741 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This Pull Request fixes/closes #4767.
It changes the following:
TextDecoder.decodeforDataViewinputs to apply the view window (byteOffset+byteLength) instead of decoding the full backingArrayBuffer.DataViewoffset/length and returnsRangeErrorif values exceed addressable size.new DataView(buffer, 1, 2)decodes only that slice (expected"CE").Testing:
cargo test -p boa_runtime text::tests— 23 passed, 0 failedcargo fmt --all— passedRepro from issue now returns
"B"instead of"BB":new TextDecoder().decode(new DataView(Uint8Array.of(0x42, 0x42).buffer, 1))Spec reference:
https://encoding.spec.whatwg.org/#dom-textdecoder-decode