| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 556ebab commit f1d6b04
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const vm = require('vm'); | ||
| 5 | + | ||
| 6 | + // Assert that accessor descriptors are not flattened on the sandbox. | ||
| 7 | + // Issue: https://github.com/nodejs/node/issues/2734 | ||
| 8 | + const sandbox = {}; | ||
| 9 | + vm.createContext(sandbox); | ||
| 10 | + const code = `Object.defineProperty( | ||
| 11 | + this, | ||
| 12 | + 'foo', | ||
| 13 | + { get: function() {return 17} } | ||
| 14 | + ); | ||
| 15 | + var desc = Object.getOwnPropertyDescriptor(this, 'foo');`; | ||
| 16 | + | ||
| 17 | + vm.runInContext(code, sandbox); | ||
| 18 | + assert.strictEqual(typeof sandbox.desc.get, 'function'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,16 +106,3 @@ assert.throws(() => { | |||
| 106 | 106 | // https://github.com/nodejs/node/issues/6158 | |
| 107 | 107 | ctx = new Proxy({}, {}); | |
| 108 | 108 | assert.strictEqual(typeof vm.runInNewContext('String', ctx), 'function'); | |
| 109 | - | ||
| 110 | - // https://github.com/nodejs/node/issues/10223 | ||
| 111 | - ctx = vm.createContext(); | ||
| 112 | - vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx); | ||
| 113 | - assert.strictEqual(ctx.x, 42); | ||
| 114 | - assert.strictEqual(vm.runInContext('x', ctx), 42); | ||
| 115 | - | ||
| 116 | - vm.runInContext('x = 0', ctx); // Does not throw but x... | ||
| 117 | - assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered. | ||
| 118 | - | ||
| 119 | - assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx), | ||
| 120 | - /Cannot assign to read only property 'x'/); | ||
| 121 | - assert.strictEqual(vm.runInContext('x', ctx), 42); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,11 +7,22 @@ const assert = require('assert'); | |||
| 7 | 7 | ||
| 8 | 8 | const context = vm.createContext({}); | |
| 9 | 9 | ||
| 10 | - const code = ` | ||
| 10 | + let code = ` | ||
| 11 | 11 | Object.defineProperty(this, 'foo', {value: 5}); | |
| 12 | 12 | Object.getOwnPropertyDescriptor(this, 'foo'); | |
| 13 | 13 | `; | |
| 14 | 14 | ||
| 15 | - const desc = vm.runInContext(code, context); | ||
| 15 | + let desc = vm.runInContext(code, context); | ||
| 16 | 16 | ||
| 17 | 17 | assert.strictEqual(desc.writable, false); | |
| 18 | + | ||
| 19 | + // Check that interceptors work for symbols. | ||
| 20 | + code = ` | ||
| 21 | + const bar = Symbol('bar'); | ||
| 22 | + Object.defineProperty(this, bar, {value: 6}); | ||
| 23 | + Object.getOwnPropertyDescriptor(this, bar); | ||
| 24 | + `; | ||
| 25 | + | ||
| 26 | + desc = vm.runInContext(code, context); | ||
| 27 | + | ||
| 28 | + assert.strictEqual(desc.value, 6); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,4 +44,4 @@ assert(res); | |||
| 44 | 44 | assert.strictEqual(typeof res, 'object'); | |
| 45 | 45 | assert.strictEqual(res, x); | |
| 46 | 46 | assert.strictEqual(o.f, res); | |
| 47 | - assert.deepStrictEqual(Object.keys(o), ['console', 'x', 'g', 'f']); | ||
| 47 | + assert.deepStrictEqual(Object.keys(o), ['console', 'x', 'f', 'g']); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,6 @@ const vm = require('vm'); | |||
| 7 | 7 | ||
| 8 | 8 | const ctx = vm.createContext(); | |
| 9 | 9 | vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx); | |
| 10 | - assert.strictEqual(ctx.x, undefined); // Not copied out by cloneProperty(). | ||
| 11 | 10 | assert.strictEqual(vm.runInContext('x', ctx), 42); | |
| 12 | 11 | vm.runInContext('x = 0', ctx); // Does not throw but x... | |
| 13 | 12 | assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,10 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - | ||
| 3 | - // Sandbox throws in CopyProperties() despite no code being run | ||
| 4 | - // Issue: https://github.com/nodejs/node/issues/11902 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | 2 | require('../common'); | |
| 8 | 3 | const assert = require('assert'); | |
| 9 | 4 | const vm = require('vm'); | |
| 10 | 5 | ||
| 6 | + // Check that we do not accidentally query attributes. | ||
| 7 | + // Issue: https://github.com/nodejs/node/issues/11902 | ||
| 11 | 8 | const handler = { | |
| 12 | 9 | getOwnPropertyDescriptor: (target, prop) => { | |
| 13 | 10 | throw new Error('whoops'); | |
@@ -16,5 +13,4 @@ const handler = { | |||
| 16 | 13 | const sandbox = new Proxy({ foo: 'bar' }, handler); | |
| 17 | 14 | const context = vm.createContext(sandbox); | |
| 18 | 15 | ||
| 19 | - | ||
| 20 | 16 | assert.doesNotThrow(() => vm.runInContext('', context)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + | ||
| 5 | + const vm = require('vm'); | ||
| 6 | + | ||
| 7 | + // https://github.com/nodejs/node/issues/10223 | ||
| 8 | + const ctx = vm.createContext(); | ||
| 9 | + | ||
| 10 | + // Define x with writable = false. | ||
| 11 | + vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx); | ||
| 12 | + assert.strictEqual(ctx.x, 42); | ||
| 13 | + assert.strictEqual(vm.runInContext('x', ctx), 42); | ||
| 14 | + | ||
| 15 | + vm.runInContext('x = 0', ctx); // Does not throw but x... | ||
| 16 | + assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered. | ||
| 17 | + | ||
| 18 | + assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx), | ||
| 19 | + /Cannot assign to read only property 'x'/); | ||
| 20 | + assert.strictEqual(vm.runInContext('x', ctx), 42); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments