mirror of
https://github.com/zebrajr/node.git
synced 2025-12-07 12:20:50 +01:00
When the previous set of changes (bfff07b) it was possible to have the
context get garbage collected while sandbox was still live. We need to
tie the lifetime of the context to the lifetime of the sandbox.
This is a backport of #5786 to v5.x.
Ref: https://github.com/nodejs/node/pull/5786
PR-URL: https://github.com/nodejs/node/pull/5800
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
30 lines
860 B
JavaScript
30 lines
860 B
JavaScript
'use strict';
|
|
// Flags: --expose-gc
|
|
require('../common');
|
|
var assert = require('assert');
|
|
|
|
var vm = require('vm');
|
|
|
|
console.error('run in a new empty context');
|
|
var context = vm.createContext();
|
|
var result = vm.runInContext('"passed";', context);
|
|
assert.equal('passed', result);
|
|
|
|
console.error('create a new pre-populated context');
|
|
context = vm.createContext({'foo': 'bar', 'thing': 'lala'});
|
|
assert.equal('bar', context.foo);
|
|
assert.equal('lala', context.thing);
|
|
|
|
console.error('test updating context');
|
|
result = vm.runInContext('var foo = 3;', context);
|
|
assert.equal(3, context.foo);
|
|
assert.equal('lala', context.thing);
|
|
|
|
// https://github.com/nodejs/node/issues/5768
|
|
console.error('run in contextified sandbox without referencing the context');
|
|
var sandbox = {x: 1};
|
|
vm.createContext(sandbox);
|
|
gc();
|
|
vm.runInContext('x = 2', sandbox);
|
|
// Should not crash.
|