Skip to content

Commit c478f28

Browse files
committed
Merge pull request #3771 from mbrio/master
Fix issue #3498
2 parents b70f657 + 8e299b0 commit c478f28

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

lib/coffee-script/coffee-script.js

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coffee-script.coffee

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,17 @@ exports.run = (code, options = {}) ->
124124
# The CoffeeScript REPL uses this to run the input.
125125
exports.eval = (code, options = {}) ->
126126
return unless code = code.trim()
127-
Script = vm.Script
128-
if Script
127+
createContext = vm.Script.createContext ? vm.createContext
128+
129+
isContext = vm.isContext ? (ctx) ->
130+
options.sandbox instanceof createContext().constructor
131+
132+
if createContext
129133
if options.sandbox?
130-
if options.sandbox instanceof Script.createContext().constructor
134+
if isContext options.sandbox
131135
sandbox = options.sandbox
132136
else
133-
sandbox = Script.createContext()
137+
sandbox = createContext()
134138
sandbox[k] = v for own k, v of options.sandbox
135139
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
136140
else
@@ -303,4 +307,3 @@ Error.prepareStackTrace = (err, stack) ->
303307
" at #{formatSourcePosition frame, getSourceMapping}"
304308

305309
"#{err.toString()}\n#{frames.join '\n'}\n"
306-

test/eval.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ if vm = require? 'vm'
1010
eq fhqwhgads, 'global superpower!'
1111

1212
test "CoffeeScript.eval can run in, and modify, a Script context sandbox", ->
13-
sandbox = vm.Script.createContext()
13+
createContext = vm.Script.createContext ? vm.createContext
14+
sandbox = createContext()
1415
sandbox.foo = 'bar'
1516
code = '''
1617
global.foo = 'not bar!'

0 commit comments

Comments
 (0)