@babylonjs/v8-android-jit-nointl-nosnapshot 11.110.1

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 (126) hide show
  1. package/dist/include/APIDesign.md +72 -0
  2. package/dist/include/DEPS +10 -0
  3. package/dist/include/DIR_METADATA +11 -0
  4. package/dist/include/OWNERS +23 -0
  5. package/dist/include/cppgc/DEPS +8 -0
  6. package/dist/include/cppgc/OWNERS +2 -0
  7. package/dist/include/cppgc/README.md +135 -0
  8. package/dist/include/cppgc/allocation.h +310 -0
  9. package/dist/include/cppgc/common.h +28 -0
  10. package/dist/include/cppgc/cross-thread-persistent.h +464 -0
  11. package/dist/include/cppgc/custom-space.h +97 -0
  12. package/dist/include/cppgc/default-platform.h +67 -0
  13. package/dist/include/cppgc/ephemeron-pair.h +30 -0
  14. package/dist/include/cppgc/explicit-management.h +100 -0
  15. package/dist/include/cppgc/garbage-collected.h +106 -0
  16. package/dist/include/cppgc/heap-consistency.h +309 -0
  17. package/dist/include/cppgc/heap-handle.h +48 -0
  18. package/dist/include/cppgc/heap-state.h +82 -0
  19. package/dist/include/cppgc/heap-statistics.h +120 -0
  20. package/dist/include/cppgc/heap.h +202 -0
  21. package/dist/include/cppgc/internal/api-constants.h +65 -0
  22. package/dist/include/cppgc/internal/atomic-entry-flag.h +48 -0
  23. package/dist/include/cppgc/internal/base-page-handle.h +45 -0
  24. package/dist/include/cppgc/internal/caged-heap-local-data.h +111 -0
  25. package/dist/include/cppgc/internal/caged-heap.h +61 -0
  26. package/dist/include/cppgc/internal/compiler-specific.h +38 -0
  27. package/dist/include/cppgc/internal/finalizer-trait.h +93 -0
  28. package/dist/include/cppgc/internal/gc-info.h +155 -0
  29. package/dist/include/cppgc/internal/logging.h +50 -0
  30. package/dist/include/cppgc/internal/member-storage.h +236 -0
  31. package/dist/include/cppgc/internal/name-trait.h +137 -0
  32. package/dist/include/cppgc/internal/persistent-node.h +214 -0
  33. package/dist/include/cppgc/internal/pointer-policies.h +207 -0
  34. package/dist/include/cppgc/internal/write-barrier.h +477 -0
  35. package/dist/include/cppgc/liveness-broker.h +78 -0
  36. package/dist/include/cppgc/macros.h +26 -0
  37. package/dist/include/cppgc/member.h +566 -0
  38. package/dist/include/cppgc/name-provider.h +65 -0
  39. package/dist/include/cppgc/object-size-trait.h +58 -0
  40. package/dist/include/cppgc/persistent.h +366 -0
  41. package/dist/include/cppgc/platform.h +158 -0
  42. package/dist/include/cppgc/prefinalizer.h +75 -0
  43. package/dist/include/cppgc/process-heap-statistics.h +36 -0
  44. package/dist/include/cppgc/sentinel-pointer.h +32 -0
  45. package/dist/include/cppgc/source-location.h +92 -0
  46. package/dist/include/cppgc/testing.h +106 -0
  47. package/dist/include/cppgc/trace-trait.h +120 -0
  48. package/dist/include/cppgc/type-traits.h +249 -0
  49. package/dist/include/cppgc/visitor.h +411 -0
  50. package/dist/include/js_protocol-1.2.json +997 -0
  51. package/dist/include/js_protocol-1.3.json +1159 -0
  52. package/dist/include/js_protocol.pdl +1766 -0
  53. package/dist/include/libplatform/DEPS +9 -0
  54. package/dist/include/libplatform/libplatform-export.h +29 -0
  55. package/dist/include/libplatform/libplatform.h +106 -0
  56. package/dist/include/libplatform/v8-tracing.h +333 -0
  57. package/dist/include/v8-array-buffer.h +512 -0
  58. package/dist/include/v8-callbacks.h +412 -0
  59. package/dist/include/v8-container.h +129 -0
  60. package/dist/include/v8-context.h +415 -0
  61. package/dist/include/v8-cppgc.h +231 -0
  62. package/dist/include/v8-data.h +80 -0
  63. package/dist/include/v8-date.h +48 -0
  64. package/dist/include/v8-debug.h +168 -0
  65. package/dist/include/v8-embedder-heap.h +223 -0
  66. package/dist/include/v8-embedder-state-scope.h +51 -0
  67. package/dist/include/v8-exception.h +217 -0
  68. package/dist/include/v8-extension.h +62 -0
  69. package/dist/include/v8-external.h +37 -0
  70. package/dist/include/v8-fast-api-calls.h +957 -0
  71. package/dist/include/v8-forward.h +81 -0
  72. package/dist/include/v8-function-callback.h +475 -0
  73. package/dist/include/v8-function.h +133 -0
  74. package/dist/include/v8-initialization.h +289 -0
  75. package/dist/include/v8-inspector-protocol.h +13 -0
  76. package/dist/include/v8-inspector.h +397 -0
  77. package/dist/include/v8-internal.h +851 -0
  78. package/dist/include/v8-isolate.h +1695 -0
  79. package/dist/include/v8-json.h +47 -0
  80. package/dist/include/v8-local-handle.h +455 -0
  81. package/dist/include/v8-locker.h +138 -0
  82. package/dist/include/v8-maybe.h +160 -0
  83. package/dist/include/v8-memory-span.h +43 -0
  84. package/dist/include/v8-message.h +214 -0
  85. package/dist/include/v8-metrics.h +311 -0
  86. package/dist/include/v8-microtask-queue.h +157 -0
  87. package/dist/include/v8-microtask.h +28 -0
  88. package/dist/include/v8-object.h +768 -0
  89. package/dist/include/v8-persistent-handle.h +588 -0
  90. package/dist/include/v8-platform.h +1130 -0
  91. package/dist/include/v8-primitive-object.h +118 -0
  92. package/dist/include/v8-primitive.h +866 -0
  93. package/dist/include/v8-profiler.h +1277 -0
  94. package/dist/include/v8-promise.h +174 -0
  95. package/dist/include/v8-proxy.h +50 -0
  96. package/dist/include/v8-regexp.h +106 -0
  97. package/dist/include/v8-script.h +803 -0
  98. package/dist/include/v8-snapshot.h +196 -0
  99. package/dist/include/v8-statistics.h +217 -0
  100. package/dist/include/v8-template.h +1018 -0
  101. package/dist/include/v8-traced-handle.h +420 -0
  102. package/dist/include/v8-typed-array.h +282 -0
  103. package/dist/include/v8-unwinder-state.h +31 -0
  104. package/dist/include/v8-unwinder.h +132 -0
  105. package/dist/include/v8-util.h +656 -0
  106. package/dist/include/v8-value-serializer-version.h +24 -0
  107. package/dist/include/v8-value-serializer.h +302 -0
  108. package/dist/include/v8-value.h +531 -0
  109. package/dist/include/v8-version-string.h +38 -0
  110. package/dist/include/v8-version.h +20 -0
  111. package/dist/include/v8-wasm-trap-handler-posix.h +31 -0
  112. package/dist/include/v8-wasm-trap-handler-win.h +28 -0
  113. package/dist/include/v8-wasm.h +200 -0
  114. package/dist/include/v8-weak-callback-info.h +80 -0
  115. package/dist/include/v8.h +88 -0
  116. package/dist/include/v8config.h +904 -0
  117. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar +0 -0
  118. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar.md5 +1 -0
  119. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar.sha1 +1 -0
  120. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom +10 -0
  121. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom.md5 +1 -0
  122. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom.sha1 +1 -0
  123. package/dist/org/chromium/v8-android/maven-metadata.xml +12 -0
  124. package/dist/org/chromium/v8-android/maven-metadata.xml.md5 +1 -0
  125. package/dist/org/chromium/v8-android/maven-metadata.xml.sha1 +1 -0
  126. package/package.json +24 -0
