nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.81k stars 29.16k forks source link

`structuredClone` Serializing a non-serializable platform object succeeds #55120

Open RedYetiDev opened 3 days ago

RedYetiDev commented 3 days ago

In Node.js, the following snippet succeeds, whereas, in the browser, it throws a DataCloneError:

structuredClone(new Response());

This is causing the following WPT to fail:

structuredCloneBatteryOfTests.push({
  description: 'Serializing a non-serializable platform object fails',
  async f(runner, t) {
    const request = new Response();
    await promise_rejects_dom(
      t,
      "DataCloneError",
      runner.structuredClone(request)
    );
  }
});
KhafraDev commented 2 days ago

A JavaScript value value is a platform object if Type(value) is Object and if value has a [[PrimaryInterface]] internal slot.

The primary interface of a platform object is the value of the object’s [[PrimaryInterface]] internal slot, which is the most-derived interface that it implements.

Request's webidl declaration does not extend anything, therefore it's a platform object.

Hopefully this may help someone.

KhafraDev commented 2 days ago

@nodejs/web-standards @joyeecheung