Chromium Code Reviews| 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 |
| 11 // PDFium code should include this file rather than including V8 headers | 11 // PDFium code should include this file rather than including V8 headers |
| 12 // directly. | 12 // directly. |
| 13 | 13 |
| 14 #ifndef FXJS_INCLUDE_FXJS_V8_H_ | 14 #ifndef FXJS_INCLUDE_FXJS_V8_H_ |
| 15 #define FXJS_INCLUDE_FXJS_V8_H_ | 15 #define FXJS_INCLUDE_FXJS_V8_H_ |
| 16 | 16 |
| 17 #include <v8-util.h> | 17 #include <v8-util.h> |
| 18 #include <v8.h> | 18 #include <v8.h> |
| 19 | 19 |
| 20 #include <vector> | 20 #include <vector> |
| 21 | 21 |
|
dsinclair
2016/08/15 13:13:32
#include <map>
Tom Sepez
2016/08/15 16:37:55
Done.
| |
| 22 #include "core/fxcrt/include/fx_string.h" | 22 #include "core/fxcrt/include/fx_string.h" |
| 23 | 23 |
| 24 class CFXJS_Engine; | |
| 24 class CFXJS_ObjDefinition; | 25 class CFXJS_ObjDefinition; |
| 25 | 26 |
| 26 // FXJS_V8 places no restrictions on these two classes; it merely passes them | 27 // FXJS_V8 places no restrictions on this class; it merely passes it |
| 27 // on to caller-provided methods. | 28 // on to caller-provided methods. |
| 28 class IJS_Context; // A description of the event that caused JS execution. | 29 class IJS_Context; // A description of the event that caused JS execution. |
| 29 class IJS_Runtime; // A native runtime, typically owns the v8::Context. | |
| 30 | 30 |
| 31 #ifdef PDF_ENABLE_XFA | 31 #ifdef PDF_ENABLE_XFA |
| 32 // FXJS_V8 places no interpreation on this calass; it merely passes it | 32 // FXJS_V8 places no interpreation on this calass; it merely passes it |
| 33 // along to XFA. | 33 // along to XFA. |
| 34 class CFXJSE_RuntimeData; | 34 class CFXJSE_RuntimeData; |
| 35 #endif // PDF_ENABLE_XFA | 35 #endif // PDF_ENABLE_XFA |
| 36 | 36 |
| 37 enum FXJSOBJTYPE { | 37 enum FXJSOBJTYPE { |
| 38 FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. | 38 FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. |
| 39 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. | 39 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 protected: | 117 protected: |
| 118 FXJS_PerIsolateData(); | 118 FXJS_PerIsolateData(); |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 121 class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 122 void* Allocate(size_t length) override; | 122 void* Allocate(size_t length) override; |
| 123 void* AllocateUninitialized(size_t length) override; | 123 void* AllocateUninitialized(size_t length) override; |
| 124 void Free(void* data, size_t length) override; | 124 void Free(void* data, size_t length) override; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 using FXJS_CONSTRUCTOR = void (*)(IJS_Runtime* cc, v8::Local<v8::Object> obj); | 127 using FXJS_CONSTRUCTOR = void (*)(CFXJS_Engine* fxjs, |
| 128 v8::Local<v8::Object> obj); | |
| 128 using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> obj); | 129 using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> obj); |
| 129 | 130 |
| 130 void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); | 131 void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); |
| 131 void FXJS_Release(); | 132 void FXJS_Release(); |
| 132 | 133 |
| 134 class CFXJS_Engine { | |
|
dsinclair
2016/08/15 13:13:32
Any reason to not put this in it's own file?
Tom Sepez
2016/08/15 16:37:55
There's a follow-on CL that puts most of this file
| |
| 135 public: | |
| 136 CFXJS_Engine(); | |
| 137 ~CFXJS_Engine(); | |
| 138 | |
| 139 protected: | |
| 140 v8::Isolate* m_isolate; | |
| 141 bool m_isolateManaged; | |
| 142 v8::Global<v8::Context> m_context; | |
| 143 std::vector<v8::Global<v8::Object>*> m_StaticObjects; | |
| 144 std::map<CFX_WideString, v8::Global<v8::Array>> m_ConstArrays; | |
| 145 }; | |
| 146 | |
| 133 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each | 147 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each |
| 134 // time if there is no such isolate. Returns true if a new isolate had to be | 148 // time if there is no such isolate. Returns true if a new isolate had to be |
| 135 // created. | 149 // created. |
| 136 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); | 150 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); |
| 137 | 151 |
| 138 // Get the global isolate's ref count. | 152 // Get the global isolate's ref count. |
| 139 size_t FXJS_GlobalIsolateRefCount(); | 153 size_t FXJS_GlobalIsolateRefCount(); |
| 140 | 154 |
| 141 // Always returns a valid, newly-created objDefnID. | 155 // Always returns a valid, newly-created objDefnID. |
| 142 int FXJS_DefineObj(v8::Isolate* pIsolate, | 156 int FXJS_DefineObj(v8::Isolate* pIsolate, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 165 const wchar_t* sConstName, | 179 const wchar_t* sConstName, |
| 166 v8::Local<v8::Value> pDefault); | 180 v8::Local<v8::Value> pDefault); |
| 167 void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, | 181 void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, |
| 168 const wchar_t* sMethodName, | 182 const wchar_t* sMethodName, |
| 169 v8::FunctionCallback pMethodCall); | 183 v8::FunctionCallback pMethodCall); |
| 170 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, | 184 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, |
| 171 const wchar_t* sConstName, | 185 const wchar_t* sConstName, |
| 172 v8::FunctionCallback pConstGetter); | 186 v8::FunctionCallback pConstGetter); |
| 173 | 187 |
| 174 // Called after FXJS_Define* calls made. | 188 // Called after FXJS_Define* calls made. |
| 175 void FXJS_InitializeRuntime( | 189 void FXJS_InitializeEngine( |
| 176 v8::Isolate* pIsolate, | 190 v8::Isolate* pIsolate, |
| 177 IJS_Runtime* pIRuntime, | 191 CFXJS_Engine* pEngine, |
| 178 v8::Global<v8::Context>* pV8PersistentContext, | 192 v8::Global<v8::Context>* pV8PersistentContext, |
| 179 std::vector<v8::Global<v8::Object>*>* pStaticObjects); | 193 std::vector<v8::Global<v8::Object>*>* pStaticObjects); |
| 180 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, | 194 void FXJS_ReleaseEngine(v8::Isolate* pIsolate, |
| 181 v8::Global<v8::Context>* pV8PersistentContext, | 195 v8::Global<v8::Context>* pV8PersistentContext, |
| 182 std::vector<v8::Global<v8::Object>*>* pStaticObjects); | 196 std::vector<v8::Global<v8::Object>*>* pStaticObjects); |
| 183 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); | 197 CFXJS_Engine* FXJS_GetEngineFromIsolate(v8::Isolate* pIsolate); |
| 184 | 198 |
| 185 #ifdef PDF_ENABLE_XFA | 199 #ifdef PDF_ENABLE_XFA |
| 186 // Called as part of FXJS_InitializeRuntime, exposed so PDF can make its | 200 // Called as part of FXJS_InitializeEngine, exposed so PDF can make its |
| 187 // own contexts compatible with XFA or vice versa. | 201 // own contexts compatible with XFA or vice versa. |
| 188 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context, | 202 void FXJS_SetEngineForV8Context(v8::Local<v8::Context> v8Context, |
| 189 IJS_Runtime* pIRuntime); | 203 CFXJS_Engine* pEngine); |
| 190 #endif // PDF_ENABLE_XFA | 204 #endif // PDF_ENABLE_XFA |
| 191 | 205 |
| 192 // Called after FXJS_InitializeRuntime call made. | 206 // Called after FXJS_InitializeEngine call made. |
| 193 int FXJS_Execute(v8::Isolate* pIsolate, | 207 int FXJS_Execute(v8::Isolate* pIsolate, |
| 194 const CFX_WideString& script, | 208 const CFX_WideString& script, |
| 195 FXJSErr* perror); | 209 FXJSErr* perror); |
| 196 | 210 |
| 197 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, | 211 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, |
| 198 IJS_Runtime* pJSContext, | 212 CFXJS_Engine* pEngine, |
| 199 int nObjDefnID, | 213 int nObjDefnID, |
| 200 bool bStatic = false); | 214 bool bStatic = false); |
| 201 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); | 215 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); |
| 202 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); | 216 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); |
| 203 | 217 |
| 204 void FXJS_SetPrivate(v8::Isolate* pIsolate, | 218 void FXJS_SetPrivate(v8::Isolate* pIsolate, |
| 205 v8::Local<v8::Object> pObj, | 219 v8::Local<v8::Object> pObj, |
| 206 void* p); | 220 void* p); |
| 207 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); | 221 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); |
| 208 void FXJS_FreePrivate(void* p); | 222 void FXJS_FreePrivate(void* p); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 int FXJS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); | 282 int FXJS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); |
| 269 bool FXJS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); | 283 bool FXJS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); |
| 270 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); | 284 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); |
| 271 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, | 285 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, |
| 272 v8::Local<v8::Value> pValue); | 286 v8::Local<v8::Value> pValue); |
| 273 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, | 287 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, |
| 274 v8::Local<v8::Value> pValue); | 288 v8::Local<v8::Value> pValue); |
| 275 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, | 289 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, |
| 276 v8::Local<v8::Value> pValue); | 290 v8::Local<v8::Value> pValue); |
| 277 #endif // FXJS_INCLUDE_FXJS_V8_H_ | 291 #endif // FXJS_INCLUDE_FXJS_V8_H_ |
| OLD | NEW |