@downdraft/native-mobile-android-arm64 0.0.0 → 0.1.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 (138) hide show
  1. package/README.md +7 -0
  2. package/include/node/cppgc/allocation.h +308 -0
  3. package/include/node/cppgc/common.h +28 -0
  4. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  5. package/include/node/cppgc/custom-space.h +97 -0
  6. package/include/node/cppgc/default-platform.h +68 -0
  7. package/include/node/cppgc/explicit-management.h +100 -0
  8. package/include/node/cppgc/garbage-collected.h +114 -0
  9. package/include/node/cppgc/heap-consistency.h +309 -0
  10. package/include/node/cppgc/heap-handle.h +48 -0
  11. package/include/node/cppgc/heap-state.h +82 -0
  12. package/include/node/cppgc/heap-statistics.h +126 -0
  13. package/include/node/cppgc/heap.h +202 -0
  14. package/include/node/cppgc/internal/api-constants.h +75 -0
  15. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  16. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  17. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  18. package/include/node/cppgc/internal/caged-heap.h +64 -0
  19. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  20. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  21. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  22. package/include/node/cppgc/internal/gc-info.h +150 -0
  23. package/include/node/cppgc/internal/logging.h +50 -0
  24. package/include/node/cppgc/internal/member-storage.h +305 -0
  25. package/include/node/cppgc/internal/name-trait.h +141 -0
  26. package/include/node/cppgc/internal/persistent-node.h +219 -0
  27. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  28. package/include/node/cppgc/internal/write-barrier.h +487 -0
  29. package/include/node/cppgc/liveness-broker.h +78 -0
  30. package/include/node/cppgc/macros.h +56 -0
  31. package/include/node/cppgc/member.h +669 -0
  32. package/include/node/cppgc/name-provider.h +75 -0
  33. package/include/node/cppgc/object-size-trait.h +58 -0
  34. package/include/node/cppgc/persistent.h +376 -0
  35. package/include/node/cppgc/platform.h +174 -0
  36. package/include/node/cppgc/prefinalizer.h +75 -0
  37. package/include/node/cppgc/process-heap-statistics.h +36 -0
  38. package/include/node/cppgc/sentinel-pointer.h +39 -0
  39. package/include/node/cppgc/source-location.h +16 -0
  40. package/include/node/cppgc/tagged-member.h +114 -0
  41. package/include/node/cppgc/testing.h +106 -0
  42. package/include/node/cppgc/trace-trait.h +127 -0
  43. package/include/node/cppgc/type-traits.h +272 -0
  44. package/include/node/cppgc/visitor.h +534 -0
  45. package/include/node/js_native_api.h +634 -0
  46. package/include/node/js_native_api_types.h +244 -0
  47. package/include/node/libplatform/libplatform-export.h +29 -0
  48. package/include/node/libplatform/libplatform.h +112 -0
  49. package/include/node/libplatform/v8-tracing.h +343 -0
  50. package/include/node/node.h +1744 -0
  51. package/include/node/node_api.h +265 -0
  52. package/include/node/node_api_types.h +58 -0
  53. package/include/node/node_buffer.h +94 -0
  54. package/include/node/node_object_wrap.h +145 -0
  55. package/include/node/node_version.h +116 -0
  56. package/include/node/uv/aix.h +32 -0
  57. package/include/node/uv/bsd.h +34 -0
  58. package/include/node/uv/darwin.h +61 -0
  59. package/include/node/uv/errno.h +483 -0
  60. package/include/node/uv/linux.h +34 -0
  61. package/include/node/uv/os390.h +33 -0
  62. package/include/node/uv/posix.h +31 -0
  63. package/include/node/uv/sunos.h +44 -0
  64. package/include/node/uv/threadpool.h +37 -0
  65. package/include/node/uv/tree.h +521 -0
  66. package/include/node/uv/unix.h +509 -0
  67. package/include/node/uv/version.h +43 -0
  68. package/include/node/uv/win.h +698 -0
  69. package/include/node/uv.h +1994 -0
  70. package/include/node/v8-array-buffer.h +646 -0
  71. package/include/node/v8-callbacks.h +533 -0
  72. package/include/node/v8-container.h +183 -0
  73. package/include/node/v8-context.h +580 -0
  74. package/include/node/v8-cpp-heap-external.h +56 -0
  75. package/include/node/v8-cppgc.h +194 -0
  76. package/include/node/v8-data.h +96 -0
  77. package/include/node/v8-date.h +57 -0
  78. package/include/node/v8-debug.h +210 -0
  79. package/include/node/v8-embedder-heap.h +54 -0
  80. package/include/node/v8-embedder-state-scope.h +52 -0
  81. package/include/node/v8-exception.h +298 -0
  82. package/include/node/v8-extension.h +60 -0
  83. package/include/node/v8-external-memory-accounter.h +60 -0
  84. package/include/node/v8-external.h +73 -0
  85. package/include/node/v8-fast-api-calls.h +784 -0
  86. package/include/node/v8-forward.h +82 -0
  87. package/include/node/v8-function-callback.h +708 -0
  88. package/include/node/v8-function.h +148 -0
  89. package/include/node/v8-handle-base.h +155 -0
  90. package/include/node/v8-initialization.h +343 -0
  91. package/include/node/v8-inspector-protocol.h +13 -0
  92. package/include/node/v8-inspector.h +458 -0
  93. package/include/node/v8-internal.h +1827 -0
  94. package/include/node/v8-isolate.h +1925 -0
  95. package/include/node/v8-json.h +54 -0
  96. package/include/node/v8-local-handle.h +884 -0
  97. package/include/node/v8-locker.h +138 -0
  98. package/include/node/v8-maybe.h +185 -0
  99. package/include/node/v8-memory-span.h +273 -0
  100. package/include/node/v8-message.h +215 -0
  101. package/include/node/v8-metrics.h +273 -0
  102. package/include/node/v8-microtask-queue.h +152 -0
  103. package/include/node/v8-microtask.h +28 -0
  104. package/include/node/v8-object.h +1134 -0
  105. package/include/node/v8-persistent-handle.h +556 -0
  106. package/include/node/v8-platform.h +1552 -0
  107. package/include/node/v8-primitive-object.h +118 -0
  108. package/include/node/v8-primitive.h +1056 -0
  109. package/include/node/v8-profiler.h +1401 -0
  110. package/include/node/v8-promise.h +185 -0
  111. package/include/node/v8-proxy.h +49 -0
  112. package/include/node/v8-regexp.h +105 -0
  113. package/include/node/v8-sandbox.h +170 -0
  114. package/include/node/v8-script.h +996 -0
  115. package/include/node/v8-snapshot.h +302 -0
  116. package/include/node/v8-source-location.h +91 -0
  117. package/include/node/v8-statistics.h +246 -0
  118. package/include/node/v8-template.h +1096 -0
  119. package/include/node/v8-trace-categories.h +28 -0
  120. package/include/node/v8-traced-handle.h +420 -0
  121. package/include/node/v8-typed-array.h +386 -0
  122. package/include/node/v8-unwinder-state.h +30 -0
  123. package/include/node/v8-unwinder.h +146 -0
  124. package/include/node/v8-util.h +549 -0
  125. package/include/node/v8-value-serializer-version.h +24 -0
  126. package/include/node/v8-value-serializer.h +316 -0
  127. package/include/node/v8-value.h +674 -0
  128. package/include/node/v8-version-string.h +38 -0
  129. package/include/node/v8-version.h +20 -0
  130. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  131. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  132. package/include/node/v8-wasm.h +325 -0
  133. package/include/node/v8-weak-callback-info.h +88 -0
  134. package/include/node/v8.h +88 -0
  135. package/include/node/v8config.h +1077 -0
  136. package/lib/libc++_shared.so +0 -0
  137. package/lib/libnode.so +4 -0
  138. package/package.json +23 -3
