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 // FXJS_V8 is a layer that makes it easier to define native objects in V8, but | 7 // FXJS_V8 is a layer that makes it easier to define native objects in V8, but |
8 // has no knowledge of PDF-specific native objects. It could in theory be used | 8 // has no knowledge of PDF-specific native objects. It could in theory be used |
9 // to implement other sets of native objects. | 9 // to implement other sets of native objects. |
10 | 10 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each | 131 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each |
132 // time if there is no such isolate. Returns true if a new isolate had to be | 132 // time if there is no such isolate. Returns true if a new isolate had to be |
133 // created. | 133 // created. |
134 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); | 134 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); |
135 | 135 |
136 // Get the global isolate's ref count. | 136 // Get the global isolate's ref count. |
137 size_t FXJS_GlobalIsolateRefCount(); | 137 size_t FXJS_GlobalIsolateRefCount(); |
138 | 138 |
139 class CFXJS_Engine { | 139 class CFXJS_Engine { |
140 public: | 140 public: |
141 CFXJS_Engine(); | 141 explicit CFXJS_Engine(v8::Isolate* pIsolate); |
142 ~CFXJS_Engine(); | 142 ~CFXJS_Engine(); |
143 | 143 |
144 using Constructor = void (*)(CFXJS_Engine* pEngine, | 144 using Constructor = void (*)(CFXJS_Engine* pEngine, |
145 v8::Local<v8::Object> obj); | 145 v8::Local<v8::Object> obj); |
146 using Destructor = void (*)(CFXJS_Engine* pEngine, v8::Local<v8::Object> obj); | 146 using Destructor = void (*)(CFXJS_Engine* pEngine, v8::Local<v8::Object> obj); |
147 | 147 |
148 static CFXJS_Engine* CurrentEngineFromIsolate(v8::Isolate* pIsolate); | 148 static CFXJS_Engine* CurrentEngineFromIsolate(v8::Isolate* pIsolate); |
149 static int GetObjDefnID(v8::Local<v8::Object> pObj); | 149 static int GetObjDefnID(v8::Local<v8::Object> pObj); |
150 | 150 |
151 #ifdef PDF_ENABLE_XFA | 151 #ifdef PDF_ENABLE_XFA |
152 // Called as part of FXJS_InitializeEngine, exposed so PDF can make its | 152 // Called as part of FXJS_InitializeEngine, exposed so PDF can make its |
153 // own contexts compatible with XFA or vice versa. | 153 // own contexts compatible with XFA or vice versa. |
154 static void SetForV8Context(v8::Local<v8::Context> v8Context, | 154 static void SetForV8Context(v8::Local<v8::Context> v8Context, |
155 CFXJS_Engine* pEngine); | 155 CFXJS_Engine* pEngine); |
156 #endif // PDF_ENABLE_XFA | 156 #endif // PDF_ENABLE_XFA |
157 | 157 |
158 // TODO(tsepez): to constructor. | |
159 void SetIsolate(v8::Isolate* pIsolate) { m_isolate = pIsolate; } | |
160 v8::Isolate* GetIsolate() const { return m_isolate; } | 158 v8::Isolate* GetIsolate() const { return m_isolate; } |
161 | 159 |
162 // Always returns a valid, newly-created objDefnID. | 160 // Always returns a valid, newly-created objDefnID. |
163 int DefineObj(const wchar_t* sObjName, | 161 int DefineObj(const wchar_t* sObjName, |
164 FXJSOBJTYPE eObjType, | 162 FXJSOBJTYPE eObjType, |
165 Constructor pConstructor, | 163 Constructor pConstructor, |
166 Destructor pDestructor); | 164 Destructor pDestructor); |
167 | 165 |
168 void DefineObjMethod(int nObjDefnID, | 166 void DefineObjMethod(int nObjDefnID, |
169 const wchar_t* sMethodName, | 167 const wchar_t* sMethodName, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 void* GetObjectPrivate(v8::Local<v8::Object> pObj); | 249 void* GetObjectPrivate(v8::Local<v8::Object> pObj); |
252 static void FreeObjectPrivate(void* p); | 250 static void FreeObjectPrivate(void* p); |
253 static void FreeObjectPrivate(v8::Local<v8::Object> pObj); | 251 static void FreeObjectPrivate(v8::Local<v8::Object> pObj); |
254 | 252 |
255 void SetConstArray(const CFX_WideString& name, v8::Local<v8::Array> array); | 253 void SetConstArray(const CFX_WideString& name, v8::Local<v8::Array> array); |
256 v8::Local<v8::Array> GetConstArray(const CFX_WideString& name); | 254 v8::Local<v8::Array> GetConstArray(const CFX_WideString& name); |
257 | 255 |
258 v8::Local<v8::String> WSToJSString(const CFX_WideString& wsPropertyName); | 256 v8::Local<v8::String> WSToJSString(const CFX_WideString& wsPropertyName); |
259 void Error(const CFX_WideString& message); | 257 void Error(const CFX_WideString& message); |
260 | 258 |
| 259 protected: |
| 260 CFXJS_Engine(); |
| 261 |
| 262 void SetIsolate(v8::Isolate* pIsolate) { m_isolate = pIsolate; } |
| 263 |
261 private: | 264 private: |
262 v8::Isolate* m_isolate; | 265 v8::Isolate* m_isolate; |
263 v8::Global<v8::Context> m_V8PersistentContext; | 266 v8::Global<v8::Context> m_V8PersistentContext; |
264 std::vector<v8::Global<v8::Object>*> m_StaticObjects; | 267 std::vector<v8::Global<v8::Object>*> m_StaticObjects; |
265 std::map<CFX_WideString, v8::Global<v8::Array>> m_ConstArrays; | 268 std::map<CFX_WideString, v8::Global<v8::Array>> m_ConstArrays; |
266 }; | 269 }; |
267 | 270 |
268 #endif // FXJS_INCLUDE_FXJS_V8_H_ | 271 #endif // FXJS_INCLUDE_FXJS_V8_H_ |
OLD | NEW |