mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 02:42:08 +00:00

PR-URL: https://github.com/nodejs/node/pull/39759 Fixes: https://github.com/nodejs/node/issues/39713 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
22 lines
490 B
JavaScript
22 lines
490 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
MessageChannel,
|
|
receiveMessageOnPort,
|
|
} = require('internal/worker/io');
|
|
|
|
let channel;
|
|
function structuredClone(value, transfer) {
|
|
// 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, transfer);
|
|
return receiveMessageOnPort(channel.port2).message;
|
|
}
|
|
|
|
module.exports = {
|
|
structuredClone
|
|
};
|