fix: prevent V8 tool scripts from being loaded as builtin modules
This patch prevents Node.js from attempting to load V8 tool scripts under
internal/deps/v8/tools/ as builtin modules.
These files are part of V8’s internal tooling and are not valid Node.js
builtins. When required or imported with --expose-internals, the loader
attempts to treat them as builtin CJS modules, which results in either:
- SyntaxError: Unexpected token 'export'
(because the V8 tool scripts contain ESM syntax), or - AssertionError in BuiltinLoader::LookupAndCompileFunction
(data->IsValue()), aborting the process.
This change adds a guard in loadBuiltinModule() to skip any module whose
path starts with internal/deps/v8/tools/, and also adds a defensive check
to avoid calling compileForPublicLoader() when no builtin module entry
exists.
This aligns the behavior with expectations and avoids a crash when users
attempt to load these paths with --expose-internals.
Fixes: #60865
Review requested:
- [ ] @nodejs/loaders
Yeah, it seems to make more sense to exclude them from the user-accesible list in the first place...