| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3f42f96 commit 7a12dd5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const vm = require('vm'); | ||
| 6 | + | ||
| 7 | + const ctx = vm.createContext({ x: 0 }); | ||
| 8 | + | ||
| 9 | + // Global properties should be intercepted in strict mode | ||
| 10 | + vm.runInContext('"use strict"; x = 42', ctx); | ||
| 11 | + assert.strictEqual(ctx.x, 42); | ||
| 12 | + | ||
| 13 | + // Contextual store should only be intercepted in non-strict mode | ||
| 14 | + vm.runInContext('y = 42', ctx); | ||
| 15 | + assert.strictEqual(ctx.y, 42); | ||
| 16 | + | ||
| 17 | + assert.throws(() => vm.runInContext('"use strict"; z = 42', ctx), | ||
| 18 | + /ReferenceError: z is not defined/); | ||
| 19 | + assert.strictEqual(Object.hasOwn(ctx, 'z'), false); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments