@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,311 @@
1
+ // Copyright 2020 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 V8_METRICS_H_
6
+ #define V8_METRICS_H_
7
+
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+
11
+ #include <vector>
12
+
13
+ #include "v8-internal.h" // NOLINT(build/include_directory)
14
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
15
+ #include "v8config.h" // NOLINT(build/include_directory)
16
+
17
+ namespace v8 {
18
+
19
+ class Context;
20
+ class Isolate;
21
+
22
+ namespace metrics {
23
+
24
+ struct GarbageCollectionPhases {
25
+ int64_t total_wall_clock_duration_in_us = -1;
26
+ int64_t compact_wall_clock_duration_in_us = -1;
27
+ int64_t mark_wall_clock_duration_in_us = -1;
28
+ int64_t sweep_wall_clock_duration_in_us = -1;
29
+ int64_t weak_wall_clock_duration_in_us = -1;
30
+ };
31
+
32
+ struct GarbageCollectionSizes {
33
+ int64_t bytes_before = -1;
34
+ int64_t bytes_after = -1;
35
+ int64_t bytes_freed = -1;
36
+ };
37
+
38
+ struct GarbageCollectionFullCycle {
39
+ int reason = -1;
40
+ GarbageCollectionPhases total;
41
+ GarbageCollectionPhases total_cpp;
42
+ GarbageCollectionPhases main_thread;
43
+ GarbageCollectionPhases main_thread_cpp;
44
+ GarbageCollectionPhases main_thread_atomic;
45
+ GarbageCollectionPhases main_thread_atomic_cpp;
46
+ GarbageCollectionPhases main_thread_incremental;
47
+ GarbageCollectionPhases main_thread_incremental_cpp;
48
+ GarbageCollectionSizes objects;
49
+ GarbageCollectionSizes objects_cpp;
50
+ GarbageCollectionSizes memory;
51
+ GarbageCollectionSizes memory_cpp;
52
+ double collection_rate_in_percent = -1.0;
53
+ double collection_rate_cpp_in_percent = -1.0;
54
+ double efficiency_in_bytes_per_us = -1.0;
55
+ double efficiency_cpp_in_bytes_per_us = -1.0;
56
+ double main_thread_efficiency_in_bytes_per_us = -1.0;
57
+ double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
58
+ };
59
+
60
+ struct GarbageCollectionFullMainThreadIncrementalMark {
61
+ int64_t wall_clock_duration_in_us = -1;
62
+ int64_t cpp_wall_clock_duration_in_us = -1;
63
+ };
64
+
65
+ struct GarbageCollectionFullMainThreadIncrementalSweep {
66
+ int64_t wall_clock_duration_in_us = -1;
67
+ int64_t cpp_wall_clock_duration_in_us = -1;
68
+ };
69
+
70
+ template <typename EventType>
71
+ struct GarbageCollectionBatchedEvents {
72
+ std::vector<EventType> events;
73
+ };
74
+
75
+ using GarbageCollectionFullMainThreadBatchedIncrementalMark =
76
+ GarbageCollectionBatchedEvents<
77
+ GarbageCollectionFullMainThreadIncrementalMark>;
78
+ using GarbageCollectionFullMainThreadBatchedIncrementalSweep =
79
+ GarbageCollectionBatchedEvents<
80
+ GarbageCollectionFullMainThreadIncrementalSweep>;
81
+
82
+ struct GarbageCollectionYoungCycle {
83
+ int reason = -1;
84
+ int64_t total_wall_clock_duration_in_us = -1;
85
+ int64_t main_thread_wall_clock_duration_in_us = -1;
86
+ double collection_rate_in_percent = -1.0;
87
+ double efficiency_in_bytes_per_us = -1.0;
88
+ double main_thread_efficiency_in_bytes_per_us = -1.0;
89
+ #if defined(CPPGC_YOUNG_GENERATION)
90
+ GarbageCollectionPhases total_cpp;
91
+ GarbageCollectionSizes objects_cpp;
92
+ GarbageCollectionSizes memory_cpp;
93
+ double collection_rate_cpp_in_percent = -1.0;
94
+ double efficiency_cpp_in_bytes_per_us = -1.0;
95
+ double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
96
+ #endif // defined(CPPGC_YOUNG_GENERATION)
97
+ };
98
+
99
+ struct WasmModuleDecoded {
100
+ WasmModuleDecoded() = default;
101
+ WasmModuleDecoded(bool async, bool streamed, bool success,
102
+ size_t module_size_in_bytes, size_t function_count,
103
+ int64_t wall_clock_duration_in_us)
104
+ : async(async),
105
+ streamed(streamed),
106
+ success(success),
107
+ module_size_in_bytes(module_size_in_bytes),
108
+ function_count(function_count),
109
+ wall_clock_duration_in_us(wall_clock_duration_in_us) {}
110
+
111
+ V8_DEPRECATE_SOON("Use the version without cpu_duration_in_us")
112
+ WasmModuleDecoded(bool async, bool streamed, bool success,
113
+ size_t module_size_in_bytes, size_t function_count,
114
+ int64_t wall_clock_duration_in_us,
115
+ int64_t cpu_duration_in_us)
116
+ : async(async),
117
+ streamed(streamed),
118
+ success(success),
119
+ module_size_in_bytes(module_size_in_bytes),
120
+ function_count(function_count),
121
+ wall_clock_duration_in_us(wall_clock_duration_in_us),
122
+ cpu_duration_in_us(cpu_duration_in_us) {}
123
+
124
+ START_ALLOW_USE_DEPRECATED()
125
+ // Copy constructor and copy assignment operator are allowed to copy the
126
+ // {cpu_duration_in_us} field.
127
+ WasmModuleDecoded(const WasmModuleDecoded&) = default;
128
+ WasmModuleDecoded& operator=(const WasmModuleDecoded&) = default;
129
+ END_ALLOW_USE_DEPRECATED()
130
+
131
+ bool async = false;
132
+ bool streamed = false;
133
+ bool success = false;
134
+ size_t module_size_in_bytes = 0;
135
+ size_t function_count = 0;
136
+ int64_t wall_clock_duration_in_us = -1;
137
+ V8_DEPRECATE_SOON("We do not collect cpu times any more")
138
+ int64_t cpu_duration_in_us = -1;
139
+ };
140
+
141
+ struct WasmModuleCompiled {
142
+ WasmModuleCompiled() = default;
143
+
144
+ WasmModuleCompiled(bool async, bool streamed, bool cached, bool deserialized,
145
+ bool lazy, bool success, size_t code_size_in_bytes,
146
+ size_t liftoff_bailout_count,
147
+ int64_t wall_clock_duration_in_us)
148
+ : async(async),
149
+ streamed(streamed),
150
+ cached(cached),
151
+ deserialized(deserialized),
152
+ lazy(lazy),
153
+ success(success),
154
+ code_size_in_bytes(code_size_in_bytes),
155
+ liftoff_bailout_count(liftoff_bailout_count),
156
+ wall_clock_duration_in_us(wall_clock_duration_in_us) {}
157
+
158
+ V8_DEPRECATE_SOON("Use the version without cpu_duration_in_us")
159
+ WasmModuleCompiled(bool async, bool streamed, bool cached, bool deserialized,
160
+ bool lazy, bool success, size_t code_size_in_bytes,
161
+ size_t liftoff_bailout_count,
162
+ int64_t wall_clock_duration_in_us,
163
+ int64_t cpu_duration_in_us)
164
+ : async(async),
165
+ streamed(streamed),
166
+ cached(cached),
167
+ deserialized(deserialized),
168
+ lazy(lazy),
169
+ success(success),
170
+ code_size_in_bytes(code_size_in_bytes),
171
+ liftoff_bailout_count(liftoff_bailout_count),
172
+ wall_clock_duration_in_us(wall_clock_duration_in_us),
173
+ cpu_duration_in_us(cpu_duration_in_us) {}
174
+
175
+ START_ALLOW_USE_DEPRECATED()
176
+ // Copy constructor and copy assignment operator are allowed to copy the
177
+ // {cpu_duration_in_us} field.
178
+ WasmModuleCompiled(const WasmModuleCompiled&) = default;
179
+ WasmModuleCompiled& operator=(const WasmModuleCompiled&) = default;
180
+ END_ALLOW_USE_DEPRECATED()
181
+
182
+ bool async = false;
183
+ bool streamed = false;
184
+ bool cached = false;
185
+ bool deserialized = false;
186
+ bool lazy = false;
187
+ bool success = false;
188
+ size_t code_size_in_bytes = 0;
189
+ size_t liftoff_bailout_count = 0;
190
+ int64_t wall_clock_duration_in_us = -1;
191
+ V8_DEPRECATE_SOON("We do not collect cpu times any more")
192
+ int64_t cpu_duration_in_us = -1;
193
+ };
194
+
195
+ struct WasmModuleInstantiated {
196
+ bool async = false;
197
+ bool success = false;
198
+ size_t imported_function_count = 0;
199
+ int64_t wall_clock_duration_in_us = -1;
200
+ };
201
+
202
+ struct WasmModulesPerIsolate {
203
+ size_t count = 0;
204
+ };
205
+
206
+ /**
207
+ * This class serves as a base class for recording event-based metrics in V8.
208
+ * There a two kinds of metrics, those which are expected to be thread-safe and
209
+ * whose implementation is required to fulfill this requirement and those whose
210
+ * implementation does not have that requirement and only needs to be
211
+ * executable on the main thread. If such an event is triggered from a
212
+ * background thread, it will be delayed and executed by the foreground task
213
+ * runner.
214
+ *
215
+ * The embedder is expected to call v8::Isolate::SetMetricsRecorder()
216
+ * providing its implementation and have the virtual methods overwritten
217
+ * for the events it cares about.
218
+ */
219
+ class V8_EXPORT Recorder {
220
+ public:
221
+ // A unique identifier for a context in this Isolate.
222
+ // It is guaranteed to not be reused throughout the lifetime of the Isolate.
223
+ class ContextId {
224
+ public:
225
+ ContextId() : id_(kEmptyId) {}
226
+
227
+ bool IsEmpty() const { return id_ == kEmptyId; }
228
+ static const ContextId Empty() { return ContextId{kEmptyId}; }
229
+
230
+ bool operator==(const ContextId& other) const { return id_ == other.id_; }
231
+ bool operator!=(const ContextId& other) const { return id_ != other.id_; }
232
+
233
+ private:
234
+ friend class ::v8::Context;
235
+ friend class ::v8::internal::Isolate;
236
+
237
+ explicit ContextId(uintptr_t id) : id_(id) {}
238
+
239
+ static constexpr uintptr_t kEmptyId = 0;
240
+ uintptr_t id_;
241
+ };
242
+
243
+ virtual ~Recorder() = default;
244
+
245
+ // Main thread events. Those are only triggered on the main thread, and hence
246
+ // can access the context.
247
+ #define ADD_MAIN_THREAD_EVENT(E) \
248
+ virtual void AddMainThreadEvent(const E&, ContextId) {}
249
+ ADD_MAIN_THREAD_EVENT(GarbageCollectionFullCycle)
250
+ ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalMark)
251
+ ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalMark)
252
+ ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalSweep)
253
+ ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalSweep)
254
+ ADD_MAIN_THREAD_EVENT(GarbageCollectionYoungCycle)
255
+ ADD_MAIN_THREAD_EVENT(WasmModuleDecoded)
256
+ ADD_MAIN_THREAD_EVENT(WasmModuleCompiled)
257
+ ADD_MAIN_THREAD_EVENT(WasmModuleInstantiated)
258
+ #undef ADD_MAIN_THREAD_EVENT
259
+
260
+ // Thread-safe events are not allowed to access the context and therefore do
261
+ // not carry a context ID with them. These IDs can be generated using
262
+ // Recorder::GetContextId() and the ID will be valid throughout the lifetime
263
+ // of the isolate. It is not guaranteed that the ID will still resolve to
264
+ // a valid context using Recorder::GetContext() at the time the metric is
265
+ // recorded. In this case, an empty handle will be returned.
266
+ #define ADD_THREAD_SAFE_EVENT(E) \
267
+ virtual void AddThreadSafeEvent(const E&) {}
268
+ ADD_THREAD_SAFE_EVENT(WasmModulesPerIsolate)
269
+ #undef ADD_THREAD_SAFE_EVENT
270
+
271
+ virtual void NotifyIsolateDisposal() {}
272
+
273
+ // Return the context with the given id or an empty handle if the context
274
+ // was already garbage collected.
275
+ static MaybeLocal<Context> GetContext(Isolate* isolate, ContextId id);
276
+ // Return the unique id corresponding to the given context.
277
+ static ContextId GetContextId(Local<Context> context);
278
+ };
279
+
280
+ /**
281
+ * Experimental API intended for the LongTasks UKM (crbug.com/1173527).
282
+ * The Reset() method should be called at the start of a potential
283
+ * long task. The Get() method returns durations of V8 work that
284
+ * happened during the task.
285
+ *
286
+ * This API is experimental and may be removed/changed in the future.
287
+ */
288
+ struct V8_EXPORT LongTaskStats {
289
+ /**
290
+ * Resets durations of V8 work for the new task.
291
+ */
292
+ V8_INLINE static void Reset(Isolate* isolate) {
293
+ v8::internal::Internals::IncrementLongTasksStatsCounter(isolate);
294
+ }
295
+
296
+ /**
297
+ * Returns durations of V8 work that happened since the last Reset().
298
+ */
299
+ static LongTaskStats Get(Isolate* isolate);
300
+
301
+ int64_t gc_full_atomic_wall_clock_duration_us = 0;
302
+ int64_t gc_full_incremental_wall_clock_duration_us = 0;
303
+ int64_t gc_young_wall_clock_duration_us = 0;
304
+ // Only collected with --slow-histograms
305
+ int64_t v8_execute_us = 0;
306
+ };
307
+
308
+ } // namespace metrics
309
+ } // namespace v8
310
+
311
+ #endif // V8_METRICS_H_
@@ -0,0 +1,157 @@
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_MICROTASKS_QUEUE_H_
6
+ #define INCLUDE_V8_MICROTASKS_QUEUE_H_
7
+
8
+ #include <stddef.h>
9
+
10
+ #include <memory>
11
+
12
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
13
+ #include "v8-microtask.h" // NOLINT(build/include_directory)
14
+ #include "v8config.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8 {
17
+
18
+ class Function;
19
+
20
+ namespace internal {
21
+ class Isolate;
22
+ class MicrotaskQueue;
23
+ } // namespace internal
24
+
25
+ /**
26
+ * Represents the microtask queue, where microtasks are stored and processed.
27
+ * https://html.spec.whatwg.org/multipage/webappapis.html#microtask-queue
28
+ * https://html.spec.whatwg.org/multipage/webappapis.html#enqueuejob(queuename,-job,-arguments)
29
+ * https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
30
+ *
31
+ * A MicrotaskQueue instance may be associated to multiple Contexts by passing
32
+ * it to Context::New(), and they can be detached by Context::DetachGlobal().
33
+ * The embedder must keep the MicrotaskQueue instance alive until all associated
34
+ * Contexts are gone or detached.
35
+ *
36
+ * Use the same instance of MicrotaskQueue for all Contexts that may access each
37
+ * other synchronously. E.g. for Web embedding, use the same instance for all
38
+ * origins that share the same URL scheme and eTLD+1.
39
+ */
40
+ class V8_EXPORT MicrotaskQueue {
41
+ public:
42
+ /**
43
+ * Creates an empty MicrotaskQueue instance.
44
+ */
45
+ static std::unique_ptr<MicrotaskQueue> New(
46
+ Isolate* isolate, MicrotasksPolicy policy = MicrotasksPolicy::kAuto);
47
+
48
+ virtual ~MicrotaskQueue() = default;
49
+
50
+ /**
51
+ * Enqueues the callback to the queue.
52
+ */
53
+ virtual void EnqueueMicrotask(Isolate* isolate,
54
+ Local<Function> microtask) = 0;
55
+
56
+ /**
57
+ * Enqueues the callback to the queue.
58
+ */
59
+ virtual void EnqueueMicrotask(v8::Isolate* isolate,
60
+ MicrotaskCallback callback,
61
+ void* data = nullptr) = 0;
62
+
63
+ /**
64
+ * Adds a callback to notify the embedder after microtasks were run. The
65
+ * callback is triggered by explicit RunMicrotasks call or automatic
66
+ * microtasks execution (see Isolate::SetMicrotasksPolicy).
67
+ *
68
+ * Callback will trigger even if microtasks were attempted to run,
69
+ * but the microtasks queue was empty and no single microtask was actually
70
+ * executed.
71
+ *
72
+ * Executing scripts inside the callback will not re-trigger microtasks and
73
+ * the callback.
74
+ */
75
+ virtual void AddMicrotasksCompletedCallback(
76
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
77
+
78
+ /**
79
+ * Removes callback that was installed by AddMicrotasksCompletedCallback.
80
+ */
81
+ virtual void RemoveMicrotasksCompletedCallback(
82
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
83
+
84
+ /**
85
+ * Runs microtasks if no microtask is running on this MicrotaskQueue instance.
86
+ */
87
+ virtual void PerformCheckpoint(Isolate* isolate) = 0;
88
+
89
+ /**
90
+ * Returns true if a microtask is running on this MicrotaskQueue instance.
91
+ */
92
+ virtual bool IsRunningMicrotasks() const = 0;
93
+
94
+ /**
95
+ * Returns the current depth of nested MicrotasksScope that has
96
+ * kRunMicrotasks.
97
+ */
98
+ virtual int GetMicrotasksScopeDepth() const = 0;
99
+
100
+ MicrotaskQueue(const MicrotaskQueue&) = delete;
101
+ MicrotaskQueue& operator=(const MicrotaskQueue&) = delete;
102
+
103
+ private:
104
+ friend class internal::MicrotaskQueue;
105
+ MicrotaskQueue() = default;
106
+ };
107
+
108
+ /**
109
+ * This scope is used to control microtasks when MicrotasksPolicy::kScoped
110
+ * is used on Isolate. In this mode every non-primitive call to V8 should be
111
+ * done inside some MicrotasksScope.
112
+ * Microtasks are executed when topmost MicrotasksScope marked as kRunMicrotasks
113
+ * exits.
114
+ * kDoNotRunMicrotasks should be used to annotate calls not intended to trigger
115
+ * microtasks.
116
+ */
117
+ class V8_EXPORT V8_NODISCARD MicrotasksScope {
118
+ public:
119
+ enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
120
+
121
+ V8_DEPRECATE_SOON(
122
+ "May be incorrect if context was created with non-default microtask "
123
+ "queue")
124
+ MicrotasksScope(Isolate* isolate, Type type);
125
+
126
+ MicrotasksScope(Local<Context> context, Type type);
127
+ MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
128
+ ~MicrotasksScope();
129
+
130
+ /**
131
+ * Runs microtasks if no kRunMicrotasks scope is currently active.
132
+ */
133
+ static void PerformCheckpoint(Isolate* isolate);
134
+
135
+ /**
136
+ * Returns current depth of nested kRunMicrotasks scopes.
137
+ */
138
+ static int GetCurrentDepth(Isolate* isolate);
139
+
140
+ /**
141
+ * Returns true while microtasks are being executed.
142
+ */
143
+ static bool IsRunningMicrotasks(Isolate* isolate);
144
+
145
+ // Prevent copying.
146
+ MicrotasksScope(const MicrotasksScope&) = delete;
147
+ MicrotasksScope& operator=(const MicrotasksScope&) = delete;
148
+
149
+ private:
150
+ internal::Isolate* const i_isolate_;
151
+ internal::MicrotaskQueue* const microtask_queue_;
152
+ bool run_;
153
+ };
154
+
155
+ } // namespace v8
156
+
157
+ #endif // INCLUDE_V8_MICROTASKS_QUEUE_H_
@@ -0,0 +1,28 @@
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_MICROTASK_H_
6
+ #define INCLUDE_V8_MICROTASK_H_
7
+
8
+ namespace v8 {
9
+
10
+ class Isolate;
11
+
12
+ // --- Microtasks Callbacks ---
13
+ using MicrotasksCompletedCallbackWithData = void (*)(Isolate*, void*);
14
+ using MicrotaskCallback = void (*)(void* data);
15
+
16
+ /**
17
+ * Policy for running microtasks:
18
+ * - explicit: microtasks are invoked with the
19
+ * Isolate::PerformMicrotaskCheckpoint() method;
20
+ * - scoped: microtasks invocation is controlled by MicrotasksScope objects;
21
+ * - auto: microtasks are invoked when the script call depth decrements
22
+ * to zero.
23
+ */
24
+ enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
25
+
26
+ } // namespace v8
27
+
28
+ #endif // INCLUDE_V8_MICROTASK_H_