Skip to content

[Fix] compare the contents of two DataViews - #113

Open
bardrop wants to merge 1 commit into
inspect-js:mainfrom
bardrop:fix-dataview-contents
Open

bardrop wants to merge 1 commit into
inspect-js:mainfrom
bardrop:fix-dataview-contents

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown

Fixes #112.

DataView had no branch in objEquiv, so two views fell through to the own-keys check. A view has no own keys, so any two DataViews were equal, in loose and strict mode:

deepEqual(new DataView(new Uint8Array([1, 2, 3]).buffer), new DataView(new Uint8Array([4, 5, 6]).buffer)); // true
deepEqual(new DataView(new ArrayBuffer(2)), new DataView(new ArrayBuffer(3)));                             // true

assert.deepEqual / assert.deepStrictEqual say both of these are not equal.

The fix follows the ArrayBuffer branch: brand-check both sides with is-data-view, then compare the bytes each view covers (buffer, byteOffset, byteLength, via data-view-buffer / data-view-byte-offset / data-view-byte-length) as a Uint8Array. Unlike the ArrayBuffer branch it doesn't return true early, so own keys are still compared after the bytes, which matches node (a view with an extra own property is not equal).

I checked each new case against node 24's assert.deepEqual and assert.deepStrictEqual:

  • same contents, different buffers: equal
  • different contents: not equal
  • different byte lengths: not equal
  • two views on one buffer at different offsets, same bytes: equal; different bytes: not equal
  • same contents, one view has an extra own key: not equal
  • a real DataView vs {} tagged DataView: not equal

14 of the new assertions fail on main and all 792 pass with the change. npm run lint is clean; I bumped the inline max-statements / max-lines limits in objEquiv for the 4 new statements, and added DataView to the eslint globals.

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (83701ad) to head (3b2dd37).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #113   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          238       249   +11     
  Branches       100       102    +2     
=========================================
+ Hits           238       249   +11     

☔ View full report in Codecov by Harness.
📢 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.

@bardrop
bardrop force-pushed the fix-dataview-contents branch from 9e64fa5 to 3b2dd37 Compare November 12, 2026 06:06
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.

DataView instances with different contents compare as equal

1 participant