|
22 | 22 | #include "DisposerPHV.h" |
23 | 23 | #include "IsolateWrapper.h" |
24 | 24 |
|
| 25 | +#include <mutex> |
25 | 26 | #include <unordered_map> |
| 27 | +#include "DevFlags.h" |
| 28 | +#include "HMRSupport.h" |
26 | 29 | #include "ModuleBinding.hpp" |
27 | 30 | #include "ModuleInternalCallbacks.h" |
28 | 31 | #include "URLImpl.h" |
29 | 32 | #include "URLPatternImpl.h" |
30 | 33 | #include "URLSearchParamsImpl.h" |
31 | | -#include <mutex> |
32 | | -#include "HMRSupport.h" |
33 | | -#include "DevFlags.h" |
34 | 34 |
|
35 | 35 | #define STRINGIZE(x) #x |
36 | 36 | #define STRINGIZE_VALUE_OF(x) STRINGIZE(x) |
@@ -128,7 +128,7 @@ static void InitializeImportMetaObject(Local<Context> context, Local<Module> mod |
128 | 128 | std::atomic<int> Runtime::nextIsolateId{0}; |
129 | 129 | SimpleAllocator allocator_; |
130 | 130 | NSDictionary* AppPackageJson = nil; |
131 | | -static std::unordered_map<std::string, id> AppConfigCache; // generic cache for app config values |
| 131 | +static std::unordered_map<std::string, id> AppConfigCache; // generic cache for app config values |
132 | 132 | static std::mutex AppConfigCacheMutex; |
133 | 133 |
|
134 | 134 | // Global flag to track when JavaScript errors occur during execution |
@@ -261,6 +261,9 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { |
261 | 261 | v8Initialized_ = true; |
262 | 262 | } |
263 | 263 |
|
| 264 | + int runtimeId = Runtime::nextRuntimeId_.fetch_add(1, std::memory_order_relaxed); |
| 265 | + this->SetWorkerId(runtimeId); |
| 266 | + |
264 | 267 | startTime = platform_->MonotonicallyIncreasingTime(); |
265 | 268 | realtimeOrigin = platform_->CurrentClockTimeMillis(); |
266 | 269 |
|
@@ -301,8 +304,8 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { |
301 | 304 | DefineDrainMicrotaskMethod(isolate, globalTemplate); |
302 | 305 | // queueMicrotask(callback) per spec |
303 | 306 | { |
304 | | - Local<FunctionTemplate> qmtTemplate = FunctionTemplate::New( |
305 | | - isolate, [](const FunctionCallbackInfo<Value>& info) { |
| 307 | + Local<FunctionTemplate> qmtTemplate = |
| 308 | + FunctionTemplate::New(isolate, [](const FunctionCallbackInfo<Value>& info) { |
306 | 309 | auto* isolate = info.GetIsolate(); |
307 | 310 | if (info.Length() < 1 || !info[0]->IsFunction()) { |
308 | 311 | isolate->ThrowException(Exception::TypeError( |
@@ -434,6 +437,11 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { |
434 | 437 | v8::Locker locker(isolate); |
435 | 438 | Isolate::Scope isolate_scope(isolate); |
436 | 439 | HandleScope handle_scope(isolate); |
| 440 | + |
| 441 | + auto cache = Caches::Get(isolate); |
| 442 | + auto context = cache->GetContext(); |
| 443 | + Context::Scope context_scope(context); |
| 444 | + |
437 | 445 | this->moduleInternal_->RunModule(isolate, "./"); |
438 | 446 | } |
439 | 447 |
|
@@ -488,7 +496,8 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { |
488 | 496 | result = AppPackageJson[nsKey]; |
489 | 497 | } |
490 | 498 |
|
491 | | - // Store in cache (can cache nil as NSNull to differentiate presence if desired; for now, cache as-is) |
| 499 | + // Store in cache (can cache nil as NSNull to differentiate presence if desired; for now, cache |
| 500 | + // as-is) |
492 | 501 | { |
493 | 502 | std::lock_guard<std::mutex> lock(AppConfigCacheMutex); |
494 | 503 | AppConfigCache[key] = result; |
@@ -624,6 +633,7 @@ void DisposeIsolateWhenPossible(Isolate* isolate) { |
624 | 633 | std::vector<Isolate*> Runtime::isolates_; |
625 | 634 | bool Runtime::v8Initialized_ = false; |
626 | 635 | thread_local Runtime* Runtime::currentRuntime_ = nullptr; |
| 636 | +std::atomic<int> Runtime::nextRuntimeId_ = {0}; |
627 | 637 | SpinMutex Runtime::isolatesMutex_; |
628 | 638 |
|
629 | 639 | } // namespace tns |
0 commit comments