| 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 FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 14 #ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
| 15 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 15 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
| 16 | 16 |
| 17 #include <v8.h> | 17 #include <v8.h> |
| 18 #include "../../../core/include/fxcrt/fx_basic.h" | 18 #include "../../../core/include/fxcrt/fx_basic.h" |
| 19 | 19 |
| 20 // FXJS_V8 places no interpretation on these two classes; it merely | 20 // FXJS_V8 places no restrictions on these two classes; it merely passes them |
| 21 // passes them on to the caller-provided FXJS_CONSTRUCTORs. | 21 // on to caller-provided methods. |
| 22 class IJS_Context; | 22 class IJS_Context; // A description of the event that caused JS execution. |
| 23 class IJS_Runtime; | 23 class IJS_Runtime; // A native runtime, typically owns the v8::Context. |
| 24 | 24 |
| 25 // FXJS_V8 places no interpreation on this calass; it merely passes it | 25 // FXJS_V8 places no interpreation on this calass; it merely passes it |
| 26 // along to XFA. | 26 // along to XFA. |
| 27 class CFXJSE_RuntimeData; | 27 class CFXJSE_RuntimeData; |
| 28 | 28 |
| 29 enum FXJSOBJTYPE { | 29 enum FXJSOBJTYPE { |
| 30 FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. | 30 FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. |
| 31 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. | 31 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. |
| 32 FXJSOBJTYPE_GLOBAL, // The global object itself (may only appear once). | 32 FXJSOBJTYPE_GLOBAL, // The global object itself (may only appear once). |
| 33 }; | 33 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 59 extern const wchar_t kFXJSValueNameNull[]; | 59 extern const wchar_t kFXJSValueNameNull[]; |
| 60 extern const wchar_t kFXJSValueNameUndefined[]; | 60 extern const wchar_t kFXJSValueNameUndefined[]; |
| 61 | 61 |
| 62 | 62 |
| 63 class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 63 class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 64 void* Allocate(size_t length) override; | 64 void* Allocate(size_t length) override; |
| 65 void* AllocateUninitialized(size_t length) override; | 65 void* AllocateUninitialized(size_t length) override; |
| 66 void Free(void* data, size_t length) override; | 66 void Free(void* data, size_t length) override; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 using FXJS_CONSTRUCTOR = void (*)(IJS_Context* cc, v8::Local<v8::Object> obj); | 69 using FXJS_CONSTRUCTOR = void (*)(IJS_Runtime* cc, v8::Local<v8::Object> obj); |
| 70 using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> obj); | 70 using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> obj); |
| 71 | 71 |
| 72 // Call before making FXJS_PrepareIsolate call. | 72 // Call before making FXJS_PrepareIsolate call. |
| 73 void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); | 73 void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); |
| 74 void FXJS_Release(); | 74 void FXJS_Release(); |
| 75 | 75 |
| 76 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each | 76 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each |
| 77 // time if there is no such isolate. Returns true if a new isolate had to be | 77 // time if there is no such isolate. Returns true if a new isolate had to be |
| 78 // created. | 78 // created. |
| 79 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); | 79 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 v8::Local<v8::Value> pDefault); | 117 v8::Local<v8::Value> pDefault); |
| 118 void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, | 118 void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, |
| 119 const wchar_t* sMethodName, | 119 const wchar_t* sMethodName, |
| 120 v8::FunctionCallback pMethodCall); | 120 v8::FunctionCallback pMethodCall); |
| 121 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, | 121 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, |
| 122 const wchar_t* sConstName, | 122 const wchar_t* sConstName, |
| 123 v8::Local<v8::Value> pDefault); | 123 v8::Local<v8::Value> pDefault); |
| 124 | 124 |
| 125 // Called after FXJS_Define* calls made. | 125 // Called after FXJS_Define* calls made. |
| 126 void FXJS_InitializeRuntime(v8::Isolate* pIsolate, | 126 void FXJS_InitializeRuntime(v8::Isolate* pIsolate, |
| 127 IJS_Runtime* pFXRuntime, | 127 IJS_Runtime* pIRuntime, |
| 128 IJS_Context* context, | |
| 129 v8::Global<v8::Context>& v8PersistentContext); | 128 v8::Global<v8::Context>& v8PersistentContext); |
| 130 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, | 129 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, |
| 131 v8::Global<v8::Context>& v8PersistentContext); | 130 v8::Global<v8::Context>& v8PersistentContext); |
| 132 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); | 131 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); |
| 133 | 132 |
| 134 // Called after FXJS_InitializeRuntime call made. | 133 // Called after FXJS_InitializeRuntime call made. |
| 135 int FXJS_Execute(v8::Isolate* pIsolate, | 134 int FXJS_Execute(v8::Isolate* pIsolate, |
| 136 IJS_Context* pJSContext, | 135 IJS_Context* pJSContext, |
| 137 const wchar_t* script, | 136 const wchar_t* script, |
| 138 long length, | |
| 139 FXJSErr* perror); | 137 FXJSErr* perror); |
| 140 | 138 |
| 141 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, | 139 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, |
| 142 IJS_Context* pJSContext, | 140 IJS_Runtime* pJSContext, |
| 143 int nObjDefnID); | 141 int nObjDefnID); |
| 144 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); | 142 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); |
| 145 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); | 143 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); |
| 146 v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj); | 144 v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj); |
| 147 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj); | 145 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj); |
| 148 | 146 |
| 149 void FXJS_SetPrivate(v8::Isolate* pIsolate, | 147 void FXJS_SetPrivate(v8::Isolate* pIsolate, |
| 150 v8::Local<v8::Object> pObj, | 148 v8::Local<v8::Object> pObj, |
| 151 void* p); | 149 void* p); |
| 152 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); | 150 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); | 218 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); |
| 221 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, | 219 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, |
| 222 v8::Local<v8::Value> pValue); | 220 v8::Local<v8::Value> pValue); |
| 223 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, | 221 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, |
| 224 v8::Local<v8::Value> pValue); | 222 v8::Local<v8::Value> pValue); |
| 225 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, | 223 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, |
| 226 v8::Local<v8::Value> pValue); | 224 v8::Local<v8::Value> pValue); |
| 227 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); | 225 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); |
| 228 | 226 |
| 229 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 227 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
| OLD | NEW |