11cb0ef41Sopenharmony_ci/* eslint-disable strict, no-var, no-delete-var, no-undef, node-core/required-modules, node-core/require-common-first */ 21cb0ef41Sopenharmony_ci// Importing common would break the execution. Indeed running `vm.runInThisContext` alters the global context 31cb0ef41Sopenharmony_ci// when declaring new variables with `var`. The other rules (strict, no-var, no-delete-var) have been disabled 41cb0ef41Sopenharmony_ci// in order to be able to test this specific not-strict case playing with `var` and `delete`. 51cb0ef41Sopenharmony_ci// Related to bug report: https://github.com/nodejs/node/issues/43129 61cb0ef41Sopenharmony_civar assert = require('assert'); 71cb0ef41Sopenharmony_civar vm = require('vm'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_civar data = []; 101cb0ef41Sopenharmony_civar a = 'direct'; 111cb0ef41Sopenharmony_cidelete a; 121cb0ef41Sopenharmony_cidata.push(a); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_civar item2 = vm.runInThisContext(` 151cb0ef41Sopenharmony_civar unusedB = 1; 161cb0ef41Sopenharmony_civar data = []; 171cb0ef41Sopenharmony_civar b = "this"; 181cb0ef41Sopenharmony_cidelete b; 191cb0ef41Sopenharmony_cidata.push(b); 201cb0ef41Sopenharmony_cidata[0] 211cb0ef41Sopenharmony_ci`); 221cb0ef41Sopenharmony_cidata.push(item2); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_civm.runInContext( 251cb0ef41Sopenharmony_ci ` 261cb0ef41Sopenharmony_civar unusedC = 1; 271cb0ef41Sopenharmony_civar c = "new"; 281cb0ef41Sopenharmony_cidelete c; 291cb0ef41Sopenharmony_cidata.push(c); 301cb0ef41Sopenharmony_ci`, 311cb0ef41Sopenharmony_ci vm.createContext({ data: data }) 321cb0ef41Sopenharmony_ci); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciassert.deepStrictEqual(data, ['direct', 'this', 'new']); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciassert.strictEqual(typeof unusedB, 'number'); // Declared within runInThisContext 371cb0ef41Sopenharmony_ciassert.strictEqual(typeof unusedC, 'undefined'); // Declared within runInContext 38