summaryrefslogtreecommitdiff
path: root/src/node_native_module.cc
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-01-05 06:02:33 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-01-12 22:56:02 +0800
commit92e95f17b64838d4cf77343c1a814d4ebd795217 (patch)
tree25aa45e582b5657505fff57ba78578e2f4dc248e /src/node_native_module.cc
parent18d3aebb06903a0151bdecbad2b6b7077b965d03 (diff)
downloadandroid-node-v8-92e95f17b64838d4cf77343c1a814d4ebd795217.tar.gz
android-node-v8-92e95f17b64838d4cf77343c1a814d4ebd795217.tar.bz2
android-node-v8-92e95f17b64838d4cf77343c1a814d4ebd795217.zip
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. PR-URL: https://github.com/nodejs/node/pull/25352 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_native_module.cc')
-rw-r--r--src/node_native_module.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/node_native_module.cc b/src/node_native_module.cc
index d7fa5798d0..1b1a5e8ec1 100644
--- a/src/node_native_module.cc
+++ b/src/node_native_module.cc
@@ -80,11 +80,21 @@ void NativeModuleLoader::GetCacheUsage(
args.GetReturnValue().Set(result);
}
-void NativeModuleLoader::SourceObjectGetter(
+void NativeModuleLoader::ModuleIdsGetter(
Local<Name> property, const PropertyCallbackInfo<Value>& info) {
Local<Context> context = info.GetIsolate()->GetCurrentContext();
- info.GetReturnValue().Set(
- per_process::native_module_loader.GetSourceObject(context));
+ Isolate* isolate = info.GetIsolate();
+
+ const NativeModuleRecordMap& source_ =
+ per_process::native_module_loader.source_;
+ std::vector<Local<Value>> ids;
+ ids.reserve(source_.size());
+
+ for (auto const& x : source_) {
+ ids.push_back(OneByteString(isolate, x.first.c_str(), x.first.size()));
+ }
+
+ info.GetReturnValue().Set(Array::New(isolate, ids.data(), ids.size()));
}
void NativeModuleLoader::ConfigStringGetter(
@@ -303,8 +313,8 @@ void NativeModuleLoader::Initialize(Local<Object> target,
.FromJust());
CHECK(target
->SetAccessor(env->context(),
- env->source_string(),
- SourceObjectGetter,
+ FIXED_ONE_BYTE_STRING(env->isolate(), "moduleIds"),
+ ModuleIdsGetter,
nullptr,
MaybeLocal<Value>(),
DEFAULT,