Commit 2eee85b
authored
test: add structuredClone suite (opt-in via runStructuredCloneTests) (#26)
* test: add structuredClone suite (opt-in via runStructuredCloneTests)
Covers the WHATWG structuredClone global: primitives (including -0, NaN
and BigInt), plain objects and arrays, Map/Set/Date/RegExp, the wrapper
objects, Error, ArrayBuffer, every typed array and DataView with their
offsets, graph identity and cycles, getter invocation, and the
uncloneable cases.
Transfer coverage asserts both halves of the hand-off: the clone is
usable and the source is detached, for a bare buffer, a buffer reached
through a typed array, and buffers not present in the cloned value.
Rejections cover duplicate entries, non-transferable entries, already
detached buffers, and non-iterable transfer lists.
Failures are asserted by `.name === "DataCloneError"` rather than
`instanceof DOMException`, so the suite runs on runtimes that have no
DOMException. The one runtime-specific expectation (a native object is
not cloneable) is behind the existing isV8iOS guard.
Deliberately kept out of runAllTests(): Android consumes master and does
not ship the global yet, so each runtime opts in once it does.
* test: pin single capture of the transfer iterator next method
WebIDL builds the iterator record once, capturing `next` at creation.
The spec drives iteration with an iterator whose `next` is an accessor
that yields a working function on the first read and throws on any
later one, so an implementation that re-reads `next` per step fails
instead of silently diverging.
* test: cover SharedArrayBuffer sharing and worker message transfer
structuredClone and worker postMessage run on one serialization core, so
the transfer rules are asserted from both entry points: a buffer posted
with a transfer list arrives usable in the worker while the sender's copy
is detached, and duplicate, non-ArrayBuffer and already-detached entries
are rejected with the same DataCloneError name as on the structuredClone
side. postMessage takes a plain array only, so a non-array transfer list
is a TypeError.
The SharedArrayBuffer specs feature-detect the constructor and assert
sharing in both directions -- written through the clone, read through the
original, and back -- plus that one shared buffer stays shared across two
references and that it cannot be transferred.
The worker specs live here rather than in Workers/index.js because this
suite is opt-in: runAllTests() runs on runtimes that have not implemented
postMessage transfer yet.
Also pins the deliberate asymmetry in host-object handling: postMessage
delivers a posted native object as an empty object where structuredClone
rejects it. Workers/index.js already pins that posting one does not
throw; this adds what the receiver actually sees.
* test: gate the shared suite on structuredClone presence
The suite was kept out of runAllTests() and wired in per runtime, which
meant every runtime that shipped the API had to remember to opt in, and
master could not carry the suite at all.
It now checks for the global itself: where structuredClone is missing it
registers one pending spec and returns, so the suite can live in
runAllTests() everywhere and a runtime without the API reports a visible
skip instead of a wall of failures. The named export stays, since it is
still the way to run just this suite.
A gate like this can hide the very regression the suite exists to catch,
so the header points implementing runtimes at the unguarded canary they
are expected to keep in their own tests.1 parent a358473 commit 2eee85b
2 files changed
Lines changed: 746 additions & 0 deletions
0 commit comments