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 enum FXJSOBJTYPE { | 25 enum FXJSOBJTYPE { |
26 FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. | 26 FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. |
27 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. | 27 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. |
28 FXJSOBJTYPE_GLOBAL, // The global object itself (may only appear once). | 28 FXJSOBJTYPE_GLOBAL, // The global object itself (may only appear once). |
29 }; | 29 }; |
30 | 30 |
31 struct FXJSErr { | 31 struct FXJSErr { |
32 const wchar_t* message; | 32 const wchar_t* message; |
33 const wchar_t* srcline; | 33 const wchar_t* srcline; |
(...skipping 20 matching lines...) Expand all Loading... |
54 extern const wchar_t kFXJSValueNameNull[]; | 54 extern const wchar_t kFXJSValueNameNull[]; |
55 extern const wchar_t kFXJSValueNameUndefined[]; | 55 extern const wchar_t kFXJSValueNameUndefined[]; |
56 | 56 |
57 | 57 |
58 class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 58 class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
59 void* Allocate(size_t length) override; | 59 void* Allocate(size_t length) override; |
60 void* AllocateUninitialized(size_t length) override; | 60 void* AllocateUninitialized(size_t length) override; |
61 void Free(void* data, size_t length) override; | 61 void Free(void* data, size_t length) override; |
62 }; | 62 }; |
63 | 63 |
64 using FXJS_CONSTRUCTOR = void (*)(IJS_Context* cc, v8::Local<v8::Object> obj); | 64 using FXJS_CONSTRUCTOR = void (*)(IJS_Runtime* cc, v8::Local<v8::Object> obj); |
65 using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> obj); | 65 using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> obj); |
66 | 66 |
67 // Call before making FXJS_PrepareIsolate call. | 67 // Call before making FXJS_PrepareIsolate call. |
68 void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); | 68 void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); |
69 void FXJS_Release(); | 69 void FXJS_Release(); |
70 | 70 |
71 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each | 71 // Gets the global isolate set by FXJS_Initialize(), or makes a new one each |
72 // time if there is no such isolate. Returns true if a new isolate had to be | 72 // time if there is no such isolate. Returns true if a new isolate had to be |
73 // created. | 73 // created. |
74 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); | 74 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 v8::Local<v8::Value> pDefault); | 112 v8::Local<v8::Value> pDefault); |
113 void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, | 113 void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, |
114 const wchar_t* sMethodName, | 114 const wchar_t* sMethodName, |
115 v8::FunctionCallback pMethodCall); | 115 v8::FunctionCallback pMethodCall); |
116 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, | 116 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, |
117 const wchar_t* sConstName, | 117 const wchar_t* sConstName, |
118 v8::Local<v8::Value> pDefault); | 118 v8::Local<v8::Value> pDefault); |
119 | 119 |
120 // Called after FXJS_Define* calls made. | 120 // Called after FXJS_Define* calls made. |
121 void FXJS_InitializeRuntime(v8::Isolate* pIsolate, | 121 void FXJS_InitializeRuntime(v8::Isolate* pIsolate, |
122 IJS_Runtime* pFXRuntime, | 122 IJS_Runtime* pIRuntime, |
123 IJS_Context* context, | |
124 v8::Global<v8::Context>& v8PersistentContext); | 123 v8::Global<v8::Context>& v8PersistentContext); |
125 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, | 124 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, |
126 v8::Global<v8::Context>& v8PersistentContext); | 125 v8::Global<v8::Context>& v8PersistentContext); |
127 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); | 126 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); |
128 | 127 |
129 // Called after FXJS_InitializeRuntime call made. | 128 // Called after FXJS_InitializeRuntime call made. |
130 int FXJS_Execute(v8::Isolate* pIsolate, | 129 int FXJS_Execute(v8::Isolate* pIsolate, |
131 IJS_Context* pJSContext, | 130 IJS_Context* pJSContext, |
132 const wchar_t* script, | 131 const wchar_t* script, |
133 long length, | |
134 FXJSErr* perror); | 132 FXJSErr* perror); |
135 | 133 |
136 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, | 134 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, |
137 IJS_Context* pJSContext, | 135 IJS_Runtime* pJSContext, |
138 int nObjDefnID); | 136 int nObjDefnID); |
139 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); | 137 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); |
140 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); | 138 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); |
141 v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj); | 139 v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj); |
142 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj); | 140 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj); |
143 | 141 |
144 void FXJS_SetPrivate(v8::Isolate* pIsolate, | 142 void FXJS_SetPrivate(v8::Isolate* pIsolate, |
145 v8::Local<v8::Object> pObj, | 143 v8::Local<v8::Object> pObj, |
146 void* p); | 144 void* p); |
147 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); | 145 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); | 213 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); |
216 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, | 214 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, |
217 v8::Local<v8::Value> pValue); | 215 v8::Local<v8::Value> pValue); |
218 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, | 216 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, |
219 v8::Local<v8::Value> pValue); | 217 v8::Local<v8::Value> pValue); |
220 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, | 218 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, |
221 v8::Local<v8::Value> pValue); | 219 v8::Local<v8::Value> pValue); |
222 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); | 220 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); |
223 | 221 |
224 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 222 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
OLD | NEW |