Loading...
Searching...
No Matches
v8-isolate.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_ISOLATE_H_
6#define INCLUDE_V8_ISOLATE_H_
7
8#include <stddef.h>
9#include <stdint.h>
10
11#include <memory>
12#include <string>
13#include <utility>
14
15#include "cppgc/common.h"
16#include "v8-array-buffer.h" // NOLINT(build/include_directory)
17#include "v8-callbacks.h" // NOLINT(build/include_directory)
18#include "v8-data.h" // NOLINT(build/include_directory)
19#include "v8-debug.h" // NOLINT(build/include_directory)
20#include "v8-embedder-heap.h" // NOLINT(build/include_directory)
21#include "v8-exception.h" // NOLINT(build/include_directory)
22#include "v8-function-callback.h" // NOLINT(build/include_directory)
23#include "v8-internal.h" // NOLINT(build/include_directory)
24#include "v8-local-handle.h" // NOLINT(build/include_directory)
25#include "v8-microtask.h" // NOLINT(build/include_directory)
26#include "v8-persistent-handle.h" // NOLINT(build/include_directory)
27#include "v8-primitive.h" // NOLINT(build/include_directory)
28#include "v8-statistics.h" // NOLINT(build/include_directory)
29#include "v8-unwinder.h" // NOLINT(build/include_directory)
30#include "v8config.h" // NOLINT(build/include_directory)
31
32namespace v8 {
33
34class CppHeap;
35class HeapProfiler;
36class MicrotaskQueue;
37class StartupData;
38class ScriptOrModule;
39class SharedArrayBuffer;
40
41namespace internal {
42class MicrotaskQueue;
43class ThreadLocalTop;
44} // namespace internal
45
46namespace metrics {
47class Recorder;
48} // namespace metrics
49
65 public:
84 void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
85 size_t maximum_heap_size_in_bytes);
86
96 void ConfigureDefaults(uint64_t physical_memory,
97 uint64_t virtual_memory_limit);
98
102 uint32_t* stack_limit() const { return stack_limit_; }
103 void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
104
114 size_t code_range_size_in_bytes() const { return code_range_size_; }
115 void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
116
125 return max_old_generation_size_;
126 }
128 max_old_generation_size_ = limit;
129 }
130
137 return max_young_generation_size_;
138 }
140 max_young_generation_size_ = limit;
141 }
142
144 return initial_old_generation_size_;
145 }
147 initial_old_generation_size_ = initial_size;
148 }
149
151 return initial_young_generation_size_;
152 }
154 initial_young_generation_size_ = initial_size;
155 }
156
157 private:
158 static constexpr size_t kMB = 1048576u;
159 size_t code_range_size_ = 0;
160 size_t max_old_generation_size_ = 0;
161 size_t max_young_generation_size_ = 0;
162 size_t initial_old_generation_size_ = 0;
163 size_t initial_young_generation_size_ = 0;
164 uint32_t* stack_limit_ = nullptr;
165};
166
176
187};
188
193
219 public:
227
232 static bool CanCreateNewGroups();
233
239
242
243 IsolateGroup(const IsolateGroup&) = delete;
245
247
248 bool operator==(const IsolateGroup& other) const {
249 return isolate_group_ == other.isolate_group_;
250 }
251
252 bool operator!=(const IsolateGroup& other) const {
253 return !operator==(other);
254 }
255
256 private:
257 friend class Isolate;
258
259 // The isolate_group pointer should be already acquired.
260 explicit IsolateGroup(internal::IsolateGroup*&& isolate_group);
261
262 internal::IsolateGroup* isolate_group_;
263};
264
274 public:
281
283
284
288 JitCodeEventHandler code_event_handler = nullptr;
289
294
299 const StartupData* snapshot_blob = nullptr;
300
305 CounterLookupCallback counter_lookup_callback = nullptr;
306
313 CreateHistogramCallback create_histogram_callback = nullptr;
314 AddHistogramSampleCallback add_histogram_sample_callback = nullptr;
315
325 ArrayBuffer::Allocator* array_buffer_allocator = nullptr;
326 std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
327
334 const intptr_t* external_references = nullptr;
335
340 bool allow_atomics_wait = true;
341
347 int embedder_wrapper_type_index = -1;
348 int embedder_wrapper_object_index = -1;
349
353 FatalErrorCallback fatal_error_callback = nullptr;
354 OOMErrorCallback oom_error_callback = nullptr;
355
360 CppHeap* cpp_heap = nullptr;
361 };
362
368 public:
369 explicit Scope(Isolate* isolate) : v8_isolate_(isolate) {
370 v8_isolate_->Enter();
371 }
372
373 ~Scope() { v8_isolate_->Exit(); }
374
375 // Prevent copying of Scope objects.
376 Scope(const Scope&) = delete;
377 Scope& operator=(const Scope&) = delete;
378
379 private:
380 Isolate* const v8_isolate_;
381 };
382
387 public:
388 enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
389
392
393 // Prevent copying of Scope objects.
395 delete;
397 const DisallowJavascriptExecutionScope&) = delete;
398
399 private:
400 v8::Isolate* const v8_isolate_;
401 const OnFailure on_failure_;
402 bool was_execution_allowed_;
403 };
404
409 public:
412
413 // Prevent copying of Scope objects.
415 delete;
417 const AllowJavascriptExecutionScope&) = delete;
418
419 private:
420 Isolate* const v8_isolate_;
421 bool was_execution_allowed_assert_;
422 bool was_execution_allowed_throws_;
423 bool was_execution_allowed_dump_;
424 };
425
431 public:
433 Isolate* isolate, MicrotaskQueue* microtask_queue = nullptr);
435
436 // Prevent copying of Scope objects.
438 delete;
440 const SuppressMicrotaskExecutionScope&) = delete;
441
442 private:
443 internal::Isolate* const i_isolate_;
444 internal::MicrotaskQueue* const microtask_queue_;
445 internal::Address previous_stack_height_;
446
447 friend class internal::ThreadLocalTop;
448 };
449
456 kMinorGarbageCollection
457 };
458
468 kUseAsm = 0,
469 kBreakIterator = 1,
470 kOBSOLETE_LegacyConst = 2,
471 kOBSOLETE_MarkDequeOverflow = 3,
472 kOBSOLETE_StoreBufferOverflow = 4,
473 kOBSOLETE_SlotsBufferOverflow = 5,
474 kOBSOLETE_ObjectObserve = 6,
475 kForcedGC = 7,
476 kSloppyMode = 8,
477 kStrictMode = 9,
478 kOBSOLETE_StrongMode = 10,
479 kRegExpPrototypeStickyGetter = 11,
480 kRegExpPrototypeToString = 12,
481 kRegExpPrototypeUnicodeGetter = 13,
482 kOBSOLETE_IntlV8Parse = 14,
483 kOBSOLETE_IntlPattern = 15,
484 kOBSOLETE_IntlResolved = 16,
485 kOBSOLETE_PromiseChain = 17,
486 kOBSOLETE_PromiseAccept = 18,
487 kOBSOLETE_PromiseDefer = 19,
488 kHtmlCommentInExternalScript = 20,
489 kHtmlComment = 21,
490 kSloppyModeBlockScopedFunctionRedefinition = 22,
491 kForInInitializer = 23,
492 kOBSOLETE_ArrayProtectorDirtied = 24,
493 kArraySpeciesModified = 25,
494 kArrayPrototypeConstructorModified = 26,
495 kOBSOLETE_ArrayInstanceProtoModified = 27,
496 kArrayInstanceConstructorModified = 28,
497 kOBSOLETE_LegacyFunctionDeclaration = 29,
498 kOBSOLETE_RegExpPrototypeSourceGetter = 30,
499 kOBSOLETE_RegExpPrototypeOldFlagGetter = 31,
500 kDecimalWithLeadingZeroInStrictMode = 32,
501 kLegacyDateParser = 33,
502 kDefineGetterOrSetterWouldThrow = 34,
503 kFunctionConstructorReturnedUndefined = 35,
504 kAssigmentExpressionLHSIsCallInSloppy = 36,
505 kAssigmentExpressionLHSIsCallInStrict = 37,
506 kPromiseConstructorReturnedUndefined = 38,
507 kOBSOLETE_ConstructorNonUndefinedPrimitiveReturn = 39,
508 kOBSOLETE_LabeledExpressionStatement = 40,
509 kOBSOLETE_LineOrParagraphSeparatorAsLineTerminator = 41,
510 kIndexAccessor = 42,
511 kErrorCaptureStackTrace = 43,
512 kErrorPrepareStackTrace = 44,
513 kErrorStackTraceLimit = 45,
514 kWebAssemblyInstantiation = 46,
515 kDeoptimizerDisableSpeculation = 47,
516 kOBSOLETE_ArrayPrototypeSortJSArrayModifiedPrototype = 48,
517 kFunctionTokenOffsetTooLongForToString = 49,
518 kWasmSharedMemory = 50,
519 kWasmThreadOpcodes = 51,
520 kOBSOLETE_AtomicsNotify = 52,
521 kOBSOLETE_AtomicsWake = 53,
522 kCollator = 54,
523 kNumberFormat = 55,
524 kDateTimeFormat = 56,
525 kPluralRules = 57,
526 kRelativeTimeFormat = 58,
527 kLocale = 59,
528 kListFormat = 60,
529 kSegmenter = 61,
530 kStringLocaleCompare = 62,
531 kOBSOLETE_StringToLocaleUpperCase = 63,
532 kStringToLocaleLowerCase = 64,
533 kNumberToLocaleString = 65,
534 kDateToLocaleString = 66,
535 kDateToLocaleDateString = 67,
536 kDateToLocaleTimeString = 68,
537 kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
538 kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
539 kOBSOLETE_OptimizedFunctionWithOneShotBytecode = 71,
540 kRegExpMatchIsTrueishOnNonJSRegExp = 72,
541 kRegExpMatchIsFalseishOnJSRegExp = 73,
542 kOBSOLETE_DateGetTimezoneOffset = 74,
543 kStringNormalize = 75,
544 kCallSiteAPIGetFunctionSloppyCall = 76,
545 kCallSiteAPIGetThisSloppyCall = 77,
546 kOBSOLETE_RegExpMatchAllWithNonGlobalRegExp = 78,
547 kRegExpExecCalledOnSlowRegExp = 79,
548 kRegExpReplaceCalledOnSlowRegExp = 80,
549 kDisplayNames = 81,
550 kSharedArrayBufferConstructed = 82,
551 kArrayPrototypeHasElements = 83,
552 kObjectPrototypeHasElements = 84,
553 kNumberFormatStyleUnit = 85,
554 kDateTimeFormatRange = 86,
555 kDateTimeFormatDateTimeStyle = 87,
556 kBreakIteratorTypeWord = 88,
557 kBreakIteratorTypeLine = 89,
558 kInvalidatedArrayBufferDetachingProtector = 90,
559 kInvalidatedArrayConstructorProtector = 91,
560 kInvalidatedArrayIteratorLookupChainProtector = 92,
561 kInvalidatedArraySpeciesLookupChainProtector = 93,
562 kInvalidatedIsConcatSpreadableLookupChainProtector = 94,
563 kInvalidatedMapIteratorLookupChainProtector = 95,
564 kInvalidatedNoElementsProtector = 96,
565 kInvalidatedPromiseHookProtector = 97,
566 kInvalidatedPromiseResolveLookupChainProtector = 98,
567 kInvalidatedPromiseSpeciesLookupChainProtector = 99,
568 kInvalidatedPromiseThenLookupChainProtector = 100,
569 kInvalidatedRegExpSpeciesLookupChainProtector = 101,
570 kInvalidatedSetIteratorLookupChainProtector = 102,
571 kInvalidatedStringIteratorLookupChainProtector = 103,
572 kInvalidatedStringLengthOverflowLookupChainProtector = 104,
573 kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
574 kWasmSimdOpcodes = 106,
575 kVarRedeclaredCatchBinding = 107,
576 kWasmRefTypes = 108,
577 kOBSOLETE_WasmBulkMemory = 109,
578 kOBSOLETE_WasmMultiValue = 110,
579 kWasmExceptionHandling = 111,
580 kInvalidatedMegaDOMProtector = 112,
581 kFunctionPrototypeArguments = 113,
582 kFunctionPrototypeCaller = 114,
583 kTurboFanOsrCompileStarted = 115,
584 kAsyncStackTaggingCreateTaskCall = 116,
585 kDurationFormat = 117,
586 kInvalidatedNumberStringNotRegexpLikeProtector = 118,
587 kOBSOLETE_RegExpUnicodeSetIncompatibilitiesWithUnicodeMode = 119,
588 kOBSOLETE_ImportAssertionDeprecatedSyntax = 120,
589 kLocaleInfoObsoletedGetters = 121,
590 kLocaleInfoFunctions = 122,
591 kCompileHintsMagicAll = 123,
592 kInvalidatedNoProfilingProtector = 124,
593 kWasmMemory64 = 125,
594 kWasmMultiMemory = 126,
595 kWasmGC = 127,
596 kWasmImportedStrings = 128,
597 kSourceMappingUrlMagicCommentAtSign = 129,
598 kTemporalObject = 130,
599 kWasmModuleCompilation = 131,
600 kInvalidatedNoUndetectableObjectsProtector = 132,
601 kWasmJavaScriptPromiseIntegration = 133,
602 kWasmReturnCall = 134,
603 kWasmExtendedConst = 135,
604 kWasmRelaxedSimd = 136,
605 kWasmTypeReflection = 137,
606 kWasmExnRef = 138,
607 kWasmTypedFuncRef = 139,
608 kInvalidatedStringWrapperToPrimitiveProtector = 140,
609 kDocumentAllLegacyCall = 141,
610 kDocumentAllLegacyConstruct = 142,
611 kConsoleContext = 143,
612 kWasmImportedStringsUtf8 = 144,
613 kResizableArrayBuffer = 145,
614 kGrowableSharedArrayBuffer = 146,
615 kArrayByCopy = 147,
616 kArrayFromAsync = 148,
617 kIteratorMethods = 149,
618 kPromiseAny = 150,
619 kSetMethods = 151,
620 kArrayFindLast = 152,
621 kArrayGroup = 153,
622 kArrayBufferTransfer = 154,
623 kPromiseWithResolvers = 155,
624 kAtomicsWaitAsync = 156,
625 kExtendingNonExtensibleWithPrivate = 157,
626 kPromiseTry = 158,
627 kStringReplaceAll = 159,
628 kStringWellFormed = 160,
629 kWeakReferences = 161,
630 kErrorIsError = 162,
631
632 // If you add new values here, you'll also need to update Chromium's:
633 // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
634 // this list need to be landed first, then changes on the Chromium side.
635 kUseCounterFeatureCount // This enum value must be last.
636 };
637
639 kMessageLog = (1 << 0),
640 kMessageDebug = (1 << 1),
641 kMessageInfo = (1 << 2),
642 kMessageError = (1 << 3),
643 kMessageWarning = (1 << 4),
644 kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
645 kMessageWarning,
646 };
647
648 // The different priorities that an isolate can have.
649 enum class Priority {
650 // The isolate does not relate to content that is currently important
651 // to the user. Lowest priority.
653
654 // The isolate contributes to content that is visible to the user, like a
655 // visible iframe that's not interacted directly with. High priority.
657
658 // The isolate contributes to content that is of the utmost importance to
659 // the user, like visible content in the focused window. Highest priority.
661 };
662
663 using UseCounterCallback = void (*)(Isolate* isolate,
664 UseCounterFeature feature);
665
680 static Isolate* Allocate();
681 static Isolate* Allocate(const IsolateGroup& group);
682
687
691 static void Initialize(Isolate* isolate, const CreateParams& params);
692
702 static Isolate* New(const CreateParams& params);
703 static Isolate* New(const IsolateGroup& group, const CreateParams& params);
704
712
720
724 bool IsCurrent() const;
725
740
753
760
772
779
786
794
800
805
806#if defined(V8_OS_WIN)
810 V8_DEPRECATE_SOON("Use SetFilterETWSessionByURL2Callback instead")
811 void SetFilterETWSessionByURLCallback(FilterETWSessionByURLCallback callback);
812 void SetFilterETWSessionByURL2Callback(
813 FilterETWSessionByURL2Callback callback);
814#endif // V8_OS_WIN
815
823
830 void SetBatterySaverMode(bool battery_saver_mode_enabled);
831
838 void SetMemorySaverMode(bool memory_saver_mode_enabled);
839
846
857 void Enter();
858
866 void Exit();
867
872 void Dispose();
873
879
888
893 V8_INLINE void SetData(uint32_t slot, void* data);
894
899 V8_INLINE void* GetData(uint32_t slot);
900
905 V8_INLINE static uint32_t GetNumberOfDataSlots();
906
912 template <class T>
913 V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
914
920
926
930 void GetHeapStatistics(HeapStatistics* heap_statistics);
931
936
947 size_t index);
948
953
964 size_t type_index);
965
974
988 std::unique_ptr<MeasureMemoryDelegate> delegate,
989 MeasureMemoryExecution execution = MeasureMemoryExecution::kDefault);
990
1003 void GetStackSample(const RegisterState& state, void** frames,
1004 size_t frames_limit, SampleInfo* sample_info);
1005
1013 V8_DEPRECATE_SOON("Use ExternalMemoryAccounter instead.")
1014 int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
1015
1020 HeapProfiler* GetHeapProfiler();
1021
1025 void SetIdle(bool is_idle);
1026
1028 ArrayBuffer::Allocator* GetArrayBufferAllocator();
1029
1031 bool InContext();
1032
1037 Local<Context> GetCurrentContext();
1038
1045 Local<Context> GetEnteredOrMicrotaskContext();
1046
1051 Local<Context> GetIncumbentContext();
1052
1057 MaybeLocal<Data> GetCurrentHostDefinedOptions();
1058
1064 template <int N>
1065 Local<Value> ThrowError(const char (&message)[N]) {
1066 return ThrowError(String::NewFromUtf8Literal(this, message));
1067 }
1069
1077
1085
1086 using GCCallback = void (*)(Isolate* isolate, GCType type,
1087 GCCallbackFlags flags);
1088 using GCCallbackWithData = void (*)(Isolate* isolate, GCType type,
1089 GCCallbackFlags flags, void* data);
1090
1102 GCType gc_type_filter = kGCTypeAll);
1103
1109 void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
1110 GCType gc_type_filter = kGCTypeAll);
1111
1119
1126
1134 GCType gc_type_filter = kGCTypeAll);
1135
1141 void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
1142 GCType gc_type_filter = kGCTypeAll);
1143
1151
1158 void* data = nullptr);
1159
1168
1180 "Set the heap on Isolate creation using CreateParams instead.")
1181 void AttachCppHeap(CppHeap*);
1182
1189 "Set the heap on Isolate creation using CreateParams instead.")
1190 void DetachCppHeap();
1191
1196 CppHeap* GetCppHeap() const;
1197
1201 enum class AtomicsWaitEvent {
1203 kStartWait,
1205 kWokenUp,
1207 kTimedOut,
1209 kTerminatedExecution,
1211 kAPIStopped,
1213 kNotEqual
1214 };
1215
1220 class V8_DEPRECATED("AtomicsWaitWakeHandle is unused and will be removed.")
1222 public:
1237 void Wake();
1238 };
1239
1265 Local<SharedArrayBuffer> array_buffer,
1266 size_t offset_in_bytes, int64_t value,
1267 double timeout_in_ms,
1268 AtomicsWaitWakeHandle* stop_handle,
1269 void* data);
1271
1278 V8_DEPRECATED("SetAtomicsWaitCallback is unused and will be removed.")
1279 void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
1280
1282
1289 void SetGetExternallyAllocatedMemoryInBytesCallback(
1291
1299 void TerminateExecution();
1300
1309 bool IsExecutionTerminating();
1310
1325 void CancelTerminateExecution();
1326
1335 void RequestInterrupt(InterruptCallback callback, void* data);
1336
1342 bool HasPendingBackgroundTasks();
1343
1353 void RequestGarbageCollectionForTesting(GarbageCollectionType type);
1354
1365 void RequestGarbageCollectionForTesting(GarbageCollectionType type,
1366 StackState stack_state);
1367
1371 void SetEventLogger(LogEventCallback that);
1372
1379 void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1380
1384 void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1385
1393 void AddCallCompletedCallback(CallCompletedCallback callback);
1394
1398 void RemoveCallCompletedCallback(CallCompletedCallback callback);
1399
1404 void SetPromiseHook(PromiseHook hook);
1405
1410 void SetPromiseRejectCallback(PromiseRejectCallback callback);
1411
1419 void SetExceptionPropagationCallback(ExceptionPropagationCallback callback);
1420
1427 void PerformMicrotaskCheckpoint();
1428
1432 void EnqueueMicrotask(Local<Function> microtask);
1433
1437 void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
1438
1442 void SetMicrotasksPolicy(MicrotasksPolicy policy);
1443
1447 MicrotasksPolicy GetMicrotasksPolicy() const;
1448
1462 void AddMicrotasksCompletedCallback(
1463 MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1464
1468 void RemoveMicrotasksCompletedCallback(
1469 MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1470
1474 void SetUseCounterCallback(UseCounterCallback callback);
1475
1480 void SetCounterFunction(CounterLookupCallback);
1481
1488 void SetCreateHistogramFunction(CreateHistogramCallback);
1489 void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
1490
1500 void SetMetricsRecorder(
1501 const std::shared_ptr<metrics::Recorder>& metrics_recorder);
1502
1508 void SetAddCrashKeyCallback(AddCrashKeyCallback);
1509
1514 void LowMemoryNotification();
1515
1525 V8_DEPRECATE_SOON("Use version that passes ContextDependants.")
1526 int ContextDisposedNotification(bool dependant_context = true);
1527
1535 void ContextDisposedNotification(ContextDependants dependants);
1536
1541 V8_DEPRECATE_SOON("Use SetPriority(Priority::kUserBlocking) instead")
1542 void IsolateInForegroundNotification();
1543
1548 V8_DEPRECATE_SOON("Use SetPriority(Priority::kBestEffort) instead")
1549 void IsolateInBackgroundNotification();
1550
1555 void SetPriority(Priority priority);
1556
1569 void SetIsLoading(bool is_loading);
1570
1577 void Freeze(bool is_frozen);
1578
1583 void IncreaseHeapLimitForDebugging();
1584
1588 void RestoreOriginalHeapLimit();
1589
1594 bool IsHeapLimitIncreasedForDebugging();
1595
1618 void SetJitCodeEventHandler(JitCodeEventOptions options,
1619 JitCodeEventHandler event_handler);
1620
1630 void SetStackLimit(uintptr_t stack_limit);
1631
1647 void GetCodeRange(void** start, size_t* length_in_bytes);
1648
1653 void GetEmbeddedCodeRange(const void** start, size_t* length_in_bytes);
1654
1658 JSEntryStubs GetJSEntryStubs();
1659
1660 static constexpr size_t kMinCodePagesBufferSize = 32;
1661
1675 size_t CopyCodePages(size_t capacity, MemoryRange* code_pages_out);
1676
1678 void SetFatalErrorHandler(FatalErrorCallback that);
1679
1681 void SetOOMErrorHandler(OOMErrorCallback that);
1682
1688 void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
1689
1697 void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
1698 size_t heap_limit);
1699
1706 void AutomaticallyRestoreInitialHeapLimit(double threshold_percent = 0.5);
1707
1712 void SetModifyCodeGenerationFromStringsCallback(
1714
1719 void SetAllowWasmCodeGenerationCallback(
1721
1726 void SetWasmModuleCallback(ExtensionCallback callback);
1727 void SetWasmInstanceCallback(ExtensionCallback callback);
1728
1729 void SetWasmStreamingCallback(WasmStreamingCallback callback);
1730
1731 void SetWasmAsyncResolvePromiseCallback(
1733
1734 void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback);
1735
1736 void SetWasmImportedStringsEnabledCallback(
1738
1739 void SetSharedArrayBufferConstructorEnabledCallback(
1741
1742 void SetWasmJSPIEnabledCallback(WasmJSPIEnabledCallback callback);
1743
1749 "Will be removed, use ScriptCompiler::CompileOptions for enabling the "
1750 "compile hints magic comments")
1751 void SetJavaScriptCompileHintsMagicEnabledCallback(
1753
1759 void InstallConditionalFeatures(Local<Context> context);
1760
1765 bool IsDead();
1766
1776 bool AddMessageListener(MessageCallback that,
1777 Local<Value> data = Local<Value>());
1778
1790 bool AddMessageListenerWithErrorLevel(MessageCallback that,
1791 int message_levels,
1792 Local<Value> data = Local<Value>());
1793
1797 void RemoveMessageListeners(MessageCallback that);
1798
1800 void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
1801
1806 void SetCaptureStackTraceForUncaughtExceptions(
1807 bool capture, int frame_limit = 10,
1808 StackTrace::StackTraceOptions options = StackTrace::kOverview);
1809
1814 bool IsInUse();
1815
1821 void SetAllowAtomicsWait(bool allow);
1822
1836 enum class TimeZoneDetection { kSkip, kRedetect };
1837
1849 TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip);
1850
1861
1866 std::string GetDefaultLocale();
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>
1883
1885 size_t index);
1886 int64_t AdjustAmountOfExternalAllocatedMemoryImpl(int64_t change_in_bytes);
1887 void HandleExternalMemoryInterrupt();
1888};
1889
1890void Isolate::SetData(uint32_t slot, void* data) {
1891 using I = internal::Internals;
1892 I::SetEmbedderData(this, slot, data);
1893}
1894
1895void* Isolate::GetData(uint32_t slot) {
1896 using I = internal::Internals;
1897 return I::GetEmbedderData(this, slot);
1898}
1899
1900uint32_t Isolate::GetNumberOfDataSlots() {
1901 using I = internal::Internals;
1902 return I::kNumIsolateDataSlots;
1903}
1904
1905template <class T>
1906MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
1907 if (auto repr = GetDataFromSnapshotOnce(index);
1908 repr != internal::ValueHelper::kEmpty) {
1909 internal::PerformCastCheck(internal::ValueHelper::ReprAsValue<T>(repr));
1910 return Local<T>::FromRepr(repr);
1911 }
1912 return {};
1913}
1914
1915} // namespace v8
1916
1917#endif // INCLUDE_V8_ISOLATE_H_
Definition: v8-array-buffer.h:124
Definition: v8-context.h:48
Definition: v8-cppgc.h:65
Definition: v8-data.h:18
Definition: v8-embedder-heap.h:22
Definition: v8-external-memory-accounter.h:23
Definition: v8-function.h:26
Definition: v8-statistics.h:219
Definition: v8-statistics.h:202
Definition: v8-profiler.h:953
Definition: v8-statistics.h:183
Definition: v8-statistics.h:140
Definition: v8-isolate.h:218
static IsolateGroup Create()
IsolateGroup & operator=(const IsolateGroup &)=delete
static IsolateGroup GetDefault()
bool operator!=(const IsolateGroup &other) const
Definition: v8-isolate.h:252
IsolateGroup(const IsolateGroup &)=delete
IsolateGroup(IsolateGroup &&other)
bool operator==(const IsolateGroup &other) const
Definition: v8-isolate.h:248
static bool CanCreateNewGroups()
IsolateGroup & operator=(IsolateGroup &&other)
Definition: v8-isolate.h:408
AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope &)=delete
AllowJavascriptExecutionScope & operator=(const AllowJavascriptExecutionScope &)=delete
Definition: v8-isolate.h:1221
DisallowJavascriptExecutionScope(Isolate *isolate, OnFailure on_failure)
DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope &)=delete
DisallowJavascriptExecutionScope & operator=(const DisallowJavascriptExecutionScope &)=delete
@ CRASH_ON_FAILURE
Definition: v8-isolate.h:388
Definition: v8-isolate.h:367
Scope(Isolate *isolate)
Definition: v8-isolate.h:369
Scope(const Scope &)=delete
~Scope()
Definition: v8-isolate.h:373
Scope & operator=(const Scope &)=delete
SuppressMicrotaskExecutionScope(Isolate *isolate, MicrotaskQueue *microtask_queue=nullptr)
SuppressMicrotaskExecutionScope & operator=(const SuppressMicrotaskExecutionScope &)=delete
SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope &)=delete
Definition: v8-isolate.h:273
int GetStackTraceLimit()
void RemoveGCEpilogueCallback(GCCallback callback)
void AddGCPrologueCallback(GCCallbackWithData callback, void *data=nullptr, GCType gc_type_filter=kGCTypeAll)
bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics *object_statistics)
bool MeasureMemory(std::unique_ptr< MeasureMemoryDelegate > delegate, MeasureMemoryExecution execution=MeasureMemoryExecution::kDefault)
size_t NumberOfTrackedHeapObjectTypes()
void RemoveGCEpilogueCallback(GCCallbackWithData callback, void *data=nullptr)
void Dispose()
void LocaleConfigurationChangeNotification()
bool GetHeapSpaceStatistics(HeapSpaceStatistics *space_statistics, size_t index)
void ClearKeptObjects()
Local< Value > ThrowError(Local< String > message)
size_t(*)() GetExternallyAllocatedMemoryInBytesCallback
Definition: v8-isolate.h:1281
static Isolate * New(const CreateParams &params)
Isolate()=delete
static Isolate * GetCurrent()
static void Initialize(Isolate *isolate, const CreateParams &params)
bool HasPendingException()
static Isolate * New(const IsolateGroup &group, const CreateParams &params)
TimeZoneDetection
Definition: v8-isolate.h:1836
void SetMemorySaverMode(bool memory_saver_mode_enabled)
GarbageCollectionType
Definition: v8-isolate.h:454
@ kFullGarbageCollection
Definition: v8-isolate.h:455
void DumpAndResetStats()
void SetHostImportModuleDynamicallyCallback(HostImportModuleDynamicallyCallback callback)
void(*)(Isolate *isolate, GCType type, GCCallbackFlags flags) GCCallback
Definition: v8-isolate.h:1087
bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics *object_statistics, size_t type_index)
static Isolate * Allocate(const IsolateGroup &group)
void SetIsJSApiWrapperNativeErrorCallback(IsJSApiWrapperNativeErrorCallback callback)
void(*)(Isolate *isolate, UseCounterFeature feature) UseCounterCallback
Definition: v8-isolate.h:664
void(*)(Isolate *isolate, GCType type, GCCallbackFlags flags, void *data) GCCallbackWithData
Definition: v8-isolate.h:1089
void SetHostCreateShadowRealmContextCallback(HostCreateShadowRealmContextCallback callback)
bool IsCurrent() const
void AddGCPrologueCallback(GCCallback callback, GCType gc_type_filter=kGCTypeAll)
void RemoveGCPrologueCallback(GCCallback callback)
void SetBatterySaverMode(bool battery_saver_mode_enabled)
void DateTimeConfigurationChangeNotification(TimeZoneDetection time_zone_detection=TimeZoneDetection::kSkip)
void GetStackSample(const RegisterState &state, void **frames, size_t frames_limit, SampleInfo *sample_info)
void SetEmbedderRootsHandler(EmbedderRootsHandler *handler)
void AddGCEpilogueCallback(GCCallbackWithData callback, void *data=nullptr, GCType gc_type_filter=kGCTypeAll)
Isolate & operator=(const Isolate &)=delete
std::string GetDefaultLocale()
AtomicsWaitEvent
Definition: v8-isolate.h:1201
void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback)
Priority
Definition: v8-isolate.h:649
Isolate(const Isolate &)=delete
void(*)(AtomicsWaitEvent event, Local< SharedArrayBuffer > array_buffer, size_t offset_in_bytes, int64_t value, double timeout_in_ms, AtomicsWaitWakeHandle *stop_handle, void *data) AtomicsWaitCallback
Definition: v8-isolate.h:1269
void AddGCEpilogueCallback(GCCallback callback, GCType gc_type_filter=kGCTypeAll)
void DiscardThreadSpecificMetadata()
static Isolate * TryGetCurrent()
Local< Value > ThrowException(Local< Value > exception)
static Isolate * Allocate()
MessageErrorLevel
Definition: v8-isolate.h:638
bool(*)(Isolate *) AbortOnUncaughtExceptionCallback
Definition: v8-isolate.h:750
void SetHostInitializeImportMetaObjectCallback(HostInitializeImportMetaObjectCallback callback)
Local< Value > GetContinuationPreservedEmbedderData()
size_t NumberOfHeapSpaces()
void GetHeapStatistics(HeapStatistics *heap_statistics)
void SetContinuationPreservedEmbedderData(Local< Value > data)
void MemoryPressureNotification(MemoryPressureLevel level)
IsolateGroup GetGroup() const
void Enter()
UseCounterFeature
Definition: v8-isolate.h:467
~Isolate()=delete
void RemoveGCPrologueCallback(GCCallbackWithData, void *data=nullptr)
void SetAbortOnUncaughtExceptionCallback(AbortOnUncaughtExceptionCallback callback)
void ClearCachesForTesting()
void SetHostImportModuleWithPhaseDynamicallyCallback(HostImportModuleWithPhaseDynamicallyCallback callback)
Definition: v8-local-handle.h:266
Definition: v8-local-handle.h:632
Definition: v8-microtask-queue.h:40
Definition: v8-util.h:166
Definition: v8-isolate.h:64
void set_code_range_size_in_bytes(size_t limit)
Definition: v8-isolate.h:115
size_t max_old_generation_size_in_bytes() const
Definition: v8-isolate.h:124
void set_stack_limit(uint32_t *value)
Definition: v8-isolate.h:103
void set_initial_old_generation_size_in_bytes(size_t initial_size)
Definition: v8-isolate.h:146
void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes, size_t maximum_heap_size_in_bytes)
uint32_t * stack_limit() const
Definition: v8-isolate.h:102
size_t code_range_size_in_bytes() const
Definition: v8-isolate.h:114
void set_initial_young_generation_size_in_bytes(size_t initial_size)
Definition: v8-isolate.h:153
size_t initial_young_generation_size_in_bytes() const
Definition: v8-isolate.h:150
size_t max_young_generation_size_in_bytes() const
Definition: v8-isolate.h:136
void set_max_young_generation_size_in_bytes(size_t limit)
Definition: v8-isolate.h:139
size_t initial_old_generation_size_in_bytes() const
Definition: v8-isolate.h:143
void ConfigureDefaults(uint64_t physical_memory, uint64_t virtual_memory_limit)
void set_max_old_generation_size_in_bytes(size_t limit)
Definition: v8-isolate.h:127
Definition: v8-script.h:402
Definition: v8-container.h:148
Definition: v8-array-buffer.h:437
Definition: v8-debug.h:117
Definition: v8-snapshot.h:21
Definition: v8-value.h:32
Definition: v8-internal.h:830
internal::Address * InternalRepresentationType
Definition: v8-internal.h:1622
Definition: v8-metrics.h:186
EmbedderStackState
Definition: common.h:15
uintptr_t Address
Definition: v8-internal.h:52
Definition: libplatform.h:15
void(*)(const JitCodeEvent *event) JitCodeEventHandler
Definition: v8-callbacks.h:142
JitCodeEventOptions
Definition: v8-callbacks.h:129
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Definition: v8-callbacks.h:230
bool(*)(Local< Context > context) SharedArrayBufferConstructorEnabledCallback
Definition: v8-callbacks.h:326
void(*)(void *data) MicrotaskCallback
Definition: v8-microtask.h:14
GCCallbackFlags
Definition: v8-callbacks.h:179
bool(*)(Local< Context > context) WasmJSPIEnabledCallback
Definition: v8-callbacks.h:333
MicrotasksPolicy
Definition: v8-microtask.h:24
void(*)(Isolate *isolate, Local< Context > context, Local< Promise::Resolver > resolver, Local< Value > result, WasmAsyncSuccess success) WasmAsyncResolvePromiseCallback
Definition: v8-callbacks.h:315
bool(*)(const FunctionCallbackInfo< Value > &) ExtensionCallback
Definition: v8-callbacks.h:298
void(*)(PromiseHookType type, Local< Promise > promise, Local< Value > parent) PromiseHook
Definition: v8-promise.h:144
void(*)(Isolate *, void *) MicrotasksCompletedCallbackWithData
Definition: v8-microtask.h:13
bool(*)(Local< Context > context) JavaScriptCompileHintsMagicEnabledCallback
Definition: v8-callbacks.h:330
ContextDependants
Definition: v8-isolate.h:181
void(*)(ExceptionPropagationMessage message) ExceptionPropagationCallback
Definition: v8-exception.h:133
void(*)(const FunctionCallbackInfo< Value > &) WasmStreamingCallback
Definition: v8-callbacks.h:308
void *(*)(const char *name, int min, int max, size_t buckets) CreateHistogramCallback
Definition: v8-callbacks.h:216
void(*)(Local< Context > context, Local< Module > module, Local< Object > meta) HostInitializeImportMetaObjectCallback
Definition: v8-callbacks.h:434
void(*)(Local< Message > message, Local< Value > data) MessageCallback
Definition: v8-callbacks.h:232
void(*)(CrashKeyId id, const std::string &value) AddCrashKeyCallback
Definition: v8-callbacks.h:253
void(*)(Isolate *isolate, void *data) InterruptCallback
Definition: v8-callbacks.h:191
void(*)(Isolate *) CallCompletedCallback
Definition: v8-callbacks.h:257
void(*)(void *histogram, int sample) AddHistogramSampleCallback
Definition: v8-callbacks.h:218
size_t(*)(void *data, size_t current_heap_limit, size_t initial_heap_limit) NearHeapLimitCallback
Definition: v8-callbacks.h:201
void(*)(Isolate *) BeforeCallEnteredCallback
Definition: v8-callbacks.h:256
bool(*)(Local< Context > context, Local< String > source) AllowWasmCodeGenerationCallback
Definition: v8-callbacks.h:301
void(*)(const char *location, const char *message) FatalErrorCallback
Definition: v8-callbacks.h:222
void(*)(PromiseRejectMessage message) PromiseRejectCallback
Definition: v8-promise.h:170
GCType
Definition: v8-callbacks.h:154
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source, bool is_code_like) ModifyCodeGenerationFromStringsCallback2
Definition: v8-callbacks.h:279
void(*)(Local< Object > target, AccessType type, Local< Value > data) FailedAccessCheckCallback
Definition: v8-callbacks.h:295
bool(*)(Local< Context > context) WasmImportedStringsEnabledCallback
Definition: v8-callbacks.h:322
void(*)(const char *name, int status) LogEventCallback
Definition: v8-callbacks.h:238
MemoryPressureLevel
Definition: v8-isolate.h:175
MeasureMemoryExecution
Definition: v8-statistics.h:43
int *(*)(const char *name) CounterLookupCallback
Definition: v8-callbacks.h:213
bool(*)(Isolate *isolate, Local< Object > obj) IsJSApiWrapperNativeErrorCallback
Definition: v8-callbacks.h:456
Definition: v8-isolate.h:278
Definition: v8-unwinder.h:69
Definition: v8-unwinder.h:60
Definition: v8-unwinder.h:21
Definition: v8-unwinder.h:50
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:603
#define V8_DEPRECATED(message)
Definition: v8config.h:595
#define END_ALLOW_USE_DEPRECATED()
Definition: v8config.h:623
#define ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(ClassName)
Definition: v8config.h:626
#define START_ALLOW_USE_DEPRECATED()
Definition: v8config.h:622
#define V8_NODISCARD
Definition: v8config.h:682