diff --git a/src/trusted/impl/nodejs/nodejsSandbox.ts b/src/trusted/impl/nodejs/nodejsSandbox.ts index e2a8da5..75b2b06 100644 --- a/src/trusted/impl/nodejs/nodejsSandbox.ts +++ b/src/trusted/impl/nodejs/nodejsSandbox.ts @@ -34,6 +34,10 @@ const nodejsSandbox: ISandbox = async ( ); } + // Needed for CC, which is unware of these properties + const on = 'on'; + const terminate = 'terminate'; + const messageChannel = new MessageChannel(); const sandboxId = (0, Math.random)().toFixed(12).slice(2); @@ -63,7 +67,7 @@ const nodejsSandbox: ISandbox = async ( ); const errorEventHandler = (e: unknown) => { - worker.terminate(); + worker[terminate](); messageChannel.port1.dispatchEvent( new MessageEvent('message', { ['data']: [ @@ -89,15 +93,16 @@ const nodejsSandbox: ISandbox = async ( ); onDestroy(); }; + const onDestroy = () => { - worker.on('error', errorEventHandler); - worker.on('exit', exitEventHandler); + worker[on]('error', errorEventHandler); + worker[on]('exit', exitEventHandler); abort?.removeEventListener('abort', onDestroy, false); - worker.terminate(); + worker[terminate](); }; - worker.on('error', errorEventHandler); - worker.on('exit', exitEventHandler); + worker[on]('error', errorEventHandler); + worker[on]('exit', exitEventHandler); abort?.addEventListener('abort', onDestroy, false); diff --git a/src/untrusted/impl/nodejs/nodejsSandboxVm.inline.ts b/src/untrusted/impl/nodejs/nodejsSandboxVm.inline.ts index cbde721..088210d 100644 --- a/src/untrusted/impl/nodejs/nodejsSandboxVm.inline.ts +++ b/src/untrusted/impl/nodejs/nodejsSandboxVm.inline.ts @@ -40,7 +40,11 @@ const { setInterval: g_setInterval, setTimeout: g_setTimeout, } = global; -const close = process.exit.bind(process, 0); + +// Needed for CC +const exit = 'exit'; + +const close = process[exit].bind(process, 0); const getRandomValues = globalThis.crypto.getRandomValues.bind(crypto); const removeAllProperties = (o: unknown, keep?: PropertyKey[]) => {