forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
334 lines (227 loc) · 14.4 KB
/
NativeMethods.cs
File metadata and controls
334 lines (227 loc) · 14.4 KB
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
using System;
using System.Runtime.InteropServices;
namespace JavaScriptEngineSwitcher.ChakraCore.JsRt
{
/// <summary>
/// Native methods
/// </summary>
internal static class NativeMethods
{
const string DllName = "ChakraCore.dll";
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, out JsRuntime runtime);
[DllImport(DllName)]
internal static extern JsErrorCode JsCollectGarbage(JsRuntime handle);
[DllImport(DllName)]
internal static extern JsErrorCode JsDisposeRuntime(JsRuntime handle);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetRuntimeMemoryUsage(JsRuntime runtime, out UIntPtr memoryUsage);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetRuntimeMemoryLimit(JsRuntime runtime, out UIntPtr memoryLimit);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetRuntimeMemoryLimit(JsRuntime runtime, UIntPtr memoryLimit);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetRuntimeMemoryAllocationCallback(JsRuntime runtime, IntPtr callbackState, JsMemoryAllocationCallback allocationCallback);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetRuntimeBeforeCollectCallback(JsRuntime runtime, IntPtr callbackState, JsBeforeCollectCallback beforeCollectCallback);
[DllImport(DllName, EntryPoint = "JsAddRef")]
internal static extern JsErrorCode JsContextAddRef(JsContext reference, out uint count);
[DllImport(DllName)]
internal static extern JsErrorCode JsAddRef(JsValue reference, out uint count);
[DllImport(DllName, EntryPoint = "JsRelease")]
internal static extern JsErrorCode JsContextRelease(JsContext reference, out uint count);
[DllImport(DllName)]
internal static extern JsErrorCode JsRelease(JsValue reference, out uint count);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateContext(JsRuntime runtime, out JsContext newContext);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetCurrentContext(out JsContext currentContext);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetCurrentContext(JsContext context);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetRuntime(JsContext context, out JsRuntime runtime);
[DllImport(DllName)]
internal static extern JsErrorCode JsIdle(out uint nextIdleTick);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsParseScript(string script, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsRunScript(string script, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsSerializeScript(string script, byte[] buffer, ref ulong bufferSize);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsParseSerializedScript(string script, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsRunSerializedScript(string script, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsGetPropertyIdFromName(string name, out JsPropertyId propertyId);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsGetPropertyNameFromId(JsPropertyId propertyId, out string name);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetUndefinedValue(out JsValue undefinedValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetNullValue(out JsValue nullValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetTrueValue(out JsValue trueValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetFalseValue(out JsValue falseValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsBoolToBoolean(bool value, out JsValue booleanValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsBooleanToBool(JsValue booleanValue, out bool boolValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsConvertValueToBoolean(JsValue value, out JsValue booleanValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetValueType(JsValue value, out JsValueType type);
[DllImport(DllName)]
internal static extern JsErrorCode JsDoubleToNumber(double doubleValue, out JsValue value);
[DllImport(DllName)]
internal static extern JsErrorCode JsIntToNumber(int intValue, out JsValue value);
[DllImport(DllName)]
internal static extern JsErrorCode JsNumberToDouble(JsValue value, out double doubleValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsConvertValueToNumber(JsValue value, out JsValue numberValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetStringLength(JsValue sringValue, out int length);
[DllImport(DllName, CharSet = CharSet.Unicode)]
internal static extern JsErrorCode JsPointerToString(string value, UIntPtr stringLength, out JsValue stringValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsStringToPointer(JsValue value, out IntPtr stringValue, out UIntPtr stringLength);
[DllImport(DllName)]
internal static extern JsErrorCode JsConvertValueToString(JsValue value, out JsValue stringValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetGlobalObject(out JsValue globalObject);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateObject(out JsValue obj);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateExternalObject(IntPtr data, JsObjectFinalizeCallback finalizeCallback, out JsValue obj);
[DllImport(DllName)]
internal static extern JsErrorCode JsConvertValueToObject(JsValue value, out JsValue obj);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetPrototype(JsValue obj, out JsValue prototypeObject);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetPrototype(JsValue obj, JsValue prototypeObject);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetExtensionAllowed(JsValue obj, out bool value);
[DllImport(DllName)]
internal static extern JsErrorCode JsPreventExtension(JsValue obj);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetProperty(JsValue obj, JsPropertyId propertyId, out JsValue value);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetOwnPropertyDescriptor(JsValue obj, JsPropertyId propertyId, out JsValue propertyDescriptor);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetOwnPropertyNames(JsValue obj, out JsValue propertyNames);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetProperty(JsValue obj, JsPropertyId propertyId, JsValue value, bool useStrictRules);
[DllImport(DllName)]
internal static extern JsErrorCode JsHasProperty(JsValue obj, JsPropertyId propertyId, out bool hasProperty);
[DllImport(DllName)]
internal static extern JsErrorCode JsDeleteProperty(JsValue obj, JsPropertyId propertyId, bool useStrictRules, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsDefineProperty(JsValue obj, JsPropertyId propertyId, JsValue propertyDescriptor, out bool result);
[DllImport(DllName)]
internal static extern JsErrorCode JsHasIndexedProperty(JsValue obj, JsValue index, out bool result);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetIndexedProperty(JsValue obj, JsValue index, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetIndexedProperty(JsValue obj, JsValue index, JsValue value);
[DllImport(DllName)]
internal static extern JsErrorCode JsDeleteIndexedProperty(JsValue obj, JsValue index);
[DllImport(DllName)]
internal static extern JsErrorCode JsEquals(JsValue obj1, JsValue obj2, out bool result);
[DllImport(DllName)]
internal static extern JsErrorCode JsStrictEquals(JsValue obj1, JsValue obj2, out bool result);
[DllImport(DllName)]
internal static extern JsErrorCode JsHasExternalData(JsValue obj, out bool value);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetExternalData(JsValue obj, out IntPtr externalData);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetExternalData(JsValue obj, IntPtr externalData);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateArray(uint length, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsCallFunction(JsValue function, JsValue[] arguments, ushort argumentCount, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsConstructObject(JsValue function, JsValue[] arguments, ushort argumentCount, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateFunction(JsNativeFunction nativeFunction, IntPtr externalData, out JsValue function);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateError(JsValue message, out JsValue error);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateRangeError(JsValue message, out JsValue error);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateReferenceError(JsValue message, out JsValue error);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateSyntaxError(JsValue message, out JsValue error);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateTypeError(JsValue message, out JsValue error);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateURIError(JsValue message, out JsValue error);
[DllImport(DllName)]
internal static extern JsErrorCode JsHasException(out bool hasException);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetAndClearException(out JsValue exception);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetException(JsValue exception);
[DllImport(DllName)]
internal static extern JsErrorCode JsDisableRuntimeExecution(JsRuntime runtime);
[DllImport(DllName)]
internal static extern JsErrorCode JsEnableRuntimeExecution(JsRuntime runtime);
[DllImport(DllName)]
internal static extern JsErrorCode JsIsRuntimeExecutionDisabled(JsRuntime runtime, out bool isDisabled);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetObjectBeforeCollectCallback(JsValue reference, IntPtr callbackState, JsObjectBeforeCollectCallback beforeCollectCallback);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateNamedFunction(JsValue name, JsNativeFunction nativeFunction, IntPtr callbackState, out JsValue function);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetPromiseContinuationCallback(JsPromiseContinuationCallback promiseContinuationCallback, IntPtr callbackState);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateArrayBuffer(uint byteLength, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateTypedArray(JsTypedArrayType arrayType, JsValue arrayBuffer, uint byteOffset,
uint elementLength, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateDataView(JsValue arrayBuffer, uint byteOffset, uint byteOffsetLength, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetArrayBufferStorage(JsValue arrayBuffer, out byte[] buffer, out uint bufferLength);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetTypedArrayStorage(JsValue typedArray, out byte[] buffer, out uint bufferLength, out JsTypedArrayType arrayType, out int elementSize);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetDataViewStorage(JsValue dataView, out byte[] buffer, out uint bufferLength);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetPropertyIdType(JsPropertyId propertyId, out JsPropertyIdType propertyIdType);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateSymbol(JsValue description, out JsValue symbol);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetSymbolFromPropertyId(JsPropertyId propertyId, out JsValue symbol);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetPropertyIdFromSymbol(JsValue symbol, out JsPropertyId propertyId);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetOwnPropertySymbols(JsValue obj, out JsValue propertySymbols);
[DllImport(DllName)]
internal static extern JsErrorCode JsNumberToInt(JsValue value, out int intValue);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetIndexedPropertiesToExternalData(JsValue obj, IntPtr data, JsTypedArrayType arrayType, uint elementLength);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetIndexedPropertiesExternalData(JsValue obj, IntPtr data, out JsTypedArrayType arrayType, out uint elementLength);
[DllImport(DllName)]
internal static extern JsErrorCode JsHasIndexedPropertiesExternalData(JsValue obj, out bool value);
[DllImport(DllName)]
internal static extern JsErrorCode JsInstanceOf(JsValue obj, JsValue constructor, out bool result);
[DllImport(DllName)]
internal static extern JsErrorCode JsCreateExternalArrayBuffer(IntPtr data, uint byteLength, JsObjectFinalizeCallback finalizeCallback, IntPtr callbackState, out bool result);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetTypedArrayInfo(JsValue typedArray, out JsTypedArrayType arrayType, out JsValue arrayBuffer, out uint byteOffset, out uint byteLength);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetContextOfObject(JsValue obj, out JsContext context);
[DllImport(DllName)]
internal static extern JsErrorCode JsGetContextData(JsContext context, out IntPtr data);
[DllImport(DllName)]
internal static extern JsErrorCode JsSetContextData(JsContext context, IntPtr data);
[DllImport(DllName)]
internal static extern JsErrorCode JsParseSerializedScriptWithCallback(JsSerializedScriptLoadSourceCallback scriptLoadCallback,
JsSerializedScriptUnloadCallback scriptUnloadCallback, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
[DllImport(DllName)]
internal static extern JsErrorCode JsRunSerializedScriptWithCallback(JsSerializedScriptLoadSourceCallback scriptLoadCallback,
JsSerializedScriptUnloadCallback scriptUnloadCallback, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
}
}