25 #include "v8-internal.h" 26 #include "v8-version.h" 37 class AccessorSignature;
49 class FunctionTemplate;
51 class ImplementationUtilities;
61 class ObjectOperationDescriptor;
68 class RawOperationDescriptor;
91 template <
class T,
class M = NonCopyablePersistentTraits<T> >
96 template <
class K,
class V,
class T>
98 template <
class K,
class V,
class T>
109 class CallHandlerHelper;
115 class DeferredHandles;
119 class LocalEmbedderHeapTracer;
120 class NeverReadOnlySpaceObject;
121 struct ScriptStreamingData;
130 class StreamingDecoder;
136 class ConsoleCallArguments;
141 #define TYPE_CHECK(T, S) \ 143 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ 180 V8_INLINE Local() : val_(nullptr) {}
183 : val_(reinterpret_cast<
T*>(*that)) {
195 V8_INLINE
bool IsEmpty()
const {
return val_ ==
nullptr; }
200 V8_INLINE
void Clear() { val_ =
nullptr; }
202 V8_INLINE
T* operator->()
const {
return val_; }
204 V8_INLINE T* operator*()
const {
return val_; }
216 if (a ==
nullptr)
return b ==
nullptr;
217 if (b ==
nullptr)
return false;
225 if (a ==
nullptr)
return b ==
nullptr;
226 if (b ==
nullptr)
return false;
252 #ifdef V8_ENABLE_CHECKS 255 if (that.IsEmpty())
return Local<T>();
281 template<
class F>
friend class Eternal;
283 template<
class F,
class M>
friend class Persistent;
284 template<
class F>
friend class Local;
291 friend class Context;
292 friend class Isolate;
301 template <
class F1,
class F2,
class F3>
307 explicit V8_INLINE
Local(
T* that) : val_(that) {}
308 V8_INLINE
static Local<T>
New(Isolate* isolate, T* that);
313 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS) 316 using Handle = Local<T>;
333 V8_INLINE MaybeLocal() : val_(nullptr) {}
335 V8_INLINE MaybeLocal(Local<S> that)
336 : val_(reinterpret_cast<T*>(*that)) {
340 V8_INLINE
bool IsEmpty()
const {
return val_ ==
nullptr; }
348 out->val_ = IsEmpty() ? nullptr : this->val_;
364 return IsEmpty() ? default_value :
Local<S>(val_);
375 template <
class T>
class Eternal {
377 V8_INLINE Eternal() : val_(nullptr) {}
379 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
380 Set(isolate, handle);
383 V8_INLINE Local<T> Get(Isolate* isolate)
const;
384 V8_INLINE
bool IsEmpty()
const {
return val_ ==
nullptr; }
385 template<
class S> V8_INLINE
void Set(Isolate* isolate, Local<S> handle);
392 static const int kInternalFieldsInWeakCallback = 2;
393 static const int kEmbedderFieldsInWeakCallback = 2;
395 template <
typename T>
401 void* embedder_fields[kEmbedderFieldsInWeakCallback],
403 : isolate_(isolate), parameter_(parameter), callback_(callback) {
404 for (
int i = 0;
i < kEmbedderFieldsInWeakCallback; ++
i) {
405 embedder_fields_[
i] = embedder_fields[
i];
409 V8_INLINE Isolate* GetIsolate()
const {
return isolate_; }
410 V8_INLINE
T* GetParameter()
const {
return parameter_; }
411 V8_INLINE
void* GetInternalField(
int index)
const;
419 void SetSecondPassCallback(Callback callback)
const { *callback_ = callback; }
425 void* embedder_fields_[kEmbedderFieldsInWeakCallback];
434 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };
449 template <
class T>
class PersistentBase {
455 V8_INLINE
void Reset();
461 V8_INLINE
void Reset(Isolate* isolate,
const Local<S>& other);
468 V8_INLINE
void Reset(Isolate* isolate,
const PersistentBase<S>& other);
470 V8_INLINE
bool IsEmpty()
const {
return val_ ==
nullptr; }
471 V8_INLINE
void Empty() { val_ = 0; }
473 V8_INLINE Local<T> Get(Isolate* isolate)
const {
478 V8_INLINE
bool operator==(
const PersistentBase<S>& that)
const {
479 internal::Address* a =
reinterpret_cast<internal::Address*
>(this->val_);
480 internal::Address* b =
reinterpret_cast<internal::Address*
>(that.val_);
481 if (a ==
nullptr)
return b ==
nullptr;
482 if (b ==
nullptr)
return false;
487 V8_INLINE
bool operator==(
const Local<S>& that)
const {
488 internal::Address* a =
reinterpret_cast<internal::Address*
>(this->val_);
489 internal::Address* b =
reinterpret_cast<internal::Address*
>(that.val_);
490 if (a ==
nullptr)
return b ==
nullptr;
491 if (b ==
nullptr)
return false;
496 V8_INLINE
bool operator!=(
const PersistentBase<S>& that)
const {
497 return !operator==(that);
501 V8_INLINE
bool operator!=(
const Local<S>& that)
const {
502 return !operator==(that);
512 template <
typename P>
513 V8_INLINE
void SetWeak(P* parameter,
514 typename WeakCallbackInfo<P>::Callback callback,
515 WeakCallbackType type);
527 V8_INLINE P* ClearWeak();
530 V8_INLINE
void ClearWeak() { ClearWeak<void>(); }
554 "Objects are always considered independent. " 555 "Use MarkActive to avoid collecting otherwise dead weak handles.",
556 V8_INLINE
void MarkIndependent());
568 V8_INLINE
bool IsIndependent()
const);
574 V8_INLINE
bool IsWeak()
const;
588 PersistentBase(
const PersistentBase& other) =
delete;
589 void operator=(
const PersistentBase&) =
delete;
592 friend class Isolate;
594 template<
class F>
friend class Local;
595 template<
class F1,
class F2>
friend class Persistent;
598 template<
class F>
friend class PersistentBase;
599 template<
class F>
friend class ReturnValue;
600 template <
class F1,
class F2,
class F3>
601 friend class PersistentValueMapBase;
602 template<
class F1,
class F2>
friend class PersistentValueVector;
605 explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
606 V8_INLINE
static T* New(Isolate* isolate, T* that);
619 class NonCopyablePersistentTraits {
621 typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
622 static const bool kResetInDestructor =
false;
623 template<
class S,
class M>
624 V8_INLINE
static void Copy(
const Persistent<S, M>& source,
625 NonCopyablePersistent* dest) {
626 Uncompilable<Object>();
629 template<
class O> V8_INLINE
static void Uncompilable() {
630 TYPE_CHECK(O, Primitive);
642 static const bool kResetInDestructor =
true;
643 template<
class S,
class M>
680 template <
class S,
class M2>
694 template <
class S,
class M2>
702 template <
class S,
class M2>
703 V8_INLINE
Persistent& operator=(
const Persistent<S, M2>& that) {
713 if (M::kResetInDestructor) this->
Reset();
719 #ifdef V8_ENABLE_CHECKS 722 if (!that.IsEmpty()) T::Cast(*that);
729 V8_INLINE Persistent<S>& As()
const {
730 return Persistent<S>::Cast(*
this);
734 friend class Isolate;
736 template<
class F>
friend class Local;
737 template<
class F1,
class F2>
friend class Persistent;
738 template<
class F>
friend class ReturnValue;
740 explicit V8_INLINE
Persistent(T* that) : PersistentBase<T>(that) {}
741 V8_INLINE T* operator*()
const {
return this->val_; }
742 template<
class S,
class M2>
743 V8_INLINE
void Copy(
const Persistent<S, M2>& that);
753 class Global :
public PersistentBase<T> {
783 other.val_ =
nullptr;
794 this->val_ = rhs.val_;
807 typedef void MoveOnlyTypeForCPP03;
815 V8_INLINE
T* operator*()
const {
return this->val_; }
821 using UniquePersistent = Global<T>;
847 static int NumberOfHandles(Isolate* isolate);
849 V8_INLINE Isolate* GetIsolate()
const {
850 return reinterpret_cast<Isolate*
>(isolate_);
859 void Initialize(Isolate* isolate);
867 void*
operator new(
size_t size);
868 void*
operator new[](
size_t size);
869 void operator delete(
void*,
size_t);
870 void operator delete[](
void*,
size_t);
881 template<
class F>
friend class Local;
886 friend class Context;
906 Escape(reinterpret_cast<internal::Address*>(*value));
907 return Local<T>(
reinterpret_cast<T*
>(slot));
912 return Escape(value.FromMaybe(
Local<T>()));
915 EscapableHandleScope(
const EscapableHandleScope&) =
delete;
916 void operator=(
const EscapableHandleScope&) =
delete;
921 void*
operator new(
size_t size);
922 void*
operator new[](
size_t size);
923 void operator delete(
void*,
size_t);
924 void operator delete[](
void*,
size_t);
926 internal::Address* Escape(internal::Address* escape_value);
927 internal::Address* escape_slot_;
946 void*
operator new(
size_t size);
947 void*
operator new[](
size_t size);
948 void operator delete(
void*,
size_t);
949 void operator delete[](
void*,
size_t);
953 int prev_sealed_level_;
1011 bool is_opaque =
false,
bool is_wasm =
false,
1012 bool is_module =
false)
1013 : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1014 (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1015 (is_module ? kIsModule : 0)) {}
1018 (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1020 bool IsSharedCrossOrigin()
const {
1021 return (flags_ & kIsSharedCrossOrigin) != 0;
1023 bool IsOpaque()
const {
return (flags_ & kIsOpaque) != 0; }
1024 bool IsWasm()
const {
return (flags_ & kIsWasm) != 0; }
1025 bool IsModule()
const {
return (flags_ & kIsModule) != 0; }
1027 int Flags()
const {
return flags_; }
1031 kIsSharedCrossOrigin = 1,
1100 int GetLineNumber(
int code_pos);
1102 static const int kNoScriptId = 0;
1117 int GetLineNumber() {
return line_number_; }
1118 int GetColumnNumber() {
return column_number_; }
1120 Location(
int line_number,
int column_number)
1121 : line_number_(line_number), column_number_(column_number) {}
1152 Status GetStatus()
const;
1162 int GetModuleRequestsLength()
const;
1174 Location GetModuleRequestLocation(
int i)
const;
1179 int GetIdentityHash()
const;
1193 ResolveCallback callback);
1270 buffer_policy(BufferNotOwned) {}
1277 BufferPolicy buffer_policy = BufferNotOwned);
1281 const uint8_t* data;
1284 BufferPolicy buffer_policy;
1306 V8_INLINE
const CachedData* GetCachedData()
const;
1362 virtual size_t GetMoreData(
const uint8_t** src) = 0;
1374 virtual bool SetBookmark();
1379 virtual void ResetToBookmark();
1390 enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1395 V8_DEPRECATED(
"No longer used",
const CachedData* GetCachedData()
const) {
1406 std::unique_ptr<internal::ScriptStreamingData> impl_;
1426 enum CompileOptions {
1427 kNoCompileOptions = 0,
1436 kNoCacheNoReason = 0,
1437 kNoCacheBecauseCachingDisabled,
1438 kNoCacheBecauseNoResource,
1439 kNoCacheBecauseInlineScript,
1440 kNoCacheBecauseModule,
1441 kNoCacheBecauseStreamingSource,
1442 kNoCacheBecauseInspector,
1443 kNoCacheBecauseScriptTooSmall,
1444 kNoCacheBecauseCacheTooCold,
1445 kNoCacheBecauseV8Extension,
1446 kNoCacheBecauseExtensionModule,
1447 kNoCacheBecausePacScript,
1448 kNoCacheBecauseInDocumentWrite,
1449 kNoCacheBecauseResourceWithNoCacheHandler,
1450 kNoCacheBecauseDeferredProduceCodeCache
1467 Isolate* isolate, Source* source,
1468 CompileOptions options = kNoCompileOptions,
1469 NoCacheReason no_cache_reason = kNoCacheNoReason);
1484 CompileOptions options = kNoCompileOptions,
1485 NoCacheReason no_cache_reason = kNoCacheNoReason);
1498 static ScriptStreamingTask* StartStreamingScript(
1499 Isolate* isolate, StreamedSource* source,
1500 CompileOptions options = kNoCompileOptions);
1531 static uint32_t CachedDataVersionTag();
1541 Isolate* isolate, Source* source,
1542 CompileOptions options = kNoCompileOptions,
1543 NoCacheReason no_cache_reason = kNoCacheNoReason);
1559 CompileOptions options = kNoCompileOptions,
1560 NoCacheReason no_cache_reason = kNoCacheNoReason);
1574 static CachedData* CreateCodeCache(
1583 static CachedData* CreateCodeCacheForFunction(
Local<Function> function);
1587 Isolate* isolate, Source* source, CompileOptions options,
1588 NoCacheReason no_cache_reason);
1602 Isolate* GetIsolate()
const;
1635 int GetStartPosition()
const;
1641 int GetEndPosition()
const;
1646 int ErrorLevel()
const;
1652 int GetStartColumn()
const;
1659 int GetEndColumn()
const;
1666 bool IsSharedCrossOrigin()
const;
1667 bool IsOpaque()
const;
1670 static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1672 static const int kNoLineNumberInfo = 0;
1673 static const int kNoColumnInfo = 0;
1674 static const int kNoScriptIdInfo = 0;
1693 kColumnOffset = 1 << 1 | kLineNumber,
1694 kScriptName = 1 << 2,
1695 kFunctionName = 1 << 3,
1697 kIsConstructor = 1 << 5,
1698 kScriptNameOrSourceURL = 1 << 6,
1700 kExposeFramesAcrossSecurityOrigins = 1 << 8,
1701 kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1702 kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1713 int GetFrameCount()
const;
1723 Isolate* isolate,
int frame_limit, StackTraceOptions options = kDetailed);
1738 int GetLineNumber()
const;
1747 int GetColumn()
const;
1755 int GetScriptId()
const;
1780 bool IsEval()
const;
1786 bool IsConstructor()
const;
1791 bool IsWasm()
const;
1818 size_t frames_count;
1820 void* external_callback_entry;
1825 const void* start =
nullptr;
1826 size_t length_in_bytes = 0;
1851 static V8_DEPRECATED(
"Use the maybe version taking context",
1888 virtual void ThrowDataCloneError(
Local<String> message) = 0;
1923 virtual void* ReallocateBufferMemory(
void* old_buffer,
size_t size,
1924 size_t* actual_size);
1931 virtual void FreeBufferMemory(
void* buffer);
1953 V8_DEPRECATED(
"Use Release()", std::vector<uint8_t> ReleaseBuffer());
1961 V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
1968 void TransferArrayBuffer(
uint32_t transfer_id,
1974 V8_DEPRECATED(
"Use Delegate::GetSharedArrayBufferId",
1975 void TransferSharedArrayBuffer(
1986 void SetTreatArrayBufferViewsAsHostObjects(
bool mode);
1994 void WriteUint64(uint64_t value);
1995 void WriteDouble(
double value);
1996 void WriteRawBytes(
const void* source,
size_t length);
2032 Isolate* isolate,
uint32_t transfer_id);
2039 Isolate* isolate,
uint32_t clone_id);
2062 void TransferArrayBuffer(
uint32_t transfer_id,
2070 void TransferSharedArrayBuffer(
uint32_t id,
2080 void SetSupportsLegacyWireFormat(
bool supports_legacy_wire_format);
2085 void SetExpectInlineWasm(
bool allow_inline_wasm);
2092 uint32_t GetWireFormatVersion()
const;
2099 V8_WARN_UNUSED_RESULT
bool ReadUint32(
uint32_t* value);
2100 V8_WARN_UNUSED_RESULT
bool ReadUint64(uint64_t* value);
2101 V8_WARN_UNUSED_RESULT
bool ReadDouble(
double* value);
2102 V8_WARN_UNUSED_RESULT
bool ReadRawBytes(
size_t length,
const void** data);
2125 V8_INLINE
bool IsUndefined()
const;
2131 V8_INLINE
bool IsNull()
const;
2138 V8_INLINE
bool IsNullOrUndefined()
const;
2143 bool IsTrue()
const;
2148 bool IsFalse()
const;
2153 bool IsName()
const;
2159 V8_INLINE
bool IsString()
const;
2164 bool IsSymbol()
const;
2169 bool IsFunction()
const;
2175 bool IsArray()
const;
2180 bool IsObject()
const;
2185 bool IsBigInt()
const;
2190 bool IsBoolean()
const;
2195 bool IsNumber()
const;
2200 bool IsExternal()
const;
2205 bool IsInt32()
const;
2210 bool IsUint32()
const;
2215 bool IsDate()
const;
2220 bool IsArgumentsObject()
const;
2225 bool IsBigIntObject()
const;
2230 bool IsBooleanObject()
const;
2235 bool IsNumberObject()
const;
2240 bool IsStringObject()
const;
2245 bool IsSymbolObject()
const;
2250 bool IsNativeError()
const;
2255 bool IsRegExp()
const;
2260 bool IsAsyncFunction()
const;
2265 bool IsGeneratorFunction()
const;
2270 bool IsGeneratorObject()
const;
2275 bool IsPromise()
const;
2290 bool IsMapIterator()
const;
2295 bool IsSetIterator()
const;
2300 bool IsWeakMap()
const;
2305 bool IsWeakSet()
const;
2310 bool IsArrayBuffer()
const;
2315 bool IsArrayBufferView()
const;
2320 bool IsTypedArray()
const;
2325 bool IsUint8Array()
const;
2330 bool IsUint8ClampedArray()
const;
2335 bool IsInt8Array()
const;
2340 bool IsUint16Array()
const;
2345 bool IsInt16Array()
const;
2350 bool IsUint32Array()
const;
2355 bool IsInt32Array()
const;
2360 bool IsFloat32Array()
const;
2365 bool IsFloat64Array()
const;
2370 bool IsBigInt64Array()
const;
2375 bool IsBigUint64Array()
const;
2380 bool IsDataView()
const;
2386 bool IsSharedArrayBuffer()
const;
2391 bool IsProxy()
const;
2393 bool IsWebAssemblyCompiledModule()
const;
2398 bool IsModuleNamespaceObject()
const;
2402 V8_DEPRECATE_SOON(
"ToBoolean can never throw. Use Local version.",
2420 V8_DEPRECATE_SOON(
"Use maybe version",
2422 V8_DEPRECATE_SOON(
"Use maybe version",
2424 V8_DEPRECATE_SOON(
"Use maybe version",
2426 V8_DEPRECATE_SOON(
"Use maybe version",
2428 V8_DEPRECATE_SOON(
"Use maybe version",
2438 bool BooleanValue(Isolate* isolate)
const;
2440 V8_DEPRECATE_SOON(
"BooleanValue can never throw. Use Isolate version.",
2456 template <
class T> V8_INLINE
static Value* Cast(
T* value);
2463 V8_INLINE
bool QuickIsUndefined()
const;
2464 V8_INLINE
bool QuickIsNull()
const;
2465 V8_INLINE
bool QuickIsNullOrUndefined()
const;
2466 V8_INLINE
bool QuickIsString()
const;
2467 bool FullIsUndefined()
const;
2468 bool FullIsNull()
const;
2469 bool FullIsString()
const;
2487 V8_INLINE
static Local<Boolean> New(Isolate* isolate,
bool value);
2506 int GetIdentityHash();
2508 V8_INLINE
static Name* Cast(
Value* obj);
2511 static void CheckCast(
Value* obj);
2539 static constexpr
int kMaxLength = internal::kApiTaggedSize == 4
2541 : internal::kSmiMaxValue / 2 - 24;
2544 UNKNOWN_ENCODING = 0x1,
2545 TWO_BYTE_ENCODING = 0x0,
2546 ONE_BYTE_ENCODING = 0x8
2557 int Utf8Length(Isolate* isolate)
const;
2565 bool IsOneByte()
const;
2572 bool ContainsOnlyOneByte()
const;
2601 HINT_MANY_WRITES_EXPECTED = 1,
2602 NO_NULL_TERMINATION = 2,
2603 PRESERVE_ONE_BYTE_NULL = 4,
2607 REPLACE_INVALID_UTF8 = 8
2611 int Write(Isolate* isolate, uint16_t* buffer,
int start = 0,
int length = -1,
2612 int options = NO_OPTIONS)
const;
2614 int WriteOneByte(Isolate* isolate, uint8_t* buffer,
int start = 0,
2615 int length = -1,
int options = NO_OPTIONS)
const;
2617 int WriteUtf8(Isolate* isolate,
char* buffer,
int length = -1,
2618 int* nchars_ref =
nullptr,
int options = NO_OPTIONS)
const;
2628 bool IsExternal()
const;
2633 bool IsExternalOneByte()
const;
2639 V8_DEPRECATED(
"Use IsCacheable().",
virtual bool IsCompressible()
const) {
2707 virtual const uint16_t* data()
const = 0;
2712 virtual size_t length()
const = 0;
2737 virtual const char* data()
const = 0;
2739 virtual size_t length()
const = 0;
2750 Encoding* encoding_out)
const;
2767 enum NewStringType {
2773 static V8_DEPRECATE_SOON(
2774 "Use maybe version",
2775 Local<String> NewFromUtf8(Isolate* isolate,
const char* data,
2792 static V8_DEPRECATE_SOON(
2793 "Use maybe version",
2794 Local<String> NewFromTwoByte(Isolate* isolate,
const uint16_t* data,
2820 Isolate* isolate, ExternalStringResource* resource);
2831 bool MakeExternal(ExternalStringResource* resource);
2841 static V8_DEPRECATE_SOON(
2842 "Use maybe version",
2844 ExternalOneByteStringResource* resource));
2846 Isolate* isolate, ExternalOneByteStringResource* resource);
2857 bool MakeExternal(ExternalOneByteStringResource* resource);
2862 bool CanMakeExternal();
2880 char* operator*() {
return str_; }
2881 const char* operator*()
const {
return str_; }
2882 int length()
const {
return length_; }
2886 void operator=(
const Utf8Value&) =
delete;
2903 uint16_t* operator*() {
return str_; }
2904 const uint16_t* operator*()
const {
return str_; }
2905 int length()
const {
return length_; }
2909 void operator=(
const Value&) =
delete;
2918 Encoding encoding)
const;
2922 String::Encoding* encoding_out)
const;
2962 static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
2976 static void CheckCast(
Value* obj);
3014 static void CheckCast(
Data* that);
3023 double Value()
const;
3052 int32_t
Value()
const;
3080 static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3089 int word_count,
const uint64_t* words);
3097 uint64_t Uint64Value(
bool* lossless =
nullptr)
const;
3104 int64_t Int64Value(
bool* lossless =
nullptr)
const;
3110 int WordCount()
const;
3120 void ToWordsArray(
int* sign_bit,
int* word_count, uint64_t* words)
const;
3151 typedef void (*AccessorNameGetterCallback)(
3156 typedef void (*AccessorSetterCallback)(
3160 typedef void (*AccessorNameSetterCallback)(
3178 ALL_CAN_WRITE = 1 << 1,
3179 PROHIBITS_OVERWRITING = 1 << 2
3188 ONLY_ENUMERABLE = 2,
3189 ONLY_CONFIGURABLE = 4,
3207 kHasSideEffectToReceiver
3241 V8_DEPRECATE_SOON(
"Use maybe version",
3246 V8_DEPRECATE_SOON(
"Use maybe version",
3271 V8_WARN_UNUSED_RESULT
Maybe<bool> DefineOwnProperty(
3313 V8_DEPRECATED(
"Use maybe version",
bool Has(
Local<Value> key));
3332 V8_DEPRECATED(
"Use maybe version",
bool Delete(
Local<Value> key));
3346 AccessorNameGetterCallback getter,
3347 AccessorNameSetterCallback setter =
nullptr,
3350 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3351 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3362 V8_WARN_UNUSED_RESULT
Maybe<bool> SetNativeDataProperty(
3364 AccessorNameGetterCallback getter,
3365 AccessorNameSetterCallback setter =
nullptr,
3367 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3368 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3378 V8_WARN_UNUSED_RESULT
Maybe<bool> SetLazyDataProperty(
3382 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3383 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3403 V8_DEPRECATE_SOON(
"Use maybe version",
Local<Array> GetPropertyNames());
3416 V8_DEPRECATE_SOON(
"Use maybe version",
Local<Array> GetOwnPropertyNames());
3470 int InternalFieldCount();
3475 return object.val_->InternalFieldCount();
3489 V8_INLINE
void* GetAlignedPointerFromInternalField(
int index);
3494 return object.val_->GetAlignedPointerFromInternalField(index);
3502 void SetAlignedPointerInInternalField(
int index,
void* value);
3503 void SetAlignedPointerInInternalFields(
int argc,
int indices[],
3515 V8_DEPRECATE_SOON(
"Use maybe version",
3532 V8_DEPRECATE_SOON(
"Use maybe version",
3533 bool HasRealIndexedProperty(
uint32_t index));
3534 V8_WARN_UNUSED_RESULT
Maybe<bool> HasRealIndexedProperty(
3536 V8_DEPRECATE_SOON(
"Use maybe version",
3538 V8_WARN_UNUSED_RESULT
Maybe<bool> HasRealNamedCallbackProperty(
3554 GetRealNamedPropertyAttributesInPrototypeChain(
Local<Context> context,
3574 bool HasNamedLookupInterceptor();
3577 bool HasIndexedLookupInterceptor();
3586 int GetIdentityHash();
3603 return object.val_->CreationContext();
3616 bool IsConstructor();
3638 Isolate* GetIsolate();
3669 static void CheckCast(
Value* obj);
3671 void* SlowGetAlignedPointerFromInternalField(
int index);
3686 static Local<Array> New(Isolate* isolate,
int length = 0);
3697 static void CheckCast(
Value* obj);
3706 size_t Size()
const;
3729 V8_INLINE
static Map* Cast(
Value* obj);
3733 static void CheckCast(
Value* obj);
3742 size_t Size()
const;
3761 V8_INLINE
static Set* Cast(
Value* obj);
3765 static void CheckCast(
Value* obj);
3769 template<
typename T>
3773 : value_(that.value_) {
3777 template <
typename S>
3778 V8_INLINE V8_DEPRECATED(
"Use Global<> instead",
3779 void Set(
const Persistent<S>& handle));
3780 template <
typename S>
3781 V8_INLINE
void Set(
const Global<S>& handle);
3782 template <
typename S>
3783 V8_INLINE
void Set(
const Local<S> handle);
3785 V8_INLINE
void Set(
bool value);
3786 V8_INLINE
void Set(
double i);
3787 V8_INLINE
void Set(int32_t
i);
3790 V8_INLINE
void SetNull();
3791 V8_INLINE
void SetUndefined();
3792 V8_INLINE
void SetEmptyString();
3794 V8_INLINE Isolate* GetIsolate()
const;
3797 template <
typename S>
3798 V8_INLINE
void Set(S* whatever);
3803 V8_INLINE Local<Value> Get()
const;
3806 template<
class F>
friend class ReturnValue;
3807 template<
class F>
friend class FunctionCallbackInfo;
3808 template<
class F>
friend class PropertyCallbackInfo;
3809 template <
class F,
class G,
class H>
3810 friend class PersistentValueMapBase;
3811 V8_INLINE
void SetInternal(internal::Address value) { *value_ = value; }
3812 V8_INLINE internal::Address GetDefaultValue();
3813 V8_INLINE
explicit ReturnValue(internal::Address* slot);
3814 internal::Address* value_;
3824 template<
typename T>
3825 class FunctionCallbackInfo {
3828 V8_INLINE
int Length()
const;
3832 V8_INLINE Local<Object>
This()
const;
3843 V8_INLINE Local<Object>
Holder()
const;
3845 V8_INLINE Local<Value>
NewTarget()
const;
3849 V8_INLINE Local<Value>
Data()
const;
3855 static const int kArgsLength = 6;
3858 friend class internal::FunctionCallbackArguments;
3859 friend class internal::CustomArguments<FunctionCallbackInfo>;
3860 friend class debug::ConsoleCallArguments;
3861 static const int kHolderIndex = 0;
3862 static const int kIsolateIndex = 1;
3863 static const int kReturnValueDefaultValueIndex = 2;
3864 static const int kReturnValueIndex = 3;
3865 static const int kDataIndex = 4;
3866 static const int kNewTargetIndex = 5;
3868 V8_INLINE FunctionCallbackInfo(internal::Address* implicit_args,
3869 internal::Address* values,
int length);
3870 internal::Address* implicit_args_;
3871 internal::Address* values_;
3880 template<
typename T>
3881 class PropertyCallbackInfo {
3893 V8_INLINE Local<Value>
Data()
const;
3936 V8_INLINE Local<Object>
This()
const;
3947 V8_INLINE Local<Object>
Holder()
const;
3969 static const int kArgsLength = 7;
3972 friend class MacroAssembler;
3973 friend class internal::PropertyCallbackArguments;
3974 friend class internal::CustomArguments<PropertyCallbackInfo>;
3975 static const int kShouldThrowOnErrorIndex = 0;
3976 static const int kHolderIndex = 1;
3977 static const int kIsolateIndex = 2;
3978 static const int kReturnValueDefaultValueIndex = 3;
3979 static const int kReturnValueIndex = 4;
3980 static const int kDataIndex = 5;
3981 static const int kThisIndex = 6;
3983 V8_INLINE PropertyCallbackInfo(internal::Address* args) : args_(args) {}
3984 internal::Address* args_;
3988 typedef void (*FunctionCallback)(
const FunctionCallbackInfo<Value>& info);
3990 enum class ConstructorBehavior { kThrow, kAllow };
4004 ConstructorBehavior behavior = ConstructorBehavior::kAllow,
4005 SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4006 static V8_DEPRECATED(
"Use maybe version",
4008 FunctionCallback callback,
4017 return NewInstance(context, 0,
nullptr);
4027 SideEffectType side_effect_type = SideEffectType::kHasSideEffect)
const;
4029 V8_DEPRECATED(
"Use maybe version",
4063 int GetScriptLineNumber()
const;
4068 int GetScriptColumnNumber()
const;
4073 int ScriptId()
const;
4083 static const int kLineOffsetNotFound;
4087 static void CheckCast(
Value* obj);
4090 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT 4092 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0 4133 static void CheckCast(
Value* obj);
4168 void MarkAsHandled();
4172 static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4176 static void CheckCast(
Value* obj);
4224 bool has_value()
const;
4227 bool has_get()
const;
4229 bool has_set()
const;
4231 void set_enumerable(
bool enumerable);
4232 bool enumerable()
const;
4233 bool has_enumerable()
const;
4235 void set_configurable(
bool configurable);
4236 bool configurable()
const;
4237 bool has_configurable()
const;
4239 bool writable()
const;
4240 bool has_writable()
const;
4243 PrivateData* get_private()
const {
return private_; }
4249 PrivateData* private_;
4274 static void CheckCast(
Value* obj);
4281 typedef std::pair<std::unique_ptr<const uint8_t[]>,
size_t> SerializedModule;
4287 const uint8_t* start;
4290 : start(start), size(size) {}
4306 typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
4307 typedef std::pair<std::unique_ptr<const uint8_t[]>,
size_t> OwnedBuffer;
4310 : shared_module_(std::move(shared_module)) {}
4312 : serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
4314 SharedModule shared_module_;
4315 OwnedBuffer serialized_ = {
nullptr, 0};
4316 OwnedBuffer wire_bytes_ = {
nullptr, 0};
4342 SerializedModule Serialize();
4358 const uint8_t* start,
4361 const TransferrableModule::OwnedBuffer& buff) {
4362 return {buff.first.get(), buff.second};
4365 WasmCompiledModule();
4366 static void CheckCast(
Value* obj);
4387 void OnBytesReceived(
const uint8_t* bytes,
size_t size);
4407 typedef void (*ModuleCompiledCallback)(
4414 void SetModuleCompiledCallback(ModuleCompiledCallback callback,
4424 bool SetCompiledModuleBytes(
const uint8_t* bytes,
size_t size);
4431 static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
4435 std::unique_ptr<WasmStreamingImpl> impl_;
4446 void OnBytesReceived(
const uint8_t*,
size_t size);
4467 Isolate* isolate_ =
nullptr;
4481 std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4484 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 4486 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 4490 enum class ArrayBufferCreationMode {
kInternalized, kExternalized };
4521 virtual void* Allocate(
size_t length) = 0;
4527 virtual void* AllocateUninitialized(
size_t length) = 0;
4533 virtual void Free(
void* data,
size_t length) = 0;
4548 static Allocator* NewDefaultAllocator();
4562 using DeleterCallback = void (*)(
void* buffer,
size_t length,
void* info);
4567 allocation_base_(
nullptr),
4568 allocation_length_(0),
4569 allocation_mode_(Allocator::AllocationMode::kNormal),
4571 deleter_data_(
nullptr) {}
4573 void* AllocationBase()
const {
return allocation_base_; }
4574 size_t AllocationLength()
const {
return allocation_length_; }
4576 return allocation_mode_;
4579 void*
Data()
const {
return data_; }
4580 size_t ByteLength()
const {
return byte_length_; }
4581 DeleterCallback Deleter()
const {
return deleter_; }
4582 void* DeleterData()
const {
return deleter_data_; }
4585 Contents(
void* data,
size_t byte_length,
void* allocation_base,
4586 size_t allocation_length,
4588 void* deleter_data);
4591 size_t byte_length_;
4592 void* allocation_base_;
4593 size_t allocation_length_;
4595 DeleterCallback deleter_;
4596 void* deleter_data_;
4605 size_t ByteLength()
const;
4625 Isolate* isolate,
void* data,
size_t byte_length,
4626 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
4632 bool IsExternal()
const;
4637 bool IsNeuterable()
const;
4671 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4672 static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4676 static void CheckCast(
Value* obj);
4680 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 4682 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2 4699 size_t ByteOffset();
4703 size_t ByteLength();
4714 size_t CopyContents(
void* dest,
size_t byte_length);
4720 bool HasBuffer()
const;
4724 static const int kInternalFieldCount =
4725 V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4726 static const int kEmbedderFieldCount =
4727 V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4731 static void CheckCast(
Value* obj);
4744 static constexpr
size_t kMaxLength = internal::kSmiMaxValue;
4756 static void CheckCast(
Value* obj);
4766 size_t byte_offset,
size_t length);
4768 size_t byte_offset,
size_t length);
4773 static void CheckCast(
Value* obj);
4783 size_t byte_offset,
size_t length);
4791 static void CheckCast(
Value* obj);
4800 size_t byte_offset,
size_t length);
4802 size_t byte_offset,
size_t length);
4807 static void CheckCast(
Value* obj);
4817 size_t byte_offset,
size_t length);
4819 size_t byte_offset,
size_t length);
4824 static void CheckCast(
Value* obj);
4834 size_t byte_offset,
size_t length);
4836 size_t byte_offset,
size_t length);
4841 static void CheckCast(
Value* obj);
4851 size_t byte_offset,
size_t length);
4853 size_t byte_offset,
size_t length);
4858 static void CheckCast(
Value* obj);
4868 size_t byte_offset,
size_t length);
4870 size_t byte_offset,
size_t length);
4875 static void CheckCast(
Value* obj);
4885 size_t byte_offset,
size_t length);
4887 size_t byte_offset,
size_t length);
4892 static void CheckCast(
Value* obj);
4902 size_t byte_offset,
size_t length);
4904 size_t byte_offset,
size_t length);
4909 static void CheckCast(
Value* obj);
4918 size_t byte_offset,
size_t length);
4920 size_t byte_offset,
size_t length);
4925 static void CheckCast(
Value* obj);
4934 size_t byte_offset,
size_t length);
4936 size_t byte_offset,
size_t length);
4941 static void CheckCast(
Value* obj);
4950 size_t byte_offset,
size_t length);
4952 size_t byte_offset,
size_t length);
4957 static void CheckCast(
Value* obj);
4981 using DeleterCallback = void (*)(
void* buffer,
size_t length,
void* info);
4986 allocation_base_(
nullptr),
4987 allocation_length_(0),
4988 allocation_mode_(Allocator::AllocationMode::kNormal),
4990 deleter_data_(
nullptr) {}
4992 void* AllocationBase()
const {
return allocation_base_; }
4993 size_t AllocationLength()
const {
return allocation_length_; }
4995 return allocation_mode_;
4998 void*
Data()
const {
return data_; }
4999 size_t ByteLength()
const {
return byte_length_; }
5000 DeleterCallback Deleter()
const {
return deleter_; }
5001 void* DeleterData()
const {
return deleter_data_; }
5004 Contents(
void* data,
size_t byte_length,
void* allocation_base,
5005 size_t allocation_length,
5007 void* deleter_data);
5010 size_t byte_length_;
5011 void* allocation_base_;
5012 size_t allocation_length_;
5014 DeleterCallback deleter_;
5015 void* deleter_data_;
5023 size_t ByteLength()
const;
5040 Isolate* isolate,
void* data,
size_t byte_length,
5041 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5047 bool IsExternal()
const;
5079 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5083 static void CheckCast(
Value* obj);
5092 static V8_DEPRECATED(
"Use maybe version.",
5101 double ValueOf()
const;
5103 V8_INLINE
static Date* Cast(
Value* obj);
5117 static void DateTimeConfigurationChangeNotification(Isolate* isolate);
5120 static void CheckCast(
Value* obj);
5129 static Local<Value> New(Isolate* isolate,
double value);
5131 double ValueOf()
const;
5136 static void CheckCast(
Value* obj);
5151 static void CheckCast(
Value* obj);
5161 bool ValueOf()
const;
5166 static void CheckCast(
Value* obj);
5182 static void CheckCast(
Value* obj);
5198 static void CheckCast(
Value* obj);
5214 kIgnoreCase = 1 << 1,
5215 kMultiline = 1 << 2,
5244 Flags GetFlags()
const;
5249 static void CheckCast(
Value* obj);
5261 void*
Value()
const;
5266 #define V8_INTRINSICS_LIST(F) \ 5267 F(ArrayProto_entries, array_entries_iterator) \ 5268 F(ArrayProto_forEach, array_for_each_iterator) \ 5269 F(ArrayProto_keys, array_keys_iterator) \ 5270 F(ArrayProto_values, array_values_iterator) \ 5271 F(ErrorPrototype, initial_error_prototype) \ 5272 F(IteratorPrototype, initial_iterator_prototype) 5275 #define V8_DECL_INTRINSIC(name, iname) k##name, 5276 V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
5277 #undef V8_DECL_INTRINSIC 5298 V8_INLINE
void Set(Isolate* isolate,
const char* name,
Local<Data> value);
5300 void SetAccessorProperty(
5334 void SetNativeDataProperty(
5336 AccessorSetterCallback setter =
nullptr,
5341 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5342 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5343 void SetNativeDataProperty(
5344 Local<Name> name, AccessorNameGetterCallback getter,
5345 AccessorNameSetterCallback setter =
nullptr,
5350 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5351 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5357 void SetLazyDataProperty(
5358 Local<Name> name, AccessorNameGetterCallback getter,
5360 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5361 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5367 void SetIntrinsicDataProperty(
Local<Name> name, Intrinsic intrinsic,
5722 Isolate* isolate, FunctionCallback callback =
nullptr,
5725 ConstructorBehavior behavior = ConstructorBehavior::kAllow,
5726 SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5736 Isolate* isolate, FunctionCallback callback,
5739 SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5760 void SetCallHandler(
5762 SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5765 void SetLength(
int length);
5803 void SetAcceptAnyReceiver(
bool value);
5817 void SetHiddenPrototype(
bool value);
5823 void ReadOnlyPrototype();
5829 void RemovePrototype();
5842 static void CheckCast(
Data* that);
5843 friend class Context;
5895 enumerator(enumerator),
5897 descriptor(descriptor),
5914 enumerator(enumerator),
5916 descriptor(nullptr),
5933 enumerator(enumerator),
5935 descriptor(descriptor),
5965 enumerator(enumerator),
5967 descriptor(descriptor),
5984 enumerator(enumerator),
5986 descriptor(nullptr),
6003 enumerator(enumerator),
6005 descriptor(descriptor),
6039 V8_DEPRECATED(
"Use maybe version",
Local<Object> NewInstance());
6073 AccessorSetterCallback setter =
nullptr,
6077 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6078 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6080 Local<Name> name, AccessorNameGetterCallback getter,
6081 AccessorNameSetterCallback setter =
nullptr,
6085 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6086 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6126 deleter, enumerator, data));
6147 void SetCallAsFunctionHandler(FunctionCallback callback,
6158 void MarkAsUndetectable();
6177 void SetAccessCheckCallbackAndHandler(
6187 int InternalFieldCount();
6193 void SetInternalFieldCount(
int value);
6198 bool IsImmutableProto();
6204 void SetImmutableProto();
6212 static void CheckCast(
Data* that);
6235 static void CheckCast(
Data* that);
6254 static void CheckCast(
Data* that);
6259 V8_DEPRECATED(
"Implementation detail",
class)
6260 V8_EXPORT ExternalOneByteStringResourceImpl
6261 : public
String::ExternalOneByteStringResource {
6263 ExternalOneByteStringResourceImpl() : data_(nullptr), length_(0) {}
6264 ExternalOneByteStringResourceImpl(
const char* data,
size_t length)
6265 : data_(data), length_(length) {}
6266 const char* data()
const override {
return data_; }
6267 size_t length()
const override {
return length_; }
6277 class V8_EXPORT Extension {
6281 Extension(
const char* name,
const char* source =
nullptr,
int dep_count = 0,
6282 const char** deps =
nullptr,
int source_length = -1);
6283 virtual ~Extension() {
delete source_; }
6284 virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
6285 Isolate* isolate, Local<String> name) {
6286 return Local<FunctionTemplate>();
6289 const char* name()
const {
return name_; }
6290 size_t source_length()
const {
return source_length_; }
6291 const String::ExternalOneByteStringResource* source()
const {
6294 int dependency_count() {
return dep_count_; }
6295 const char** dependencies() {
return deps_; }
6296 void set_auto_enable(
bool value) { auto_enable_ = value; }
6297 bool auto_enable() {
return auto_enable_; }
6300 Extension(
const Extension&) =
delete;
6301 void operator=(
const Extension&) =
delete;
6305 size_t source_length_;
6306 String::ExternalOneByteStringResource* source_;
6313 void V8_EXPORT RegisterExtension(Extension* extension);
6318 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6319 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6320 V8_INLINE Local<Boolean> True(Isolate* isolate);
6321 V8_INLINE Local<Boolean> False(Isolate* isolate);
6337 class V8_EXPORT ResourceConstraints {
6339 ResourceConstraints();
6350 void ConfigureDefaults(uint64_t physical_memory,
6351 uint64_t virtual_memory_limit);
6354 V8_DEPRECATED(
"Use max_semi_space_size_in_kb()",
6355 size_t max_semi_space_size()) {
6356 return max_semi_space_size_in_kb_ / 1024;
6360 V8_DEPRECATED(
"Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6361 void set_max_semi_space_size(
size_t limit_in_mb)) {
6362 max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6366 size_t max_semi_space_size_in_kb()
const {
6367 return max_semi_space_size_in_kb_;
6371 void set_max_semi_space_size_in_kb(
size_t limit_in_kb) {
6372 max_semi_space_size_in_kb_ = limit_in_kb;
6375 size_t max_old_space_size()
const {
return max_old_space_size_; }
6376 void set_max_old_space_size(
size_t limit_in_mb) {
6377 max_old_space_size_ = limit_in_mb;
6379 V8_DEPRECATED(
"max_executable_size_ is subsumed by max_old_space_size_",
6380 size_t max_executable_size()
const) {
6381 return max_executable_size_;
6383 V8_DEPRECATED(
"max_executable_size_ is subsumed by max_old_space_size_",
6384 void set_max_executable_size(
size_t limit_in_mb)) {
6385 max_executable_size_ = limit_in_mb;
6387 uint32_t* stack_limit()
const {
return stack_limit_; }
6389 void set_stack_limit(
uint32_t* value) { stack_limit_ = value; }
6390 size_t code_range_size()
const {
return code_range_size_; }
6391 void set_code_range_size(
size_t limit_in_mb) {
6392 code_range_size_ = limit_in_mb;
6394 size_t max_zone_pool_size()
const {
return max_zone_pool_size_; }
6395 void set_max_zone_pool_size(
size_t bytes) { max_zone_pool_size_ = bytes; }
6399 size_t max_semi_space_size_in_kb_;
6402 size_t max_old_space_size_;
6403 size_t max_executable_size_;
6405 size_t code_range_size_;
6406 size_t max_zone_pool_size_;
6413 typedef void (*FatalErrorCallback)(
const char* location,
const char* message);
6415 typedef void (*OOMErrorCallback)(
const char* location,
bool is_heap_oom);
6417 typedef void (*DcheckErrorCallback)(
const char* file,
int line,
6418 const char* message);
6420 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6424 typedef void (*LogEventCallback)(
const char* name,
int event);
6430 class V8_EXPORT Exception {
6432 static Local<Value> RangeError(Local<String> message);
6433 static Local<Value> ReferenceError(Local<String> message);
6434 static Local<Value> SyntaxError(Local<String> message);
6435 static Local<Value> TypeError(Local<String> message);
6436 static Local<Value> Error(Local<String> message);
6443 static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6449 static Local<StackTrace> GetStackTrace(Local<Value> exception);
6455 typedef int* (*CounterLookupCallback)(
const char* name);
6457 typedef void* (*CreateHistogramCallback)(
const char* name,
6462 typedef void (*AddHistogramSampleCallback)(
void* histogram,
int sample);
6465 typedef void (*BeforeCallEnteredCallback)(Isolate*);
6466 typedef void (*CallCompletedCallback)(Isolate*);
6488 typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)(
6489 Local<Context> context, Local<ScriptOrModule> referrer,
6490 Local<String> specifier);
6502 typedef void (*HostInitializeImportMetaObjectCallback)(Local<Context> context,
6503 Local<Module> module,
6504 Local<Object> meta);
6513 typedef MaybeLocal<Value> (*PrepareStackTraceCallback)(Local<Context> context,
6515 Local<Array> sites);
6533 enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
6535 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6536 Local<Value> parent);
6539 enum PromiseRejectEvent {
6540 kPromiseRejectWithNoHandler = 0,
6541 kPromiseHandlerAddedAfterReject = 1,
6542 kPromiseRejectAfterResolved = 2,
6543 kPromiseResolveAfterResolved = 3,
6546 class PromiseRejectMessage {
6548 PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
6549 Local<Value> value, Local<StackTrace> stack_trace)
6550 : promise_(promise),
6553 stack_trace_(stack_trace) {}
6555 V8_INLINE Local<Promise> GetPromise()
const {
return promise_; }
6556 V8_INLINE PromiseRejectEvent GetEvent()
const {
return event_; }
6557 V8_INLINE Local<Value> GetValue()
const {
return value_; }
6560 Local<Promise> promise_;
6561 PromiseRejectEvent event_;
6562 Local<Value> value_;
6563 Local<StackTrace> stack_trace_;
6566 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
6569 typedef void (*MicrotasksCompletedCallback)(Isolate*);
6570 typedef void (*MicrotaskCallback)(
void* data);
6580 enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
6592 class V8_EXPORT MicrotasksScope {
6594 enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6596 MicrotasksScope(Isolate* isolate,
Type type);
6602 static void PerformCheckpoint(Isolate* isolate);
6607 static int GetCurrentDepth(Isolate* isolate);
6612 static bool IsRunningMicrotasks(Isolate* isolate);
6615 MicrotasksScope(
const MicrotasksScope&) =
delete;
6616 MicrotasksScope& operator=(
const MicrotasksScope&) =
delete;
6619 internal::Isolate*
const isolate_;
6625 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
6635 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context,
6636 Local<String> source);
6639 typedef bool (*ExtensionCallback)(
const FunctionCallbackInfo<Value>&);
6641 typedef bool (*AllowWasmCodeGenerationCallback)(Local<Context> context,
6642 Local<String> source);
6646 typedef void (*ApiImplementationCallback)(
const FunctionCallbackInfo<Value>&);
6649 typedef void (*WasmStreamingCallback)(
const FunctionCallbackInfo<Value>&);
6652 typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context);
6664 kGCTypeScavenge = 1 << 0,
6665 kGCTypeMarkSweepCompact = 1 << 1,
6666 kGCTypeIncrementalMarking = 1 << 2,
6667 kGCTypeProcessWeakCallbacks = 1 << 3,
6668 kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
6669 kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
6686 enum GCCallbackFlags {
6687 kNoGCCallbackFlags = 0,
6688 kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
6689 kGCCallbackFlagForced = 1 << 2,
6690 kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
6691 kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
6692 kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
6693 kGCCallbackScheduleIdleGarbageCollection = 1 << 6,
6696 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6698 typedef void (*InterruptCallback)(Isolate* isolate,
void* data);
6707 typedef size_t (*NearHeapLimitCallback)(
void* data,
size_t current_heap_limit,
6708 size_t initial_heap_limit);
6716 class V8_EXPORT HeapStatistics {
6719 size_t total_heap_size() {
return total_heap_size_; }
6720 size_t total_heap_size_executable() {
return total_heap_size_executable_; }
6721 size_t total_physical_size() {
return total_physical_size_; }
6722 size_t total_available_size() {
return total_available_size_; }
6723 size_t used_heap_size() {
return used_heap_size_; }
6724 size_t heap_size_limit() {
return heap_size_limit_; }
6725 size_t malloced_memory() {
return malloced_memory_; }
6726 size_t external_memory() {
return external_memory_; }
6727 size_t peak_malloced_memory() {
return peak_malloced_memory_; }
6728 size_t number_of_native_contexts() {
return number_of_native_contexts_; }
6729 size_t number_of_detached_contexts() {
return number_of_detached_contexts_; }
6735 size_t does_zap_garbage() {
return does_zap_garbage_; }
6738 size_t total_heap_size_;
6739 size_t total_heap_size_executable_;
6740 size_t total_physical_size_;
6741 size_t total_available_size_;
6742 size_t used_heap_size_;
6743 size_t heap_size_limit_;
6744 size_t malloced_memory_;
6745 size_t external_memory_;
6746 size_t peak_malloced_memory_;
6747 bool does_zap_garbage_;
6748 size_t number_of_native_contexts_;
6749 size_t number_of_detached_contexts_;
6752 friend class Isolate;
6756 class V8_EXPORT HeapSpaceStatistics {
6758 HeapSpaceStatistics();
6759 const char* space_name() {
return space_name_; }
6760 size_t space_size() {
return space_size_; }
6761 size_t space_used_size() {
return space_used_size_; }
6762 size_t space_available_size() {
return space_available_size_; }
6763 size_t physical_space_size() {
return physical_space_size_; }
6766 const char* space_name_;
6768 size_t space_used_size_;
6769 size_t space_available_size_;
6770 size_t physical_space_size_;
6772 friend class Isolate;
6776 class V8_EXPORT HeapObjectStatistics {
6778 HeapObjectStatistics();
6779 const char* object_type() {
return object_type_; }
6780 const char* object_sub_type() {
return object_sub_type_; }
6781 size_t object_count() {
return object_count_; }
6782 size_t object_size() {
return object_size_; }
6785 const char* object_type_;
6786 const char* object_sub_type_;
6787 size_t object_count_;
6788 size_t object_size_;
6790 friend class Isolate;
6793 class V8_EXPORT HeapCodeStatistics {
6795 HeapCodeStatistics();
6796 size_t code_and_metadata_size() {
return code_and_metadata_size_; }
6797 size_t bytecode_and_metadata_size() {
return bytecode_and_metadata_size_; }
6798 size_t external_script_source_size() {
return external_script_source_size_; }
6801 size_t code_and_metadata_size_;
6802 size_t bytecode_and_metadata_size_;
6803 size_t external_script_source_size_;
6805 friend class Isolate;
6808 class RetainedObjectInfo;
6822 typedef void (*FunctionEntryHook)(
uintptr_t function,
6830 struct JitCodeEvent {
6835 CODE_ADD_LINE_POS_INFO,
6836 CODE_START_LINE_INFO_RECORDING,
6837 CODE_END_LINE_INFO_RECORDING
6844 enum PositionType { POSITION, STATEMENT_POSITION };
6852 enum CodeType { BYTE_CODE, JIT_CODE };
6862 Local<UnboundScript> script;
6883 PositionType position_type;
6894 void* new_code_start;
6909 PERFORMANCE_RESPONSE,
6913 PERFORMANCE_ANIMATION,
6925 enum JitCodeEventOptions {
6926 kJitCodeEventDefault = 0,
6928 kJitCodeEventEnumExisting = 1
6937 typedef void (*JitCodeEventHandler)(
const JitCodeEvent* event);
6943 class V8_EXPORT ExternalResourceVisitor {
6945 virtual ~ExternalResourceVisitor() =
default;
6946 virtual void VisitExternalString(Local<String>
string) {}
6953 class V8_EXPORT PersistentHandleVisitor {
6955 virtual ~PersistentHandleVisitor() =
default;
6956 virtual void VisitPersistentHandle(Persistent<Value>* value,
6957 uint16_t class_id) {}
6968 enum class MemoryPressureLevel {
kNone, kModerate, kCritical };
6977 class V8_EXPORT EmbedderHeapTracer {
6980 enum EmbedderStackState {
6986 virtual ~EmbedderHeapTracer() =
default;
6994 virtual void RegisterV8References(
6995 const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
7000 virtual void TracePrologue() = 0;
7012 virtual bool AdvanceTracing(
double deadline_in_ms) = 0;
7018 virtual bool IsTracingDone() = 0;
7025 virtual void TraceEpilogue() = 0;
7031 virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
7039 V8_DEPRECATED(
"Obsolete as V8 will not abort tracing anymore.",
7040 virtual void AbortTracing()) {}
7051 void FinalizeTracing();
7058 void GarbageCollectionForTesting(EmbedderStackState stack_state);
7064 v8::Isolate* isolate()
const {
return isolate_; }
7067 v8::Isolate* isolate_ =
nullptr;
7069 friend class internal::LocalEmbedderHeapTracer;
7080 struct SerializeInternalFieldsCallback {
7081 typedef StartupData (*CallbackFunction)(Local<Object> holder,
int index,
7083 SerializeInternalFieldsCallback(CallbackFunction
function =
nullptr,
7084 void* data_arg =
nullptr)
7085 : callback(function), data(data_arg) {}
7086 CallbackFunction callback;
7091 typedef SerializeInternalFieldsCallback SerializeEmbedderFieldsCallback;
7097 struct DeserializeInternalFieldsCallback {
7098 typedef void (*CallbackFunction)(Local<Object> holder,
int index,
7099 StartupData payload,
void* data);
7100 DeserializeInternalFieldsCallback(CallbackFunction
function =
nullptr,
7101 void* data_arg =
nullptr)
7102 : callback(function), data(data_arg) {}
7103 void (*callback)(Local<Object> holder,
int index, StartupData payload,
7107 typedef DeserializeInternalFieldsCallback DeserializeEmbedderFieldsCallback;
7117 class V8_EXPORT Isolate {
7124 : entry_hook(
nullptr),
7125 code_event_handler(
nullptr),
7126 snapshot_blob(
nullptr),
7127 counter_lookup_callback(
nullptr),
7128 create_histogram_callback(
nullptr),
7129 add_histogram_sample_callback(
nullptr),
7130 array_buffer_allocator(
nullptr),
7131 external_references(
nullptr),
7132 allow_atomics_wait(
true),
7133 only_terminate_in_safe_scope(
false) {}
7176 AddHistogramSampleCallback add_histogram_sample_callback;
7211 explicit Scope(Isolate* isolate) : isolate_(isolate) {
7215 ~
Scope() { isolate_->Exit(); }
7222 Isolate*
const isolate_;
7231 enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
7243 OnFailure on_failure_;
7263 void* internal_throws_;
7264 void* internal_assert_;
7265 void* internal_dump_;
7309 enum GarbageCollectionType {
7310 kFullGarbageCollection,
7311 kMinorGarbageCollection
7319 enum UseCounterFeature {
7323 kMarkDequeOverflow = 3,
7324 kStoreBufferOverflow = 4,
7325 kSlotsBufferOverflow = 5,
7331 kRegExpPrototypeStickyGetter = 11,
7332 kRegExpPrototypeToString = 12,
7333 kRegExpPrototypeUnicodeGetter = 13,
7338 kPromiseAccept = 18,
7340 kHtmlCommentInExternalScript = 20,
7342 kSloppyModeBlockScopedFunctionRedefinition = 22,
7343 kForInInitializer = 23,
7344 kArrayProtectorDirtied = 24,
7345 kArraySpeciesModified = 25,
7346 kArrayPrototypeConstructorModified = 26,
7347 kArrayInstanceProtoModified = 27,
7348 kArrayInstanceConstructorModified = 28,
7349 kLegacyFunctionDeclaration = 29,
7350 kRegExpPrototypeSourceGetter = 30,
7351 kRegExpPrototypeOldFlagGetter = 31,
7352 kDecimalWithLeadingZeroInStrictMode = 32,
7353 kLegacyDateParser = 33,
7354 kDefineGetterOrSetterWouldThrow = 34,
7355 kFunctionConstructorReturnedUndefined = 35,
7356 kAssigmentExpressionLHSIsCallInSloppy = 36,
7357 kAssigmentExpressionLHSIsCallInStrict = 37,
7358 kPromiseConstructorReturnedUndefined = 38,
7359 kConstructorNonUndefinedPrimitiveReturn = 39,
7360 kLabeledExpressionStatement = 40,
7361 kLineOrParagraphSeparatorAsLineTerminator = 41,
7362 kIndexAccessor = 42,
7363 kErrorCaptureStackTrace = 43,
7364 kErrorPrepareStackTrace = 44,
7365 kErrorStackTraceLimit = 45,
7366 kWebAssemblyInstantiation = 46,
7367 kDeoptimizerDisableSpeculation = 47,
7368 kArrayPrototypeSortJSArrayModifiedPrototype = 48,
7369 kFunctionTokenOffsetTooLongForToString = 49,
7370 kWasmSharedMemory = 50,
7371 kWasmThreadOpcodes = 51,
7372 kAtomicsNotify = 52,
7376 kDateTimeFormat = 56,
7378 kRelativeTimeFormat = 58,
7382 kStringLocaleCompare = 62,
7383 kStringToLocaleUpperCase = 63,
7384 kStringToLocaleLowerCase = 64,
7385 kNumberToLocaleString = 65,
7386 kDateToLocaleString = 66,
7387 kDateToLocaleDateString = 67,
7388 kDateToLocaleTimeString = 68,
7389 kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
7390 kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
7391 kOptimizedFunctionWithOneShotBytecode = 71,
7396 kUseCounterFeatureCount
7399 enum MessageErrorLevel {
7400 kMessageLog = (1 << 0),
7401 kMessageDebug = (1 << 1),
7402 kMessageInfo = (1 << 2),
7403 kMessageError = (1 << 3),
7404 kMessageWarning = (1 << 4),
7405 kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7409 typedef void (*UseCounterCallback)(Isolate* isolate,
7410 UseCounterFeature feature);
7426 static Isolate* Allocate();
7431 static void Initialize(Isolate* isolate,
const CreateParams& params);
7442 static Isolate* New(
const CreateParams& params);
7450 static Isolate* GetCurrent();
7461 typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7462 void SetAbortOnUncaughtExceptionCallback(
7463 AbortOnUncaughtExceptionCallback callback);
7469 void SetHostImportModuleDynamicallyCallback(
7470 HostImportModuleDynamicallyCallback callback);
7476 void SetHostInitializeImportMetaObjectCallback(
7477 HostInitializeImportMetaObjectCallback callback);
7483 void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
7491 void MemoryPressureNotification(MemoryPressureLevel level);
7524 void DumpAndResetStats();
7533 void DiscardThreadSpecificMetadata();
7539 V8_INLINE
void SetData(
uint32_t slot,
void* data);
7545 V8_INLINE
void* GetData(
uint32_t slot);
7551 V8_INLINE
static uint32_t GetNumberOfDataSlots();
7559 V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(
size_t index);
7564 void GetHeapStatistics(HeapStatistics* heap_statistics);
7569 size_t NumberOfHeapSpaces();
7580 bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7586 size_t NumberOfTrackedHeapObjectTypes();
7597 bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7607 bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7621 void GetStackSample(
const RegisterState& state,
void** frames,
7622 size_t frames_limit, SampleInfo* sample_info);
7638 AdjustAmountOfExternalAllocatedMemory(
int64_t change_in_bytes);
7644 size_t NumberOfPhantomHandleResetsSinceLastCall();
7650 HeapProfiler* GetHeapProfiler();
7655 void SetIdle(
bool is_idle);
7664 Local<Context> GetCurrentContext();
7667 Local<Context> GetEnteredContext();
7675 Local<Context> GetEnteredOrMicrotaskContext();
7681 Local<Context> GetIncumbentContext();
7689 Local<Value> ThrowException(Local<Value> exception);
7691 typedef void (*GCCallback)(Isolate* isolate, GCType type,
7692 GCCallbackFlags flags);
7693 typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7694 GCCallbackFlags flags,
void* data);
7705 void AddGCPrologueCallback(GCCallbackWithData callback,
void* data =
nullptr,
7706 GCType gc_type_filter = kGCTypeAll);
7707 void AddGCPrologueCallback(GCCallback callback,
7708 GCType gc_type_filter = kGCTypeAll);
7714 void RemoveGCPrologueCallback(GCCallbackWithData,
void* data =
nullptr);
7715 void RemoveGCPrologueCallback(GCCallback callback);
7720 void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7725 EmbedderHeapTracer* GetEmbedderHeapTracer();
7730 enum class AtomicsWaitEvent {
7738 kTerminatedExecution,
7791 typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event,
7793 size_t offset_in_bytes, int32_t value,
7794 double timeout_in_ms,
7804 void SetAtomicsWaitCallback(AtomicsWaitCallback callback,
void* data);
7815 void AddGCEpilogueCallback(GCCallbackWithData callback,
void* data =
nullptr,
7816 GCType gc_type_filter = kGCTypeAll);
7817 void AddGCEpilogueCallback(GCCallback callback,
7818 GCType gc_type_filter = kGCTypeAll);
7824 void RemoveGCEpilogueCallback(GCCallbackWithData callback,
7825 void* data =
nullptr);
7826 void RemoveGCEpilogueCallback(GCCallback callback);
7828 typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7836 void SetGetExternallyAllocatedMemoryInBytesCallback(
7837 GetExternallyAllocatedMemoryInBytesCallback callback);
7846 void TerminateExecution();
7856 bool IsExecutionTerminating();
7872 void CancelTerminateExecution();
7882 void RequestInterrupt(InterruptCallback callback,
void* data);
7894 void RequestGarbageCollectionForTesting(GarbageCollectionType
type);
7899 void SetEventLogger(LogEventCallback that);
7907 void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7912 void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7921 void AddCallCompletedCallback(CallCompletedCallback callback);
7926 void RemoveCallCompletedCallback(CallCompletedCallback callback);
7932 void SetPromiseHook(PromiseHook hook);
7938 void SetPromiseRejectCallback(PromiseRejectCallback callback);
7944 void RunMicrotasks();
7954 void EnqueueMicrotask(MicrotaskCallback callback,
void* data =
nullptr);
7959 void SetMicrotasksPolicy(MicrotasksPolicy policy);
7964 MicrotasksPolicy GetMicrotasksPolicy()
const;
7978 void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7983 void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7988 void SetUseCounterCallback(UseCounterCallback callback);
7994 void SetCounterFunction(CounterLookupCallback);
8002 void SetCreateHistogramFunction(CreateHistogramCallback);
8003 void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
8019 bool IdleNotificationDeadline(
double deadline_in_seconds);
8025 void LowMemoryNotification();
8036 int ContextDisposedNotification(
bool dependant_context =
true);
8042 void IsolateInForegroundNotification();
8048 void IsolateInBackgroundNotification();
8055 void EnableMemorySavingsMode();
8060 void DisableMemorySavingsMode();
8069 void SetRAILMode(RAILMode rail_mode);
8075 void IncreaseHeapLimitForDebugging();
8080 void RestoreOriginalHeapLimit();
8086 bool IsHeapLimitIncreasedForDebugging();
8110 void SetJitCodeEventHandler(JitCodeEventOptions options,
8111 JitCodeEventHandler event_handler);
8122 void SetStackLimit(
uintptr_t stack_limit);
8139 void GetCodeRange(
void** start,
size_t* length_in_bytes);
8147 void SetFatalErrorHandler(FatalErrorCallback that);
8150 void SetOOMErrorHandler(OOMErrorCallback that);
8157 void AddNearHeapLimitCallback(NearHeapLimitCallback callback,
void* data);
8166 void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
8173 void SetAllowCodeGenerationFromStringsCallback(
8174 AllowCodeGenerationFromStringsCallback callback);
8180 void SetAllowWasmCodeGenerationCallback(
8181 AllowWasmCodeGenerationCallback callback);
8187 void SetWasmModuleCallback(ExtensionCallback callback);
8188 void SetWasmInstanceCallback(ExtensionCallback callback);
8191 "The callback set in SetWasmStreamingCallback is used now",
8192 void SetWasmCompileStreamingCallback(ApiImplementationCallback callback));
8194 void SetWasmStreamingCallback(WasmStreamingCallback callback);
8196 void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback);
8213 bool AddMessageListener(MessageCallback that,
8227 bool AddMessageListenerWithErrorLevel(MessageCallback that,
8234 void RemoveMessageListeners(MessageCallback that);
8237 void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
8243 void SetCaptureStackTraceForUncaughtExceptions(
8244 bool capture,
int frame_limit = 10,
8252 void VisitExternalResources(ExternalResourceVisitor* visitor);
8258 void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
8267 void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
8274 void VisitWeakHandles(PersistentHandleVisitor* visitor);
8287 void SetAllowAtomicsWait(
bool allow);
8290 ~Isolate() =
delete;
8291 Isolate(
const Isolate&) =
delete;
8292 Isolate& operator=(
const Isolate&) =
delete;
8295 void*
operator new(
size_t size) =
delete;
8296 void*
operator new[](
size_t size) =
delete;
8297 void operator delete(
void*,
size_t) =
delete;
8298 void operator delete[](
void*,
size_t) =
delete;
8301 template <
class K,
class V,
class Traits>
8305 void ReportExternalAllocationLimitReached();
8306 void CheckMemoryPressure();
8309 class V8_EXPORT StartupData {
8320 typedef bool (*EntropySource)(
unsigned char* buffer,
size_t length);
8335 typedef uintptr_t (*ReturnAddressLocationResolver)(
8342 class V8_EXPORT V8 {
8359 static void SetNativesDataBlob(StartupData* startup_blob);
8360 static void SetSnapshotDataBlob(StartupData* startup_blob);
8363 static void SetDcheckErrorHandler(DcheckErrorCallback that);
8369 static void SetFlagsFromString(
const char* str,
int length);
8374 static void SetFlagsFromCommandLine(
int* argc,
8379 static const char* GetVersion();
8385 static bool Initialize();
8391 static void SetEntropySource(EntropySource source);
8397 static void SetReturnAddressLocationResolver(
8398 ReturnAddressLocationResolver return_address_resolver);
8409 static bool Dispose();
8418 static bool InitializeICU(
const char* icu_data_file =
nullptr);
8432 static bool InitializeICUDefaultLocation(
const char* exec_path,
8433 const char* icu_data_file =
nullptr);
8451 static void InitializeExternalStartupData(
const char* directory_path);
8452 static void InitializeExternalStartupData(
const char* natives_blob,
8453 const char* snapshot_blob);
8458 static void InitializePlatform(Platform* platform);
8464 static void ShutdownPlatform();
8486 V8_DEPRECATE_SOON(
"Use TryHandleWebAssemblyTrapPosix",
8487 static bool TryHandleSignal(
int signal_number,
void* info,
8489 #endif // V8_OS_POSIX 8495 V8_DEPRECATED(
"Use EnableWebAssemblyTrapHandler",
8496 static bool RegisterDefaultSignalHandler());
8504 static bool EnableWebAssemblyTrapHandler(
bool use_v8_signal_handler);
8509 static internal::Address* GlobalizeReference(internal::Isolate* isolate,
8510 internal::Address* handle);
8511 static internal::Address* CopyPersistent(internal::Address* handle);
8512 static void DisposeGlobal(internal::Address* global_handle);
8513 static void MakeWeak(internal::Address* location,
void* data,
8514 WeakCallbackInfo<void>::Callback weak_callback,
8515 WeakCallbackType type);
8516 static void MakeWeak(internal::Address** location_addr);
8517 static void* ClearWeak(internal::Address* location);
8518 static void AnnotateStrongRetainer(internal::Address* location,
8520 static Value* Eternalize(Isolate* isolate,
Value* handle);
8522 static void RegisterExternallyReferencedObject(internal::Address* location,
8523 internal::Isolate* isolate);
8525 template <
class K,
class V,
class T>
8526 friend class PersistentValueMapBase;
8528 static void FromJustIsNothing();
8529 static void ToLocalEmpty();
8530 static void InternalFieldOutOfBounds(
int index);
8531 template <
class T>
friend class Local;
8533 friend class MaybeLocal;
8537 friend class WeakCallbackInfo;
8538 template <
class T>
friend class Eternal;
8539 template <
class T>
friend class PersistentBase;
8540 template <
class T,
class M>
friend class Persistent;
8541 friend class Context;
8547 class V8_EXPORT SnapshotCreator {
8549 enum class FunctionCodeHandling { kClear, kKeep };
8559 SnapshotCreator(Isolate* isolate,
8560 const intptr_t* external_references =
nullptr,
8561 StartupData* existing_blob =
nullptr);
8571 SnapshotCreator(
const intptr_t* external_references =
nullptr,
8572 StartupData* existing_blob =
nullptr);
8579 Isolate* GetIsolate();
8588 void SetDefaultContext(Local<Context> context,
8589 SerializeInternalFieldsCallback callback =
8590 SerializeInternalFieldsCallback());
8600 size_t AddContext(Local<Context> context,
8601 SerializeInternalFieldsCallback callback =
8602 SerializeInternalFieldsCallback());
8608 size_t AddTemplate(Local<Template> template_obj);
8617 V8_INLINE
size_t AddData(Local<Context> context, Local<T>
object);
8626 V8_INLINE
size_t AddData(Local<T>
object);
8636 StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8639 SnapshotCreator(
const SnapshotCreator&) =
delete;
8640 void operator=(
const SnapshotCreator&) =
delete;
8643 size_t AddData(Local<Context> context, internal::Address
object);
8644 size_t AddData(internal::Address
object);
8662 V8_INLINE
bool IsNothing()
const {
return !has_value_; }
8663 V8_INLINE
bool IsJust()
const {
return has_value_; }
8674 V8_WARN_UNUSED_RESULT V8_INLINE
bool To(
T* out)
const {
8675 if (V8_LIKELY(IsJust())) *out = value_;
8684 if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8693 return has_value_ ? value_ : default_value;
8696 V8_INLINE
bool operator==(
const Maybe& other)
const {
8697 return (IsJust() == other.IsJust()) &&
8698 (!IsJust() ||
FromJust() == other.FromJust());
8701 V8_INLINE
bool operator!=(
const Maybe& other)
const {
8702 return !operator==(other);
8706 Maybe() : has_value_(false) {}
8707 explicit Maybe(
const T& t) : has_value_(true), value_(t) {}
8713 friend Maybe<U> Nothing();
8715 friend Maybe<U> Just(
const U& u);
8719 inline Maybe<T> Nothing() {
8724 inline Maybe<T> Just(
const T& t) {
8732 V8_INLINE
bool IsNothing()
const {
return !is_valid_; }
8733 V8_INLINE
bool IsJust()
const {
return is_valid_; }
8735 V8_INLINE
bool operator==(
const Maybe& other)
const {
8736 return IsJust() == other.IsJust();
8739 V8_INLINE
bool operator!=(
const Maybe& other)
const {
8740 return !operator==(other);
8746 Maybe() : is_valid_(false) {}
8747 explicit Maybe(JustTag) : is_valid_(true) {}
8752 friend Maybe<U> Nothing();
8753 friend Maybe<void> JustVoid();
8756 inline Maybe<void> JustVoid() {
return Maybe<void>(Maybe<void>::JustTag()); }
8761 class V8_EXPORT TryCatch {
8768 explicit TryCatch(Isolate* isolate);
8778 bool HasCaught()
const;
8788 bool CanContinue()
const;
8802 bool HasTerminated()
const;
8811 Local<Value> ReThrow();
8819 Local<Value> Exception()
const;
8825 V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
8826 Local<Context> context)
const;
8835 Local<v8::Message> Message()
const;
8857 void SetVerbose(
bool value);
8862 bool IsVerbose()
const;
8869 void SetCaptureMessage(
bool value);
8882 static void* JSStackComparableAddress(TryCatch* handler) {
8883 if (handler ==
nullptr)
return nullptr;
8884 return handler->js_stack_comparable_address_;
8887 TryCatch(
const TryCatch&) =
delete;
8888 void operator=(
const TryCatch&) =
delete;
8893 void*
operator new(
size_t size);
8894 void*
operator new[](
size_t size);
8895 void operator delete(
void*,
size_t);
8896 void operator delete[](
void*,
size_t);
8898 void ResetInternal();
8900 internal::Isolate* isolate_;
8904 void* js_stack_comparable_address_;
8905 bool is_verbose_ : 1;
8906 bool can_continue_ : 1;
8907 bool capture_message_ : 1;
8909 bool has_terminated_ : 1;
8911 friend class internal::Isolate;
8921 class V8_EXPORT ExtensionConfiguration {
8923 ExtensionConfiguration() : name_count_(0), names_(nullptr) {}
8924 ExtensionConfiguration(
int name_count,
const char* names[])
8925 : name_count_(name_count), names_(names) { }
8927 const char** begin()
const {
return &names_[0]; }
8928 const char** end()
const {
return &names_[name_count_]; }
8931 const int name_count_;
8932 const char** names_;
8939 class V8_EXPORT Context {
8953 Local<Object> Global();
8959 void DetachGlobal();
8979 static Local<Context> New(
8980 Isolate* isolate, ExtensionConfiguration* extensions =
nullptr,
8981 MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(),
8982 MaybeLocal<Value> global_object = MaybeLocal<Value>(),
8983 DeserializeInternalFieldsCallback internal_fields_deserializer =
8984 DeserializeInternalFieldsCallback());
9005 static MaybeLocal<Context> FromSnapshot(
9006 Isolate* isolate,
size_t context_snapshot_index,
9007 DeserializeInternalFieldsCallback embedder_fields_deserializer =
9008 DeserializeInternalFieldsCallback(),
9009 ExtensionConfiguration* extensions =
nullptr,
9010 MaybeLocal<Value> global_object = MaybeLocal<Value>());
9029 static MaybeLocal<Object> NewRemoteContext(
9030 Isolate* isolate, Local<ObjectTemplate> global_template,
9031 MaybeLocal<Value> global_object = MaybeLocal<Value>());
9037 void SetSecurityToken(Local<Value> token);
9040 void UseDefaultSecurityToken();
9043 Local<Value> GetSecurityToken();
9060 Isolate* GetIsolate();
9066 enum EmbedderDataFields { kDebugIdIndex = 0 };
9071 uint32_t GetNumberOfEmbedderDataFields();
9077 V8_INLINE Local<Value> GetEmbedderData(
int index);
9085 Local<Object> GetExtrasBindingObject();
9092 void SetEmbedderData(
int index, Local<Value> value);
9100 V8_INLINE
void* GetAlignedPointerFromEmbedderData(
int index);
9107 void SetAlignedPointerInEmbedderData(
int index,
void* value);
9122 void AllowCodeGenerationFromStrings(
bool allow);
9128 bool IsCodeGenerationFromStringsAllowed();
9135 void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
9143 V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(
size_t index);
9154 V8_INLINE ~
Scope() { context_->Exit(); }
9189 void* SlowGetAlignedPointerFromEmbedderData(
int index);
9269 class V8_EXPORT Unlocker {
9274 V8_INLINE
explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
9278 void Initialize(Isolate* isolate);
9280 internal::Isolate* isolate_;
9284 class V8_EXPORT Locker {
9289 V8_INLINE
explicit Locker(Isolate* isolate) { Initialize(isolate); }
9297 static bool IsLocked(Isolate* isolate);
9302 static bool IsActive();
9305 Locker(
const Locker&) =
delete;
9306 void operator=(
const Locker&) =
delete;
9309 void Initialize(Isolate* isolate);
9313 internal::Isolate* isolate_;
9321 class V8_EXPORT Unwinder {
9347 static bool TryUnwindV8Frames(
const UnwindState& unwind_state,
9348 RegisterState* register_state,
9349 const void* stack_base);
9359 static bool PCIsInV8(
const UnwindState& unwind_state,
void* pc);
9366 return New(isolate, that.val_);
9371 return New(isolate, that.val_);
9377 if (that ==
nullptr)
return Local<T>();
9379 internal::Address* p =
reinterpret_cast<internal::Address*
>(that_ptr);
9380 return Local<T>(
reinterpret_cast<T*
>(HandleScope::CreateHandle(
9381 reinterpret_cast<internal::Isolate*>(isolate), *p)));
9387 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
9389 val_ =
reinterpret_cast<T*
>(
9390 V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
9394 Local<T> Eternal<T>::Get(Isolate* isolate)
const {
9397 return Local<T>(val_);
9403 if (V8_UNLIKELY(val_ ==
nullptr)) V8::ToLocalEmpty();
9410 #ifdef V8_ENABLE_CHECKS 9411 if (index < 0 || index >= kEmbedderFieldsInWeakCallback) {
9412 V8::InternalFieldOutOfBounds(index);
9415 return embedder_fields_[index];
9420 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
9421 if (that ==
nullptr)
return nullptr;
9422 internal::Address* p =
reinterpret_cast<internal::Address*
>(that);
9423 return reinterpret_cast<T*
>(
9424 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
9429 template <
class T,
class M>
9430 template <
class S,
class M2>
9431 void Persistent<T, M>::Copy(
const Persistent<S, M2>& that) {
9434 if (that.IsEmpty())
return;
9435 internal::Address* p =
reinterpret_cast<internal::Address*
>(that.val_);
9436 this->val_ =
reinterpret_cast<T*
>(V8::CopyPersistent(p));
9437 M::Copy(that,
this);
9441 bool PersistentBase<T>::IsIndependent()
const {
9442 typedef internal::Internals I;
9443 if (this->IsEmpty())
return false;
9444 return I::GetNodeFlag(reinterpret_cast<internal::Address*>(this->val_),
9445 I::kNodeIsIndependentShift);
9451 if (this->IsEmpty())
return false;
9452 uint8_t node_state =
9453 I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_));
9454 return node_state == I::kNodeStateIsNearDeathValue ||
9455 node_state == I::kNodeStateIsPendingValue;
9462 if (this->IsEmpty())
return false;
9463 return I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_)) ==
9464 I::kNodeStateIsWeakValue;
9470 if (this->IsEmpty())
return;
9471 V8::DisposeGlobal(reinterpret_cast<internal::Address*>(this->val_));
9481 if (other.IsEmpty())
return;
9482 this->val_ = New(isolate, other.val_);
9489 const PersistentBase<S>& other) {
9492 if (other.IsEmpty())
return;
9493 this->val_ = New(isolate, other.val_);
9498 template <
typename P>
9501 WeakCallbackType
type) {
9503 V8::MakeWeak(reinterpret_cast<internal::Address*>(this->val_), parameter,
9504 reinterpret_cast<Callback>(callback),
type);
9509 V8::MakeWeak(reinterpret_cast<internal::Address**>(&this->val_));
9513 template <
typename P>
9515 return reinterpret_cast<P*
>(
9516 V8::ClearWeak(reinterpret_cast<internal::Address*>(this->val_)));
9521 V8::AnnotateStrongRetainer(reinterpret_cast<internal::Address*>(this->val_),
9527 if (IsEmpty())
return;
9528 V8::RegisterExternallyReferencedObject(
9529 reinterpret_cast<internal::Address*>(this->val_),
9530 reinterpret_cast<internal::Isolate*>(isolate));
9536 if (this->IsEmpty())
return;
9537 I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_),
true,
9538 I::kNodeIsIndependentShift);
9544 if (this->IsEmpty())
return;
9545 I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_),
true,
9546 I::kNodeIsActiveShift);
9553 if (this->IsEmpty())
return;
9555 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + I::kNodeClassIdOffset;
9556 *
reinterpret_cast<uint16_t*
>(addr) = class_id;
9563 if (this->IsEmpty())
return 0;
9565 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + I::kNodeClassIdOffset;
9566 return *
reinterpret_cast<uint16_t*
>(addr);
9569 template <
typename T>
9572 template<
typename T>
9573 template<
typename S>
9574 void ReturnValue<T>::Set(
const Persistent<S>& handle) {
9576 if (V8_UNLIKELY(handle.IsEmpty())) {
9577 *value_ = GetDefaultValue();
9579 *value_ = *
reinterpret_cast<internal::Address*
>(*handle);
9583 template <
typename T>
9584 template <
typename S>
9585 void ReturnValue<T>::Set(
const Global<S>& handle) {
9587 if (V8_UNLIKELY(handle.IsEmpty())) {
9588 *value_ = GetDefaultValue();
9590 *value_ = *
reinterpret_cast<internal::Address*
>(*handle);
9594 template <
typename T>
9595 template <
typename S>
9596 void ReturnValue<T>::Set(
const Local<S> handle) {
9598 if (V8_UNLIKELY(handle.IsEmpty())) {
9599 *value_ = GetDefaultValue();
9601 *value_ = *
reinterpret_cast<internal::Address*
>(*handle);
9605 template<
typename T>
9606 void ReturnValue<T>::Set(
double i) {
9607 TYPE_CHECK(T, Number);
9608 Set(Number::New(GetIsolate(),
i));
9611 template<
typename T>
9612 void ReturnValue<T>::Set(int32_t
i) {
9613 TYPE_CHECK(T, Integer);
9614 typedef internal::Internals I;
9615 if (V8_LIKELY(I::IsValidSmi(
i))) {
9616 *value_ = I::IntToSmi(
i);
9619 Set(Integer::New(GetIsolate(),
i));
9622 template<
typename T>
9624 TYPE_CHECK(T, Integer);
9626 bool fits_into_int32_t = (
i & (1U << 31)) == 0;
9627 if (V8_LIKELY(fits_into_int32_t)) {
9628 Set(static_cast<int32_t>(
i));
9631 Set(Integer::NewFromUnsigned(GetIsolate(),
i));
9634 template<
typename T>
9635 void ReturnValue<T>::Set(
bool value) {
9636 TYPE_CHECK(T, Boolean);
9637 typedef internal::Internals I;
9640 root_index = I::kTrueValueRootIndex;
9642 root_index = I::kFalseValueRootIndex;
9644 *value_ = *I::GetRoot(GetIsolate(), root_index);
9647 template<
typename T>
9648 void ReturnValue<T>::SetNull() {
9649 TYPE_CHECK(T, Primitive);
9650 typedef internal::Internals I;
9651 *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
9654 template<
typename T>
9655 void ReturnValue<T>::SetUndefined() {
9656 TYPE_CHECK(T, Primitive);
9657 typedef internal::Internals I;
9658 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
9661 template<
typename T>
9662 void ReturnValue<T>::SetEmptyString() {
9663 TYPE_CHECK(T, String);
9664 typedef internal::Internals I;
9665 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
9668 template <
typename T>
9669 Isolate* ReturnValue<T>::GetIsolate()
const {
9671 return *
reinterpret_cast<Isolate**
>(&value_[-2]);
9674 template <
typename T>
9675 Local<Value> ReturnValue<T>::Get()
const {
9676 typedef internal::Internals I;
9677 if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex))
9678 return Local<Value>(*Undefined(GetIsolate()));
9679 return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
9682 template <
typename T>
9683 template <
typename S>
9684 void ReturnValue<T>::Set(S* whatever) {
9686 TYPE_CHECK(S*, Primitive);
9689 template <
typename T>
9690 internal::Address ReturnValue<T>::GetDefaultValue() {
9695 template <
typename T>
9696 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Address* implicit_args,
9697 internal::Address* values,
9699 : implicit_args_(implicit_args), values_(values), length_(length) {}
9701 template<
typename T>
9703 if (
i < 0 || length_ <=
i)
return Local<Value>(*Undefined(GetIsolate()));
9708 template<
typename T>
9714 template<
typename T>
9717 &implicit_args_[kHolderIndex]));
9720 template <
typename T>
9723 reinterpret_cast<Value*
>(&implicit_args_[kNewTargetIndex]));
9726 template <
typename T>
9732 template<
typename T>
9734 return *
reinterpret_cast<Isolate**
>(&implicit_args_[kIsolateIndex]);
9738 template<
typename T>
9744 template<
typename T>
9746 return !NewTarget()->IsUndefined();
9750 template<
typename T>
9764 : resource_name_(resource_name),
9765 resource_line_offset_(resource_line_offset),
9766 resource_column_offset_(resource_column_offset),
9767 options_(!resource_is_shared_cross_origin.IsEmpty() &&
9768 resource_is_shared_cross_origin->IsTrue(),
9769 !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue(),
9770 !is_wasm.IsEmpty() && is_wasm->IsTrue(),
9771 !is_module.IsEmpty() && is_module->IsTrue()),
9772 script_id_(script_id),
9773 source_map_url_(source_map_url),
9774 host_defined_options_(host_defined_options) {}
9776 Local<Value> ScriptOrigin::ResourceName()
const {
return resource_name_; }
9778 Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions()
const {
9779 return host_defined_options_;
9782 Local<Integer> ScriptOrigin::ResourceLineOffset()
const {
9783 return resource_line_offset_;
9787 Local<Integer> ScriptOrigin::ResourceColumnOffset()
const {
9788 return resource_column_offset_;
9792 Local<Integer> ScriptOrigin::ScriptID()
const {
return script_id_; }
9795 Local<Value> ScriptOrigin::SourceMapUrl()
const {
return source_map_url_; }
9797 ScriptCompiler::Source::Source(Local<String>
string,
const ScriptOrigin& origin,
9799 : source_string(string),
9800 resource_name(origin.ResourceName()),
9801 resource_line_offset(origin.ResourceLineOffset()),
9802 resource_column_offset(origin.ResourceColumnOffset()),
9803 resource_options(origin.Options()),
9804 source_map_url(origin.SourceMapUrl()),
9805 host_defined_options(origin.HostDefinedOptions()),
9806 cached_data(data) {}
9808 ScriptCompiler::Source::Source(Local<String>
string,
9810 : source_string(string), cached_data(data) {}
9813 ScriptCompiler::Source::~Source() {
9818 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
9823 const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions()
const {
9824 return resource_options;
9827 Local<Boolean> Boolean::New(Isolate* isolate,
bool value) {
9828 return value ? True(isolate) : False(isolate);
9831 void Template::Set(Isolate* isolate,
const char* name, Local<Data> value) {
9832 Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized)
9837 FunctionTemplate* FunctionTemplate::Cast(Data* data) {
9838 #ifdef V8_ENABLE_CHECKS 9841 return reinterpret_cast<FunctionTemplate*
>(data);
9844 ObjectTemplate* ObjectTemplate::Cast(Data* data) {
9845 #ifdef V8_ENABLE_CHECKS 9848 return reinterpret_cast<ObjectTemplate*
>(data);
9851 Signature* Signature::Cast(Data* data) {
9852 #ifdef V8_ENABLE_CHECKS 9855 return reinterpret_cast<Signature*
>(data);
9858 AccessorSignature* AccessorSignature::Cast(Data* data) {
9859 #ifdef V8_ENABLE_CHECKS 9862 return reinterpret_cast<AccessorSignature*
>(data);
9866 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS) 9869 A obj = *
reinterpret_cast<A*
>(
this);
9872 auto instance_type = I::GetInstanceType(obj);
9873 if (instance_type == I::kJSObjectType ||
9874 instance_type == I::kJSApiObjectType ||
9875 instance_type == I::kJSSpecialApiObjectType) {
9876 int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
9877 A value = I::ReadField<A>(obj, offset);
9878 A* result = HandleScope::CreateHandle(
9879 reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value);
9883 return SlowGetInternalField(index);
9887 void* Object::GetAlignedPointerFromInternalField(
int index) {
9888 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS) 9891 A obj = *
reinterpret_cast<A*
>(
this);
9894 auto instance_type = I::GetInstanceType(obj);
9895 if (V8_LIKELY(instance_type == I::kJSObjectType ||
9896 instance_type == I::kJSApiObjectType ||
9897 instance_type == I::kJSSpecialApiObjectType)) {
9898 int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
9899 return I::ReadField<void*>(obj, offset);
9902 return SlowGetAlignedPointerFromInternalField(index);
9906 #ifdef V8_ENABLE_CHECKS 9909 return static_cast<String*
>(value);
9916 I::CheckInitialized(isolate);
9917 S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
9925 A obj = *
reinterpret_cast<const A*
>(
this);
9928 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
9929 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
9932 result = GetExternalStringResourceSlow();
9934 #ifdef V8_ENABLE_CHECKS 9935 VerifyExternalStringResource(result);
9942 String::Encoding* encoding_out)
const {
9945 A obj = *
reinterpret_cast<const A*
>(
this);
9946 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
9947 *encoding_out =
static_cast<Encoding
>(
type & I::kStringEncodingMask);
9949 if (
type == I::kExternalOneByteRepresentationTag ||
9950 type == I::kExternalTwoByteRepresentationTag) {
9951 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
9954 resource = GetExternalStringResourceBaseSlow(encoding_out);
9956 #ifdef V8_ENABLE_CHECKS 9957 VerifyExternalStringResourceBase(resource, *encoding_out);
9963 bool Value::IsUndefined()
const {
9964 #ifdef V8_ENABLE_CHECKS 9965 return FullIsUndefined();
9967 return QuickIsUndefined();
9971 bool Value::QuickIsUndefined()
const {
9974 A obj = *
reinterpret_cast<const A*
>(
this);
9975 if (!I::HasHeapObjectTag(obj))
return false;
9976 if (I::GetInstanceType(obj) != I::kOddballType)
return false;
9977 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
9981 bool Value::IsNull()
const {
9982 #ifdef V8_ENABLE_CHECKS 9983 return FullIsNull();
9985 return QuickIsNull();
9989 bool Value::QuickIsNull()
const {
9992 A obj = *
reinterpret_cast<const A*
>(
this);
9993 if (!I::HasHeapObjectTag(obj))
return false;
9994 if (I::GetInstanceType(obj) != I::kOddballType)
return false;
9995 return (I::GetOddballKind(obj) == I::kNullOddballKind);
9998 bool Value::IsNullOrUndefined()
const {
9999 #ifdef V8_ENABLE_CHECKS 10000 return FullIsNull() || FullIsUndefined();
10002 return QuickIsNullOrUndefined();
10006 bool Value::QuickIsNullOrUndefined()
const {
10009 A obj = *
reinterpret_cast<const A*
>(
this);
10010 if (!I::HasHeapObjectTag(obj))
return false;
10011 if (I::GetInstanceType(obj) != I::kOddballType)
return false;
10012 int kind = I::GetOddballKind(obj);
10013 return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
10016 bool Value::IsString()
const {
10017 #ifdef V8_ENABLE_CHECKS 10018 return FullIsString();
10020 return QuickIsString();
10024 bool Value::QuickIsString()
const {
10027 A obj = *
reinterpret_cast<const A*
>(
this);
10028 if (!I::HasHeapObjectTag(obj))
return false;
10029 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
10033 template <
class T>
Value* Value::Cast(T* value) {
10034 return static_cast<Value*
>(value);
10038 Boolean* Boolean::Cast(
v8::Value* value) {
10039 #ifdef V8_ENABLE_CHECKS 10042 return static_cast<Boolean*
>(value);
10047 #ifdef V8_ENABLE_CHECKS 10050 return static_cast<Name*
>(value);
10054 Symbol* Symbol::Cast(
v8::Value* value) {
10055 #ifdef V8_ENABLE_CHECKS 10058 return static_cast<Symbol*
>(value);
10062 Private* Private::Cast(Data* data) {
10063 #ifdef V8_ENABLE_CHECKS 10066 return reinterpret_cast<Private*
>(data);
10070 Number* Number::Cast(
v8::Value* value) {
10071 #ifdef V8_ENABLE_CHECKS 10074 return static_cast<Number*
>(value);
10078 Integer* Integer::Cast(
v8::Value* value) {
10079 #ifdef V8_ENABLE_CHECKS 10082 return static_cast<Integer*
>(value);
10087 #ifdef V8_ENABLE_CHECKS 10090 return static_cast<Int32*
>(value);
10094 Uint32* Uint32::Cast(
v8::Value* value) {
10095 #ifdef V8_ENABLE_CHECKS 10098 return static_cast<Uint32*
>(value);
10101 BigInt* BigInt::Cast(
v8::Value* value) {
10102 #ifdef V8_ENABLE_CHECKS 10105 return static_cast<BigInt*
>(value);
10109 #ifdef V8_ENABLE_CHECKS 10112 return static_cast<Date*
>(value);
10116 StringObject* StringObject::Cast(
v8::Value* value) {
10117 #ifdef V8_ENABLE_CHECKS 10120 return static_cast<StringObject*
>(value);
10124 SymbolObject* SymbolObject::Cast(
v8::Value* value) {
10125 #ifdef V8_ENABLE_CHECKS 10128 return static_cast<SymbolObject*
>(value);
10132 NumberObject* NumberObject::Cast(
v8::Value* value) {
10133 #ifdef V8_ENABLE_CHECKS 10136 return static_cast<NumberObject*
>(value);
10139 BigIntObject* BigIntObject::Cast(
v8::Value* value) {
10140 #ifdef V8_ENABLE_CHECKS 10143 return static_cast<BigIntObject*
>(value);
10146 BooleanObject* BooleanObject::Cast(
v8::Value* value) {
10147 #ifdef V8_ENABLE_CHECKS 10150 return static_cast<BooleanObject*
>(value);
10154 RegExp* RegExp::Cast(
v8::Value* value) {
10155 #ifdef V8_ENABLE_CHECKS 10158 return static_cast<RegExp*
>(value);
10162 Object* Object::Cast(
v8::Value* value) {
10163 #ifdef V8_ENABLE_CHECKS 10166 return static_cast<Object*
>(value);
10171 #ifdef V8_ENABLE_CHECKS 10174 return static_cast<Array*
>(value);
10179 #ifdef V8_ENABLE_CHECKS 10182 return static_cast<Map*
>(value);
10187 #ifdef V8_ENABLE_CHECKS 10190 return static_cast<Set*
>(value);
10194 Promise* Promise::Cast(
v8::Value* value) {
10195 #ifdef V8_ENABLE_CHECKS 10198 return static_cast<Promise*
>(value);
10203 #ifdef V8_ENABLE_CHECKS 10206 return static_cast<Proxy*
>(value);
10209 WasmCompiledModule* WasmCompiledModule::Cast(
v8::Value* value) {
10210 #ifdef V8_ENABLE_CHECKS 10213 return static_cast<WasmCompiledModule*
>(value);
10216 Promise::Resolver* Promise::Resolver::Cast(
v8::Value* value) {
10217 #ifdef V8_ENABLE_CHECKS 10220 return static_cast<Promise::Resolver*
>(value);
10224 ArrayBuffer* ArrayBuffer::Cast(
v8::Value* value) {
10225 #ifdef V8_ENABLE_CHECKS 10228 return static_cast<ArrayBuffer*
>(value);
10232 ArrayBufferView* ArrayBufferView::Cast(
v8::Value* value) {
10233 #ifdef V8_ENABLE_CHECKS 10236 return static_cast<ArrayBufferView*
>(value);
10240 TypedArray* TypedArray::Cast(
v8::Value* value) {
10241 #ifdef V8_ENABLE_CHECKS 10244 return static_cast<TypedArray*
>(value);
10248 Uint8Array* Uint8Array::Cast(
v8::Value* value) {
10249 #ifdef V8_ENABLE_CHECKS 10252 return static_cast<Uint8Array*
>(value);
10256 Int8Array* Int8Array::Cast(
v8::Value* value) {
10257 #ifdef V8_ENABLE_CHECKS 10260 return static_cast<Int8Array*
>(value);
10264 Uint16Array* Uint16Array::Cast(
v8::Value* value) {
10265 #ifdef V8_ENABLE_CHECKS 10268 return static_cast<Uint16Array*
>(value);
10272 Int16Array* Int16Array::Cast(
v8::Value* value) {
10273 #ifdef V8_ENABLE_CHECKS 10276 return static_cast<Int16Array*
>(value);
10280 Uint32Array* Uint32Array::Cast(
v8::Value* value) {
10281 #ifdef V8_ENABLE_CHECKS 10284 return static_cast<Uint32Array*
>(value);
10288 Int32Array* Int32Array::Cast(
v8::Value* value) {
10289 #ifdef V8_ENABLE_CHECKS 10292 return static_cast<Int32Array*
>(value);
10296 Float32Array* Float32Array::Cast(
v8::Value* value) {
10297 #ifdef V8_ENABLE_CHECKS 10300 return static_cast<Float32Array*
>(value);
10304 Float64Array* Float64Array::Cast(
v8::Value* value) {
10305 #ifdef V8_ENABLE_CHECKS 10308 return static_cast<Float64Array*
>(value);
10311 BigInt64Array* BigInt64Array::Cast(
v8::Value* value) {
10312 #ifdef V8_ENABLE_CHECKS 10315 return static_cast<BigInt64Array*
>(value);
10318 BigUint64Array* BigUint64Array::Cast(
v8::Value* value) {
10319 #ifdef V8_ENABLE_CHECKS 10322 return static_cast<BigUint64Array*
>(value);
10325 Uint8ClampedArray* Uint8ClampedArray::Cast(
v8::Value* value) {
10326 #ifdef V8_ENABLE_CHECKS 10329 return static_cast<Uint8ClampedArray*
>(value);
10333 DataView* DataView::Cast(
v8::Value* value) {
10334 #ifdef V8_ENABLE_CHECKS 10337 return static_cast<DataView*
>(value);
10341 SharedArrayBuffer* SharedArrayBuffer::Cast(
v8::Value* value) {
10342 #ifdef V8_ENABLE_CHECKS 10345 return static_cast<SharedArrayBuffer*
>(value);
10349 Function* Function::Cast(
v8::Value* value) {
10350 #ifdef V8_ENABLE_CHECKS 10353 return static_cast<Function*
>(value);
10357 External* External::Cast(
v8::Value* value) {
10358 #ifdef V8_ENABLE_CHECKS 10361 return static_cast<External*
>(value);
10365 template<
typename T>
10367 return *
reinterpret_cast<Isolate**
>(&args_[kIsolateIndex]);
10371 template<
typename T>
10377 template<
typename T>
10383 template<
typename T>
10389 template<
typename T>
10394 template <
typename T>
10397 return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(0);
10404 I::CheckInitialized(isolate);
10405 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
10410 Local<Primitive> Null(Isolate* isolate) {
10411 typedef internal::Address S;
10412 typedef internal::Internals I;
10413 I::CheckInitialized(isolate);
10414 S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
10415 return Local<Primitive>(
reinterpret_cast<Primitive*
>(slot));
10419 Local<Boolean> True(Isolate* isolate) {
10420 typedef internal::Address S;
10421 typedef internal::Internals I;
10422 I::CheckInitialized(isolate);
10423 S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
10424 return Local<Boolean>(
reinterpret_cast<Boolean*
>(slot));
10428 Local<Boolean> False(Isolate* isolate) {
10429 typedef internal::Address S;
10430 typedef internal::Internals I;
10431 I::CheckInitialized(isolate);
10432 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
10433 return Local<Boolean>(
reinterpret_cast<Boolean*
>(slot));
10437 void Isolate::SetData(
uint32_t slot,
void* data) {
10438 typedef internal::Internals I;
10439 I::SetEmbedderData(
this, slot, data);
10443 void* Isolate::GetData(
uint32_t slot) {
10444 typedef internal::Internals I;
10445 return I::GetEmbedderData(
this, slot);
10449 uint32_t Isolate::GetNumberOfDataSlots() {
10450 typedef internal::Internals I;
10451 return I::kNumIsolateDataSlots;
10455 MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(
size_t index) {
10456 T* data =
reinterpret_cast<T*
>(GetDataFromSnapshotOnce(index));
10457 if (data) internal::PerformCastCheck(data);
10458 return Local<T>(data);
10461 int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
10463 typedef internal::Internals I;
10464 constexpr
int64_t kMemoryReducerActivationLimit = 32 * 1024 * 1024;
10466 reinterpret_cast<uint8_t*
>(
this) + I::kExternalMemoryOffset);
10468 reinterpret_cast<uint8_t*
>(
this) + I::kExternalMemoryLimitOffset);
10469 int64_t* external_memory_at_last_mc =
10470 reinterpret_cast<int64_t*
>(
reinterpret_cast<uint8_t*
>(
this) +
10471 I::kExternalMemoryAtLastMarkCompactOffset);
10473 const int64_t amount = *external_memory + change_in_bytes;
10474 *external_memory = amount;
10476 int64_t allocation_diff_since_last_mc =
10477 *external_memory - *external_memory_at_last_mc;
10480 if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) {
10481 CheckMemoryPressure();
10484 if (change_in_bytes < 0) {
10485 const int64_t lower_limit = *external_memory_limit + change_in_bytes;
10486 if (lower_limit > I::kExternalAllocationSoftLimit)
10487 *external_memory_limit = lower_limit;
10488 }
else if (change_in_bytes > 0 && amount > *external_memory_limit) {
10489 ReportExternalAllocationLimitReached();
10491 return *external_memory;
10494 Local<Value> Context::GetEmbedderData(
int index) {
10495 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS) 10496 typedef internal::Address A;
10497 typedef internal::Internals I;
10498 auto* context = *
reinterpret_cast<internal::NeverReadOnlySpaceObject**
>(
this);
10500 HandleScope::CreateHandle(context, I::ReadEmbedderData<A>(
this, index));
10501 return Local<Value>(
reinterpret_cast<Value*
>(result));
10503 return SlowGetEmbedderData(index);
10508 void* Context::GetAlignedPointerFromEmbedderData(
int index) {
10509 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS) 10510 typedef internal::Internals I;
10511 return I::ReadEmbedderData<void*>(
this, index);
10513 return SlowGetAlignedPointerFromEmbedderData(index);
10518 MaybeLocal<T> Context::GetDataFromSnapshotOnce(
size_t index) {
10519 T* data =
reinterpret_cast<T*
>(GetDataFromSnapshotOnce(index));
10520 if (data) internal::PerformCastCheck(data);
10521 return Local<T>(data);
10525 size_t SnapshotCreator::AddData(Local<Context> context, Local<T>
object) {
10526 T* object_ptr = *object;
10527 internal::Address* p =
reinterpret_cast<internal::Address*
>(object_ptr);
10528 return AddData(context, *p);
10532 size_t SnapshotCreator::AddData(Local<T>
object) {
10533 T* object_ptr = *object;
10534 internal::Address* p =
reinterpret_cast<internal::Address*
>(object_ptr);
10535 return AddData(*p);
10556 #endif // INCLUDE_V8_H_ V8_INLINE bool IsNearDeath() const
V8_INLINE uint16_t WrapperClassId() const
virtual void Unlock() const
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
static V8_INLINE Local< Context > CreationContext(const PersistentBase< Object > &object)
bool only_terminate_in_safe_scope
void(* GenericNamedPropertyDefinerCallback)(Local< Name > property, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
V8_INLINE Local< T > Escape(Local< T > value)
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
virtual bool IsCacheable() const
V8_INLINE int Length() const
static V8_INLINE Local< T > Cast(Local< S > that)
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
V8_INLINE bool IsWeak() const
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
void(* GenericNamedPropertyDeleterCallback)(Local< Name > property, const PropertyCallbackInfo< Boolean > &info)
void(* IndexedPropertyDescriptorCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
V8_INLINE bool IsEmpty() const
V8_INLINE Local< Object > Holder() const
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
V8_INLINE Local< Value > NewTarget() const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE T FromJust() const
V8_INLINE bool ShouldThrowOnError() const
V8_INLINE Local< S > As() const
void(* IndexedPropertyDefinerCallback)(uint32_t index, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
void SetIndexedPropertyHandler(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter=nullptr, IndexedPropertyQueryCallback query=nullptr, IndexedPropertyDeleterCallback deleter=nullptr, IndexedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >())
V8_INLINE Persistent(const Persistent &that)
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
bool(* AccessCheckCallback)(Local< Context > accessing_context, Local< Object > accessed_object, Local< Value > data)
CreateHistogramCallback create_histogram_callback
void(* GenericNamedPropertyQueryCallback)(Local< Name > property, const PropertyCallbackInfo< Integer > &info)
V8_DEPRECATE_SOON("Objects are always considered independent. " "Use MarkActive to avoid collecting otherwise dead weak handles.", V8_INLINE void MarkIndependent())
void(* GenericNamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
StartupData * snapshot_blob
NamedPropertyHandlerConfiguration(GenericNamedPropertyGetterCallback getter=nullptr, GenericNamedPropertySetterCallback setter=nullptr, GenericNamedPropertyQueryCallback query=nullptr, GenericNamedPropertyDeleterCallback deleter=nullptr, GenericNamedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
V8_INLINE Local< Value > operator[](int i) const
V8_INLINE Global & operator=(Global< S > &&rhs)
V8_INLINE bool operator!=(const Local< S > &that) const
CounterLookupCallback counter_lookup_callback
void(* GenericNamedPropertyDescriptorCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
V8_INLINE bool operator==(const Local< S > &that) const
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
V8_INLINE Local< T > ToLocalChecked()
V8_INLINE Local< Value > Data() const
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_WARN_UNUSED_RESULT V8_INLINE bool To(T *out) const
FunctionEntryHook entry_hook
V8_INLINE void MarkActive()
V8_INLINE Local< Value > Data() const
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
V8_INLINE Local(Local< S > that)
IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback getter=nullptr, IndexedPropertySetterCallback setter=nullptr, IndexedPropertyQueryCallback query=nullptr, IndexedPropertyDeleterCallback deleter=nullptr, IndexedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
const intptr_t * external_references
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
V8_INLINE Global(Isolate *isolate, Local< S > that)
V8_INLINE Local< Object > Holder() const
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_INLINE void SetWrapperClassId(uint16_t class_id)
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
V8_INLINE T FromMaybe(const T &default_value) const
void(* GenericNamedPropertyGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
virtual void Lock() const
JitCodeEventHandler code_event_handler
V8_INLINE Global(Global &&other)
ArrayBuffer::Allocator * array_buffer_allocator
V8_INLINE void RegisterExternalReference(Isolate *isolate) const
V8_INLINE Local< Object > This() const
V8_INLINE void AnnotateStrongRetainer(const char *label)
V8_INLINE bool IsConstructCall() const
V8_INLINE T ToChecked() const
V8_INLINE Local< S > FromMaybe(Local< S > default_value) const
void(* GenericNamedPropertySetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
V8_INLINE Local< Object > This() const
V8_INLINE Isolate * GetIsolate() const
ResourceConstraints constraints