2010-12-05 07:20:34 +08:00
|
|
|
var common = require('../common');
|
2010-12-06 03:15:30 +08:00
|
|
|
var assert = require('assert');
|
2010-06-24 18:17:05 +08:00
|
|
|
|
2010-11-16 10:37:27 +08:00
|
|
|
var Script = require('vm').Script;
|
2010-06-24 18:17:05 +08:00
|
|
|
|
2010-07-16 02:47:25 +08:00
|
|
|
common.debug('run in a new empty context');
|
2010-06-24 18:17:05 +08:00
|
|
|
var context = Script.createContext();
|
|
|
|
var result = Script.runInContext('"passed";', context);
|
|
|
|
assert.equal('passed', result);
|
|
|
|
|
2010-07-16 02:47:25 +08:00
|
|
|
common.debug('create a new pre-populated context');
|
2010-06-24 18:17:05 +08:00
|
|
|
context = Script.createContext({'foo': 'bar', 'thing': 'lala'});
|
|
|
|
assert.equal('bar', context.foo);
|
|
|
|
assert.equal('lala', context.thing);
|
|
|
|
|
2010-07-16 02:47:25 +08:00
|
|
|
common.debug('test updating context');
|
2010-06-24 18:17:05 +08:00
|
|
|
result = Script.runInContext('var foo = 3;', context);
|
|
|
|
assert.equal(3, context.foo);
|
|
|
|
assert.equal('lala', context.thing);
|