11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci codes: { ERR_MISSING_ARGS }, 51cb0ef41Sopenharmony_ci} = require('internal/errors'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst { 81cb0ef41Sopenharmony_ci MessageChannel, 91cb0ef41Sopenharmony_ci receiveMessageOnPort, 101cb0ef41Sopenharmony_ci} = require('internal/worker/io'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cilet channel; 131cb0ef41Sopenharmony_cifunction structuredClone(value, options = undefined) { 141cb0ef41Sopenharmony_ci if (arguments.length === 0) { 151cb0ef41Sopenharmony_ci throw new ERR_MISSING_ARGS('value'); 161cb0ef41Sopenharmony_ci } 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci // TODO: Improve this with a more efficient solution that avoids 191cb0ef41Sopenharmony_ci // instantiating a MessageChannel 201cb0ef41Sopenharmony_ci channel ??= new MessageChannel(); 211cb0ef41Sopenharmony_ci channel.port1.unref(); 221cb0ef41Sopenharmony_ci channel.port2.unref(); 231cb0ef41Sopenharmony_ci channel.port1.postMessage(value, options?.transfer); 241cb0ef41Sopenharmony_ci return receiveMessageOnPort(channel.port2).message; 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_cimodule.exports = { 281cb0ef41Sopenharmony_ci structuredClone, 291cb0ef41Sopenharmony_ci}; 30