diff options
author | Rich Trott <rtrott@gmail.com> | 2016-04-14 20:34:24 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-04-17 20:02:46 -0700 |
commit | 15f13cd74a8bb9e62b871076328447b4ead7e8b6 (patch) | |
tree | 1647a93761a4a920f6f6a530b94b829a49358f41 /test/parallel/test-vm-run-in-new-context.js | |
parent | 978166796edb5a867a9152f8a2a1ae35899e4000 (diff) | |
download | android-node-v8-15f13cd74a8bb9e62b871076328447b4ead7e8b6.tar.gz android-node-v8-15f13cd74a8bb9e62b871076328447b4ead7e8b6.tar.bz2 android-node-v8-15f13cd74a8bb9e62b871076328447b4ead7e8b6.zip |
test,vm: enable strict mode for vm tests
Some vm tests are not in strict mode because they need to create and use
global variables. By using `global.foo` instead of just `foo`, we can
still enable strict mode.
PR-URL: https://github.com/nodejs/node/pull/6209
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Diffstat (limited to 'test/parallel/test-vm-run-in-new-context.js')
-rw-r--r-- | test/parallel/test-vm-run-in-new-context.js | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/test/parallel/test-vm-run-in-new-context.js b/test/parallel/test-vm-run-in-new-context.js index 2b32eccf40..1467ea1e17 100644 --- a/test/parallel/test-vm-run-in-new-context.js +++ b/test/parallel/test-vm-run-in-new-context.js @@ -1,16 +1,16 @@ -/* eslint-disable strict */ +'use strict'; // Flags: --expose-gc -var common = require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const common = require('../common'); +const assert = require('assert'); +const vm = require('vm'); assert.equal(typeof gc, 'function', 'Run this test with --expose-gc'); common.globalCheck = false; console.error('run a string'); -var result = vm.runInNewContext('\'passed\';'); +const result = vm.runInNewContext('\'passed\';'); assert.equal('passed', result); console.error('thrown error'); @@ -18,28 +18,28 @@ assert.throws(function() { vm.runInNewContext('throw new Error(\'test\');'); }); -hello = 5; +global.hello = 5; vm.runInNewContext('hello = 2'); -assert.equal(5, hello); +assert.equal(5, global.hello); console.error('pass values in and out'); -code = 'foo = 1;' + - 'bar = 2;' + - 'if (baz !== 3) throw new Error(\'test fail\');'; -foo = 2; -obj = { foo: 0, baz: 3 }; +global.code = 'foo = 1;' + + 'bar = 2;' + + 'if (baz !== 3) throw new Error(\'test fail\');'; +global.foo = 2; +global.obj = { foo: 0, baz: 3 }; /* eslint-disable no-unused-vars */ -var baz = vm.runInNewContext(code, obj); +var baz = vm.runInNewContext(global.code, global.obj); /* eslint-enable no-unused-vars */ -assert.equal(1, obj.foo); -assert.equal(2, obj.bar); -assert.equal(2, foo); +assert.equal(1, global.obj.foo); +assert.equal(2, global.obj.bar); +assert.equal(2, global.foo); console.error('call a function by reference'); -function changeFoo() { foo = 100; } +function changeFoo() { global.foo = 100; } vm.runInNewContext('f()', { f: changeFoo }); -assert.equal(foo, 100); +assert.equal(global.foo, 100); console.error('modify an object by reference'); var f = { a: 1 }; |