node/lib/internal/v8_prof_processor.js
Antoine du Hamel c723e4cb0b lib: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/35875
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-11-05 23:15:41 +01:00

46 lines
1.2 KiB
JavaScript

'use strict';
const {
ArrayPrototypePush,
ArrayPrototypeSlice,
JSONStringify,
} = primordials;
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'
];
let script = '';
for (const s of scriptFiles) {
script += internalBinding('natives')[s] + '\n';
}
const tickArguments = [];
if (process.platform === 'darwin') {
ArrayPrototypePush(tickArguments, '--mac');
} else if (process.platform === 'win32') {
ArrayPrototypePush(tickArguments, '--windows');
}
ArrayPrototypePush(tickArguments,
...ArrayPrototypeSlice(process.argv, 1));
script = `(function(module, require) {
arguments = ${JSONStringify(tickArguments)};
function write (s) { process.stdout.write(s) }
function printErr(err) { console.error(err); }
${script}
})`;
vm.runInThisContext(script)(module, require);