lib: replace eval with vm.runInThisContext

PR-URL: https://github.com/nodejs/node/pull/18623
Refs: https://github.com/nodejs/node/pull/18212#pullrequestreview-94616927
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Myles Borins authored and Rod Vagg committed 2018-08-16 11:38:51 +10:00
1 parent f0f44f69a6
commit 2702fd779e
1 file changed
+7 -4
+7 -4
View File
@@ -1,4 +1,7 @@
/* eslint-disable strict */
'use strict';
const vm = require('vm');
const scriptFiles = [
'internal/v8_prof_polyfill',
'v8/tools/splaytree',
@@ -30,9 +33,9 @@ if (process.platform === 'darwin') {
tickArguments.push('--windows');
}
tickArguments.push.apply(tickArguments, process.argv.slice(1));
script = `(function() {
script = `(function(require) {
arguments = ${JSON.stringify(tickArguments)};
function write (s) { process.stdout.write(s) }
${script}
})()`;
eval(script);
})`;
vm.runInThisContext(script)(require);