Skip to content

Commit

Permalink
String for process.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Oct 28, 2023
1 parent cee6072 commit 1a0598b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/trusted/impl/nodejs/nodejsSandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -63,7 +67,7 @@ const nodejsSandbox: ISandbox = async (
);

const errorEventHandler = (e: unknown) => {
worker.terminate();
worker[terminate]();
messageChannel.port1.dispatchEvent(
new MessageEvent('message', {
['data']: [
Expand All @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion src/untrusted/impl/nodejs/nodejsSandboxVm.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down

0 comments on commit 1a0598b

Please sign in to comment.