Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: fpdfsdk/src/javascript/JS_Runtime.cpp

Issue 1367033002: Pass v8::Isolate to PDFium at init time. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: fix leak, clear globals while we're at it. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_EventHandler.h" 9 #include "../../include/javascript/JS_EventHandler.h"
10 #include "../../include/javascript/JS_Runtime.h" 10 #include "../../include/javascript/JS_Runtime.h"
(...skipping 17 matching lines...) Expand all
28 #include "../../include/javascript/console.h" 28 #include "../../include/javascript/console.h"
29 29
30 /* ------------------------------ CJS_Runtime ------------------------------ */ 30 /* ------------------------------ CJS_Runtime ------------------------------ */
31 31
32 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) 32 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
33 : m_pApp(pApp), 33 : m_pApp(pApp),
34 m_pDocument(NULL), 34 m_pDocument(NULL),
35 m_bBlocking(FALSE), 35 m_bBlocking(FALSE),
36 m_isolate(NULL), 36 m_isolate(NULL),
37 m_isolateManaged(false) { 37 m_isolateManaged(false) {
38 unsigned int embedderDataSlot = 0; 38 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform;
39 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { 39 if (pPlatform->version <= 2) {
Lei Zhang 2015/10/02 22:02:15 Can you mention this is the deprecated way and mar
Tom Sepez 2015/10/02 22:46:50 Oh yes, once chrome catches up, using v2 is going
40 m_isolate = reinterpret_cast<v8::Isolate*>( 40 unsigned int embedderDataSlot = 0;
41 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); 41 v8::Isolate* pExternalIsolate = nullptr;
42 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; 42 if (pPlatform->version == 2) {
43 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
44 embedderDataSlot = pPlatform->m_v8EmbedderSlot;
45 }
46 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
43 } 47 }
44 if (!m_isolate) { 48 m_isolateManaged = FXJS_GetIsolate(&m_isolate);
45 m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator());
46
47 v8::Isolate::CreateParams params;
48 params.array_buffer_allocator = m_pArrayBufferAllocator.get();
49 m_isolate = v8::Isolate::New(params);
50 m_isolateManaged = true;
51 }
52
53 FXJS_Initialize(embedderDataSlot);
54 DefineJSObjects(); 49 DefineJSObjects();
55 50
56 CJS_Context* pContext = (CJS_Context*)NewContext(); 51 CJS_Context* pContext = (CJS_Context*)NewContext();
57 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); 52 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context);
58 ReleaseContext(pContext); 53 ReleaseContext(pContext);
59 } 54 }
60 55
61 CJS_Runtime::~CJS_Runtime() { 56 CJS_Runtime::~CJS_Runtime() {
62 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) 57 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++)
63 delete m_ContextArray.GetAt(i); 58 delete m_ContextArray.GetAt(i);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 174
180 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { 175 v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
181 return v8::Local<v8::Context>::New(m_isolate, m_context); 176 return v8::Local<v8::Context>::New(m_isolate, m_context);
182 } 177 }
183 178
184 CFX_WideString ChangeObjName(const CFX_WideString& str) { 179 CFX_WideString ChangeObjName(const CFX_WideString& str) {
185 CFX_WideString sRet = str; 180 CFX_WideString sRet = str;
186 sRet.Replace(L"_", L"."); 181 sRet.Replace(L"_", L".");
187 return sRet; 182 return sRet;
188 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698