Skip to content

runtime/binary-data: complete ArrayBuffer/DataView view semantics - #4041

Merged
proggeramlug merged 2 commits into
PerryTS:mainfrom
andrewtdiz:codex/arraybuffer-dataview-semantics
Jun 2, 2026
Merged

proggeramlug merged 2 commits into
PerryTS:mainfrom
andrewtdiz:codex/arraybuffer-dataview-semantics

Conversation

@andrewtdiz

Copy link
Copy Markdown
Contributor

Summary

Fixes #4033 by filling the ordinary ArrayBuffer/DataView semantics needed by binary-heavy packages:

  • add validated ArrayBuffer / SharedArrayBuffer constructor length coercion so huge or negative sizes throw RangeError before truncation/allocation
  • install ArrayBuffer.isView as a real callable static and support value extraction (const isView = ArrayBuffer.isView)
  • install ArrayBuffer.prototype.byteLength as an accessor with brand checks and descriptor metadata
  • keep full-span DataView instances distinct from their backing ArrayBuffer while preserving view registry write propagation
  • recognize direct DataView instances, DataView subclasses, and existing typed views in ArrayBuffer.isView / util.types.isArrayBufferView

DeepWiki

Required reference saved at:

  • target/deepwiki/arraybuffer-dataview-semantics.md

Queried boa-dev/boa for ArrayBuffer constructor/prototype/static surface, ArrayBuffer.isView, DataView internal slot/subclass recognition, byteLength getter descriptors/brand checks, slice bounds/defaults, and avoiding SharedArrayBuffer/resizable scope creep.

Evidence

Base SHA: 132fb26cf461eced3da6bc86e04f680557c49400
Commit: bbf96e3e3

Issue baseline for the requested subset was:

  • pass=40 runtime-fail=40 parity=50.0%

After this change:

scripts/test262_subset.py --root vendor/test262 --dir built-ins/ArrayBuffer built-ins/DataView --max 80 --timeout 8 --sample-cap 20 --report /tmp/perry-c262-arraybuffer-dataview.json

pass           47
diff           0
runtime-fail   33
compile-fail   0
skip           0
judged         80
parity:        58.8%
report:        /tmp/perry-c262-arraybuffer-dataview.json

Focused smoke covered representative #4033 failures:

  • huge ArrayBuffer lengths throw RangeError
  • typeof ArrayBuffer.isView === "function"
  • extracted const isView = ArrayBuffer.isView is callable
  • ArrayBuffer.isView(new DataView(ab)) === true
  • ArrayBuffer.isView(new (class extends DataView {})(ab)) === true
  • ArrayBuffer.isView(ab) === false
  • ArrayBuffer.prototype.byteLength descriptor/getter/brand checks work
  • ab.slice(1).byteLength === 3

Additional commands run:

cargo fmt --all --check
git diff --check
cargo build --release -p perry
cargo build --release -p perry-runtime -p perry-stdlib
PERRY_NO_AUTO_OPTIMIZE=1 target/release/perry run test-files/test_parity_buffer.ts
PERRY_NO_AUTO_OPTIMIZE=1 target/release/perry run test-files/test_gap_fetch_reqresp_2640_2643.ts
PERRY_NO_AUTO_OPTIMIZE=1 target/release/perry run test-files/test_issue_3988_typedarray_static_accessors.ts
PERRY_NO_AUTO_OPTIMIZE=1 target/release/perry run test-files/test_gap_dataview_2878_2877_2879.ts

Residual risks

  • This intentionally avoids SharedArrayBuffer/Atomics, resizable/growable buffers, transfer semantics, and broad TypedArray transform-method work.
  • Remaining c262 failures include broader constructor/prototype descriptor completeness, species/slice edge cases, and typed-array subclass view recognition beyond the DataView subclass recognition fixed here.
  • DataView subclass recognition is modeled for view/brand predicates; this does not attempt a full JS internal-slot object model for arbitrary subclass byte access beyond Perry's existing DataView paths.

@proggeramlug
proggeramlug merged commit a2e6480 into PerryTS:main Jun 2, 2026
11 checks passed
proggeramlug pushed a commit that referenced this pull request Jun 2, 2026
…4041)

The #1103 object.rs split trunk crossed the 2000-line gate on current
main; splitting the cache/root-scanner groups into siblings is tracked
under #1435. Matches the existing global_this/field_get_set/class_registry
allowlist precedent. Unblocks lint for all PRs.
proggeramlug added a commit that referenced this pull request Jun 2, 2026
#3961) (#4048)

* test(buffer): lock Uint8Array.prototype.buffer ArrayBuffer return type (#3961)

* ci(file-size): allowlist object/mod.rs trunk (2 LOC over after #4039-#4041)

The #1103 object.rs split trunk crossed the 2000-line gate on current
main; splitting the cache/root-scanner groups into siblings is tracked
under #1435. Matches the existing global_this/field_get_set/class_registry
allowlist precedent. Unblocks lint for all PRs.

---------

Co-authored-by: Ralph Küpper <ralph@skelpo.com>
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.

runtime/binary-data: complete ArrayBuffer/DataView view and prototype semantics (c262)

2 participants