src: simplify NativeModule caching and remove redudant data
- Remove
NativeModule._source
- the compilation is now entirely done in C++ andprocess.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 throughmod.loading
/mod.loaded
. - Rename
NativeModule.nonInternalExists
toNativeModule.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 whereworker_threads
can be made available with--expose-internals
- Rename
NativeModule.requireForDeps
toNativeModule.requireWithFallbackInDeps
. - Add a test to make sure we do not accidentally leak any module to the global namespace.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines