Files
scriptc/tests/corpus/2283-structured-clone.cjs
T
Chris Tate 9835ad0d75 Move scriptc to Node 24.22.0
Pin Node v24.22.0 (commit f14cd3aa7bf9, Undici 7.29.1, OpenSSL 3.5.8) in
.node-version, Dockerfile.sandbox, the docs matrix fallback, the
compatibility pin, the fetch profile, and process.version. A node-pin test
checks that these pins agree. The Node compatibility snapshot is
regenerated from the v24.22.0 API docs; the new stream_iter chapter maps
to node:stream/iter, and the SuiteContext rows no longer match the
TestContext evidence.

Runtime and compiler changes follow Node 24.22 behavior:

- fs.read, fs.readSync, and FileHandle.read validate the position before
  the zero-length return.
- fs.statfs results include frsize; Windows reads
  FileFsFullSizeInformation and reports bfree and bavail separately.
- fs.utimes, futimes, and lutimes keep nanosecond precision.
- ServerResponse sets writableFinished where 'finish' is emitted and runs
  end() callbacks before the 'finish' listeners while the socket is still
  attached; a request read to 'end' closes before its response.
- socket.write(string, 'buffer') throws ERR_UNKNOWN_ENCODING.
- URL protocol-setter rejections keep the current URL, the host setter
  no longer leaves a "/." escape when it adds a port to a "//" path, and
  new URLSearchParams(null) parses "null".
- util.stripVTControlCharacters uses Node 24.22's ANSI pattern,
  util.styleText accepts #RGB and #RRGGBB colors, and
  util.types.isDataView has its JS name and length.
- structuredClone and AbortSignal.any use the "cannot be converted to
  sequence" message.
- crypto.getCiphers, getHashes, and constants match Node 24.22.
- dns.lookup, net.connect, and tls.connect throw ERR_INVALID_ARG_VALUE for
  hosts with null bytes.
- fs.readFile validates options.buffer and refuses its valid forms;
  httpValidation and certificateCompression refuse by name.
- url.domainToASCII, url.domainToUnicode, and url.parse hostnames follow
  ada 4.0: ASCII domains are lowercased without checking their xn--
  labels, the RFC 5893 rule checks how LTR labels end and how RTL labels
  start, a Punycode label whose decoded form begins with "xn--" fails, and
  ToUnicode decodes only labels that pass the ToASCII checks. The url
  legacy test cases are regenerated with Node 24.22.

Corpus programs 5275-5279 cover the new behavior. 1640, 2283, 2599, and
3136 are updated where they pinned Node 24.15 output.
2026-10-14 17:27:02 -05:00

29 lines
1.8 KiB
JavaScript

// structuredClone: the JSON-safe + bytes subset clones deep (option
// validation with Node's exact errors, DataCloneError on non-empty
// transfer lists, DOMException per WebIDL serialization), and builtin
// error classes answer instanceof on checked-dynamic values through the
// from_error identity cache.
'use strict';
const assert = require('assert');
assert.throws(() => structuredClone(), { code: 'ERR_MISSING_ARGS' });
assert.throws(() => structuredClone(undefined, ''), { code: 'ERR_INVALID_ARG_TYPE', message: "Failed to execute 'structuredClone': Options cannot be converted to a dictionary" });
assert.throws(() => structuredClone(undefined, 1), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => structuredClone(undefined, { transfer: 1 }), { code: 'ERR_INVALID_ARG_TYPE', message: "Failed to execute 'structuredClone': transfer in Options cannot be converted to sequence." });
assert.throws(() => structuredClone(undefined, { transfer: null }), { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(structuredClone(undefined), undefined);
assert.strictEqual(structuredClone(undefined, null), undefined);
assert.strictEqual(structuredClone(undefined, {}), undefined);
console.log(JSON.stringify(structuredClone({ a: [1, 'x', null], b: { c: true } })));
const orig = { n: 1, arr: [1, 2] };
const copy = structuredClone(orig);
copy.arr.push(3);
console.log(JSON.stringify(orig), JSON.stringify(copy));
const e = new DOMException('t', 'DataCloneError');
const c = structuredClone(e);
console.log(c.name, c.code, c.message, c instanceof DOMException, c instanceof Error);
assert.throws(() => { structuredClone(e, { transfer: [e] }); }, { name: 'DataCloneError' });
function takesAny(x) { return [x instanceof DOMException, x instanceof TypeError, x instanceof Error]; }
console.log(String(takesAny(c)));
console.log(String(takesAny(new TypeError('q'))));
console.log('ok');