Skip to content

Commit 7a92662

Browse files
committed
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 ed7b676 commit 7a92662

11 files changed

+357
-431
lines changed

node.gyp

-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@
504504
'src/node_messaging.cc',
505505
'src/node_metadata.cc',
506506
'src/node_native_module.cc',
507-
'src/node_native_module_env.cc',
508507
'src/node_options.cc',
509508
'src/node_os.cc',
510509
'src/node_perf.cc',
@@ -610,7 +609,6 @@
610609
'src/node_metadata.h',
611610
'src/node_mutex.h',
612611
'src/node_native_module.h',
613-
'src/node_native_module_env.h',
614612
'src/node_object_wrap.h',
615613
'src/node_options.h',
616614
'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_shadow_realm.h"
@@ -449,9 +449,8 @@ MaybeLocal<Value> LoadEnvironment(
449449

450450
// TODO(addaleax): Avoid having a global table for all scripts.
451451
std::string name = "embedder_main_" + std::to_string(env->thread_id());
452-
native_module::NativeModuleEnv::Add(
453-
name.c_str(),
454-
UnionBytes(**main_utf16, main_utf16->length()));
452+
native_module::NativeModuleLoader::Add(
453+
name.c_str(), UnionBytes(**main_utf16, main_utf16->length()));
455454
env->set_main_utf16(std::move(main_utf16));
456455
std::vector<Local<String>> params = {
457456
env->process_string(),
@@ -705,7 +704,7 @@ Maybe<bool> InitializePrimordials(Local<Context> context) {
705704
global_string, exports_string, primordials_string};
706705
Local<Value> arguments[] = {context->Global(), exports, primordials};
707706
MaybeLocal<Function> maybe_fn =
708-
native_module::NativeModuleEnv::LookupAndCompile(
707+
native_module::NativeModuleLoader::LookupAndCompile(
709708
context, *module, &parameters, nullptr);
710709
Local<Function> fn;
711710
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"
@@ -121,7 +121,7 @@
121121

122122
namespace node {
123123

124-
using native_module::NativeModuleEnv;
124+
using native_module::NativeModuleLoader;
125125

126126
using v8::EscapableHandleScope;
127127
using v8::Function;
@@ -174,7 +174,7 @@ MaybeLocal<Value> ExecuteBootstrapper(Environment* env,
174174
std::vector<Local<Value>>* arguments) {
175175
EscapableHandleScope scope(env->isolate());
176176
MaybeLocal<Function> maybe_fn =
177-
NativeModuleEnv::LookupAndCompile(env->context(), id, parameters, env);
177+
NativeModuleLoader::LookupAndCompile(env->context(), id, parameters, env);
178178

179179
Local<Function> fn;
180180
if (!maybe_fn.ToLocal(&fn)) {
@@ -1188,8 +1188,7 @@ int Start(int argc, char** argv) {
11881188
uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);
11891189

11901190
if (snapshot_data != nullptr) {
1191-
native_module::NativeModuleEnv::RefreshCodeCache(
1192-
snapshot_data->code_cache);
1191+
NativeModuleLoader::RefreshCodeCache(snapshot_data->code_cache);
11931192
}
11941193
NodeMainInstance main_instance(snapshot_data,
11951194
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>
@@ -591,13 +591,14 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
591591
exports->SetPrototype(env->context(), Null(env->isolate())).FromJust());
592592
DefineConstants(env->isolate(), exports);
593593
} else if (!strcmp(*module_v, "natives")) {
594-
exports = native_module::NativeModuleEnv::GetSourceObject(env->context());
594+
exports =
595+
native_module::NativeModuleLoader::GetSourceObject(env->context());
595596
// Legacy feature: process.binding('natives').config contains stringified
596597
// config.gypi
597598
CHECK(exports
598599
->Set(env->context(),
599600
env->config_string(),
600-
native_module::NativeModuleEnv::GetConfigString(
601+
native_module::NativeModuleLoader::GetConfigString(
601602
env->isolate()))
602603
.FromJust());
603604
} 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)