Skip to content

Commit 4c2118a

Browse files
committed
static-lib: do not force-uninitialize on atexit when context IsInScript
1 parent 6630ef9 commit 4c2118a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/Jsrt/JsrtHelper.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ void JsrtCallbackState::ObjectBeforeCallectCallbackWrapper(JsObjectBeforeCollect
109109
// we do not track the main thread. When it exits do the cleanup below
110110
#ifdef CHAKRA_STATIC_LIBRARY
111111
atexit([]() {
112-
ThreadBoundThreadContextManager::DestroyContextAndEntryForCurrentThread();
112+
ThreadContext *threadContext = ThreadContext::GetContextForCurrentThread();
113+
if (threadContext)
114+
{
115+
if (threadContext->IsInScript()) return;
116+
ThreadBoundThreadContextManager::DestroyContextAndEntryForCurrentThread();
117+
}
113118

114119
JsrtRuntime::Uninitialize();
115120

lib/Jsrt/JsrtRuntime.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ void JsrtRuntime::Uninitialize()
5353
while (currentThreadContext)
5454
{
5555
Assert(!currentThreadContext->IsScriptActive());
56+
#ifdef CHAKRA_STATIC_LIBRARY
57+
if (currentThreadContext->IsInScript()) break;
58+
#endif
5659
JsrtRuntime* currentRuntime = static_cast<JsrtRuntime*>(currentThreadContext->GetJSRTRuntime());
5760
tmpThreadContext = currentThreadContext;
5861
currentThreadContext = currentThreadContext->Next();

0 commit comments

Comments
 (0)