@downdraft/native-mobile-android-arm64 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/include/node/cppgc/allocation.h +308 -0
  2. package/include/node/cppgc/common.h +28 -0
  3. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  4. package/include/node/cppgc/custom-space.h +97 -0
  5. package/include/node/cppgc/default-platform.h +68 -0
  6. package/include/node/cppgc/explicit-management.h +100 -0
  7. package/include/node/cppgc/garbage-collected.h +114 -0
  8. package/include/node/cppgc/heap-consistency.h +309 -0
  9. package/include/node/cppgc/heap-handle.h +48 -0
  10. package/include/node/cppgc/heap-state.h +82 -0
  11. package/include/node/cppgc/heap-statistics.h +126 -0
  12. package/include/node/cppgc/heap.h +202 -0
  13. package/include/node/cppgc/internal/api-constants.h +75 -0
  14. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  15. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  16. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  17. package/include/node/cppgc/internal/caged-heap.h +64 -0
  18. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  19. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  20. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  21. package/include/node/cppgc/internal/gc-info.h +150 -0
  22. package/include/node/cppgc/internal/logging.h +50 -0
  23. package/include/node/cppgc/internal/member-storage.h +305 -0
  24. package/include/node/cppgc/internal/name-trait.h +141 -0
  25. package/include/node/cppgc/internal/persistent-node.h +219 -0
  26. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  27. package/include/node/cppgc/internal/write-barrier.h +487 -0
  28. package/include/node/cppgc/liveness-broker.h +78 -0
  29. package/include/node/cppgc/macros.h +56 -0
  30. package/include/node/cppgc/member.h +669 -0
  31. package/include/node/cppgc/name-provider.h +75 -0
  32. package/include/node/cppgc/object-size-trait.h +58 -0
  33. package/include/node/cppgc/persistent.h +376 -0
  34. package/include/node/cppgc/platform.h +174 -0
  35. package/include/node/cppgc/prefinalizer.h +75 -0
  36. package/include/node/cppgc/process-heap-statistics.h +36 -0
  37. package/include/node/cppgc/sentinel-pointer.h +39 -0
  38. package/include/node/cppgc/source-location.h +16 -0
  39. package/include/node/cppgc/tagged-member.h +114 -0
  40. package/include/node/cppgc/testing.h +106 -0
  41. package/include/node/cppgc/trace-trait.h +127 -0
  42. package/include/node/cppgc/type-traits.h +272 -0
  43. package/include/node/cppgc/visitor.h +534 -0
  44. package/include/node/js_native_api.h +634 -0
  45. package/include/node/js_native_api_types.h +244 -0
  46. package/include/node/libplatform/libplatform-export.h +29 -0
  47. package/include/node/libplatform/libplatform.h +112 -0
  48. package/include/node/libplatform/v8-tracing.h +343 -0
  49. package/include/node/node.h +1744 -0
  50. package/include/node/node_api.h +265 -0
  51. package/include/node/node_api_types.h +58 -0
  52. package/include/node/node_buffer.h +94 -0
  53. package/include/node/node_object_wrap.h +145 -0
  54. package/include/node/node_version.h +116 -0
  55. package/include/node/uv/aix.h +32 -0
  56. package/include/node/uv/bsd.h +34 -0
  57. package/include/node/uv/darwin.h +61 -0
  58. package/include/node/uv/errno.h +483 -0
  59. package/include/node/uv/linux.h +34 -0
  60. package/include/node/uv/os390.h +33 -0
  61. package/include/node/uv/posix.h +31 -0
  62. package/include/node/uv/sunos.h +44 -0
  63. package/include/node/uv/threadpool.h +37 -0
  64. package/include/node/uv/tree.h +521 -0
  65. package/include/node/uv/unix.h +509 -0
  66. package/include/node/uv/version.h +43 -0
  67. package/include/node/uv/win.h +698 -0
  68. package/include/node/uv.h +1994 -0
  69. package/include/node/v8-array-buffer.h +646 -0
  70. package/include/node/v8-callbacks.h +533 -0
  71. package/include/node/v8-container.h +183 -0
  72. package/include/node/v8-context.h +580 -0
  73. package/include/node/v8-cpp-heap-external.h +56 -0
  74. package/include/node/v8-cppgc.h +194 -0
  75. package/include/node/v8-data.h +96 -0
  76. package/include/node/v8-date.h +57 -0
  77. package/include/node/v8-debug.h +210 -0
  78. package/include/node/v8-embedder-heap.h +54 -0
  79. package/include/node/v8-embedder-state-scope.h +52 -0
  80. package/include/node/v8-exception.h +298 -0
  81. package/include/node/v8-extension.h +60 -0
  82. package/include/node/v8-external-memory-accounter.h +60 -0
  83. package/include/node/v8-external.h +73 -0
  84. package/include/node/v8-fast-api-calls.h +784 -0
  85. package/include/node/v8-forward.h +82 -0
  86. package/include/node/v8-function-callback.h +708 -0
  87. package/include/node/v8-function.h +148 -0
  88. package/include/node/v8-handle-base.h +155 -0
  89. package/include/node/v8-initialization.h +343 -0
  90. package/include/node/v8-inspector-protocol.h +13 -0
  91. package/include/node/v8-inspector.h +458 -0
  92. package/include/node/v8-internal.h +1827 -0
  93. package/include/node/v8-isolate.h +1925 -0
  94. package/include/node/v8-json.h +54 -0
  95. package/include/node/v8-local-handle.h +884 -0
  96. package/include/node/v8-locker.h +138 -0
  97. package/include/node/v8-maybe.h +185 -0
  98. package/include/node/v8-memory-span.h +273 -0
  99. package/include/node/v8-message.h +215 -0
  100. package/include/node/v8-metrics.h +273 -0
  101. package/include/node/v8-microtask-queue.h +152 -0
  102. package/include/node/v8-microtask.h +28 -0
  103. package/include/node/v8-object.h +1134 -0
  104. package/include/node/v8-persistent-handle.h +556 -0
  105. package/include/node/v8-platform.h +1552 -0
  106. package/include/node/v8-primitive-object.h +118 -0
  107. package/include/node/v8-primitive.h +1056 -0
  108. package/include/node/v8-profiler.h +1401 -0
  109. package/include/node/v8-promise.h +185 -0
  110. package/include/node/v8-proxy.h +49 -0
  111. package/include/node/v8-regexp.h +105 -0
  112. package/include/node/v8-sandbox.h +170 -0
  113. package/include/node/v8-script.h +996 -0
  114. package/include/node/v8-snapshot.h +302 -0
  115. package/include/node/v8-source-location.h +91 -0
  116. package/include/node/v8-statistics.h +246 -0
  117. package/include/node/v8-template.h +1096 -0
  118. package/include/node/v8-trace-categories.h +28 -0
  119. package/include/node/v8-traced-handle.h +420 -0
  120. package/include/node/v8-typed-array.h +386 -0
  121. package/include/node/v8-unwinder-state.h +30 -0
  122. package/include/node/v8-unwinder.h +146 -0
  123. package/include/node/v8-util.h +549 -0
  124. package/include/node/v8-value-serializer-version.h +24 -0
  125. package/include/node/v8-value-serializer.h +316 -0
  126. package/include/node/v8-value.h +674 -0
  127. package/include/node/v8-version-string.h +38 -0
  128. package/include/node/v8-version.h +20 -0
  129. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  130. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  131. package/include/node/v8-wasm.h +325 -0
  132. package/include/node/v8-weak-callback-info.h +88 -0
  133. package/include/node/v8.h +88 -0
  134. package/include/node/v8config.h +1077 -0
  135. package/lib/libc++_shared.so +0 -0
  136. package/lib/libnode.so +4 -0
  137. package/package.json +23 -3
