Skip to content

Commit

Permalink
src: merge NativeModuleEnv into NativeModuleLoader
Browse files Browse the repository at this point in the history
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 <legendecas@gmail.com>
  • Loading branch information
joyeecheung authored and danielleadams committed Jul 26, 2022
1 parent ed45088 commit 9f9d00c
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 431 deletions.
2 changes: 0 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@
'src/node_messaging.cc',
'src/node_metadata.cc',
'src/node_native_module.cc',
'src/node_native_module_env.cc',
'src/node_options.cc',
'src/node_os.cc',
'src/node_perf.cc',
Expand Down Expand Up @@ -621,7 +620,6 @@
'src/node_metadata.h',
'src/node_mutex.h',
'src/node_native_module.h',
'src/node_native_module_env.h',
'src/node_object_wrap.h',
'src/node_options.h',
'src/node_options-inl.h',
Expand Down
9 changes: 4 additions & 5 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "node_context_data.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_native_module_env.h"
#include "node_native_module.h"
#include "node_options-inl.h"
#include "node_platform.h"
#include "node_v8_platform-inl.h"
Expand Down Expand Up @@ -442,9 +442,8 @@ MaybeLocal<Value> LoadEnvironment(

// TODO(addaleax): Avoid having a global table for all scripts.
std::string name = "embedder_main_" + std::to_string(env->thread_id());
native_module::NativeModuleEnv::Add(
name.c_str(),
UnionBytes(**main_utf16, main_utf16->length()));
native_module::NativeModuleLoader::Add(
name.c_str(), UnionBytes(**main_utf16, main_utf16->length()));
env->set_main_utf16(std::move(main_utf16));
std::vector<Local<String>> params = {
env->process_string(),
Expand Down Expand Up @@ -698,7 +697,7 @@ Maybe<bool> InitializePrimordials(Local<Context> context) {
global_string, exports_string, primordials_string};
Local<Value> arguments[] = {context->Global(), exports, primordials};
MaybeLocal<Function> maybe_fn =
native_module::NativeModuleEnv::LookupAndCompile(
native_module::NativeModuleLoader::LookupAndCompile(
context, *module, &parameters, nullptr);
Local<Function> fn;
if (!maybe_fn.ToLocal(&fn)) {
Expand Down
9 changes: 4 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "node_internals.h"
#include "node_main_instance.h"
#include "node_metadata.h"
#include "node_native_module_env.h"
#include "node_native_module.h"
#include "node_options-inl.h"
#include "node_perf.h"
#include "node_process-inl.h"
Expand Down Expand Up @@ -125,7 +125,7 @@

namespace node {

using native_module::NativeModuleEnv;
using native_module::NativeModuleLoader;

using v8::EscapableHandleScope;
using v8::Function;
Expand Down Expand Up @@ -178,7 +178,7 @@ MaybeLocal<Value> ExecuteBootstrapper(Environment* env,
std::vector<Local<Value>>* arguments) {
EscapableHandleScope scope(env->isolate());
MaybeLocal<Function> maybe_fn =
NativeModuleEnv::LookupAndCompile(env->context(), id, parameters, env);
NativeModuleLoader::LookupAndCompile(env->context(), id, parameters, env);

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

if (snapshot_data != nullptr) {
native_module::NativeModuleEnv::RefreshCodeCache(
snapshot_data->code_cache);
NativeModuleLoader::RefreshCodeCache(snapshot_data->code_cache);
}
NodeMainInstance main_instance(snapshot_data,
uv_default_loop(),
Expand Down
7 changes: 4 additions & 3 deletions src/node_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_native_module_env.h"
#include "node_native_module.h"
#include "util.h"

#include <string>
Expand Down Expand Up @@ -598,13 +598,14 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
exports->SetPrototype(env->context(), Null(env->isolate())).FromJust());
DefineConstants(env->isolate(), exports);
} else if (!strcmp(*module_v, "natives")) {
exports = native_module::NativeModuleEnv::GetSourceObject(env->context());
exports =
native_module::NativeModuleLoader::GetSourceObject(env->context());
// Legacy feature: process.binding('natives').config contains stringified
// config.gypi
CHECK(exports
->Set(env->context(),
env->config_string(),
native_module::NativeModuleEnv::GetConfigString(
native_module::NativeModuleLoader::GetConfigString(
env->isolate()))
.FromJust());
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "memory_tracker.h"
#include "node.h"
#include "node_i18n.h"
#include "node_native_module_env.h"
#include "node_native_module.h"
#include "node_options.h"
#include "util-inl.h"

Expand Down
2 changes: 1 addition & 1 deletion src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "debug_utils-inl.h"
#include "node_external_reference.h"
#include "node_internals.h"
#include "node_native_module_env.h"
#include "node_native_module.h"
#include "node_options-inl.h"
#include "node_snapshot_builder.h"
#include "node_snapshotable.h"
Expand Down
Loading

0 comments on commit 9f9d00c

Please sign in to comment.