Skip to content

Commit 9f9d00c

Browse files
joyeecheungdanielleadams
authored andcommitted
src: merge NativeModuleEnv into NativeModuleLoader
Now that we include the code cache into the embedded snapshot, there is no point in splitting an Environment-independent NativeModuleLoader out of NativeModuleEnv. Merge the two classes for simplicity. PR-URL: #43824 Refs: #31074 Reviewed-By: Chengzhong Wu <[email protected]>
1 parent ed45088 commit 9f9d00c

11 files changed

+357
-431
lines changed

node.gyp

-2
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@
516516
'src/node_messaging.cc',
517517
'src/node_metadata.cc',
518518
'src/node_native_module.cc',
519-
'src/node_native_module_env.cc',
520519
'src/node_options.cc',
521520
'src/node_os.cc',
522521
'src/node_perf.cc',
@@ -621,7 +620,6 @@
621620
'src/node_metadata.h',
622621
'src/node_mutex.h',
623622
'src/node_native_module.h',
624-
'src/node_native_module_env.h',
625623
'src/node_object_wrap.h',
626624
'src/node_options.h',
627625
'src/node_options-inl.h',

src/api/environment.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "node_context_data.h"
33
#include "node_errors.h"
44
#include "node_internals.h"
5-
#include "node_native_module_env.h"
5+
#include "node_native_module.h"
66
#include "node_options-inl.h"
77
#include "node_platform.h"
88
#include "node_v8_platform-inl.h"
@@ -442,9 +442,8 @@ MaybeLocal<Value> LoadEnvironment(
442442

443443
// TODO(addaleax): Avoid having a global table for all scripts.
444444
std::string name = "embedder_main_" + std::to_string(env->thread_id());
445-
native_module::NativeModuleEnv::Add(
446-
name.c_str(),
447-
UnionBytes(**main_utf16, main_utf16->length()));
445+
native_module::NativeModuleLoader::Add(
446+
name.c_str(), UnionBytes(**main_utf16, main_utf16->length()));
448447
env->set_main_utf16(std::move(main_utf16));
449448
std::vector<Local<String>> params = {
450449
env->process_string(),
@@ -698,7 +697,7 @@ Maybe<bool> InitializePrimordials(Local<Context> context) {
698697
global_string, exports_string, primordials_string};
699698
Local<Value> arguments[] = {context->Global(), exports, primordials};
700699
MaybeLocal<Function> maybe_fn =
701-
native_module::NativeModuleEnv::LookupAndCompile(
700+
native_module::NativeModuleLoader::LookupAndCompile(
702701
context, *module, &parameters, nullptr);
703702
Local<Function> fn;
704703
if (!maybe_fn.ToLocal(&fn)) {

src/node.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "node_internals.h"
3333
#include "node_main_instance.h"
3434
#include "node_metadata.h"
35-
#include "node_native_module_env.h"
35+
#include "node_native_module.h"
3636
#include "node_options-inl.h"
3737
#include "node_perf.h"
3838
#include "node_process-inl.h"
@@ -125,7 +125,7 @@
125125

126126
namespace node {
127127

128-
using native_module::NativeModuleEnv;
128+
using native_module::NativeModuleLoader;
129129

130130
using v8::EscapableHandleScope;
131131
using v8::Function;
@@ -178,7 +178,7 @@ MaybeLocal<Value> ExecuteBootstrapper(Environment* env,
178178
std::vector<Local<Value>>* arguments) {
179179
EscapableHandleScope scope(env->isolate());
180180
MaybeLocal<Function> maybe_fn =
181-
NativeModuleEnv::LookupAndCompile(env->context(), id, parameters, env);
181+
NativeModuleLoader::LookupAndCompile(env->context(), id, parameters, env);
182182

183183
Local<Function> fn;
184184
if (!maybe_fn.ToLocal(&fn)) {
@@ -1196,8 +1196,7 @@ int Start(int argc, char** argv) {
11961196
uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);
11971197

11981198
if (snapshot_data != nullptr) {
1199-
native_module::NativeModuleEnv::RefreshCodeCache(
1200-
snapshot_data->code_cache);
1199+
NativeModuleLoader::RefreshCodeCache(snapshot_data->code_cache);
12011200
}
12021201
NodeMainInstance main_instance(snapshot_data,
12031202
uv_default_loop(),

src/node_binding.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "env-inl.h"
44
#include "node_errors.h"
55
#include "node_external_reference.h"
6-
#include "node_native_module_env.h"
6+
#include "node_native_module.h"
77
#include "util.h"
88

99
#include <string>
@@ -598,13 +598,14 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
598598
exports->SetPrototype(env->context(), Null(env->isolate())).FromJust());
599599
DefineConstants(env->isolate(), exports);
600600
} else if (!strcmp(*module_v, "natives")) {
601-
exports = native_module::NativeModuleEnv::GetSourceObject(env->context());
601+
exports =
602+
native_module::NativeModuleLoader::GetSourceObject(env->context());
602603
// Legacy feature: process.binding('natives').config contains stringified
603604
// config.gypi
604605
CHECK(exports
605606
->Set(env->context(),
606607
env->config_string(),
607-
native_module::NativeModuleEnv::GetConfigString(
608+
native_module::NativeModuleLoader::GetConfigString(
608609
env->isolate()))
609610
.FromJust());
610611
} else {

src/node_config.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "memory_tracker.h"
33
#include "node.h"
44
#include "node_i18n.h"
5-
#include "node_native_module_env.h"
5+
#include "node_native_module.h"
66
#include "node_options.h"
77
#include "util-inl.h"
88

src/node_main_instance.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "debug_utils-inl.h"
77
#include "node_external_reference.h"
88
#include "node_internals.h"
9-
#include "node_native_module_env.h"
9+
#include "node_native_module.h"
1010
#include "node_options-inl.h"
1111
#include "node_snapshot_builder.h"
1212
#include "node_snapshotable.h"

0 commit comments

Comments
 (0)