Files
node/lib/internal/structured_clone.js
voltrexmaster 3d11bafaa0 lib: make structuredClone spec compliant
Fixes: https://github.com/nodejs/node/issues/40246

PR-URL: https://github.com/nodejs/node/pull/40251
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2021-10-03 15:19:58 +00:00

22 lines
510 B
JavaScript

'use strict';
const {
MessageChannel,
receiveMessageOnPort,
} = require('internal/worker/io');
let channel;
function structuredClone(value, options = undefined) {
// TODO: Improve this with a more efficient solution that avoids
// instantiating a MessageChannel
channel ??= new MessageChannel();
channel.port1.unref();
channel.port2.unref();
channel.port1.postMessage(value, options?.transfer);
return receiveMessageOnPort(channel.port2).message;
}
module.exports = {
structuredClone
};