Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from decentralion/enumerable-globals
Browse files Browse the repository at this point in the history
ensure that globals includes process and console
  • Loading branch information
pierrec authored Jul 6, 2019
2 parents ae48528 + 758db14 commit 5135bfb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = function (content, filename, scope, includeGlobals) {

if (includeGlobals) {
merge(sandbox, global)
// console is non-enumerable in node v10 and above
sandbox.console = global.console
// process is non-enumerable in node v12 and above
sandbox.process = global.process
sandbox.require = requireLike(_filename)
}

Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ assert.throws(function () {
_eval('require("fs")')
})

// Verify that the console is available when globals are passed
res = _eval('exports.x = console', true)
assert.deepEqual(res.x, console)

console.log('All tests passed')

0 comments on commit 5135bfb

Please sign in to comment.