diff options
author | Franziska Hinkelmann <franzih@chromium.org> | 2017-02-01 19:57:22 +0100 |
---|---|---|
committer | Franziska Hinkelmann <franzih@chromium.org> | 2017-02-04 12:23:43 +0100 |
commit | e116cbe3207a471b3d604466baad49b141e32230 (patch) | |
tree | 97d71791f4afdd61e3b1c5a3e88dcac64fb3f774 /test/parallel/test-vm-context.js | |
parent | 0101d77a22bef19830d8f39c3727801513df63a1 (diff) | |
download | android-node-v8-e116cbe3207a471b3d604466baad49b141e32230.tar.gz android-node-v8-e116cbe3207a471b3d604466baad49b141e32230.tar.bz2 android-node-v8-e116cbe3207a471b3d604466baad49b141e32230.zip |
src: don't overwrite non-writable vm globals
Check that the property doesn't have the read-only flag set before
overwriting it.
This is Ben Noordhuis previous commit, but keeping
is_contextual_store. is_contextual_store describes whether
this.foo = 42 or foo = 42 was called. The second is contextual
and will fail in strict mode if foo is used without
declaration. Therefore only do an early return if it is
a contextual store. In particular, don't do an early
return for Object.defineProperty(this, ...).
Fixes: https://github.com/nodejs/node/issues/10223
Refs: https://github.com/nodejs/node/pull/10227
PR-URL: https://github.com/nodejs/node/pull/11109
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'test/parallel/test-vm-context.js')
-rw-r--r-- | test/parallel/test-vm-context.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 75d91ce812..c58bdc29da 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -75,3 +75,16 @@ 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, 42); +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); |