mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
src: simplify NativeModule caching and remove redundant data
- Remove `NativeModule._source` - the compilation is now entirely
done in C++ and `process.binding('natives')` is implemented
directly in the binding loader so there is no need to store
additional source code strings.
- Instead of using an object as `NativeModule._cached` and insert
into it after compilation of each native module, simply prebuild
a JS map filled with all the native modules and infer the
state of compilation through `mod.loading`/`mod.loaded`.
- Rename `NativeModule.nonInternalExists` to
`NativeModule.canBeRequiredByUsers` and precompute that
property for all the native modules during bootstrap instead
of branching in every require call during runtime. This also fixes
the bug where `worker_threads` can be made available with
`--expose-internals`.
- Rename `NativeModule.requireForDeps` to
`NativeModule.requireWithFallbackInDeps`.
- Add a test to make sure we do not accidentally leak any module
to the global namespace.
Backport-PR-URL: https://github.com/nodejs/node/pull/25964
PR-URL: https://github.com/nodejs/node/pull/25352
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
508a2e7f0f
commit
b280d90279
9 files changed
+199
-101
No files matched your search
@@ -5,15 +5,12 @@
|
||||
// and the cache is used when built in modules are compiled.
|
||||
// Otherwise, verifies that no cache is used when compiling builtins.
|
||||
|
||||
require('../common');
|
||||
const { isMainThread } = require('../common');
|
||||
const assert = require('assert');
|
||||
const {
|
||||
cachableBuiltins,
|
||||
cannotUseCache
|
||||
} = require('internal/bootstrap/cache');
|
||||
const {
|
||||
isMainThread
|
||||
} = require('worker_threads');
|
||||
|
||||
const {
|
||||
internalBinding
|
||||
|
||||
Reference in new issue
Block a user