All files / lib/internal structured_clone.js

57.14% Statements 12/21
100% Branches 1/1
0% Functions 0/1
57.14% Lines 12/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2227x 27x 27x 27x 27x 27x 27x 27x                   27x 27x 27x 27x  
'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
};