Initialize V8 outside of PDFium.
authorJohn Abd-El-Malek <jam@chromium.org>
Thu, 5 Feb 2015 00:04:05 +0000 (16:04 -0800)
committerJohn Abd-El-Malek <jam@chromium.org>
Thu, 5 Feb 2015 00:04:05 +0000 (16:04 -0800)
This is similar to how we initialize ICU for V8 inside PDFium.

BUG=455399
R=wfh@chromium.org

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

fpdfsdk/include/javascript/IJavaScript.h
fpdfsdk/src/javascript/JS_Runtime.cpp
pdfium.gyp
samples/pdfium_test.cc
samples/samples.gyp

index 8ea9a4e..9ae0329 100644 (file)
@@ -7,10 +7,6 @@
 #ifndef _IJAVASCRIPT_H_
 #define _IJAVASCRIPT_H_
 
-namespace v8 {
-class Platform;
-}
-
 class IFXJS_Context
 {
 public:
@@ -99,7 +95,7 @@ class CJS_GlobalData;
 class CJS_RuntimeFactory
 {
 public:
-       CJS_RuntimeFactory():m_bInit(FALSE),m_nRef(0),m_pGlobalData(NULL),m_nGlobalDataCount(0),m_platform(NULL) {}
+       CJS_RuntimeFactory():m_bInit(FALSE),m_nRef(0),m_pGlobalData(NULL),m_nGlobalDataCount(0) {}
        ~CJS_RuntimeFactory();
        IFXJS_Runtime*                                  NewJSRuntime(CPDFDoc_Environment* pApp);
        void                                                    DeleteJSRuntime(IFXJS_Runtime* pRuntime);
@@ -113,7 +109,6 @@ private:
        int m_nRef;
        CJS_GlobalData*                                 m_pGlobalData;
        FX_INT32                                                m_nGlobalDataCount;
-        v8::Platform*                                          m_platform;
 };
 
 #endif //_IJAVASCRIPT_H_
index 52e3ae8..30d1cc3 100644 (file)
@@ -27,8 +27,6 @@
 #include "../../include/javascript/global.h"
 #include "../../include/javascript/console.h"
 
-#include <libplatform/libplatform.h>
-
 CJS_RuntimeFactory::~CJS_RuntimeFactory()
 {
 }
@@ -38,10 +36,6 @@ IFXJS_Runtime*                                       CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
        if (!m_bInit)
        {
                JS_Initial();
-                m_platform = v8::platform::CreateDefaultPlatform();
-                v8::V8::InitializePlatform(m_platform);
-                v8::V8::Initialize();
-               
                m_bInit = TRUE;
        }
        return new CJS_Runtime(pApp);
@@ -60,9 +54,6 @@ void                                                  CJS_RuntimeFactory::Release()
                {
                        JS_Release();
                        ReleaseGlobalData();
-                        v8::V8::ShutdownPlatform();
-                        delete m_platform;
-                        m_platform = NULL;
                        m_bInit = FALSE;
                }
        }
index df85452..c23059d 100644 (file)
     {
       'target_name': 'javascript',
       'type': 'static_library',
-        'include_dirs': [
-          '<(DEPTH)/v8',
-          '<(DEPTH)/v8/include',
-        ],
+      'include_dirs': [
+        '<(DEPTH)/v8',
+        '<(DEPTH)/v8/include',
+      ],
       'dependencies': [
         '<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
-        '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform',
       ],
       'export_dependent_settings': [
         '<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
index debe033..7ba85ef 100644 (file)
@@ -20,6 +20,7 @@
 #include "../fpdfsdk/include/fpdfview.h"
 #include "../core/include/fxcrt/fx_system.h"
 #include "v8/include/v8.h"
+#include "v8/include/libplatform/libplatform.h"
 
 #ifdef _WIN32
 #define snprintf _snprintf
@@ -497,6 +498,9 @@ int main(int argc, const char* argv[]) {
   }
 
   v8::V8::InitializeICU();
+  v8::Platform* platform = v8::platform::CreateDefaultPlatform();
+  v8::V8::InitializePlatform(platform);
+  v8::V8::Initialize();
 
 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
   v8::StartupData natives;
@@ -530,6 +534,8 @@ int main(int argc, const char* argv[]) {
   }
 
   FPDF_DestroyLibrary();
+  v8::V8::ShutdownPlatform();
+  delete platform;
 
   return 0;
 }
index 0c8ee93..607a5b9 100644 (file)
@@ -7,8 +7,13 @@
     'type': 'executable',
     'dependencies': [
       '../pdfium.gyp:pdfium',
+      '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform',
+    ],
+    'include_dirs': [
+      '<(DEPTH)',
+      '<(DEPTH)/v8',
+      '<(DEPTH)/v8/include',
     ],
-    'include_dirs': ['<(DEPTH)'],
   },
   'targets': [
     {