forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChakraCommonWindows.h
More file actions
367 lines (350 loc) · 15.6 KB
/
ChakraCommonWindows.h
File metadata and controls
367 lines (350 loc) · 15.6 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
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma once
#endif // _MSC_VER
#ifndef _CHAKRACOMMONWINDOWS_H_
#define _CHAKRACOMMONWINDOWS_H_
/// <summary>
/// Called by the runtime to load the source code of the serialized script.
/// The caller must keep the script buffer valid until the JsSerializedScriptUnloadCallback.
/// This callback is only supported by the Win32 version of the API
/// </summary>
/// <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptWithCallback</param>
/// <param name="scriptBuffer">The script returned.</param>
/// <returns>
/// true if the operation succeeded, false otherwise.
/// </returns>
typedef bool (CHAKRA_CALLBACK * JsSerializedScriptLoadSourceCallback)(_In_ JsSourceContext sourceContext, _Outptr_result_z_ const WCHAR** scriptBuffer);
/// <summary>
/// Parses a script and returns a function representing the script.
/// </summary>
/// <remarks>
/// Requires an active script context.
/// </remarks>
/// <param name="script">The script to parse.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// </param>
/// <param name="sourceUrl">The location the script came from.</param>
/// <param name="result">A function representing the script code.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsParseScript(
_In_z_ const wchar_t *script,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_Out_ JsValueRef *result);
/// <summary>
/// Parses a script and returns a function representing the script.
/// </summary>
/// <remarks>
/// Requires an active script context.
/// </remarks>
/// <param name="script">The script to parse.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// </param>
/// <param name="sourceUrl">The location the script came from.</param>
/// <param name="parseAttributes">Attribute mask for parsing the script</param>
/// <param name="result">A function representing the script code.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsParseScriptWithAttributes(
_In_z_ const wchar_t *script,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_In_ JsParseScriptAttributes parseAttributes,
_Out_ JsValueRef *result);
/// <summary>
/// Executes a script.
/// </summary>
/// <remarks>
/// Requires an active script context.
/// </remarks>
/// <param name="script">The script to run.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// </param>
/// <param name="sourceUrl">The location the script came from.</param>
/// <param name="result">The result of the script, if any. This parameter can be null.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsRunScript(
_In_z_ const wchar_t *script,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_Out_ JsValueRef *result);
/// <summary>
/// Executes a module.
/// </summary>
/// <remarks>
/// Requires an active script context.
/// </remarks>
/// <param name="script">The module script to parse and execute.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// </param>
/// <param name="sourceUrl">The location the module script came from.</param>
/// <param name="result">The result of executing the module script, if any. This parameter can be null.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsExperimentalApiRunModule(
_In_z_ const wchar_t *script,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_Out_ JsValueRef *result);
/// <summary>
/// Serializes a parsed script to a buffer than can be reused.
/// </summary>
/// <remarks>
/// <para>
/// <c>JsSerializeScript</c> parses a script and then stores the parsed form of the script in a
/// runtime-independent format. The serialized script then can be deserialized in any
/// runtime without requiring the script to be re-parsed.
/// </para>
/// <para>
/// Requires an active script context.
/// </para>
/// </remarks>
/// <param name="script">The script to serialize.</param>
/// <param name="buffer">The buffer to put the serialized script into. Can be null.</param>
/// <param name="bufferSize">
/// On entry, the size of the buffer, in bytes; on exit, the size of the buffer, in bytes,
/// required to hold the serialized script.
/// </param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsSerializeScript(
_In_z_ const wchar_t *script,
_Out_writes_to_opt_(*bufferSize, *bufferSize) BYTE *buffer,
_Inout_ unsigned int *bufferSize);
/// <summary>
/// Parses a serialized script and returns a function representing the script.
/// Provides the ability to lazy load the script source only if/when it is needed.
/// </summary>
/// <remarks>
/// <para>
/// Requires an active script context.
/// </para>
/// <para>
/// The runtime will hold on to the buffer until all instances of any functions created from
/// the buffer are garbage collected. It will then call scriptUnloadCallback to inform the
/// caller it is safe to release.
/// </para>
/// </remarks>
/// <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param>
/// <param name="scriptUnloadCallback">Callback called when the serialized script and source code are no longer needed.</param>
/// <param name="buffer">The serialized script.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// This context will passed into scriptLoadCallback and scriptUnloadCallback.
/// </param>
/// <param name="sourceUrl">The location the script came from.</param>
/// <param name="result">A function representing the script code.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsParseSerializedScriptWithCallback(
_In_ JsSerializedScriptLoadSourceCallback scriptLoadCallback,
_In_ JsSerializedScriptUnloadCallback scriptUnloadCallback,
_In_ BYTE *buffer,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_Out_ JsValueRef * result);
/// <summary>
/// Runs a serialized script.
/// Provides the ability to lazy load the script source only if/when it is needed.
/// </summary>
/// <remarks>
/// <para>
/// Requires an active script context.
/// </para>
/// <para>
/// The runtime will hold on to the buffer until all instances of any functions created from
/// the buffer are garbage collected. It will then call scriptUnloadCallback to inform the
/// caller it is safe to release.
/// </para>
/// </remarks>
/// <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param>
/// <param name="scriptUnloadCallback">Callback called when the serialized script and source code are no longer needed.</param>
/// <param name="buffer">The serialized script.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// This context will passed into scriptLoadCallback and scriptUnloadCallback.
/// </param>
/// <param name="sourceUrl">The location the script came from.</param>
/// <param name="result">
/// The result of running the script, if any. This parameter can be null.
/// </param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsRunSerializedScriptWithCallback(
_In_ JsSerializedScriptLoadSourceCallback scriptLoadCallback,
_In_ JsSerializedScriptUnloadCallback scriptUnloadCallback,
_In_ BYTE *buffer,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_Out_opt_ JsValueRef * result);
/// <summary>
/// Parses a serialized script and returns a function representing the script.
/// </summary>
/// <remarks>
/// <para>
/// Requires an active script context.
/// </para>
/// <para>
/// The runtime will hold on to the buffer until all instances of any functions created from
/// the buffer are garbage collected.
/// </para>
/// </remarks>
/// <param name="script">The script to parse.</param>
/// <param name="buffer">The serialized script.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// </param>
/// <param name="sourceUrl">The location the script came from.</param>
/// <param name="result">A function representing the script code.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsParseSerializedScript(
_In_z_ const wchar_t *script,
_In_ BYTE *buffer,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_Out_ JsValueRef *result);
/// <summary>
/// Runs a serialized script.
/// </summary>
/// <remarks>
/// <para>
/// Requires an active script context.
/// </para>
/// <para>
/// The runtime will hold on to the buffer until all instances of any functions created from
/// the buffer are garbage collected.
/// </para>
/// </remarks>
/// <param name="script">The source code of the serialized script.</param>
/// <param name="buffer">The serialized script.</param>
/// <param name="sourceContext">
/// A cookie identifying the script that can be used by debuggable script contexts.
/// </param>
/// <param name="sourceUrl">The location the script came from.</param>
/// <param name="result">
/// The result of running the script, if any. This parameter can be null.
/// </param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsRunSerializedScript(
_In_z_ const wchar_t *script,
_In_ BYTE *buffer,
_In_ JsSourceContext sourceContext,
_In_z_ const wchar_t *sourceUrl,
_Out_ JsValueRef *result);
/// <summary>
/// Gets the property ID associated with the name.
/// </summary>
/// <remarks>
/// <para>
/// Property IDs are specific to a context and cannot be used across contexts.
/// </para>
/// <para>
/// Requires an active script context.
/// </para>
/// </remarks>
/// <param name="name">
/// The name of the property ID to get or create. The name may consist of only digits.
/// </param>
/// <param name="propertyId">The property ID in this runtime for the given name.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsGetPropertyIdFromName(
_In_z_ const wchar_t *name,
_Out_ JsPropertyIdRef *propertyId);
/// <summary>
/// Gets the name associated with the property ID.
/// </summary>
/// <remarks>
/// <para>
/// Requires an active script context.
/// </para>
/// <para>
/// The returned buffer is valid as long as the runtime is alive and cannot be used
/// once the runtime has been disposed.
/// </para>
/// </remarks>
/// <param name="propertyId">The property ID to get the name of.</param>
/// <param name="name">The name associated with the property ID.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsGetPropertyNameFromId(
_In_ JsPropertyIdRef propertyId,
_Outptr_result_z_ const wchar_t **name);
/// <summary>
/// Creates a string value from a string pointer.
/// </summary>
/// <remarks>
/// Requires an active script context.
/// </remarks>
/// <param name="stringValue">The string pointer to convert to a string value.</param>
/// <param name="stringLength">The length of the string to convert.</param>
/// <param name="value">The new string value.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsPointerToString(
_In_reads_(stringLength) const wchar_t *stringValue,
_In_ size_t stringLength,
_Out_ JsValueRef *value);
/// <summary>
/// Retrieves the string pointer of a string value.
/// </summary>
/// <remarks>
/// <para>
/// This function retrieves the string pointer of a string value. It will fail with
/// <c>JsErrorInvalidArgument</c> if the type of the value is not string. The lifetime
/// of the string returned will be the same as the lifetime of the value it came from, however
/// the string pointer is not considered a reference to the value (and so will not keep it
/// from being collected).
/// </para>
/// <para>
/// Requires an active script context.
/// </para>
/// </remarks>
/// <param name="value">The string value to convert to a string pointer.</param>
/// <param name="stringValue">The string pointer.</param>
/// <param name="stringLength">The length of the string.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsStringToPointer(
_In_ JsValueRef value,
_Outptr_result_buffer_(*stringLength) const wchar_t **stringValue,
_Out_ size_t *stringLength);
#endif // _CHAKRACOMMONWINDOWS_H_