1/* eslint-disable strict, no-var, no-delete-var, no-undef, node-core/required-modules, node-core/require-common-first */
2// Importing common would break the execution. Indeed running `vm.runInThisContext` alters the global context
3// when declaring new variables with `var`. The other rules (strict, no-var, no-delete-var) have been disabled
4// in order to be able to test this specific not-strict case playing with `var` and `delete`.
5// Related to bug report: https://github.com/nodejs/node/issues/43129
6var assert = require('assert');
7var vm = require('vm');
8
9var data = [];
10var a = 'direct';
11delete a;
12data.push(a);
13
14var item2 = vm.runInThisContext(`
15var unusedB = 1;
16var data = [];
17var b = "this";
18delete b;
19data.push(b);
20data[0]
21`);
22data.push(item2);
23
24vm.runInContext(
25  `
26var unusedC = 1;
27var c = "new";
28delete c;
29data.push(c);
30`,
31  vm.createContext({ data: data })
32);
33
34assert.deepStrictEqual(data, ['direct', 'this', 'new']);
35
36assert.strictEqual(typeof unusedB, 'number'); // Declared within runInThisContext
37assert.strictEqual(typeof unusedC, 'undefined'); // Declared within runInContext
38