From 74ff804dbdc72d2577bf3c915d4cc2cb87808931 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 20 Jan 2017 19:44:56 +0100 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- .../test-vm-global-non-writable-properties.js | 16 ++++++++++++++++ test/parallel/test-vm-global-assignment.js | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/known_issues/test-vm-global-non-writable-properties.js create mode 100644 test/parallel/test-vm-global-assignment.js diff --git a/test/known_issues/test-vm-global-non-writable-properties.js b/test/known_issues/test-vm-global-non-writable-properties.js new file mode 100644 index 00000000000000..8d7dfce55e3d81 --- /dev/null +++ b/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); diff --git a/test/parallel/test-vm-global-assignment.js b/test/parallel/test-vm-global-assignment.js new file mode 100644 index 00000000000000..3fb3470b4c2a43 --- /dev/null +++ b/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);