@@ -0,0 +1,1925 @@
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 <functional>
12
+ #include <memory>
13
+ #include <string>
14
+ #include <utility>
15
+
16
+ #include "cppgc/common.h"
17
+ #include "v8-array-buffer.h" // NOLINT(build/include_directory)
18
+ #include "v8-callbacks.h" // NOLINT(build/include_directory)
19
+ #include "v8-data.h" // NOLINT(build/include_directory)
20
+ #include "v8-debug.h" // NOLINT(build/include_directory)
21
+ #include "v8-embedder-heap.h" // NOLINT(build/include_directory)
22
+ #include "v8-exception.h" // NOLINT(build/include_directory)
23
+ #include "v8-function-callback.h" // NOLINT(build/include_directory)
24
+ #include "v8-internal.h" // NOLINT(build/include_directory)
25
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
26
+ #include "v8-microtask.h" // NOLINT(build/include_directory)
27
+ #include "v8-persistent-handle.h" // NOLINT(build/include_directory)
28
+ #include "v8-primitive.h" // NOLINT(build/include_directory)
29
+ #include "v8-statistics.h" // NOLINT(build/include_directory)
30
+ #include "v8-unwinder.h" // NOLINT(build/include_directory)
31
+ #include "v8config.h" // NOLINT(build/include_directory)
32
+
33
+ namespace v8 {
34
+
35
+ class CppHeap;
36
+ class HeapProfiler;
37
+ class MicrotaskQueue;
38
+ class StartupData;
39
+ class ScriptOrModule;
40
+ class SharedArrayBuffer;
41
+
42
+ namespace internal {
43
+ class MicrotaskQueue;
44
+ class ThreadLocalTop;
45
+ } // namespace internal
46
+
47
+ namespace metrics {
48
+ class Recorder;
49
+ } // namespace metrics
50
+
51
+ /**
52
+ * A set of constraints that specifies the limits of the runtime's memory use.
53
+ * You must set the heap size before initializing the VM - the size cannot be
54
+ * adjusted after the VM is initialized.
55
+ *
56
+ * If you are using threads then you should hold the V8::Locker lock while
57
+ * setting the stack limit and you must set a non-default stack limit separately
58
+ * for each thread.
59
+ *
60
+ * The arguments for set_max_semi_space_size, set_max_old_space_size,
61
+ * set_max_executable_size, set_code_range_size specify limits in MB.
62
+ *
63
+ * The argument for set_max_semi_space_size_in_kb is in KB.
64
+ */
65
+ class V8_EXPORT ResourceConstraints {
66
+ public:
67
+ /**
68
+ * Configures the constraints with reasonable default values based on the
69
+ * provided heap size limit. The heap size includes both the young and
70
+ * the old generation.
71
+ *
72
+ * \param initial_heap_size_in_bytes The initial heap size or zero.
73
+ * By default V8 starts with a small heap and dynamically grows it to
74
+ * match the set of live objects. This may lead to ineffective
75
+ * garbage collections at startup if the live set is large.
76
+ * Setting the initial heap size avoids such garbage collections.
77
+ * Note that this does not affect young generation garbage collections.
78
+ *
79
+ * \param maximum_heap_size_in_bytes The hard limit for the heap size.
80
+ * When the heap size approaches this limit, V8 will perform series of
81
+ * garbage collections and invoke the NearHeapLimitCallback. If the garbage
82
+ * collections do not help and the callback does not increase the limit,
83
+ * then V8 will crash with V8::FatalProcessOutOfMemory.
84
+ */
85
+ void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
86
+ size_t maximum_heap_size_in_bytes);
87
+
88
+ /**
89
+ * Configures the constraints with reasonable default values based on the
90
+ * capabilities of the current device the VM is running on.
91
+ *
92
+ * \param physical_memory The total amount of physical memory on the current
93
+ * device, in bytes.
94
+ * \param virtual_memory_limit The amount of virtual memory on the current
95
+ * device, in bytes, or zero, if there is no limit.
96
+ */
97
+ void ConfigureDefaults(uint64_t physical_memory,
98
+ uint64_t virtual_memory_limit);
99
+
100
+ /**
101
+ * The address beyond which the VM's stack may not grow.
102
+ */
103
+ uint32_t* stack_limit() const { return stack_limit_; }
104
+ void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
105
+
106
+ /**
107
+ * The amount of virtual memory reserved for generated code. This is relevant
108
+ * for 64-bit architectures that rely on code range for calls in code.
109
+ *
110
+ * When V8_COMPRESS_POINTERS_IN_SHARED_CAGE is defined, there is a shared
111
+ * process-wide code range that is lazily initialized. This value is used to
112
+ * configure that shared code range when the first Isolate is
113
+ * created. Subsequent Isolates ignore this value.
114
+ */
115
+ size_t code_range_size_in_bytes() const { return code_range_size_; }
116
+ void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
117
+
118
+ /**
119
+ * The maximum size of the old generation.
120
+ * When the old generation approaches this limit, V8 will perform series of
121
+ * garbage collections and invoke the NearHeapLimitCallback.
122
+ * If the garbage collections do not help and the callback does not
123
+ * increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
124
+ */
125
+ size_t max_old_generation_size_in_bytes() const {
126
+ return max_old_generation_size_;
127
+ }
128
+ void set_max_old_generation_size_in_bytes(size_t limit) {
129
+ max_old_generation_size_ = limit;
130
+ }
131
+
132
+ /**
133
+ * The maximum size of the young generation, which consists of two semi-spaces
134
+ * and a large object space. This affects frequency of Scavenge garbage
135
+ * collections and should be typically much smaller that the old generation.
136
+ */
137
+ size_t max_young_generation_size_in_bytes() const {
138
+ return max_young_generation_size_;
139
+ }
140
+ void set_max_young_generation_size_in_bytes(size_t limit) {
141
+ max_young_generation_size_ = limit;
142
+ }
143
+
144
+ size_t initial_old_generation_size_in_bytes() const {
145
+ return initial_old_generation_size_;
146
+ }
147
+ void set_initial_old_generation_size_in_bytes(size_t initial_size) {
148
+ initial_old_generation_size_ = initial_size;
149
+ }
150
+
151
+ size_t initial_young_generation_size_in_bytes() const {
152
+ return initial_young_generation_size_;
153
+ }
154
+ void set_initial_young_generation_size_in_bytes(size_t initial_size) {
155
+ initial_young_generation_size_ = initial_size;
156
+ }
157
+
158
+ uint64_t physical_memory_size_in_bytes() const {
159
+ return physical_memory_size_;
160
+ }
161
+
162
+ private:
163
+ static constexpr size_t kMB = 1048576u;
164
+ size_t code_range_size_ = 0;
165
+ size_t max_old_generation_size_ = 0;
166
+ size_t max_young_generation_size_ = 0;
167
+ size_t initial_old_generation_size_ = 0;
168
+ size_t initial_young_generation_size_ = 0;
169
+ uint64_t physical_memory_size_ = 0;
170
+ uint32_t* stack_limit_ = nullptr;
171
+ };
172
+
173
+ /**
174
+ * Memory pressure level for the MemoryPressureNotification.
175
+ * kNone hints V8 that there is no memory pressure.
176
+ * kModerate hints V8 to speed up incremental garbage collection at the cost of
177
+ * of higher latency due to garbage collection pauses.
178
+ * kCritical hints V8 to free memory as soon as possible. Garbage collection
179
+ * pauses at this level will be large.
180
+ */
181
+ enum class MemoryPressureLevel { kNone, kModerate, kCritical };
182
+
183
+ /**
184
+ * Signal for dependants of contexts. Useful for
185
+ * `ContextDisposedNotification()` to implement different strategies.
186
+ */
187
+ enum class ContextDependants {
188
+ /** Context has no dependants. These are usually top-level contexts. */
189
+ kNoDependants,
190
+ /** Context has some dependants, i.e., it may depend on other contexts. This
191
+ is usually the case for inner contexts. */
192
+ kSomeDependants
193
+ };
194
+
195
+ /**
196
+ * Indicator for the stack state.
197
+ */
198
+ using StackState = cppgc::EmbedderStackState;
199
+
200
+ /**
201
+ * The set of V8 isolates in a process is partitioned into groups. Each group
202
+ * has its own sandbox (if V8 was configured with support for the sandbox) and
203
+ * pointer-compression cage (if configured with pointer compression).
204
+ *
205
+ * By default, all isolates are placed in the same group. This is the most
206
+ * efficient configuration in terms of speed and memory use. However, with
207
+ * pointer compression enabled, total heap usage of isolates in a group
208
+ * cannot exceed 4 GB, not counting array buffers and other off-heap storage.
209
+ * Using multiple isolate groups can allow embedders to allocate more than 4GB
210
+ * of objects with pointer compression enabled, if the embedder's use case can
211
+ * span multiple isolates.
212
+ *
213
+ * Creating an isolate group reserves a range of virtual memory addresses. A
214
+ * group's memory mapping will be released when the last isolate in the group is
215
+ * disposed, and there are no more live IsolateGroup objects that refer to it.
216
+ *
217
+ * Note that Isolate groups are reference counted, and
218
+ * the IsolateGroup type is a reference to one.
219
+ *
220
+ * Note that it's not going to be possible to pass shared JS objects
221
+ * across IsolateGroup boundary.
222
+ *
223
+ */
224
+ class V8_EXPORT IsolateGroup {
225
+ public:
226
+ /**
227
+ * Get the default isolate group. If this V8's build configuration only
228
+ * supports a single group, this is a reference to that single group.
229
+ * Otherwise this is a group like any other, distinguished only
230
+ * in that it is the first group.
231
+ */
232
+ static IsolateGroup GetDefault();
233
+
234
+ /**
235
+ * Return true if new isolate groups can be created at run-time, or false if
236
+ * all isolates must be in the same group.
237
+ */
238
+ static bool CanCreateNewGroups();
239
+
240
+ /**
241
+ * Create a new isolate group. If this V8's build configuration only supports
242
+ * a single group, abort.
243
+ */
244
+ static IsolateGroup Create();
245
+
246
+ IsolateGroup(IsolateGroup&& other);
247
+ IsolateGroup& operator=(IsolateGroup&& other);
248
+
249
+ IsolateGroup(const IsolateGroup&);
250
+ IsolateGroup& operator=(const IsolateGroup&);
251
+
252
+ ~IsolateGroup();
253
+
254
+ bool operator==(const IsolateGroup& other) const {
255
+ return isolate_group_ == other.isolate_group_;
256
+ }
257
+
258
+ bool operator!=(const IsolateGroup& other) const {
259
+ return !operator==(other);
260
+ }
261
+
262
+ #ifdef V8_ENABLE_SANDBOX
263
+ /**
264
+ * Whether the sandbox of the isolate group contains a given pointer.
265
+ * Will always return true if the sandbox is not enabled.
266
+ */
267
+ bool SandboxContains(void* pointer) const;
268
+ VirtualAddressSpace* GetSandboxAddressSpace();
269
+ #else
270
+ V8_INLINE bool SandboxContains(void* pointer) const { return true; }
271
+ #endif
272
+
273
+ private:
274
+ friend class Isolate;
275
+ friend class ArrayBuffer::Allocator;
276
+
277
+ // The isolate_group pointer should be already acquired.
278
+ explicit IsolateGroup(internal::IsolateGroup*&& isolate_group);
279
+
280
+ internal::IsolateGroup* isolate_group_;
281
+ };
282
+
283
+ /**
284
+ * Isolate represents an isolated instance of the V8 engine. V8 isolates have
285
+ * completely separate states. Objects from one isolate must not be used in
286
+ * other isolates. The embedder can create multiple isolates and use them in
287
+ * parallel in multiple threads. An isolate can be entered by at most one
288
+ * thread at any given time. The Locker/Unlocker API must be used to
289
+ * synchronize.
290
+ */
291
+ class V8_EXPORT Isolate {
292
+ public:
293
+ /**
294
+ * Initial configuration parameters for a new Isolate.
295
+ */
296
+ struct V8_EXPORT CreateParams {
297
+ CreateParams();
298
+ ~CreateParams();
299
+
300
+ ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(CreateParams)
301
+
302
+ /**
303
+ * Allows the host application to provide the address of a function that is
304
+ * notified each time code is added, moved or removed.
305
+ */
306
+ JitCodeEventHandler code_event_handler = nullptr;
307
+
308
+ /**
309
+ * ResourceConstraints to use for the new Isolate.
310
+ */
311
+ ResourceConstraints constraints;
312
+
313
+ /**
314
+ * Explicitly specify a startup snapshot blob. The embedder owns the blob.
315
+ * The embedder *must* ensure that the snapshot is from a trusted source.
316
+ */
317
+ const StartupData* snapshot_blob = nullptr;
318
+
319
+ /**
320
+ * Enables the host application to provide a mechanism for recording
321
+ * statistics counters.
322
+ */
323
+ CounterLookupCallback counter_lookup_callback = nullptr;
324
+
325
+ /**
326
+ * Enables the host application to provide a mechanism for recording
327
+ * histograms. The CreateHistogram function returns a
328
+ * histogram which will later be passed to the AddHistogramSample
329
+ * function.
330
+ */
331
+ CreateHistogramCallback create_histogram_callback = nullptr;
332
+ AddHistogramSampleCallback add_histogram_sample_callback = nullptr;
333
+
334
+ /**
335
+ * The ArrayBuffer::Allocator to use for allocating and freeing the backing
336
+ * store of ArrayBuffers.
337
+ *
338
+ * If the shared_ptr version is used, the Isolate instance and every
339
+ * |BackingStore| allocated using this allocator hold a std::shared_ptr
340
+ * to the allocator, in order to facilitate lifetime
341
+ * management for the allocator instance.
342
+ */
343
+ ArrayBuffer::Allocator* array_buffer_allocator = nullptr;
344
+ std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
345
+
346
+ /**
347
+ * Specifies an optional nullptr-terminated array of raw addresses in the
348
+ * embedder that V8 can match against during serialization and use for
349
+ * deserialization. This array and its content must stay valid for the
350
+ * entire lifetime of the isolate.
351
+ */
352
+ const intptr_t* external_references = nullptr;
353
+
354
+ /**
355
+ * Whether calling Atomics.wait (a function that may block) is allowed in
356
+ * this isolate. This can also be configured via SetAllowAtomicsWait.
357
+ */
358
+ bool allow_atomics_wait = true;
359
+
360
+ /**
361
+ * Callbacks to invoke in case of fatal or OOM errors.
362
+ */
363
+ FatalErrorCallback fatal_error_callback = nullptr;
364
+ OOMErrorCallback oom_error_callback = nullptr;
365
+
366
+ /**
367
+ * A CppHeap used to construct the Isolate. V8 takes ownership of the
368
+ * CppHeap passed this way.
369
+ */
370
+ CppHeap* cpp_heap = nullptr;
371
+ };
372
+
373
+ /**
374
+ * Stack-allocated class which sets the isolate for all operations
375
+ * executed within a local scope.
376
+ */
377
+ class V8_EXPORT V8_NODISCARD Scope {
378
+ public:
379
+ explicit Scope(Isolate* isolate) : v8_isolate_(isolate) {
380
+ v8_isolate_->Enter();
381
+ }
382
+
383
+ ~Scope() { v8_isolate_->Exit(); }
384
+
385
+ // Prevent copying of Scope objects.
386
+ Scope(const Scope&) = delete;
387
+ Scope& operator=(const Scope&) = delete;
388
+
389
+ private:
390
+ Isolate* const v8_isolate_;
391
+ };
392
+
393
+ /**
394
+ * Assert that no Javascript code is invoked.
395
+ */
396
+ class V8_EXPORT V8_NODISCARD DisallowJavascriptExecutionScope {
397
+ public:
398
+ enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
399
+
400
+ DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
401
+ ~DisallowJavascriptExecutionScope();
402
+
403
+ // Prevent copying of Scope objects.
404
+ DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope&) =
405
+ delete;
406
+ DisallowJavascriptExecutionScope& operator=(
407
+ const DisallowJavascriptExecutionScope&) = delete;
408
+
409
+ private:
410
+ v8::Isolate* const v8_isolate_;
411
+ const OnFailure on_failure_;
412
+ bool was_execution_allowed_;
413
+ };
414
+
415
+ /**
416
+ * Introduce exception to DisallowJavascriptExecutionScope.
417
+ */
418
+ class V8_EXPORT V8_NODISCARD AllowJavascriptExecutionScope {
419
+ public:
420
+ explicit AllowJavascriptExecutionScope(Isolate* isolate);
421
+ ~AllowJavascriptExecutionScope();
422
+
423
+ // Prevent copying of Scope objects.
424
+ AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope&) =
425
+ delete;
426
+ AllowJavascriptExecutionScope& operator=(
427
+ const AllowJavascriptExecutionScope&) = delete;
428
+
429
+ private:
430
+ Isolate* const v8_isolate_;
431
+ bool was_execution_allowed_assert_;
432
+ bool was_execution_allowed_throws_;
433
+ bool was_execution_allowed_dump_;
434
+ };
435
+
436
+ /**
437
+ * Do not run microtasks while this scope is active, even if microtasks are
438
+ * automatically executed otherwise.
439
+ */
440
+ class V8_EXPORT V8_NODISCARD SuppressMicrotaskExecutionScope {
441
+ public:
442
+ explicit SuppressMicrotaskExecutionScope(
443
+ Isolate* isolate, MicrotaskQueue* microtask_queue = nullptr);
444
+ ~SuppressMicrotaskExecutionScope();
445
+
446
+ // Prevent copying of Scope objects.
447
+ SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope&) =
448
+ delete;
449
+ SuppressMicrotaskExecutionScope& operator=(
450
+ const SuppressMicrotaskExecutionScope&) = delete;
451
+
452
+ private:
453
+ internal::Isolate* const i_isolate_;
454
+ internal::MicrotaskQueue* const microtask_queue_;
455
+ internal::Address previous_stack_height_;
456
+
457
+ friend class internal::ThreadLocalTop;
458
+ };
459
+
460
+ /**
461
+ * Types of garbage collections that can be requested via
462
+ * RequestGarbageCollectionForTesting.
463
+ */
464
+ enum GarbageCollectionType {
465
+ kFullGarbageCollection,
466
+ kMinorGarbageCollection
467
+ };
468
+
469
+ /**
470
+ * Features reported via the SetUseCounterCallback callback. Do not change
471
+ * assigned numbers of existing items; add new features to the end of this
472
+ * list.
473
+ * Dead features can be marked `V8_DEPRECATE_SOON`, then `V8_DEPRECATED`, and
474
+ * then finally be renamed to `kOBSOLETE_...` to stop embedders from using
475
+ * them.
476
+ */
477
+ enum UseCounterFeature {
478
+ kUseAsm = 0,
479
+ kBreakIterator = 1,
480
+ kOBSOLETE_LegacyConst = 2,
481
+ kOBSOLETE_MarkDequeOverflow = 3,
482
+ kOBSOLETE_StoreBufferOverflow = 4,
483
+ kOBSOLETE_SlotsBufferOverflow = 5,
484
+ kOBSOLETE_ObjectObserve = 6,
485
+ kForcedGC = 7,
486
+ kSloppyMode = 8,
487
+ kStrictMode = 9,
488
+ kOBSOLETE_StrongMode = 10,
489
+ kRegExpPrototypeStickyGetter = 11,
490
+ kRegExpPrototypeToString = 12,
491
+ kRegExpPrototypeUnicodeGetter = 13,
492
+ kOBSOLETE_IntlV8Parse = 14,
493
+ kOBSOLETE_IntlPattern = 15,
494
+ kOBSOLETE_IntlResolved = 16,
495
+ kOBSOLETE_PromiseChain = 17,
496
+ kOBSOLETE_PromiseAccept = 18,
497
+ kOBSOLETE_PromiseDefer = 19,
498
+ kHtmlCommentInExternalScript = 20,
499
+ kHtmlComment = 21,
500
+ kSloppyModeBlockScopedFunctionRedefinition = 22,
501
+ kForInInitializer = 23,
502
+ kOBSOLETE_ArrayProtectorDirtied = 24,
503
+ kArraySpeciesModified = 25,
504
+ kArrayPrototypeConstructorModified = 26,
505
+ kOBSOLETE_ArrayInstanceProtoModified = 27,
506
+ kArrayInstanceConstructorModified = 28,
507
+ kOBSOLETE_LegacyFunctionDeclaration = 29,
508
+ kOBSOLETE_RegExpPrototypeSourceGetter = 30,
509
+ kOBSOLETE_RegExpPrototypeOldFlagGetter = 31,
510
+ kDecimalWithLeadingZeroInStrictMode = 32,
511
+ kLegacyDateParser = 33,
512
+ kDefineGetterOrSetterWouldThrow = 34,
513
+ kFunctionConstructorReturnedUndefined = 35,
514
+ kAssigmentExpressionLHSIsCallInSloppy = 36,
515
+ kAssigmentExpressionLHSIsCallInStrict = 37,
516
+ kPromiseConstructorReturnedUndefined = 38,
517
+ kOBSOLETE_ConstructorNonUndefinedPrimitiveReturn = 39,
518
+ kOBSOLETE_LabeledExpressionStatement = 40,
519
+ kOBSOLETE_LineOrParagraphSeparatorAsLineTerminator = 41,
520
+ kIndexAccessor = 42,
521
+ kErrorCaptureStackTrace = 43,
522
+ kErrorPrepareStackTrace = 44,
523
+ kErrorStackTraceLimit = 45,
524
+ kWebAssemblyInstantiation = 46,
525
+ kDeoptimizerDisableSpeculation = 47,
526
+ kOBSOLETE_ArrayPrototypeSortJSArrayModifiedPrototype = 48,
527
+ kFunctionTokenOffsetTooLongForToString = 49,
528
+ kWasmSharedMemory = 50,
529
+ kWasmThreadOpcodes = 51,
530
+ kOBSOLETE_AtomicsNotify = 52,
531
+ kOBSOLETE_AtomicsWake = 53,
532
+ kCollator = 54,
533
+ kNumberFormat = 55,
534
+ kDateTimeFormat = 56,
535
+ kPluralRules = 57,
536
+ kRelativeTimeFormat = 58,
537
+ kLocale = 59,
538
+ kListFormat = 60,
539
+ kSegmenter = 61,
540
+ kStringLocaleCompare = 62,
541
+ kOBSOLETE_StringToLocaleUpperCase = 63,
542
+ kStringToLocaleLowerCase = 64,
543
+ kNumberToLocaleString = 65,
544
+ kDateToLocaleString = 66,
545
+ kDateToLocaleDateString = 67,
546
+ kDateToLocaleTimeString = 68,
547
+ kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
548
+ kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
549
+ kOBSOLETE_OptimizedFunctionWithOneShotBytecode = 71,
550
+ kRegExpMatchIsTrueishOnNonJSRegExp = 72,
551
+ kRegExpMatchIsFalseishOnJSRegExp = 73,
552
+ kOBSOLETE_DateGetTimezoneOffset = 74,
553
+ kStringNormalize = 75,
554
+ kCallSiteAPIGetFunctionSloppyCall = 76,
555
+ kCallSiteAPIGetThisSloppyCall = 77,
556
+ kOBSOLETE_RegExpMatchAllWithNonGlobalRegExp = 78,
557
+ kRegExpExecCalledOnSlowRegExp = 79,
558
+ kRegExpReplaceCalledOnSlowRegExp = 80,
559
+ kDisplayNames = 81,
560
+ kSharedArrayBufferConstructed = 82,
561
+ kArrayPrototypeHasElements = 83,
562
+ kObjectPrototypeHasElements = 84,
563
+ kNumberFormatStyleUnit = 85,
564
+ kDateTimeFormatRange = 86,
565
+ kDateTimeFormatDateTimeStyle = 87,
566
+ kBreakIteratorTypeWord = 88,
567
+ kBreakIteratorTypeLine = 89,
568
+ kInvalidatedArrayBufferDetachingProtector = 90,
569
+ kInvalidatedArrayConstructorProtector V8_DEPRECATE_SOON(
570
+ "The ArrayConstructorProtector has been removed") = 91,
571
+ kInvalidatedArrayIteratorLookupChainProtector = 92,
572
+ kInvalidatedArraySpeciesLookupChainProtector = 93,
573
+ kInvalidatedIsConcatSpreadableLookupChainProtector = 94,
574
+ kInvalidatedMapIteratorLookupChainProtector = 95,
575
+ kInvalidatedNoElementsProtector = 96,
576
+ kInvalidatedPromiseHookProtector = 97,
577
+ kInvalidatedPromiseResolveLookupChainProtector = 98,
578
+ kInvalidatedPromiseSpeciesLookupChainProtector = 99,
579
+ kInvalidatedPromiseThenLookupChainProtector = 100,
580
+ kInvalidatedRegExpSpeciesLookupChainProtector = 101,
581
+ kInvalidatedSetIteratorLookupChainProtector = 102,
582
+ kInvalidatedStringIteratorLookupChainProtector = 103,
583
+ kInvalidatedStringLengthOverflowLookupChainProtector = 104,
584
+ kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
585
+ kWasmSimdOpcodes = 106,
586
+ kVarRedeclaredCatchBinding = 107,
587
+ kWasmRefTypes = 108,
588
+ kWasmBulkMemory = 109,
589
+ kWasmMultiValue = 110,
590
+ kWasmExceptionHandling = 111,
591
+ kInvalidatedMegaDOMProtector = 112,
592
+ kFunctionPrototypeArguments = 113,
593
+ kFunctionPrototypeCaller = 114,
594
+ kTurboFanOsrCompileStarted = 115,
595
+ kAsyncStackTaggingCreateTaskCall = 116,
596
+ kDurationFormat = 117,
597
+ kInvalidatedNumberStringNotRegexpLikeProtector = 118,
598
+ kOBSOLETE_RegExpUnicodeSetIncompatibilitiesWithUnicodeMode = 119,
599
+ kOBSOLETE_ImportAssertionDeprecatedSyntax = 120,
600
+ kLocaleInfoObsoletedGetters = 121,
601
+ kLocaleInfoFunctions = 122,
602
+ kCompileHintsMagicAll = 123,
603
+ kInvalidatedNoProfilingProtector = 124,
604
+ kWasmMemory64 = 125,
605
+ kWasmMultiMemory = 126,
606
+ kWasmGC = 127,
607
+ kWasmImportedStrings = 128,
608
+ kSourceMappingUrlMagicCommentAtSign = 129,
609
+ kTemporalObject = 130,
610
+ kWasmModuleCompilation = 131,
611
+ kInvalidatedNoUndetectableObjectsProtector = 132,
612
+ kWasmJavaScriptPromiseIntegration = 133,
613
+ kWasmReturnCall = 134,
614
+ kWasmExtendedConst = 135,
615
+ kWasmRelaxedSimd = 136,
616
+ kWasmTypeReflection = 137,
617
+ kWasmExnRef = 138,
618
+ kWasmTypedFuncRef = 139,
619
+ kInvalidatedStringWrapperToPrimitiveProtector = 140,
620
+ kDocumentAllLegacyCall = 141,
621
+ kDocumentAllLegacyConstruct = 142,
622
+ kConsoleContext = 143,
623
+ kWasmImportedStringsUtf8 = 144,
624
+ kResizableArrayBuffer = 145,
625
+ kGrowableSharedArrayBuffer = 146,
626
+ kArrayByCopy = 147,
627
+ kArrayFromAsync = 148,
628
+ kIteratorMethods = 149,
629
+ kPromiseAny = 150,
630
+ kSetMethods = 151,
631
+ kArrayFindLast = 152,
632
+ kArrayGroup = 153,
633
+ kArrayBufferTransfer = 154,
634
+ kPromiseWithResolvers = 155,
635
+ kAtomicsWaitAsync = 156,
636
+ kExtendingNonExtensibleWithPrivate = 157,
637
+ kPromiseTry = 158,
638
+ kStringReplaceAll = 159,
639
+ kStringWellFormed = 160,
640
+ kWeakReferences = 161,
641
+ kErrorIsError = 162,
642
+ kInvalidatedTypedArrayLengthLookupChainProtector = 163,
643
+ kRegExpEscape = 164,
644
+ kFloat16Array = 165,
645
+ kExplicitResourceManagement = 166,
646
+ kWasmBranchHinting = 167,
647
+ kWasmMutableGlobals = 168,
648
+ kUint8ArrayToFromBase64AndHex = 169,
649
+ kAtomicsPause = 170,
650
+ kTopLevelAwait = 171,
651
+ kLogicalAssignment = 172,
652
+ kNullishCoalescing = 173,
653
+ kInvalidatedNoDateTimeConfigurationChangeProtector = 174,
654
+ kWasmNonTrappingFloatToInt = 175,
655
+ kWasmSignExtensionOps = 176,
656
+ kRegExpCompile = 177,
657
+ kRegExpStaticProperties = 178,
658
+ kRegExpStaticPropertiesWithLastMatch = 179,
659
+ kWithStatement = 180,
660
+ kHtmlWrapperMethods = 181,
661
+ kWasmCustomDescriptors = 182,
662
+ kWasmResizableBuffers = 183,
663
+
664
+ // If you add new values here, you'll also need to update Chromium's:
665
+ // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
666
+ // this list need to be landed first, then changes on the Chromium side.
667
+ kUseCounterFeatureCount // This enum value must be last.
668
+ };
669
+
670
+ enum MessageErrorLevel {
671
+ kMessageLog = (1 << 0),
672
+ kMessageDebug = (1 << 1),
673
+ kMessageInfo = (1 << 2),
674
+ kMessageError = (1 << 3),
675
+ kMessageWarning = (1 << 4),
676
+ kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
677
+ kMessageWarning,
678
+ };
679
+
680
+ // The different priorities that an isolate can have.
681
+ enum class Priority {
682
+ // The isolate does not relate to content that is currently important
683
+ // to the user. Lowest priority.
684
+ kBestEffort,
685
+
686
+ // The isolate contributes to content that is visible to the user, like a
687
+ // visible iframe that's not interacted directly with. High priority.
688
+ kUserVisible,
689
+
690
+ // The isolate contributes to content that is of the utmost importance to
691
+ // the user, like visible content in the focused window. Highest priority.
692
+ kUserBlocking,
693
+ };
694
+
695
+ using UseCounterCallback = void (*)(Isolate* isolate,
696
+ UseCounterFeature feature);
697
+
698
+ /**
699
+ * Allocates a new isolate but does not initialize it. Does not change the
700
+ * currently entered isolate.
701
+ *
702
+ * Only Isolate::GetData() and Isolate::SetData(), which access the
703
+ * embedder-controlled parts of the isolate, as well as Isolate::GetGroup(),
704
+ * are allowed to be called on the uninitialized isolate. To initialize the
705
+ * isolate, call `Isolate::Initialize()` or initialize a `SnapshotCreator`.
706
+ *
707
+ * When an isolate is no longer used its resources should be freed
708
+ * by calling Dispose(). Using the delete operator is not allowed.
709
+ *
710
+ * V8::Initialize() must have run prior to this.
711
+ */
712
+ static Isolate* Allocate();
713
+ static Isolate* Allocate(const IsolateGroup& group);
714
+
715
+ /**
716
+ * Return the group for this isolate.
717
+ */
718
+ IsolateGroup GetGroup() const;
719
+
720
+ /**
721
+ * Initialize an Isolate previously allocated by Isolate::Allocate().
722
+ */
723
+ static void Initialize(Isolate* isolate, const CreateParams& params);
724
+
725
+ /**
726
+ * Creates a new isolate. Does not change the currently entered
727
+ * isolate.
728
+ *
729
+ * When an isolate is no longer used its resources should be freed
730
+ * by calling Dispose(). Using the delete operator is not allowed.
731
+ *
732
+ * V8::Initialize() must have run prior to this.
733
+ */
734
+ static Isolate* New(const CreateParams& params);
735
+ static Isolate* New(const IsolateGroup& group, const CreateParams& params);
736
+
737
+ /**
738
+ * Returns the entered isolate for the current thread or NULL in
739
+ * case there is no current isolate.
740
+ *
741
+ * This method must not be invoked before V8::Initialize() was invoked.
742
+ */
743
+ static Isolate* GetCurrent();
744
+
745
+ /**
746
+ * Returns the entered isolate for the current thread or NULL in
747
+ * case there is no current isolate.
748
+ *
749
+ * No checks are performed by this method.
750
+ */
751
+ static Isolate* TryGetCurrent();
752
+
753
+ /**
754
+ * Return true if this isolate is currently active.
755
+ **/
756
+ bool IsCurrent() const;
757
+
758
+ /**
759
+ * Clears the set of objects held strongly by the heap. This set of
760
+ * objects are originally built when a WeakRef is created or
761
+ * successfully dereferenced.
762
+ *
763
+ * This is invoked automatically after microtasks are run. See
764
+ * MicrotasksPolicy for when microtasks are run.
765
+ *
766
+ * This needs to be manually invoked only if the embedder is manually running
767
+ * microtasks via a custom MicrotaskQueue class's PerformCheckpoint. In that
768
+ * case, it is the embedder's responsibility to make this call at a time which
769
+ * does not interrupt synchronous ECMAScript code execution.
770
+ */
771
+ void ClearKeptObjects();
772
+
773
+ /**
774
+ * Custom callback used by embedders to help V8 determine if it should abort
775
+ * when it throws and no internal handler is predicted to catch the
776
+ * exception. If --abort-on-uncaught-exception is used on the command line,
777
+ * then V8 will abort if either:
778
+ * - no custom callback is set.
779
+ * - the custom callback set returns true.
780
+ * Otherwise, the custom callback will not be called and V8 will not abort.
781
+ */
782
+ using AbortOnUncaughtExceptionCallback = bool (*)(Isolate*);
783
+ void SetAbortOnUncaughtExceptionCallback(
784
+ AbortOnUncaughtExceptionCallback callback);
785
+
786
+ /**
787
+ * This specifies the callback called by the upcoming dynamic
788
+ * import() language feature to load modules.
789
+ */
790
+ void SetHostImportModuleDynamicallyCallback(
791
+ HostImportModuleDynamicallyCallback callback);
792
+
793
+ /**
794
+ * This specifies the callback called by the upcoming dynamic
795
+ * import() and import.source() language feature to load modules.
796
+ *
797
+ * This API is experimental and is expected to be changed or removed in the
798
+ * future. The callback is currently only called when for source-phase
799
+ * imports. Evaluation-phase imports use the existing
800
+ * HostImportModuleDynamicallyCallback callback.
801
+ */
802
+ void SetHostImportModuleWithPhaseDynamicallyCallback(
803
+ HostImportModuleWithPhaseDynamicallyCallback callback);
804
+
805
+ /**
806
+ * This specifies the callback called by the upcoming import.meta
807
+ * language feature to retrieve host-defined meta data for a module.
808
+ */
809
+ void SetHostInitializeImportMetaObjectCallback(
810
+ HostInitializeImportMetaObjectCallback callback);
811
+
812
+ /**
813
+ * This specifies the callback called by the upcoming ShadowRealm
814
+ * construction language feature to retrieve host created globals.
815
+ */
816
+ void SetHostCreateShadowRealmContextCallback(
817
+ HostCreateShadowRealmContextCallback callback);
818
+
819
+ /**
820
+ * Set the callback that checks whether a Error.isError should return true for
821
+ * a JSApiWrapper object, i.e. whether it represents a native JS error. For
822
+ * example, in an HTML embedder, DOMExceptions are considered native errors.
823
+ */
824
+ void SetIsJSApiWrapperNativeErrorCallback(
825
+ IsJSApiWrapperNativeErrorCallback callback);
826
+
827
+ /**
828
+ * This specifies the callback called when the stack property of Error
829
+ * is accessed.
830
+ */
831
+ void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
832
+
833
+ /**
834
+ * Get the stackTraceLimit property of Error.
835
+ */
836
+ int GetStackTraceLimit();
837
+
838
+ #if defined(V8_OS_WIN)
839
+ /**
840
+ * This specifies the callback called when an ETW tracing session starts.
841
+ */
842
+ V8_DEPRECATE_SOON("Use SetFilterETWSessionByURL2Callback instead")
843
+ void SetFilterETWSessionByURLCallback(FilterETWSessionByURLCallback callback);
844
+ void SetFilterETWSessionByURL2Callback(
845
+ FilterETWSessionByURL2Callback callback);
846
+ #endif // V8_OS_WIN
847
+
848
+ /**
849
+ * Optional notification that the system is running low on memory.
850
+ * V8 uses these notifications to guide heuristics.
851
+ * It is allowed to call this function from another thread while
852
+ * the isolate is executing long running JavaScript code.
853
+ */
854
+ void MemoryPressureNotification(MemoryPressureLevel level);
855
+
856
+ /**
857
+ * This triggers garbage collections until either `allocate` succeeds, or
858
+ * until v8 gives up and triggers an OOM error.
859
+ */
860
+ bool RetryCustomAllocate(std::function<bool()> allocate);
861
+
862
+ /**
863
+ * Optional request from the embedder to tune v8 towards energy efficiency
864
+ * rather than speed if `battery_saver_mode_enabled` is true, because the
865
+ * embedder is in battery saver mode. If false, the correct tuning is left
866
+ * to v8 to decide.
867
+ */
868
+ void SetBatterySaverMode(bool battery_saver_mode_enabled);
869
+
870
+ /**
871
+ * Optional request from the embedder to tune v8 towards memory efficiency
872
+ * rather than speed if `memory_saver_mode_enabled` is true, because the
873
+ * embedder is in memory saver mode. If false, the correct tuning is left
874
+ * to v8 to decide.
875
+ */
876
+ void SetMemorySaverMode(bool memory_saver_mode_enabled);
877
+
878
+ /**
879
+ * Drop non-essential caches. Should only be called from testing code.
880
+ * The method can potentially block for a long time and does not necessarily
881
+ * trigger GC.
882
+ */
883
+ void ClearCachesForTesting();
884
+
885
+ /**
886
+ * Methods below this point require holding a lock (using Locker) in
887
+ * a multi-threaded environment.
888
+ */
889
+
890
+ /**
891
+ * Sets this isolate as the entered one for the current thread.
892
+ * Saves the previously entered one (if any), so that it can be
893
+ * restored when exiting. Re-entering an isolate is allowed.
894
+ */
895
+ void Enter();
896
+
897
+ /**
898
+ * Exits this isolate by restoring the previously entered one in the
899
+ * current thread. The isolate may still stay the same, if it was
900
+ * entered more than once.
901
+ *
902
+ * Requires: this == Isolate::GetCurrent().
903
+ */
904
+ void Exit();
905
+
906
+ /**
907
+ * Deinitializes and frees the isolate. The isolate must not be entered by any
908
+ * thread to be disposable.
909
+ */
910
+ void Dispose();
911
+
912
+ /**
913
+ * Deinitializes the isolate, but does not free the address. The isolate must
914
+ * not be entered by any thread to be deinitializable. Embedders must call
915
+ * Isolate::Free() to free the isolate afterwards.
916
+ */
917
+ void Deinitialize();
918
+
919
+ /**
920
+ * Frees the memory allocated for the isolate. Can only be called after the
921
+ * Isolate has already been deinitialized with Isolate::Deinitialize(). After
922
+ * the isolate is freed, the next call to Isolate::New() or
923
+ * Isolate::Allocate() might return the same address that just get freed.
924
+ */
925
+ static void Free(Isolate* isolate);
926
+
927
+ /**
928
+ * Dumps activated low-level V8 internal stats. This can be used instead
929
+ * of performing a full isolate disposal.
930
+ */
931
+ void DumpAndResetStats();
932
+
933
+ /**
934
+ * Discards all V8 thread-specific data for the Isolate. Should be used
935
+ * if a thread is terminating and it has used an Isolate that will outlive
936
+ * the thread -- all thread-specific data for an Isolate is discarded when
937
+ * an Isolate is disposed so this call is pointless if an Isolate is about
938
+ * to be Disposed.
939
+ */
940
+ void DiscardThreadSpecificMetadata();
941
+
942
+ /**
943
+ * Associate embedder-specific data with the isolate. |slot| has to be
944
+ * between 0 and GetNumberOfDataSlots() - 1.
945
+ */
946
+ V8_INLINE void SetData(uint32_t slot, void* data);
947
+
948
+ /**
949
+ * Retrieve embedder-specific data from the isolate.
950
+ * Returns NULL if SetData has never been called for the given |slot|.
951
+ */
952
+ V8_INLINE void* GetData(uint32_t slot);
953
+
954
+ /**
955
+ * Returns the maximum number of available embedder data slots. Valid slots
956
+ * are in the range of 0 - GetNumberOfDataSlots() - 1.
957
+ */
958
+ V8_INLINE static uint32_t GetNumberOfDataSlots();
959
+
960
+ /**
961
+ * Return data that was previously attached to the isolate snapshot via
962
+ * SnapshotCreator, and removes the reference to it.
963
+ * Repeated call with the same index returns an empty MaybeLocal.
964
+ */
965
+ template <class T>
966
+ V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
967
+
968
+ /**
969
+ * Returns the value that was set or restored by
970
+ * SetContinuationPreservedEmbedderData(), if any.
971
+ */
972
+ V8_DEPRECATED("Use GetContinuationPreservedEmbedderDataV2 instead")
973
+ Local<Value> GetContinuationPreservedEmbedderData();
974
+
975
+ /**
976
+ * Sets a value that will be stored on continuations and reset while the
977
+ * continuation runs.
978
+ */
979
+ V8_DEPRECATED("Use SetContinuationPreservedEmbedderDataV2 instead")
980
+ void SetContinuationPreservedEmbedderData(Local<Value> data);
981
+
982
+ /**
983
+ * Returns the value set by `SetContinuationPreservedEmbedderDataV2()` or
984
+ * restored during microtask execution for the currently running continuation,
985
+ * if any. Returns undefiend if no continuation preserved embedder data was
986
+ * set.
987
+ */
988
+ Local<Data> GetContinuationPreservedEmbedderDataV2();
989
+
990
+ /**
991
+ * Sets a value that will be stored on continuations and restored while the
992
+ * continuation runs. If `data` is empty, the continuation preserved embedder
993
+ * data is set to undefined.
994
+ */
995
+ void SetContinuationPreservedEmbedderDataV2(Local<Data> data);
996
+
997
+ /**
998
+ * Get statistics about the heap memory usage.
999
+ */
1000
+ void GetHeapStatistics(HeapStatistics* heap_statistics);
1001
+
1002
+ /**
1003
+ * Returns the number of spaces in the heap.
1004
+ */
1005
+ size_t NumberOfHeapSpaces();
1006
+
1007
+ /**
1008
+ * Get the memory usage of a space in the heap.
1009
+ *
1010
+ * \param space_statistics The HeapSpaceStatistics object to fill in
1011
+ * statistics.
1012
+ * \param index The index of the space to get statistics from, which ranges
1013
+ * from 0 to NumberOfHeapSpaces() - 1.
1014
+ * \returns true on success.
1015
+ */
1016
+ bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
1017
+ size_t index);
1018
+
1019
+ /**
1020
+ * Returns the number of types of objects tracked in the heap at GC.
1021
+ */
1022
+ size_t NumberOfTrackedHeapObjectTypes();
1023
+
1024
+ /**
1025
+ * Get statistics about objects in the heap.
1026
+ *
1027
+ * \param object_statistics The HeapObjectStatistics object to fill in
1028
+ * statistics of objects of given type, which were live in the previous GC.
1029
+ * \param type_index The index of the type of object to fill details about,
1030
+ * which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1.
1031
+ * \returns true on success.
1032
+ */
1033
+ bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
1034
+ size_t type_index);
1035
+
1036
+ /**
1037
+ * Get statistics about code and its metadata in the heap.
1038
+ *
1039
+ * \param object_statistics The HeapCodeStatistics object to fill in
1040
+ * statistics of code, bytecode and their metadata.
1041
+ * \returns true on success.
1042
+ */
1043
+ bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
1044
+
1045
+ /**
1046
+ * This API is experimental and may change significantly.
1047
+ *
1048
+ * Enqueues a memory measurement request and invokes the delegate with the
1049
+ * results.
1050
+ *
1051
+ * \param delegate the delegate that defines which contexts to measure and
1052
+ * reports the results.
1053
+ *
1054
+ * \param execution promptness executing the memory measurement.
1055
+ * The kEager value is expected to be used only in tests.
1056
+ */
1057
+ bool MeasureMemory(
1058
+ std::unique_ptr<MeasureMemoryDelegate> delegate,
1059
+ MeasureMemoryExecution execution = MeasureMemoryExecution::kDefault);
1060
+
1061
+ /**
1062
+ * Get a call stack sample from the isolate.
1063
+ * \param state Execution state.
1064
+ * \param frames Caller allocated buffer to store stack frames.
1065
+ * \param frames_limit Maximum number of frames to capture. The buffer must
1066
+ * be large enough to hold the number of frames.
1067
+ * \param sample_info The sample info is filled up by the function
1068
+ * provides number of actual captured stack frames and
1069
+ * the current VM state.
1070
+ * \note GetStackSample should only be called when the JS thread is paused or
1071
+ * interrupted. Otherwise the behavior is undefined.
1072
+ */
1073
+ void GetStackSample(const RegisterState& state, void** frames,
1074
+ size_t frames_limit, SampleInfo* sample_info);
1075
+
1076
+ /**
1077
+ * Adjusts the amount of registered external memory.
1078
+ *
1079
+ * \param change_in_bytes the change in externally allocated memory that is
1080
+ * kept alive by JavaScript objects.
1081
+ * \returns the adjusted value.
1082
+ */
1083
+ V8_DEPRECATE_SOON("Use ExternalMemoryAccounter instead.")
1084
+ int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
1085
+
1086
+ /**
1087
+ * Returns heap profiler for this isolate. Will return NULL until the isolate
1088
+ * is initialized.
1089
+ */
1090
+ HeapProfiler* GetHeapProfiler();
1091
+
1092
+ /**
1093
+ * Tells the VM whether the embedder is idle or not.
1094
+ */
1095
+ void SetIdle(bool is_idle);
1096
+
1097
+ /** Returns the ArrayBuffer::Allocator used in this isolate. */
1098
+ ArrayBuffer::Allocator* GetArrayBufferAllocator();
1099
+
1100
+ /** Returns true if this isolate has a current context. */
1101
+ bool InContext();
1102
+
1103
+ /**
1104
+ * Returns the context of the currently running JavaScript, or the context
1105
+ * on the top of the stack if no JavaScript is running.
1106
+ */
1107
+ Local<Context> GetCurrentContext();
1108
+
1109
+ /**
1110
+ * Returns either the last context entered through V8's C++ API, or the
1111
+ * context of the currently running microtask while processing microtasks.
1112
+ * If a context is entered while executing a microtask, that context is
1113
+ * returned.
1114
+ */
1115
+ Local<Context> GetEnteredOrMicrotaskContext();
1116
+
1117
+ /**
1118
+ * Returns the Context that corresponds to the Incumbent realm in HTML spec.
1119
+ * https://html.spec.whatwg.org/multipage/webappapis.html#incumbent
1120
+ */
1121
+ Local<Context> GetIncumbentContext();
1122
+
1123
+ /**
1124
+ * Returns the host defined options set for currently running script or
1125
+ * module, if available.
1126
+ */
1127
+ MaybeLocal<Data> GetCurrentHostDefinedOptions();
1128
+
1129
+ /**
1130
+ * Schedules a v8::Exception::Error with the given message.
1131
+ * See ThrowException for more details. Templatized to provide compile-time
1132
+ * errors in case of too long strings (see v8::String::NewFromUtf8Literal).
1133
+ */
1134
+ template <int N>
1135
+ Local<Value> ThrowError(const char (&message)[N]) {
1136
+ return ThrowError(String::NewFromUtf8Literal(this, message));
1137
+ }
1138
+ Local<Value> ThrowError(Local<String> message);
1139
+
1140
+ /**
1141
+ * Schedules an exception to be thrown when returning to JavaScript. When an
1142
+ * exception has been scheduled it is illegal to invoke any JavaScript
1143
+ * operation; the caller must return immediately and only after the exception
1144
+ * has been handled does it become legal to invoke JavaScript operations.
1145
+ */
1146
+ Local<Value> ThrowException(Local<Value> exception);
1147
+
1148
+ /**
1149
+ * Returns true if an exception was thrown but not processed yet by an
1150
+ * exception handler on JavaScript side or by v8::TryCatch handler.
1151
+ *
1152
+ * This is an experimental feature and may still change significantly.
1153
+ */
1154
+ bool HasPendingException();
1155
+
1156
+ using GCCallback = void (*)(Isolate* isolate, GCType type,
1157
+ GCCallbackFlags flags);
1158
+ using GCCallbackWithData = void (*)(Isolate* isolate, GCType type,
1159
+ GCCallbackFlags flags, void* data);
1160
+
1161
+ /**
1162
+ * Enables the host application to receive a notification before a
1163
+ * garbage collection.
1164
+ *
1165
+ * \param callback The callback to be invoked. The callback is allowed to
1166
+ * allocate but invocation is not re-entrant: a callback triggering
1167
+ * garbage collection will not be called again. JS execution is prohibited
1168
+ * from these callbacks. A single callback may only be registered once.
1169
+ * \param gc_type_filter A filter in case it should be applied.
1170
+ */
1171
+ void AddGCPrologueCallback(GCCallback callback,
1172
+ GCType gc_type_filter = kGCTypeAll);
1173
+
1174
+ /**
1175
+ * \copydoc AddGCPrologueCallback(GCCallback, GCType)
1176
+ *
1177
+ * \param data Additional data that should be passed to the callback.
1178
+ */
1179
+ void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
1180
+ GCType gc_type_filter = kGCTypeAll);
1181
+
1182
+ /**
1183
+ * This function removes a callback which was added by
1184
+ * `AddGCPrologueCallback`.
1185
+ *
1186
+ * \param callback the callback to remove.
1187
+ */
1188
+ void RemoveGCPrologueCallback(GCCallback callback);
1189
+
1190
+ /**
1191
+ * \copydoc AddGCPrologueCallback(GCCallback)
1192
+ *
1193
+ * \param data Additional data that was used to install the callback.
1194
+ */
1195
+ void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
1196
+
1197
+ /**
1198
+ * Enables the host application to receive a notification after a
1199
+ * garbage collection.
1200
+ *
1201
+ * \copydetails AddGCPrologueCallback(GCCallback, GCType)
1202
+ */
1203
+ void AddGCEpilogueCallback(GCCallback callback,
1204
+ GCType gc_type_filter = kGCTypeAll);
1205
+
1206
+ /**
1207
+ * \copydoc AddGCEpilogueCallback(GCCallback, GCType)
1208
+ *
1209
+ * \param data Additional data that should be passed to the callback.
1210
+ */
1211
+ void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
1212
+ GCType gc_type_filter = kGCTypeAll);
1213
+
1214
+ /**
1215
+ * This function removes a callback which was added by
1216
+ * `AddGCEpilogueCallback`.
1217
+ *
1218
+ * \param callback the callback to remove.
1219
+ */
1220
+ void RemoveGCEpilogueCallback(GCCallback callback);
1221
+
1222
+ /**
1223
+ * \copydoc RemoveGCEpilogueCallback(GCCallback)
1224
+ *
1225
+ * \param data Additional data that was used to install the callback.
1226
+ */
1227
+ void RemoveGCEpilogueCallback(GCCallbackWithData callback,
1228
+ void* data = nullptr);
1229
+
1230
+ /**
1231
+ * Sets an embedder roots handle that V8 should consider when performing
1232
+ * non-unified heap garbage collections. The intended use case is for setting
1233
+ * a custom handler after invoking `AttachCppHeap()`.
1234
+ *
1235
+ * V8 does not take ownership of the handler.
1236
+ */
1237
+ void SetEmbedderRootsHandler(EmbedderRootsHandler* handler);
1238
+
1239
+ using ReleaseCppHeapCallback = void (*)(std::unique_ptr<CppHeap>);
1240
+
1241
+ /**
1242
+ * Sets a callback on the isolate that gets called when the CppHeap gets
1243
+ * detached. The callback can then either take ownership of the CppHeap, or
1244
+ * the CppHeap gets deallocated.
1245
+ */
1246
+ void SetReleaseCppHeapCallbackForTesting(ReleaseCppHeapCallback callback);
1247
+
1248
+ /**
1249
+ * \returns the C++ heap managed by V8. Only available if such a heap has been
1250
+ * attached using `AttachCppHeap()`.
1251
+ */
1252
+ CppHeap* GetCppHeap() const;
1253
+
1254
+ using GetExternallyAllocatedMemoryInBytesCallback = size_t (*)();
1255
+
1256
+ /**
1257
+ * Set the callback that tells V8 how much memory is currently allocated
1258
+ * externally of the V8 heap. Ideally this memory is somehow connected to V8
1259
+ * objects and may get freed-up when the corresponding V8 objects get
1260
+ * collected by a V8 garbage collection.
1261
+ */
1262
+ void SetGetExternallyAllocatedMemoryInBytesCallback(
1263
+ GetExternallyAllocatedMemoryInBytesCallback callback);
1264
+
1265
+ /**
1266
+ * Forcefully terminate the current thread of JavaScript execution
1267
+ * in the given isolate.
1268
+ *
1269
+ * This method can be used by any thread even if that thread has not
1270
+ * acquired the V8 lock with a Locker object.
1271
+ */
1272
+ void TerminateExecution();
1273
+
1274
+ /**
1275
+ * Is V8 terminating JavaScript execution.
1276
+ *
1277
+ * Returns true if JavaScript execution is currently terminating
1278
+ * because of a call to TerminateExecution. In that case there are
1279
+ * still JavaScript frames on the stack and the termination
1280
+ * exception is still active.
1281
+ */
1282
+ bool IsExecutionTerminating();
1283
+
1284
+ /**
1285
+ * Resume execution capability in the given isolate, whose execution
1286
+ * was previously forcefully terminated using TerminateExecution().
1287
+ *
1288
+ * When execution is forcefully terminated using TerminateExecution(),
1289
+ * the isolate can not resume execution until all JavaScript frames
1290
+ * have propagated the uncatchable exception which is generated. This
1291
+ * method allows the program embedding the engine to handle the
1292
+ * termination event and resume execution capability, even if
1293
+ * JavaScript frames remain on the stack.
1294
+ *
1295
+ * This method can be used by any thread even if that thread has not
1296
+ * acquired the V8 lock with a Locker object.
1297
+ */
1298
+ void CancelTerminateExecution();
1299
+
1300
+ /**
1301
+ * Request V8 to interrupt long running JavaScript code and invoke
1302
+ * the given |callback| passing the given |data| to it. After |callback|
1303
+ * returns control will be returned to the JavaScript code.
1304
+ * There may be a number of interrupt requests in flight.
1305
+ * Can be called from another thread without acquiring a |Locker|.
1306
+ * Registered |callback| must not reenter interrupted Isolate.
1307
+ */
1308
+ void RequestInterrupt(InterruptCallback callback, void* data);
1309
+
1310
+ /**
1311
+ * Returns true if there is ongoing background work within V8 that will
1312
+ * eventually post a foreground task, like asynchronous WebAssembly
1313
+ * compilation.
1314
+ */
1315
+ bool HasPendingBackgroundTasks();
1316
+
1317
+ /**
1318
+ * Request garbage collection in this Isolate. It is only valid to call this
1319
+ * function if --expose_gc was specified.
1320
+ *
1321
+ * This should only be used for testing purposes and not to enforce a garbage
1322
+ * collection schedule. It has strong negative impact on the garbage
1323
+ * collection performance. Use MemoryPressureNotification() instead to
1324
+ * influence the garbage collection schedule.
1325
+ */
1326
+ void RequestGarbageCollectionForTesting(GarbageCollectionType type);
1327
+
1328
+ /**
1329
+ * Request garbage collection with a specific embedderstack state in this
1330
+ * Isolate. It is only valid to call this function if --expose_gc was
1331
+ * specified.
1332
+ *
1333
+ * This should only be used for testing purposes and not to enforce a garbage
1334
+ * collection schedule. It has strong negative impact on the garbage
1335
+ * collection performance. Use MemoryPressureNotification() instead to
1336
+ * influence the garbage collection schedule.
1337
+ */
1338
+ void RequestGarbageCollectionForTesting(GarbageCollectionType type,
1339
+ StackState stack_state);
1340
+
1341
+ /**
1342
+ * Set the callback to invoke for logging event.
1343
+ */
1344
+ void SetEventLogger(LogEventCallback that);
1345
+
1346
+ /**
1347
+ * Adds a callback to notify the host application right before a script
1348
+ * is about to run. If a script re-enters the runtime during executing, the
1349
+ * BeforeCallEnteredCallback is invoked for each re-entrance.
1350
+ * Executing scripts inside the callback will re-trigger the callback.
1351
+ */
1352
+ void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1353
+
1354
+ /**
1355
+ * Removes callback that was installed by AddBeforeCallEnteredCallback.
1356
+ */
1357
+ void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1358
+
1359
+ /**
1360
+ * Adds a callback to notify the host application when a script finished
1361
+ * running. If a script re-enters the runtime during executing, the
1362
+ * CallCompletedCallback is only invoked when the outer-most script
1363
+ * execution ends. Executing scripts inside the callback do not trigger
1364
+ * further callbacks.
1365
+ */
1366
+ void AddCallCompletedCallback(CallCompletedCallback callback);
1367
+
1368
+ /**
1369
+ * Removes callback that was installed by AddCallCompletedCallback.
1370
+ */
1371
+ void RemoveCallCompletedCallback(CallCompletedCallback callback);
1372
+
1373
+ /**
1374
+ * Set the PromiseHook callback for various promise lifecycle
1375
+ * events.
1376
+ */
1377
+ void SetPromiseHook(PromiseHook hook);
1378
+
1379
+ /**
1380
+ * Set callback to notify about promise reject with no handler, or
1381
+ * revocation of such a previous notification once the handler is added.
1382
+ */
1383
+ void SetPromiseRejectCallback(PromiseRejectCallback callback);
1384
+
1385
+ /**
1386
+ * This is a part of experimental Api and might be changed without further
1387
+ * notice.
1388
+ * Do not use it.
1389
+ *
1390
+ * Set callback to notify about a new exception being thrown.
1391
+ */
1392
+ void SetExceptionPropagationCallback(ExceptionPropagationCallback callback);
1393
+
1394
+ /**
1395
+ * Runs the default MicrotaskQueue until it gets empty and perform other
1396
+ * microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
1397
+ * the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
1398
+ * callbacks are swallowed.
1399
+ */
1400
+ void PerformMicrotaskCheckpoint();
1401
+
1402
+ /**
1403
+ * Enqueues the callback to the default MicrotaskQueue
1404
+ */
1405
+ void EnqueueMicrotask(Local<Function> microtask);
1406
+
1407
+ /**
1408
+ * Enqueues the callback to the default MicrotaskQueue
1409
+ */
1410
+ void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
1411
+
1412
+ /**
1413
+ * Controls how Microtasks are invoked. See MicrotasksPolicy for details.
1414
+ */
1415
+ void SetMicrotasksPolicy(MicrotasksPolicy policy);
1416
+
1417
+ /**
1418
+ * Returns the policy controlling how Microtasks are invoked.
1419
+ */
1420
+ MicrotasksPolicy GetMicrotasksPolicy() const;
1421
+
1422
+ /**
1423
+ * Adds a callback to notify the host application after
1424
+ * microtasks were run on the default MicrotaskQueue. The callback is
1425
+ * triggered by explicit RunMicrotasks call or automatic microtasks execution
1426
+ * (see SetMicrotaskPolicy).
1427
+ *
1428
+ * Callback will trigger even if microtasks were attempted to run,
1429
+ * but the microtasks queue was empty and no single microtask was actually
1430
+ * executed.
1431
+ *
1432
+ * Executing scripts inside the callback will not re-trigger microtasks and
1433
+ * the callback.
1434
+ */
1435
+ void AddMicrotasksCompletedCallback(
1436
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1437
+
1438
+ /**
1439
+ * Removes callback that was installed by AddMicrotasksCompletedCallback.
1440
+ */
1441
+ void RemoveMicrotasksCompletedCallback(
1442
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1443
+
1444
+ /**
1445
+ * Sets a callback for counting the number of times a feature of V8 is used.
1446
+ */
1447
+ void SetUseCounterCallback(UseCounterCallback callback);
1448
+
1449
+ /**
1450
+ * Enables the host application to provide a mechanism for recording
1451
+ * statistics counters.
1452
+ */
1453
+ void SetCounterFunction(CounterLookupCallback);
1454
+
1455
+ /**
1456
+ * Enables the host application to provide a mechanism for recording
1457
+ * histograms. The CreateHistogram function returns a
1458
+ * histogram which will later be passed to the AddHistogramSample
1459
+ * function.
1460
+ */
1461
+ void SetCreateHistogramFunction(CreateHistogramCallback);
1462
+ void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
1463
+
1464
+ /**
1465
+ * Enables the host application to provide a mechanism for recording
1466
+ * event based metrics. In order to use this interface
1467
+ * include/v8-metrics.h
1468
+ * needs to be included and the recorder needs to be derived from the
1469
+ * Recorder base class defined there.
1470
+ * This method can only be called once per isolate and must happen during
1471
+ * isolate initialization before background threads are spawned.
1472
+ */
1473
+ void SetMetricsRecorder(
1474
+ const std::shared_ptr<metrics::Recorder>& metrics_recorder);
1475
+
1476
+ /**
1477
+ * Enables the host application to provide a mechanism for recording a
1478
+ * predefined set of data as crash keys to be used in postmortem debugging in
1479
+ * case of a crash.
1480
+ */
1481
+ void SetAddCrashKeyCallback(AddCrashKeyCallback);
1482
+
1483
+ /**
1484
+ * Enables the host application to provide a mechanism for allocating a new
1485
+ * crash key and setting/updating values for them.
1486
+ */
1487
+ void SetCrashKeyStringCallbacks(AllocateCrashKeyStringCallback,
1488
+ SetCrashKeyStringCallback);
1489
+
1490
+ /**
1491
+ * Optional notification that the system is running low on memory.
1492
+ * V8 uses these notifications to attempt to free memory.
1493
+ */
1494
+ void LowMemoryNotification();
1495
+
1496
+ /**
1497
+ * Optional notification that a context has been disposed. V8 uses these
1498
+ * notifications to guide the GC heuristic and cancel FinalizationRegistry
1499
+ * cleanup tasks. Returns the number of context disposals - including this one
1500
+ * - since the last time V8 had a chance to clean up.
1501
+ *
1502
+ * The optional parameter |dependant_context| specifies whether the disposed
1503
+ * context was depending on state from other contexts or not.
1504
+ */
1505
+ V8_DEPRECATE_SOON("Use version that passes ContextDependants.")
1506
+ int ContextDisposedNotification(bool dependant_context = true);
1507
+
1508
+ /**
1509
+ * Optional notification that a context has been disposed. V8 uses these
1510
+ * notifications to guide heuristics on e.g. GC or compilers.
1511
+ *
1512
+ * \param dependants A signal on whether this context possibly had any
1513
+ * dependants.
1514
+ */
1515
+ void ContextDisposedNotification(ContextDependants dependants);
1516
+
1517
+ /**
1518
+ * Optional notification that the isolate switched to the foreground.
1519
+ * V8 uses these notifications to guide heuristics.
1520
+ */
1521
+ V8_DEPRECATE_SOON("Use SetPriority(Priority::kUserBlocking) instead")
1522
+ void IsolateInForegroundNotification();
1523
+
1524
+ /**
1525
+ * Optional notification that the isolate switched to the background.
1526
+ * V8 uses these notifications to guide heuristics.
1527
+ */
1528
+ V8_DEPRECATE_SOON("Use SetPriority(Priority::kBestEffort) instead")
1529
+ void IsolateInBackgroundNotification();
1530
+
1531
+ /**
1532
+ * Optional notification that the isolate changed `priority`.
1533
+ * V8 uses the priority value to guide heuristics.
1534
+ */
1535
+ void SetPriority(Priority priority);
1536
+
1537
+ /**
1538
+ * Optional notification to tell V8 whether the embedder is currently loading
1539
+ * resources. If the embedder uses this notification, it should call
1540
+ * SetIsLoading(true) when loading starts and SetIsLoading(false) when it
1541
+ * ends.
1542
+ * It's valid to call SetIsLoading(true) again while loading, which will
1543
+ * update the timestamp when V8 considers the load started. Calling
1544
+ * SetIsLoading(false) while not loading does nothing.
1545
+ * V8 uses these notifications to guide heuristics.
1546
+ * This is an unfinished experimental feature. Semantics and implementation
1547
+ * may change frequently.
1548
+ */
1549
+ void SetIsLoading(bool is_loading);
1550
+
1551
+ /**
1552
+ * Optional notification to tell V8 whether the embedder is currently
1553
+ * handling user input. If the embedder uses this notification, it should
1554
+ * call SetIsInputHandling(true) when input handling starts, and
1555
+ * SetIsInputHandling(false) when it ends.
1556
+ * Calling SetIsInputHandling(true) while handling input, or calling
1557
+ * SetIsInputHandling(false) while not handling input, both have no effect.
1558
+ * V8 uses these notifications to guide heuristics.
1559
+ * This is an unfinished experimental feature. Semantics and implementation
1560
+ * may change frequently.
1561
+ */
1562
+ void SetIsInputHandling(bool is_input_handling);
1563
+
1564
+ /**
1565
+ * Optional notification to tell V8 whether the embedder is currently frozen.
1566
+ * V8 uses these notifications to guide heuristics.
1567
+ * This is an unfinished experimental feature. Semantics and implementation
1568
+ * may change frequently.
1569
+ */
1570
+ void Freeze(bool is_frozen);
1571
+
1572
+ /**
1573
+ * Optional notification to tell V8 the current isolate is used for debugging
1574
+ * and requires higher heap limit.
1575
+ */
1576
+ void IncreaseHeapLimitForDebugging();
1577
+
1578
+ /**
1579
+ * Restores the original heap limit after IncreaseHeapLimitForDebugging().
1580
+ */
1581
+ void RestoreOriginalHeapLimit();
1582
+
1583
+ /**
1584
+ * Returns true if the heap limit was increased for debugging and the
1585
+ * original heap limit was not restored yet.
1586
+ */
1587
+ bool IsHeapLimitIncreasedForDebugging();
1588
+
1589
+ /**
1590
+ * Allows the host application to provide the address of a function that is
1591
+ * notified each time code is added, moved or removed.
1592
+ *
1593
+ * \param options options for the JIT code event handler.
1594
+ * \param event_handler the JIT code event handler, which will be invoked
1595
+ * each time code is added, moved or removed.
1596
+ * \note \p event_handler won't get notified of existent code.
1597
+ * \note since code removal notifications are not currently issued, the
1598
+ * \p event_handler may get notifications of code that overlaps earlier
1599
+ * code notifications. This happens when code areas are reused, and the
1600
+ * earlier overlapping code areas should therefore be discarded.
1601
+ * \note the events passed to \p event_handler and the strings they point to
1602
+ * are not guaranteed to live past each call. The \p event_handler must
1603
+ * copy strings and other parameters it needs to keep around.
1604
+ * \note the set of events declared in JitCodeEvent::EventType is expected to
1605
+ * grow over time, and the JitCodeEvent structure is expected to accrue
1606
+ * new members. The \p event_handler function must ignore event codes
1607
+ * it does not recognize to maintain future compatibility.
1608
+ * \note Use Isolate::CreateParams to get events for code executed during
1609
+ * Isolate setup.
1610
+ */
1611
+ void SetJitCodeEventHandler(JitCodeEventOptions options,
1612
+ JitCodeEventHandler event_handler);
1613
+
1614
+ /**
1615
+ * Modifies the stack limit for this Isolate.
1616
+ *
1617
+ * \param stack_limit An address beyond which the Vm's stack may not grow.
1618
+ *
1619
+ * \note If you are using threads then you should hold the V8::Locker lock
1620
+ * while setting the stack limit and you must set a non-default stack
1621
+ * limit separately for each thread.
1622
+ */
1623
+ void SetStackLimit(uintptr_t stack_limit);
1624
+
1625
+ /**
1626
+ * Returns a memory range that can potentially contain jitted code. Code for
1627
+ * V8's 'builtins' will not be in this range if embedded builtins is enabled.
1628
+ *
1629
+ * On Win64, embedders are advised to install function table callbacks for
1630
+ * these ranges, as default SEH won't be able to unwind through jitted code.
1631
+ * The first page of the code range is reserved for the embedder and is
1632
+ * committed, writable, and executable, to be used to store unwind data, as
1633
+ * documented in
1634
+ * https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64.
1635
+ *
1636
+ * Might be empty on other platforms.
1637
+ *
1638
+ * https://code.google.com/p/v8/issues/detail?id=3598
1639
+ */
1640
+ void GetCodeRange(void** start, size_t* length_in_bytes);
1641
+
1642
+ /**
1643
+ * As GetCodeRange, but for embedded builtins (these live in a distinct
1644
+ * memory region from other V8 Code objects).
1645
+ */
1646
+ void GetEmbeddedCodeRange(const void** start, size_t* length_in_bytes);
1647
+
1648
+ /**
1649
+ * Returns the JSEntryStubs necessary for use with the Unwinder API.
1650
+ */
1651
+ JSEntryStubs GetJSEntryStubs();
1652
+
1653
+ static constexpr size_t kMinCodePagesBufferSize = 32;
1654
+
1655
+ /**
1656
+ * Copies the code heap pages currently in use by V8 into |code_pages_out|.
1657
+ * |code_pages_out| must have at least kMinCodePagesBufferSize capacity and
1658
+ * must be empty.
1659
+ *
1660
+ * Signal-safe, does not allocate, does not access the V8 heap.
1661
+ * No code on the stack can rely on pages that might be missing.
1662
+ *
1663
+ * Returns the number of pages available to be copied, which might be greater
1664
+ * than |capacity|. In this case, only |capacity| pages will be copied into
1665
+ * |code_pages_out|. The caller should provide a bigger buffer on the next
1666
+ * call in order to get all available code pages, but this is not required.
1667
+ */
1668
+ size_t CopyCodePages(size_t capacity, MemoryRange* code_pages_out);
1669
+
1670
+ /** Set the callback to invoke in case of fatal errors. */
1671
+ void SetFatalErrorHandler(FatalErrorCallback that);
1672
+
1673
+ /** Set the callback to invoke in case of OOM errors. */
1674
+ void SetOOMErrorHandler(OOMErrorCallback that);
1675
+
1676
+ /**
1677
+ * \copydoc SetOOMErrorHandler(OOMErrorCallback)
1678
+ *
1679
+ * \param data Additional data that should be passed to the callback.
1680
+ */
1681
+ void SetOOMErrorHandler(OOMErrorCallbackWithData that, void* data);
1682
+
1683
+ /**
1684
+ * Add a callback to invoke in case the heap size is close to the heap limit.
1685
+ * If multiple callbacks are added, only the most recently added callback is
1686
+ * invoked.
1687
+ */
1688
+ void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
1689
+
1690
+ /**
1691
+ * Remove the given callback and restore the heap limit to the
1692
+ * given limit. If the given limit is zero, then it is ignored.
1693
+ * If the current heap size is greater than the given limit,
1694
+ * then the heap limit is restored to the minimal limit that
1695
+ * is possible for the current heap size.
1696
+ */
1697
+ void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
1698
+ size_t heap_limit);
1699
+
1700
+ /**
1701
+ * If the heap limit was changed by the NearHeapLimitCallback, then the
1702
+ * initial heap limit will be restored once the heap size falls below the
1703
+ * given threshold percentage of the initial heap limit.
1704
+ * The threshold percentage is a number in (0.0, 1.0) range.
1705
+ */
1706
+ void AutomaticallyRestoreInitialHeapLimit(double threshold_percent = 0.5);
1707
+
1708
+ /**
1709
+ * Set the callback to invoke to check if code generation from
1710
+ * strings should be allowed.
1711
+ */
1712
+ void SetModifyCodeGenerationFromStringsCallback(
1713
+ ModifyCodeGenerationFromStringsCallback2 callback);
1714
+
1715
+ /**
1716
+ * Set the callback to invoke to check if wasm code generation should
1717
+ * be allowed.
1718
+ */
1719
+ void SetAllowWasmCodeGenerationCallback(
1720
+ AllowWasmCodeGenerationCallback callback);
1721
+
1722
+ /**
1723
+ * Embedder over{ride|load} injection points for wasm APIs. The expectation
1724
+ * is that the embedder sets them at most once.
1725
+ */
1726
+ void SetWasmModuleCallback(ExtensionCallback callback);
1727
+ void SetWasmInstanceCallback(ExtensionCallback callback);
1728
+
1729
+ void SetWasmStreamingCallback(WasmStreamingCallback callback);
1730
+
1731
+ void SetWasmAsyncResolvePromiseCallback(
1732
+ WasmAsyncResolvePromiseCallback callback);
1733
+
1734
+ void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback);
1735
+
1736
+ void SetWasmCustomDescriptorsEnabledCallback(
1737
+ WasmCustomDescriptorsEnabledCallback callback);
1738
+
1739
+ void SetSharedArrayBufferConstructorEnabledCallback(
1740
+ SharedArrayBufferConstructorEnabledCallback callback);
1741
+
1742
+ /**
1743
+ * This function can be called by the embedder to signal V8 that the dynamic
1744
+ * enabling of features has finished. V8 can now set up dynamically added
1745
+ * features.
1746
+ */
1747
+ void InstallConditionalFeatures(Local<Context> context);
1748
+
1749
+ /**
1750
+ * Check if V8 is dead and therefore unusable. This is the case after
1751
+ * fatal errors such as out-of-memory situations.
1752
+ */
1753
+ bool IsDead();
1754
+
1755
+ /**
1756
+ * Adds a message listener (errors only).
1757
+ *
1758
+ * The same message listener can be added more than once and in that
1759
+ * case it will be called more than once for each message.
1760
+ *
1761
+ * If data is specified, it will be passed to the callback when it is called.
1762
+ * Otherwise, the exception object will be passed to the callback instead.
1763
+ */
1764
+ bool AddMessageListener(MessageCallback callback,
1765
+ Local<Value> data = Local<Value>());
1766
+
1767
+ /**
1768
+ * Adds a message listener.
1769
+ *
1770
+ * The same message listener can be added more than once and in that
1771
+ * case it will be called more than once for each message.
1772
+ *
1773
+ * If data is specified, it will be passed to the callback when it is called.
1774
+ * Otherwise, the exception object will be passed to the callback instead.
1775
+ *
1776
+ * A listener can listen for particular error levels by providing a mask.
1777
+ */
1778
+ bool AddMessageListenerWithErrorLevel(MessageCallback callback,
1779
+ int message_levels,
1780
+ Local<Value> data = Local<Value>());
1781
+
1782
+ /**
1783
+ * Remove all message listeners from the specified callback function.
1784
+ */
1785
+ void RemoveMessageListeners(MessageCallback callback);
1786
+
1787
+ /** Callback function for reporting failed access checks.*/
1788
+ void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
1789
+
1790
+ /**
1791
+ * Tells V8 to capture current stack trace when uncaught exception occurs
1792
+ * and report it to the message listeners. The option is off by default.
1793
+ */
1794
+ void SetCaptureStackTraceForUncaughtExceptions(
1795
+ bool capture, int frame_limit = 10,
1796
+ StackTrace::StackTraceOptions options = StackTrace::kOverview);
1797
+
1798
+ /**
1799
+ * Check if this isolate is in use.
1800
+ * True if at least one thread Enter'ed this isolate.
1801
+ */
1802
+ bool IsInUse();
1803
+
1804
+ /**
1805
+ * Set whether calling Atomics.wait (a function that may block) is allowed in
1806
+ * this isolate. This can also be configured via
1807
+ * CreateParams::allow_atomics_wait.
1808
+ */
1809
+ void SetAllowAtomicsWait(bool allow);
1810
+
1811
+ /**
1812
+ * Time zone redetection indicator for
1813
+ * DateTimeConfigurationChangeNotification.
1814
+ *
1815
+ * kSkip indicates V8 that the notification should not trigger redetecting
1816
+ * host time zone. kRedetect indicates V8 that host time zone should be
1817
+ * redetected, and used to set the default time zone.
1818
+ *
1819
+ * The host time zone detection may require file system access or similar
1820
+ * operations unlikely to be available inside a sandbox. If v8 is run inside a
1821
+ * sandbox, the host time zone has to be detected outside the sandbox before
1822
+ * calling DateTimeConfigurationChangeNotification function.
1823
+ */
1824
+ enum class TimeZoneDetection { kSkip, kRedetect };
1825
+
1826
+ /**
1827
+ * Notification that the embedder has changed the time zone, daylight savings
1828
+ * time or other date / time configuration parameters. V8 keeps a cache of
1829
+ * various values used for date / time computation. This notification will
1830
+ * reset those cached values for the current context so that date / time
1831
+ * configuration changes would be reflected.
1832
+ *
1833
+ * This API should not be called more than needed as it will negatively impact
1834
+ * the performance of date operations.
1835
+ */
1836
+ void DateTimeConfigurationChangeNotification(
1837
+ TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip);
1838
+
1839
+ /**
1840
+ * Notification that the embedder has changed the locale. V8 keeps a cache of
1841
+ * various values used for locale computation. This notification will reset
1842
+ * those cached values for the current context so that locale configuration
1843
+ * changes would be reflected.
1844
+ *
1845
+ * This API should not be called more than needed as it will negatively impact
1846
+ * the performance of locale operations.
1847
+ */
1848
+ void LocaleConfigurationChangeNotification();
1849
+
1850
+ /**
1851
+ * Returns the default locale in a string if Intl support is enabled.
1852
+ * Otherwise returns an empty string.
1853
+ */
1854
+ std::string GetDefaultLocale();
1855
+
1856
+ /**
1857
+ * Returns a canonical and case-regularized form of locale if Intl support is
1858
+ * enabled. If the locale is not syntactically well-formed, throws a
1859
+ * RangeError.
1860
+ *
1861
+ * If Intl support is not enabled, returns Nothing<std::string>().
1862
+ *
1863
+ * Corresponds to the combination of the abstract operations
1864
+ * IsStructurallyValidLanguageTag and CanonicalizeUnicodeLocaleId. See:
1865
+ * https://tc39.es/ecma402/#sec-isstructurallyvalidlanguagetag
1866
+ * https://tc39.es/ecma402/#sec-canonicalizeunicodelocaleid
1867
+ */
1868
+ V8_WARN_UNUSED_RESULT Maybe<std::string>
1869
+ ValidateAndCanonicalizeUnicodeLocaleId(std::string_view locale);
1870
+
1871
+ /**
1872
+ * Returns the hash seed for that isolate, for testing purposes.
1873
+ */
1874
+ uint64_t GetHashSeed();
1875
+
1876
+ Isolate() = delete;
1877
+ ~Isolate() = delete;
1878
+ Isolate(const Isolate&) = delete;
1879
+ Isolate& operator=(const Isolate&) = delete;
1880
+ // Deleting operator new and delete here is allowed as ctor and dtor is also
1881
+ // deleted.
1882
+ void* operator new(size_t size) = delete;
1883
+ void* operator new[](size_t size) = delete;
1884
+ void operator delete(void*, size_t) = delete;
1885
+ void operator delete[](void*, size_t) = delete;
1886
+
1887
+ private:
1888
+ template <class K, class V, class Traits>
1889
+ friend class PersistentValueMapBase;
1890
+ friend class ExternalMemoryAccounter;
1891
+
1892
+ internal::ValueHelper::InternalRepresentationType GetDataFromSnapshotOnce(
1893
+ size_t index);
1894
+ int64_t AdjustAmountOfExternalAllocatedMemoryImpl(int64_t change_in_bytes);
1895
+ void HandleExternalMemoryInterrupt();
1896
+ };
1897
+
1898
+ void Isolate::SetData(uint32_t slot, void* data) {
1899
+ using I = internal::Internals;
1900
+ I::SetEmbedderData(this, slot, data);
1901
+ }
1902
+
1903
+ void* Isolate::GetData(uint32_t slot) {
1904
+ using I = internal::Internals;
1905
+ return I::GetEmbedderData(this, slot);
1906
+ }
1907
+
1908
+ uint32_t Isolate::GetNumberOfDataSlots() {
1909
+ using I = internal::Internals;
1910
+ return I::kNumIsolateDataSlots;
1911
+ }
1912
+
1913
+ template <class T>
1914
+ MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
1915
+ if (auto repr = GetDataFromSnapshotOnce(index);
1916
+ repr != internal::ValueHelper::kEmpty) {
1917
+ internal::PerformCastCheck(internal::ValueHelper::ReprAsValue<T>(repr));
1918
+ return Local<T>::FromRepr(repr);
1919
+ }
1920
+ return {};
1921
+ }
1922
+
1923
+ } // namespace v8
1924
+
1925
+ #endif // INCLUDE_V8_ISOLATE_H_