0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/lib/internal/v8_prof_processor.js
cjihrig 22b6804259 lib: define printErr() in script string
This commit moves the printErr() function, used by the
tick profiler processer, into the code string passed to
vm.runInThisContext().

PR-URL: https://github.com/nodejs/node/pull/19285
Fixes: https://github.com/nodejs/node/issues/19260
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-03-12 08:45:13 -07:00

39 lines
1.1 KiB
JavaScript

'use strict';
const vm = require('vm');
const scriptFiles = [
'internal/v8_prof_polyfill',
'internal/deps/v8/tools/splaytree',
'internal/deps/v8/tools/codemap',
'internal/deps/v8/tools/csvparser',
'internal/deps/v8/tools/consarray',
'internal/deps/v8/tools/profile',
'internal/deps/v8/tools/profile_view',
'internal/deps/v8/tools/logreader',
'internal/deps/v8/tools/arguments',
'internal/deps/v8/tools/tickprocessor',
'internal/deps/v8/tools/SourceMap',
'internal/deps/v8/tools/tickprocessor-driver'
];
var script = '';
scriptFiles.forEach(function(s) {
script += process.binding('natives')[s] + '\n';
});
const tickArguments = [];
if (process.platform === 'darwin') {
tickArguments.push('--mac');
} else if (process.platform === 'win32') {
tickArguments.push('--windows');
}
tickArguments.push.apply(tickArguments, process.argv.slice(1));
script = `(function(module, require) {
arguments = ${JSON.stringify(tickArguments)};
function write (s) { process.stdout.write(s) }
function printErr(err) { console.error(err); }
${script}
})`;
vm.runInThisContext(script)(module, require);