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