Skip to content

Commit 74ff804

Browse files
addaleaxitaloacasas
authored andcommitted
test: add regression tests for vm bugs
Add the regression test script presented in #10806 to `test/parallel` and re-add the original regression test for #10223 in `test/known_issues`. PR-URL: #10920 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 8a6367c commit 74ff804

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
// https://github.com/nodejs/node/issues/10223
3+
4+
require('../common');
5+
const assert = require('assert');
6+
const vm = require('vm');
7+
8+
const ctx = vm.createContext();
9+
vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx);
10+
assert.strictEqual(ctx.x, undefined); // Not copied out by cloneProperty().
11+
assert.strictEqual(vm.runInContext('x', ctx), 42);
12+
vm.runInContext('x = 0', ctx); // Does not throw but x...
13+
assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered.
14+
assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx),
15+
/Cannot assign to read only property 'x'/);
16+
assert.strictEqual(vm.runInContext('x', ctx), 42);
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
// Regression test for https://github.com/nodejs/node/issues/10806
3+
4+
require('../common');
5+
const assert = require('assert');
6+
const vm = require('vm');
7+
const ctx = vm.createContext({ open() { } });
8+
const window = vm.runInContext('this', ctx);
9+
const other = 123;
10+
11+
assert.notStrictEqual(window.open, other);
12+
window.open = other;
13+
assert.strictEqual(window.open, other);
14+
window.open = other;
15+
assert.strictEqual(window.open, other);

0 commit comments

Comments
 (0)