-
Notifications
You must be signed in to change notification settings - Fork 2
/
v8_c_bridge-old.h
184 lines (159 loc) · 5.08 KB
/
v8_c_bridge-old.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
#include <stddef.h>
#include <stdint.h>
#ifndef V8_C_BRIDGE_H
#define V8_C_BRIDGE_H
#ifdef __cplusplus
extern "C" {
#endif
typedef void* IsolatePtr;
typedef void* ContextPtr;
typedef void* PersistentValuePtr;
typedef struct {
const char* ptr;
int len;
} String;
typedef String Error;
typedef String StartupData;
typedef String ByteArray;
typedef struct {
size_t total_heap_size;
size_t total_heap_size_executable;
size_t total_physical_size;
size_t total_available_size;
size_t used_heap_size;
size_t heap_size_limit;
size_t malloced_memory;
size_t peak_malloced_memory;
size_t does_zap_garbage;
} HeapStatistics;
// NOTE! These values must exactly match the values in kinds.go. Any mismatch
// will cause kinds to be misreported.
typedef enum {
kUndefined = 0,
kNull,
kName,
kString,
kSymbol,
kFunction,
kArray,
kObject,
kBoolean,
kNumber,
kExternal,
kInt32,
kUint32,
kDate,
kArgumentsObject,
kBooleanObject,
kNumberObject,
kStringObject,
kSymbolObject,
kNativeError,
kRegExp,
kAsyncFunction,
kGeneratorFunction,
kGeneratorObject,
kPromise,
kMap,
kSet,
kMapIterator,
kSetIterator,
kWeakMap,
kWeakSet,
kArrayBuffer,
kArrayBufferView,
kTypedArray,
kUint8Array,
kUint8ClampedArray,
kInt8Array,
kUint16Array,
kInt16Array,
kUint32Array,
kInt32Array,
kFloat32Array,
kFloat64Array,
kDataView,
kSharedArrayBuffer,
kProxy,
kWebAssemblyCompiledModule,
kNumKinds,
} Kind;
// Each kind can be represent using only single 64 bit bitmask since there
// are less than 64 kinds so far. If this grows beyond 64 kinds, we can switch
// to multiple bitmasks or a dynamically-allocated array.
typedef uint64_t KindMask;
typedef struct {
PersistentValuePtr Value;
KindMask Kinds;
Error error_msg;
} ValueTuple;
typedef struct {
String Funcname;
String Filename;
int Line;
int Column;
} CallerInfo;
typedef struct { int Major, Minor, Build, Patch; } Version;
extern Version version;
// typedef unsigned int uint32_t;
// v8_init must be called once before anything else.
extern void v8_init();
extern StartupData v8_CreateSnapshotDataBlob(const char* js);
extern IsolatePtr v8_Isolate_New(StartupData data);
extern ContextPtr v8_Isolate_NewContext(IsolatePtr isolate);
extern void v8_Isolate_Terminate(IsolatePtr isolate);
extern void v8_Isolate_Release(IsolatePtr isolate);
extern HeapStatistics v8_Isolate_GetHeapStatistics(IsolatePtr isolate);
extern void v8_Isolate_LowMemoryNotification(IsolatePtr isolate);
extern ValueTuple v8_Context_Run(ContextPtr ctx,
const char* code, const char* filename);
extern PersistentValuePtr v8_Context_RegisterCallback(ContextPtr ctx,
const char* name, const char* id);
extern PersistentValuePtr v8_Context_Global(ContextPtr ctx);
extern void v8_Context_Release(ContextPtr ctx);
typedef enum {
tSTRING,
tBOOL,
tFLOAT64,
tINT64,
tOBJECT,
tARRAY,
tARRAYBUFFER,
tUNDEFINED,
tDATE, // uses Float64 for msec since Unix epoch
} ImmediateValueType;
typedef struct {
ImmediateValueType Type;
// Mem is used for String, ArrayBuffer, or Array. For Array, only len is
// used -- ptr is ignored.
ByteArray Mem;
int Bool;
double Float64;
int64_t Int64;
} ImmediateValue;
extern PersistentValuePtr v8_Context_Create(ContextPtr ctx, ImmediateValue val);
extern ValueTuple v8_Value_Get(ContextPtr ctx, PersistentValuePtr value, const char* field);
extern Error v8_Value_Set(ContextPtr ctx, PersistentValuePtr value,
const char* field, PersistentValuePtr new_value);
extern ValueTuple v8_Value_GetIdx(ContextPtr ctx, PersistentValuePtr value, int idx);
extern Error v8_Value_SetIdx(ContextPtr ctx, PersistentValuePtr value,
int idx, PersistentValuePtr new_value);
extern ValueTuple v8_Value_Call(ContextPtr ctx,
PersistentValuePtr func,
PersistentValuePtr self,
int argc, PersistentValuePtr* argv);
extern ValueTuple v8_Value_New(ContextPtr ctx,
PersistentValuePtr func,
int argc, PersistentValuePtr* argv);
extern void v8_Value_Release(ContextPtr ctx, PersistentValuePtr value);
extern String v8_Value_String(ContextPtr ctx, PersistentValuePtr value);
extern double v8_Value_Float64(ContextPtr ctx, PersistentValuePtr value);
extern int64_t v8_Value_Int64(ContextPtr ctx, PersistentValuePtr value);
extern int v8_Value_Bool(ContextPtr ctx, PersistentValuePtr value);
extern ByteArray v8_Value_Bytes(ContextPtr ctx, PersistentValuePtr value);
extern ValueTuple v8_Value_PromiseInfo(ContextPtr ctx, PersistentValuePtr value,
int* promise_state);
#ifdef __cplusplus
}
#endif
#endif // !defined(V8_C_BRIDGE_H)