This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
forked from kingland/go-v8
-
Notifications
You must be signed in to change notification settings - Fork 3
/
v8_wrap.h
437 lines (281 loc) · 11.1 KB
/
v8_wrap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#ifndef _V8_WARP_H_
#define _V8_WARP_H_
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
OTP_Context = 0,
OTP_Getter,
OTP_Setter,
OTP_Query,
OTP_Deleter,
OTP_Enumerator,
OTP_Data,
OTP_Num
} PropertyDataEnum;
typedef enum {
OTA_Context = 0,
OTA_Getter,
OTA_Setter,
OTA_KeyString,
OTA_KeyLength,
OTA_Data,
OTA_Num
} AccessorDataEnum;
typedef enum {
OTAC_Context = 0,
OTAC_Name ,
OTAC_Index ,
OTAC_Data,
OTAC_Num
} AccessCheckDataEnum;
typedef struct {
void* engine;
void* info;
void* setValue;
const char* key;
int key_length;
void* data;
void* callback;
void* returnValue;
} V8_AccessorCallbackInfo;
typedef struct {
void* engine;
void* info;
void* callback;
void* setValue;
void* data;
char* key;
uint32_t index;
void* returnValue;
} V8_PropertyCallbackInfo;
typedef struct{
void* engine;
void* host;
void* key;
uint32_t index;
void* data;
void* callback;
} V8_AccessCheckCallbackInfo;
/*
platform
*/
extern void V8_Init();
/*
engine
*/
extern void* V8_NewEngine();
extern void V8_DisposeEngine(void* engine);
extern void* V8_ParseJSON(void* context, const char* json, int json_length);
extern void V8_ForceGC(void* engine);
/*
context
*/
extern void* V8_NewContext(void* engine, void* global_template);
extern void V8_DisposeContext(void* context);
extern void V8_Context_Enter(void* context);
extern void V8_Context_Exit(void* context);
extern void V8_Context_Scope(void* context, void* context_ptr, void* callback);
extern void* V8_Context_Global(void* context);
extern void V8_Context_ThrowException(void* context, const char* err, int err_length);
extern void V8_Context_ThrowException2(void* value);
extern void* V8_Context_TryCatch(void* context, void* callback);
extern void* V8_Context_TryCatchException(void* context, void* callback);
extern void V8_Context_SetSecurityToken(void* context, void* value);
extern void* V8_Context_GetSecurityToken(void* context);
extern void V8_Context_UseDefaultSecurityToken(void* context);
extern void* V8_Context_GetEmbedderData(void* context, int index);
extern void V8_Context_SetEmbedderData(void* context, int index, void* value);
extern void V8_Context_SetAlignedPointerInEmbedderData(void* context, int index, void* value_ptr);
extern void* V8_Context_GetAlignedPointerFromEmbedderData(void* context, int index);
/*
Escapable Scope
*/
extern void V8_Escapable_Scope(void* context, void* context_ptr, void* callback);
extern void* V8_Context_Escape(void* context, void* escapeContext);
extern void* V8_Value_Escape(void* context ,void* cscapeValue);
/*
Isolate
*/
extern unsigned int V8_Isolate_GetNumberOfDataSlots();
/*
script
*/
extern void* V8_Compile(void* engine, const char* code, int length, void* script_origin);
extern void V8_DisposeScript(void* script);
extern void* V8_Script_Run(void* script);
/*
value
*/
extern void V8_DisposeValue(void* value);
extern int V8_Value_IsUndefined(void* value);
extern int V8_Value_IsNull(void* value);
extern int V8_Value_IsTrue(void* value);
extern int V8_Value_IsFalse(void* value);
extern int V8_Value_IsString(void* value);
extern int V8_Value_IsFunction(void* value);
extern int V8_Value_IsArray(void* value);
extern int V8_Value_IsObject(void* value);
extern int V8_Value_IsBoolean(void* value);
extern int V8_Value_IsNumber(void* value);
extern int V8_Value_IsExternal(void* value);
extern int V8_Value_IsInt32(void* value);
extern int V8_Value_IsUint32(void* value);
extern int V8_Value_IsDate(void* value);
extern int V8_Value_IsBooleanObject(void* value);
extern int V8_Value_IsNumberObject(void* value);
extern int V8_Value_IsStringObject(void* value);
extern int V8_Value_IsNativeError(void* value);
extern int V8_Value_IsRegExp(void* value);
extern int V8_Value_ToBoolean(void* value);
extern double V8_Value_ToNumber(void* value);
extern int64_t V8_Value_ToInteger(void* value);
extern uint32_t V8_Value_ToUint32(void* value);
extern int32_t V8_Value_ToInt32(void* value);
extern char* V8_Value_ToString(void* value);
extern void V8_Value_SetFieldOwnerInfo(void* value, void* engine, int64_t ownerId);
extern void* V8_Undefined(void* engine);
extern void* V8_Null(void* engine);
extern void* V8_True(void* engine);
extern void* V8_False(void* engine);
extern void* V8_NewNumber(void* engine, double val);
extern void* V8_NewDate(void* engine, double val);
extern void* V8_NewString(void* engine, const char* val, int val_length);
extern void* V8_NewExternal(void* engine, void* data);
extern void* V8_External_Value(void* external);
/*
object
*/
extern void* V8_NewObject(void* engine);
extern int V8_Object_SetProperty(void* value, const char* key, int key_length, void* prop_value);
extern void* V8_Object_GetProperty(void* value, const char* key, int key_length);
extern int V8_Object_SetElement(void* value, uint32_t index, void* elem_value);
extern void* V8_Object_GetElement(void* value, uint32_t index);
extern int V8_Object_GetPropertyAttributes(void *value, const char* key, int key_length);
extern int V8_Object_ForceSetProperty(void* value, const char* key, int key_length, void* prop_value, int attribs);
extern int V8_Object_HasProperty(void *value, const char* key, int key_length);
extern int V8_Object_DeleteProperty(void *value, const char* key, int key_length);
extern int V8_Object_ForceDeleteProperty(void *value, const char* key, int key_length);
extern int V8_Object_HasElement(void* value, uint32_t index);
extern int V8_Object_DeleteElement(void* value, uint32_t index);
extern void* V8_Object_GetPropertyNames(void *value);
extern void* V8_Object_GetOwnPropertyNames(void *value);
extern void* V8_Object_GetPrototype(void *value);
extern int V8_Object_SetPrototype(void *value, void *proto);
extern void V8_Object_SetAccessor(void *value, const char* key, int key_length, void* getter, void* setter, void* data, int attribs);
extern int V8_Object_InternalFieldCount(void* value);
extern void* V8_Object_GetInternalField(void* value, int index);
extern void V8_Object_SetInternalField(void* value, int index, void* data);
extern void* V8_Object_GetHiddenValue(void* value, const char* key);
extern int V8_Object_SetHiddenValue(void* value, const char* key ,void* data);
extern int V8_Object_DeleteHiddenValue(void* value, const char* key);
extern void V8_Object_SetAlignedPointerInInternalField(void* value, int index, void* value_ptr);
extern void* V8_Object_GetRealNamedProperty(void* value, const char* key);
extern int V8_Object_HasRealNamedProperty(void* value, const char* key);
extern void* V8_Object_GetAlignedPointerFromInternalField(void* value, int index);
extern void* V8_Object_GetConstructorName(void* value);
extern void* V8_AccessorCallbackInfo_This(void *info, AccessorDataEnum type);
extern void* V8_AccessorCallbackInfo_Holder(void *info, AccessorDataEnum type);
extern void* V8_AccessorCallbackInfo_ReturnValue(void *info, AccessorDataEnum typ);
extern void* V8_PropertyCallbackInfo_This(void *info, PropertyDataEnum typ );
extern void* V8_PropertyCallbackInfo_Holder(void *info, PropertyDataEnum typ );
extern void* V8_PropertyCallbackInfo_ReturnValue(void *info, PropertyDataEnum typ );
/*
array
*/
extern void* V8_NewArray(void* engine, int length);
extern int V8_Array_Length(void* value);
/*
regexp
*/
extern void* V8_NewRegExp(void* engine, const char* pattern, int length, int flags);
extern char* V8_RegExp_Pattern(void* value);
extern int V8_RegExp_Flags(void* value);
/*
error
*/
extern void* V8_Exception_RangeError(void* engine, const char* val, int val_length);
extern void* V8_Exception_ReferenceError(void* engine, const char* val, int val_length);
extern void* V8_Exception_SyntaxError(void* engine, const char* val, int val_length);
extern void* V8_Exception_TypeError(void* engine, const char* val, int val_length);
extern void* V8_Exception_Error(void* engine, const char* val, int val_length);
/*
return value
*/
extern void V8_ReturnValue_Set(void* rv, void* result);
extern void V8_ReturnValue_SetBoolean(void* rv, int v);
extern void V8_ReturnValue_SetNumber(void* rv, double v);
extern void V8_ReturnValue_SetInt32(void* rv, int32_t v);
extern void V8_ReturnValue_SetUint32(void* rv, uint32_t v);
extern void V8_ReturnValue_SetString(void* rv, const char* str, int str_length);
extern void V8_ReturnValue_SetNull(void* rv);
extern void V8_ReturnValue_SetUndefined(void* rv);
/*
function
*/
extern void* V8_NewFunction(void* engine, void* callback, void* data);
extern void* V8_Function_Call(void* value, int argc, void* argv);
extern void* V8_Function_NewInstance(void* value, int argc, void* argv);
extern void* V8_FunctionCallbackInfo_Get(void* info, int i);
extern int V8_FunctionCallbackInfo_Length(void* info);
extern void* V8_FunctionCallbackInfo_Callee(void* info);
extern void* V8_FunctionCallbackInfo_This(void* info);
extern void* V8_FunctionCallbackInfo_Holder(void* info);
extern void* V8_FunctionCallbackInfo_ReturnValue(void* info);
/*
object template
*/
extern void* V8_NewObjectTemplate(void* engine);
extern void V8_DisposeObjectTemplate(void* tpl);
extern void V8_ObjectTemplate_Plugin(void* tpl, void* init);
extern void V8_ObjectTemplate_SetProperty(void* tpl, const char* key, int key_length, void* prop_value, int attribs);
extern void* V8_ObjectTemplate_NewInstance(void* engine, void* tpl);
extern void V8_ObjectTemplate_SetAccessor(void *tpl, const char* key, int key_length, void* getter, void* setter, void* data, int attribs);
extern void V8_ObjectTemplate_SetNamedPropertyHandler(
void* tpl,
void* getter,
void* setter,
void* query,
void* deleter,
void* enumerator,
void* data
);
extern void V8_ObjectTemplate_SetIndexedPropertyHandler(
void* tpl,
void* getter,
void* setter,
void* query,
void* deleter,
void* enumerator,
void* data
);
extern void V8_ObjectTemplate_SetInternalFieldCount(void *tpl, int count);
extern void V8_ObjectTemplate_SetAccessCheckCallbacks(
void* tpl,
void* namesecurity,
void* indexedsecuriry,
void* data
);
/*
function template
*/
extern void* V8_NewFunctionTemplate(void* engine, void* callback, void* data);
extern void V8_DisposeFunctionTemplate(void* tpl);
extern void* V8_FunctionTemplate_GetFunction(void* tpl);
extern void V8_FunctionTemplate_SetClassName(void* tpl, const char* name, int name_length);
extern void* V8_FunctionTemplate_InstanceTemplate(void* tpl);
extern void V8_FunctionTemplate_SetHiddenPrototype(void* tpl, int value);
/*
V8
*/
extern const char* V8_GetVersion();
extern void V8_SetFlagsFromString(const char* str, int length);
extern void V8_UseDefaultArrayBufferAllocator();
extern void V8_EnableMessageListener(void* engine, void* go_engine, int enable);
extern void V8_SetCaptureStackTraceForUncaughtExceptions(void* engine, int capture, int frame_limit);
#ifdef __cplusplus
} // extern "C"
#endif
#endif