| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9c6f6b0 commit ed116dc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const vm = require('vm'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + | ||
| 8 | + let base = { | ||
| 9 | + propBase: 1 | ||
| 10 | + }; | ||
| 11 | + | ||
| 12 | + let sandbox = Object.create(base, { | ||
| 13 | + propSandbox: { value: 3 } | ||
| 14 | + }); | ||
| 15 | + | ||
| 16 | + const context = vm.createContext(sandbox); | ||
| 17 | + | ||
| 18 | + let result = vm.runInContext('Object.hasOwnProperty(this, "propBase");', | ||
| 19 | + context); | ||
| 20 | + | ||
| 21 | + assert.strictEqual(result, false); | ||
| 22 | + | ||
| 23 | + // Ref: https://github.com/nodejs/node/issues/5350 | ||
| 24 | + base = Object.create(null); | ||
| 25 | + base.x = 1; | ||
| 26 | + base.y = 2; | ||
| 27 | + | ||
| 28 | + sandbox = Object.create(base); | ||
| 29 | + sandbox.z = 3; | ||
| 30 | + | ||
| 31 | + assert.deepStrictEqual(Object.keys(sandbox), ['z']); | ||
| 32 | + | ||
| 33 | + const code = 'x = 0; z = 4;'; | ||
| 34 | + result = vm.runInNewContext(code, sandbox); | ||
| 35 | + assert.strictEqual(result, 4); | ||
| 36 | + | ||
| 37 | + // Check that y is not an own property. | ||
| 38 | + assert.deepStrictEqual(Object.keys(sandbox), ['z', 'x']); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments