Skip to content

Commit 3d70c11

Browse files
committed
fix: prevent crashes during isolate disposal
1 parent e954c78 commit 3d70c11

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

NativeScript/runtime/Caches.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ class Caches {
7575
return isolateId_;
7676
}
7777

78+
inline void InvalidateIsolate() {
79+
isolateId_ = -1;
80+
}
81+
82+
inline bool IsValid() {
83+
return isolateId_ != -1;
84+
}
85+
7886
void SetContext(v8::Local<v8::Context> context);
7987
v8::Local<v8::Context> GetContext();
8088

NativeScript/runtime/Runtime.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void DisposeIsolateWhenPossible(Isolate* isolate) {
7070
// it terminates execution
7171
SpinLock lock(isolatesMutex_);
7272
Runtime::isolates_.erase(std::remove(Runtime::isolates_.begin(), Runtime::isolates_.end(), this->isolate_), Runtime::isolates_.end());
73+
Caches::Get(isolate_)->InvalidateIsolate();
7374
}
7475
this->isolate_->TerminateExecution();
7576

@@ -306,7 +307,8 @@ void DisposeIsolateWhenPossible(Isolate* isolate) {
306307
// speedup lookup by avoiding locking if thread locals match
307308
// note: this can be a problem when the Runtime is deleted in a different thread that it was created
308309
// which could happen under some specific embedding scenarios
309-
if (Isolate::TryGetCurrent() == isolate || (currentRuntime_ != nullptr && currentRuntime_->GetIsolate() == isolate)) {
310+
if ((Isolate::TryGetCurrent() == isolate || (currentRuntime_ != nullptr && currentRuntime_->GetIsolate() == isolate))
311+
&& Caches::Get((Isolate*)isolate)->IsValid()) {
310312
return true;
311313
}
312314
SpinLock lock(isolatesMutex_);

0 commit comments

Comments
 (0)