Revert "Fix else-after-returns throughout pdfium."
[pdfium.git] / fpdfsdk / src / javascript / JS_Runtime.cpp
index c2c1a51..34a451b 100644 (file)
@@ -35,7 +35,11 @@ IFXJS_Runtime*                                       CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
 {
        if (!m_bInit)
        {
-               JS_Initial();
+               unsigned int embedderDataSlot = 0;
+               if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+                       embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
+                }
+               JS_Initial(embedderDataSlot);
                m_bInit = TRUE;
        }
        return new CJS_Runtime(pApp);
@@ -61,8 +65,7 @@ void                                                  CJS_RuntimeFactory::Release()
 
 void                                                   CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
 {
-       if(pRuntime)
-               delete (CJS_Runtime*)pRuntime;
+    delete (CJS_Runtime*)pRuntime;
 }
 
 CJS_GlobalData*        CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
@@ -109,14 +112,19 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
        m_pApp(pApp),
        m_pDocument(NULL),
        m_bBlocking(FALSE),
-       m_bRegistered(FALSE),
-       m_pFieldEventPath(NULL)
+       m_pFieldEventPath(NULL),
+        m_isolate(NULL)
 {
-       m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
+       if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+               m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
+       }
+       if (!m_isolate) {
+               m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
 
-       v8::Isolate::CreateParams params;
-       params.array_buffer_allocator = m_pArrayBufferAllocator.get();
-       m_isolate = v8::Isolate::New(params);
+               v8::Isolate::CreateParams params;
+               params.array_buffer_allocator = m_pArrayBufferAllocator.get();
+               m_isolate = v8::Isolate::New(params);
+        }
 
        InitJSObjects();