v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 
22 #include <atomic>
23 #include <memory>
24 #include <string>
25 #include <type_traits>
26 #include <utility>
27 #include <vector>
28 
29 #include "cppgc/common.h"
30 #include "v8-internal.h" // NOLINT(build/include_directory)
31 #include "v8-version.h" // NOLINT(build/include_directory)
32 #include "v8config.h" // NOLINT(build/include_directory)
33 
34 // We reserve the V8_* prefix for macros defined in V8 public API and
35 // assume there are no name conflicts with the embedder's code.
36 
40 namespace v8 {
41 
42 class AccessorSignature;
43 class Array;
44 class ArrayBuffer;
45 class BigInt;
46 class BigIntObject;
47 class Boolean;
48 class BooleanObject;
49 class CFunction;
50 class CallHandlerHelper;
51 class Context;
52 class CppHeap;
53 class Data;
54 class Date;
55 class EscapableHandleScope;
56 class External;
57 class Function;
58 class FunctionTemplate;
59 class HeapProfiler;
60 class ImplementationUtilities;
61 class Int32;
62 class Integer;
63 class Isolate;
64 class Isolate;
65 class MicrotaskQueue;
66 class Name;
67 class Number;
68 class NumberObject;
69 class Object;
70 class ObjectOperationDescriptor;
71 class ObjectTemplate;
72 class Platform;
73 class Primitive;
74 class PrimitiveArray;
75 class Private;
76 class Promise;
77 class PropertyDescriptor;
78 class Proxy;
79 class RawOperationDescriptor;
80 class Script;
81 class SharedArrayBuffer;
82 class Signature;
83 class StackFrame;
84 class StackTrace;
85 class StartupData;
86 class String;
87 class StringObject;
88 class Symbol;
89 class SymbolObject;
90 class TracedReferenceBase;
91 class Uint32;
92 class Utils;
93 class Value;
94 class WasmMemoryObject;
95 class WasmModuleObject;
96 template <class K, class V, class T>
97 class GlobalValueMap;
98 template <class K, class V, class T>
99 class PersistentValueMapBase;
100 template<class T> class NonCopyablePersistentTraits;
101 template <class T, class M = NonCopyablePersistentTraits<T>>
102 class Persistent;
103 template <class T>
104 class BasicTracedReference;
105 template <class T>
106 class Eternal;
107 template <class T>
108 class Global;
109 template <class T>
110 class Local;
111 template <class T>
112 class Maybe;
113 template <class T>
114 class MaybeLocal;
115 template <class T>
116 class TracedGlobal;
117 template <class T>
118 class TracedReference;
119 template<class K, class V, class T> class PersistentValueMap;
120 template<class T, class P> class WeakCallbackObject;
121 template <class T>
122 class PersistentBase;
123 template <class V, class T>
125 template<typename T> class FunctionCallbackInfo;
126 template<typename T> class PropertyCallbackInfo;
127 template<typename T> class ReturnValue;
128 
129 namespace internal {
130 class BasicTracedReferenceExtractor;
131 class ExternalString;
132 class FunctionCallbackArguments;
133 class GlobalHandles;
134 class Heap;
135 class HeapObject;
136 class Isolate;
137 class LocalEmbedderHeapTracer;
138 class MicrotaskQueue;
139 class PropertyCallbackArguments;
140 class ReadOnlyHeap;
141 class ScopedExternalStringLock;
142 class ThreadLocalTop;
143 struct ScriptStreamingData;
144 enum class ArgumentsType;
145 template <ArgumentsType>
146 class Arguments;
147 template <typename T>
149 
150 namespace wasm {
151 class NativeModule;
152 class StreamingDecoder;
153 } // namespace wasm
154 
155 } // namespace internal
156 
157 namespace metrics {
158 class Recorder;
159 } // namespace metrics
160 
161 namespace debug {
162 class ConsoleCallArguments;
163 } // namespace debug
164 
165 // --- Handles ---
166 
198 template <class T>
199 class Local {
200  public:
201  V8_INLINE Local() : val_(nullptr) {}
202  template <class S>
204  : val_(reinterpret_cast<T*>(*that)) {
210  static_assert(std::is_base_of<T, S>::value, "type check");
211  }
212 
216  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
217 
221  V8_INLINE void Clear() { val_ = nullptr; }
222 
223  V8_INLINE T* operator->() const { return val_; }
224 
225  V8_INLINE T* operator*() const { return val_; }
226 
237  template <class S>
238  V8_INLINE bool operator==(const Local<S>& that) const {
239  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
240  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
241  if (a == nullptr) return b == nullptr;
242  if (b == nullptr) return false;
243  return *a == *b;
244  }
245 
246  template <class S> V8_INLINE bool operator==(
247  const PersistentBase<S>& that) const {
248  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
249  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
250  if (a == nullptr) return b == nullptr;
251  if (b == nullptr) return false;
252  return *a == *b;
253  }
254 
265  template <class S>
266  V8_INLINE bool operator!=(const Local<S>& that) const {
267  return !operator==(that);
268  }
269 
270  template <class S> V8_INLINE bool operator!=(
271  const Persistent<S>& that) const {
272  return !operator==(that);
273  }
274 
280  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
281 #ifdef V8_ENABLE_CHECKS
282  // If we're going to perform the type check then we have to check
283  // that the handle isn't empty before doing the checked cast.
284  if (that.IsEmpty()) return Local<T>();
285 #endif
286  return Local<T>(T::Cast(*that));
287  }
288 
294  template <class S>
296  return Local<S>::Cast(*this);
297  }
298 
304  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
305  V8_INLINE static Local<T> New(Isolate* isolate,
306  const PersistentBase<T>& that);
307  V8_INLINE static Local<T> New(Isolate* isolate,
308  const BasicTracedReference<T>& that);
309 
310  private:
311  friend class TracedReferenceBase;
312  friend class Utils;
313  template<class F> friend class Eternal;
314  template<class F> friend class PersistentBase;
315  template<class F, class M> friend class Persistent;
316  template<class F> friend class Local;
317  template <class F>
318  friend class MaybeLocal;
319  template<class F> friend class FunctionCallbackInfo;
320  template<class F> friend class PropertyCallbackInfo;
321  friend class String;
322  friend class Object;
323  friend class Context;
324  friend class Isolate;
325  friend class Private;
326  template<class F> friend class internal::CustomArguments;
328  friend Local<Primitive> Null(Isolate* isolate);
329  friend Local<Boolean> True(Isolate* isolate);
330  friend Local<Boolean> False(Isolate* isolate);
331  friend class HandleScope;
332  friend class EscapableHandleScope;
333  template <class F1, class F2, class F3>
335  template<class F1, class F2> friend class PersistentValueVector;
336  template <class F>
337  friend class ReturnValue;
338  template <class F>
339  friend class Traced;
340  template <class F>
341  friend class TracedGlobal;
342  template <class F>
343  friend class BasicTracedReference;
344  template <class F>
345  friend class TracedReference;
346 
347  explicit V8_INLINE Local(T* that) : val_(that) {}
348  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
349  T* val_;
350 };
351 
352 
353 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
354 // Handle is an alias for Local for historical reasons.
355 template <class T>
356 using Handle = Local<T>;
357 #endif
358 
359 
370 template <class T>
371 class MaybeLocal {
372  public:
373  V8_INLINE MaybeLocal() : val_(nullptr) {}
374  template <class S>
376  : val_(reinterpret_cast<T*>(*that)) {
377  static_assert(std::is_base_of<T, S>::value, "type check");
378  }
379 
380  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
381 
386  template <class S>
388  out->val_ = IsEmpty() ? nullptr : this->val_;
389  return !IsEmpty();
390  }
391 
397 
402  template <class S>
403  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
404  return IsEmpty() ? default_value : Local<S>(val_);
405  }
406 
407  private:
408  T* val_;
409 };
410 
415 template <class T> class Eternal {
416  public:
417  V8_INLINE Eternal() : val_(nullptr) {}
418  template <class S>
419  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
420  Set(isolate, handle);
421  }
422  // Can only be safely called if already set.
423  V8_INLINE Local<T> Get(Isolate* isolate) const;
424  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
425  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
426 
427  private:
428  T* val_;
429 };
430 
431 
432 static const int kInternalFieldsInWeakCallback = 2;
433 static const int kEmbedderFieldsInWeakCallback = 2;
434 
435 template <typename T>
437  public:
438  using Callback = void (*)(const WeakCallbackInfo<T>& data);
439 
440  WeakCallbackInfo(Isolate* isolate, T* parameter,
441  void* embedder_fields[kEmbedderFieldsInWeakCallback],
442  Callback* callback)
443  : isolate_(isolate), parameter_(parameter), callback_(callback) {
444  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
445  embedder_fields_[i] = embedder_fields[i];
446  }
447  }
448 
449  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
450  V8_INLINE T* GetParameter() const { return parameter_; }
451  V8_INLINE void* GetInternalField(int index) const;
452 
453  // When first called, the embedder MUST Reset() the Global which triggered the
454  // callback. The Global itself is unusable for anything else. No v8 other api
455  // calls may be called in the first callback. Should additional work be
456  // required, the embedder must set a second pass callback, which will be
457  // called after all the initial callbacks are processed.
458  // Calling SetSecondPassCallback on the second pass will immediately crash.
459  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
460 
461  private:
462  Isolate* isolate_;
463  T* parameter_;
464  Callback* callback_;
465  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
466 };
467 
468 
469 // kParameter will pass a void* parameter back to the callback, kInternalFields
470 // will pass the first two internal fields back to the callback, kFinalizer
471 // will pass a void* parameter back, but is invoked before the object is
472 // actually collected, so it can be resurrected. In the last case, it is not
473 // possible to request a second pass callback.
475 
489 template <class T> class PersistentBase {
490  public:
495  V8_INLINE void Reset();
500  template <class S>
501  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
502 
507  template <class S>
508  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
509 
510  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
511  V8_INLINE void Empty() { val_ = 0; }
512 
513  V8_INLINE Local<T> Get(Isolate* isolate) const {
514  return Local<T>::New(isolate, *this);
515  }
516 
517  template <class S>
518  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
519  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
520  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
521  if (a == nullptr) return b == nullptr;
522  if (b == nullptr) return false;
523  return *a == *b;
524  }
525 
526  template <class S>
527  V8_INLINE bool operator==(const Local<S>& that) const {
528  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
529  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
530  if (a == nullptr) return b == nullptr;
531  if (b == nullptr) return false;
532  return *a == *b;
533  }
534 
535  template <class S>
536  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
537  return !operator==(that);
538  }
539 
540  template <class S>
541  V8_INLINE bool operator!=(const Local<S>& that) const {
542  return !operator==(that);
543  }
544 
557  template <typename P>
558  V8_INLINE void SetWeak(P* parameter,
559  typename WeakCallbackInfo<P>::Callback callback,
560  WeakCallbackType type);
561 
569  V8_INLINE void SetWeak();
570 
571  template<typename P>
572  V8_INLINE P* ClearWeak();
573 
574  // TODO(dcarney): remove this.
575  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
576 
583  V8_INLINE void AnnotateStrongRetainer(const char* label);
584 
586  V8_INLINE bool IsWeak() const;
587 
591  V8_INLINE void SetWrapperClassId(uint16_t class_id);
592 
597  V8_INLINE uint16_t WrapperClassId() const;
598 
599  PersistentBase(const PersistentBase& other) = delete; // NOLINT
600  void operator=(const PersistentBase&) = delete;
601 
602  private:
603  friend class Isolate;
604  friend class Utils;
605  template<class F> friend class Local;
606  template<class F1, class F2> friend class Persistent;
607  template <class F>
608  friend class Global;
609  template<class F> friend class PersistentBase;
610  template<class F> friend class ReturnValue;
611  template <class F1, class F2, class F3>
613  template<class F1, class F2> friend class PersistentValueVector;
614  friend class Object;
615 
616  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
617  V8_INLINE static T* New(Isolate* isolate, T* that);
618 
619  T* val_;
620 };
621 
622 
629 template<class T>
631  public:
633  static const bool kResetInDestructor = false;
634  template<class S, class M>
635  V8_INLINE static void Copy(const Persistent<S, M>& source,
636  NonCopyablePersistent* dest) {
637  static_assert(sizeof(S) < 0,
638  "NonCopyablePersistentTraits::Copy is not instantiable");
639  }
640 };
641 
642 
647 template<class T>
650  static const bool kResetInDestructor = true;
651  template<class S, class M>
652  static V8_INLINE void Copy(const Persistent<S, M>& source,
653  CopyablePersistent* dest) {
654  // do nothing, just allow copy
655  }
656 };
657 
658 
667 template <class T, class M> class Persistent : public PersistentBase<T> {
668  public:
678  template <class S>
680  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
681  static_assert(std::is_base_of<T, S>::value, "type check");
682  }
688  template <class S, class M2>
690  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
691  static_assert(std::is_base_of<T, S>::value, "type check");
692  }
699  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(nullptr) {
700  Copy(that);
701  }
702  template <class S, class M2>
704  Copy(that);
705  }
707  Copy(that);
708  return *this;
709  }
710  template <class S, class M2>
712  Copy(that);
713  return *this;
714  }
721  if (M::kResetInDestructor) this->Reset();
722  }
723 
724  // TODO(dcarney): this is pretty useless, fix or remove
725  template <class S>
726  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
727 #ifdef V8_ENABLE_CHECKS
728  // If we're going to perform the type check then we have to check
729  // that the handle isn't empty before doing the checked cast.
730  if (!that.IsEmpty()) T::Cast(*that);
731 #endif
732  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
733  }
734 
735  // TODO(dcarney): this is pretty useless, fix or remove
736  template <class S>
737  V8_INLINE Persistent<S>& As() const { // NOLINT
738  return Persistent<S>::Cast(*this);
739  }
740 
741  private:
742  friend class Isolate;
743  friend class Utils;
744  template<class F> friend class Local;
745  template<class F1, class F2> friend class Persistent;
746  template<class F> friend class ReturnValue;
747 
748  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
749  V8_INLINE T* operator*() const { return this->val_; }
750  template<class S, class M2>
751  V8_INLINE void Copy(const Persistent<S, M2>& that);
752 };
753 
754 
760 template <class T>
761 class Global : public PersistentBase<T> {
762  public:
766  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
767 
773  template <class S>
775  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
776  static_assert(std::is_base_of<T, S>::value, "type check");
777  }
778 
784  template <class S>
785  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
786  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
787  static_assert(std::is_base_of<T, S>::value, "type check");
788  }
789 
793  V8_INLINE Global(Global&& other);
794 
795  V8_INLINE ~Global() { this->Reset(); }
796 
800  template <class S>
802 
806  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
807 
808  /*
809  * For compatibility with Chromium's base::Bind (base::Passed).
810  */
811  using MoveOnlyTypeForCPP03 = void;
812 
813  Global(const Global&) = delete;
814  void operator=(const Global&) = delete;
815 
816  private:
817  template <class F>
818  friend class ReturnValue;
819  V8_INLINE T* operator*() const { return this->val_; }
820 };
821 
822 
823 // UniquePersistent is an alias for Global for historical reason.
824 template <class T>
826 
830 template <typename T>
832 
834  public:
839  bool IsEmpty() const { return val_ == nullptr; }
840 
845  V8_INLINE void Reset();
846 
851 
856  bool IsEmptyThreadSafe() const {
857  return this->GetSlotThreadSafe() == nullptr;
858  }
859 
863  V8_INLINE void SetWrapperClassId(uint16_t class_id);
864 
869  V8_INLINE uint16_t WrapperClassId() const;
870 
871  protected:
875  void SetSlotThreadSafe(void* new_val) {
876  reinterpret_cast<std::atomic<void*>*>(&val_)->store(
877  new_val, std::memory_order_relaxed);
878  }
879 
883  const void* GetSlotThreadSafe() const {
884  return reinterpret_cast<std::atomic<const void*> const*>(&val_)->load(
885  std::memory_order_relaxed);
886  }
887 
888  // val_ points to a GlobalHandles node.
890 
892  template <typename F>
893  friend class Local;
894  template <typename U>
895  friend bool operator==(const TracedReferenceBase&, const Local<U>&);
896  friend bool operator==(const TracedReferenceBase&,
897  const TracedReferenceBase&);
898 };
899 
915 template <typename T>
917  public:
921  Local<T> Get(Isolate* isolate) const { return Local<T>::New(isolate, *this); }
922 
923  template <class S>
925  return reinterpret_cast<BasicTracedReference<S>&>(
926  const_cast<BasicTracedReference<T>&>(*this));
927  }
928 
929  T* operator->() const { return reinterpret_cast<T*>(val_); }
930  T* operator*() const { return reinterpret_cast<T*>(val_); }
931 
932  private:
933  enum DestructionMode { kWithDestructor, kWithoutDestructor };
934 
938  BasicTracedReference() = default;
939 
940  V8_INLINE static internal::Address* New(Isolate* isolate, T* that, void* slot,
941  DestructionMode destruction_mode);
942 
943  friend class EmbedderHeapTracer;
944  template <typename F>
945  friend class Local;
946  friend class Object;
947  template <typename F>
948  friend class TracedGlobal;
949  template <typename F>
950  friend class TracedReference;
951  template <typename F>
952  friend class BasicTracedReference;
953  template <typename F>
954  friend class ReturnValue;
955 };
956 
961 template <typename T>
963  public:
965 
969  ~TracedGlobal() { this->Reset(); }
970 
975 
982  template <class S>
984  this->val_ = this->New(isolate, that.val_, &this->val_,
986  static_assert(std::is_base_of<T, S>::value, "type check");
987  }
988 
993  // Forward to operator=.
994  *this = std::move(other);
995  }
996 
1000  template <typename S>
1002  // Forward to operator=.
1003  *this = std::move(other);
1004  }
1005 
1010  // Forward to operator=;
1011  *this = other;
1012  }
1013 
1017  template <typename S>
1019  // Forward to operator=;
1020  *this = other;
1021  }
1022 
1027 
1031  template <class S>
1033 
1041 
1048  template <class S>
1050 
1055  template <class S>
1056  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
1057 
1058  template <class S>
1060  return reinterpret_cast<TracedGlobal<S>&>(
1061  const_cast<TracedGlobal<T>&>(*this));
1062  }
1063 
1075  void* parameter, WeakCallbackInfo<void>::Callback callback);
1076 };
1077 
1089 template <typename T>
1091  public:
1093 
1098 
1105  template <class S>
1107  this->val_ = this->New(isolate, that.val_, &this->val_,
1109  static_assert(std::is_base_of<T, S>::value, "type check");
1110  }
1111 
1117  // Forward to operator=.
1118  *this = std::move(other);
1119  }
1120 
1125  template <typename S>
1127  // Forward to operator=.
1128  *this = std::move(other);
1129  }
1130 
1136  // Forward to operator=;
1137  *this = other;
1138  }
1139 
1144  template <typename S>
1146  // Forward to operator=;
1147  *this = other;
1148  }
1149 
1154 
1158  template <class S>
1160 
1165 
1169  template <class S>
1171 
1176  template <class S>
1177  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
1178 
1179  template <class S>
1181  return reinterpret_cast<TracedReference<S>&>(
1182  const_cast<TracedReference<T>&>(*this));
1183  }
1184 };
1185 
1201  public:
1202  explicit HandleScope(Isolate* isolate);
1203 
1205 
1209  static int NumberOfHandles(Isolate* isolate);
1210 
1212  return reinterpret_cast<Isolate*>(isolate_);
1213  }
1214 
1215  HandleScope(const HandleScope&) = delete;
1216  void operator=(const HandleScope&) = delete;
1217 
1218  protected:
1219  V8_INLINE HandleScope() = default;
1220 
1221  void Initialize(Isolate* isolate);
1222 
1223  static internal::Address* CreateHandle(internal::Isolate* isolate,
1224  internal::Address value);
1225 
1226  private:
1227  // Declaring operator new and delete as deleted is not spec compliant.
1228  // Therefore declare them private instead to disable dynamic alloc
1229  void* operator new(size_t size);
1230  void* operator new[](size_t size);
1231  void operator delete(void*, size_t);
1232  void operator delete[](void*, size_t);
1233 
1234  internal::Isolate* isolate_;
1235  internal::Address* prev_next_;
1236  internal::Address* prev_limit_;
1237 
1238  // Local::New uses CreateHandle with an Isolate* parameter.
1239  template<class F> friend class Local;
1240 
1241  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
1242  // a HeapObject in their shortcuts.
1243  friend class Object;
1244  friend class Context;
1245 };
1246 
1252  public:
1253  explicit EscapableHandleScope(Isolate* isolate);
1255 
1260  template <class T>
1262  internal::Address* slot =
1263  Escape(reinterpret_cast<internal::Address*>(*value));
1264  return Local<T>(reinterpret_cast<T*>(slot));
1265  }
1266 
1267  template <class T>
1269  return Escape(value.FromMaybe(Local<T>()));
1270  }
1271 
1273  void operator=(const EscapableHandleScope&) = delete;
1274 
1275  private:
1276  // Declaring operator new and delete as deleted is not spec compliant.
1277  // Therefore declare them private instead to disable dynamic alloc
1278  void* operator new(size_t size);
1279  void* operator new[](size_t size);
1280  void operator delete(void*, size_t);
1281  void operator delete[](void*, size_t);
1282 
1283  internal::Address* Escape(internal::Address* escape_value);
1284  internal::Address* escape_slot_;
1285 };
1286 
1293  public:
1294  explicit SealHandleScope(Isolate* isolate);
1296 
1298  void operator=(const SealHandleScope&) = delete;
1299 
1300  private:
1301  // Declaring operator new and delete as deleted is not spec compliant.
1302  // Therefore declare them private instead to disable dynamic alloc
1303  void* operator new(size_t size);
1304  void* operator new[](size_t size);
1305  void operator delete(void*, size_t);
1306  void operator delete[](void*, size_t);
1307 
1308  internal::Isolate* const isolate_;
1309  internal::Address* prev_limit_;
1310  int prev_sealed_level_;
1311 };
1312 
1313 // --- Special objects ---
1314 
1319  public:
1323  bool IsValue() const;
1324 
1328  bool IsModule() const;
1329 
1333  bool IsPrivate() const;
1334 
1338  bool IsObjectTemplate() const;
1339 
1343  bool IsFunctionTemplate() const;
1344 
1348  bool IsContext() const;
1349 
1350  private:
1351  Data();
1352 };
1353 
1361  public:
1367 
1373 };
1374 
1384  public:
1385  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1386  int Length() const;
1387  void Set(Isolate* isolate, int index, Local<Primitive> item);
1388  Local<Primitive> Get(Isolate* isolate, int index);
1389 };
1390 
1395  public:
1396  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1397  bool is_opaque = false, bool is_wasm = false,
1398  bool is_module = false)
1399  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1400  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1401  (is_module ? kIsModule : 0)) {}
1403  : flags_(flags &
1404  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1405 
1406  bool IsSharedCrossOrigin() const {
1407  return (flags_ & kIsSharedCrossOrigin) != 0;
1408  }
1409  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1410  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1411  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1412 
1413  int Flags() const { return flags_; }
1414 
1415  private:
1416  enum {
1417  kIsSharedCrossOrigin = 1,
1418  kIsOpaque = 1 << 1,
1419  kIsWasm = 1 << 2,
1420  kIsModule = 1 << 3
1421  };
1422  const int flags_;
1423 };
1424 
1429  public:
1430  V8_DEPRECATE_SOON("Use constructor with primitive C++ types")
1431  V8_INLINE explicit ScriptOrigin(
1432  Local<Value> resource_name, Local<Integer> resource_line_offset,
1433  Local<Integer> resource_column_offset,
1434  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1435  Local<Integer> script_id = Local<Integer>(),
1436  Local<Value> source_map_url = Local<Value>(),
1437  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1438  Local<Boolean> is_wasm = Local<Boolean>(),
1439  Local<Boolean> is_module = Local<Boolean>(),
1440  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1441  V8_DEPRECATE_SOON("Use constructor that takes an isolate")
1442  V8_INLINE explicit ScriptOrigin(
1443  Local<Value> resource_name, int resource_line_offset = 0,
1444  int resource_column_offset = 0,
1445  bool resource_is_shared_cross_origin = false, int script_id = -1,
1446  Local<Value> source_map_url = Local<Value>(),
1447  bool resource_is_opaque = false, bool is_wasm = false,
1448  bool is_module = false,
1449  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1450  V8_INLINE explicit ScriptOrigin(
1451  Isolate* isolate, Local<Value> resource_name,
1452  int resource_line_offset = 0, int resource_column_offset = 0,
1453  bool resource_is_shared_cross_origin = false, int script_id = -1,
1454  Local<Value> source_map_url = Local<Value>(),
1455  bool resource_is_opaque = false, bool is_wasm = false,
1456  bool is_module = false,
1457  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1458 
1460  V8_DEPRECATE_SOON("Use getter with primitvie C++ types.")
1462  V8_DEPRECATE_SOON("Use getter with primitvie C++ types.")
1464  V8_DEPRECATE_SOON("Use getter with primitvie C++ types.")
1466  V8_INLINE int LineOffset() const;
1467  V8_INLINE int ColumnOffset() const;
1468  V8_INLINE int ScriptId() const;
1471  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1472 
1473  private:
1474  Isolate* isolate_;
1475  Local<Value> resource_name_;
1476  int resource_line_offset_;
1477  int resource_column_offset_;
1478  ScriptOriginOptions options_;
1479  int script_id_;
1480  Local<Value> source_map_url_;
1481  Local<PrimitiveArray> host_defined_options_;
1482 };
1483 
1488  public:
1493 
1494  int GetId();
1496 
1505 
1510  int GetLineNumber(int code_pos);
1511 
1512  static const int kNoScriptId = 0;
1513 };
1514 
1519  // Only used as a container for code caching.
1520 };
1521 
1526  public:
1527  int GetLineNumber() { return line_number_; }
1528  int GetColumnNumber() { return column_number_; }
1529 
1530  Location(int line_number, int column_number)
1531  : line_number_(line_number), column_number_(column_number) {}
1532 
1533  private:
1534  int line_number_;
1535  int column_number_;
1536 };
1537 
1541 class V8_EXPORT FixedArray : public Data {
1542  public:
1543  int Length() const;
1544  Local<Data> Get(Local<Context> context, int i) const;
1545 };
1546 
1547 class V8_EXPORT ModuleRequest : public Data {
1548  public:
1553 
1558  int GetSourceOffset() const;
1559 
1575 
1576  V8_INLINE static ModuleRequest* Cast(Data* data);
1577 
1578  private:
1579  static void CheckCast(Data* obj);
1580 };
1581 
1585 class V8_EXPORT Module : public Data {
1586  public:
1594  enum Status {
1600  kErrored
1601  };
1602 
1607 
1612 
1616  V8_DEPRECATE_SOON("Use Module::GetModuleRequests() and FixedArray::Length().")
1617  int GetModuleRequestsLength() const;
1618 
1624  "Use Module::GetModuleRequests() and ModuleRequest::GetSpecifier().")
1625  Local<String> GetModuleRequest(int i) const;
1626 
1632  "Use Module::GetModuleRequests(), ModuleRequest::GetSourceOffset(), and "
1633  "Module::SourceOffsetToLocation().")
1634  Location GetModuleRequestLocation(int i) const;
1635 
1639  Local<FixedArray> GetModuleRequests() const;
1640 
1645  Location SourceOffsetToLocation(int offset) const;
1646 
1650  int GetIdentityHash() const;
1651 
1653  MaybeLocal<Module> (*)(Local<Context> context, Local<String> specifier,
1654  Local<Module> referrer);
1656  Local<Context> context, Local<String> specifier,
1657  Local<FixedArray> import_assertions, Local<Module> referrer);
1658 
1667  "Use the version of InstantiateModule that takes a ResolveModuleCallback "
1668  "parameter")
1669  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1670  ResolveCallback callback);
1671  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(
1672  Local<Context> context, ResolveModuleCallback callback);
1673 
1683 
1689  Local<Value> GetModuleNamespace();
1690 
1697  Local<UnboundModuleScript> GetUnboundModuleScript();
1698 
1704  int ScriptId();
1705 
1712  bool IsGraphAsync() const;
1713 
1717  bool IsSourceTextModule() const;
1718 
1722  bool IsSyntheticModule() const;
1723 
1724  /*
1725  * Callback defined in the embedder. This is responsible for setting
1726  * the module's exported values with calls to SetSyntheticModuleExport().
1727  * The callback must return a resolved Promise to indicate success (where no
1728  * exception was thrown) and return an empy MaybeLocal to indicate falure
1729  * (where an exception was thrown).
1730  */
1732  MaybeLocal<Value> (*)(Local<Context> context, Local<Module> module);
1733 
1741  static Local<Module> CreateSyntheticModule(
1742  Isolate* isolate, Local<String> module_name,
1743  const std::vector<Local<String>>& export_names,
1744  SyntheticModuleEvaluationSteps evaluation_steps);
1745 
1753  V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport(
1754  Isolate* isolate, Local<String> export_name, Local<Value> export_value);
1755  V8_DEPRECATED(
1756  "Use the preceding SetSyntheticModuleExport with an Isolate parameter, "
1757  "instead of the one that follows. The former will throw a runtime "
1758  "error if called for an export that doesn't exist (as per spec); "
1759  "the latter will crash with a failed CHECK().")
1760  void SetSyntheticModuleExport(Local<String> export_name,
1761  Local<Value> export_value);
1762 
1763  V8_INLINE static Module* Cast(Data* data);
1764 
1765  private:
1766  static void CheckCast(Data* obj);
1767 };
1768 
1774  public:
1779  Local<Context> context, Local<String> source,
1780  ScriptOrigin* origin = nullptr);
1781 
1788 
1793 };
1794 
1795 enum class ScriptType { kClassic, kModule };
1796 
1801  public:
1812  BufferOwned
1813  };
1814 
1816  : data(nullptr),
1817  length(0),
1818  rejected(false),
1819  buffer_policy(BufferNotOwned) {}
1820 
1821  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1822  // data and guarantees that it stays alive until the CachedData object is
1823  // destroyed. If the policy is BufferOwned, the given data will be deleted
1824  // (with delete[]) when the CachedData object is destroyed.
1825  CachedData(const uint8_t* data, int length,
1826  BufferPolicy buffer_policy = BufferNotOwned);
1828  // TODO(marja): Async compilation; add constructors which take a callback
1829  // which will be called when V8 no longer needs the data.
1830  const uint8_t* data;
1831  int length;
1832  bool rejected;
1834 
1835  // Prevent copying.
1836  CachedData(const CachedData&) = delete;
1837  CachedData& operator=(const CachedData&) = delete;
1838  };
1839 
1843  class Source {
1844  public:
1845  // Source takes ownership of CachedData.
1846  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1847  CachedData* cached_data = nullptr);
1848  V8_INLINE explicit Source(Local<String> source_string,
1849  CachedData* cached_data = nullptr);
1850  V8_INLINE ~Source();
1851 
1852  // Ownership of the CachedData or its buffers is *not* transferred to the
1853  // caller. The CachedData object is alive as long as the Source object is
1854  // alive.
1855  V8_INLINE const CachedData* GetCachedData() const;
1856 
1857  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1858 
1859  // Prevent copying.
1860  Source(const Source&) = delete;
1861  Source& operator=(const Source&) = delete;
1862 
1863  private:
1864  friend class ScriptCompiler;
1865 
1866  Local<String> source_string;
1867 
1868  // Origin information
1869  Local<Value> resource_name;
1870  int resource_line_offset;
1871  int resource_column_offset;
1872  ScriptOriginOptions resource_options;
1873  Local<Value> source_map_url;
1874  Local<PrimitiveArray> host_defined_options;
1875 
1876  // Cached data from previous compilation (if a kConsume*Cache flag is
1877  // set), or hold newly generated cache data (kProduce*Cache flags) are
1878  // set when calling a compile method.
1879  CachedData* cached_data;
1880  };
1881 
1887  public:
1888  virtual ~ExternalSourceStream() = default;
1889 
1911  virtual size_t GetMoreData(const uint8_t** src) = 0;
1912 
1923  virtual bool SetBookmark();
1924 
1928  virtual void ResetToBookmark();
1929  };
1930 
1938  public:
1939  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1940 
1941  V8_DEPRECATED(
1942  "This class takes ownership of source_stream, so use the constructor "
1943  "taking a unique_ptr to make these semantics clearer")
1944  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1945  StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream,
1946  Encoding encoding);
1948 
1949  internal::ScriptStreamingData* impl() const { return impl_.get(); }
1950 
1951  // Prevent copying.
1952  StreamedSource(const StreamedSource&) = delete;
1954 
1955  private:
1956  std::unique_ptr<internal::ScriptStreamingData> impl_;
1957  };
1958 
1964  public:
1965  void Run();
1966 
1967  private:
1968  friend class ScriptCompiler;
1969 
1970  explicit ScriptStreamingTask(internal::ScriptStreamingData* data)
1971  : data_(data) {}
1972 
1973  internal::ScriptStreamingData* data_;
1974  };
1975 
1977  kNoCompileOptions = 0,
1979  kEagerCompile
1980  };
1981 
1986  kNoCacheNoReason = 0,
2000  kNoCacheBecauseDeferredProduceCodeCache
2001  };
2002 
2017  Isolate* isolate, Source* source,
2018  CompileOptions options = kNoCompileOptions,
2019  NoCacheReason no_cache_reason = kNoCacheNoReason);
2020 
2033  Local<Context> context, Source* source,
2034  CompileOptions options = kNoCompileOptions,
2035  NoCacheReason no_cache_reason = kNoCacheNoReason);
2036 
2048  V8_DEPRECATED("Use ScriptCompiler::StartStreaming instead.")
2049  static ScriptStreamingTask* StartStreamingScript(
2050  Isolate* isolate, StreamedSource* source,
2051  CompileOptions options = kNoCompileOptions);
2052  static ScriptStreamingTask* StartStreaming(
2053  Isolate* isolate, StreamedSource* source,
2054  ScriptType type = ScriptType::kClassic);
2055 
2064  Local<Context> context, StreamedSource* source,
2065  Local<String> full_source_string, const ScriptOrigin& origin);
2066 
2085  static uint32_t CachedDataVersionTag();
2086 
2094  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
2095  Isolate* isolate, Source* source,
2096  CompileOptions options = kNoCompileOptions,
2097  NoCacheReason no_cache_reason = kNoCacheNoReason);
2098 
2106  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
2107  Local<Context> context, StreamedSource* v8_source,
2108  Local<String> full_source_string, const ScriptOrigin& origin);
2109 
2120  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
2121  Local<Context> context, Source* source, size_t arguments_count,
2122  Local<String> arguments[], size_t context_extension_count,
2123  Local<Object> context_extensions[],
2124  CompileOptions options = kNoCompileOptions,
2125  NoCacheReason no_cache_reason = kNoCacheNoReason,
2126  Local<ScriptOrModule>* script_or_module_out = nullptr);
2127 
2133  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
2134 
2140  static CachedData* CreateCodeCache(
2141  Local<UnboundModuleScript> unbound_module_script);
2142 
2149  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
2150 
2151  private:
2152  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
2153  Isolate* isolate, Source* source, CompileOptions options,
2154  NoCacheReason no_cache_reason);
2155 };
2156 
2157 
2162  public:
2164 
2169 
2171  Local<Context> context) const;
2172 
2178 
2184 
2191 
2196 
2201  int GetStartPosition() const;
2202 
2207  int GetEndPosition() const;
2208 
2214 
2218  int ErrorLevel() const;
2219 
2224  int GetStartColumn() const;
2226 
2231  int GetEndColumn() const;
2233 
2238  bool IsSharedCrossOrigin() const;
2239  bool IsOpaque() const;
2240 
2241  // TODO(1245381): Print to a string instead of on a FILE.
2242  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
2243 
2244  static const int kNoLineNumberInfo = 0;
2245  static const int kNoColumnInfo = 0;
2246  static const int kNoScriptIdInfo = 0;
2247  static const int kNoWasmFunctionIndexInfo = -1;
2248 };
2249 
2250 
2257  public:
2265  kLineNumber = 1,
2266  kColumnOffset = 1 << 1 | kLineNumber,
2267  kScriptName = 1 << 2,
2268  kFunctionName = 1 << 3,
2269  kIsEval = 1 << 4,
2270  kIsConstructor = 1 << 5,
2271  kScriptNameOrSourceURL = 1 << 6,
2272  kScriptId = 1 << 7,
2273  kExposeFramesAcrossSecurityOrigins = 1 << 8,
2274  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
2275  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
2276  };
2277 
2281  Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
2282 
2286  int GetFrameCount() const;
2287 
2296  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
2297 };
2298 
2299 
2304  public:
2311  int GetLineNumber() const;
2312 
2320  int GetColumn() const;
2321 
2328  int GetScriptId() const;
2329 
2335 
2343 
2348 
2353  bool IsEval() const;
2354 
2359  bool IsConstructor() const;
2360 
2364  bool IsWasm() const;
2365 
2369  bool IsUserJavaScript() const;
2370 };
2371 
2372 
2373 // A StateTag represents a possible state of the VM.
2374 enum StateTag {
2383  IDLE
2384 };
2385 
2386 // Holds the callee saved registers needed for the stack unwinder. It is the
2387 // empty struct if no registers are required. Implemented in
2388 // include/v8-unwinder-state.h.
2389 struct CalleeSavedRegisters;
2390 
2391 // A RegisterState represents the current state of registers used
2392 // by the sampling profiler API.
2398 
2399  void* pc; // Instruction pointer.
2400  void* sp; // Stack pointer.
2401  void* fp; // Frame pointer.
2402  void* lr; // Link register (or nullptr on platforms without a link register).
2403  // Callee saved registers (or null if no callee saved registers were stored)
2404  std::unique_ptr<CalleeSavedRegisters> callee_saved;
2405 };
2406 
2407 // The output structure filled up by GetStackSample API function.
2408 struct SampleInfo {
2409  size_t frames_count; // Number of frames collected.
2410  StateTag vm_state; // Current VM state.
2411  void* external_callback_entry; // External callback address if VM is
2412  // executing an external callback.
2413  void* top_context; // Incumbent native context address.
2414 };
2415 
2416 struct MemoryRange {
2417  const void* start = nullptr;
2418  size_t length_in_bytes = 0;
2419 };
2420 
2421 struct JSEntryStub {
2423 };
2424 
2429 };
2430 
2435  public:
2445  Local<Context> context, Local<String> json_string);
2446 
2455  Local<Context> context, Local<Value> json_object,
2456  Local<String> gap = Local<String>());
2457 };
2458 
2464  public:
2466  public:
2467  virtual ~Delegate() = default;
2468 
2474  virtual void ThrowDataCloneError(Local<String> message) = 0;
2475 
2482 
2494  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
2495 
2497  Isolate* isolate, Local<WasmModuleObject> module);
2509  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
2510  size_t* actual_size);
2511 
2517  virtual void FreeBufferMemory(void* buffer);
2518  };
2519 
2520  explicit ValueSerializer(Isolate* isolate);
2521  ValueSerializer(Isolate* isolate, Delegate* delegate);
2523 
2527  void WriteHeader();
2528 
2533  Local<Value> value);
2534 
2541  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
2542 
2548  void TransferArrayBuffer(uint32_t transfer_id,
2549  Local<ArrayBuffer> array_buffer);
2550 
2551 
2560 
2566  void WriteUint32(uint32_t value);
2567  void WriteUint64(uint64_t value);
2568  void WriteDouble(double value);
2569  void WriteRawBytes(const void* source, size_t length);
2570 
2572  void operator=(const ValueSerializer&) = delete;
2573 
2574  private:
2575  struct PrivateData;
2576  PrivateData* private_;
2577 };
2578 
2584  public:
2586  public:
2587  virtual ~Delegate() = default;
2588 
2595 
2601  Isolate* isolate, uint32_t transfer_id);
2602 
2608  Isolate* isolate, uint32_t clone_id);
2609  };
2610 
2611  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2612  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2613  Delegate* delegate);
2615 
2621 
2626 
2631  void TransferArrayBuffer(uint32_t transfer_id,
2632  Local<ArrayBuffer> array_buffer);
2633 
2639  void TransferSharedArrayBuffer(uint32_t id,
2640  Local<SharedArrayBuffer> shared_array_buffer);
2641 
2649  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2650 
2656  uint32_t GetWireFormatVersion() const;
2657 
2663  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2664  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2665  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2666  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2667 
2669  void operator=(const ValueDeserializer&) = delete;
2670 
2671  private:
2672  struct PrivateData;
2673  PrivateData* private_;
2674 };
2675 
2676 
2677 // --- Value ---
2678 
2679 
2683 class V8_EXPORT Value : public Data {
2684  public:
2691  V8_INLINE bool IsUndefined() const;
2692 
2699  V8_INLINE bool IsNull() const;
2700 
2708  V8_INLINE bool IsNullOrUndefined() const;
2709 
2717  bool IsTrue() const;
2718 
2726  bool IsFalse() const;
2727 
2734  bool IsName() const;
2735 
2742  V8_INLINE bool IsString() const;
2743 
2749  bool IsSymbol() const;
2750 
2756  bool IsFunction() const;
2757 
2762  bool IsArray() const;
2763 
2767  bool IsObject() const;
2768 
2774  bool IsBigInt() const;
2775 
2781  bool IsBoolean() const;
2782 
2788  bool IsNumber() const;
2789 
2793  bool IsExternal() const;
2794 
2798  bool IsInt32() const;
2799 
2803  bool IsUint32() const;
2804 
2808  bool IsDate() const;
2809 
2813  bool IsArgumentsObject() const;
2814 
2818  bool IsBigIntObject() const;
2819 
2823  bool IsBooleanObject() const;
2824 
2828  bool IsNumberObject() const;
2829 
2833  bool IsStringObject() const;
2834 
2838  bool IsSymbolObject() const;
2839 
2843  bool IsNativeError() const;
2844 
2848  bool IsRegExp() const;
2849 
2853  bool IsAsyncFunction() const;
2854 
2858  bool IsGeneratorFunction() const;
2859 
2863  bool IsGeneratorObject() const;
2864 
2868  bool IsPromise() const;
2869 
2873  bool IsMap() const;
2874 
2878  bool IsSet() const;
2879 
2883  bool IsMapIterator() const;
2884 
2888  bool IsSetIterator() const;
2889 
2893  bool IsWeakMap() const;
2894 
2898  bool IsWeakSet() const;
2899 
2903  bool IsArrayBuffer() const;
2904 
2908  bool IsArrayBufferView() const;
2909 
2913  bool IsTypedArray() const;
2914 
2918  bool IsUint8Array() const;
2919 
2923  bool IsUint8ClampedArray() const;
2924 
2928  bool IsInt8Array() const;
2929 
2933  bool IsUint16Array() const;
2934 
2938  bool IsInt16Array() const;
2939 
2943  bool IsUint32Array() const;
2944 
2948  bool IsInt32Array() const;
2949 
2953  bool IsFloat32Array() const;
2954 
2958  bool IsFloat64Array() const;
2959 
2963  bool IsBigInt64Array() const;
2964 
2968  bool IsBigUint64Array() const;
2969 
2973  bool IsDataView() const;
2974 
2978  bool IsSharedArrayBuffer() const;
2979 
2983  bool IsProxy() const;
2984 
2988  bool IsWasmMemoryObject() const;
2989 
2993  bool IsWasmModuleObject() const;
2994 
2999 
3004  Local<Context> context) const;
3009  Local<Context> context) const;
3014  Local<Context> context) const;
3021  Local<Context> context) const;
3026  Local<Context> context) const;
3033  Local<Context> context) const;
3040  Local<Context> context) const;
3047 
3052 
3058  Local<Context> context) const;
3059 
3061  bool BooleanValue(Isolate* isolate) const;
3062 
3067  Local<Context> context) const;
3070  Local<Context> context) const;
3073 
3076  Local<Value> that) const;
3077  bool StrictEquals(Local<Value> that) const;
3078  bool SameValue(Local<Value> that) const;
3079 
3080  template <class T> V8_INLINE static Value* Cast(T* value);
3081 
3083 
3085 
3086  private:
3087  V8_INLINE bool QuickIsUndefined() const;
3088  V8_INLINE bool QuickIsNull() const;
3089  V8_INLINE bool QuickIsNullOrUndefined() const;
3090  V8_INLINE bool QuickIsString() const;
3091  bool FullIsUndefined() const;
3092  bool FullIsNull() const;
3093  bool FullIsString() const;
3094 
3095  static void CheckCast(Data* that);
3096 };
3097 
3098 
3102 class V8_EXPORT Primitive : public Value { };
3103 
3104 
3109 class V8_EXPORT Boolean : public Primitive {
3110  public:
3111  bool Value() const;
3112  V8_INLINE static Boolean* Cast(v8::Data* data);
3113  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
3114 
3115  private:
3116  static void CheckCast(v8::Data* that);
3117 };
3118 
3119 
3123 class V8_EXPORT Name : public Primitive {
3124  public:
3133 
3134  V8_INLINE static Name* Cast(Data* data);
3135 
3136  private:
3137  static void CheckCast(Data* that);
3138 };
3139 
3146 enum class NewStringType {
3150  kNormal,
3151 
3158 };
3159 
3163 class V8_EXPORT String : public Name {
3164  public:
3165  static constexpr int kMaxLength =
3166  internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
3167 
3168  enum Encoding {
3169  UNKNOWN_ENCODING = 0x1,
3170  TWO_BYTE_ENCODING = 0x0,
3171  ONE_BYTE_ENCODING = 0x8
3172  };
3176  int Length() const;
3177 
3182  int Utf8Length(Isolate* isolate) const;
3183 
3190  bool IsOneByte() const;
3191 
3197  bool ContainsOnlyOneByte() const;
3198 
3225  NO_OPTIONS = 0,
3226  HINT_MANY_WRITES_EXPECTED = 1,
3227  NO_NULL_TERMINATION = 2,
3228  PRESERVE_ONE_BYTE_NULL = 4,
3229  // Used by WriteUtf8 to replace orphan surrogate code units with the
3230  // unicode replacement character. Needs to be set to guarantee valid UTF-8
3231  // output.
3232  REPLACE_INVALID_UTF8 = 8
3233  };
3234 
3235  // 16-bit character codes.
3236  int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
3237  int options = NO_OPTIONS) const;
3238  // One byte characters.
3239  int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
3240  int length = -1, int options = NO_OPTIONS) const;
3241  // UTF-8 encoded characters.
3242  int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
3243  int* nchars_ref = nullptr, int options = NO_OPTIONS) const;
3244 
3248  V8_INLINE static Local<String> Empty(Isolate* isolate);
3249 
3253  bool IsExternalTwoByte() const;
3254 
3258  bool IsExternalOneByte() const;
3259 
3261  public:
3262  virtual ~ExternalStringResourceBase() = default;
3263 
3269  virtual bool IsCacheable() const { return true; }
3270 
3271  // Disallow copying and assigning.
3273  void operator=(const ExternalStringResourceBase&) = delete;
3274 
3275  protected:
3277 
3284  virtual void Dispose() { delete this; }
3285 
3297  virtual void Lock() const {}
3298 
3302  virtual void Unlock() const {}
3303 
3304  private:
3305  friend class internal::ExternalString;
3306  friend class v8::String;
3307  friend class internal::ScopedExternalStringLock;
3308  };
3309 
3317  : public ExternalStringResourceBase {
3318  public:
3323  ~ExternalStringResource() override = default;
3324 
3328  virtual const uint16_t* data() const = 0;
3329 
3333  virtual size_t length() const = 0;
3334 
3335  protected:
3337  };
3338 
3350  : public ExternalStringResourceBase {
3351  public:
3356  ~ExternalOneByteStringResource() override = default;
3358  virtual const char* data() const = 0;
3360  virtual size_t length() const = 0;
3361  protected:
3363  };
3364 
3370  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
3371  Encoding* encoding_out) const;
3372 
3377  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
3378 
3384 
3385  V8_INLINE static String* Cast(v8::Data* data);
3386 
3396  template <int N>
3398  Isolate* isolate, const char (&literal)[N],
3400  static_assert(N <= kMaxLength, "String is too long");
3401  return NewFromUtf8Literal(isolate, literal, type, N - 1);
3402  }
3403 
3407  Isolate* isolate, const char* data,
3408  NewStringType type = NewStringType::kNormal, int length = -1);
3409 
3413  Isolate* isolate, const uint8_t* data,
3414  NewStringType type = NewStringType::kNormal, int length = -1);
3415 
3419  Isolate* isolate, const uint16_t* data,
3420  NewStringType type = NewStringType::kNormal, int length = -1);
3421 
3427  Local<String> right);
3428 
3438  Isolate* isolate, ExternalStringResource* resource);
3439 
3450 
3460  Isolate* isolate, ExternalOneByteStringResource* resource);
3461 
3472 
3477 
3482 
3491  public:
3494  char* operator*() { return str_; }
3495  const char* operator*() const { return str_; }
3496  int length() const { return length_; }
3497 
3498  // Disallow copying and assigning.
3499  Utf8Value(const Utf8Value&) = delete;
3500  void operator=(const Utf8Value&) = delete;
3501 
3502  private:
3503  char* str_;
3504  int length_;
3505  };
3506 
3514  public:
3517  uint16_t* operator*() { return str_; }
3518  const uint16_t* operator*() const { return str_; }
3519  int length() const { return length_; }
3520 
3521  // Disallow copying and assigning.
3522  Value(const Value&) = delete;
3523  void operator=(const Value&) = delete;
3524 
3525  private:
3526  uint16_t* str_;
3527  int length_;
3528  };
3529 
3530  private:
3531  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
3532  Encoding encoding) const;
3533  void VerifyExternalStringResource(ExternalStringResource* val) const;
3534  ExternalStringResource* GetExternalStringResourceSlow() const;
3535  ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
3536  String::Encoding* encoding_out) const;
3537 
3538  static Local<v8::String> NewFromUtf8Literal(Isolate* isolate,
3539  const char* literal,
3540  NewStringType type, int length);
3541 
3542  static void CheckCast(v8::Data* that);
3543 };
3544 
3545 // Zero-length string specialization (templated string size includes
3546 // terminator).
3547 template <>
3549  Isolate* isolate, const char (&literal)[1], NewStringType type) {
3550  return String::Empty(isolate);
3551 }
3552 
3556 class V8_EXPORT Symbol : public Name {
3557  public:
3562 
3563  V8_DEPRECATED("Use Symbol::Description()")
3564  Local<Value> Name() const { return Description(); }
3565 
3570  static Local<Symbol> New(Isolate* isolate,
3571  Local<String> description = Local<String>());
3572 
3581  static Local<Symbol> For(Isolate* isolate, Local<String> description);
3582 
3587  static Local<Symbol> ForApi(Isolate* isolate, Local<String> description);
3588 
3589  // Well-known symbols
3594  static Local<Symbol> GetMatch(Isolate* isolate);
3596  static Local<Symbol> GetSearch(Isolate* isolate);
3597  static Local<Symbol> GetSplit(Isolate* isolate);
3601 
3602  V8_INLINE static Symbol* Cast(Data* data);
3603 
3604  private:
3605  Symbol();
3606  static void CheckCast(Data* that);
3607 };
3608 
3609 
3615 class V8_EXPORT Private : public Data {
3616  public:
3621 
3625  static Local<Private> New(Isolate* isolate,
3626  Local<String> name = Local<String>());
3627 
3637  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3638 
3639  V8_INLINE static Private* Cast(Data* data);
3640 
3641  private:
3642  Private();
3643 
3644  static void CheckCast(Data* that);
3645 };
3646 
3647 
3651 class V8_EXPORT Number : public Primitive {
3652  public:
3653  double Value() const;
3654  static Local<Number> New(Isolate* isolate, double value);
3655  V8_INLINE static Number* Cast(v8::Data* data);
3656 
3657  private:
3658  Number();
3659  static void CheckCast(v8::Data* that);
3660 };
3661 
3662 
3666 class V8_EXPORT Integer : public Number {
3667  public:
3668  static Local<Integer> New(Isolate* isolate, int32_t value);
3669  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3670  int64_t Value() const;
3671  V8_INLINE static Integer* Cast(v8::Data* data);
3672 
3673  private:
3674  Integer();
3675  static void CheckCast(v8::Data* that);
3676 };
3677 
3678 
3682 class V8_EXPORT Int32 : public Integer {
3683  public:
3684  int32_t Value() const;
3685  V8_INLINE static Int32* Cast(v8::Data* data);
3686 
3687  private:
3688  Int32();
3689  static void CheckCast(v8::Data* that);
3690 };
3691 
3692 
3696 class V8_EXPORT Uint32 : public Integer {
3697  public:
3698  uint32_t Value() const;
3699  V8_INLINE static Uint32* Cast(v8::Data* data);
3700 
3701  private:
3702  Uint32();
3703  static void CheckCast(v8::Data* that);
3704 };
3705 
3709 class V8_EXPORT BigInt : public Primitive {
3710  public:
3711  static Local<BigInt> New(Isolate* isolate, int64_t value);
3712  static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3720  static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
3721  int word_count, const uint64_t* words);
3722 
3729  uint64_t Uint64Value(bool* lossless = nullptr) const;
3730 
3736  int64_t Int64Value(bool* lossless = nullptr) const;
3737 
3742  int WordCount() const;
3743 
3752  void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
3753 
3754  V8_INLINE static BigInt* Cast(v8::Data* data);
3755 
3756  private:
3757  BigInt();
3758  static void CheckCast(v8::Data* that);
3759 };
3760 
3766  None = 0,
3768  ReadOnly = 1 << 0,
3770  DontEnum = 1 << 1,
3772  DontDelete = 1 << 2
3773 };
3774 
3781  void (*)(Local<String> property, const PropertyCallbackInfo<Value>& info);
3783  void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
3784 
3785 using AccessorSetterCallback = void (*)(Local<String> property,
3786  Local<Value> value,
3787  const PropertyCallbackInfo<void>& info);
3789  void (*)(Local<Name> property, Local<Value> value,
3790  const PropertyCallbackInfo<void>& info);
3791 
3802  DEFAULT = 0,
3804  ALL_CAN_WRITE = 1 << 1,
3805  PROHIBITS_OVERWRITING = 1 << 2
3806 };
3807 
3817  SKIP_SYMBOLS = 16
3818 };
3819 
3830 enum class SideEffectType {
3834 };
3835 
3844 
3850 
3856 
3861 
3865 class V8_EXPORT Object : public Value {
3866  public:
3872  Local<Value> key, Local<Value> value);
3873 
3875  Local<Value> value);
3876 
3877  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3878  //
3879  // Defines a configurable, writable, enumerable property with the given value
3880  // on the object unless the property already exists and is not configurable
3881  // or the object is not extensible.
3882  //
3883  // Returns true on success.
3885  Local<Name> key,
3886  Local<Value> value);
3888  uint32_t index,
3889  Local<Value> value);
3890 
3891  // Implements DefineOwnProperty.
3892  //
3893  // In general, CreateDataProperty will be faster, however, does not allow
3894  // for specifying attributes.
3895  //
3896  // Returns true on success.
3898  Local<Context> context, Local<Name> key, Local<Value> value,
3899  PropertyAttribute attributes = None);
3900 
3901  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3902  //
3903  // The defineProperty function is used to add an own property or
3904  // update the attributes of an existing own property of an object.
3905  //
3906  // Both data and accessor descriptors can be used.
3907  //
3908  // In general, CreateDataProperty is faster, however, does not allow
3909  // for specifying attributes or an accessor descriptor.
3910  //
3911  // The PropertyDescriptor can change when redefining a property.
3912  //
3913  // Returns true on success.
3915  Local<Context> context, Local<Name> key,
3916  PropertyDescriptor& descriptor); // NOLINT(runtime/references)
3917 
3919  Local<Value> key);
3920 
3922  uint32_t index);
3923 
3930  Local<Context> context, Local<Value> key);
3931 
3936  Local<Context> context, Local<Name> key);
3937 
3954  Local<Value> key);
3955 
3957  Local<Value> key);
3958 
3960 
3962  uint32_t index);
3963 
3968  Local<Context> context, Local<Name> name,
3970  AccessorNameSetterCallback setter = nullptr,
3972  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3973  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3974  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3975 
3977  Local<Function> setter = Local<Function>(),
3978  PropertyAttribute attribute = None,
3979  AccessControl settings = DEFAULT);
3980 
3986  Local<Context> context, Local<Name> name,
3988  AccessorNameSetterCallback setter = nullptr,
3989  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
3990  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3991  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3992 
4002  Local<Context> context, Local<Name> name,
4004  PropertyAttribute attributes = None,
4005  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
4006  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
4007 
4016  Local<Value> value);
4019 
4027  Local<Context> context);
4029  Local<Context> context, KeyCollectionMode mode,
4030  PropertyFilter property_filter, IndexFilter index_filter,
4032 
4039  Local<Context> context);
4040 
4048  Local<Context> context, PropertyFilter filter,
4050 
4057 
4064  Local<Value> prototype);
4065 
4071 
4078  Local<Context> context);
4079 
4084 
4089 
4092 
4095  const PersistentBase<Object>& object) {
4096  return object.val_->InternalFieldCount();
4097  }
4098 
4101  const BasicTracedReference<Object>& object) {
4102  return object->InternalFieldCount();
4103  }
4104 
4106  V8_INLINE Local<Value> GetInternalField(int index);
4107 
4109  void SetInternalField(int index, Local<Value> value);
4110 
4116  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
4117 
4120  const PersistentBase<Object>& object, int index) {
4121  return object.val_->GetAlignedPointerFromInternalField(index);
4122  }
4123 
4126  const BasicTracedReference<Object>& object, int index) {
4127  return object->GetAlignedPointerFromInternalField(index);
4128  }
4129 
4135  void SetAlignedPointerInInternalField(int index, void* value);
4136  void SetAlignedPointerInInternalFields(int argc, int indices[],
4137  void* values[]);
4138 
4145  Local<Name> key);
4147  uint32_t index);
4162  Local<Name> key);
4164  Local<Context> context, uint32_t index);
4166  Local<Context> context, Local<Name> key);
4167 
4173  Local<Context> context, Local<Name> key);
4174 
4182  Local<Name> key);
4183 
4190  Local<Context> context, Local<Name> key);
4191 
4198  Local<Context> context, Local<Name> key);
4199 
4202 
4205 
4214 
4219  // TODO(dcarney): take an isolate and optionally bail out?
4221 
4226 
4229  const PersistentBase<Object>& object) {
4230  return object.val_->CreationContext();
4231  }
4232 
4238  bool IsCallable();
4239 
4244 
4253 
4260 
4266  Local<Value> recv,
4267  int argc,
4268  Local<Value> argv[]);
4269 
4276  Local<Context> context, int argc, Local<Value> argv[]);
4277 
4282 
4292  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
4293 
4294  static Local<Object> New(Isolate* isolate);
4295 
4304  static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null,
4305  Local<Name>* names, Local<Value>* values,
4306  size_t length);
4307 
4308  V8_INLINE static Object* Cast(Value* obj);
4309 
4318  bool IsCodeLike(Isolate* isolate);
4319 
4320  private:
4321  Object();
4322  static void CheckCast(Value* obj);
4323  Local<Value> SlowGetInternalField(int index);
4324  void* SlowGetAlignedPointerFromInternalField(int index);
4325 };
4326 
4327 
4331 class V8_EXPORT Array : public Object {
4332  public:
4333  uint32_t Length() const;
4334 
4339  static Local<Array> New(Isolate* isolate, int length = 0);
4340 
4345  static Local<Array> New(Isolate* isolate, Local<Value>* elements,
4346  size_t length);
4347  V8_INLINE static Array* Cast(Value* obj);
4348  private:
4349  Array();
4350  static void CheckCast(Value* obj);
4351 };
4352 
4353 
4357 class V8_EXPORT Map : public Object {
4358  public:
4359  size_t Size() const;
4360  void Clear();
4362  Local<Value> key);
4364  Local<Value> key,
4365  Local<Value> value);
4367  Local<Value> key);
4369  Local<Value> key);
4370 
4376 
4380  static Local<Map> New(Isolate* isolate);
4381 
4382  V8_INLINE static Map* Cast(Value* obj);
4383 
4384  private:
4385  Map();
4386  static void CheckCast(Value* obj);
4387 };
4388 
4389 
4393 class V8_EXPORT Set : public Object {
4394  public:
4395  size_t Size() const;
4396  void Clear();
4398  Local<Value> key);
4400  Local<Value> key);
4402  Local<Value> key);
4403 
4408 
4412  static Local<Set> New(Isolate* isolate);
4413 
4414  V8_INLINE static Set* Cast(Value* obj);
4415 
4416  private:
4417  Set();
4418  static void CheckCast(Value* obj);
4419 };
4420 
4421 
4422 template<typename T>
4424  public:
4425  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
4426  : value_(that.value_) {
4427  static_assert(std::is_base_of<T, S>::value, "type check");
4428  }
4429  // Local setters
4430  template <typename S>
4431  V8_INLINE void Set(const Global<S>& handle);
4432  template <typename S>
4433  V8_INLINE void Set(const BasicTracedReference<S>& handle);
4434  template <typename S>
4435  V8_INLINE void Set(const Local<S> handle);
4436  // Fast primitive setters
4437  V8_INLINE void Set(bool value);
4438  V8_INLINE void Set(double i);
4439  V8_INLINE void Set(int32_t i);
4440  V8_INLINE void Set(uint32_t i);
4441  // Fast JS primitive setters
4442  V8_INLINE void SetNull();
4443  V8_INLINE void SetUndefined();
4444  V8_INLINE void SetEmptyString();
4445  // Convenience getter for Isolate
4446  V8_INLINE Isolate* GetIsolate() const;
4447 
4448  // Pointer setter: Uncompilable to prevent inadvertent misuse.
4449  template <typename S>
4450  V8_INLINE void Set(S* whatever);
4451 
4452  // Getter. Creates a new Local<> so it comes with a certain performance
4453  // hit. If the ReturnValue was not yet set, this will return the undefined
4454  // value.
4455  V8_INLINE Local<Value> Get() const;
4456 
4457  private:
4458  template<class F> friend class ReturnValue;
4459  template<class F> friend class FunctionCallbackInfo;
4460  template<class F> friend class PropertyCallbackInfo;
4461  template <class F, class G, class H>
4463  V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
4464  V8_INLINE internal::Address GetDefaultValue();
4465  V8_INLINE explicit ReturnValue(internal::Address* slot);
4466  internal::Address* value_;
4467 };
4468 
4469 
4476 template<typename T>
4478  public:
4480  V8_INLINE int Length() const;
4485  V8_INLINE Local<Value> operator[](int i) const;
4487  V8_INLINE Local<Object> This() const;
4498  V8_INLINE Local<Object> Holder() const;
4500  V8_INLINE Local<Value> NewTarget() const;
4502  V8_INLINE bool IsConstructCall() const;
4504  V8_INLINE Local<Value> Data() const;
4506  V8_INLINE Isolate* GetIsolate() const;
4508  V8_INLINE ReturnValue<T> GetReturnValue() const;
4509  // This shouldn't be public, but the arm compiler needs it.
4510  static const int kArgsLength = 6;
4511 
4512  protected:
4513  friend class internal::FunctionCallbackArguments;
4515  friend class debug::ConsoleCallArguments;
4516  static const int kHolderIndex = 0;
4517  static const int kIsolateIndex = 1;
4518  static const int kReturnValueDefaultValueIndex = 2;
4519  static const int kReturnValueIndex = 3;
4520  static const int kDataIndex = 4;
4521  static const int kNewTargetIndex = 5;
4522 
4524  internal::Address* values, int length);
4527  int length_;
4528 };
4529 
4530 
4535 template<typename T>
4537  public:
4542 
4549 
4592 
4603 
4613 
4622 
4623  // This shouldn't be public, but the arm compiler needs it.
4624  static const int kArgsLength = 7;
4625 
4626  protected:
4627  friend class MacroAssembler;
4628  friend class internal::PropertyCallbackArguments;
4630  static const int kShouldThrowOnErrorIndex = 0;
4631  static const int kHolderIndex = 1;
4632  static const int kIsolateIndex = 2;
4633  static const int kReturnValueDefaultValueIndex = 3;
4634  static const int kReturnValueIndex = 4;
4635  static const int kDataIndex = 5;
4636  static const int kThisIndex = 6;
4637 
4640 };
4641 
4642 using FunctionCallback = void (*)(const FunctionCallbackInfo<Value>& info);
4643 
4645 
4649 class V8_EXPORT Function : public Object {
4650  public:
4656  Local<Context> context, FunctionCallback callback,
4657  Local<Value> data = Local<Value>(), int length = 0,
4659  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4660 
4662  Local<Context> context, int argc, Local<Value> argv[]) const;
4663 
4665  Local<Context> context) const {
4666  return NewInstance(context, 0, nullptr);
4667  }
4668 
4675  Local<Context> context, int argc, Local<Value> argv[],
4676  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4677 
4679  Local<Value> recv, int argc,
4680  Local<Value> argv[]);
4681 
4684 
4692 
4698 
4703  V8_DEPRECATED(
4704  "Use v8::Object::Get() instead to look up \"displayName\". "
4705  "V8 and DevTools no longer use \"displayName\" in stack "
4706  "traces, but the standard \"name\" property. "
4707  "See http://crbug.com/1177685.")
4708  Local<Value> GetDisplayName() const;
4709 
4714  int GetScriptLineNumber() const;
4719  int GetScriptColumnNumber() const;
4720 
4724  int ScriptId() const;
4725 
4730  Local<Value> GetBoundFunction() const;
4731 
4738  V8_WARN_UNUSED_RESULT MaybeLocal<String> FunctionProtoToString(
4739  Local<Context> context);
4740 
4741  ScriptOrigin GetScriptOrigin() const;
4742  V8_INLINE static Function* Cast(Value* obj);
4743  static const int kLineOffsetNotFound;
4744 
4745  private:
4746  Function();
4747  static void CheckCast(Value* obj);
4748 };
4749 
4750 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4751 // The number of required internal fields can be defined by embedder.
4752 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4753 #endif
4754 
4758 class V8_EXPORT Promise : public Object {
4759  public:
4764  enum PromiseState { kPending, kFulfilled, kRejected };
4765 
4766  class V8_EXPORT Resolver : public Object {
4767  public:
4772  Local<Context> context);
4773 
4778 
4784  Local<Value> value);
4785 
4787  Local<Value> value);
4788 
4789  V8_INLINE static Resolver* Cast(Value* obj);
4790 
4791  private:
4792  Resolver();
4793  static void CheckCast(Value* obj);
4794  };
4795 
4803  Local<Function> handler);
4804 
4806  Local<Function> handler);
4807 
4809  Local<Function> on_fulfilled,
4810  Local<Function> on_rejected);
4811 
4816  bool HasHandler();
4817 
4823 
4828 
4833 
4834  V8_INLINE static Promise* Cast(Value* obj);
4835 
4836  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4837 
4838  private:
4839  Promise();
4840  static void CheckCast(Value* obj);
4841 };
4842 
4872  public:
4873  // GenericDescriptor
4875 
4876  // DataDescriptor
4878 
4879  // DataDescriptor with writable property
4880  PropertyDescriptor(Local<Value> value, bool writable);
4881 
4882  // AccessorDescriptor
4884 
4886 
4888  bool has_value() const;
4889 
4891  bool has_get() const;
4893  bool has_set() const;
4894 
4895  void set_enumerable(bool enumerable);
4896  bool enumerable() const;
4897  bool has_enumerable() const;
4898 
4899  void set_configurable(bool configurable);
4900  bool configurable() const;
4901  bool has_configurable() const;
4902 
4903  bool writable() const;
4904  bool has_writable() const;
4905 
4906  struct PrivateData;
4907  PrivateData* get_private() const { return private_; }
4908 
4910  void operator=(const PropertyDescriptor&) = delete;
4911 
4912  private:
4913  PrivateData* private_;
4914 };
4915 
4920 class V8_EXPORT Proxy : public Object {
4921  public:
4924  bool IsRevoked();
4925  void Revoke();
4926 
4931  Local<Object> local_target,
4932  Local<Object> local_handler);
4933 
4934  V8_INLINE static Proxy* Cast(Value* obj);
4935 
4936  private:
4937  Proxy();
4938  static void CheckCast(Value* obj);
4939 };
4940 
4951 template <typename T>
4953  public:
4955  constexpr MemorySpan() = default;
4956 
4957  constexpr MemorySpan(T* data, size_t size) : data_(data), size_(size) {}
4958 
4960  constexpr T* data() const { return data_; }
4962  constexpr size_t size() const { return size_; }
4963 
4964  private:
4965  T* data_ = nullptr;
4966  size_t size_ = 0;
4967 };
4968 
4972 struct OwnedBuffer {
4973  std::unique_ptr<const uint8_t[]> buffer;
4974  size_t size = 0;
4975  OwnedBuffer(std::unique_ptr<const uint8_t[]> buffer, size_t size)
4976  : buffer(std::move(buffer)), size(size) {}
4977  OwnedBuffer() = default;
4978 };
4979 
4980 // Wrapper around a compiled WebAssembly module, which is potentially shared by
4981 // different WasmModuleObjects.
4983  public:
4989 
4994 
4995  const std::string& source_url() const { return source_url_; }
4996 
4997  private:
4998  friend class WasmModuleObject;
4999  friend class WasmStreaming;
5000 
5001  explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>,
5002  const char* source_url, size_t url_length);
5003 
5004  const std::shared_ptr<internal::wasm::NativeModule> native_module_;
5005  const std::string source_url_;
5006 };
5007 
5008 // An instance of WebAssembly.Memory.
5010  public:
5011  WasmMemoryObject() = delete;
5012 
5017 
5018  V8_INLINE static WasmMemoryObject* Cast(Value* obj);
5019 
5020  private:
5021  static void CheckCast(Value* object);
5022 };
5023 
5024 // An instance of WebAssembly.Module.
5026  public:
5027  WasmModuleObject() = delete;
5028 
5034  Isolate* isolate, const CompiledWasmModule&);
5035 
5041 
5042  V8_INLINE static WasmModuleObject* Cast(Value* obj);
5043 
5044  private:
5045  static void CheckCast(Value* obj);
5046 };
5047 
5055  public:
5056  class WasmStreamingImpl;
5057 
5061  class Client {
5062  public:
5063  virtual ~Client() = default;
5068  virtual void OnModuleCompiled(CompiledWasmModule compiled_module) = 0;
5069  };
5070 
5071  explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
5072 
5074 
5079  void OnBytesReceived(const uint8_t* bytes, size_t size);
5080 
5086  void Finish();
5087 
5093  void Abort(MaybeLocal<Value> exception);
5094 
5102  bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size);
5103 
5108  void SetClient(std::shared_ptr<Client> client);
5109 
5110  /*
5111  * Sets the UTF-8 encoded source URL for the {Script} object. This must be
5112  * called before {Finish}.
5113  */
5114  void SetUrl(const char* url, size_t length);
5115 
5121  static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
5122  Local<Value> value);
5123 
5124  private:
5125  std::unique_ptr<WasmStreamingImpl> impl_;
5126 };
5127 
5128 // TODO(mtrofin): when streaming compilation is done, we can rename this
5129 // to simply WasmModuleObjectBuilder
5131  public:
5136  void OnBytesReceived(const uint8_t*, size_t size);
5137  void Finish();
5143  void Abort(MaybeLocal<Value> exception);
5145 
5147 
5148  private:
5150  delete;
5152  default;
5154  const WasmModuleObjectBuilderStreaming&) = delete;
5156  WasmModuleObjectBuilderStreaming&&) = default;
5157  Isolate* isolate_ = nullptr;
5158 
5159 #if V8_CC_MSVC
5168 #else
5169  Persistent<Promise> promise_;
5170 #endif
5171  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
5172 };
5173 
5174 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
5175 // The number of required internal fields can be defined by embedder.
5176 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
5177 #endif
5178 
5179 
5181 
5196  public:
5198 
5204  void* Data() const;
5205 
5209  size_t ByteLength() const;
5210 
5215  bool IsShared() const;
5216 
5222  void operator delete(void* ptr) { ::operator delete(ptr); }
5223 
5229  static std::unique_ptr<BackingStore> Reallocate(
5230  v8::Isolate* isolate, std::unique_ptr<BackingStore> backing_store,
5231  size_t byte_length);
5232 
5238  using DeleterCallback = void (*)(void* data, size_t length,
5239  void* deleter_data);
5240 
5250  static void EmptyDeleter(void* data, size_t length, void* deleter_data);
5251 
5252  private:
5257  BackingStore();
5258 };
5259 
5260 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
5261 // Use v8::BackingStore::DeleterCallback instead.
5262 using BackingStoreDeleterCallback = void (*)(void* data, size_t length,
5263  void* deleter_data);
5264 
5265 #endif
5266 
5270 class V8_EXPORT ArrayBuffer : public Object {
5271  public:
5287  class V8_EXPORT Allocator { // NOLINT
5288  public:
5289  virtual ~Allocator() = default;
5290 
5295  virtual void* Allocate(size_t length) = 0;
5296 
5301  virtual void* AllocateUninitialized(size_t length) = 0;
5302 
5307  virtual void Free(void* data, size_t length) = 0;
5308 
5321  virtual void* Reallocate(void* data, size_t old_length, size_t new_length);
5322 
5328  enum class AllocationMode { kNormal, kReservation };
5329 
5337  };
5338 
5348  class V8_EXPORT Contents { // NOLINT
5349  public:
5350  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
5351 
5353  : data_(nullptr),
5354  byte_length_(0),
5355  allocation_base_(nullptr),
5356  allocation_length_(0),
5357  allocation_mode_(Allocator::AllocationMode::kNormal),
5358  deleter_(nullptr),
5359  deleter_data_(nullptr) {}
5360 
5361  void* AllocationBase() const { return allocation_base_; }
5362  size_t AllocationLength() const { return allocation_length_; }
5364  return allocation_mode_;
5365  }
5366 
5367  void* Data() const { return data_; }
5368  size_t ByteLength() const { return byte_length_; }
5369  DeleterCallback Deleter() const { return deleter_; }
5370  void* DeleterData() const { return deleter_data_; }
5371 
5372  private:
5373  Contents(void* data, size_t byte_length, void* allocation_base,
5374  size_t allocation_length,
5375  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
5376  void* deleter_data);
5377 
5378  void* data_;
5379  size_t byte_length_;
5380  void* allocation_base_;
5381  size_t allocation_length_;
5382  Allocator::AllocationMode allocation_mode_;
5383  DeleterCallback deleter_;
5384  void* deleter_data_;
5385 
5386  friend class ArrayBuffer;
5387  };
5388 
5389 
5393  size_t ByteLength() const;
5394 
5401  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
5402 
5412  V8_DEPRECATED(
5413  "Use the version that takes a BackingStore. "
5414  "See http://crbug.com/v8/9908.")
5415  static Local<ArrayBuffer> New(
5416  Isolate* isolate, void* data, size_t byte_length,
5417  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5418 
5431  static Local<ArrayBuffer> New(Isolate* isolate,
5432  std::shared_ptr<BackingStore> backing_store);
5433 
5443  static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
5444  size_t byte_length);
5453  static std::unique_ptr<BackingStore> NewBackingStore(
5454  void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
5455  void* deleter_data);
5456 
5461  V8_DEPRECATED(
5462  "With v8::BackingStore externalized ArrayBuffers are "
5463  "the same as ordinary ArrayBuffers. See http://crbug.com/v8/9908.")
5464  bool IsExternal() const;
5465 
5469  bool IsDetachable() const;
5470 
5477  void Detach();
5478 
5489  V8_DEPRECATED("Use GetBackingStore or Detach. See http://crbug.com/v8/9908.")
5490  Contents Externalize();
5491 
5499  V8_DEPRECATED("This will be removed together with IsExternal.")
5500  void Externalize(const std::shared_ptr<BackingStore>& backing_store);
5501 
5510  V8_DEPRECATED("Use GetBackingStore. See http://crbug.com/v8/9908.")
5511  Contents GetContents();
5512 
5521  std::shared_ptr<BackingStore> GetBackingStore();
5522 
5523  V8_INLINE static ArrayBuffer* Cast(Value* obj);
5524 
5525  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5526  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5527 
5528  private:
5529  ArrayBuffer();
5530  static void CheckCast(Value* obj);
5531  Contents GetContents(bool externalize);
5532 };
5533 
5534 
5535 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
5536 // The number of required internal fields can be defined by embedder.
5537 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
5538 #endif
5539 
5540 
5546  public:
5554  size_t ByteOffset();
5558  size_t ByteLength();
5559 
5569  size_t CopyContents(void* dest, size_t byte_length);
5570 
5575  bool HasBuffer() const;
5576 
5577  V8_INLINE static ArrayBufferView* Cast(Value* obj);
5578 
5579  static const int kInternalFieldCount =
5581  static const int kEmbedderFieldCount =
5583 
5584  private:
5585  ArrayBufferView();
5586  static void CheckCast(Value* obj);
5587 };
5588 
5589 
5595  public:
5596  /*
5597  * The largest typed array size that can be constructed using New.
5598  */
5599  static constexpr size_t kMaxLength =
5602  : static_cast<size_t>(uint64_t{1} << 32);
5603 
5608  size_t Length();
5609 
5610  V8_INLINE static TypedArray* Cast(Value* obj);
5611 
5612  private:
5613  TypedArray();
5614  static void CheckCast(Value* obj);
5615 };
5616 
5617 
5622  public:
5624  size_t byte_offset, size_t length);
5625  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5626  size_t byte_offset, size_t length);
5627  V8_INLINE static Uint8Array* Cast(Value* obj);
5628 
5629  private:
5630  Uint8Array();
5631  static void CheckCast(Value* obj);
5632 };
5633 
5634 
5639  public:
5641  size_t byte_offset, size_t length);
5643  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
5644  size_t length);
5645  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
5646 
5647  private:
5649  static void CheckCast(Value* obj);
5650 };
5651 
5656  public:
5658  size_t byte_offset, size_t length);
5659  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5660  size_t byte_offset, size_t length);
5661  V8_INLINE static Int8Array* Cast(Value* obj);
5662 
5663  private:
5664  Int8Array();
5665  static void CheckCast(Value* obj);
5666 };
5667 
5668 
5673  public:
5675  size_t byte_offset, size_t length);
5677  size_t byte_offset, size_t length);
5678  V8_INLINE static Uint16Array* Cast(Value* obj);
5679 
5680  private:
5681  Uint16Array();
5682  static void CheckCast(Value* obj);
5683 };
5684 
5685 
5690  public:
5692  size_t byte_offset, size_t length);
5693  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5694  size_t byte_offset, size_t length);
5695  V8_INLINE static Int16Array* Cast(Value* obj);
5696 
5697  private:
5698  Int16Array();
5699  static void CheckCast(Value* obj);
5700 };
5701 
5702 
5707  public:
5709  size_t byte_offset, size_t length);
5711  size_t byte_offset, size_t length);
5712  V8_INLINE static Uint32Array* Cast(Value* obj);
5713 
5714  private:
5715  Uint32Array();
5716  static void CheckCast(Value* obj);
5717 };
5718 
5719 
5724  public:
5726  size_t byte_offset, size_t length);
5727  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5728  size_t byte_offset, size_t length);
5729  V8_INLINE static Int32Array* Cast(Value* obj);
5730 
5731  private:
5732  Int32Array();
5733  static void CheckCast(Value* obj);
5734 };
5735 
5736 
5741  public:
5743  size_t byte_offset, size_t length);
5745  size_t byte_offset, size_t length);
5746  V8_INLINE static Float32Array* Cast(Value* obj);
5747 
5748  private:
5749  Float32Array();
5750  static void CheckCast(Value* obj);
5751 };
5752 
5753 
5758  public:
5760  size_t byte_offset, size_t length);
5762  size_t byte_offset, size_t length);
5763  V8_INLINE static Float64Array* Cast(Value* obj);
5764 
5765  private:
5766  Float64Array();
5767  static void CheckCast(Value* obj);
5768 };
5769 
5774  public:
5776  size_t byte_offset, size_t length);
5778  size_t byte_offset, size_t length);
5779  V8_INLINE static BigInt64Array* Cast(Value* obj);
5780 
5781  private:
5782  BigInt64Array();
5783  static void CheckCast(Value* obj);
5784 };
5785 
5790  public:
5792  size_t byte_offset, size_t length);
5794  size_t byte_offset, size_t length);
5795  V8_INLINE static BigUint64Array* Cast(Value* obj);
5796 
5797  private:
5798  BigUint64Array();
5799  static void CheckCast(Value* obj);
5800 };
5801 
5806  public:
5808  size_t byte_offset, size_t length);
5809  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
5810  size_t byte_offset, size_t length);
5811  V8_INLINE static DataView* Cast(Value* obj);
5812 
5813  private:
5814  DataView();
5815  static void CheckCast(Value* obj);
5816 };
5817 
5818 
5823  public:
5833  class V8_EXPORT Contents { // NOLINT
5834  public:
5836  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
5837 
5839  : data_(nullptr),
5840  byte_length_(0),
5841  allocation_base_(nullptr),
5842  allocation_length_(0),
5843  allocation_mode_(Allocator::AllocationMode::kNormal),
5844  deleter_(nullptr),
5845  deleter_data_(nullptr) {}
5846 
5847  void* AllocationBase() const { return allocation_base_; }
5848  size_t AllocationLength() const { return allocation_length_; }
5850  return allocation_mode_;
5851  }
5852 
5853  void* Data() const { return data_; }
5854  size_t ByteLength() const { return byte_length_; }
5855  DeleterCallback Deleter() const { return deleter_; }
5856  void* DeleterData() const { return deleter_data_; }
5857 
5858  private:
5859  Contents(void* data, size_t byte_length, void* allocation_base,
5860  size_t allocation_length,
5861  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
5862  void* deleter_data);
5863 
5864  void* data_;
5865  size_t byte_length_;
5866  void* allocation_base_;
5867  size_t allocation_length_;
5868  Allocator::AllocationMode allocation_mode_;
5869  DeleterCallback deleter_;
5870  void* deleter_data_;
5871 
5872  friend class SharedArrayBuffer;
5873  };
5874 
5878  size_t ByteLength() const;
5879 
5886  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
5887 
5894  V8_DEPRECATED(
5895  "Use the version that takes a BackingStore. "
5896  "See http://crbug.com/v8/9908.")
5898  Isolate* isolate, void* data, size_t byte_length,
5899  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5900 
5914  Isolate* isolate, std::shared_ptr<BackingStore> backing_store);
5915 
5925  static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
5926  size_t byte_length);
5935  static std::unique_ptr<BackingStore> NewBackingStore(
5936  void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
5937  void* deleter_data);
5938 
5943  V8_DEPRECATED(
5944  "Use the version that takes a BackingStore. "
5945  "See http://crbug.com/v8/9908.")
5947  Isolate* isolate, const SharedArrayBuffer::Contents&,
5948  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5949 
5954  V8_DEPRECATED(
5955  "With v8::BackingStore externalized SharedArrayBuffers are the same "
5956  "as ordinary SharedArrayBuffers. See http://crbug.com/v8/9908.")
5957  bool IsExternal() const;
5958 
5971  V8_DEPRECATED("Use GetBackingStore or Detach. See http://crbug.com/v8/9908.")
5972  Contents Externalize();
5973 
5981  V8_DEPRECATED("This will be removed together with IsExternal.")
5982  void Externalize(const std::shared_ptr<BackingStore>& backing_store);
5983 
5996  V8_DEPRECATED("Use GetBackingStore. See http://crbug.com/v8/9908.")
5997  Contents GetContents();
5998 
6007  std::shared_ptr<BackingStore> GetBackingStore();
6008 
6009  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
6010 
6011  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
6012 
6013  private:
6015  static void CheckCast(Value* obj);
6016  Contents GetContents(bool externalize);
6017 };
6018 
6019 
6023 class V8_EXPORT Date : public Object {
6024  public:
6026  double time);
6027 
6032  double ValueOf() const;
6033 
6034  V8_INLINE static Date* Cast(Value* obj);
6035 
6036  private:
6037  static void CheckCast(Value* obj);
6038 };
6039 
6040 
6045  public:
6046  static Local<Value> New(Isolate* isolate, double value);
6047 
6048  double ValueOf() const;
6049 
6050  V8_INLINE static NumberObject* Cast(Value* obj);
6051 
6052  private:
6053  static void CheckCast(Value* obj);
6054 };
6055 
6060  public:
6061  static Local<Value> New(Isolate* isolate, int64_t value);
6062 
6064 
6065  V8_INLINE static BigIntObject* Cast(Value* obj);
6066 
6067  private:
6068  static void CheckCast(Value* obj);
6069 };
6070 
6075  public:
6076  static Local<Value> New(Isolate* isolate, bool value);
6077 
6078  bool ValueOf() const;
6079 
6080  V8_INLINE static BooleanObject* Cast(Value* obj);
6081 
6082  private:
6083  static void CheckCast(Value* obj);
6084 };
6085 
6086 
6091  public:
6092  static Local<Value> New(Isolate* isolate, Local<String> value);
6093 
6095 
6096  V8_INLINE static StringObject* Cast(Value* obj);
6097 
6098  private:
6099  static void CheckCast(Value* obj);
6100 };
6101 
6102 
6107  public:
6108  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
6109 
6111 
6112  V8_INLINE static SymbolObject* Cast(Value* obj);
6113 
6114  private:
6115  static void CheckCast(Value* obj);
6116 };
6117 
6118 
6122 class V8_EXPORT RegExp : public Object {
6123  public:
6132  enum Flags {
6133  kNone = 0,
6134  kGlobal = 1 << 0,
6135  kIgnoreCase = 1 << 1,
6136  kMultiline = 1 << 2,
6137  kSticky = 1 << 3,
6138  kUnicode = 1 << 4,
6139  kDotAll = 1 << 5,
6140  kLinear = 1 << 6,
6141  kHasIndices = 1 << 7,
6142  };
6143 
6144  static constexpr int kFlagCount = 8;
6145 
6157  Local<String> pattern,
6158  Flags flags);
6159 
6166  Local<Context> context, Local<String> pattern, Flags flags,
6167  uint32_t backtrack_limit);
6168 
6181  Local<String> subject);
6182 
6188 
6192  Flags GetFlags() const;
6193 
6194  V8_INLINE static RegExp* Cast(Value* obj);
6195 
6196  private:
6197  static void CheckCast(Value* obj);
6198 };
6199 
6204 class V8_EXPORT External : public Value {
6205  public:
6206  static Local<External> New(Isolate* isolate, void* value);
6207  V8_INLINE static External* Cast(Value* obj);
6208  void* Value() const;
6209  private:
6210  static void CheckCast(v8::Value* obj);
6211 };
6212 
6213 #define V8_INTRINSICS_LIST(F) \
6214  F(ArrayProto_entries, array_entries_iterator) \
6215  F(ArrayProto_forEach, array_for_each_iterator) \
6216  F(ArrayProto_keys, array_keys_iterator) \
6217  F(ArrayProto_values, array_values_iterator) \
6218  F(AsyncIteratorPrototype, initial_async_iterator_prototype) \
6219  F(ErrorPrototype, initial_error_prototype) \
6220  F(IteratorPrototype, initial_iterator_prototype) \
6221  F(ObjProto_valueOf, object_value_of_function)
6222 
6224 #define V8_DECL_INTRINSIC(name, iname) k##name,
6226 #undef V8_DECL_INTRINSIC
6227 };
6228 
6229 
6230 // --- Templates ---
6231 
6232 
6236 class V8_EXPORT Template : public Data {
6237  public:
6243  void Set(Local<Name> name, Local<Data> value,
6244  PropertyAttribute attributes = None);
6245  void SetPrivate(Local<Private> name, Local<Data> value,
6246  PropertyAttribute attributes = None);
6247  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
6249  void SetAccessorProperty(
6250  Local<Name> name,
6253  PropertyAttribute attribute = None,
6254  AccessControl settings = DEFAULT);
6255 
6283  void SetNativeDataProperty(
6285  AccessorSetterCallback setter = nullptr,
6286  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
6288  AccessControl settings = DEFAULT,
6289  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6291  void SetNativeDataProperty(
6293  AccessorNameSetterCallback setter = nullptr,
6294  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
6296  AccessControl settings = DEFAULT,
6297  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6298  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6299 
6304  void SetLazyDataProperty(
6306  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
6307  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6308  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6309 
6314  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
6315  PropertyAttribute attribute = None);
6316 
6317  private:
6318  Template();
6320  friend class ObjectTemplate;
6321  friend class FunctionTemplate;
6322 };
6323 
6324 // TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
6325 // NamedPropertyFooCallback.
6326 
6364  void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
6365 
6388  void (*)(Local<Name> property, Local<Value> value,
6389  const PropertyCallbackInfo<Value>& info);
6390 
6413  void (*)(Local<Name> property, const PropertyCallbackInfo<Integer>& info);
6414 
6437  void (*)(Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
6438 
6446  void (*)(const PropertyCallbackInfo<Array>& info);
6447 
6469  void (*)(Local<Name> property, const PropertyDescriptor& desc,
6470  const PropertyCallbackInfo<Value>& info);
6471 
6492  void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
6493 
6498  void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
6499 
6504  void (*)(uint32_t index, Local<Value> value,
6505  const PropertyCallbackInfo<Value>& info);
6506 
6511  void (*)(uint32_t index, const PropertyCallbackInfo<Integer>& info);
6512 
6517  void (*)(uint32_t index, const PropertyCallbackInfo<Boolean>& info);
6518 
6526  void (*)(const PropertyCallbackInfo<Array>& info);
6527 
6532  void (*)(uint32_t index, const PropertyDescriptor& desc,
6533  const PropertyCallbackInfo<Value>& info);
6534 
6539  void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
6540 
6548  ACCESS_DELETE,
6550 };
6551 
6552 
6557 using AccessCheckCallback = bool (*)(Local<Context> accessing_context,
6558  Local<Object> accessed_object,
6559  Local<Value> data);
6560 
6668 class V8_EXPORT FunctionTemplate : public Template {
6669  public:
6671  static Local<FunctionTemplate> New(
6672  Isolate* isolate, FunctionCallback callback = nullptr,
6673  Local<Value> data = Local<Value>(),
6674  Local<Signature> signature = Local<Signature>(), int length = 0,
6677  const CFunction* c_function = nullptr);
6678 
6682  static Local<FunctionTemplate> NewWithCache(
6683  Isolate* isolate, FunctionCallback callback,
6684  Local<Private> cache_property, Local<Value> data = Local<Value>(),
6685  Local<Signature> signature = Local<Signature>(), int length = 0,
6686  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
6687 
6689  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
6690  Local<Context> context);
6691 
6699  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
6700 
6707  void SetCallHandler(
6708  FunctionCallback callback, Local<Value> data = Local<Value>(),
6710  const CFunction* c_function = nullptr);
6711 
6713  void SetLength(int length);
6714 
6716  Local<ObjectTemplate> InstanceTemplate();
6717 
6723  void Inherit(Local<FunctionTemplate> parent);
6724 
6729  Local<ObjectTemplate> PrototypeTemplate();
6730 
6737  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
6738 
6744  void SetClassName(Local<String> name);
6745 
6746 
6751  void SetAcceptAnyReceiver(bool value);
6752 
6757  void ReadOnlyPrototype();
6758 
6763  void RemovePrototype();
6764 
6769  bool HasInstance(Local<Value> object);
6770 
6771  V8_INLINE static FunctionTemplate* Cast(Data* data);
6772 
6773  private:
6774  FunctionTemplate();
6775 
6776  static void CheckCast(Data* that);
6777  friend class Context;
6778  friend class ObjectTemplate;
6779 };
6780 
6785 enum class PropertyHandlerFlags {
6789  kNone = 0,
6790 
6794  kAllCanRead = 1,
6795 
6800  kNonMasking = 1 << 1,
6801 
6806  kOnlyInterceptStrings = 1 << 2,
6807 
6811  kHasNoSideEffect = 1 << 3,
6812 };
6823  Local<Value> data = Local<Value>(),
6825  : getter(getter),
6826  setter(setter),
6827  query(query),
6828  deleter(deleter),
6829  enumerator(enumerator),
6830  definer(definer),
6831  descriptor(descriptor),
6832  data(data),
6833  flags(flags) {}
6837  GenericNamedPropertyGetterCallback getter = nullptr,
6838  GenericNamedPropertySetterCallback setter = nullptr,
6839  GenericNamedPropertyQueryCallback query = nullptr,
6840  GenericNamedPropertyDeleterCallback deleter = nullptr,
6841  GenericNamedPropertyEnumeratorCallback enumerator = nullptr,
6842  Local<Value> data = Local<Value>(),
6844  : getter(getter),
6845  setter(setter),
6846  query(query),
6847  deleter(deleter),
6848  enumerator(enumerator),
6849  definer(nullptr),
6850  descriptor(nullptr),
6851  data(data),
6852  flags(flags) {}
6861  Local<Value> data = Local<Value>(),
6863  : getter(getter),
6864  setter(setter),
6865  query(nullptr),
6866  deleter(deleter),
6867  enumerator(enumerator),
6868  definer(definer),
6869  descriptor(descriptor),
6870  data(data),
6871  flags(flags) {}
6881  PropertyHandlerFlags flags;
6882 };
6883 
6893  Local<Value> data = Local<Value>(),
6895  : getter(getter),
6896  setter(setter),
6897  query(query),
6898  deleter(deleter),
6899  enumerator(enumerator),
6900  definer(definer),
6901  descriptor(descriptor),
6902  data(data),
6903  flags(flags) {}
6907  IndexedPropertyGetterCallback getter = nullptr,
6908  IndexedPropertySetterCallback setter = nullptr,
6909  IndexedPropertyQueryCallback query = nullptr,
6910  IndexedPropertyDeleterCallback deleter = nullptr,
6911  IndexedPropertyEnumeratorCallback enumerator = nullptr,
6912  Local<Value> data = Local<Value>(),
6914  : getter(getter),
6915  setter(setter),
6916  query(query),
6917  deleter(deleter),
6918  enumerator(enumerator),
6919  definer(nullptr),
6920  descriptor(nullptr),
6921  data(data),
6922  flags(flags) {}
6931  Local<Value> data = Local<Value>(),
6933  : getter(getter),
6934  setter(setter),
6935  query(nullptr),
6936  deleter(deleter),
6937  enumerator(enumerator),
6938  definer(definer),
6939  descriptor(descriptor),
6940  data(data),
6941  flags(flags) {}
6951  PropertyHandlerFlags flags;
6952 };
6953 
6954 
6961 class V8_EXPORT ObjectTemplate : public Template {
6962  public:
6964  static Local<ObjectTemplate> New(
6965  Isolate* isolate,
6967 
6970 
7000  void SetAccessor(
7002  AccessorSetterCallback setter = nullptr,
7003  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
7004  PropertyAttribute attribute = None,
7006  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
7008  void SetAccessor(
7010  AccessorNameSetterCallback setter = nullptr,
7011  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
7012  PropertyAttribute attribute = None,
7014  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
7015  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
7016 
7028  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
7029 
7046  // TODO(dcarney): deprecate
7047  void SetIndexedPropertyHandler(
7049  IndexedPropertySetterCallback setter = nullptr,
7050  IndexedPropertyQueryCallback query = nullptr,
7051  IndexedPropertyDeleterCallback deleter = nullptr,
7052  IndexedPropertyEnumeratorCallback enumerator = nullptr,
7053  Local<Value> data = Local<Value>()) {
7054  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
7055  deleter, enumerator, data));
7056  }
7057 
7068  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
7069 
7076  void SetCallAsFunctionHandler(FunctionCallback callback,
7077  Local<Value> data = Local<Value>());
7078 
7087  void MarkAsUndetectable();
7088 
7097  void SetAccessCheckCallback(AccessCheckCallback callback,
7098  Local<Value> data = Local<Value>());
7099 
7106  void SetAccessCheckCallbackAndHandler(
7107  AccessCheckCallback callback,
7108  const NamedPropertyHandlerConfiguration& named_handler,
7109  const IndexedPropertyHandlerConfiguration& indexed_handler,
7110  Local<Value> data = Local<Value>());
7111 
7116  int InternalFieldCount();
7117 
7122  void SetInternalFieldCount(int value);
7123 
7127  bool IsImmutableProto();
7128 
7133  void SetImmutableProto();
7134 
7144  void SetCodeLike();
7145  bool IsCodeLike();
7146 
7147  V8_INLINE static ObjectTemplate* Cast(Data* data);
7148 
7149  private:
7150  ObjectTemplate();
7151  static Local<ObjectTemplate> New(internal::Isolate* isolate,
7152  Local<FunctionTemplate> constructor);
7153  static void CheckCast(Data* that);
7154  friend class FunctionTemplate;
7155 };
7156 
7165 class V8_EXPORT Signature : public Data {
7166  public:
7167  static Local<Signature> New(
7168  Isolate* isolate,
7170 
7171  V8_INLINE static Signature* Cast(Data* data);
7172 
7173  private:
7174  Signature();
7175 
7176  static void CheckCast(Data* that);
7177 };
7178 
7179 
7184 class V8_EXPORT AccessorSignature : public Data {
7185  public:
7186  static Local<AccessorSignature> New(
7187  Isolate* isolate,
7189 
7190  V8_INLINE static AccessorSignature* Cast(Data* data);
7191 
7192  private:
7194 
7195  static void CheckCast(Data* that);
7196 };
7197 
7198 
7199 // --- Extensions ---
7200 
7204 class V8_EXPORT Extension { // NOLINT
7205  public:
7206  // Note that the strings passed into this constructor must live as long
7207  // as the Extension itself.
7208  Extension(const char* name, const char* source = nullptr, int dep_count = 0,
7209  const char** deps = nullptr, int source_length = -1);
7210  virtual ~Extension() { delete source_; }
7211  virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
7212  Isolate* isolate, Local<String> name) {
7213  return Local<FunctionTemplate>();
7214  }
7216  const char* name() const { return name_; }
7217  size_t source_length() const { return source_length_; }
7218  const String::ExternalOneByteStringResource* source() const {
7219  return source_;
7220  }
7221  int dependency_count() const { return dep_count_; }
7222  const char** dependencies() const { return deps_; }
7223  void set_auto_enable(bool value) { auto_enable_ = value; }
7224  bool auto_enable() { return auto_enable_; }
7225 
7226  // Disallow copying and assigning.
7227  Extension(const Extension&) = delete;
7228  void operator=(const Extension&) = delete;
7229 
7230  private:
7231  const char* name_;
7232  size_t source_length_; // expected to initialize before source_
7234  int dep_count_;
7235  const char** deps_;
7236  bool auto_enable_;
7237 };
7239 void V8_EXPORT RegisterExtension(std::unique_ptr<Extension>);
7240 
7241 // --- Statics ---
7242 
7247 
7263  public:
7282  void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
7283  size_t maximum_heap_size_in_bytes);
7284 
7294  void ConfigureDefaults(uint64_t physical_memory,
7295  uint64_t virtual_memory_limit);
7296 
7300  uint32_t* stack_limit() const { return stack_limit_; }
7301  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
7302 
7307  size_t code_range_size_in_bytes() const { return code_range_size_; }
7308  void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
7309 
7317  size_t max_old_generation_size_in_bytes() const {
7318  return max_old_generation_size_;
7319  }
7320  void set_max_old_generation_size_in_bytes(size_t limit) {
7321  max_old_generation_size_ = limit;
7322  }
7323 
7329  size_t max_young_generation_size_in_bytes() const {
7330  return max_young_generation_size_;
7331  }
7332  void set_max_young_generation_size_in_bytes(size_t limit) {
7333  max_young_generation_size_ = limit;
7334  }
7336  size_t initial_old_generation_size_in_bytes() const {
7337  return initial_old_generation_size_;
7338  }
7339  void set_initial_old_generation_size_in_bytes(size_t initial_size) {
7340  initial_old_generation_size_ = initial_size;
7341  }
7343  size_t initial_young_generation_size_in_bytes() const {
7344  return initial_young_generation_size_;
7345  }
7346  void set_initial_young_generation_size_in_bytes(size_t initial_size) {
7347  initial_young_generation_size_ = initial_size;
7348  }
7349 
7350  private:
7351  static constexpr size_t kMB = 1048576u;
7352  size_t code_range_size_ = 0;
7353  size_t max_old_generation_size_ = 0;
7354  size_t max_young_generation_size_ = 0;
7355  size_t initial_old_generation_size_ = 0;
7356  size_t initial_young_generation_size_ = 0;
7357  uint32_t* stack_limit_ = nullptr;
7358 };
7359 
7360 
7361 // --- Exceptions ---
7363 using FatalErrorCallback = void (*)(const char* location, const char* message);
7365 using OOMErrorCallback = void (*)(const char* location, bool is_heap_oom);
7367 using DcheckErrorCallback = void (*)(const char* file, int line,
7368  const char* message);
7370 using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
7371 
7372 // --- Tracing ---
7374 using LogEventCallback = void (*)(const char* name, int event);
7375 
7380 class V8_EXPORT Exception {
7381  public:
7382  static Local<Value> RangeError(Local<String> message);
7383  static Local<Value> ReferenceError(Local<String> message);
7384  static Local<Value> SyntaxError(Local<String> message);
7385  static Local<Value> TypeError(Local<String> message);
7386  static Local<Value> WasmCompileError(Local<String> message);
7387  static Local<Value> WasmLinkError(Local<String> message);
7388  static Local<Value> WasmRuntimeError(Local<String> message);
7389  static Local<Value> Error(Local<String> message);
7390 
7396  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
7397 
7402  static Local<StackTrace> GetStackTrace(Local<Value> exception);
7403 };
7404 
7405 
7406 // --- Counters Callbacks ---
7408 using CounterLookupCallback = int* (*)(const char* name);
7410 using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
7411  size_t buckets);
7413 using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
7414 
7415 // --- Crashkeys Callback ---
7416 enum class CrashKeyId {
7421  kDumpType,
7422 };
7424 using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
7425 
7426 // --- Enter/Leave Script Callback ---
7428 using CallCompletedCallback = void (*)(Isolate*);
7429 
7451  "Use HostImportModuleDynamicallyWithImportAssertionsCallback instead") =
7452  MaybeLocal<Promise> (*)(Local<Context> context,
7453  Local<ScriptOrModule> referrer,
7454  Local<String> specifier);
7455 
7483  MaybeLocal<Promise> (*)(Local<Context> context,
7484  Local<ScriptOrModule> referrer,
7485  Local<String> specifier,
7486  Local<FixedArray> import_assertions);
7487 
7499  Local<Module> module,
7500  Local<Object> meta);
7501 
7510  Local<Value> error,
7511  Local<Array> sites);
7512 
7529 enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
7531 using PromiseHook = void (*)(PromiseHookType type, Local<Promise> promise,
7532  Local<Value> parent);
7533 
7534 // --- Promise Reject Callback ---
7540 };
7542 class PromiseRejectMessage {
7543  public:
7545  Local<Value> value)
7546  : promise_(promise), event_(event), value_(value) {}
7548  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
7549  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
7550  V8_INLINE Local<Value> GetValue() const { return value_; }
7551 
7552  private:
7553  Local<Promise> promise_;
7554  PromiseRejectEvent event_;
7555  Local<Value> value_;
7556 };
7558 using PromiseRejectCallback = void (*)(PromiseRejectMessage message);
7559 
7560 // --- Microtasks Callbacks ---
7562 using MicrotaskCallback = void (*)(void* data);
7563 
7572 enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
7573 
7589 class V8_EXPORT MicrotaskQueue {
7590  public:
7594  static std::unique_ptr<MicrotaskQueue> New(
7595  Isolate* isolate, MicrotasksPolicy policy = MicrotasksPolicy::kAuto);
7597  virtual ~MicrotaskQueue() = default;
7598 
7602  virtual void EnqueueMicrotask(Isolate* isolate,
7603  Local<Function> microtask) = 0;
7604 
7608  virtual void EnqueueMicrotask(v8::Isolate* isolate,
7609  MicrotaskCallback callback,
7610  void* data = nullptr) = 0;
7611 
7624  virtual void AddMicrotasksCompletedCallback(
7625  MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
7626 
7630  virtual void RemoveMicrotasksCompletedCallback(
7631  MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
7632 
7636  virtual void PerformCheckpoint(Isolate* isolate) = 0;
7637 
7641  virtual bool IsRunningMicrotasks() const = 0;
7642 
7647  virtual int GetMicrotasksScopeDepth() const = 0;
7649  MicrotaskQueue(const MicrotaskQueue&) = delete;
7650  MicrotaskQueue& operator=(const MicrotaskQueue&) = delete;
7651 
7652  private:
7653  friend class internal::MicrotaskQueue;
7654  MicrotaskQueue() = default;
7655 };
7656 
7667  public:
7668  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
7670  MicrotasksScope(Isolate* isolate, Type type);
7671  MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
7672  ~MicrotasksScope();
7673 
7677  static void PerformCheckpoint(Isolate* isolate);
7678 
7682  static int GetCurrentDepth(Isolate* isolate);
7683 
7687  static bool IsRunningMicrotasks(Isolate* isolate);
7688 
7689  // Prevent copying.
7691  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
7692 
7693  private:
7694  internal::Isolate* const isolate_;
7695  internal::MicrotaskQueue* const microtask_queue_;
7696  bool run_;
7697 };
7698 
7699 // --- Failed Access Check Callback ---
7700 using FailedAccessCheckCallback = void (*)(Local<Object> target,
7701  AccessType type, Local<Value> data);
7702 
7703 // --- AllowCodeGenerationFromStrings callbacks ---
7704 
7710  Local<String> source);
7713  // If true, proceed with the codegen algorithm. Otherwise, block it.
7714  bool codegen_allowed = false;
7715  // Overwrite the original source with this string, if present.
7716  // Use the original source if empty.
7717  // This field is considered only if codegen_allowed is true.
7718  MaybeLocal<String> modified_source;
7719 };
7720 
7727  Local<Value> source);
7730  Local<Value> source,
7731  bool is_code_like);
7732 
7733 // --- WebAssembly compilation callbacks ---
7734 using ExtensionCallback = bool (*)(const FunctionCallbackInfo<Value>&);
7736 using AllowWasmCodeGenerationCallback = bool (*)(Local<Context> context,
7737  Local<String> source);
7738 
7739 // --- Callback for APIs defined on v8-supported objects, but implemented
7740 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
7742 
7743 // --- Callback for WebAssembly.compileStreaming ---
7744 using WasmStreamingCallback = void (*)(const FunctionCallbackInfo<Value>&);
7745 
7746 // --- Callback for checking if WebAssembly threads are enabled ---
7747 using WasmThreadsEnabledCallback = bool (*)(Local<Context> context);
7748 
7749 // --- Callback for loading source map file for Wasm profiling support
7750 using WasmLoadSourceMapCallback = Local<String> (*)(Isolate* isolate,
7751  const char* name);
7752 
7753 // --- Callback for checking if WebAssembly Simd is enabled ---
7754 using WasmSimdEnabledCallback = bool (*)(Local<Context> context);
7755 
7756 // --- Callback for checking if WebAssembly exceptions are enabled ---
7757 using WasmExceptionsEnabledCallback = bool (*)(Local<Context> context);
7758 
7759 // --- Garbage Collection Callbacks ---
7760 
7768 enum GCType {
7772  kGCTypeProcessWeakCallbacks = 1 << 3,
7775 };
7776 
7799 };
7801 using GCCallback = void (*)(GCType type, GCCallbackFlags flags);
7803 using InterruptCallback = void (*)(Isolate* isolate, void* data);
7804 
7812 using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
7813  size_t initial_heap_limit);
7814 
7822  public:
7824  size_t read_only_space_size() { return read_only_space_size_; }
7825  size_t read_only_space_used_size() { return read_only_space_used_size_; }
7826  size_t read_only_space_physical_size() {
7827  return read_only_space_physical_size_;
7828  }
7829 
7830  private:
7831  size_t read_only_space_size_;
7832  size_t read_only_space_used_size_;
7833  size_t read_only_space_physical_size_;
7835  friend class V8;
7836  friend class internal::ReadOnlyHeap;
7837 };
7838 
7845 class V8_EXPORT HeapStatistics {
7846  public:
7848  size_t total_heap_size() { return total_heap_size_; }
7849  size_t total_heap_size_executable() { return total_heap_size_executable_; }
7850  size_t total_physical_size() { return total_physical_size_; }
7851  size_t total_available_size() { return total_available_size_; }
7852  size_t total_global_handles_size() { return total_global_handles_size_; }
7853  size_t used_global_handles_size() { return used_global_handles_size_; }
7854  size_t used_heap_size() { return used_heap_size_; }
7855  size_t heap_size_limit() { return heap_size_limit_; }
7856  size_t malloced_memory() { return malloced_memory_; }
7857  size_t external_memory() { return external_memory_; }
7858  size_t peak_malloced_memory() { return peak_malloced_memory_; }
7859  size_t number_of_native_contexts() { return number_of_native_contexts_; }
7860  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
7861 
7866  size_t does_zap_garbage() { return does_zap_garbage_; }
7867 
7868  private:
7869  size_t total_heap_size_;
7870  size_t total_heap_size_executable_;
7871  size_t total_physical_size_;
7872  size_t total_available_size_;
7873  size_t used_heap_size_;
7874  size_t heap_size_limit_;
7875  size_t malloced_memory_;
7876  size_t external_memory_;
7877  size_t peak_malloced_memory_;
7878  bool does_zap_garbage_;
7879  size_t number_of_native_contexts_;
7880  size_t number_of_detached_contexts_;
7881  size_t total_global_handles_size_;
7882  size_t used_global_handles_size_;
7884  friend class V8;
7885  friend class Isolate;
7886 };
7887 
7890  public:
7892  const char* space_name() { return space_name_; }
7893  size_t space_size() { return space_size_; }
7894  size_t space_used_size() { return space_used_size_; }
7895  size_t space_available_size() { return space_available_size_; }
7896  size_t physical_space_size() { return physical_space_size_; }
7897 
7898  private:
7899  const char* space_name_;
7900  size_t space_size_;
7901  size_t space_used_size_;
7902  size_t space_available_size_;
7903  size_t physical_space_size_;
7905  friend class Isolate;
7906 };
7907 
7910  public:
7912  const char* object_type() { return object_type_; }
7913  const char* object_sub_type() { return object_sub_type_; }
7914  size_t object_count() { return object_count_; }
7915  size_t object_size() { return object_size_; }
7916 
7917  private:
7918  const char* object_type_;
7919  const char* object_sub_type_;
7920  size_t object_count_;
7921  size_t object_size_;
7923  friend class Isolate;
7924 };
7927  public:
7929  size_t code_and_metadata_size() { return code_and_metadata_size_; }
7930  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
7931  size_t external_script_source_size() { return external_script_source_size_; }
7932 
7933  private:
7934  size_t code_and_metadata_size_;
7935  size_t bytecode_and_metadata_size_;
7936  size_t external_script_source_size_;
7938  friend class Isolate;
7939 };
7940 
7947  enum EventType {
7948  CODE_ADDED,
7949  CODE_MOVED,
7950  CODE_REMOVED,
7951  CODE_ADD_LINE_POS_INFO,
7952  CODE_START_LINE_INFO_RECORDING,
7953  CODE_END_LINE_INFO_RECORDING
7954  };
7955  // Definition of the code position type. The "POSITION" type means the place
7956  // in the source code which are of interest when making stack traces to
7957  // pin-point the source location of a stack frame as close as possible.
7958  // The "STATEMENT_POSITION" means the place at the beginning of each
7959  // statement, and is used to indicate possible break locations.
7960  enum PositionType { POSITION, STATEMENT_POSITION };
7961 
7962  // There are two different kinds of JitCodeEvents, one for JIT code generated
7963  // by the optimizing compiler, and one for byte code generated for the
7964  // interpreter. For JIT_CODE events, the |code_start| member of the event
7965  // points to the beginning of jitted assembly code, while for BYTE_CODE
7966  // events, |code_start| points to the first bytecode of the interpreted
7967  // function.
7968  enum CodeType { BYTE_CODE, JIT_CODE };
7969 
7970  // Type of event.
7972  CodeType code_type;
7973  // Start of the instructions.
7974  void* code_start;
7975  // Size of the instructions.
7976  size_t code_len;
7977  // Script info for CODE_ADDED event.
7978  Local<UnboundScript> script;
7979  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
7980  // code line information which is returned from the
7981  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
7982  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
7983  void* user_data;
7985  struct name_t {
7986  // Name of the object associated with the code, note that the string is not
7987  // zero-terminated.
7988  const char* str;
7989  // Number of chars in str.
7990  size_t len;
7991  };
7993  struct line_info_t {
7994  // PC offset
7995  size_t offset;
7996  // Code position
7997  size_t pos;
7998  // The position type.
7999  PositionType position_type;
8000  };
8002  struct wasm_source_info_t {
8003  // Source file name.
8004  const char* filename;
8005  // Length of filename.
8006  size_t filename_size;
8007  // Line number table, which maps offsets of JITted code to line numbers of
8008  // source file.
8009  const line_info_t* line_number_table;
8010  // Number of entries in the line number table.
8011  size_t line_number_table_size;
8012  };
8014  wasm_source_info_t* wasm_source_info;
8015 
8016  union {
8017  // Only valid for CODE_ADDED.
8018  struct name_t name;
8019 
8020  // Only valid for CODE_ADD_LINE_POS_INFO
8021  struct line_info_t line_info;
8022 
8023  // New location of instructions. Only valid for CODE_MOVED.
8024  void* new_code_start;
8025  };
8027  Isolate* isolate;
8028 };
8029 
8035 enum RAILMode : unsigned {
8036  // Response performance mode: In this mode very low virtual machine latency
8037  // is provided. V8 will try to avoid JavaScript execution interruptions.
8038  // Throughput may be throttled.
8040  // Animation performance mode: In this mode low virtual machine latency is
8041  // provided. V8 will try to avoid as many JavaScript execution interruptions
8042  // as possible. Throughput may be throttled. This is the default mode.
8044  // Idle performance mode: The embedder is idle. V8 can complete deferred work
8045  // in this mode.
8047  // Load performance mode: In this mode high throughput is provided. V8 may
8048  // turn off latency optimizations.
8050 };
8051 
8057  // Generate callbacks for already existent code.
8059 };
8060 
8061 
8067 using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
8068 
8072 #if defined(V8_OS_WIN)
8073 using UnhandledExceptionCallback =
8074  int (*)(_EXCEPTION_POINTERS* exception_pointers);
8075 #endif
8076 
8080 class V8_EXPORT ExternalResourceVisitor { // NOLINT
8081  public:
8082  virtual ~ExternalResourceVisitor() = default;
8083  virtual void VisitExternalString(Local<String> string) {}
8084 };
8085 
8086 
8090 class V8_EXPORT PersistentHandleVisitor { // NOLINT
8091  public:
8092  virtual ~PersistentHandleVisitor() = default;
8093  virtual void VisitPersistentHandle(Persistent<Value>* value,
8094  uint16_t class_id) {}
8095 };
8096 
8105 enum class MemoryPressureLevel { kNone, kModerate, kCritical };
8106 
8114 class V8_EXPORT EmbedderHeapTracer {
8115  public:
8118  enum TraceFlags : uint64_t {
8119  kNoFlags = 0,
8120  kReduceMemory = 1 << 0,
8121  kForced = 1 << 2,
8122  };
8123 
8127  class V8_EXPORT TracedGlobalHandleVisitor {
8128  public:
8129  virtual ~TracedGlobalHandleVisitor() = default;
8130  virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& handle) {}
8131  virtual void VisitTracedReference(const TracedReference<Value>& handle) {}
8132  };
8133 
8138  struct TraceSummary {
8143  double time = 0.0;
8144 
8149  size_t allocated_size = 0;
8150  };
8152  virtual ~EmbedderHeapTracer() = default;
8153 
8158  void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor);
8159 
8164  void SetStackStart(void* stack_start);
8165 
8169  void NotifyEmptyEmbedderStack();
8170 
8177  virtual void RegisterV8References(
8178  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
8180  void RegisterEmbedderReference(const BasicTracedReference<v8::Data>& ref);
8181 
8185  virtual void TracePrologue(TraceFlags flags) {}
8186 
8197  virtual bool AdvanceTracing(double deadline_in_ms) = 0;
8198 
8199  /*
8200  * Returns true if there no more tracing work to be done (see AdvanceTracing)
8201  * and false otherwise.
8202  */
8203  virtual bool IsTracingDone() = 0;
8204 
8212  virtual void TraceEpilogue(TraceSummary* trace_summary) {}
8213 
8218  virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
8219 
8220  /*
8221  * Called by the embedder to request immediate finalization of the currently
8222  * running tracing phase that has been started with TracePrologue and not
8223  * yet finished with TraceEpilogue.
8224  *
8225  * Will be a noop when currently not in tracing.
8226  *
8227  * This is an experimental feature.
8228  */
8229  void FinalizeTracing();
8230 
8248  virtual bool IsRootForNonTracingGC(
8250  virtual bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>& handle);
8251 
8261  virtual void ResetHandleInNonTracingGC(
8262  const v8::TracedReference<v8::Value>& handle);
8263 
8264  /*
8265  * Called by the embedder to immediately perform a full garbage collection.
8266  *
8267  * Should only be used in testing code.
8268  */
8269  void GarbageCollectionForTesting(EmbedderStackState stack_state);
8270 
8271  /*
8272  * Called by the embedder to signal newly allocated or freed memory. Not bound
8273  * to tracing phases. Embedders should trade off when increments are reported
8274  * as V8 may consult global heuristics on whether to trigger garbage
8275  * collection on this change.
8276  */
8277  void IncreaseAllocatedSize(size_t bytes);
8278  void DecreaseAllocatedSize(size_t bytes);
8279 
8280  /*
8281  * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
8282  * is not attached to any v8::Isolate.
8283  */
8284  v8::Isolate* isolate() const { return isolate_; }
8285 
8286  protected:
8287  v8::Isolate* isolate_ = nullptr;
8289  friend class internal::LocalEmbedderHeapTracer;
8290 };
8291 
8301  using CallbackFunction = StartupData (*)(Local<Object> holder, int index,
8302  void* data);
8304  void* data_arg = nullptr)
8305  : callback(function), data(data_arg) {}
8307  void* data;
8308 };
8309 // Note that these fields are called "internal fields" in the API and called
8310 // "embedder fields" within V8.
8312 
8318  using CallbackFunction = void (*)(Local<Object> holder, int index,
8319  StartupData payload, void* data);
8321  void* data_arg = nullptr)
8322  : callback(function), data(data_arg) {}
8323  void (*callback)(Local<Object> holder, int index, StartupData payload,
8324  void* data);
8325  void* data;
8326 };
8327 using DeserializeEmbedderFieldsCallback = DeserializeInternalFieldsCallback;
8328 
8334 enum class MeasureMemoryMode { kSummary, kDetailed };
8335 
8343 enum class MeasureMemoryExecution { kDefault, kEager, kLazy };
8344 
8351 class V8_EXPORT MeasureMemoryDelegate {
8352  public:
8353  virtual ~MeasureMemoryDelegate() = default;
8354 
8358  virtual bool ShouldMeasure(Local<Context> context) = 0;
8359 
8370  virtual void MeasurementComplete(
8371  const std::vector<std::pair<Local<Context>, size_t>>&
8372  context_sizes_in_bytes,
8373  size_t unattributed_size_in_bytes) = 0;
8374 
8385  static std::unique_ptr<MeasureMemoryDelegate> Default(
8386  Isolate* isolate, Local<Context> context,
8387  Local<Promise::Resolver> promise_resolver, MeasureMemoryMode mode);
8388 };
8389 
8398 class V8_EXPORT Isolate {
8399  public:
8405  ~CreateParams();
8406 
8411  JitCodeEventHandler code_event_handler = nullptr;
8412 
8416  ResourceConstraints constraints;
8417 
8421  StartupData* snapshot_blob = nullptr;
8422 
8427  CounterLookupCallback counter_lookup_callback = nullptr;
8428 
8435  CreateHistogramCallback create_histogram_callback = nullptr;
8436  AddHistogramSampleCallback add_histogram_sample_callback = nullptr;
8437 
8447  ArrayBuffer::Allocator* array_buffer_allocator = nullptr;
8448  std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
8449 
8456  const intptr_t* external_references = nullptr;
8457 
8462  bool allow_atomics_wait = true;
8463 
8467  bool only_terminate_in_safe_scope = false;
8468 
8474  int embedder_wrapper_type_index = -1;
8475  int embedder_wrapper_object_index = -1;
8476 
8477  V8_DEPRECATED(
8478  "Setting this has no effect. Embedders should ignore import assertions "
8479  "that they do not use.")
8480  std::vector<std::string> supported_import_assertions;
8481  };
8482 
8487  class V8_EXPORT V8_NODISCARD Scope {
8488  public:
8489  explicit Scope(Isolate* isolate) : isolate_(isolate) {
8490  isolate->Enter();
8491  }
8493  ~Scope() { isolate_->Exit(); }
8494 
8495  // Prevent copying of Scope objects.
8496  Scope(const Scope&) = delete;
8497  Scope& operator=(const Scope&) = delete;
8498 
8499  private:
8500  Isolate* const isolate_;
8501  };
8502 
8507  public:
8508  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };