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

ensure that globals includes process and console #18

Merged
merged 1 commit into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')