1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/eval.coffee
2011-11-08 18:01:45 -05:00

28 lines
No EOL
852 B
CoffeeScript

test "CoffeeScript.eval runs in the global context by default", ->
global.punctuation = '!'
code = '''
global.fhqwhgads = "global superpower#{global.punctuation}"
'''
result = CoffeeScript.eval code
eq result, 'global superpower!'
eq fhqwhgads, 'global superpower!'
test "CoffeeScript.eval can run in, and modify, a Script context sandbox", ->
if vm = require? 'vm'
sandbox = vm.Script.createContext()
sandbox.foo = 'bar'
code = '''
global.foo = 'not bar!'
'''
result = CoffeeScript.eval code, {sandbox}
eq result, 'not bar!'
eq sandbox.foo, 'not bar!'
test "CoffeeScript.eval can run in, but cannot modify, an ordinary object sandbox", ->
sandbox = {foo: 'bar'}
code = '''
global.foo = 'not bar!'
'''
result = CoffeeScript.eval code, {sandbox}
eq result, 'not bar!'
eq sandbox.foo, 'bar'