Browse Source

test: add regression tests for vm bugs

Add the regression test script presented in
https://github.com/nodejs/node/issues/10806 to `test/parallel` and
re-add the original regression test for
https://github.com/nodejs/node/issues/10223 in `test/known_issues`.

PR-URL: https://github.com/nodejs/node/pull/10920
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
v7.x
Anna Henningsen 8 years ago
committed by Italo A. Casas
parent
commit
74ff804dbd
No known key found for this signature in database GPG Key ID: 23EFEFE93C4CFFFE
  1. 16
      test/known_issues/test-vm-global-non-writable-properties.js
  2. 15
      test/parallel/test-vm-global-assignment.js

16
test/known_issues/test-vm-global-non-writable-properties.js

@ -0,0 +1,16 @@
'use strict';
// https://github.com/nodejs/node/issues/10223
require('../common');
const assert = require('assert');
const vm = require('vm');
const ctx = vm.createContext();
vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx);
assert.strictEqual(ctx.x, undefined); // Not copied out by cloneProperty().
assert.strictEqual(vm.runInContext('x', ctx), 42);
vm.runInContext('x = 0', ctx); // Does not throw but x...
assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered.
assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx),
/Cannot assign to read only property 'x'/);
assert.strictEqual(vm.runInContext('x', ctx), 42);

15
test/parallel/test-vm-global-assignment.js

@ -0,0 +1,15 @@
'use strict';
// Regression test for https://github.com/nodejs/node/issues/10806
require('../common');
const assert = require('assert');
const vm = require('vm');
const ctx = vm.createContext({ open() { } });
const window = vm.runInContext('this', ctx);
const other = 123;
assert.notStrictEqual(window.open, other);
window.open = other;
assert.strictEqual(window.open, other);
window.open = other;
assert.strictEqual(window.open, other);
Loading…
Cancel
Save