Skip to content

fix(runtime): honor DataView offset and length in TextDecoder.decode#5172

Merged
jedel1043 merged 2 commits into
boa-dev:mainfrom
HiteshShonak:fix/textdecoder-dataview-offset
Mar 20, 2026
Merged

fix(runtime): honor DataView offset and length in TextDecoder.decode#5172
jedel1043 merged 2 commits into
boa-dev:mainfrom
HiteshShonak:fix/textdecoder-dataview-offset

Conversation

@HiteshShonak

Copy link
Copy Markdown
Contributor

This Pull Request fixes/closes #4767.

It changes the following:

  • Updates TextDecoder.decode for DataView inputs to apply the view window (byteOffset + byteLength) instead of decoding the full backing ArrayBuffer.
  • Adds checked conversion for DataView offset/length and returns RangeError if values exceed addressable size.
  • Adds a regression test to verify new DataView(buffer, 1, 2) decodes only that slice (expected "CE").

Testing:

  • cargo test -p boa_runtime text::tests — 23 passed, 0 failed
  • cargo fmt --all — passed

Repro 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

@HiteshShonak HiteshShonak requested a review from a team as a code owner March 20, 2026 02:41
Copilot AI review requested due to automatic review settings March 20, 2026 02:41
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics C-Runtime Issues and PRs related to Boa's runtime features Waiting On Review Waiting on reviews from the maintainers labels Mar 20, 2026
@github-actions github-actions Bot added this to the v1.0.0 milestone Mar 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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’s byteOffset + byteLength slice when decoding in TextDecoder.decode.
  • Add checked conversion from u64 to usize for DataView offset/length, returning a RangeError when 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.

@github-actions

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,079 50,079 0
Ignored 2,072 2,072 0
Failed 812 812 0
Panics 0 0 0
Conformance 94.55% 94.55% 0.00%

Tested main commit: 07ebe591c721307f110cc4b082f03d7d62f4a352
Tested PR commit: 2b3343037aba3ca5df2af8944150699daa2408d6
Compare commits: 07ebe59...2b33430

@codecov

codecov Bot commented Mar 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.72%. Comparing base (6ddc2b4) to head (2b33430).
⚠️ Report is 899 commits behind head on main.

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.
📢 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.

@jedel1043 jedel1043 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@jedel1043 jedel1043 added the A-Bug Something isn't working label Mar 20, 2026
@jedel1043 jedel1043 added this pull request to the merge queue Mar 20, 2026
Merged via the queue into boa-dev:main with commit 118e225 Mar 20, 2026
22 checks passed
@github-actions github-actions Bot removed the Waiting On Review Waiting on reviews from the maintainers label Mar 20, 2026
@jedel1043 jedel1043 removed the C-Builtins PRs and Issues related to builtins/intrinsics label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Bug Something isn't working C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextDecoder does not respect DataView offset and length

3 participants