VM: weird behaviour in runInContext/runInThisContext
While working on my electron based REPL application, I noticed a weird behaviour in vm.runInContext.
Program
Desktop 🙈 ₹ cat repl-vm-strict.js 'use strict'; const vm = require('vm'); const ctx = vm.createContext(); try { const result = vm.runInContext('"use strict"; x = 1', ctx); } catch(e) { console.log(e.stack); console.log('x is', ctx.x) }
Output
Desktop 🙈 ₹ node repl-vm-strict.js ReferenceError: x is not defined at evalmachine.<anonymous>:1:17 at Object.exports.runInContext (vm.js:44:17) at Object.<anonymous> (/Users/princejohnwesley/Desktop/repl-vm-strict.js:7:21) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Function.Module.runMain (module.js:447:10) at startup (node.js:140:18) at node.js:1001:3 x is 1
Behaviour
vm.runInThisContext/vm.runInContextthrows error. ✅- context is also updated as if variable is created with
varorletbinding ❌
Versions
Tested versions: v5.6.0 & v5.1.1
Platform
Desktop 🙈 ₹ uname -a
Darwin Princes-MacBook-Pro.local 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
Subsystem
vm
repl with strict is affected by this issue.