diff --git a/NativeScript/runtime/Runtime.mm b/NativeScript/runtime/Runtime.mm index e98f56f4..530aa922 100644 --- a/NativeScript/runtime/Runtime.mm +++ b/NativeScript/runtime/Runtime.mm @@ -22,15 +22,15 @@ #include "DisposerPHV.h" #include "IsolateWrapper.h" +#include #include +#include "DevFlags.h" +#include "HMRSupport.h" #include "ModuleBinding.hpp" #include "ModuleInternalCallbacks.h" #include "URLImpl.h" #include "URLPatternImpl.h" #include "URLSearchParamsImpl.h" -#include -#include "HMRSupport.h" -#include "DevFlags.h" #define STRINGIZE(x) #x #define STRINGIZE_VALUE_OF(x) STRINGIZE(x) @@ -128,7 +128,7 @@ static void InitializeImportMetaObject(Local context, Local mod std::atomic Runtime::nextIsolateId{0}; SimpleAllocator allocator_; NSDictionary* AppPackageJson = nil; -static std::unordered_map AppConfigCache; // generic cache for app config values +static std::unordered_map AppConfigCache; // generic cache for app config values static std::mutex AppConfigCacheMutex; // Global flag to track when JavaScript errors occur during execution @@ -301,8 +301,8 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { DefineDrainMicrotaskMethod(isolate, globalTemplate); // queueMicrotask(callback) per spec { - Local qmtTemplate = FunctionTemplate::New( - isolate, [](const FunctionCallbackInfo& info) { + Local qmtTemplate = + FunctionTemplate::New(isolate, [](const FunctionCallbackInfo& info) { auto* isolate = info.GetIsolate(); if (info.Length() < 1 || !info[0]->IsFunction()) { isolate->ThrowException(Exception::TypeError( @@ -434,6 +434,11 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { v8::Locker locker(isolate); Isolate::Scope isolate_scope(isolate); HandleScope handle_scope(isolate); + + auto cache = Caches::Get(isolate); + auto context = cache->GetContext(); + Context::Scope context_scope(context); + this->moduleInternal_->RunModule(isolate, "./"); } @@ -441,6 +446,11 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { Isolate* isolate = this->GetIsolate(); Isolate::Scope isolate_scope(isolate); HandleScope handle_scope(isolate); + + auto cache = Caches::Get(isolate); + auto context = cache->GetContext(); + Context::Scope context_scope(context); + this->moduleInternal_->RunModule(isolate, moduleName); } @@ -449,6 +459,11 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { v8::Locker locker(isolate); Isolate::Scope isolate_scope(isolate); HandleScope handle_scope(isolate); + + auto cache = Caches::Get(isolate); + auto context = cache->GetContext(); + Context::Scope context_scope(context); + this->moduleInternal_->RunScript(isolate, script); } @@ -488,7 +503,8 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { result = AppPackageJson[nsKey]; } - // Store in cache (can cache nil as NSNull to differentiate presence if desired; for now, cache as-is) + // Store in cache (can cache nil as NSNull to differentiate presence if desired; for now, cache + // as-is) { std::lock_guard lock(AppConfigCacheMutex); AppConfigCache[key] = result;