Only call DefineJSObjects() once for the global V8 isolate.
authorLei Zhang <thestig@chromium.org>
Mon, 5 Oct 2015 03:40:15 +0000 (20:40 -0700)
committerLei Zhang <thestig@chromium.org>
Mon, 5 Oct 2015 03:40:15 +0000 (20:40 -0700)
BUG=539106
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/1386823002 .

fpdfsdk/include/jsapi/fxjs_v8.h
fpdfsdk/src/javascript/JS_Runtime.cpp
fpdfsdk/src/jsapi/fxjs_v8.cpp

index 1705b89..8b5c0b2 100644 (file)
@@ -70,6 +70,9 @@ void FXJS_Release();
 // created.
 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate);
 
+// Get the global isolate's ref count.
+size_t FXJS_GlobalIsolateRefCount();
+
 // Call before making FXJS_Define* calls. Resources allocated here are cleared
 // as part of FXJS_ReleaseRuntime().
 void FXJS_PrepareIsolate(v8::Isolate* pIsolate);
index 4c502a7..707551a 100644 (file)
@@ -45,7 +45,8 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
     FXJS_Initialize(embedderDataSlot, pExternalIsolate);
   }
   m_isolateManaged = FXJS_GetIsolate(&m_isolate);
-  DefineJSObjects();
+  if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
+    DefineJSObjects();
 
   CJS_Context* pContext = (CJS_Context*)NewContext();
   FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context);
index bea9f4c..54044e2 100644 (file)
@@ -166,6 +166,10 @@ bool FXJS_GetIsolate(v8::Isolate** pResultIsolate) {
   return true;
 }
 
+size_t FXJS_GlobalIsolateRefCount() {
+  return g_isolate_ref_count;
+}
+
 // static
 void FXJS_PerIsolateData::SetUp(v8::Isolate* pIsolate) {
   if (!pIsolate->GetData(g_embedderDataSlot))