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-new-script-this-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-new-script-this-context.js')
-rw-r--r-- | test/parallel/test-vm-new-script-this-context.js | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/test/parallel/test-vm-new-script-this-context.js b/test/parallel/test-vm-new-script-this-context.js index 16d8acd1ca..d225fb0d40 100644 --- a/test/parallel/test-vm-new-script-this-context.js +++ b/test/parallel/test-vm-new-script-this-context.js @@ -1,13 +1,13 @@ -/* eslint-disable strict */ -var common = require('../common'); -var assert = require('assert'); -var Script = require('vm').Script; +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const Script = require('vm').Script; common.globalCheck = false; console.error('run a string'); var script = new Script('\'passed\';'); -var result = script.runInThisContext(script); +const result = script.runInThisContext(script); assert.equal('passed', result); console.error('thrown error'); @@ -16,26 +16,26 @@ assert.throws(function() { script.runInThisContext(script); }); -hello = 5; +global.hello = 5; script = new Script('hello = 2'); script.runInThisContext(script); -assert.equal(2, hello); +assert.equal(2, global.hello); console.error('pass values'); -code = 'foo = 1;' + - 'bar = 2;' + - 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; -foo = 2; -obj = { foo: 0, baz: 3 }; -script = new Script(code); +global.code = 'foo = 1;' + + 'bar = 2;' + + 'if (typeof baz !== "undefined") throw new Error("test fail");'; +global.foo = 2; +global.obj = { foo: 0, baz: 3 }; +script = new Script(global.code); script.runInThisContext(script); -assert.equal(0, obj.foo); -assert.equal(2, bar); -assert.equal(1, foo); +assert.equal(0, global.obj.foo); +assert.equal(2, global.bar); +assert.equal(1, global.foo); console.error('call a function'); -f = function() { foo = 100; }; +global.f = function() { global.foo = 100; }; script = new Script('f()'); script.runInThisContext(script); -assert.equal(100, foo); +assert.equal(100, global.foo); |