summaryrefslogtreecommitdiff
path: root/test/parallel/test-vm-context.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2016-12-11 17:28:21 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2016-12-13 13:13:24 +0100
commit524f693872cf453af2655ec47356d25d52394e3d (patch)
treed8f54cae75caad81e075e7267f3dca95b29f6f0f /test/parallel/test-vm-context.js
parent3b2a63065331cc3aa100a332d9732f119ec8ab78 (diff)
downloadandroid-node-v8-524f693872cf453af2655ec47356d25d52394e3d.tar.gz
android-node-v8-524f693872cf453af2655ec47356d25d52394e3d.tar.bz2
android-node-v8-524f693872cf453af2655ec47356d25d52394e3d.zip
src: don't overwrite non-writable vm globals
Check that the property doesn't have the read-only flag set before overwriting it. Fixes: https://github.com/nodejs/node/issues/10223 PR-URL: https://github.com/nodejs/node/pull/10227 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'test/parallel/test-vm-context.js')
-rw-r--r--test/parallel/test-vm-context.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js
index 659a092eb3..d3269d9035 100644
--- a/test/parallel/test-vm-context.js
+++ b/test/parallel/test-vm-context.js
@@ -75,3 +75,14 @@ assert.throws(function() {
// https://github.com/nodejs/node/issues/6158
ctx = new Proxy({}, {});
assert.strictEqual(typeof vm.runInNewContext('String', ctx), 'function');
+
+// https://github.com/nodejs/node/issues/10223
+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);