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 "../../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 Loading... |
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, pContext, m_context); | 67 FXJS_InitializeRuntime(GetIsolate(), this, m_context); |
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 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { | 174 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { |
175 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) | 175 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) |
176 pDocument->AttachDoc(pReaderDoc); | 176 pDocument->AttachDoc(pReaderDoc); |
177 } | 177 } |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
| 184 int CJS_Runtime::Execute(IJS_Context* cc, |
| 185 const wchar_t* script, |
| 186 CFX_WideString* info) { |
| 187 FXJSErr error = {}; |
| 188 int nRet = FXJS_Execute(m_isolate, cc, script, &error); |
| 189 if (nRet < 0) { |
| 190 info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline, |
| 191 error.message); |
| 192 } |
| 193 return nRet; |
| 194 } |
| 195 |
184 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { | 196 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { |
185 return m_FieldEventSet.insert(event).second; | 197 return m_FieldEventSet.insert(event).second; |
186 } | 198 } |
187 | 199 |
188 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { | 200 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { |
189 m_FieldEventSet.erase(event); | 201 m_FieldEventSet.erase(event); |
190 } | 202 } |
191 | 203 |
192 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 204 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
193 return v8::Local<v8::Context>::New(m_isolate, m_context); | 205 return v8::Local<v8::Context>::New(m_isolate, m_context); |
194 } | 206 } |
195 | 207 |
196 void CJS_Runtime::AddObserver(Observer* observer) { | 208 void CJS_Runtime::AddObserver(Observer* observer) { |
197 ASSERT(m_observers.find(observer) == m_observers.end()); | 209 ASSERT(m_observers.find(observer) == m_observers.end()); |
198 m_observers.insert(observer); | 210 m_observers.insert(observer); |
199 } | 211 } |
200 | 212 |
201 void CJS_Runtime::RemoveObserver(Observer* observer) { | 213 void CJS_Runtime::RemoveObserver(Observer* observer) { |
202 ASSERT(m_observers.find(observer) != m_observers.end()); | 214 ASSERT(m_observers.find(observer) != m_observers.end()); |
203 m_observers.erase(observer); | 215 m_observers.erase(observer); |
204 } | 216 } |
205 | 217 |
206 CFX_WideString ChangeObjName(const CFX_WideString& str) { | 218 CFX_WideString ChangeObjName(const CFX_WideString& str) { |
207 CFX_WideString sRet = str; | 219 CFX_WideString sRet = str; |
208 sRet.Replace(L"_", L"."); | 220 sRet.Replace(L"_", L"."); |
209 return sRet; | 221 return sRet; |
210 } | 222 } |
OLD | NEW |