@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,1695 @@
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_ISOLATE_H_
6
+ #define INCLUDE_V8_ISOLATE_H_
7
+
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+
11
+ #include <memory>
12
+ #include <utility>
13
+
14
+ #include "cppgc/common.h"
15
+ #include "v8-array-buffer.h" // NOLINT(build/include_directory)
16
+ #include "v8-callbacks.h" // NOLINT(build/include_directory)
17
+ #include "v8-data.h" // NOLINT(build/include_directory)
18
+ #include "v8-debug.h" // NOLINT(build/include_directory)
19
+ #include "v8-embedder-heap.h" // NOLINT(build/include_directory)
20
+ #include "v8-function-callback.h" // NOLINT(build/include_directory)
21
+ #include "v8-internal.h" // NOLINT(build/include_directory)
22
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
23
+ #include "v8-microtask.h" // NOLINT(build/include_directory)
24
+ #include "v8-persistent-handle.h" // NOLINT(build/include_directory)
25
+ #include "v8-primitive.h" // NOLINT(build/include_directory)
26
+ #include "v8-statistics.h" // NOLINT(build/include_directory)
27
+ #include "v8-unwinder.h" // NOLINT(build/include_directory)
28
+ #include "v8config.h" // NOLINT(build/include_directory)
29
+
30
+ namespace v8 {
31
+
32
+ class CppHeap;
33
+ class HeapProfiler;
34
+ class MicrotaskQueue;
35
+ class StartupData;
36
+ class ScriptOrModule;
37
+ class SharedArrayBuffer;
38
+
39
+ namespace internal {
40
+ class MicrotaskQueue;
41
+ class ThreadLocalTop;
42
+ } // namespace internal
43
+
44
+ namespace metrics {
45
+ class Recorder;
46
+ } // namespace metrics
47
+
48
+ /**
49
+ * A set of constraints that specifies the limits of the runtime's memory use.
50
+ * You must set the heap size before initializing the VM - the size cannot be
51
+ * adjusted after the VM is initialized.
52
+ *
53
+ * If you are using threads then you should hold the V8::Locker lock while
54
+ * setting the stack limit and you must set a non-default stack limit separately
55
+ * for each thread.
56
+ *
57
+ * The arguments for set_max_semi_space_size, set_max_old_space_size,
58
+ * set_max_executable_size, set_code_range_size specify limits in MB.
59
+ *
60
+ * The argument for set_max_semi_space_size_in_kb is in KB.
61
+ */
62
+ class V8_EXPORT ResourceConstraints {
63
+ public:
64
+ /**
65
+ * Configures the constraints with reasonable default values based on the
66
+ * provided heap size limit. The heap size includes both the young and
67
+ * the old generation.
68
+ *
69
+ * \param initial_heap_size_in_bytes The initial heap size or zero.
70
+ * By default V8 starts with a small heap and dynamically grows it to
71
+ * match the set of live objects. This may lead to ineffective
72
+ * garbage collections at startup if the live set is large.
73
+ * Setting the initial heap size avoids such garbage collections.
74
+ * Note that this does not affect young generation garbage collections.
75
+ *
76
+ * \param maximum_heap_size_in_bytes The hard limit for the heap size.
77
+ * When the heap size approaches this limit, V8 will perform series of
78
+ * garbage collections and invoke the NearHeapLimitCallback. If the garbage
79
+ * collections do not help and the callback does not increase the limit,
80
+ * then V8 will crash with V8::FatalProcessOutOfMemory.
81
+ */
82
+ void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
83
+ size_t maximum_heap_size_in_bytes);
84
+
85
+ /**
86
+ * Configures the constraints with reasonable default values based on the
87
+ * capabilities of the current device the VM is running on.
88
+ *
89
+ * \param physical_memory The total amount of physical memory on the current
90
+ * device, in bytes.
91
+ * \param virtual_memory_limit The amount of virtual memory on the current
92
+ * device, in bytes, or zero, if there is no limit.
93
+ */
94
+ void ConfigureDefaults(uint64_t physical_memory,
95
+ uint64_t virtual_memory_limit);
96
+
97
+ /**
98
+ * The address beyond which the VM's stack may not grow.
99
+ */
100
+ uint32_t* stack_limit() const { return stack_limit_; }
101
+ void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
102
+
103
+ /**
104
+ * The amount of virtual memory reserved for generated code. This is relevant
105
+ * for 64-bit architectures that rely on code range for calls in code.
106
+ *
107
+ * When V8_COMPRESS_POINTERS_IN_SHARED_CAGE is defined, there is a shared
108
+ * process-wide code range that is lazily initialized. This value is used to
109
+ * configure that shared code range when the first Isolate is
110
+ * created. Subsequent Isolates ignore this value.
111
+ */
112
+ size_t code_range_size_in_bytes() const { return code_range_size_; }
113
+ void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
114
+
115
+ /**
116
+ * The maximum size of the old generation.
117
+ * When the old generation approaches this limit, V8 will perform series of
118
+ * garbage collections and invoke the NearHeapLimitCallback.
119
+ * If the garbage collections do not help and the callback does not
120
+ * increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
121
+ */
122
+ size_t max_old_generation_size_in_bytes() const {
123
+ return max_old_generation_size_;
124
+ }
125
+ void set_max_old_generation_size_in_bytes(size_t limit) {
126
+ max_old_generation_size_ = limit;
127
+ }
128
+
129
+ /**
130
+ * The maximum size of the young generation, which consists of two semi-spaces
131
+ * and a large object space. This affects frequency of Scavenge garbage
132
+ * collections and should be typically much smaller that the old generation.
133
+ */
134
+ size_t max_young_generation_size_in_bytes() const {
135
+ return max_young_generation_size_;
136
+ }
137
+ void set_max_young_generation_size_in_bytes(size_t limit) {
138
+ max_young_generation_size_ = limit;
139
+ }
140
+
141
+ size_t initial_old_generation_size_in_bytes() const {
142
+ return initial_old_generation_size_;
143
+ }
144
+ void set_initial_old_generation_size_in_bytes(size_t initial_size) {
145
+ initial_old_generation_size_ = initial_size;
146
+ }
147
+
148
+ size_t initial_young_generation_size_in_bytes() const {
149
+ return initial_young_generation_size_;
150
+ }
151
+ void set_initial_young_generation_size_in_bytes(size_t initial_size) {
152
+ initial_young_generation_size_ = initial_size;
153
+ }
154
+
155
+ private:
156
+ static constexpr size_t kMB = 1048576u;
157
+ size_t code_range_size_ = 0;
158
+ size_t max_old_generation_size_ = 0;
159
+ size_t max_young_generation_size_ = 0;
160
+ size_t initial_old_generation_size_ = 0;
161
+ size_t initial_young_generation_size_ = 0;
162
+ uint32_t* stack_limit_ = nullptr;
163
+ };
164
+
165
+ /**
166
+ * Option flags passed to the SetRAILMode function.
167
+ * See documentation https://developers.google.com/web/tools/chrome-devtools/
168
+ * profile/evaluate-performance/rail
169
+ */
170
+ enum RAILMode : unsigned {
171
+ // Response performance mode: In this mode very low virtual machine latency
172
+ // is provided. V8 will try to avoid JavaScript execution interruptions.
173
+ // Throughput may be throttled.
174
+ PERFORMANCE_RESPONSE,
175
+ // Animation performance mode: In this mode low virtual machine latency is
176
+ // provided. V8 will try to avoid as many JavaScript execution interruptions
177
+ // as possible. Throughput may be throttled. This is the default mode.
178
+ PERFORMANCE_ANIMATION,
179
+ // Idle performance mode: The embedder is idle. V8 can complete deferred work
180
+ // in this mode.
181
+ PERFORMANCE_IDLE,
182
+ // Load performance mode: In this mode high throughput is provided. V8 may
183
+ // turn off latency optimizations.
184
+ PERFORMANCE_LOAD
185
+ };
186
+
187
+ /**
188
+ * Memory pressure level for the MemoryPressureNotification.
189
+ * kNone hints V8 that there is no memory pressure.
190
+ * kModerate hints V8 to speed up incremental garbage collection at the cost of
191
+ * of higher latency due to garbage collection pauses.
192
+ * kCritical hints V8 to free memory as soon as possible. Garbage collection
193
+ * pauses at this level will be large.
194
+ */
195
+ enum class MemoryPressureLevel { kNone, kModerate, kCritical };
196
+
197
+ /**
198
+ * Indicator for the stack state.
199
+ */
200
+ using StackState = cppgc::EmbedderStackState;
201
+
202
+ /**
203
+ * Isolate represents an isolated instance of the V8 engine. V8 isolates have
204
+ * completely separate states. Objects from one isolate must not be used in
205
+ * other isolates. The embedder can create multiple isolates and use them in
206
+ * parallel in multiple threads. An isolate can be entered by at most one
207
+ * thread at any given time. The Locker/Unlocker API must be used to
208
+ * synchronize.
209
+ */
210
+ class V8_EXPORT Isolate {
211
+ public:
212
+ /**
213
+ * Initial configuration parameters for a new Isolate.
214
+ */
215
+ struct V8_EXPORT CreateParams {
216
+ CreateParams();
217
+ ~CreateParams();
218
+
219
+ ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(CreateParams)
220
+
221
+ /**
222
+ * Allows the host application to provide the address of a function that is
223
+ * notified each time code is added, moved or removed.
224
+ */
225
+ JitCodeEventHandler code_event_handler = nullptr;
226
+
227
+ /**
228
+ * ResourceConstraints to use for the new Isolate.
229
+ */
230
+ ResourceConstraints constraints;
231
+
232
+ /**
233
+ * Explicitly specify a startup snapshot blob. The embedder owns the blob.
234
+ * The embedder *must* ensure that the snapshot is from a trusted source.
235
+ */
236
+ const StartupData* snapshot_blob = nullptr;
237
+
238
+ /**
239
+ * Enables the host application to provide a mechanism for recording
240
+ * statistics counters.
241
+ */
242
+ CounterLookupCallback counter_lookup_callback = nullptr;
243
+
244
+ /**
245
+ * Enables the host application to provide a mechanism for recording
246
+ * histograms. The CreateHistogram function returns a
247
+ * histogram which will later be passed to the AddHistogramSample
248
+ * function.
249
+ */
250
+ CreateHistogramCallback create_histogram_callback = nullptr;
251
+ AddHistogramSampleCallback add_histogram_sample_callback = nullptr;
252
+
253
+ /**
254
+ * The ArrayBuffer::Allocator to use for allocating and freeing the backing
255
+ * store of ArrayBuffers.
256
+ *
257
+ * If the shared_ptr version is used, the Isolate instance and every
258
+ * |BackingStore| allocated using this allocator hold a std::shared_ptr
259
+ * to the allocator, in order to facilitate lifetime
260
+ * management for the allocator instance.
261
+ */
262
+ ArrayBuffer::Allocator* array_buffer_allocator = nullptr;
263
+ std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
264
+
265
+ /**
266
+ * Specifies an optional nullptr-terminated array of raw addresses in the
267
+ * embedder that V8 can match against during serialization and use for
268
+ * deserialization. This array and its content must stay valid for the
269
+ * entire lifetime of the isolate.
270
+ */
271
+ const intptr_t* external_references = nullptr;
272
+
273
+ /**
274
+ * Whether calling Atomics.wait (a function that may block) is allowed in
275
+ * this isolate. This can also be configured via SetAllowAtomicsWait.
276
+ */
277
+ bool allow_atomics_wait = true;
278
+
279
+ /**
280
+ * Termination is postponed when there is no active SafeForTerminationScope.
281
+ */
282
+ bool only_terminate_in_safe_scope = false;
283
+
284
+ /**
285
+ * The following parameters describe the offsets for addressing type info
286
+ * for wrapped API objects and are used by the fast C API
287
+ * (for details see v8-fast-api-calls.h).
288
+ */
289
+ int embedder_wrapper_type_index = -1;
290
+ int embedder_wrapper_object_index = -1;
291
+
292
+ /**
293
+ * Callbacks to invoke in case of fatal or OOM errors.
294
+ */
295
+ FatalErrorCallback fatal_error_callback = nullptr;
296
+ OOMErrorCallback oom_error_callback = nullptr;
297
+ };
298
+
299
+ /**
300
+ * Stack-allocated class which sets the isolate for all operations
301
+ * executed within a local scope.
302
+ */
303
+ class V8_EXPORT V8_NODISCARD Scope {
304
+ public:
305
+ explicit Scope(Isolate* isolate) : v8_isolate_(isolate) {
306
+ v8_isolate_->Enter();
307
+ }
308
+
309
+ ~Scope() { v8_isolate_->Exit(); }
310
+
311
+ // Prevent copying of Scope objects.
312
+ Scope(const Scope&) = delete;
313
+ Scope& operator=(const Scope&) = delete;
314
+
315
+ private:
316
+ Isolate* const v8_isolate_;
317
+ };
318
+
319
+ /**
320
+ * Assert that no Javascript code is invoked.
321
+ */
322
+ class V8_EXPORT V8_NODISCARD DisallowJavascriptExecutionScope {
323
+ public:
324
+ enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
325
+
326
+ DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
327
+ ~DisallowJavascriptExecutionScope();
328
+
329
+ // Prevent copying of Scope objects.
330
+ DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope&) =
331
+ delete;
332
+ DisallowJavascriptExecutionScope& operator=(
333
+ const DisallowJavascriptExecutionScope&) = delete;
334
+
335
+ private:
336
+ OnFailure on_failure_;
337
+ v8::Isolate* v8_isolate_;
338
+
339
+ bool was_execution_allowed_assert_;
340
+ bool was_execution_allowed_throws_;
341
+ bool was_execution_allowed_dump_;
342
+ };
343
+
344
+ /**
345
+ * Introduce exception to DisallowJavascriptExecutionScope.
346
+ */
347
+ class V8_EXPORT V8_NODISCARD AllowJavascriptExecutionScope {
348
+ public:
349
+ explicit AllowJavascriptExecutionScope(Isolate* isolate);
350
+ ~AllowJavascriptExecutionScope();
351
+
352
+ // Prevent copying of Scope objects.
353
+ AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope&) =
354
+ delete;
355
+ AllowJavascriptExecutionScope& operator=(
356
+ const AllowJavascriptExecutionScope&) = delete;
357
+
358
+ private:
359
+ Isolate* v8_isolate_;
360
+ bool was_execution_allowed_assert_;
361
+ bool was_execution_allowed_throws_;
362
+ bool was_execution_allowed_dump_;
363
+ };
364
+
365
+ /**
366
+ * Do not run microtasks while this scope is active, even if microtasks are
367
+ * automatically executed otherwise.
368
+ */
369
+ class V8_EXPORT V8_NODISCARD SuppressMicrotaskExecutionScope {
370
+ public:
371
+ explicit SuppressMicrotaskExecutionScope(
372
+ Isolate* isolate, MicrotaskQueue* microtask_queue = nullptr);
373
+ ~SuppressMicrotaskExecutionScope();
374
+
375
+ // Prevent copying of Scope objects.
376
+ SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope&) =
377
+ delete;
378
+ SuppressMicrotaskExecutionScope& operator=(
379
+ const SuppressMicrotaskExecutionScope&) = delete;
380
+
381
+ private:
382
+ internal::Isolate* const i_isolate_;
383
+ internal::MicrotaskQueue* const microtask_queue_;
384
+ internal::Address previous_stack_height_;
385
+
386
+ friend class internal::ThreadLocalTop;
387
+ };
388
+
389
+ /**
390
+ * This scope allows terminations inside direct V8 API calls and forbid them
391
+ * inside any recursive API calls without explicit SafeForTerminationScope.
392
+ */
393
+ class V8_EXPORT V8_NODISCARD SafeForTerminationScope {
394
+ public:
395
+ explicit SafeForTerminationScope(v8::Isolate* v8_isolate);
396
+ ~SafeForTerminationScope();
397
+
398
+ // Prevent copying of Scope objects.
399
+ SafeForTerminationScope(const SafeForTerminationScope&) = delete;
400
+ SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
401
+
402
+ private:
403
+ internal::Isolate* i_isolate_;
404
+ bool prev_value_;
405
+ };
406
+
407
+ /**
408
+ * Types of garbage collections that can be requested via
409
+ * RequestGarbageCollectionForTesting.
410
+ */
411
+ enum GarbageCollectionType {
412
+ kFullGarbageCollection,
413
+ kMinorGarbageCollection
414
+ };
415
+
416
+ /**
417
+ * Features reported via the SetUseCounterCallback callback. Do not change
418
+ * assigned numbers of existing items; add new features to the end of this
419
+ * list.
420
+ */
421
+ enum UseCounterFeature {
422
+ kUseAsm = 0,
423
+ kBreakIterator = 1,
424
+ kLegacyConst = 2,
425
+ kMarkDequeOverflow = 3,
426
+ kStoreBufferOverflow = 4,
427
+ kSlotsBufferOverflow = 5,
428
+ kObjectObserve = 6,
429
+ kForcedGC = 7,
430
+ kSloppyMode = 8,
431
+ kStrictMode = 9,
432
+ kStrongMode = 10,
433
+ kRegExpPrototypeStickyGetter = 11,
434
+ kRegExpPrototypeToString = 12,
435
+ kRegExpPrototypeUnicodeGetter = 13,
436
+ kIntlV8Parse = 14,
437
+ kIntlPattern = 15,
438
+ kIntlResolved = 16,
439
+ kPromiseChain = 17,
440
+ kPromiseAccept = 18,
441
+ kPromiseDefer = 19,
442
+ kHtmlCommentInExternalScript = 20,
443
+ kHtmlComment = 21,
444
+ kSloppyModeBlockScopedFunctionRedefinition = 22,
445
+ kForInInitializer = 23,
446
+ kArrayProtectorDirtied = 24,
447
+ kArraySpeciesModified = 25,
448
+ kArrayPrototypeConstructorModified = 26,
449
+ kArrayInstanceProtoModified = 27,
450
+ kArrayInstanceConstructorModified = 28,
451
+ kLegacyFunctionDeclaration = 29,
452
+ kRegExpPrototypeSourceGetter = 30, // Unused.
453
+ kRegExpPrototypeOldFlagGetter = 31, // Unused.
454
+ kDecimalWithLeadingZeroInStrictMode = 32,
455
+ kLegacyDateParser = 33,
456
+ kDefineGetterOrSetterWouldThrow = 34,
457
+ kFunctionConstructorReturnedUndefined = 35,
458
+ kAssigmentExpressionLHSIsCallInSloppy = 36,
459
+ kAssigmentExpressionLHSIsCallInStrict = 37,
460
+ kPromiseConstructorReturnedUndefined = 38,
461
+ kConstructorNonUndefinedPrimitiveReturn = 39,
462
+ kLabeledExpressionStatement = 40,
463
+ kLineOrParagraphSeparatorAsLineTerminator = 41,
464
+ kIndexAccessor = 42,
465
+ kErrorCaptureStackTrace = 43,
466
+ kErrorPrepareStackTrace = 44,
467
+ kErrorStackTraceLimit = 45,
468
+ kWebAssemblyInstantiation = 46,
469
+ kDeoptimizerDisableSpeculation = 47,
470
+ kArrayPrototypeSortJSArrayModifiedPrototype = 48,
471
+ kFunctionTokenOffsetTooLongForToString = 49,
472
+ kWasmSharedMemory = 50,
473
+ kWasmThreadOpcodes = 51,
474
+ kAtomicsNotify = 52, // Unused.
475
+ kAtomicsWake = 53, // Unused.
476
+ kCollator = 54,
477
+ kNumberFormat = 55,
478
+ kDateTimeFormat = 56,
479
+ kPluralRules = 57,
480
+ kRelativeTimeFormat = 58,
481
+ kLocale = 59,
482
+ kListFormat = 60,
483
+ kSegmenter = 61,
484
+ kStringLocaleCompare = 62,
485
+ kStringToLocaleUpperCase = 63,
486
+ kStringToLocaleLowerCase = 64,
487
+ kNumberToLocaleString = 65,
488
+ kDateToLocaleString = 66,
489
+ kDateToLocaleDateString = 67,
490
+ kDateToLocaleTimeString = 68,
491
+ kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
492
+ kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
493
+ kOptimizedFunctionWithOneShotBytecode = 71, // Unused.
494
+ kRegExpMatchIsTrueishOnNonJSRegExp = 72,
495
+ kRegExpMatchIsFalseishOnJSRegExp = 73,
496
+ kDateGetTimezoneOffset = 74, // Unused.
497
+ kStringNormalize = 75,
498
+ kCallSiteAPIGetFunctionSloppyCall = 76,
499
+ kCallSiteAPIGetThisSloppyCall = 77,
500
+ kRegExpMatchAllWithNonGlobalRegExp = 78,
501
+ kRegExpExecCalledOnSlowRegExp = 79,
502
+ kRegExpReplaceCalledOnSlowRegExp = 80,
503
+ kDisplayNames = 81,
504
+ kSharedArrayBufferConstructed = 82,
505
+ kArrayPrototypeHasElements = 83,
506
+ kObjectPrototypeHasElements = 84,
507
+ kNumberFormatStyleUnit = 85,
508
+ kDateTimeFormatRange = 86,
509
+ kDateTimeFormatDateTimeStyle = 87,
510
+ kBreakIteratorTypeWord = 88,
511
+ kBreakIteratorTypeLine = 89,
512
+ kInvalidatedArrayBufferDetachingProtector = 90,
513
+ kInvalidatedArrayConstructorProtector = 91,
514
+ kInvalidatedArrayIteratorLookupChainProtector = 92,
515
+ kInvalidatedArraySpeciesLookupChainProtector = 93,
516
+ kInvalidatedIsConcatSpreadableLookupChainProtector = 94,
517
+ kInvalidatedMapIteratorLookupChainProtector = 95,
518
+ kInvalidatedNoElementsProtector = 96,
519
+ kInvalidatedPromiseHookProtector = 97,
520
+ kInvalidatedPromiseResolveLookupChainProtector = 98,
521
+ kInvalidatedPromiseSpeciesLookupChainProtector = 99,
522
+ kInvalidatedPromiseThenLookupChainProtector = 100,
523
+ kInvalidatedRegExpSpeciesLookupChainProtector = 101,
524
+ kInvalidatedSetIteratorLookupChainProtector = 102,
525
+ kInvalidatedStringIteratorLookupChainProtector = 103,
526
+ kInvalidatedStringLengthOverflowLookupChainProtector = 104,
527
+ kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
528
+ kWasmSimdOpcodes = 106,
529
+ kVarRedeclaredCatchBinding = 107,
530
+ kWasmRefTypes = 108,
531
+ kWasmBulkMemory = 109, // Unused.
532
+ kWasmMultiValue = 110,
533
+ kWasmExceptionHandling = 111,
534
+ kInvalidatedMegaDOMProtector = 112,
535
+ kFunctionPrototypeArguments = 113,
536
+ kFunctionPrototypeCaller = 114,
537
+ kTurboFanOsrCompileStarted = 115,
538
+ kAsyncStackTaggingCreateTaskCall = 116,
539
+ kDurationFormat = 117,
540
+
541
+ // If you add new values here, you'll also need to update Chromium's:
542
+ // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
543
+ // this list need to be landed first, then changes on the Chromium side.
544
+ kUseCounterFeatureCount // This enum value must be last.
545
+ };
546
+
547
+ enum MessageErrorLevel {
548
+ kMessageLog = (1 << 0),
549
+ kMessageDebug = (1 << 1),
550
+ kMessageInfo = (1 << 2),
551
+ kMessageError = (1 << 3),
552
+ kMessageWarning = (1 << 4),
553
+ kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
554
+ kMessageWarning,
555
+ };
556
+
557
+ using UseCounterCallback = void (*)(Isolate* isolate,
558
+ UseCounterFeature feature);
559
+
560
+ /**
561
+ * Allocates a new isolate but does not initialize it. Does not change the
562
+ * currently entered isolate.
563
+ *
564
+ * Only Isolate::GetData() and Isolate::SetData(), which access the
565
+ * embedder-controlled parts of the isolate, are allowed to be called on the
566
+ * uninitialized isolate. To initialize the isolate, call
567
+ * Isolate::Initialize().
568
+ *
569
+ * When an isolate is no longer used its resources should be freed
570
+ * by calling Dispose(). Using the delete operator is not allowed.
571
+ *
572
+ * V8::Initialize() must have run prior to this.
573
+ */
574
+ static Isolate* Allocate();
575
+
576
+ /**
577
+ * Initialize an Isolate previously allocated by Isolate::Allocate().
578
+ */
579
+ static void Initialize(Isolate* isolate, const CreateParams& params);
580
+
581
+ /**
582
+ * Creates a new isolate. Does not change the currently entered
583
+ * isolate.
584
+ *
585
+ * When an isolate is no longer used its resources should be freed
586
+ * by calling Dispose(). Using the delete operator is not allowed.
587
+ *
588
+ * V8::Initialize() must have run prior to this.
589
+ */
590
+ static Isolate* New(const CreateParams& params);
591
+
592
+ /**
593
+ * Returns the entered isolate for the current thread or NULL in
594
+ * case there is no current isolate.
595
+ *
596
+ * This method must not be invoked before V8::Initialize() was invoked.
597
+ */
598
+ static Isolate* GetCurrent();
599
+
600
+ /**
601
+ * Returns the entered isolate for the current thread or NULL in
602
+ * case there is no current isolate.
603
+ *
604
+ * No checks are performed by this method.
605
+ */
606
+ static Isolate* TryGetCurrent();
607
+
608
+ /**
609
+ * Return true if this isolate is currently active.
610
+ **/
611
+ bool IsCurrent() const;
612
+
613
+ /**
614
+ * Clears the set of objects held strongly by the heap. This set of
615
+ * objects are originally built when a WeakRef is created or
616
+ * successfully dereferenced.
617
+ *
618
+ * This is invoked automatically after microtasks are run. See
619
+ * MicrotasksPolicy for when microtasks are run.
620
+ *
621
+ * This needs to be manually invoked only if the embedder is manually running
622
+ * microtasks via a custom MicrotaskQueue class's PerformCheckpoint. In that
623
+ * case, it is the embedder's responsibility to make this call at a time which
624
+ * does not interrupt synchronous ECMAScript code execution.
625
+ */
626
+ void ClearKeptObjects();
627
+
628
+ /**
629
+ * Custom callback used by embedders to help V8 determine if it should abort
630
+ * when it throws and no internal handler is predicted to catch the
631
+ * exception. If --abort-on-uncaught-exception is used on the command line,
632
+ * then V8 will abort if either:
633
+ * - no custom callback is set.
634
+ * - the custom callback set returns true.
635
+ * Otherwise, the custom callback will not be called and V8 will not abort.
636
+ */
637
+ using AbortOnUncaughtExceptionCallback = bool (*)(Isolate*);
638
+ void SetAbortOnUncaughtExceptionCallback(
639
+ AbortOnUncaughtExceptionCallback callback);
640
+
641
+ /**
642
+ * This specifies the callback called by the upcoming dynamic
643
+ * import() language feature to load modules.
644
+ */
645
+ void SetHostImportModuleDynamicallyCallback(
646
+ HostImportModuleDynamicallyCallback callback);
647
+
648
+ /**
649
+ * This specifies the callback called by the upcoming import.meta
650
+ * language feature to retrieve host-defined meta data for a module.
651
+ */
652
+ void SetHostInitializeImportMetaObjectCallback(
653
+ HostInitializeImportMetaObjectCallback callback);
654
+
655
+ /**
656
+ * This specifies the callback called by the upcoming ShadowRealm
657
+ * construction language feature to retrieve host created globals.
658
+ */
659
+ void SetHostCreateShadowRealmContextCallback(
660
+ HostCreateShadowRealmContextCallback callback);
661
+
662
+ /**
663
+ * This specifies the callback called when the stack property of Error
664
+ * is accessed.
665
+ */
666
+ void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
667
+
668
+ /**
669
+ * Optional notification that the system is running low on memory.
670
+ * V8 uses these notifications to guide heuristics.
671
+ * It is allowed to call this function from another thread while
672
+ * the isolate is executing long running JavaScript code.
673
+ */
674
+ void MemoryPressureNotification(MemoryPressureLevel level);
675
+
676
+ /**
677
+ * Drop non-essential caches. Should only be called from testing code.
678
+ * The method can potentially block for a long time and does not necessarily
679
+ * trigger GC.
680
+ */
681
+ void ClearCachesForTesting();
682
+
683
+ /**
684
+ * Methods below this point require holding a lock (using Locker) in
685
+ * a multi-threaded environment.
686
+ */
687
+
688
+ /**
689
+ * Sets this isolate as the entered one for the current thread.
690
+ * Saves the previously entered one (if any), so that it can be
691
+ * restored when exiting. Re-entering an isolate is allowed.
692
+ */
693
+ void Enter();
694
+
695
+ /**
696
+ * Exits this isolate by restoring the previously entered one in the
697
+ * current thread. The isolate may still stay the same, if it was
698
+ * entered more than once.
699
+ *
700
+ * Requires: this == Isolate::GetCurrent().
701
+ */
702
+ void Exit();
703
+
704
+ /**
705
+ * Disposes the isolate. The isolate must not be entered by any
706
+ * thread to be disposable.
707
+ */
708
+ void Dispose();
709
+
710
+ /**
711
+ * Dumps activated low-level V8 internal stats. This can be used instead
712
+ * of performing a full isolate disposal.
713
+ */
714
+ void DumpAndResetStats();
715
+
716
+ /**
717
+ * Discards all V8 thread-specific data for the Isolate. Should be used
718
+ * if a thread is terminating and it has used an Isolate that will outlive
719
+ * the thread -- all thread-specific data for an Isolate is discarded when
720
+ * an Isolate is disposed so this call is pointless if an Isolate is about
721
+ * to be Disposed.
722
+ */
723
+ void DiscardThreadSpecificMetadata();
724
+
725
+ /**
726
+ * Associate embedder-specific data with the isolate. |slot| has to be
727
+ * between 0 and GetNumberOfDataSlots() - 1.
728
+ */
729
+ V8_INLINE void SetData(uint32_t slot, void* data);
730
+
731
+ /**
732
+ * Retrieve embedder-specific data from the isolate.
733
+ * Returns NULL if SetData has never been called for the given |slot|.
734
+ */
735
+ V8_INLINE void* GetData(uint32_t slot);
736
+
737
+ /**
738
+ * Returns the maximum number of available embedder data slots. Valid slots
739
+ * are in the range of 0 - GetNumberOfDataSlots() - 1.
740
+ */
741
+ V8_INLINE static uint32_t GetNumberOfDataSlots();
742
+
743
+ /**
744
+ * Return data that was previously attached to the isolate snapshot via
745
+ * SnapshotCreator, and removes the reference to it.
746
+ * Repeated call with the same index returns an empty MaybeLocal.
747
+ */
748
+ template <class T>
749
+ V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
750
+
751
+ /**
752
+ * Get statistics about the heap memory usage.
753
+ */
754
+ void GetHeapStatistics(HeapStatistics* heap_statistics);
755
+
756
+ /**
757
+ * Returns the number of spaces in the heap.
758
+ */
759
+ size_t NumberOfHeapSpaces();
760
+
761
+ /**
762
+ * Get the memory usage of a space in the heap.
763
+ *
764
+ * \param space_statistics The HeapSpaceStatistics object to fill in
765
+ * statistics.
766
+ * \param index The index of the space to get statistics from, which ranges
767
+ * from 0 to NumberOfHeapSpaces() - 1.
768
+ * \returns true on success.
769
+ */
770
+ bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
771
+ size_t index);
772
+
773
+ /**
774
+ * Returns the number of types of objects tracked in the heap at GC.
775
+ */
776
+ size_t NumberOfTrackedHeapObjectTypes();
777
+
778
+ /**
779
+ * Get statistics about objects in the heap.
780
+ *
781
+ * \param object_statistics The HeapObjectStatistics object to fill in
782
+ * statistics of objects of given type, which were live in the previous GC.
783
+ * \param type_index The index of the type of object to fill details about,
784
+ * which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1.
785
+ * \returns true on success.
786
+ */
787
+ bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
788
+ size_t type_index);
789
+
790
+ /**
791
+ * Get statistics about code and its metadata in the heap.
792
+ *
793
+ * \param object_statistics The HeapCodeStatistics object to fill in
794
+ * statistics of code, bytecode and their metadata.
795
+ * \returns true on success.
796
+ */
797
+ bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
798
+
799
+ /**
800
+ * This API is experimental and may change significantly.
801
+ *
802
+ * Enqueues a memory measurement request and invokes the delegate with the
803
+ * results.
804
+ *
805
+ * \param delegate the delegate that defines which contexts to measure and
806
+ * reports the results.
807
+ *
808
+ * \param execution promptness executing the memory measurement.
809
+ * The kEager value is expected to be used only in tests.
810
+ */
811
+ bool MeasureMemory(
812
+ std::unique_ptr<MeasureMemoryDelegate> delegate,
813
+ MeasureMemoryExecution execution = MeasureMemoryExecution::kDefault);
814
+
815
+ /**
816
+ * Get a call stack sample from the isolate.
817
+ * \param state Execution state.
818
+ * \param frames Caller allocated buffer to store stack frames.
819
+ * \param frames_limit Maximum number of frames to capture. The buffer must
820
+ * be large enough to hold the number of frames.
821
+ * \param sample_info The sample info is filled up by the function
822
+ * provides number of actual captured stack frames and
823
+ * the current VM state.
824
+ * \note GetStackSample should only be called when the JS thread is paused or
825
+ * interrupted. Otherwise the behavior is undefined.
826
+ */
827
+ void GetStackSample(const RegisterState& state, void** frames,
828
+ size_t frames_limit, SampleInfo* sample_info);
829
+
830
+ /**
831
+ * Adjusts the amount of registered external memory. Used to give V8 an
832
+ * indication of the amount of externally allocated memory that is kept alive
833
+ * by JavaScript objects. V8 uses this to decide when to perform global
834
+ * garbage collections. Registering externally allocated memory will trigger
835
+ * global garbage collections more often than it would otherwise in an attempt
836
+ * to garbage collect the JavaScript objects that keep the externally
837
+ * allocated memory alive.
838
+ *
839
+ * \param change_in_bytes the change in externally allocated memory that is
840
+ * kept alive by JavaScript objects.
841
+ * \returns the adjusted value.
842
+ */
843
+ int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
844
+
845
+ /**
846
+ * Returns heap profiler for this isolate. Will return NULL until the isolate
847
+ * is initialized.
848
+ */
849
+ HeapProfiler* GetHeapProfiler();
850
+
851
+ /**
852
+ * Tells the VM whether the embedder is idle or not.
853
+ */
854
+ void SetIdle(bool is_idle);
855
+
856
+ /** Returns the ArrayBuffer::Allocator used in this isolate. */
857
+ ArrayBuffer::Allocator* GetArrayBufferAllocator();
858
+
859
+ /** Returns true if this isolate has a current context. */
860
+ bool InContext();
861
+
862
+ /**
863
+ * Returns the context of the currently running JavaScript, or the context
864
+ * on the top of the stack if no JavaScript is running.
865
+ */
866
+ Local<Context> GetCurrentContext();
867
+
868
+ /**
869
+ * Returns either the last context entered through V8's C++ API, or the
870
+ * context of the currently running microtask while processing microtasks.
871
+ * If a context is entered while executing a microtask, that context is
872
+ * returned.
873
+ */
874
+ Local<Context> GetEnteredOrMicrotaskContext();
875
+
876
+ /**
877
+ * Returns the Context that corresponds to the Incumbent realm in HTML spec.
878
+ * https://html.spec.whatwg.org/multipage/webappapis.html#incumbent
879
+ */
880
+ Local<Context> GetIncumbentContext();
881
+
882
+ /**
883
+ * Schedules a v8::Exception::Error with the given message.
884
+ * See ThrowException for more details. Templatized to provide compile-time
885
+ * errors in case of too long strings (see v8::String::NewFromUtf8Literal).
886
+ */
887
+ template <int N>
888
+ Local<Value> ThrowError(const char (&message)[N]) {
889
+ return ThrowError(String::NewFromUtf8Literal(this, message));
890
+ }
891
+ Local<Value> ThrowError(Local<String> message);
892
+
893
+ /**
894
+ * Schedules an exception to be thrown when returning to JavaScript. When an
895
+ * exception has been scheduled it is illegal to invoke any JavaScript
896
+ * operation; the caller must return immediately and only after the exception
897
+ * has been handled does it become legal to invoke JavaScript operations.
898
+ */
899
+ Local<Value> ThrowException(Local<Value> exception);
900
+
901
+ using GCCallback = void (*)(Isolate* isolate, GCType type,
902
+ GCCallbackFlags flags);
903
+ using GCCallbackWithData = void (*)(Isolate* isolate, GCType type,
904
+ GCCallbackFlags flags, void* data);
905
+
906
+ /**
907
+ * Enables the host application to receive a notification before a
908
+ * garbage collection. Allocations are allowed in the callback function,
909
+ * but the callback is not re-entrant: if the allocation inside it will
910
+ * trigger the garbage collection, the callback won't be called again.
911
+ * It is possible to specify the GCType filter for your callback. But it is
912
+ * not possible to register the same callback function two times with
913
+ * different GCType filters.
914
+ */
915
+ void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
916
+ GCType gc_type_filter = kGCTypeAll);
917
+ void AddGCPrologueCallback(GCCallback callback,
918
+ GCType gc_type_filter = kGCTypeAll);
919
+
920
+ /**
921
+ * This function removes callback which was installed by
922
+ * AddGCPrologueCallback function.
923
+ */
924
+ void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
925
+ void RemoveGCPrologueCallback(GCCallback callback);
926
+
927
+ START_ALLOW_USE_DEPRECATED()
928
+ /**
929
+ * Sets the embedder heap tracer for the isolate.
930
+ * SetEmbedderHeapTracer cannot be used simultaneously with AttachCppHeap.
931
+ */
932
+ void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
933
+
934
+ /*
935
+ * Gets the currently active heap tracer for the isolate that was set with
936
+ * SetEmbedderHeapTracer.
937
+ */
938
+ EmbedderHeapTracer* GetEmbedderHeapTracer();
939
+ END_ALLOW_USE_DEPRECATED()
940
+
941
+ /**
942
+ * Sets an embedder roots handle that V8 should consider when performing
943
+ * non-unified heap garbage collections.
944
+ *
945
+ * Using only EmbedderHeapTracer automatically sets up a default handler.
946
+ * The intended use case is for setting a custom handler after invoking
947
+ * `AttachCppHeap()`.
948
+ *
949
+ * V8 does not take ownership of the handler.
950
+ */
951
+ void SetEmbedderRootsHandler(EmbedderRootsHandler* handler);
952
+
953
+ /**
954
+ * Attaches a managed C++ heap as an extension to the JavaScript heap. The
955
+ * embedder maintains ownership of the CppHeap. At most one C++ heap can be
956
+ * attached to V8.
957
+ *
958
+ * AttachCppHeap cannot be used simultaneously with SetEmbedderHeapTracer.
959
+ *
960
+ * Multi-threaded use requires the use of v8::Locker/v8::Unlocker, see
961
+ * CppHeap.
962
+ */
963
+ void AttachCppHeap(CppHeap*);
964
+
965
+ /**
966
+ * Detaches a managed C++ heap if one was attached using `AttachCppHeap()`.
967
+ */
968
+ void DetachCppHeap();
969
+
970
+ /**
971
+ * \returns the C++ heap managed by V8. Only available if such a heap has been
972
+ * attached using `AttachCppHeap()`.
973
+ */
974
+ CppHeap* GetCppHeap() const;
975
+
976
+ /**
977
+ * Use for |AtomicsWaitCallback| to indicate the type of event it receives.
978
+ */
979
+ enum class AtomicsWaitEvent {
980
+ /** Indicates that this call is happening before waiting. */
981
+ kStartWait,
982
+ /** `Atomics.wait()` finished because of an `Atomics.wake()` call. */
983
+ kWokenUp,
984
+ /** `Atomics.wait()` finished because it timed out. */
985
+ kTimedOut,
986
+ /** `Atomics.wait()` was interrupted through |TerminateExecution()|. */
987
+ kTerminatedExecution,
988
+ /** `Atomics.wait()` was stopped through |AtomicsWaitWakeHandle|. */
989
+ kAPIStopped,
990
+ /** `Atomics.wait()` did not wait, as the initial condition was not met. */
991
+ kNotEqual
992
+ };
993
+
994
+ /**
995
+ * Passed to |AtomicsWaitCallback| as a means of stopping an ongoing
996
+ * `Atomics.wait` call.
997
+ */
998
+ class V8_EXPORT AtomicsWaitWakeHandle {
999
+ public:
1000
+ /**
1001
+ * Stop this `Atomics.wait()` call and call the |AtomicsWaitCallback|
1002
+ * with |kAPIStopped|.
1003
+ *
1004
+ * This function may be called from another thread. The caller has to ensure
1005
+ * through proper synchronization that it is not called after
1006
+ * the finishing |AtomicsWaitCallback|.
1007
+ *
1008
+ * Note that the ECMAScript specification does not plan for the possibility
1009
+ * of wakeups that are neither coming from a timeout or an `Atomics.wake()`
1010
+ * call, so this may invalidate assumptions made by existing code.
1011
+ * The embedder may accordingly wish to schedule an exception in the
1012
+ * finishing |AtomicsWaitCallback|.
1013
+ */
1014
+ void Wake();
1015
+ };
1016
+
1017
+ /**
1018
+ * Embedder callback for `Atomics.wait()` that can be added through
1019
+ * |SetAtomicsWaitCallback|.
1020
+ *
1021
+ * This will be called just before starting to wait with the |event| value
1022
+ * |kStartWait| and after finishing waiting with one of the other
1023
+ * values of |AtomicsWaitEvent| inside of an `Atomics.wait()` call.
1024
+ *
1025
+ * |array_buffer| will refer to the underlying SharedArrayBuffer,
1026
+ * |offset_in_bytes| to the location of the waited-on memory address inside
1027
+ * the SharedArrayBuffer.
1028
+ *
1029
+ * |value| and |timeout_in_ms| will be the values passed to
1030
+ * the `Atomics.wait()` call. If no timeout was used, |timeout_in_ms|
1031
+ * will be `INFINITY`.
1032
+ *
1033
+ * In the |kStartWait| callback, |stop_handle| will be an object that
1034
+ * is only valid until the corresponding finishing callback and that
1035
+ * can be used to stop the wait process while it is happening.
1036
+ *
1037
+ * This callback may schedule exceptions, *unless* |event| is equal to
1038
+ * |kTerminatedExecution|.
1039
+ */
1040
+ using AtomicsWaitCallback = void (*)(AtomicsWaitEvent event,
1041
+ Local<SharedArrayBuffer> array_buffer,
1042
+ size_t offset_in_bytes, int64_t value,
1043
+ double timeout_in_ms,
1044
+ AtomicsWaitWakeHandle* stop_handle,
1045
+ void* data);
1046
+
1047
+ /**
1048
+ * Set a new |AtomicsWaitCallback|. This overrides an earlier
1049
+ * |AtomicsWaitCallback|, if there was any. If |callback| is nullptr,
1050
+ * this unsets the callback. |data| will be passed to the callback
1051
+ * as its last parameter.
1052
+ */
1053
+ void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
1054
+
1055
+ /**
1056
+ * Enables the host application to receive a notification after a
1057
+ * garbage collection. Allocations are allowed in the callback function,
1058
+ * but the callback is not re-entrant: if the allocation inside it will
1059
+ * trigger the garbage collection, the callback won't be called again.
1060
+ * It is possible to specify the GCType filter for your callback. But it is
1061
+ * not possible to register the same callback function two times with
1062
+ * different GCType filters.
1063
+ */
1064
+ void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
1065
+ GCType gc_type_filter = kGCTypeAll);
1066
+ void AddGCEpilogueCallback(GCCallback callback,
1067
+ GCType gc_type_filter = kGCTypeAll);
1068
+
1069
+ /**
1070
+ * This function removes callback which was installed by
1071
+ * AddGCEpilogueCallback function.
1072
+ */
1073
+ void RemoveGCEpilogueCallback(GCCallbackWithData callback,
1074
+ void* data = nullptr);
1075
+ void RemoveGCEpilogueCallback(GCCallback callback);
1076
+
1077
+ using GetExternallyAllocatedMemoryInBytesCallback = size_t (*)();
1078
+
1079
+ /**
1080
+ * Set the callback that tells V8 how much memory is currently allocated
1081
+ * externally of the V8 heap. Ideally this memory is somehow connected to V8
1082
+ * objects and may get freed-up when the corresponding V8 objects get
1083
+ * collected by a V8 garbage collection.
1084
+ */
1085
+ void SetGetExternallyAllocatedMemoryInBytesCallback(
1086
+ GetExternallyAllocatedMemoryInBytesCallback callback);
1087
+
1088
+ /**
1089
+ * Forcefully terminate the current thread of JavaScript execution
1090
+ * in the given isolate.
1091
+ *
1092
+ * This method can be used by any thread even if that thread has not
1093
+ * acquired the V8 lock with a Locker object.
1094
+ */
1095
+ void TerminateExecution();
1096
+
1097
+ /**
1098
+ * Is V8 terminating JavaScript execution.
1099
+ *
1100
+ * Returns true if JavaScript execution is currently terminating
1101
+ * because of a call to TerminateExecution. In that case there are
1102
+ * still JavaScript frames on the stack and the termination
1103
+ * exception is still active.
1104
+ */
1105
+ bool IsExecutionTerminating();
1106
+
1107
+ /**
1108
+ * Resume execution capability in the given isolate, whose execution
1109
+ * was previously forcefully terminated using TerminateExecution().
1110
+ *
1111
+ * When execution is forcefully terminated using TerminateExecution(),
1112
+ * the isolate can not resume execution until all JavaScript frames
1113
+ * have propagated the uncatchable exception which is generated. This
1114
+ * method allows the program embedding the engine to handle the
1115
+ * termination event and resume execution capability, even if
1116
+ * JavaScript frames remain on the stack.
1117
+ *
1118
+ * This method can be used by any thread even if that thread has not
1119
+ * acquired the V8 lock with a Locker object.
1120
+ */
1121
+ void CancelTerminateExecution();
1122
+
1123
+ /**
1124
+ * Request V8 to interrupt long running JavaScript code and invoke
1125
+ * the given |callback| passing the given |data| to it. After |callback|
1126
+ * returns control will be returned to the JavaScript code.
1127
+ * There may be a number of interrupt requests in flight.
1128
+ * Can be called from another thread without acquiring a |Locker|.
1129
+ * Registered |callback| must not reenter interrupted Isolate.
1130
+ */
1131
+ void RequestInterrupt(InterruptCallback callback, void* data);
1132
+
1133
+ /**
1134
+ * Returns true if there is ongoing background work within V8 that will
1135
+ * eventually post a foreground task, like asynchronous WebAssembly
1136
+ * compilation.
1137
+ */
1138
+ bool HasPendingBackgroundTasks();
1139
+
1140
+ /**
1141
+ * Request garbage collection in this Isolate. It is only valid to call this
1142
+ * function if --expose_gc was specified.
1143
+ *
1144
+ * This should only be used for testing purposes and not to enforce a garbage
1145
+ * collection schedule. It has strong negative impact on the garbage
1146
+ * collection performance. Use IdleNotificationDeadline() or
1147
+ * LowMemoryNotification() instead to influence the garbage collection
1148
+ * schedule.
1149
+ */
1150
+ void RequestGarbageCollectionForTesting(GarbageCollectionType type);
1151
+
1152
+ /**
1153
+ * Request garbage collection with a specific embedderstack state in this
1154
+ * Isolate. It is only valid to call this function if --expose_gc was
1155
+ * specified.
1156
+ *
1157
+ * This should only be used for testing purposes and not to enforce a garbage
1158
+ * collection schedule. It has strong negative impact on the garbage
1159
+ * collection performance. Use IdleNotificationDeadline() or
1160
+ * LowMemoryNotification() instead to influence the garbage collection
1161
+ * schedule.
1162
+ */
1163
+ void RequestGarbageCollectionForTesting(GarbageCollectionType type,
1164
+ StackState stack_state);
1165
+
1166
+ /**
1167
+ * Set the callback to invoke for logging event.
1168
+ */
1169
+ void SetEventLogger(LogEventCallback that);
1170
+
1171
+ /**
1172
+ * Adds a callback to notify the host application right before a script
1173
+ * is about to run. If a script re-enters the runtime during executing, the
1174
+ * BeforeCallEnteredCallback is invoked for each re-entrance.
1175
+ * Executing scripts inside the callback will re-trigger the callback.
1176
+ */
1177
+ void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1178
+
1179
+ /**
1180
+ * Removes callback that was installed by AddBeforeCallEnteredCallback.
1181
+ */
1182
+ void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1183
+
1184
+ /**
1185
+ * Adds a callback to notify the host application when a script finished
1186
+ * running. If a script re-enters the runtime during executing, the
1187
+ * CallCompletedCallback is only invoked when the outer-most script
1188
+ * execution ends. Executing scripts inside the callback do not trigger
1189
+ * further callbacks.
1190
+ */
1191
+ void AddCallCompletedCallback(CallCompletedCallback callback);
1192
+
1193
+ /**
1194
+ * Removes callback that was installed by AddCallCompletedCallback.
1195
+ */
1196
+ void RemoveCallCompletedCallback(CallCompletedCallback callback);
1197
+
1198
+ /**
1199
+ * Set the PromiseHook callback for various promise lifecycle
1200
+ * events.
1201
+ */
1202
+ void SetPromiseHook(PromiseHook hook);
1203
+
1204
+ /**
1205
+ * Set callback to notify about promise reject with no handler, or
1206
+ * revocation of such a previous notification once the handler is added.
1207
+ */
1208
+ void SetPromiseRejectCallback(PromiseRejectCallback callback);
1209
+
1210
+ /**
1211
+ * Runs the default MicrotaskQueue until it gets empty and perform other
1212
+ * microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
1213
+ * the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
1214
+ * callbacks are swallowed.
1215
+ */
1216
+ void PerformMicrotaskCheckpoint();
1217
+
1218
+ /**
1219
+ * Enqueues the callback to the default MicrotaskQueue
1220
+ */
1221
+ void EnqueueMicrotask(Local<Function> microtask);
1222
+
1223
+ /**
1224
+ * Enqueues the callback to the default MicrotaskQueue
1225
+ */
1226
+ void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
1227
+
1228
+ /**
1229
+ * Controls how Microtasks are invoked. See MicrotasksPolicy for details.
1230
+ */
1231
+ void SetMicrotasksPolicy(MicrotasksPolicy policy);
1232
+
1233
+ /**
1234
+ * Returns the policy controlling how Microtasks are invoked.
1235
+ */
1236
+ MicrotasksPolicy GetMicrotasksPolicy() const;
1237
+
1238
+ /**
1239
+ * Adds a callback to notify the host application after
1240
+ * microtasks were run on the default MicrotaskQueue. The callback is
1241
+ * triggered by explicit RunMicrotasks call or automatic microtasks execution
1242
+ * (see SetMicrotaskPolicy).
1243
+ *
1244
+ * Callback will trigger even if microtasks were attempted to run,
1245
+ * but the microtasks queue was empty and no single microtask was actually
1246
+ * executed.
1247
+ *
1248
+ * Executing scripts inside the callback will not re-trigger microtasks and
1249
+ * the callback.
1250
+ */
1251
+ void AddMicrotasksCompletedCallback(
1252
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1253
+
1254
+ /**
1255
+ * Removes callback that was installed by AddMicrotasksCompletedCallback.
1256
+ */
1257
+ void RemoveMicrotasksCompletedCallback(
1258
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1259
+
1260
+ /**
1261
+ * Sets a callback for counting the number of times a feature of V8 is used.
1262
+ */
1263
+ void SetUseCounterCallback(UseCounterCallback callback);
1264
+
1265
+ /**
1266
+ * Enables the host application to provide a mechanism for recording
1267
+ * statistics counters.
1268
+ */
1269
+ void SetCounterFunction(CounterLookupCallback);
1270
+
1271
+ /**
1272
+ * Enables the host application to provide a mechanism for recording
1273
+ * histograms. The CreateHistogram function returns a
1274
+ * histogram which will later be passed to the AddHistogramSample
1275
+ * function.
1276
+ */
1277
+ void SetCreateHistogramFunction(CreateHistogramCallback);
1278
+ void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
1279
+
1280
+ /**
1281
+ * Enables the host application to provide a mechanism for recording
1282
+ * event based metrics. In order to use this interface
1283
+ * include/v8-metrics.h
1284
+ * needs to be included and the recorder needs to be derived from the
1285
+ * Recorder base class defined there.
1286
+ * This method can only be called once per isolate and must happen during
1287
+ * isolate initialization before background threads are spawned.
1288
+ */
1289
+ void SetMetricsRecorder(
1290
+ const std::shared_ptr<metrics::Recorder>& metrics_recorder);
1291
+
1292
+ /**
1293
+ * Enables the host application to provide a mechanism for recording a
1294
+ * predefined set of data as crash keys to be used in postmortem debugging in
1295
+ * case of a crash.
1296
+ */
1297
+ void SetAddCrashKeyCallback(AddCrashKeyCallback);
1298
+
1299
+ /**
1300
+ * Optional notification that the embedder is idle.
1301
+ * V8 uses the notification to perform garbage collection.
1302
+ * This call can be used repeatedly if the embedder remains idle.
1303
+ * Returns true if the embedder should stop calling IdleNotificationDeadline
1304
+ * until real work has been done. This indicates that V8 has done
1305
+ * as much cleanup as it will be able to do.
1306
+ *
1307
+ * The deadline_in_seconds argument specifies the deadline V8 has to finish
1308
+ * garbage collection work. deadline_in_seconds is compared with
1309
+ * MonotonicallyIncreasingTime() and should be based on the same timebase as
1310
+ * that function. There is no guarantee that the actual work will be done
1311
+ * within the time limit.
1312
+ */
1313
+ bool IdleNotificationDeadline(double deadline_in_seconds);
1314
+
1315
+ /**
1316
+ * Optional notification that the system is running low on memory.
1317
+ * V8 uses these notifications to attempt to free memory.
1318
+ */
1319
+ void LowMemoryNotification();
1320
+
1321
+ /**
1322
+ * Optional notification that a context has been disposed. V8 uses these
1323
+ * notifications to guide the GC heuristic and cancel FinalizationRegistry
1324
+ * cleanup tasks. Returns the number of context disposals - including this one
1325
+ * - since the last time V8 had a chance to clean up.
1326
+ *
1327
+ * The optional parameter |dependant_context| specifies whether the disposed
1328
+ * context was depending on state from other contexts or not.
1329
+ */
1330
+ int ContextDisposedNotification(bool dependant_context = true);
1331
+
1332
+ /**
1333
+ * Optional notification that the isolate switched to the foreground.
1334
+ * V8 uses these notifications to guide heuristics.
1335
+ */
1336
+ void IsolateInForegroundNotification();
1337
+
1338
+ /**
1339
+ * Optional notification that the isolate switched to the background.
1340
+ * V8 uses these notifications to guide heuristics.
1341
+ */
1342
+ void IsolateInBackgroundNotification();
1343
+
1344
+ /**
1345
+ * Optional notification which will enable the memory savings mode.
1346
+ * V8 uses this notification to guide heuristics which may result in a
1347
+ * smaller memory footprint at the cost of reduced runtime performance.
1348
+ */
1349
+ void EnableMemorySavingsMode();
1350
+
1351
+ /**
1352
+ * Optional notification which will disable the memory savings mode.
1353
+ */
1354
+ void DisableMemorySavingsMode();
1355
+
1356
+ /**
1357
+ * Optional notification to tell V8 the current performance requirements
1358
+ * of the embedder based on RAIL.
1359
+ * V8 uses these notifications to guide heuristics.
1360
+ * This is an unfinished experimental feature. Semantics and implementation
1361
+ * may change frequently.
1362
+ */
1363
+ void SetRAILMode(RAILMode rail_mode);
1364
+
1365
+ /**
1366
+ * Update load start time of the RAIL mode
1367
+ */
1368
+ void UpdateLoadStartTime();
1369
+
1370
+ /**
1371
+ * Optional notification to tell V8 the current isolate is used for debugging
1372
+ * and requires higher heap limit.
1373
+ */
1374
+ void IncreaseHeapLimitForDebugging();
1375
+
1376
+ /**
1377
+ * Restores the original heap limit after IncreaseHeapLimitForDebugging().
1378
+ */
1379
+ void RestoreOriginalHeapLimit();
1380
+
1381
+ /**
1382
+ * Returns true if the heap limit was increased for debugging and the
1383
+ * original heap limit was not restored yet.
1384
+ */
1385
+ bool IsHeapLimitIncreasedForDebugging();
1386
+
1387
+ /**
1388
+ * Allows the host application to provide the address of a function that is
1389
+ * notified each time code is added, moved or removed.
1390
+ *
1391
+ * \param options options for the JIT code event handler.
1392
+ * \param event_handler the JIT code event handler, which will be invoked
1393
+ * each time code is added, moved or removed.
1394
+ * \note \p event_handler won't get notified of existent code.
1395
+ * \note since code removal notifications are not currently issued, the
1396
+ * \p event_handler may get notifications of code that overlaps earlier
1397
+ * code notifications. This happens when code areas are reused, and the
1398
+ * earlier overlapping code areas should therefore be discarded.
1399
+ * \note the events passed to \p event_handler and the strings they point to
1400
+ * are not guaranteed to live past each call. The \p event_handler must
1401
+ * copy strings and other parameters it needs to keep around.
1402
+ * \note the set of events declared in JitCodeEvent::EventType is expected to
1403
+ * grow over time, and the JitCodeEvent structure is expected to accrue
1404
+ * new members. The \p event_handler function must ignore event codes
1405
+ * it does not recognize to maintain future compatibility.
1406
+ * \note Use Isolate::CreateParams to get events for code executed during
1407
+ * Isolate setup.
1408
+ */
1409
+ void SetJitCodeEventHandler(JitCodeEventOptions options,
1410
+ JitCodeEventHandler event_handler);
1411
+
1412
+ /**
1413
+ * Modifies the stack limit for this Isolate.
1414
+ *
1415
+ * \param stack_limit An address beyond which the Vm's stack may not grow.
1416
+ *
1417
+ * \note If you are using threads then you should hold the V8::Locker lock
1418
+ * while setting the stack limit and you must set a non-default stack
1419
+ * limit separately for each thread.
1420
+ */
1421
+ void SetStackLimit(uintptr_t stack_limit);
1422
+
1423
+ /**
1424
+ * Returns a memory range that can potentially contain jitted code. Code for
1425
+ * V8's 'builtins' will not be in this range if embedded builtins is enabled.
1426
+ *
1427
+ * On Win64, embedders are advised to install function table callbacks for
1428
+ * these ranges, as default SEH won't be able to unwind through jitted code.
1429
+ * The first page of the code range is reserved for the embedder and is
1430
+ * committed, writable, and executable, to be used to store unwind data, as
1431
+ * documented in
1432
+ * https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64.
1433
+ *
1434
+ * Might be empty on other platforms.
1435
+ *
1436
+ * https://code.google.com/p/v8/issues/detail?id=3598
1437
+ */
1438
+ void GetCodeRange(void** start, size_t* length_in_bytes);
1439
+
1440
+ /**
1441
+ * As GetCodeRange, but for embedded builtins (these live in a distinct
1442
+ * memory region from other V8 Code objects).
1443
+ */
1444
+ void GetEmbeddedCodeRange(const void** start, size_t* length_in_bytes);
1445
+
1446
+ /**
1447
+ * Returns the JSEntryStubs necessary for use with the Unwinder API.
1448
+ */
1449
+ JSEntryStubs GetJSEntryStubs();
1450
+
1451
+ static constexpr size_t kMinCodePagesBufferSize = 32;
1452
+
1453
+ /**
1454
+ * Copies the code heap pages currently in use by V8 into |code_pages_out|.
1455
+ * |code_pages_out| must have at least kMinCodePagesBufferSize capacity and
1456
+ * must be empty.
1457
+ *
1458
+ * Signal-safe, does not allocate, does not access the V8 heap.
1459
+ * No code on the stack can rely on pages that might be missing.
1460
+ *
1461
+ * Returns the number of pages available to be copied, which might be greater
1462
+ * than |capacity|. In this case, only |capacity| pages will be copied into
1463
+ * |code_pages_out|. The caller should provide a bigger buffer on the next
1464
+ * call in order to get all available code pages, but this is not required.
1465
+ */
1466
+ size_t CopyCodePages(size_t capacity, MemoryRange* code_pages_out);
1467
+
1468
+ /** Set the callback to invoke in case of fatal errors. */
1469
+ void SetFatalErrorHandler(FatalErrorCallback that);
1470
+
1471
+ /** Set the callback to invoke in case of OOM errors. */
1472
+ void SetOOMErrorHandler(OOMErrorCallback that);
1473
+
1474
+ /**
1475
+ * Add a callback to invoke in case the heap size is close to the heap limit.
1476
+ * If multiple callbacks are added, only the most recently added callback is
1477
+ * invoked.
1478
+ */
1479
+ void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
1480
+
1481
+ /**
1482
+ * Remove the given callback and restore the heap limit to the
1483
+ * given limit. If the given limit is zero, then it is ignored.
1484
+ * If the current heap size is greater than the given limit,
1485
+ * then the heap limit is restored to the minimal limit that
1486
+ * is possible for the current heap size.
1487
+ */
1488
+ void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
1489
+ size_t heap_limit);
1490
+
1491
+ /**
1492
+ * If the heap limit was changed by the NearHeapLimitCallback, then the
1493
+ * initial heap limit will be restored once the heap size falls below the
1494
+ * given threshold percentage of the initial heap limit.
1495
+ * The threshold percentage is a number in (0.0, 1.0) range.
1496
+ */
1497
+ void AutomaticallyRestoreInitialHeapLimit(double threshold_percent = 0.5);
1498
+
1499
+ /**
1500
+ * Set the callback to invoke to check if code generation from
1501
+ * strings should be allowed.
1502
+ */
1503
+ void SetModifyCodeGenerationFromStringsCallback(
1504
+ ModifyCodeGenerationFromStringsCallback2 callback);
1505
+
1506
+ /**
1507
+ * Set the callback to invoke to check if wasm code generation should
1508
+ * be allowed.
1509
+ */
1510
+ void SetAllowWasmCodeGenerationCallback(
1511
+ AllowWasmCodeGenerationCallback callback);
1512
+
1513
+ /**
1514
+ * Embedder over{ride|load} injection points for wasm APIs. The expectation
1515
+ * is that the embedder sets them at most once.
1516
+ */
1517
+ void SetWasmModuleCallback(ExtensionCallback callback);
1518
+ void SetWasmInstanceCallback(ExtensionCallback callback);
1519
+
1520
+ void SetWasmStreamingCallback(WasmStreamingCallback callback);
1521
+
1522
+ void SetWasmAsyncResolvePromiseCallback(
1523
+ WasmAsyncResolvePromiseCallback callback);
1524
+
1525
+ void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback);
1526
+
1527
+ V8_DEPRECATED("Wasm SIMD is always enabled")
1528
+ void SetWasmSimdEnabledCallback(WasmSimdEnabledCallback callback);
1529
+
1530
+ V8_DEPRECATED("Wasm exceptions are always enabled")
1531
+ void SetWasmExceptionsEnabledCallback(WasmExceptionsEnabledCallback callback);
1532
+
1533
+ void SetSharedArrayBufferConstructorEnabledCallback(
1534
+ SharedArrayBufferConstructorEnabledCallback callback);
1535
+
1536
+ /**
1537
+ * This function can be called by the embedder to signal V8 that the dynamic
1538
+ * enabling of features has finished. V8 can now set up dynamically added
1539
+ * features.
1540
+ */
1541
+ void InstallConditionalFeatures(Local<Context> context);
1542
+
1543
+ /**
1544
+ * Check if V8 is dead and therefore unusable. This is the case after
1545
+ * fatal errors such as out-of-memory situations.
1546
+ */
1547
+ bool IsDead();
1548
+
1549
+ /**
1550
+ * Adds a message listener (errors only).
1551
+ *
1552
+ * The same message listener can be added more than once and in that
1553
+ * case it will be called more than once for each message.
1554
+ *
1555
+ * If data is specified, it will be passed to the callback when it is called.
1556
+ * Otherwise, the exception object will be passed to the callback instead.
1557
+ */
1558
+ bool AddMessageListener(MessageCallback that,
1559
+ Local<Value> data = Local<Value>());
1560
+
1561
+ /**
1562
+ * Adds a message listener.
1563
+ *
1564
+ * The same message listener can be added more than once and in that
1565
+ * case it will be called more than once for each message.
1566
+ *
1567
+ * If data is specified, it will be passed to the callback when it is called.
1568
+ * Otherwise, the exception object will be passed to the callback instead.
1569
+ *
1570
+ * A listener can listen for particular error levels by providing a mask.
1571
+ */
1572
+ bool AddMessageListenerWithErrorLevel(MessageCallback that,
1573
+ int message_levels,
1574
+ Local<Value> data = Local<Value>());
1575
+
1576
+ /**
1577
+ * Remove all message listeners from the specified callback function.
1578
+ */
1579
+ void RemoveMessageListeners(MessageCallback that);
1580
+
1581
+ /** Callback function for reporting failed access checks.*/
1582
+ void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
1583
+
1584
+ /**
1585
+ * Tells V8 to capture current stack trace when uncaught exception occurs
1586
+ * and report it to the message listeners. The option is off by default.
1587
+ */
1588
+ void SetCaptureStackTraceForUncaughtExceptions(
1589
+ bool capture, int frame_limit = 10,
1590
+ StackTrace::StackTraceOptions options = StackTrace::kOverview);
1591
+
1592
+ /**
1593
+ * Iterates through all external resources referenced from current isolate
1594
+ * heap. GC is not invoked prior to iterating, therefore there is no
1595
+ * guarantee that visited objects are still alive.
1596
+ */
1597
+ void VisitExternalResources(ExternalResourceVisitor* visitor);
1598
+
1599
+ /**
1600
+ * Check if this isolate is in use.
1601
+ * True if at least one thread Enter'ed this isolate.
1602
+ */
1603
+ bool IsInUse();
1604
+
1605
+ /**
1606
+ * Set whether calling Atomics.wait (a function that may block) is allowed in
1607
+ * this isolate. This can also be configured via
1608
+ * CreateParams::allow_atomics_wait.
1609
+ */
1610
+ void SetAllowAtomicsWait(bool allow);
1611
+
1612
+ /**
1613
+ * Time zone redetection indicator for
1614
+ * DateTimeConfigurationChangeNotification.
1615
+ *
1616
+ * kSkip indicates V8 that the notification should not trigger redetecting
1617
+ * host time zone. kRedetect indicates V8 that host time zone should be
1618
+ * redetected, and used to set the default time zone.
1619
+ *
1620
+ * The host time zone detection may require file system access or similar
1621
+ * operations unlikely to be available inside a sandbox. If v8 is run inside a
1622
+ * sandbox, the host time zone has to be detected outside the sandbox before
1623
+ * calling DateTimeConfigurationChangeNotification function.
1624
+ */
1625
+ enum class TimeZoneDetection { kSkip, kRedetect, kCustom };
1626
+
1627
+ /**
1628
+ * Notification that the embedder has changed the time zone, daylight savings
1629
+ * time or other date / time configuration parameters. V8 keeps a cache of
1630
+ * various values used for date / time computation. This notification will
1631
+ * reset those cached values for the current context so that date / time
1632
+ * configuration changes would be reflected.
1633
+ *
1634
+ * This API should not be called more than needed as it will negatively impact
1635
+ * the performance of date operations.
1636
+ */
1637
+ void DateTimeConfigurationChangeNotification(
1638
+ TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip,
1639
+ const char* custom_timezone_id = nullptr);
1640
+
1641
+ /**
1642
+ * Notification that the embedder has changed the locale. V8 keeps a cache of
1643
+ * various values used for locale computation. This notification will reset
1644
+ * those cached values for the current context so that locale configuration
1645
+ * changes would be reflected.
1646
+ *
1647
+ * This API should not be called more than needed as it will negatively impact
1648
+ * the performance of locale operations.
1649
+ */
1650
+ void LocaleConfigurationChangeNotification();
1651
+
1652
+ Isolate() = delete;
1653
+ ~Isolate() = delete;
1654
+ Isolate(const Isolate&) = delete;
1655
+ Isolate& operator=(const Isolate&) = delete;
1656
+ // Deleting operator new and delete here is allowed as ctor and dtor is also
1657
+ // deleted.
1658
+ void* operator new(size_t size) = delete;
1659
+ void* operator new[](size_t size) = delete;
1660
+ void operator delete(void*, size_t) = delete;
1661
+ void operator delete[](void*, size_t) = delete;
1662
+
1663
+ private:
1664
+ template <class K, class V, class Traits>
1665
+ friend class PersistentValueMapBase;
1666
+
1667
+ internal::Address* GetDataFromSnapshotOnce(size_t index);
1668
+ void ReportExternalAllocationLimitReached();
1669
+ };
1670
+
1671
+ void Isolate::SetData(uint32_t slot, void* data) {
1672
+ using I = internal::Internals;
1673
+ I::SetEmbedderData(this, slot, data);
1674
+ }
1675
+
1676
+ void* Isolate::GetData(uint32_t slot) {
1677
+ using I = internal::Internals;
1678
+ return I::GetEmbedderData(this, slot);
1679
+ }
1680
+
1681
+ uint32_t Isolate::GetNumberOfDataSlots() {
1682
+ using I = internal::Internals;
1683
+ return I::kNumIsolateDataSlots;
1684
+ }
1685
+
1686
+ template <class T>
1687
+ MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
1688
+ T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
1689
+ if (data) internal::PerformCastCheck(data);
1690
+ return Local<T>(data);
1691
+ }
1692
+
1693
+ } // namespace v8
1694
+
1695
+ #endif // INCLUDE_V8_ISOLATE_H_