| 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 "fpdfsdk/src/javascript/JS_Runtime.h" | 7 #include "fpdfsdk/src/javascript/JS_Runtime.h" |
| 8 | 8 |
| 9 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. | 9 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. |
| 10 #include "fpdfsdk/include/javascript/IJavaScript.h" | 10 #include "fpdfsdk/include/javascript/IJavaScript.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 CJS_Runtime::~CJS_Runtime() { | 116 CJS_Runtime::~CJS_Runtime() { |
| 117 for (auto* obs : m_observers) | 117 for (auto* obs : m_observers) |
| 118 obs->OnDestroyed(); | 118 obs->OnDestroyed(); |
| 119 | 119 |
| 120 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) | 120 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) |
| 121 delete m_ContextArray.GetAt(i); | 121 delete m_ContextArray.GetAt(i); |
| 122 | 122 |
| 123 m_ContextArray.RemoveAll(); | 123 m_ContextArray.RemoveAll(); |
| 124 m_ConstArrays.clear(); |
| 124 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects); | 125 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects); |
| 125 | 126 |
| 126 m_pApp = NULL; | 127 m_pApp = NULL; |
| 127 m_pDocument = NULL; | 128 m_pDocument = NULL; |
| 128 m_context.Reset(); | 129 m_context.Reset(); |
| 129 | 130 |
| 130 if (m_isolateManaged) | 131 if (m_isolateManaged) |
| 131 m_isolate->Dispose(); | 132 m_isolate->Dispose(); |
| 132 } | 133 } |
| 133 | 134 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 250 } |
| 250 | 251 |
| 251 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { | 252 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { |
| 252 m_FieldEventSet.erase(event); | 253 m_FieldEventSet.erase(event); |
| 253 } | 254 } |
| 254 | 255 |
| 255 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 256 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
| 256 return v8::Local<v8::Context>::New(m_isolate, m_context); | 257 return v8::Local<v8::Context>::New(m_isolate, m_context); |
| 257 } | 258 } |
| 258 | 259 |
| 260 void CJS_Runtime::SetConstArray(const CFX_WideString& name, |
| 261 v8::Local<v8::Array> array) { |
| 262 m_ConstArrays[name] = v8::Global<v8::Array>(m_isolate, array); |
| 263 } |
| 264 |
| 265 v8::Local<v8::Array> CJS_Runtime::GetConstArray(const CFX_WideString& name) { |
| 266 return v8::Local<v8::Array>::New(m_isolate, m_ConstArrays[name]); |
| 267 } |
| 268 |
| 259 #ifdef PDF_ENABLE_XFA | 269 #ifdef PDF_ENABLE_XFA |
| 260 CFX_WideString ChangeObjName(const CFX_WideString& str) { | 270 CFX_WideString ChangeObjName(const CFX_WideString& str) { |
| 261 CFX_WideString sRet = str; | 271 CFX_WideString sRet = str; |
| 262 sRet.Replace(L"_", L"."); | 272 sRet.Replace(L"_", L"."); |
| 263 return sRet; | 273 return sRet; |
| 264 } | 274 } |
| 265 FX_BOOL CJS_Runtime::GetHValueByName(const CFX_ByteStringC& utf8Name, | 275 FX_BOOL CJS_Runtime::GetHValueByName(const CFX_ByteStringC& utf8Name, |
| 266 FXJSE_HVALUE hValue) { | 276 FXJSE_HVALUE hValue) { |
| 267 #ifdef PDF_ENABLE_XFA | 277 #ifdef PDF_ENABLE_XFA |
| 268 const FX_CHAR* name = utf8Name.GetCStr(); | 278 const FX_CHAR* name = utf8Name.GetCStr(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 #endif | 336 #endif |
| 327 void CJS_Runtime::AddObserver(Observer* observer) { | 337 void CJS_Runtime::AddObserver(Observer* observer) { |
| 328 ASSERT(!pdfium::ContainsKey(m_observers, observer)); | 338 ASSERT(!pdfium::ContainsKey(m_observers, observer)); |
| 329 m_observers.insert(observer); | 339 m_observers.insert(observer); |
| 330 } | 340 } |
| 331 | 341 |
| 332 void CJS_Runtime::RemoveObserver(Observer* observer) { | 342 void CJS_Runtime::RemoveObserver(Observer* observer) { |
| 333 ASSERT(pdfium::ContainsKey(m_observers, observer)); | 343 ASSERT(pdfium::ContainsKey(m_observers, observer)); |
| 334 m_observers.erase(observer); | 344 m_observers.erase(observer); |
| 335 } | 345 } |
| OLD | NEW |