OLD | NEW |
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 "../../../xfa/src/fxjse/src/value.h" | 9 #include "../../../xfa/src/fxjse/src/value.h" |
10 #include "../../include/fpdfxfa/fpdfxfa_app.h" | 10 #include "../../include/fpdfxfa/fpdfxfa_app.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "app.h" | 22 #include "app.h" |
23 #include "color.h" | 23 #include "color.h" |
24 #include "console.h" | 24 #include "console.h" |
25 #include "event.h" | 25 #include "event.h" |
26 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. | 26 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. |
27 #include "fpdfsdk/include/javascript/IJavaScript.h" | 27 #include "fpdfsdk/include/javascript/IJavaScript.h" |
28 #include "global.h" | 28 #include "global.h" |
29 #include "report.h" | 29 #include "report.h" |
30 #include "util.h" | 30 #include "util.h" |
31 | 31 |
32 /* ------------------------------ CJS_Runtime ------------------------------ */ | |
33 v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate); | |
34 | |
35 // static | 32 // static |
36 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { | 33 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { |
37 FXJS_Initialize(slot, reinterpret_cast<v8::Isolate*>(isolate)); | 34 FXJS_Initialize(slot, reinterpret_cast<v8::Isolate*>(isolate)); |
38 } | 35 } |
39 | 36 |
40 // static | 37 // static |
41 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { | 38 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { |
42 return new CJS_Runtime(pEnv); | 39 return new CJS_Runtime(pEnv); |
43 } | 40 } |
44 | 41 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 86 |
90 CJS_Context* pContext = (CJS_Context*)NewContext(); | 87 CJS_Context* pContext = (CJS_Context*)NewContext(); |
91 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); | 88 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); |
92 ReleaseContext(pContext); | 89 ReleaseContext(pContext); |
93 } | 90 } |
94 | 91 |
95 CJS_Runtime::~CJS_Runtime() { | 92 CJS_Runtime::~CJS_Runtime() { |
96 for (auto* obs : m_observers) | 93 for (auto* obs : m_observers) |
97 obs->OnDestroyed(); | 94 obs->OnDestroyed(); |
98 | 95 |
99 int size = m_ContextArray.GetSize(); | 96 for (int i = 0; i < m_ContextArray.GetSize(); i++) |
100 for (int i = 0; i < size; i++) | |
101 delete m_ContextArray.GetAt(i); | 97 delete m_ContextArray.GetAt(i); |
102 | 98 |
103 m_ContextArray.RemoveAll(); | 99 m_ContextArray.RemoveAll(); |
104 | 100 |
105 m_pApp = NULL; | 101 m_pApp = NULL; |
106 m_pDocument = NULL; | 102 m_pDocument = NULL; |
107 m_context.Reset(); | 103 m_context.Reset(); |
108 | 104 |
109 if (m_isolateManaged) | 105 if (m_isolateManaged) |
110 m_isolate->Dispose(); | 106 m_isolate->Dispose(); |
111 m_isolate = NULL; | |
112 } | 107 } |
113 | 108 |
114 void CJS_Runtime::DefineJSObjects() { | 109 void CJS_Runtime::DefineJSObjects() { |
115 v8::Isolate::Scope isolate_scope(GetIsolate()); | 110 v8::Isolate::Scope isolate_scope(GetIsolate()); |
116 v8::Locker locker(GetIsolate()); | 111 v8::Locker locker(GetIsolate()); |
117 v8::HandleScope handle_scope(GetIsolate()); | 112 v8::HandleScope handle_scope(GetIsolate()); |
118 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); | 113 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); |
119 v8::Context::Scope context_scope(context); | 114 v8::Context::Scope context_scope(context); |
120 | 115 |
121 // The call order determines the "ObjDefID" assigned to each class. | 116 // The call order determines the "ObjDefID" assigned to each class. |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 295 |
301 void CJS_Runtime::AddObserver(Observer* observer) { | 296 void CJS_Runtime::AddObserver(Observer* observer) { |
302 ASSERT(m_observers.find(observer) == m_observers.end()); | 297 ASSERT(m_observers.find(observer) == m_observers.end()); |
303 m_observers.insert(observer); | 298 m_observers.insert(observer); |
304 } | 299 } |
305 | 300 |
306 void CJS_Runtime::RemoveObserver(Observer* observer) { | 301 void CJS_Runtime::RemoveObserver(Observer* observer) { |
307 ASSERT(m_observers.find(observer) != m_observers.end()); | 302 ASSERT(m_observers.find(observer) != m_observers.end()); |
308 m_observers.erase(observer); | 303 m_observers.erase(observer); |
309 } | 304 } |
OLD | NEW |