@@ -0,0 +1,803 @@
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 <vector>
13
+
14
+ #include "v8-data.h" // NOLINT(build/include_directory)
15
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
16
+ #include "v8-maybe.h" // NOLINT(build/include_directory)
17
+ #include "v8-message.h" // NOLINT(build/include_directory)
18
+ #include "v8config.h" // NOLINT(build/include_directory)
19
+
20
+ namespace v8 {
21
+
22
+ class Function;
23
+ class Message;
24
+ class Object;
25
+ class PrimitiveArray;
26
+ class Script;
27
+
28
+ namespace internal {
29
+ class BackgroundDeserializeTask;
30
+ struct ScriptStreamingData;
31
+ } // namespace internal
32
+
33
+ /**
34
+ * A container type that holds relevant metadata for module loading.
35
+ *
36
+ * This is passed back to the embedder as part of
37
+ * HostImportModuleDynamicallyCallback for module loading.
38
+ */
39
+ class V8_EXPORT ScriptOrModule {
40
+ public:
41
+ /**
42
+ * The name that was passed by the embedder as ResourceName to the
43
+ * ScriptOrigin. This can be either a v8::String or v8::Undefined.
44
+ */
45
+ Local<Value> GetResourceName();
46
+
47
+ /**
48
+ * The options that were passed by the embedder as HostDefinedOptions to
49
+ * the ScriptOrigin.
50
+ */
51
+ Local<Data> HostDefinedOptions();
52
+ };
53
+
54
+ /**
55
+ * A compiled JavaScript script, not yet tied to a Context.
56
+ */
57
+ class V8_EXPORT UnboundScript {
58
+ public:
59
+ /**
60
+ * Binds the script to the currently entered context.
61
+ */
62
+ Local<Script> BindToCurrentContext();
63
+
64
+ int GetId() const;
65
+ Local<Value> GetScriptName();
66
+
67
+ /**
68
+ * Data read from magic sourceURL comments.
69
+ */
70
+ Local<Value> GetSourceURL();
71
+ /**
72
+ * Data read from magic sourceMappingURL comments.
73
+ */
74
+ Local<Value> GetSourceMappingURL();
75
+
76
+ /**
77
+ * Returns zero based line number of the code_pos location in the script.
78
+ * -1 will be returned if no information available.
79
+ */
80
+ int GetLineNumber(int code_pos = 0);
81
+
82
+ /**
83
+ * Returns zero based column number of the code_pos location in the script.
84
+ * -1 will be returned if no information available.
85
+ */
86
+ int GetColumnNumber(int code_pos = 0);
87
+
88
+ static const int kNoScriptId = 0;
89
+ };
90
+
91
+ /**
92
+ * A compiled JavaScript module, not yet tied to a Context.
93
+ */
94
+ class V8_EXPORT UnboundModuleScript : public Data {
95
+ public:
96
+ /**
97
+ * Data read from magic sourceURL comments.
98
+ */
99
+ Local<Value> GetSourceURL();
100
+ /**
101
+ * Data read from magic sourceMappingURL comments.
102
+ */
103
+ Local<Value> GetSourceMappingURL();
104
+ };
105
+
106
+ /**
107
+ * A location in JavaScript source.
108
+ */
109
+ class V8_EXPORT Location {
110
+ public:
111
+ int GetLineNumber() { return line_number_; }
112
+ int GetColumnNumber() { return column_number_; }
113
+
114
+ Location(int line_number, int column_number)
115
+ : line_number_(line_number), column_number_(column_number) {}
116
+
117
+ private:
118
+ int line_number_;
119
+ int column_number_;
120
+ };
121
+
122
+ class V8_EXPORT ModuleRequest : public Data {
123
+ public:
124
+ /**
125
+ * Returns the module specifier for this ModuleRequest.
126
+ */
127
+ Local<String> GetSpecifier() const;
128
+
129
+ /**
130
+ * Returns the source code offset of this module request.
131
+ * Use Module::SourceOffsetToLocation to convert this to line/column numbers.
132
+ */
133
+ int GetSourceOffset() const;
134
+
135
+ /**
136
+ * Contains the import assertions for this request in the form:
137
+ * [key1, value1, source_offset1, key2, value2, source_offset2, ...].
138
+ * The keys and values are of type v8::String, and the source offsets are of
139
+ * type Int32. Use Module::SourceOffsetToLocation to convert the source
140
+ * offsets to Locations with line/column numbers.
141
+ *
142
+ * All assertions present in the module request will be supplied in this
143
+ * list, regardless of whether they are supported by the host. Per
144
+ * https://tc39.es/proposal-import-assertions/#sec-hostgetsupportedimportassertions,
145
+ * hosts are expected to ignore assertions that they do not support (as
146
+ * opposed to, for example, triggering an error if an unsupported assertion is
147
+ * present).
148
+ */
149
+ Local<FixedArray> GetImportAssertions() const;
150
+
151
+ V8_INLINE static ModuleRequest* Cast(Data* data);
152
+
153
+ private:
154
+ static void CheckCast(Data* obj);
155
+ };
156
+
157
+ /**
158
+ * A compiled JavaScript module.
159
+ */
160
+ class V8_EXPORT Module : public Data {
161
+ public:
162
+ /**
163
+ * The different states a module can be in.
164
+ *
165
+ * This corresponds to the states used in ECMAScript except that "evaluated"
166
+ * is split into kEvaluated and kErrored, indicating success and failure,
167
+ * respectively.
168
+ */
169
+ enum Status {
170
+ kUninstantiated,
171
+ kInstantiating,
172
+ kInstantiated,
173
+ kEvaluating,
174
+ kEvaluated,
175
+ kErrored
176
+ };
177
+
178
+ /**
179
+ * Returns the module's current status.
180
+ */
181
+ Status GetStatus() const;
182
+
183
+ /**
184
+ * For a module in kErrored status, this returns the corresponding exception.
185
+ */
186
+ Local<Value> GetException() const;
187
+
188
+ /**
189
+ * Returns the ModuleRequests for this module.
190
+ */
191
+ Local<FixedArray> GetModuleRequests() const;
192
+
193
+ /**
194
+ * For the given source text offset in this module, returns the corresponding
195
+ * Location with line and column numbers.
196
+ */
197
+ Location SourceOffsetToLocation(int offset) const;
198
+
199
+ /**
200
+ * Returns the identity hash for this object.
201
+ */
202
+ int GetIdentityHash() const;
203
+
204
+ using ResolveModuleCallback = MaybeLocal<Module> (*)(
205
+ Local<Context> context, Local<String> specifier,
206
+ Local<FixedArray> import_assertions, Local<Module> referrer);
207
+
208
+ /**
209
+ * Instantiates the module and its dependencies.
210
+ *
211
+ * Returns an empty Maybe<bool> if an exception occurred during
212
+ * instantiation. (In the case where the callback throws an exception, that
213
+ * exception is propagated.)
214
+ */
215
+ V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(
216
+ Local<Context> context, ResolveModuleCallback callback);
217
+
218
+ /**
219
+ * Evaluates the module and its dependencies.
220
+ *
221
+ * If status is kInstantiated, run the module's code and return a Promise
222
+ * object. On success, set status to kEvaluated and resolve the Promise with
223
+ * the completion value; on failure, set status to kErrored and reject the
224
+ * Promise with the error.
225
+ *
226
+ * If IsGraphAsync() is false, the returned Promise is settled.
227
+ */
228
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
229
+
230
+ /**
231
+ * Returns the namespace object of this module.
232
+ *
233
+ * The module's status must be at least kInstantiated.
234
+ */
235
+ Local<Value> GetModuleNamespace();
236
+
237
+ /**
238
+ * Returns the corresponding context-unbound module script.
239
+ *
240
+ * The module must be unevaluated, i.e. its status must not be kEvaluating,
241
+ * kEvaluated or kErrored.
242
+ */
243
+ Local<UnboundModuleScript> GetUnboundModuleScript();
244
+
245
+ /**
246
+ * Returns the underlying script's id.
247
+ *
248
+ * The module must be a SourceTextModule and must not have a kErrored status.
249
+ */
250
+ int ScriptId() const;
251
+
252
+ /**
253
+ * Returns whether this module or any of its requested modules is async,
254
+ * i.e. contains top-level await.
255
+ *
256
+ * The module's status must be at least kInstantiated.
257
+ */
258
+ bool IsGraphAsync() const;
259
+
260
+ /**
261
+ * Returns whether the module is a SourceTextModule.
262
+ */
263
+ bool IsSourceTextModule() const;
264
+
265
+ /**
266
+ * Returns whether the module is a SyntheticModule.
267
+ */
268
+ bool IsSyntheticModule() const;
269
+
270
+ /*
271
+ * Callback defined in the embedder. This is responsible for setting
272
+ * the module's exported values with calls to SetSyntheticModuleExport().
273
+ * The callback must return a resolved Promise to indicate success (where no
274
+ * exception was thrown) and return an empy MaybeLocal to indicate falure
275
+ * (where an exception was thrown).
276
+ */
277
+ using SyntheticModuleEvaluationSteps =
278
+ MaybeLocal<Value> (*)(Local<Context> context, Local<Module> module);
279
+
280
+ /**
281
+ * Creates a new SyntheticModule with the specified export names, where
282
+ * evaluation_steps will be executed upon module evaluation.
283
+ * export_names must not contain duplicates.
284
+ * module_name is used solely for logging/debugging and doesn't affect module
285
+ * behavior.
286
+ */
287
+ static Local<Module> CreateSyntheticModule(
288
+ Isolate* isolate, Local<String> module_name,
289
+ const std::vector<Local<String>>& export_names,
290
+ SyntheticModuleEvaluationSteps evaluation_steps);
291
+
292
+ /**
293
+ * Set this module's exported value for the name export_name to the specified
294
+ * export_value. This method must be called only on Modules created via
295
+ * CreateSyntheticModule. An error will be thrown if export_name is not one
296
+ * of the export_names that were passed in that CreateSyntheticModule call.
297
+ * Returns Just(true) on success, Nothing<bool>() if an error was thrown.
298
+ */
299
+ V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport(
300
+ Isolate* isolate, Local<String> export_name, Local<Value> export_value);
301
+
302
+ /**
303
+ * Search the modules requested directly or indirectly by the module for
304
+ * any top-level await that has not yet resolved. If there is any, the
305
+ * returned vector contains a tuple of the unresolved module and a message
306
+ * with the pending top-level await.
307
+ * An embedder may call this before exiting to improve error messages.
308
+ */
309
+ std::vector<std::tuple<Local<Module>, Local<Message>>>
310
+ GetStalledTopLevelAwaitMessage(Isolate* isolate);
311
+
312
+ V8_INLINE static Module* Cast(Data* data);
313
+
314
+ private:
315
+ static void CheckCast(Data* obj);
316
+ };
317
+
318
+ /**
319
+ * A compiled JavaScript script, tied to a Context which was active when the
320
+ * script was compiled.
321
+ */
322
+ class V8_EXPORT Script {
323
+ public:
324
+ /**
325
+ * A shorthand for ScriptCompiler::Compile().
326
+ */
327
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
328
+ Local<Context> context, Local<String> source,
329
+ ScriptOrigin* origin = nullptr);
330
+
331
+ /**
332
+ * Runs the script returning the resulting value. It will be run in the
333
+ * context in which it was created (ScriptCompiler::CompileBound or
334
+ * UnboundScript::BindToCurrentContext()).
335
+ */
336
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
337
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context,
338
+ Local<Data> host_defined_options);
339
+
340
+ /**
341
+ * Returns the corresponding context-unbound script.
342
+ */
343
+ Local<UnboundScript> GetUnboundScript();
344
+
345
+ /**
346
+ * The name that was passed by the embedder as ResourceName to the
347
+ * ScriptOrigin. This can be either a v8::String or v8::Undefined.
348
+ */
349
+ Local<Value> GetResourceName();
350
+ };
351
+
352
+ enum class ScriptType { kClassic, kModule };
353
+
354
+ /**
355
+ * For compiling scripts.
356
+ */
357
+ class V8_EXPORT ScriptCompiler {
358
+ public:
359
+ class ConsumeCodeCacheTask;
360
+
361
+ /**
362
+ * Compilation data that the embedder can cache and pass back to speed up
363
+ * future compilations. The data is produced if the CompilerOptions passed to
364
+ * the compilation functions in ScriptCompiler contains produce_data_to_cache
365
+ * = true. The data to cache can then can be retrieved from
366
+ * UnboundScript.
367
+ */
368
+ struct V8_EXPORT CachedData {
369
+ enum BufferPolicy { BufferNotOwned, BufferOwned };
370
+
371
+ CachedData()
372
+ : data(nullptr),
373
+ length(0),
374
+ rejected(false),
375
+ buffer_policy(BufferNotOwned) {}
376
+
377
+ // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
378
+ // data and guarantees that it stays alive until the CachedData object is
379
+ // destroyed. If the policy is BufferOwned, the given data will be deleted
380
+ // (with delete[]) when the CachedData object is destroyed.
381
+ CachedData(const uint8_t* data, int length,
382
+ BufferPolicy buffer_policy = BufferNotOwned);
383
+ ~CachedData();
384
+ // TODO(marja): Async compilation; add constructors which take a callback
385
+ // which will be called when V8 no longer needs the data.
386
+ const uint8_t* data;
387
+ int length;
388
+ bool rejected;
389
+ BufferPolicy buffer_policy;
390
+
391
+ // Prevent copying.
392
+ CachedData(const CachedData&) = delete;
393
+ CachedData& operator=(const CachedData&) = delete;
394
+ };
395
+
396
+ /**
397
+ * Source code which can be then compiled to a UnboundScript or Script.
398
+ */
399
+ class Source {
400
+ public:
401
+ // Source takes ownership of both CachedData and CodeCacheConsumeTask.
402
+ // The caller *must* ensure that the cached data is from a trusted source.
403
+ V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
404
+ CachedData* cached_data = nullptr,
405
+ ConsumeCodeCacheTask* consume_cache_task = nullptr);
406
+ // Source takes ownership of both CachedData and CodeCacheConsumeTask.
407
+ V8_INLINE explicit Source(
408
+ Local<String> source_string, CachedData* cached_data = nullptr,
409
+ ConsumeCodeCacheTask* consume_cache_task = nullptr);
410
+ V8_INLINE ~Source() = default;
411
+
412
+ // Ownership of the CachedData or its buffers is *not* transferred to the
413
+ // caller. The CachedData object is alive as long as the Source object is
414
+ // alive.
415
+ V8_INLINE const CachedData* GetCachedData() const;
416
+
417
+ V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
418
+
419
+ private:
420
+ friend class ScriptCompiler;
421
+
422
+ Local<String> source_string;
423
+
424
+ // Origin information
425
+ Local<Value> resource_name;
426
+ int resource_line_offset;
427
+ int resource_column_offset;
428
+ ScriptOriginOptions resource_options;
429
+ Local<Value> source_map_url;
430
+ Local<Data> host_defined_options;
431
+
432
+ // Cached data from previous compilation (if a kConsume*Cache flag is
433
+ // set), or hold newly generated cache data (kProduce*Cache flags) are
434
+ // set when calling a compile method.
435
+ std::unique_ptr<CachedData> cached_data;
436
+ std::unique_ptr<ConsumeCodeCacheTask> consume_cache_task;
437
+ };
438
+
439
+ /**
440
+ * For streaming incomplete script data to V8. The embedder should implement a
441
+ * subclass of this class.
442
+ */
443
+ class V8_EXPORT ExternalSourceStream {
444
+ public:
445
+ virtual ~ExternalSourceStream() = default;
446
+
447
+ /**
448
+ * V8 calls this to request the next chunk of data from the embedder. This
449
+ * function will be called on a background thread, so it's OK to block and
450
+ * wait for the data, if the embedder doesn't have data yet. Returns the
451
+ * length of the data returned. When the data ends, GetMoreData should
452
+ * return 0. Caller takes ownership of the data.
453
+ *
454
+ * When streaming UTF-8 data, V8 handles multi-byte characters split between
455
+ * two data chunks, but doesn't handle multi-byte characters split between
456
+ * more than two data chunks. The embedder can avoid this problem by always
457
+ * returning at least 2 bytes of data.
458
+ *
459
+ * When streaming UTF-16 data, V8 does not handle characters split between
460
+ * two data chunks. The embedder has to make sure that chunks have an even
461
+ * length.
462
+ *
463
+ * If the embedder wants to cancel the streaming, they should make the next
464
+ * GetMoreData call return 0. V8 will interpret it as end of data (and most
465
+ * probably, parsing will fail). The streaming task will return as soon as
466
+ * V8 has parsed the data it received so far.
467
+ */
468
+ virtual size_t GetMoreData(const uint8_t** src) = 0;
469
+ };
470
+
471
+ /**
472
+ * Source code which can be streamed into V8 in pieces. It will be parsed
473
+ * while streaming and compiled after parsing has completed. StreamedSource
474
+ * must be kept alive while the streaming task is run (see ScriptStreamingTask
475
+ * below).
476
+ */
477
+ class V8_EXPORT StreamedSource {
478
+ public:
479
+ enum Encoding { ONE_BYTE, TWO_BYTE, UTF8, WINDOWS_1252 };
480
+
481
+ StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream,
482
+ Encoding encoding);
483
+ ~StreamedSource();
484
+
485
+ internal::ScriptStreamingData* impl() const { return impl_.get(); }
486
+
487
+ // Prevent copying.
488
+ StreamedSource(const StreamedSource&) = delete;
489
+ StreamedSource& operator=(const StreamedSource&) = delete;
490
+
491
+ private:
492
+ std::unique_ptr<internal::ScriptStreamingData> impl_;
493
+ };
494
+
495
+ /**
496
+ * A streaming task which the embedder must run on a background thread to
497
+ * stream scripts into V8. Returned by ScriptCompiler::StartStreaming.
498
+ */
499
+ class V8_EXPORT ScriptStreamingTask final {
500
+ public:
501
+ void Run();
502
+
503
+ private:
504
+ friend class ScriptCompiler;
505
+
506
+ explicit ScriptStreamingTask(internal::ScriptStreamingData* data)
507
+ : data_(data) {}
508
+
509
+ internal::ScriptStreamingData* data_;
510
+ };
511
+
512
+ /**
513
+ * A task which the embedder must run on a background thread to
514
+ * consume a V8 code cache. Returned by
515
+ * ScriptCompiler::StartConsumingCodeCache.
516
+ */
517
+ class V8_EXPORT ConsumeCodeCacheTask final {
518
+ public:
519
+ ~ConsumeCodeCacheTask();
520
+
521
+ void Run();
522
+
523
+ /**
524
+ * Provides the source text string and origin information to the consumption
525
+ * task. May be called before, during, or after Run(). This step checks
526
+ * whether the script matches an existing script in the Isolate's
527
+ * compilation cache. To check whether such a script was found, call
528
+ * ShouldMergeWithExistingScript.
529
+ *
530
+ * The Isolate provided must be the same one used during
531
+ * StartConsumingCodeCache and must be currently entered on the thread that
532
+ * calls this function. The source text and origin provided in this step
533
+ * must precisely match those used later in the ScriptCompiler::Source that
534
+ * will contain this ConsumeCodeCacheTask.
535
+ */
536
+ void SourceTextAvailable(Isolate* isolate, Local<String> source_text,
537
+ const ScriptOrigin& origin);
538
+
539
+ /**
540
+ * Returns whether the embedder should call MergeWithExistingScript. This
541
+ * function may be called from any thread, any number of times, but its
542
+ * return value is only meaningful after SourceTextAvailable has completed.
543
+ */
544
+ bool ShouldMergeWithExistingScript() const;
545
+
546
+ /**
547
+ * Merges newly deserialized data into an existing script which was found
548
+ * during SourceTextAvailable. May be called only after Run() has completed.
549
+ * Can execute on any thread, like Run().
550
+ */
551
+ void MergeWithExistingScript();
552
+
553
+ private:
554
+ friend class ScriptCompiler;
555
+
556
+ explicit ConsumeCodeCacheTask(
557
+ std::unique_ptr<internal::BackgroundDeserializeTask> impl);
558
+
559
+ std::unique_ptr<internal::BackgroundDeserializeTask> impl_;
560
+ };
561
+
562
+ enum CompileOptions {
563
+ kNoCompileOptions = 0,
564
+ kConsumeCodeCache,
565
+ kEagerCompile
566
+ };
567
+
568
+ /**
569
+ * The reason for which we are not requesting or providing a code cache.
570
+ */
571
+ enum NoCacheReason {
572
+ kNoCacheNoReason = 0,
573
+ kNoCacheBecauseCachingDisabled,
574
+ kNoCacheBecauseNoResource,
575
+ kNoCacheBecauseInlineScript,
576
+ kNoCacheBecauseModule,
577
+ kNoCacheBecauseStreamingSource,
578
+ kNoCacheBecauseInspector,
579
+ kNoCacheBecauseScriptTooSmall,
580
+ kNoCacheBecauseCacheTooCold,
581
+ kNoCacheBecauseV8Extension,
582
+ kNoCacheBecauseExtensionModule,
583
+ kNoCacheBecausePacScript,
584
+ kNoCacheBecauseInDocumentWrite,
585
+ kNoCacheBecauseResourceWithNoCacheHandler,
586
+ kNoCacheBecauseDeferredProduceCodeCache
587
+ };
588
+
589
+ /**
590
+ * Compiles the specified script (context-independent).
591
+ * Cached data as part of the source object can be optionally produced to be
592
+ * consumed later to speed up compilation of identical source scripts.
593
+ *
594
+ * Note that when producing cached data, the source must point to NULL for
595
+ * cached data. When consuming cached data, the cached data must have been
596
+ * produced by the same version of V8, and the embedder needs to ensure the
597
+ * cached data is the correct one for the given script.
598
+ *
599
+ * \param source Script source code.
600
+ * \return Compiled script object (context independent; for running it must be
601
+ * bound to a context).
602
+ */
603
+ static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
604
+ Isolate* isolate, Source* source,
605
+ CompileOptions options = kNoCompileOptions,
606
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
607
+
608
+ /**
609
+ * Compiles the specified script (bound to current context).
610
+ *
611
+ * \param source Script source code.
612
+ * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
613
+ * using pre_data speeds compilation if it's done multiple times.
614
+ * Owned by caller, no references are kept when this function returns.
615
+ * \return Compiled script object, bound to the context that was active
616
+ * when this function was called. When run it will always use this
617
+ * context.
618
+ */
619
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
620
+ Local<Context> context, Source* source,
621
+ CompileOptions options = kNoCompileOptions,
622
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
623
+
624
+ /**
625
+ * Returns a task which streams script data into V8, or NULL if the script
626
+ * cannot be streamed. The user is responsible for running the task on a
627
+ * background thread and deleting it. When ran, the task starts parsing the
628
+ * script, and it will request data from the StreamedSource as needed. When
629
+ * ScriptStreamingTask::Run exits, all data has been streamed and the script
630
+ * can be compiled (see Compile below).
631
+ *
632
+ * This API allows to start the streaming with as little data as possible, and
633
+ * the remaining data (for example, the ScriptOrigin) is passed to Compile.
634
+ */
635
+ static ScriptStreamingTask* StartStreaming(
636
+ Isolate* isolate, StreamedSource* source,
637
+ ScriptType type = ScriptType::kClassic,
638
+ CompileOptions options = kNoCompileOptions);
639
+
640
+ static ConsumeCodeCacheTask* StartConsumingCodeCache(
641
+ Isolate* isolate, std::unique_ptr<CachedData> source);
642
+
643
+ /**
644
+ * Compiles a streamed script (bound to current context).
645
+ *
646
+ * This can only be called after the streaming has finished
647
+ * (ScriptStreamingTask has been run). V8 doesn't construct the source string
648
+ * during streaming, so the embedder needs to pass the full source here.
649
+ */
650
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
651
+ Local<Context> context, StreamedSource* source,
652
+ Local<String> full_source_string, const ScriptOrigin& origin);
653
+
654
+ /**
655
+ * Return a version tag for CachedData for the current V8 version & flags.
656
+ *
657
+ * This value is meant only for determining whether a previously generated
658
+ * CachedData instance is still valid; the tag has no other meaing.
659
+ *
660
+ * Background: The data carried by CachedData may depend on the exact
661
+ * V8 version number or current compiler flags. This means that when
662
+ * persisting CachedData, the embedder must take care to not pass in
663
+ * data from another V8 version, or the same version with different
664
+ * features enabled.
665
+ *
666
+ * The easiest way to do so is to clear the embedder's cache on any
667
+ * such change.
668
+ *
669
+ * Alternatively, this tag can be stored alongside the cached data and
670
+ * compared when it is being used.
671
+ */
672
+ static uint32_t CachedDataVersionTag();
673
+
674
+ /**
675
+ * Compile an ES module, returning a Module that encapsulates
676
+ * the compiled code.
677
+ *
678
+ * Corresponds to the ParseModule abstract operation in the
679
+ * ECMAScript specification.
680
+ */
681
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
682
+ Isolate* isolate, Source* source,
683
+ CompileOptions options = kNoCompileOptions,
684
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
685
+
686
+ /**
687
+ * Compiles a streamed module script.
688
+ *
689
+ * This can only be called after the streaming has finished
690
+ * (ScriptStreamingTask has been run). V8 doesn't construct the source string
691
+ * during streaming, so the embedder needs to pass the full source here.
692
+ */
693
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
694
+ Local<Context> context, StreamedSource* v8_source,
695
+ Local<String> full_source_string, const ScriptOrigin& origin);
696
+
697
+ /**
698
+ * Compile a function for a given context. This is equivalent to running
699
+ *
700
+ * with (obj) {
701
+ * return function(args) { ... }
702
+ * }
703
+ *
704
+ * It is possible to specify multiple context extensions (obj in the above
705
+ * example).
706
+ */
707
+ V8_DEPRECATED("Use CompileFunction")
708
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
709
+ Local<Context> context, Source* source, size_t arguments_count,
710
+ Local<String> arguments[], size_t context_extension_count,
711
+ Local<Object> context_extensions[],
712
+ CompileOptions options = kNoCompileOptions,
713
+ NoCacheReason no_cache_reason = kNoCacheNoReason,
714
+ Local<ScriptOrModule>* script_or_module_out = nullptr);
715
+
716
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunction(
717
+ Local<Context> context, Source* source, size_t arguments_count = 0,
718
+ Local<String> arguments[] = nullptr, size_t context_extension_count = 0,
719
+ Local<Object> context_extensions[] = nullptr,
720
+ CompileOptions options = kNoCompileOptions,
721
+ NoCacheReason no_cache_reason = kNoCacheNoReason);
722
+
723
+ /**
724
+ * Creates and returns code cache for the specified unbound_script.
725
+ * This will return nullptr if the script cannot be serialized. The
726
+ * CachedData returned by this function should be owned by the caller.
727
+ */
728
+ static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
729
+
730
+ /**
731
+ * Creates and returns code cache for the specified unbound_module_script.
732
+ * This will return nullptr if the script cannot be serialized. The
733
+ * CachedData returned by this function should be owned by the caller.
734
+ */
735
+ static CachedData* CreateCodeCache(
736
+ Local<UnboundModuleScript> unbound_module_script);
737
+
738
+ /**
739
+ * Creates and returns code cache for the specified function that was
740
+ * previously produced by CompileFunction.
741
+ * This will return nullptr if the script cannot be serialized. The
742
+ * CachedData returned by this function should be owned by the caller.
743
+ */
744
+ static CachedData* CreateCodeCacheForFunction(Local<Function> function);
745
+
746
+ private:
747
+ static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
748
+ Isolate* isolate, Source* source, CompileOptions options,
749
+ NoCacheReason no_cache_reason);
750
+
751
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInternal(
752
+ Local<Context> context, Source* source, size_t arguments_count,
753
+ Local<String> arguments[], size_t context_extension_count,
754
+ Local<Object> context_extensions[], CompileOptions options,
755
+ NoCacheReason no_cache_reason,
756
+ Local<ScriptOrModule>* script_or_module_out);
757
+ };
758
+
759
+ ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
760
+ CachedData* data,
761
+ ConsumeCodeCacheTask* consume_cache_task)
762
+ : source_string(string),
763
+ resource_name(origin.ResourceName()),
764
+ resource_line_offset(origin.LineOffset()),
765
+ resource_column_offset(origin.ColumnOffset()),
766
+ resource_options(origin.Options()),
767
+ source_map_url(origin.SourceMapUrl()),
768
+ host_defined_options(origin.GetHostDefinedOptions()),
769
+ cached_data(data),
770
+ consume_cache_task(consume_cache_task) {}
771
+
772
+ ScriptCompiler::Source::Source(Local<String> string, CachedData* data,
773
+ ConsumeCodeCacheTask* consume_cache_task)
774
+ : source_string(string),
775
+ cached_data(data),
776
+ consume_cache_task(consume_cache_task) {}
777
+
778
+ const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
779
+ const {
780
+ return cached_data.get();
781
+ }
782
+
783
+ const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
784
+ return resource_options;
785
+ }
786
+
787
+ ModuleRequest* ModuleRequest::Cast(Data* data) {
788
+ #ifdef V8_ENABLE_CHECKS
789
+ CheckCast(data);
790
+ #endif
791
+ return reinterpret_cast<ModuleRequest*>(data);
792
+ }
793
+
794
+ Module* Module::Cast(Data* data) {
795
+ #ifdef V8_ENABLE_CHECKS
796
+ CheckCast(data);
797
+ #endif
798
+ return reinterpret_cast<Module*>(data);
799
+ }
800
+
801
+ } // namespace v8
802
+
803
+ #endif // INCLUDE_V8_SCRIPT_H_