From 4dd27499ed617598ec729642aa5e2ce5628720cc Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Wed, 7 Feb 2018 10:42:26 -0500 Subject: [PATCH] lib: replace `eval` with `vm.runInThisContext` Refs: https://github.com/nodejs/node/pull/18212#pullrequestreview-94616927 --- lib/internal/v8_prof_processor.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/internal/v8_prof_processor.js b/lib/internal/v8_prof_processor.js index 9c63430f964917..0d9cfd6df4d12a 100644 --- a/lib/internal/v8_prof_processor.js +++ b/lib/internal/v8_prof_processor.js @@ -1,4 +1,7 @@ -/* eslint-disable strict */ +'use strict'; + +const vm = require('vm'); + const scriptFiles = [ 'internal/v8_prof_polyfill', 'internal/deps/v8/tools/splaytree', @@ -31,9 +34,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);