node-eval icon indicating copy to clipboard operation
node-eval copied to clipboard

Unable to overwrite globals.

Open reggi opened this issue 9 years ago • 0 comments

Here's an example where I'm requiring a file ./global.js Array.marker a property of a global variable is not being updated.

// file eval ./example.js
var _eval = require('eval')
var code = [
  'Array.marker = true',
  "require('./global.js')",
  'console.log(Array.marker)' // => true
].join('\n')

var fileName = __dirname + '/example.js'

_eval(code, fileName, {}, {
  'require': require
})
// file eval ./global.js
var hi = function () {
  Array.marker = false
}
module.exports = hi()

Is there any way to make it so that the required module edits the global value for Array.marker?

Note, I'm replacing requireLike with require. So we can see that it's not requireLike that is causing the issue.

reggi avatar Aug 22 '15 18:08 reggi