Files
node/lib/internal/main/prof_process.js
Joyee Cheung 12fad1bd7b src: build v8 tick processor as built-in source text modules
Instead of polyfilling it with vm.SourceTextModule,
use a built-in source text module loader so that we can
also build the code cache for it at build tiem to
embed the code cache for them in the binary.

Drive-by: instead of inferring how to compile a particular
built-in at run time, do the inferring at build time,
so the function-based built-ins can be compiled using
parameters quickly looked up from a static map, and
the builtins that should be compiled as source text
modules are known internally based on extension in
the source code (at run time, the extensions are all
removed).

PR-URL: https://github.com/nodejs/node/pull/60518
Reviewed-By: Aditi Singh <aditisingh1400@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2025-11-11 02:53:13 +00:00

38 lines
1.4 KiB
JavaScript

'use strict';
// This main script is used by --prof-process to process logs generated by --prof.
// The tick processor implementation is vendor-in from V8, placed in deps/v8/tools,
// and they have different resolution rules compared to normal Node.js internal builtins,
// despite being embedded into the binary as a built-in as well.
// TODO(joyeecheung): put the context locals in import.meta.
const {
ObjectAssign,
PromisePrototypeThen,
globalThis,
} = primordials;
const {
prepareMainThreadExecution,
markBootstrapComplete,
} = require('internal/process/pre_execution');
const { importBuiltinSourceTextModule } = internalBinding('builtins');
const { triggerUncaughtException } = internalBinding('errors');
prepareMainThreadExecution();
markBootstrapComplete();
// Polyfill the context with globals needed by the tick processor.
const { globals, openFile } = require('internal/v8_prof_polyfill');
ObjectAssign(globalThis, globals);
openFile(process.argv[process.argv.length - 1]);
// Load and evaluate the V8 tick processor as a source text module.
const { promise } = importBuiltinSourceTextModule('internal/deps/v8/tools/tickprocessor-driver');
// We must catch the rejection asynchronously to print it out properly since
// the tick processor contains top level await.
PromisePrototypeThen(promise, undefined, (err) => {
triggerUncaughtException(err, true /* fromPromise */);
});