Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
chakrashim: allow Persistent::Reset after V8::Dispose
Browse files Browse the repository at this point in the history
Some addons use global static Persistent to hold references. ~Persistent()
and Persistent::Reset() are called at process exit when the runtime has
already been disposed.

Add a global g_disposed flag to record V8::Dispose()/V8::IsDead() state.
Make Persistent::Reset() no-op if V8::IsDead(). This allows above scenario.

PR-URL: #33
Reviewed-By: Sandeep Agarwal <Agarwal.Sandeep@microsoft.com>
  • Loading branch information
Jianchun Xu committed Mar 3, 2016
1 parent fc3cf3e commit 9e23f00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deps/chakrashim/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2453,7 +2453,7 @@ bool PersistentBase<T>::IsWeak() const {

template <class T>
void PersistentBase<T>::Reset() {
if (this->IsEmpty()) return;
if (this->IsEmpty() || V8::IsDead()) return;

if (IsWeak()) {
if (_weakWrapper.unique()) {
Expand Down
8 changes: 6 additions & 2 deletions deps/chakrashim/src/v8v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace v8 {

bool g_disposed = false;
bool g_exposeGC = false;
bool g_useStrict = false;
ArrayBuffer::Allocator* g_arrayBufferAllocator = nullptr;
Expand Down Expand Up @@ -124,6 +125,9 @@ void V8::SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags) {
}

bool V8::Initialize() {
if (g_disposed) {
return false; // Can no longer Initialize if Disposed
}
#ifndef NODE_ENGINE_CHAKRACORE
if (g_EnableDebug && JsStartDebugging() != JsNoError) {
return false;
Expand All @@ -142,11 +146,11 @@ void V8::SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator) {
}

bool V8::IsDead() {
// CHAKRA-TODO
return false;
return g_disposed;
}

bool V8::Dispose() {
g_disposed = true;
jsrt::IsolateShim::DisposeAll();
Debug::Dispose();
return true;
Expand Down

0 comments on commit 9e23f00

Please sign in to comment.