Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structuredClone global method #39759

Prev Previous commit
Next Next commit
nits
Ethan-Arrowood committed Aug 13, 2021

Unverified

This user has not yet uploaded their public signing key.
commit d0dedb00b10b029e34af2b1cbe20d5a3fe1cd22d
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -362,6 +362,6 @@ module.exports = {
btoa: 'readable',
atob: 'readable',
performance: 'readable',
structuredClone: 'readable'
structuredClone: 'readable',
},
};
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
@@ -256,7 +256,7 @@ if (!config.noBrowserGlobals) {
defineOperation(globalThis, 'setImmediate', timers.setImmediate);

const {
structuredClone
structuredClone,
} = require('internal/structured_clone');
defineOperation(globalThis, 'structuredClone', structuredClone);
}
6 changes: 2 additions & 4 deletions lib/internal/structured_clone.js
Original file line number Diff line number Diff line change
@@ -2,16 +2,14 @@

const {
MessageChannel,
receiveMessageOnPort
receiveMessageOnPort,
} = require('internal/worker/io');

let channel;
function structuredClone(value, transfer) {
// TODO: Improve this with a more efficient solution that avoids
// instantiating a MessageChannel
if (!channel) {
channel = new MessageChannel();
}
channel ??= new MessageChannel();
channel.port1.unref();
channel.port2.unref();
channel.port1.postMessage(value, transfer);