@@ -30,7 +30,8 @@ using v8::Value;
30
30
31
31
NativeModuleLoader NativeModuleLoader::instance_;
32
32
33
- NativeModuleLoader::NativeModuleLoader () : config_(GetConfig()) {
33
+ NativeModuleLoader::NativeModuleLoader ()
34
+ : config_(GetConfig()), has_code_cache_(false ) {
34
35
LoadJavaScriptSource ();
35
36
}
36
37
@@ -39,19 +40,19 @@ NativeModuleLoader* NativeModuleLoader::GetInstance() {
39
40
}
40
41
41
42
bool NativeModuleLoader::Exists (const char * id) {
42
- auto & source = NativeModuleLoader:: GetInstance ()->source_ ;
43
+ auto & source = GetInstance ()->source_ ;
43
44
return source.find (id) != source.end ();
44
45
}
45
46
46
47
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);
48
49
return result.second ;
49
50
}
50
51
51
52
Local<Object> NativeModuleLoader::GetSourceObject (Local<Context> context) {
52
53
Isolate* isolate = context->GetIsolate ();
53
54
Local<Object> out = Object::New (isolate);
54
- auto & source = NativeModuleLoader:: GetInstance ()->source_ ;
55
+ auto & source = GetInstance ()->source_ ;
55
56
for (auto const & x : source) {
56
57
Local<String> key = OneByteString (isolate, x.first .c_str (), x.first .size ());
57
58
out->Set (context, key, x.second .ToStringChecked (isolate)).FromJust ();
@@ -60,7 +61,7 @@ Local<Object> NativeModuleLoader::GetSourceObject(Local<Context> context) {
60
61
}
61
62
62
63
Local<String> NativeModuleLoader::GetConfigString (Isolate* isolate) {
63
- return NativeModuleLoader:: GetInstance ()->config_ .ToStringChecked (isolate);
64
+ return GetInstance ()->config_ .ToStringChecked (isolate);
64
65
}
65
66
66
67
std::vector<std::string> NativeModuleLoader::GetModuleIds () {
@@ -361,20 +362,17 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompile(
361
362
const char * id,
362
363
std::vector<Local<String>>* parameters,
363
364
Environment* optional_env) {
364
- NativeModuleLoader:: Result result;
365
+ Result result;
365
366
MaybeLocal<Function> maybe =
366
- NativeModuleLoader::GetInstance ()->LookupAndCompileInternal (
367
- context, id, parameters, &result);
367
+ GetInstance ()->LookupAndCompileInternal (context, id, parameters, &result);
368
368
if (optional_env != nullptr ) {
369
369
RecordResult (id, result, optional_env);
370
370
}
371
371
return maybe;
372
372
}
373
373
374
- bool NativeModuleLoader::has_code_cache_ = false ;
375
-
376
374
bool NativeModuleLoader::CompileAllModules (Local<Context> context) {
377
- NativeModuleLoader* loader = NativeModuleLoader:: GetInstance ();
375
+ NativeModuleLoader* loader = GetInstance ();
378
376
std::vector<std::string> ids = loader->GetModuleIds ();
379
377
bool all_succeeded = true ;
380
378
for (const auto & id : ids) {
@@ -383,7 +381,7 @@ bool NativeModuleLoader::CompileAllModules(Local<Context> context) {
383
381
continue ;
384
382
}
385
383
v8::TryCatch bootstrapCatch (context->GetIsolate ());
386
- native_module::NativeModuleLoader:: Result result;
384
+ Result result;
387
385
USE (loader->CompileAsModule (context, id.c_str (), &result));
388
386
if (bootstrapCatch.HasCaught ()) {
389
387
per_process::Debug (DebugCategory::CODE_CACHE,
@@ -397,7 +395,7 @@ bool NativeModuleLoader::CompileAllModules(Local<Context> context) {
397
395
}
398
396
399
397
void NativeModuleLoader::CopyCodeCache (std::vector<CodeCacheInfo>* out) {
400
- NativeModuleLoader* loader = NativeModuleLoader:: GetInstance ();
398
+ NativeModuleLoader* loader = GetInstance ();
401
399
Mutex::ScopedLock lock (loader->code_cache_mutex ());
402
400
auto in = loader->code_cache ();
403
401
for (auto const & item : *in) {
@@ -409,7 +407,7 @@ void NativeModuleLoader::CopyCodeCache(std::vector<CodeCacheInfo>* out) {
409
407
410
408
void NativeModuleLoader::RefreshCodeCache (
411
409
const std::vector<CodeCacheInfo>& in) {
412
- NativeModuleLoader* loader = NativeModuleLoader:: GetInstance ();
410
+ NativeModuleLoader* loader = GetInstance ();
413
411
Mutex::ScopedLock lock (loader->code_cache_mutex ());
414
412
auto out = loader->code_cache ();
415
413
for (auto const & item : in) {
@@ -426,7 +424,7 @@ void NativeModuleLoader::RefreshCodeCache(
426
424
out->emplace (item.id , new_cache.release ());
427
425
}
428
426
}
429
- NativeModuleLoader:: has_code_cache_ = true ;
427
+ loader-> has_code_cache_ = true ;
430
428
}
431
429
432
430
void NativeModuleLoader::GetModuleCategories (
@@ -438,9 +436,8 @@ void NativeModuleLoader::GetModuleCategories(
438
436
439
437
// Copy from the per-process categories
440
438
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 ();
444
441
445
442
if (!env->owns_process_state ()) {
446
443
can_be_required.erase (" trace_events" );
@@ -522,8 +519,7 @@ void NativeModuleLoader::ModuleIdsGetter(
522
519
Local<Name> property, const PropertyCallbackInfo<Value>& info) {
523
520
Isolate* isolate = info.GetIsolate ();
524
521
525
- std::vector<std::string> ids =
526
- NativeModuleLoader::GetInstance ()->GetModuleIds ();
522
+ std::vector<std::string> ids = GetInstance ()->GetModuleIds ();
527
523
info.GetReturnValue ().Set (
528
524
ToV8Value (isolate->GetCurrentContext (), ids).ToLocalChecked ());
529
525
}
@@ -550,8 +546,7 @@ void NativeModuleLoader::CompileFunction(
550
546
const char * id = *id_v;
551
547
NativeModuleLoader::Result result;
552
548
MaybeLocal<Function> maybe =
553
- NativeModuleLoader::GetInstance ()->CompileAsModule (
554
- env->context (), id, &result);
549
+ GetInstance ()->CompileAsModule (env->context (), id, &result);
555
550
RecordResult (id, result, env);
556
551
Local<Function> fn;
557
552
if (maybe.ToLocal (&fn)) {
@@ -562,7 +557,7 @@ void NativeModuleLoader::CompileFunction(
562
557
void NativeModuleLoader::HasCachedBuiltins (
563
558
const FunctionCallbackInfo<Value>& args) {
564
559
args.GetReturnValue ().Set (
565
- v8::Boolean::New (args.GetIsolate (), NativeModuleLoader:: has_code_cache_));
560
+ v8::Boolean::New (args.GetIsolate (), GetInstance ()-> has_code_cache_ ));
566
561
}
567
562
568
563
// TODO(joyeecheung): It is somewhat confusing that Class::Initialize
0 commit comments