@@ -0,0 +1,996 @@
1
+ // Copyright 2021 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_V8_SCRIPT_H_
6
+ #define INCLUDE_V8_SCRIPT_H_
7
+
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+
11
+ #include <memory>
12
+ #include <tuple>
13
+ #include <vector>
14
+
15
+ #include "v8-callbacks.h" // NOLINT(build/include_directory)
16
+ #include "v8-data.h" // NOLINT(build/include_directory)
17
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
18
+ #include "v8-maybe.h" // NOLINT(build/include_directory)
19
+ #include "v8-memory-span.h" // NOLINT(build/include_directory)
20
+ #include "v8-message.h" // NOLINT(build/include_directory)
21
+ #include "v8config.h" // NOLINT(build/include_directory)
22
+
23
+ namespace v8 {
24
+
25
+ class Function;
26
+ class Message;
27
+ class Object;
28
+ class PrimitiveArray;
29
+ class Script;
30
+
31
+ namespace internal {
32
+ class BackgroundDeserializeTask;
33
+ struct ScriptStreamingData;
34
+ } // namespace internal
35
+
36
+ /**
37
+ * A container type that holds relevant metadata for module loading.
38
+ *
39
+ * This is passed back to the embedder as part of
40
+ * HostImportModuleDynamicallyCallback for module loading.
41
+ */
42
+ class V8_EXPORT ScriptOrModule {
43
+ public:
44
+ /**
45
+ * The name that was passed by the embedder as ResourceName to the
46
+ * ScriptOrigin. This can be either a v8::String or v8::Undefined.
47
+ */
48
+ Local<Value> GetResourceName();
49
+
50
+ /**
51
+ * The options that were passed by the embedder as HostDefinedOptions to
52
+ * the ScriptOrigin.
53
+ */
54
+ Local<Data> HostDefinedOptions();
55
+ };
56
+
57
+ /**
58
+ * A compiled JavaScript script, not yet tied to a Context.
59
+ */
60
+ class V8_EXPORT UnboundScript : public Data {
61
+ public:
62
+ /**
63
+ * Binds the script to the currently entered context.
64
+ */
65
+ Local<Script> BindToCurrentContext();
66
+
67
+ /*
68
+ * A unique id.
69
+ */
70
+ int ScriptId() const;
71
+ V8_DEPRECATE_SOON("Use ScriptId")
72
+ int GetId() const;
73
+
74
+ Local<Value> GetScriptName();
75
+
76
+ /**
77
+ * Data read from magic sourceURL comments.
78
+ */
79
+ Local<Value> GetSourceURL();
80
+ /**
81
+ * Data read from magic sourceMappingURL comments.
82
+ */
83
+ Local<Value> GetSourceMappingURL();
84
+
85
+ /**
86
+ * Returns zero based line number of the code_pos location in the script.
87
+ * -1 will be returned if no information available.
88
+ */
89
+ int GetLineNumber(int code_pos = 0);
90
+
91
+ /**
92
+ * Returns zero based column number of the code_pos location in the script.
93
+ * -1 will be returned if no information available.
94
+ */
95
+ int GetColumnNumber(int code_pos = 0);
96
+
97
+ static const int kNoScriptId = 0;
98
+ };
99
+
100
+ /**
101
+ * A compiled JavaScript module, not yet tied to a Context.
102
+ */
103
+ class V8_EXPORT UnboundModuleScript : public Data {
104
+ public:
105
+ /**
106
+ * Data read from magic sourceURL comments.
107
+ */
108
+ Local<Value> GetSourceURL();
109
+ /**
110
+ * Data read from magic sourceMappingURL comments.
111
+ */
112
+ Local<Value> GetSourceMappingURL();
113
+
114
+ /*
115
+ * A unique id.
116
+ */
117
+ int ScriptId() const;
118
+
119
+ static const int kNoScriptId = 0;
120
+ };
121
+
122
+ static_assert(UnboundModuleScript::kNoScriptId == UnboundScript::kNoScriptId);
123
+
124
+ /**
125
+ * A location in JavaScript source.
126
+ */
127
+ class V8_EXPORT Location {
128
+ public:
129
+ int GetLineNumber() { return line_number_; }
130
+ int GetColumnNumber() { return column_number_; }
131
+
132
+ Location(int line_number, int column_number)
133
+ : line_number_(line_number), column_number_(column_number) {}
134
+
135
+ private:
136
+ int line_number_;
137
+ int column_number_;
138
+ };
139
+
140
+ class V8_EXPORT ModuleRequest : public Data {
141
+ public:
142
+ /**
143
+ * Returns the module specifier for this ModuleRequest.
144
+ */
145
+ Local<String> GetSpecifier() const;
146
+
147
+ /**
148
+ * Returns the module import phase for this ModuleRequest.
149
+ */
150
+ ModuleImportPhase GetPhase() const;
151
+
152
+ /**
153
+ * Returns the source code offset of this module request.
154
+ * Use Module::SourceOffsetToLocation to convert this to line/column numbers.
155
+ */
156
+ int GetSourceOffset() const;
157
+
158
+ /**
159
+ * Contains the import attributes for this request in the form:
160
+ * [key1, value1, source_offset1, key2, value2, source_offset2, ...].
161
+ * The keys and values are of type v8::String, and the source offsets are of
162
+ * type Int32. Use Module::SourceOffsetToLocation to convert the source
163
+ * offsets to Locations with line/column numbers.
164
+ *
165
+ * All attributes present in the module request will be supplied in this
166
+ * list, regardless of whether they are supported by the host. Per
167
+ * https://tc39.es/proposal-import-attributes/#sec-hostgetsupportedimportattributes,
168
+ * hosts are expected to throw for attributes that they do not support (as
169
+ * opposed to, for example, ignoring them).
170
+ */
171
+ Local<FixedArray> GetImportAttributes() const;
172
+
173
+ V8_DEPRECATED("Use GetImportAttributes instead")
174
+ Local<FixedArray> GetImportAssertions() const {
175
+ return GetImportAttributes();
176
+ }
177
+
178
+ V8_INLINE static ModuleRequest* Cast(Data* data);
179
+
180
+ private:
181
+ static void CheckCast(Data* obj);
182
+ };
183
+
184
+ /**
185
+ * A compiled JavaScript module.
186
+ */
187
+ class V8_EXPORT Module : public Data {
188
+ public:
189
+ /**
190
+ * The different states a module can be in.
191
+ *
192
+ * This corresponds to the states used in ECMAScript except that "evaluated"
193
+ * is split into kEvaluated and kErrored, indicating success and failure,
194
+ * respectively.
195
+ */
196
+ enum Status {
197
+ kUninstantiated,
198
+ kInstantiating,
199
+ kInstantiated,
200
+ kEvaluating,
201
+ kEvaluated,
202
+ kErrored
203
+ };
204
+
205
+ /**
206
+ * If the module is a Source Text Module, returns the name that was passed
207
+ * by the embedder as resource_name to the ScriptOrigin. If it's a Synthetic
208
+ * Module, returns the module_name passed to CreateSyntheticModule().
209
+ */
210
+ Local<Value> GetResourceName() const;
211
+
212
+ /**
213
+ * Returns the module's current status.
214
+ */
215
+ Status GetStatus() const;
216
+
217
+ /**
218
+ * For a module in kErrored status, this returns the corresponding exception.
219
+ */
220
+ Local<Value> GetException() const;
221
+
222
+ /**
223
+ * Returns the ModuleRequests for this module.
224
+ */
225
+ Local<FixedArray> GetModuleRequests() const;
226
+
227
+ /**
228
+ * For the given source text offset in this module, returns the corresponding
229
+ * Location with line and column numbers.
230
+ */
231
+ Location SourceOffsetToLocation(int offset) const;
232
+
233
+ /**
234
+ * Returns the identity hash for this object.
235
+ */
236
+ int GetIdentityHash() const;
237
+
238
+ using ResolveModuleCallback = MaybeLocal<Module> (*)(
239
+ Local<Context> context, Local<String> specifier,
240
+ Local<FixedArray> import_attributes, Local<Module> referrer);
241
+ using ResolveSourceCallback = MaybeLocal<Object> (*)(
242
+ Local<Context> context, Local<String> specifier,
243
+ Local<FixedArray> import_attributes, Local<Module> referrer);
244
+
245
+ using ResolveModuleByIndexCallback = MaybeLocal<Module> (*)(
246
+ Local<Context> context, size_t module_request_index,
247
+ Local<Module> referrer);
248
+ using ResolveSourceByIndexCallback = MaybeLocal<Object> (*)(
249
+ Local<Context> context, size_t module_request_index,
250
+ Local<Module> referrer);
251
+
252
+ /**
253
+ * Instantiates the module and its dependencies.
254
+ *
255
+ * Returns an empty Maybe<bool> if an exception occurred during
256
+ * instantiation. (In the case where the callback throws an exception, that
257
+ * exception is propagated.)
258
+ */
259
+ V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(
260
+ Local<Context> context, ResolveModuleCallback module_callback,
261
+ ResolveSourceCallback source_callback = nullptr);
262
+
263
+ /**
264
+ * Similar to the variant that takes ResolveModuleCallback and
265
+ * ResolveSourceCallback, but uses the index into the array that is returned
266
+ * by GetModuleRequests() instead of the specifier and import attributes to
267
+ * identify the requests.
268
+ */
269
+ V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(
270
+ Local<Context> context, ResolveModuleByIndexCallback module_callback,
271
+ ResolveSourceByIndexCallback source_callback = nullptr);
272
+
273
+ /**
274
+ * Evaluates the module and its dependencies.
275
+ *
276
+ * If status is kInstantiated, run the module's code and return a Promise
277
+ * object. On success, set status to kEvaluated and resolve the Promise with
278
+ * the completion value; on failure, set status to kErrored and reject the
279
+ * Promise with the error.
280
+ *
281
+ * If IsGraphAsync() is false, the returned Promise is settled.
282
+ */
283
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
284
+
285
+ /**
286
+ * Returns the namespace object of this module.
287
+ *
288
+ * The module's status must be at least kInstantiated.
289
+ */
290
+ Local<Value> GetModuleNamespace();
291
+
292
+ /**
293
+ * Returns the corresponding context-unbound module script.
294
+ *
295
+ * The module must be unevaluated, i.e. its status must not be kEvaluating,
296
+ * kEvaluated or kErrored.
297
+ */
298
+ Local<UnboundModuleScript> GetUnboundModuleScript();
299
+
300
+ /**
301
+ * Returns the underlying script's id.
302
+ *
303
+ * The module must be a SourceTextModule and must not have a kErrored status.
304
+ */
305
+ int ScriptId() const;
306
+
307
+ /**
308
+ * Returns whether this module or any of its requested modules is async,
309
+ * i.e. contains top-level await.
310
+ *
311
+ * The module's status must be at least kInstantiated.
312
+ */
313
+ bool IsGraphAsync() const;
314
+
315
+ /**
316
+ * Returns whether this module is individually asynchronous (for example,
317
+ * if it's a Source Text Module Record containing a top-level await).
318
+ * See [[HasTLA]] in https://tc39.es/ecma262/#sec-cyclic-module-records
319
+ */
320
+ bool HasTopLevelAwait() const;
321
+
322
+ /**
323
+ * Returns whether the module is a SourceTextModule.
324
+ */
325
+ bool IsSourceTextModule() const;
326
+
327
+ /**
328
+ * Returns whether the module is a SyntheticModule.
329
+ */
330
+ bool IsSyntheticModule() const;
331
+
332
+ /*
333
+ * Callback defined in the embedder. This is responsible for setting
334
+ * the module's exported values with calls to SetSyntheticModuleExport().
335
+ * The callback must return a resolved Promise to indicate success (where no
336
+ * exception was thrown) and return an empy MaybeLocal to indicate falure
337
+ * (where an exception was thrown).
338
+ */
339
+ using SyntheticModuleEvaluationSteps =
340
+ MaybeLocal<Value> (*)(Local<Context> context, Local<Module> module);
341
+
342
+ /**
343
+ * Creates a new SyntheticModule with the specified export names, where
344
+ * evaluation_steps will be executed upon module evaluation.
345
+ * export_names must not contain duplicates.
346
+ * module_name is used solely for logging/debugging and doesn't affect module
347
+ * behavior.
348
+ */
349
+ static Local<Module> CreateSyntheticModule(
350
+ Isolate* isolate, Local<String> module_name,
351
+ const MemorySpan<const Local<String>>& export_names,
352
+ SyntheticModuleEvaluationSteps evaluation_steps);
353
+
354
+ /**
355
+ * Set this module's exported value for the name export_name to the specified
356
+ * export_value. This method must be called only on Modules created via
357
+ * CreateSyntheticModule. An error will be thrown if export_name is not one
358
+ * of the export_names that were passed in that CreateSyntheticModule call.
359
+ * Returns Just(true) on success, Nothing<bool>() if an error was thrown.
360
+ */
361
+ V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport(
362
+ Isolate* isolate, Local<String> export_name, Local<Value> export_value);
363
+
364
+ /**
365
+ * Search the modules requested directly or indirectly by the module for
366
+ * any top-level await that has not yet resolved. If there is any, the
367
+ * returned pair of vectors (of equal size) contain the unresolved module
368
+ * and corresponding message with the pending top-level await.
369
+ * An embedder may call this before exiting to improve error messages.
370
+ */
371
+ std::pair<LocalVector<Module>, LocalVector<Message>>
372
+ GetStalledTopLevelAwaitMessages(Isolate* isolate);
373
+
374
+ V8_INLINE static Module* Cast(Data* data);
375
+
376
+ private:
377
+ static void CheckCast(Data* obj);
378
+ };
379
+
380
+ class V8_EXPORT CompileHintsCollector : public Data {
381
+ public:
382
+ /**
383
+ * Returns the positions of lazy functions which were compiled and executed.
384
+ */
385
+ std::vector<int> GetCompileHints(Isolate* isolate) const;
386
+ };
387
+
388
+ /**
389
+ * A compiled JavaScript script, tied to a Context which was active when the
390
+ * script was compiled.
391
+ */
392
+ class V8_EXPORT Script : public Data {
393
+ public:
394
+ /**
395
+ * A shorthand for ScriptCompiler::Compile().
396
+ */
397
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
398
+ Local<Context> context, Local<String> source,
399
+ ScriptOrigin* origin = nullptr);
400
+
401
+ /**
402
+ * Runs the script returning the resulting value. It will be run in the
403
+ * context in which it was created (ScriptCompiler::CompileBound or
404
+ * UnboundScript::BindToCurrentContext()).
405
+ */
406
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
407
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context,
408
+ Local<Data> host_defined_options);
409
+
410
+ /**
411
+ * Returns the corresponding context-unbound script.
412
+ */
413
+ Local<UnboundScript> GetUnboundScript();
414
+
415
+ /**
416
+ * Returns the id of the corresponding context-unbound script.
417
+ */
418
+ int ScriptId() const;
419
+
420
+ /**
421
+ * The name that was passed by the embedder as ResourceName to the
422
+ * ScriptOrigin. This can be either a v8::String or v8::Undefined.
423
+ */
424
+ Local<Value> GetResourceName();
425
+
426
+ /**
427
+ * If the script was compiled, returns the positions of lazy functions which
428
+ * were eventually compiled and executed.
429
+ */
430
+ V8_DEPRECATE_SOON("Use GetCompileHintsCollector instead")
431
+ std::vector<int> GetProducedCompileHints() const;
432
+
433
+ /**
434
+ * Get a compile hints collector object which we can use later for retrieving
435
+ * compile hints (= positions of lazy functions which were compiled and
436
+ * executed).
437
+ */
438
+ Local<CompileHintsCollector> GetCompileHintsCollector() const;
439
+ };
440
+
441
+ enum class ScriptType { kClassic, kModule };
442
+
443
+ /**
444
+ * For compiling scripts.
445
+ */
446
+ class V8_EXPORT ScriptCompiler {
447
+ public:
448
+ class ConsumeCodeCacheTask;
449
+
450
+ /**
451
+ * Compilation data that the embedder can cache and pass back to speed up
452
+ * future compilations. The data is produced if the CompilerOptions passed to
453
+ * the compilation functions in ScriptCompiler contains produce_data_to_cache
454
+ * = true. The data to cache can then can be retrieved from
455
+ * UnboundScript.
456
+ */
457
+ struct V8_EXPORT CachedData {
458
+ enum BufferPolicy { BufferNotOwned, BufferOwned };
459
+
460
+ CachedData()
461
+ : data(nullptr),
462
+ length(0),
463
+ rejected(false),
464
+ buffer_policy(BufferNotOwned) {}
465
+
466
+ // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
467
+ // data and guarantees that it stays alive until the CachedData object is
468
+ // destroyed. If the policy is BufferOwned, the given data will be deleted
469
+ // (with delete[]) when the CachedData object is destroyed.
470
+ CachedData(const uint8_t* data, int length,
471
+ BufferPolicy buffer_policy = BufferNotOwned);
472
+ ~CachedData();
473
+
474
+ enum CompatibilityCheckResult {
475
+ // Don't change order/existing values of this enum since it keys into the
476
+ // `code_cache_reject_reason` histogram. Append-only!
477
+ kSuccess = 0,
478
+ kMagicNumberMismatch = 1,
479
+ kVersionMismatch = 2,
480
+ kSourceMismatch = 3,
481
+ kFlagsMismatch = 5,
482
+ kChecksumMismatch = 6,
483
+ kInvalidHeader = 7,
484
+ kLengthMismatch = 8,
485
+ kReadOnlySnapshotChecksumMismatch = 9,
486
+
487
+ // This should always point at the last real enum value.
488
+ kLast = kReadOnlySnapshotChecksumMismatch
489
+ };
490
+
491
+ // Check if the CachedData can be loaded in the given isolate.
492
+ CompatibilityCheckResult CompatibilityCheck(Isolate* isolate);
493
+
494
+ // TODO(marja): Async compilation; add constructors which take a callback
495
+ // which will be called when V8 no longer needs the data.
496
+ const uint8_t* data;
497
+ int length;
498
+ bool rejected;
499
+ BufferPolicy buffer_policy;
500
+
501
+ // Prevent copying.
502
+ CachedData(const CachedData&) = delete;
503
+ CachedData& operator=(const CachedData&) = delete;
504
+ };
505
+
506
+ enum class InMemoryCacheResult {
507
+ // V8 did not attempt to find this script in its in-memory cache.
508
+ kNotAttempted,
509
+
510
+ // V8 found a previously compiled copy of this script in its in-memory
511
+ // cache. Any data generated by a streaming compilation or background
512
+ // deserialization was abandoned.
513
+ kHit,
514
+
515
+ // V8 didn't have any previously compiled data for this script.
516
+ kMiss,
517
+
518
+ // V8 had some previously compiled data for an identical script, but the
519
+ // data was incomplete.
520
+ kPartial,
521
+ };
522
+
523
+ // Details about what happened during a compilation.
524
+ struct CompilationDetails {
525
+ InMemoryCacheResult in_memory_cache_result =
526
+ InMemoryCacheResult::kNotAttempted;
527
+
528
+ static constexpr int64_t kTimeNotMeasured = -1;
529
+ int64_t foreground_time_in_microseconds = kTimeNotMeasured;
530
+ int64_t background_time_in_microseconds = kTimeNotMeasured;
531
+ };
532
+
533
+ /**
534
+ * Source code which can be then compiled to a UnboundScript or Script.
535
+ */
536
+ class Source {
537
+ public:
538
+ // Source takes ownership of both CachedData and CodeCacheConsumeTask.
539
+ // The caller *must* ensure that the cached data is from a trusted source.
540
+ V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
541
+ CachedData* cached_data = nullptr,
542
+ ConsumeCodeCacheTask* consume_cache_task = nullptr);
543
+ // Source takes ownership of both CachedData and CodeCacheConsumeTask.
544
+ V8_INLINE explicit Source(
545
+ Local<String> source_string, CachedData* cached_data = nullptr,
546
+ ConsumeCodeCacheTask* consume_cache_task = nullptr);
547
+ V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
548
+ CompileHintCallback callback, void* callback_data);
549
+ V8_INLINE ~Source() = default;
550
+
551
+ // Ownership of the CachedData or its buffers is *not* transferred to the
552
+ // caller. The CachedData object is alive as long as the Source object is
553
+ // alive.
554
+ V8_INLINE const CachedData* GetCachedData() const;
555
+
556
+ V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
557
+
558
+ V8_INLINE const CompilationDetails& GetCompilationDetails() const;
559
+
560
+ private:
561
+ friend class ScriptCompiler;
562
+
563
+ Local<String> source_string;
564
+
565
+ // Origin information
566
+ Local<Value> resource_name;
567
+ int resource_line_offset = -1;
568
+ int resource_column_offset = -1;
569
+ ScriptOriginOptions resource_options;
570
+ Local<Value> source_map_url;
571
+ Local<Data> host_defined_options;
572
+
573
+ // Cached data from previous compilation (if a kConsume*Cache flag is
574
+ // set), or hold newly generated cache data (kProduce*Cache flags) are
575
+ // set when calling a compile method.
576
+ std::unique_ptr<CachedData> cached_data;
577
+ std::unique_ptr<ConsumeCodeCacheTask> consume_cache_task;
578
+
579
+ // For requesting compile hints from the embedder.
580
+ CompileHintCallback compile_hint_callback = nullptr;
581
+ void* compile_hint_callback_data = nullptr;
582
+
583
+ // V8 writes this data and never reads it. It exists only to be informative
584
+ // to the embedder.
585
+ CompilationDetails compilation_details;
586
+ };
587
+
588
+ /**
589
+ * For streaming incomplete script data to V8. The embedder should implement a
590
+ * subclass of this class.
591
+ */
592
+ class V8_EXPORT ExternalSourceStream {
593
+ public:
594
+ virtual ~ExternalSourceStream() = default;
595
+
596
+ /**
597
+ * V8 calls this to request the next chunk of data from the embedder. This
598
+ * function will be called on a background thread, so it's OK to block and
599
+ * wait for the data, if the embedder doesn't have data yet. Returns the
600
+ * length of the data returned. When the data ends, GetMoreData should
601
+ * return 0. Caller takes ownership of the data.
602
+ *
603
+ * When streaming UTF-8 data, V8 handles multi-byte characters split between
604
+ * two data chunks, but doesn't handle multi-byte characters split between
605
+ * more than two data chunks. The embedder can avoid this problem by always
606
+ * returning at least 2 bytes of data.
607
+ *
608
+ * When streaming UTF-16 data, V8 does not handle characters split between
609
+ * two data chunks. The embedder has to make sure that chunks have an even
610
+ * length.
611
+ *
612
+ * If the embedder wants to cancel the streaming, they should make the next
613
+ * GetMoreData call return 0. V8 will interpret it as end of data (and most
614
+ * probably, parsing will fail). The streaming task will return as soon as
615
+ * V8 has parsed the data it received so far.
616
+ */
617
+ virtual size_t GetMoreData(const uint8_t** src) = 0;
618
+ };
619
+
620
+ /**
621
+ * Source code which can be streamed into V8 in pieces. It will be parsed
622
+ * while streaming and compiled after parsing has completed. StreamedSource
623
+ * must be kept alive while the streaming task is run (see ScriptStreamingTask
624
+ * below).
625
+ */
626
+ class V8_EXPORT StreamedSource {
627
+ public:
628
+ enum Encoding { ONE_BYTE, TWO_BYTE, UTF8, WINDOWS_1252 };
629
+
630
+ StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream,
631
+ Encoding encoding);
632
+ ~StreamedSource();
633
+
634
+ internal::ScriptStreamingData* impl() const { return impl_.get(); }
635
+
636
+ // Prevent copying.
637
+ StreamedSource(const StreamedSource&) = delete;
638
+ StreamedSource& operator=(const StreamedSource&) = delete;
639
+
640
+ CompilationDetails& compilation_details() { return compilation_details_; }
641
+
642
+ private:
643
+ std::unique_ptr<internal::ScriptStreamingData> impl_;
644
+
645
+ // V8 writes this data and never reads it. It exists only to be informative
646
+ // to the embedder.
647
+ CompilationDetails compilation_details_;
648
+ };
649
+
650
+ /**
651
+ * A streaming task which the embedder must run on a background thread to
652
+ * stream scripts into V8. Returned by ScriptCompiler::StartStreaming.
653
+ */
654
+ class V8_EXPORT ScriptStreamingTask final {
655
+ public:
656
+ void Run();
657
+
658
+ private:
659
+ friend class ScriptCompiler;
660
+
661
+ explicit ScriptStreamingTask(internal::ScriptStreamingData* data)
662
+ : data_(data) {}
663
+
664
+ internal::ScriptStreamingData* data_;
665
+ };
666
+
667
+ /**
668
+ * A task which the embedder must run on a background thread to
669
+ * consume a V8 code cache. Returned by
670
+ * ScriptCompiler::StartConsumingCodeCache.
671
+ */
672
+ class V8_EXPORT ConsumeCodeCacheTask final {
673
+ public:
674
+ ~ConsumeCodeCacheTask();
675
+
676
+ void Run();
677
+
678
+ /**
679
+ * Provides the source text string and origin information to the consumption
680
+ * task. May be called before, during, or after Run(). This step checks
681
+ * whether the script matches an existing script in the Isolate's
682
+ * compilation cache. To check whether such a script was found, call
683
+ * ShouldMergeWithExistingScript.
684
+ *
685
+ * The Isolate provided must be the same one used during
686
+ * StartConsumingCodeCache and must be currently entered on the thread that
687
+ * calls this function. The source text and origin provided in this step
688
+ * must precisely match those used later in the ScriptCompiler::Source that
689
+ * will contain this ConsumeCodeCacheTask.
690
+ */
691
+ void SourceTextAvailable(Isolate* isolate, Local<String> source_text,
692
+ const ScriptOrigin& origin);
693
+
694
+ /**
695
+ * Returns whether the embedder should call MergeWithExistingScript. This
696
+ * function may be called from any thread, any number of times, but its
697
+ * return value is only meaningful after SourceTextAvailable has completed.
698
+ */
699
+ bool ShouldMergeWithExistingScript() const;
700
+
701
+ /**
702
+ * Merges newly deserialized data into an existing script which was found
703
+ * during SourceTextAvailable. May be called only after Run() has completed.
704
+ * Can execute on any thread, like Run().
705
+ */
706
+ void MergeWithExistingScript();
707
+
708
+ private:
709
+ friend class ScriptCompiler;
710
+
711
+ explicit ConsumeCodeCacheTask(
712
+ std::unique_ptr<internal::BackgroundDeserializeTask> impl);
713
+
714
+ std::unique_ptr<internal::BackgroundDeserializeTask> impl_;
715
+ };
716
+
717
+ enum CompileOptions {
718
+ kNoCompileOptions = 0,
719
+ kConsumeCodeCache = 1 << 0,
720
+ kEagerCompile = 1 << 1,
721
+ kProduceCompileHints = 1 << 2,
722
+ kConsumeCompileHints = 1 << 3,
723
+ kFollowCompileHintsMagicComment = 1 << 4,
724
+ kFollowCompileHintsPerFunctionMagicComment = 1 << 5,
725
+ };
726
+
727
+ static inline bool CompileOptionsIsValid(CompileOptions compile_options) {
728
+ // kConsumeCodeCache is mutually exclusive with all other flag bits.
729
+ if ((compile_options & kConsumeCodeCache) &&
730
+ compile_options != kConsumeCodeCache) {
731
+ return false;
732
+ }
733
+ // kEagerCompile is mutually exclusive with all other flag bits.
734
+ if ((compile_options & kEagerCompile) && compile_options != kEagerCompile) {
735
+ return false;
736
+ }
737
+ // We don't currently support producing and consuming compile hints at the
738
+ // same time.
739
+ constexpr int produce_and_consume = CompileOptions::kProduceCompileHints |
740
+ CompileOptions::kConsumeCompileHints;
741
+ if ((compile_options & produce_and_consume) == produce_and_consume) {
742
+ return false;
743
+ }
744
+ return true;
745
+ }
746
+
747
+ /**
748
+ * The reason for which we are not requesting or providing a code cache.
749
+ */
750
+ enum NoCacheReason {
751
+ kNoCacheNoReason = 0,
752
+ kNoCacheBecauseCachingDisabled,
753
+ kNoCacheBecauseNoResource,
754
+ kNoCacheBecauseInlineScript,
755
+ kNoCacheBecauseModule,
756
+ kNoCacheBecauseStreamingSource,
757
+ kNoCacheBecauseInspector,
758
+ kNoCacheBecauseScriptTooSmall,
759
+ kNoCacheBecauseCacheTooCold,
760
+ kNoCacheBecauseV8Extension,
761
+ kNoCacheBecauseExtensionModule,
762
+ kNoCacheBecausePacScript,
763
+ kNoCacheBecauseInDocumentWrite,
764
+ kNoCacheBecauseResourceWithNoCacheHandler,
765
+ kNoCacheBecauseDeferredProduceCodeCache,
766
+ kNoCacheBecauseStaticCodeCache,
767
+ };
768
+
769
+ /**
770
+ * Compiles the specified script (context-independent).
771
+ * Cached data as part of the source object can be optionally produced to be
772
+ * consumed later to speed up compilation of identical source scripts.
773
+ *
774
+ * Note that when producing cached data, the source must point to NULL for
775
+ * cached data. When consuming cached data, the cached data must have been
776
+ * produced by the same version of V8, and the embedder needs to ensure the
777
+ * cached data is the correct one for the given script.
778
+ *
779
+ * \param source Script source code.
780
+ * \return Compiled script object (context independent; for running it must be
781
+ * bound to a context).
782
+ */
783
+ static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
784
+ Isolate* isolate, Source* source,
785
+ CompileOptions options = kNoCompileOptions,
786
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
787
+
788
+ /**
789
+ * Compiles the specified script (bound to current context).
790
+ *
791
+ * \param source Script source code.
792
+ * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
793
+ * using pre_data speeds compilation if it's done multiple times.
794
+ * Owned by caller, no references are kept when this function returns.
795
+ * \return Compiled script object, bound to the context that was active
796
+ * when this function was called. When run it will always use this
797
+ * context.
798
+ */
799
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
800
+ Local<Context> context, Source* source,
801
+ CompileOptions options = kNoCompileOptions,
802
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
803
+
804
+ /**
805
+ * Returns a task which streams script data into V8, or NULL if the script
806
+ * cannot be streamed. The user is responsible for running the task on a
807
+ * background thread and deleting it. When ran, the task starts parsing the
808
+ * script, and it will request data from the StreamedSource as needed. When
809
+ * ScriptStreamingTask::Run exits, all data has been streamed and the script
810
+ * can be compiled (see Compile below).
811
+ *
812
+ * This API allows to start the streaming with as little data as possible, and
813
+ * the remaining data (for example, the ScriptOrigin) is passed to Compile.
814
+ */
815
+ static ScriptStreamingTask* StartStreaming(
816
+ Isolate* isolate, StreamedSource* source,
817
+ ScriptType type = ScriptType::kClassic,
818
+ CompileOptions options = kNoCompileOptions,
819
+ CompileHintCallback compile_hint_callback = nullptr,
820
+ void* compile_hint_callback_data = nullptr);
821
+
822
+ static ConsumeCodeCacheTask* StartConsumingCodeCache(
823
+ Isolate* isolate, std::unique_ptr<CachedData> source);
824
+ static ConsumeCodeCacheTask* StartConsumingCodeCacheOnBackground(
825
+ Isolate* isolate, std::unique_ptr<CachedData> source);
826
+
827
+ /**
828
+ * Compiles a streamed script (bound to current context).
829
+ *
830
+ * This can only be called after the streaming has finished
831
+ * (ScriptStreamingTask has been run). V8 doesn't construct the source string
832
+ * during streaming, so the embedder needs to pass the full source here.
833
+ */
834
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
835
+ Local<Context> context, StreamedSource* source,
836
+ Local<String> full_source_string, const ScriptOrigin& origin);
837
+
838
+ /**
839
+ * Return a version tag for CachedData for the current V8 version & flags.
840
+ *
841
+ * This value is meant only for determining whether a previously generated
842
+ * CachedData instance is still valid; the tag has no other meaing.
843
+ *
844
+ * Background: The data carried by CachedData may depend on the exact
845
+ * V8 version number or current compiler flags. This means that when
846
+ * persisting CachedData, the embedder must take care to not pass in
847
+ * data from another V8 version, or the same version with different
848
+ * features enabled.
849
+ *
850
+ * The easiest way to do so is to clear the embedder's cache on any
851
+ * such change.
852
+ *
853
+ * Alternatively, this tag can be stored alongside the cached data and
854
+ * compared when it is being used.
855
+ */
856
+ static uint32_t CachedDataVersionTag();
857
+
858
+ /**
859
+ * Compile an ES module, returning a Module that encapsulates
860
+ * the compiled code.
861
+ *
862
+ * Corresponds to the ParseModule abstract operation in the
863
+ * ECMAScript specification.
864
+ */
865
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
866
+ Isolate* isolate, Source* source,
867
+ CompileOptions options = kNoCompileOptions,
868
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
869
+
870
+ /**
871
+ * Compiles a streamed module script.
872
+ *
873
+ * This can only be called after the streaming has finished
874
+ * (ScriptStreamingTask has been run). V8 doesn't construct the source string
875
+ * during streaming, so the embedder needs to pass the full source here.
876
+ */
877
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
878
+ Local<Context> context, StreamedSource* v8_source,
879
+ Local<String> full_source_string, const ScriptOrigin& origin);
880
+
881
+ /**
882
+ * Compile a function for a given context. This is equivalent to running
883
+ *
884
+ * with (obj) {
885
+ * return function(args) { ... }
886
+ * }
887
+ *
888
+ * It is possible to specify multiple context extensions (obj in the above
889
+ * example).
890
+ */
891
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunction(
892
+ Local<Context> context, Source* source, size_t arguments_count = 0,
893
+ Local<String> arguments[] = nullptr, size_t context_extension_count = 0,
894
+ Local<Object> context_extensions[] = nullptr,
895
+ CompileOptions options = kNoCompileOptions,
896
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
897
+
898
+ /**
899
+ * Creates and returns code cache for the specified unbound_script.
900
+ * This will return nullptr if the script cannot be serialized. The
901
+ * CachedData returned by this function should be owned by the caller.
902
+ */
903
+ static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
904
+
905
+ /**
906
+ * Creates and returns code cache for the specified unbound_module_script.
907
+ * This will return nullptr if the script cannot be serialized. The
908
+ * CachedData returned by this function should be owned by the caller.
909
+ */
910
+ static CachedData* CreateCodeCache(
911
+ Local<UnboundModuleScript> unbound_module_script);
912
+
913
+ /**
914
+ * Creates and returns code cache for the specified function that was
915
+ * previously produced by CompileFunction.
916
+ * This will return nullptr if the script cannot be serialized. The
917
+ * CachedData returned by this function should be owned by the caller.
918
+ */
919
+ static CachedData* CreateCodeCacheForFunction(Local<Function> function);
920
+
921
+ private:
922
+ static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
923
+ Isolate* isolate, Source* source, CompileOptions options,
924
+ NoCacheReason no_cache_reason);
925
+
926
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInternal(
927
+ Local<Context> context, Source* source, size_t arguments_count,
928
+ Local<String> arguments[], size_t context_extension_count,
929
+ Local<Object> context_extensions[], CompileOptions options,
930
+ NoCacheReason no_cache_reason,
931
+ Local<ScriptOrModule>* script_or_module_out);
932
+ };
933
+
934
+ ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
935
+ CachedData* data,
936
+ ConsumeCodeCacheTask* consume_cache_task)
937
+ : source_string(string),
938
+ resource_name(origin.ResourceName()),
939
+ resource_line_offset(origin.LineOffset()),
940
+ resource_column_offset(origin.ColumnOffset()),
941
+ resource_options(origin.Options()),
942
+ source_map_url(origin.SourceMapUrl()),
943
+ host_defined_options(origin.GetHostDefinedOptions()),
944
+ cached_data(data),
945
+ consume_cache_task(consume_cache_task) {}
946
+
947
+ ScriptCompiler::Source::Source(Local<String> string, CachedData* data,
948
+ ConsumeCodeCacheTask* consume_cache_task)
949
+ : source_string(string),
950
+ cached_data(data),
951
+ consume_cache_task(consume_cache_task) {}
952
+
953
+ ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
954
+ CompileHintCallback callback,
955
+ void* callback_data)
956
+ : source_string(string),
957
+ resource_name(origin.ResourceName()),
958
+ resource_line_offset(origin.LineOffset()),
959
+ resource_column_offset(origin.ColumnOffset()),
960
+ resource_options(origin.Options()),
961
+ source_map_url(origin.SourceMapUrl()),
962
+ host_defined_options(origin.GetHostDefinedOptions()),
963
+ compile_hint_callback(callback),
964
+ compile_hint_callback_data(callback_data) {}
965
+
966
+ const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
967
+ const {
968
+ return cached_data.get();
969
+ }
970
+
971
+ const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
972
+ return resource_options;
973
+ }
974
+
975
+ const ScriptCompiler::CompilationDetails&
976
+ ScriptCompiler::Source::GetCompilationDetails() const {
977
+ return compilation_details;
978
+ }
979
+
980
+ ModuleRequest* ModuleRequest::Cast(Data* data) {
981
+ #ifdef V8_ENABLE_CHECKS
982
+ CheckCast(data);
983
+ #endif
984
+ return reinterpret_cast<ModuleRequest*>(data);
985
+ }
986
+
987
+ Module* Module::Cast(Data* data) {
988
+ #ifdef V8_ENABLE_CHECKS
989
+ CheckCast(data);
990
+ #endif
991
+ return reinterpret_cast<Module*>(data);
992
+ }
993
+
994
+ } // namespace v8
995
+
996
+ #endif // INCLUDE_V8_SCRIPT_H_