| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 m_isolateManaged = FXJS_GetIsolate(&m_isolate); | 71 m_isolateManaged = FXJS_GetIsolate(&m_isolate); |
| 72 } | 72 } |
| 73 | 73 |
| 74 v8::Isolate* isolate = m_isolate; | 74 v8::Isolate* isolate = m_isolate; |
| 75 v8::Isolate::Scope isolate_scope(isolate); | 75 v8::Isolate::Scope isolate_scope(isolate); |
| 76 v8::Locker locker(isolate); | 76 v8::Locker locker(isolate); |
| 77 v8::HandleScope handle_scope(isolate); | 77 v8::HandleScope handle_scope(isolate); |
| 78 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { | 78 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { |
| 79 CJS_Context* pContext = (CJS_Context*)NewContext(); | 79 CJS_Context* pContext = (CJS_Context*)NewContext(); |
| 80 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); | 80 FXJS_InitializeRuntime(GetIsolate(), this, m_context); |
| 81 ReleaseContext(pContext); | 81 ReleaseContext(pContext); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) | 85 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) |
| 86 DefineJSObjects(); | 86 DefineJSObjects(); |
| 87 | 87 |
| 88 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); | 88 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); |
| 89 | 89 |
| 90 CJS_Context* pContext = (CJS_Context*)NewContext(); | 90 CJS_Context* pContext = (CJS_Context*)NewContext(); |
| 91 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); | 91 FXJS_InitializeRuntime(GetIsolate(), this, m_context); |
| 92 ReleaseContext(pContext); | 92 ReleaseContext(pContext); |
| 93 } | 93 } |
| 94 | 94 |
| 95 CJS_Runtime::~CJS_Runtime() { | 95 CJS_Runtime::~CJS_Runtime() { |
| 96 for (auto* obs : m_observers) | 96 for (auto* obs : m_observers) |
| 97 obs->OnDestroyed(); | 97 obs->OnDestroyed(); |
| 98 | 98 |
| 99 int size = m_ContextArray.GetSize(); | 99 int size = m_ContextArray.GetSize(); |
| 100 for (int i = 0; i < size; i++) | 100 for (int i = 0; i < size; i++) |
| 101 delete m_ContextArray.GetAt(i); | 101 delete m_ContextArray.GetAt(i); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { | 201 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { |
| 202 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) | 202 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) |
| 203 pDocument->AttachDoc(pReaderDoc); | 203 pDocument->AttachDoc(pReaderDoc); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 int CJS_Runtime::Execute(IJS_Context* cc, |
| 212 const wchar_t* script, |
| 213 CFX_WideString* info) { |
| 214 FXJSErr error = {}; |
| 215 int nRet = FXJS_Execute(m_isolate, cc, script, &error); |
| 216 if (nRet < 0) { |
| 217 info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline, |
| 218 error.message); |
| 219 } |
| 220 return nRet; |
| 221 } |
| 222 |
| 211 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { | 223 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { |
| 212 return m_FieldEventSet.insert(event).second; | 224 return m_FieldEventSet.insert(event).second; |
| 213 } | 225 } |
| 214 | 226 |
| 215 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { | 227 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { |
| 216 m_FieldEventSet.erase(event); | 228 m_FieldEventSet.erase(event); |
| 217 } | 229 } |
| 218 | 230 |
| 219 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 231 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
| 220 return v8::Local<v8::Context>::New(m_isolate, m_context); | 232 return v8::Local<v8::Context>::New(m_isolate, m_context); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 292 |
| 281 void CJS_Runtime::AddObserver(Observer* observer) { | 293 void CJS_Runtime::AddObserver(Observer* observer) { |
| 282 ASSERT(m_observers.find(observer) == m_observers.end()); | 294 ASSERT(m_observers.find(observer) == m_observers.end()); |
| 283 m_observers.insert(observer); | 295 m_observers.insert(observer); |
| 284 } | 296 } |
| 285 | 297 |
| 286 void CJS_Runtime::RemoveObserver(Observer* observer) { | 298 void CJS_Runtime::RemoveObserver(Observer* observer) { |
| 287 ASSERT(m_observers.find(observer) != m_observers.end()); | 299 ASSERT(m_observers.find(observer) != m_observers.end()); |
| 288 m_observers.erase(observer); | 300 m_observers.erase(observer); |
| 289 } | 301 } |
| OLD | NEW |