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

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

Issue 1424933013: Keep "static" objects per-context rather than per isolate. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month 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 "JS_Runtime.h" 7 #include "JS_Runtime.h"
8 8
9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. 9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment.
10 #include "../../include/javascript/IJavaScript.h" 10 #include "../../include/javascript/IJavaScript.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); 57 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
58 embedderDataSlot = pPlatform->m_v8EmbedderSlot; 58 embedderDataSlot = pPlatform->m_v8EmbedderSlot;
59 } 59 }
60 FXJS_Initialize(embedderDataSlot, pExternalIsolate); 60 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
61 } 61 }
62 m_isolateManaged = FXJS_GetIsolate(&m_isolate); 62 m_isolateManaged = FXJS_GetIsolate(&m_isolate);
63 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) 63 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
64 DefineJSObjects(); 64 DefineJSObjects();
65 65
66 CJS_Context* pContext = (CJS_Context*)NewContext(); 66 CJS_Context* pContext = (CJS_Context*)NewContext();
67 FXJS_InitializeRuntime(GetIsolate(), this, m_context); 67 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
68 ReleaseContext(pContext); 68 ReleaseContext(pContext);
69 } 69 }
70 70
71 CJS_Runtime::~CJS_Runtime() { 71 CJS_Runtime::~CJS_Runtime() {
72 for (auto* obs : m_observers) 72 for (auto* obs : m_observers)
73 obs->OnDestroyed(); 73 obs->OnDestroyed();
74 74
75 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) 75 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++)
76 delete m_ContextArray.GetAt(i); 76 delete m_ContextArray.GetAt(i);
77 77
78 m_ContextArray.RemoveAll(); 78 m_ContextArray.RemoveAll();
79 FXJS_ReleaseRuntime(GetIsolate(), m_context); 79 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects);
80 80
81 m_pApp = NULL; 81 m_pApp = NULL;
82 m_pDocument = NULL; 82 m_pDocument = NULL;
83 m_context.Reset(); 83 m_context.Reset();
84 84
85 if (m_isolateManaged) 85 if (m_isolateManaged)
86 m_isolate->Dispose(); 86 m_isolate->Dispose();
87 } 87 }
88 88
89 void CJS_Runtime::DefineJSObjects() { 89 void CJS_Runtime::DefineJSObjects() {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 void CJS_Runtime::AddObserver(Observer* observer) { 208 void CJS_Runtime::AddObserver(Observer* observer) {
209 ASSERT(m_observers.find(observer) == m_observers.end()); 209 ASSERT(m_observers.find(observer) == m_observers.end());
210 m_observers.insert(observer); 210 m_observers.insert(observer);
211 } 211 }
212 212
213 void CJS_Runtime::RemoveObserver(Observer* observer) { 213 void CJS_Runtime::RemoveObserver(Observer* observer) {
214 ASSERT(m_observers.find(observer) != m_observers.end()); 214 ASSERT(m_observers.find(observer) != m_observers.end());
215 m_observers.erase(observer); 215 m_observers.erase(observer);
216 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698