Skip to content

Commit d809c84

Browse files
TrottMyles Borins
authored andcommitted
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: #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>
1 parent f3c0b78 commit d809c84

3 files changed

Lines changed: 56 additions & 56 deletions

File tree

‎test/parallel/test-vm-new-script-new-context.js‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
/* eslint-disable strict */
2-
varcommon=require('../common');
3-
varassert=require('assert');
4-
varScript=require('vm').Script;
1+
'use strict';
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
constScript=require('vm').Script;
55

66
common.globalCheck=false;
77

88
console.error('run a string');
99
varscript=newScript('\'passed\';');
1010
console.error('script created');
11-
varresult1=script.runInNewContext();
12-
varresult2=script.runInNewContext();
11+
constresult1=script.runInNewContext();
12+
constresult2=script.runInNewContext();
1313
assert.equal('passed',result1);
1414
assert.equal('passed',result2);
1515

@@ -27,31 +27,31 @@ assert.throws(function() {
2727
},/notdefined/);
2828

2929

30-
hello=5;
30+
global.hello=5;
3131
script=newScript('hello = 2');
3232
script.runInNewContext();
33-
assert.equal(5,hello);
33+
assert.equal(5,global.hello);
3434

3535

3636
console.error('pass values in and out');
37-
code='foo = 1;'+
38-
'bar = 2;'+
39-
'if (baz !== 3) throw new Error(\'test fail\');';
40-
foo=2;
41-
obj={foo: 0,baz: 3};
42-
script=newScript(code);
37+
global.code='foo = 1;'+
38+
'bar = 2;'+
39+
'if (baz !== 3) throw new Error(\'test fail\');';
40+
global.foo=2;
41+
global.obj={foo: 0,baz: 3};
42+
script=newScript(global.code);
4343
/* eslint-disable no-unused-vars */
44-
varbaz=script.runInNewContext(obj);
44+
varbaz=script.runInNewContext(global.obj);
4545
/* eslint-enable no-unused-vars */
46-
assert.equal(1,obj.foo);
47-
assert.equal(2,obj.bar);
48-
assert.equal(2,foo);
46+
assert.equal(1,global.obj.foo);
47+
assert.equal(2,global.obj.bar);
48+
assert.equal(2,global.foo);
4949

5050
console.error('call a function by reference');
5151
script=newScript('f()');
52-
functionchangeFoo(){foo=100;}
52+
functionchangeFoo(){global.foo=100;}
5353
script.runInNewContext({f: changeFoo});
54-
assert.equal(foo,100);
54+
assert.equal(global.foo,100);
5555

5656
console.error('modify an object by reference');
5757
script=newScript('f.a = 2');
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/* eslint-disable strict */
2-
varcommon=require('../common');
3-
varassert=require('assert');
4-
varScript=require('vm').Script;
1+
'use strict';
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
constScript=require('vm').Script;
55

66
common.globalCheck=false;
77

88
console.error('run a string');
99
varscript=newScript('\'passed\';');
10-
varresult=script.runInThisContext(script);
10+
constresult=script.runInThisContext(script);
1111
assert.equal('passed',result);
1212

1313
console.error('thrown error');
@@ -16,26 +16,26 @@ assert.throws(function() {
1616
script.runInThisContext(script);
1717
});
1818

19-
hello=5;
19+
global.hello=5;
2020
script=newScript('hello = 2');
2121
script.runInThisContext(script);
22-
assert.equal(2,hello);
22+
assert.equal(2,global.hello);
2323

2424

2525
console.error('pass values');
26-
code='foo = 1;'+
27-
'bar = 2;'+
28-
'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');';
29-
foo=2;
30-
obj={foo: 0,baz: 3};
31-
script=newScript(code);
26+
global.code='foo = 1;'+
27+
'bar = 2;'+
28+
'if (typeof baz !== "undefined") throw new Error("test fail");';
29+
global.foo=2;
30+
global.obj={foo: 0,baz: 3};
31+
script=newScript(global.code);
3232
script.runInThisContext(script);
33-
assert.equal(0,obj.foo);
34-
assert.equal(2,bar);
35-
assert.equal(1,foo);
33+
assert.equal(0,global.obj.foo);
34+
assert.equal(2,global.bar);
35+
assert.equal(1,global.foo);
3636

3737
console.error('call a function');
38-
f=function(){foo=100;};
38+
global.f=function(){global.foo=100;};
3939
script=newScript('f()');
4040
script.runInThisContext(script);
41-
assert.equal(100,foo);
41+
assert.equal(100,global.foo);

‎test/parallel/test-vm-run-in-new-context.js‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
/* eslint-disable strict */
1+
'use strict';
22
// Flags: --expose-gc
33

4-
varcommon=require('../common');
5-
varassert=require('assert');
6-
varvm=require('vm');
4+
constcommon=require('../common');
5+
constassert=require('assert');
6+
constvm=require('vm');
77

88
assert.equal(typeofgc,'function','Run this test with --expose-gc');
99

1010
common.globalCheck=false;
1111

1212
console.error('run a string');
13-
varresult=vm.runInNewContext('\'passed\';');
13+
constresult=vm.runInNewContext('\'passed\';');
1414
assert.equal('passed',result);
1515

1616
console.error('thrown error');
1717
assert.throws(function(){
1818
vm.runInNewContext('throw new Error(\'test\');');
1919
});
2020

21-
hello=5;
21+
global.hello=5;
2222
vm.runInNewContext('hello = 2');
23-
assert.equal(5,hello);
23+
assert.equal(5,global.hello);
2424

2525

2626
console.error('pass values in and out');
27-
code='foo = 1;'+
28-
'bar = 2;'+
29-
'if (baz !== 3) throw new Error(\'test fail\');';
30-
foo=2;
31-
obj={foo: 0,baz: 3};
27+
global.code='foo = 1;'+
28+
'bar = 2;'+
29+
'if (baz !== 3) throw new Error(\'test fail\');';
30+
global.foo=2;
31+
global.obj={foo: 0,baz: 3};
3232
/* eslint-disable no-unused-vars */
33-
varbaz=vm.runInNewContext(code,obj);
33+
varbaz=vm.runInNewContext(global.code,global.obj);
3434
/* eslint-enable no-unused-vars */
35-
assert.equal(1,obj.foo);
36-
assert.equal(2,obj.bar);
37-
assert.equal(2,foo);
35+
assert.equal(1,global.obj.foo);
36+
assert.equal(2,global.obj.bar);
37+
assert.equal(2,global.foo);
3838

3939
console.error('call a function by reference');
40-
functionchangeFoo(){foo=100;}
40+
functionchangeFoo(){global.foo=100;}
4141
vm.runInNewContext('f()',{f: changeFoo});
42-
assert.equal(foo,100);
42+
assert.equal(global.foo,100);
4343

4444
console.error('modify an object by reference');
4545
varf={a: 1};

0 commit comments

Comments
 (0)