2010-12-03 09:03:18 +08:00
|
|
|
common = require('../common');
|
|
|
|
assert = common.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
|
|
|
var script = new Script('"passed";');
|
|
|
|
|
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(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
|
|
|
script = new Script('foo = 3;');
|
|
|
|
result = script.runInContext(context);
|
|
|
|
assert.equal(3, context.foo);
|
|
|
|
assert.equal('lala', context.thing);
|
2010-08-05 01:20:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Issue GH-227:
|
|
|
|
Script.runInNewContext('', null, 'some.js');
|