capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.08k stars 185 forks source link

Range.compareBoundaryPoints should throw error #1462

Open mozesstumpf opened 3 weeks ago

mozesstumpf commented 3 weeks ago

Describe the bug Range.compareBoundaryPoints should throw error instead of returning -1.

To Reproduce

Repo to reproduce: compare-boundary-points-error

    const text1 = document.createElement("text");
    const text2 = document.createElement("text");

    const range = new Range();
    range.setStart(text1, 0);

    const sourceRange = new Range();
    sourceRange.setStart(text2, 0);

    const position = range.compareBoundaryPoints(
        Range.START_TO_START,
        sourceRange,
    ); // shoud throw an error, since the text1 and text2 are in the different tree

    console.log(position); // -1

Expected behavior Range.compareBoundaryPoints should throw error if the compared ranges' boundary-point's are in different tree.

Documentation: Range.compareBoundaryPoints 2nd point:

If this’s root is not the same as sourceRange’s root, then throw a "WrongDocumentError" DOMException.

Device:

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 AMD Ryzen 5 5600 6-Core Processor
    Memory: 19.36 GB / 31.89 GB
  Binaries:
    Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
    bun: 1.1.10 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (125.0.2535.51)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @vitest/coverage-v8: ^1.6.0 => 1.6.0
    vite: ^5.2.10 => 5.2.10
    vitest: ^1.6.0 => 1.6.0

Additional context The issue was tested on vitest, and it worked well on jsdom, only caused error with happy-dom.