| 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 14 matching lines...) Expand all Loading... |
| 25 #include "color.h" | 25 #include "color.h" |
| 26 #include "console.h" | 26 #include "console.h" |
| 27 #include "event.h" | 27 #include "event.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 ------------------------------ */ | 32 /* ------------------------------ CJS_Runtime ------------------------------ */ |
| 33 v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate); | 33 v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate); |
| 34 | 34 |
| 35 IFXJS_Runtime* IFXJS_Runtime::Create(CPDFDoc_Environment* pEnv) { | 35 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { |
| 36 return new CJS_Runtime(pEnv); | 36 return new CJS_Runtime(pEnv); |
| 37 } | 37 } |
| 38 | 38 |
| 39 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) | 39 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) |
| 40 : m_pApp(pApp), | 40 : m_pApp(pApp), |
| 41 m_pDocument(NULL), | 41 m_pDocument(NULL), |
| 42 m_bBlocking(FALSE), | 42 m_bBlocking(FALSE), |
| 43 m_isolate(NULL), | 43 m_isolate(NULL), |
| 44 m_isolateManaged(false) { | 44 m_isolateManaged(false) { |
| 45 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { | 45 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // ObjDefIDs 18 - 20 (these can't fail, return void). | 138 // ObjDefIDs 18 - 20 (these can't fail, return void). |
| 139 CJS_PublicMethods::DefineJSObjects(GetIsolate()); | 139 CJS_PublicMethods::DefineJSObjects(GetIsolate()); |
| 140 CJS_GlobalConsts::DefineJSObjects(GetIsolate()); | 140 CJS_GlobalConsts::DefineJSObjects(GetIsolate()); |
| 141 CJS_GlobalArrays::DefineJSObjects(GetIsolate()); | 141 CJS_GlobalArrays::DefineJSObjects(GetIsolate()); |
| 142 | 142 |
| 143 // ObjDefIDs 21 - 22. | 143 // ObjDefIDs 21 - 22. |
| 144 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); | 144 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); |
| 145 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); | 145 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); |
| 146 } | 146 } |
| 147 | 147 |
| 148 IFXJS_Context* CJS_Runtime::NewContext() { | 148 IJS_Context* CJS_Runtime::NewContext() { |
| 149 CJS_Context* p = new CJS_Context(this); | 149 CJS_Context* p = new CJS_Context(this); |
| 150 m_ContextArray.Add(p); | 150 m_ContextArray.Add(p); |
| 151 return p; | 151 return p; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void CJS_Runtime::ReleaseContext(IFXJS_Context* pContext) { | 154 void CJS_Runtime::ReleaseContext(IJS_Context* pContext) { |
| 155 CJS_Context* pJSContext = (CJS_Context*)pContext; | 155 CJS_Context* pJSContext = (CJS_Context*)pContext; |
| 156 | 156 |
| 157 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) { | 157 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) { |
| 158 if (pJSContext == m_ContextArray.GetAt(i)) { | 158 if (pJSContext == m_ContextArray.GetAt(i)) { |
| 159 delete pJSContext; | 159 delete pJSContext; |
| 160 m_ContextArray.RemoveAt(i); | 160 m_ContextArray.RemoveAt(i); |
| 161 break; | 161 break; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 IFXJS_Context* CJS_Runtime::GetCurrentContext() { | 166 IJS_Context* CJS_Runtime::GetCurrentContext() { |
| 167 if (!m_ContextArray.GetSize()) | 167 if (!m_ContextArray.GetSize()) |
| 168 return NULL; | 168 return NULL; |
| 169 return m_ContextArray.GetAt(m_ContextArray.GetSize() - 1); | 169 return m_ContextArray.GetAt(m_ContextArray.GetSize() - 1); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { | 172 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { |
| 173 if (m_pDocument != pReaderDoc) { | 173 if (m_pDocument != pReaderDoc) { |
| 174 v8::Isolate::Scope isolate_scope(m_isolate); | 174 v8::Isolate::Scope isolate_scope(m_isolate); |
| 175 v8::Locker locker(m_isolate); | 175 v8::Locker locker(m_isolate); |
| 176 v8::HandleScope handle_scope(m_isolate); | 176 v8::HandleScope handle_scope(m_isolate); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 void CJS_Runtime::AddObserver(Observer* observer) { | 264 void CJS_Runtime::AddObserver(Observer* observer) { |
| 265 ASSERT(m_observers.find(observer) == m_observers.end()); | 265 ASSERT(m_observers.find(observer) == m_observers.end()); |
| 266 m_observers.insert(observer); | 266 m_observers.insert(observer); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void CJS_Runtime::RemoveObserver(Observer* observer) { | 269 void CJS_Runtime::RemoveObserver(Observer* observer) { |
| 270 ASSERT(m_observers.find(observer) != m_observers.end()); | 270 ASSERT(m_observers.find(observer) != m_observers.end()); |
| 271 m_observers.erase(observer); | 271 m_observers.erase(observer); |
| 272 } | 272 } |
| OLD | NEW |