Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions NativeScript/runtime/Runtime.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#include "DisposerPHV.h"
#include "IsolateWrapper.h"

#include <mutex>
#include <unordered_map>
#include "DevFlags.h"
#include "HMRSupport.h"
#include "ModuleBinding.hpp"
#include "ModuleInternalCallbacks.h"
#include "URLImpl.h"
#include "URLPatternImpl.h"
#include "URLSearchParamsImpl.h"
#include <mutex>
#include "HMRSupport.h"
#include "DevFlags.h"

#define STRINGIZE(x) #x
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
Expand Down Expand Up @@ -128,7 +128,7 @@ static void InitializeImportMetaObject(Local<Context> context, Local<Module> mod
std::atomic<int> Runtime::nextIsolateId{0};
SimpleAllocator allocator_;
NSDictionary* AppPackageJson = nil;
static std::unordered_map<std::string, id> AppConfigCache; // generic cache for app config values
static std::unordered_map<std::string, id> AppConfigCache; // generic cache for app config values
static std::mutex AppConfigCacheMutex;

// Global flag to track when JavaScript errors occur during execution
Expand Down Expand Up @@ -301,8 +301,8 @@ void DisposeIsolateWhenPossible(Isolate* isolate) {
DefineDrainMicrotaskMethod(isolate, globalTemplate);
// queueMicrotask(callback) per spec
{
Local<FunctionTemplate> qmtTemplate = FunctionTemplate::New(
isolate, [](const FunctionCallbackInfo<Value>& info) {
Local<FunctionTemplate> qmtTemplate =
FunctionTemplate::New(isolate, [](const FunctionCallbackInfo<Value>& info) {
auto* isolate = info.GetIsolate();
if (info.Length() < 1 || !info[0]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(
Expand Down Expand Up @@ -434,13 +434,23 @@ 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, "./");
}

void Runtime::RunModule(const std::string moduleName) {
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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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<std::mutex> lock(AppConfigCacheMutex);
AppConfigCache[key] = result;
Expand Down