Skip to content

Fix DOM parity gaps found via real-world MDN test scenarios - #49

Merged
eumaninho54 merged 4 commits into
mainfrom
test/real-world-mdn-snippets
Jul 25, 2026
Merged

Fix DOM parity gaps found via real-world MDN test scenarios#49
eumaninho54 merged 4 commits into
mainfrom
test/real-world-mdn-snippets

Conversation

@eumaninho54

@eumaninho54 eumaninho54 commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary

  • Tested the sandbox against real HTML/JS snippets adapted from mdn/dom-examples (URL params, localStorage, insertAdjacent, matchMedia, getBoundingClientRect) and found 3 genuine jsdom-parity gaps
  • document.location was never set (only window.location existed), so scripts using the common document.location.href pattern threw silently inside sandboxed event handlers
  • onchange/oninput/onsubmit/onreset handler properties were never wired to the event system (only onclick/onload/onerror were)
  • insertAdjacentElement()/insertAdjacentText() were missing (only insertAdjacentHTML() existed)
  • Added the real-world scenarios themselves as permanent regression coverage in RealWorld.harness.ts

Test plan

  • tsc --noEmit clean in example/
  • clang++ -fsyntax-only clean on all three touched C++ files
  • yarn --cwd example test:harness:ios / test:harness:android on a real device/simulator

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added insertAdjacentElement() and insertAdjacentText() for inserting elements and text at standard positions.
    • Added inline event handler support for onchange, oninput, onsubmit, and onreset.
    • Added document.location, including URL reading and navigation assignment support.
  • Tests

    • Added coverage for DOM insertion, form events, location behavior, and real-world widget scenarios.

eumaninho54 and others added 4 commits July 25, 2026 00:04
document.location was never set, so scripts using the common
document.location.href pattern threw silently inside sandboxed
event handlers.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Only onclick/onload/onerror were connected to the handler-property
mechanism; assigning el.onchange etc. silently did nothing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Only insertAdjacentHTML existed; these two ChildNode-mixin methods
are common in real-world scripts that insert an existing element or
plain text next to a reference node.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Covers URL-param personalization, localStorage-backed preferences,
insertAdjacentElement-based list growth, matchMedia, and
getBoundingClientRect + CSS custom properties.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

DOM binding extensions

Layer / File(s) Summary
Adjacent insertion APIs
cpp/quickjs/bindings/ElementBindings.cpp, example/src/__harness__/JSDOM.mutation.harness.ts, example/src/__harness__/RealWorld.harness.ts
Adds insertAdjacentElement and insertAdjacentText with four positions, mutation notifications, return values, error handling, and integration coverage.
Inline form and input handlers
cpp/quickjs/bindings/EventBindings.cpp, example/src/__harness__/JSDOM.events.harness.ts, example/src/__harness__/RealWorld.harness.ts
Adds onchange, oninput, onsubmit, and onreset mappings and tests event dispatch, persistence, and media-query handler behavior.
Document location exposure
cpp/quickjs/bindings/WindowBindings.cpp, example/src/__harness__/JSDOM.navigator.harness.ts, example/src/__harness__/RealWorld.harness.ts
Exposes document.location as the existing location object and supports navigation through assignments.
Browser API integration scenarios
example/src/__harness__/RealWorld.harness.ts
Adds scenarios covering URL query rendering and CSS custom-property updates from element geometry.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant JavaScript
  participant ElementBindings
  participant DOMTree
  participant MutationObservers
  JavaScript->>ElementBindings: call insertAdjacentElement or insertAdjacentText
  ElementBindings->>DOMTree: insert node at computed position
  ElementBindings->>MutationObservers: notifyChildList with sibling context
  ElementBindings-->>JavaScript: return inserted element or undefined
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the PR’s DOM parity fixes and MDN-based regression scenarios.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/real-world-mdn-snippets

Comment @coderabbitai help to get the list of available commands.

@eumaninho54
eumaninho54 merged commit 2f7e957 into main Jul 25, 2026
5 checks passed
@eumaninho54
eumaninho54 deleted the test/real-world-mdn-snippets branch July 25, 2026 03:23
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant