0

i just want to know how to run eval() in another process (more like a sandbox) so it can't affect global program's variables.

EX:

// program.js

let code  = await prompt('>>> ');
let evalted = eval(code);

console.log(evalted);


// QUESTION/BUG:
// if the inserted code is '>>> console.log = undefined', there will be a 
// ReferenceError (console is not defined) on the main process.

console.log(evalted); // Uncaught ReferenceError: console is not defined
      ^^^
Ramy Hadid
  • 120
  • 6

0 Answers0