1'use strict'; 2const { 3 Error, 4 StringPrototypeSplit, 5} = primordials; 6const { 7 messaging_deserialize_symbol, 8 messaging_transfer_symbol, 9 messaging_clone_symbol, 10 messaging_transfer_list_symbol 11} = internalBinding('symbols'); 12const { 13 JSTransferable, 14 setDeserializerCreateObjectFunction 15} = internalBinding('messaging'); 16 17function setup() { 18 // Register the handler that will be used when deserializing JS-based objects 19 // from .postMessage() calls. The format of `deserializeInfo` is generally 20 // 'module:Constructor', e.g. 'internal/fs/promises:FileHandle'. 21 setDeserializerCreateObjectFunction((deserializeInfo) => { 22 const { 0: module, 1: ctor } = StringPrototypeSplit(deserializeInfo, ':'); 23 const Ctor = require(module)[ctor]; 24 if (typeof Ctor !== 'function' || 25 !(Ctor.prototype instanceof JSTransferable)) { 26 // Not one of the official errors because one should not be able to get 27 // here without messing with Node.js internals. 28 // eslint-disable-next-line no-restricted-syntax 29 throw new Error(`Unknown deserialize spec ${deserializeInfo}`); 30 } 31 return new Ctor(); 32 }); 33} 34 35module.exports = { 36 setup, 37 JSTransferable, 38 kClone: messaging_clone_symbol, 39 kDeserialize: messaging_deserialize_symbol, 40 kTransfer: messaging_transfer_symbol, 41 kTransferList: messaging_transfer_list_symbol 42}; 43