Skip to content

Commit 6bae8a4

Browse files
committed
fixup! src: merge NativeModuleEnv into NativeModuleLoader
1 parent d3c29ac commit 6bae8a4

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

src/node.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -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::NativeModuleLoader::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_native_module.cc

+18-23
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ using v8::Value;
3030

3131
NativeModuleLoader NativeModuleLoader::instance_;
3232

33-
NativeModuleLoader::NativeModuleLoader() : config_(GetConfig()) {
33+
NativeModuleLoader::NativeModuleLoader()
34+
: config_(GetConfig()), has_code_cache_(false) {
3435
LoadJavaScriptSource();
3536
}
3637

@@ -39,19 +40,19 @@ NativeModuleLoader* NativeModuleLoader::GetInstance() {
3940
}
4041

4142
bool NativeModuleLoader::Exists(const char* id) {
42-
auto& source = NativeModuleLoader::GetInstance()->source_;
43+
auto& source = GetInstance()->source_;
4344
return source.find(id) != source.end();
4445
}
4546

4647
bool NativeModuleLoader::Add(const char* id, const UnionBytes& source) {
47-
auto result = NativeModuleLoader::GetInstance()->source_.emplace(id, source);
48+
auto result = GetInstance()->source_.emplace(id, source);
4849
return result.second;
4950
}
5051

5152
Local<Object> NativeModuleLoader::GetSourceObject(Local<Context> context) {
5253
Isolate* isolate = context->GetIsolate();
5354
Local<Object> out = Object::New(isolate);
54-
auto& source = NativeModuleLoader::GetInstance()->source_;
55+
auto& source = GetInstance()->source_;
5556
for (auto const& x : source) {
5657
Local<String> key = OneByteString(isolate, x.first.c_str(), x.first.size());
5758
out->Set(context, key, x.second.ToStringChecked(isolate)).FromJust();
@@ -60,7 +61,7 @@ Local<Object> NativeModuleLoader::GetSourceObject(Local<Context> context) {
6061
}
6162

6263
Local<String> NativeModuleLoader::GetConfigString(Isolate* isolate) {
63-
return NativeModuleLoader::GetInstance()->config_.ToStringChecked(isolate);
64+
return GetInstance()->config_.ToStringChecked(isolate);
6465
}
6566

6667
std::vector<std::string> NativeModuleLoader::GetModuleIds() {
@@ -361,20 +362,17 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompile(
361362
const char* id,
362363
std::vector<Local<String>>* parameters,
363364
Environment* optional_env) {
364-
NativeModuleLoader::Result result;
365+
Result result;
365366
MaybeLocal<Function> maybe =
366-
NativeModuleLoader::GetInstance()->LookupAndCompileInternal(
367-
context, id, parameters, &result);
367+
GetInstance()->LookupAndCompileInternal(context, id, parameters, &result);
368368
if (optional_env != nullptr) {
369369
RecordResult(id, result, optional_env);
370370
}
371371
return maybe;
372372
}
373373

374-
bool NativeModuleLoader::has_code_cache_ = false;
375-
376374
bool NativeModuleLoader::CompileAllModules(Local<Context> context) {
377-
NativeModuleLoader* loader = NativeModuleLoader::GetInstance();
375+
NativeModuleLoader* loader = GetInstance();
378376
std::vector<std::string> ids = loader->GetModuleIds();
379377
bool all_succeeded = true;
380378
for (const auto& id : ids) {
@@ -383,7 +381,7 @@ bool NativeModuleLoader::CompileAllModules(Local<Context> context) {
383381
continue;
384382
}
385383
v8::TryCatch bootstrapCatch(context->GetIsolate());
386-
native_module::NativeModuleLoader::Result result;
384+
Result result;
387385
USE(loader->CompileAsModule(context, id.c_str(), &result));
388386
if (bootstrapCatch.HasCaught()) {
389387
per_process::Debug(DebugCategory::CODE_CACHE,
@@ -397,7 +395,7 @@ bool NativeModuleLoader::CompileAllModules(Local<Context> context) {
397395
}
398396

399397
void NativeModuleLoader::CopyCodeCache(std::vector<CodeCacheInfo>* out) {
400-
NativeModuleLoader* loader = NativeModuleLoader::GetInstance();
398+
NativeModuleLoader* loader = GetInstance();
401399
Mutex::ScopedLock lock(loader->code_cache_mutex());
402400
auto in = loader->code_cache();
403401
for (auto const& item : *in) {
@@ -409,7 +407,7 @@ void NativeModuleLoader::CopyCodeCache(std::vector<CodeCacheInfo>* out) {
409407

410408
void NativeModuleLoader::RefreshCodeCache(
411409
const std::vector<CodeCacheInfo>& in) {
412-
NativeModuleLoader* loader = NativeModuleLoader::GetInstance();
410+
NativeModuleLoader* loader = GetInstance();
413411
Mutex::ScopedLock lock(loader->code_cache_mutex());
414412
auto out = loader->code_cache();
415413
for (auto const& item : in) {
@@ -426,7 +424,7 @@ void NativeModuleLoader::RefreshCodeCache(
426424
out->emplace(item.id, new_cache.release());
427425
}
428426
}
429-
NativeModuleLoader::has_code_cache_ = true;
427+
loader->has_code_cache_ = true;
430428
}
431429

432430
void NativeModuleLoader::GetModuleCategories(
@@ -438,9 +436,8 @@ void NativeModuleLoader::GetModuleCategories(
438436

439437
// Copy from the per-process categories
440438
std::set<std::string> cannot_be_required =
441-
NativeModuleLoader::GetInstance()->GetCannotBeRequired();
442-
std::set<std::string> can_be_required =
443-
NativeModuleLoader::GetInstance()->GetCanBeRequired();
439+
GetInstance()->GetCannotBeRequired();
440+
std::set<std::string> can_be_required = GetInstance()->GetCanBeRequired();
444441

445442
if (!env->owns_process_state()) {
446443
can_be_required.erase("trace_events");
@@ -522,8 +519,7 @@ void NativeModuleLoader::ModuleIdsGetter(
522519
Local<Name> property, const PropertyCallbackInfo<Value>& info) {
523520
Isolate* isolate = info.GetIsolate();
524521

525-
std::vector<std::string> ids =
526-
NativeModuleLoader::GetInstance()->GetModuleIds();
522+
std::vector<std::string> ids = GetInstance()->GetModuleIds();
527523
info.GetReturnValue().Set(
528524
ToV8Value(isolate->GetCurrentContext(), ids).ToLocalChecked());
529525
}
@@ -550,8 +546,7 @@ void NativeModuleLoader::CompileFunction(
550546
const char* id = *id_v;
551547
NativeModuleLoader::Result result;
552548
MaybeLocal<Function> maybe =
553-
NativeModuleLoader::GetInstance()->CompileAsModule(
554-
env->context(), id, &result);
549+
GetInstance()->CompileAsModule(env->context(), id, &result);
555550
RecordResult(id, result, env);
556551
Local<Function> fn;
557552
if (maybe.ToLocal(&fn)) {
@@ -562,7 +557,7 @@ void NativeModuleLoader::CompileFunction(
562557
void NativeModuleLoader::HasCachedBuiltins(
563558
const FunctionCallbackInfo<Value>& args) {
564559
args.GetReturnValue().Set(
565-
v8::Boolean::New(args.GetIsolate(), NativeModuleLoader::has_code_cache_));
560+
v8::Boolean::New(args.GetIsolate(), GetInstance()->has_code_cache_));
566561
}
567562

568563
// TODO(joyeecheung): It is somewhat confusing that Class::Initialize

src/node_native_module.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class NODE_EXTERN_PRIVATE NativeModuleLoader {
133133
// Used to synchronize access to the code cache map
134134
Mutex code_cache_mutex_;
135135

136-
static bool has_code_cache_;
136+
bool has_code_cache_;
137137

138138
friend class ::PerProcessTest;
139139
};

0 commit comments

Comments
 (0)