v8  7.9.317(node13.2.0)
V8 is Google's open source JavaScript engine
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 #include <memory>
22 #include <string>
23 #include <type_traits>
24 #include <utility>
25 #include <vector>
26 
27 #include "v8-internal.h" // NOLINT(build/include)
28 #include "v8-version.h" // NOLINT(build/include)
29 #include "v8config.h" // NOLINT(build/include)
30 
31 // We reserve the V8_* prefix for macros defined in V8 public API and
32 // assume there are no name conflicts with the embedder's code.
33 
37 namespace v8 {
38 
39 class AccessorSignature;
40 class Array;
41 class ArrayBuffer;
42 class BigInt;
43 class BigIntObject;
44 class Boolean;
45 class BooleanObject;
46 class Context;
47 class Data;
48 class Date;
49 class External;
50 class Function;
51 class FunctionTemplate;
52 class HeapProfiler;
53 class ImplementationUtilities;
54 class Int32;
55 class Integer;
56 class Isolate;
57 template <class T>
58 class Maybe;
59 class MicrotaskQueue;
60 class Name;
61 class Number;
62 class NumberObject;
63 class Object;
64 class ObjectOperationDescriptor;
65 class ObjectTemplate;
66 class Platform;
67 class Primitive;
68 class Promise;
69 class PropertyDescriptor;
70 class Proxy;
71 class RawOperationDescriptor;
72 class Script;
73 class SharedArrayBuffer;
74 class Signature;
75 class StartupData;
76 class StackFrame;
77 class StackTrace;
78 class String;
79 class StringObject;
80 class Symbol;
81 class SymbolObject;
82 class PrimitiveArray;
83 class Private;
84 class Uint32;
85 class Utils;
86 class Value;
87 class WasmModuleObject;
88 template <class T> class Local;
89 template <class T>
90 class MaybeLocal;
91 template <class T> class Eternal;
92 template<class T> class NonCopyablePersistentTraits;
93 template<class T> class PersistentBase;
94 template <class T, class M = NonCopyablePersistentTraits<T> >
95 class Persistent;
96 template <class T>
97 class Global;
98 template <class T>
100 template <class T>
102 template <class T>
104 template<class K, class V, class T> class PersistentValueMap;
105 template <class K, class V, class T>
107 template <class K, class V, class T>
108 class GlobalValueMap;
109 template<class V, class T> class PersistentValueVector;
110 template<class T, class P> class WeakCallbackObject;
111 class FunctionTemplate;
112 class ObjectTemplate;
113 template<typename T> class FunctionCallbackInfo;
114 template<typename T> class PropertyCallbackInfo;
115 class StackTrace;
116 class StackFrame;
117 class Isolate;
118 class CallHandlerHelper;
120 template<typename T> class ReturnValue;
121 
122 namespace internal {
123 class Arguments;
124 class DeferredHandles;
125 class Heap;
126 class HeapObject;
127 class ExternalString;
128 class Isolate;
129 class LocalEmbedderHeapTracer;
130 class MicrotaskQueue;
131 struct ScriptStreamingData;
132 template<typename T> class CustomArguments;
133 class PropertyCallbackArguments;
134 class FunctionCallbackArguments;
135 class GlobalHandles;
136 class ScopedExternalStringLock;
137 class ThreadLocalTop;
138 
139 namespace wasm {
140 class NativeModule;
141 class StreamingDecoder;
142 } // namespace wasm
143 
144 } // namespace internal
145 
146 namespace debug {
147 class ConsoleCallArguments;
148 } // namespace debug
149 
150 // --- Handles ---
151 
152 #define TYPE_CHECK(T, S) \
153  while (false) { \
154  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
155  }
156 
188 template <class T>
189 class Local {
190  public:
191  V8_INLINE Local() : val_(nullptr) {}
192  template <class S>
194  : val_(reinterpret_cast<T*>(*that)) {
200  TYPE_CHECK(T, S);
201  }
202 
206  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
207 
211  V8_INLINE void Clear() { val_ = nullptr; }
212 
213  V8_INLINE T* operator->() const { return val_; }
214 
215  V8_INLINE T* operator*() const { return val_; }
216 
223  template <class S>
224  V8_INLINE bool operator==(const Local<S>& that) const {
225  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
226  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
227  if (a == nullptr) return b == nullptr;
228  if (b == nullptr) return false;
229  return *a == *b;
230  }
231 
232  template <class S> V8_INLINE bool operator==(
233  const PersistentBase<S>& that) const {
234  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
235  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
236  if (a == nullptr) return b == nullptr;
237  if (b == nullptr) return false;
238  return *a == *b;
239  }
240 
247  template <class S>
248  V8_INLINE bool operator!=(const Local<S>& that) const {
249  return !operator==(that);
250  }
251 
252  template <class S> V8_INLINE bool operator!=(
253  const Persistent<S>& that) const {
254  return !operator==(that);
255  }
256 
262  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
263 #ifdef V8_ENABLE_CHECKS
264  // If we're going to perform the type check then we have to check
265  // that the handle isn't empty before doing the checked cast.
266  if (that.IsEmpty()) return Local<T>();
267 #endif
268  return Local<T>(T::Cast(*that));
269  }
270 
276  template <class S>
278  return Local<S>::Cast(*this);
279  }
280 
286  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
287  V8_INLINE static Local<T> New(Isolate* isolate,
288  const PersistentBase<T>& that);
289  V8_INLINE static Local<T> New(Isolate* isolate,
290  const TracedReferenceBase<T>& that);
291 
292  private:
293  friend class Utils;
294  template<class F> friend class Eternal;
295  template<class F> friend class PersistentBase;
296  template<class F, class M> friend class Persistent;
297  template<class F> friend class Local;
298  template <class F>
299  friend class MaybeLocal;
300  template<class F> friend class FunctionCallbackInfo;
301  template<class F> friend class PropertyCallbackInfo;
302  friend class String;
303  friend class Object;
304  friend class Context;
305  friend class Isolate;
306  friend class Private;
307  template<class F> friend class internal::CustomArguments;
308  friend Local<Primitive> Undefined(Isolate* isolate);
309  friend Local<Primitive> Null(Isolate* isolate);
310  friend Local<Boolean> True(Isolate* isolate);
311  friend Local<Boolean> False(Isolate* isolate);
312  friend class HandleScope;
313  friend class EscapableHandleScope;
314  template <class F1, class F2, class F3>
316  template<class F1, class F2> friend class PersistentValueVector;
317  template <class F>
318  friend class ReturnValue;
319  template <class F>
320  friend class Traced;
321  template <class F>
322  friend class TracedGlobal;
323  template <class F>
324  friend class TracedReferenceBase;
325  template <class F>
326  friend class TracedReference;
327 
328  explicit V8_INLINE Local(T* that) : val_(that) {}
329  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
330  T* val_;
331 };
332 
333 
334 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
335 // Handle is an alias for Local for historical reasons.
336 template <class T>
337 using Handle = Local<T>;
338 #endif
339 
340 
351 template <class T>
352 class MaybeLocal {
353  public:
354  V8_INLINE MaybeLocal() : val_(nullptr) {}
355  template <class S>
357  : val_(reinterpret_cast<T*>(*that)) {
358  TYPE_CHECK(T, S);
359  }
360 
361  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
362 
367  template <class S>
369  out->val_ = IsEmpty() ? nullptr : this->val_;
370  return !IsEmpty();
371  }
372 
378 
383  template <class S>
384  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
385  return IsEmpty() ? default_value : Local<S>(val_);
386  }
387 
388  private:
389  T* val_;
390 };
391 
396 template <class T> class Eternal {
397  public:
398  V8_INLINE Eternal() : val_(nullptr) {}
399  template <class S>
400  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
401  Set(isolate, handle);
402  }
403  // Can only be safely called if already set.
404  V8_INLINE Local<T> Get(Isolate* isolate) const;
405  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
406  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
407 
408  private:
409  T* val_;
410 };
411 
412 
413 static const int kInternalFieldsInWeakCallback = 2;
414 static const int kEmbedderFieldsInWeakCallback = 2;
415 
416 template <typename T>
418  public:
419  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
420 
421  WeakCallbackInfo(Isolate* isolate, T* parameter,
422  void* embedder_fields[kEmbedderFieldsInWeakCallback],
423  Callback* callback)
424  : isolate_(isolate), parameter_(parameter), callback_(callback) {
425  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
426  embedder_fields_[i] = embedder_fields[i];
427  }
428  }
429 
430  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
431  V8_INLINE T* GetParameter() const { return parameter_; }
432  V8_INLINE void* GetInternalField(int index) const;
433 
434  // When first called, the embedder MUST Reset() the Global which triggered the
435  // callback. The Global itself is unusable for anything else. No v8 other api
436  // calls may be called in the first callback. Should additional work be
437  // required, the embedder must set a second pass callback, which will be
438  // called after all the initial callbacks are processed.
439  // Calling SetSecondPassCallback on the second pass will immediately crash.
440  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
441 
442  private:
443  Isolate* isolate_;
444  T* parameter_;
445  Callback* callback_;
446  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
447 };
448 
449 
450 // kParameter will pass a void* parameter back to the callback, kInternalFields
451 // will pass the first two internal fields back to the callback, kFinalizer
452 // will pass a void* parameter back, but is invoked before the object is
453 // actually collected, so it can be resurrected. In the last case, it is not
454 // possible to request a second pass callback.
456 
470 template <class T> class PersistentBase {
471  public:
476  V8_INLINE void Reset();
481  template <class S>
482  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
483 
488  template <class S>
489  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
490 
491  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
492  V8_INLINE void Empty() { val_ = 0; }
493 
494  V8_INLINE Local<T> Get(Isolate* isolate) const {
495  return Local<T>::New(isolate, *this);
496  }
497 
498  template <class S>
499  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
500  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
501  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
502  if (a == nullptr) return b == nullptr;
503  if (b == nullptr) return false;
504  return *a == *b;
505  }
506 
507  template <class S>
508  V8_INLINE bool operator==(const Local<S>& that) const {
509  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
510  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
511  if (a == nullptr) return b == nullptr;
512  if (b == nullptr) return false;
513  return *a == *b;
514  }
515 
516  template <class S>
517  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
518  return !operator==(that);
519  }
520 
521  template <class S>
522  V8_INLINE bool operator!=(const Local<S>& that) const {
523  return !operator==(that);
524  }
525 
533  template <typename P>
534  V8_INLINE void SetWeak(P* parameter,
535  typename WeakCallbackInfo<P>::Callback callback,
536  WeakCallbackType type);
537 
545  V8_INLINE void SetWeak();
546 
547  template<typename P>
548  V8_INLINE P* ClearWeak();
549 
550  // TODO(dcarney): remove this.
551  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
552 
559  V8_INLINE void AnnotateStrongRetainer(const char* label);
560 
562  V8_INLINE bool IsWeak() const;
563 
567  V8_INLINE void SetWrapperClassId(uint16_t class_id);
568 
573  V8_INLINE uint16_t WrapperClassId() const;
574 
575  PersistentBase(const PersistentBase& other) = delete; // NOLINT
576  void operator=(const PersistentBase&) = delete;
577 
578  private:
579  friend class Isolate;
580  friend class Utils;
581  template<class F> friend class Local;
582  template<class F1, class F2> friend class Persistent;
583  template <class F>
584  friend class Global;
585  template<class F> friend class PersistentBase;
586  template<class F> friend class ReturnValue;
587  template <class F1, class F2, class F3>
589  template<class F1, class F2> friend class PersistentValueVector;
590  friend class Object;
591 
592  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
593  V8_INLINE static T* New(Isolate* isolate, T* that);
594 
595  T* val_;
596 };
597 
598 
605 template<class T>
606 class NonCopyablePersistentTraits {
607  public:
609  static const bool kResetInDestructor = false;
610  template<class S, class M>
611  V8_INLINE static void Copy(const Persistent<S, M>& source,
612  NonCopyablePersistent* dest) {
613  Uncompilable<Object>();
614  }
615  // TODO(dcarney): come up with a good compile error here.
616  template<class O> V8_INLINE static void Uncompilable() {
617  TYPE_CHECK(O, Primitive);
618  }
619 };
620 
621 
626 template<class T>
629  static const bool kResetInDestructor = true;
630  template<class S, class M>
631  static V8_INLINE void Copy(const Persistent<S, M>& source,
632  CopyablePersistent* dest) {
633  // do nothing, just allow copy
634  }
635 };
636 
637 
646 template <class T, class M> class Persistent : public PersistentBase<T> {
647  public:
657  template <class S>
659  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
660  TYPE_CHECK(T, S);
661  }
667  template <class S, class M2>
669  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
670  TYPE_CHECK(T, S);
671  }
678  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(nullptr) {
679  Copy(that);
680  }
681  template <class S, class M2>
683  Copy(that);
684  }
686  Copy(that);
687  return *this;
688  }
689  template <class S, class M2>
691  Copy(that);
692  return *this;
693  }
700  if (M::kResetInDestructor) this->Reset();
701  }
702 
703  // TODO(dcarney): this is pretty useless, fix or remove
704  template <class S>
705  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
706 #ifdef V8_ENABLE_CHECKS
707  // If we're going to perform the type check then we have to check
708  // that the handle isn't empty before doing the checked cast.
709  if (!that.IsEmpty()) T::Cast(*that);
710 #endif
711  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
712  }
713 
714  // TODO(dcarney): this is pretty useless, fix or remove
715  template <class S>
716  V8_INLINE Persistent<S>& As() const { // NOLINT
717  return Persistent<S>::Cast(*this);
718  }
719 
720  private:
721  friend class Isolate;
722  friend class Utils;
723  template<class F> friend class Local;
724  template<class F1, class F2> friend class Persistent;
725  template<class F> friend class ReturnValue;
726 
727  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
728  V8_INLINE T* operator*() const { return this->val_; }
729  template<class S, class M2>
730  V8_INLINE void Copy(const Persistent<S, M2>& that);
731 };
732 
733 
739 template <class T>
740 class Global : public PersistentBase<T> {
741  public:
745  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
746 
752  template <class S>
754  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
755  TYPE_CHECK(T, S);
756  }
757 
763  template <class S>
764  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
765  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
766  TYPE_CHECK(T, S);
767  }
768 
772  V8_INLINE Global(Global&& other);
773 
774  V8_INLINE ~Global() { this->Reset(); }
775 
779  template <class S>
781 
785  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
786 
787  /*
788  * For compatibility with Chromium's base::Bind (base::Passed).
789  */
790  typedef void MoveOnlyTypeForCPP03;
791 
792  Global(const Global&) = delete;
793  void operator=(const Global&) = delete;
794 
795  private:
796  template <class F>
797  friend class ReturnValue;
798  V8_INLINE T* operator*() const { return this->val_; }
799 };
800 
801 
802 // UniquePersistent is an alias for Global for historical reason.
803 template <class T>
805 
809 template <typename T>
811 
827 template <typename T>
828 class TracedReferenceBase {
829  public:
834  bool IsEmpty() const { return val_ == nullptr; }
835 
840  V8_INLINE void Reset();
841 
845  Local<T> Get(Isolate* isolate) const { return Local<T>::New(isolate, *this); }
846 
847  template <class S>
848  V8_INLINE bool operator==(const TracedReferenceBase<S>& that) const {
849  internal::Address* a = reinterpret_cast<internal::Address*>(val_);
850  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
851  if (a == nullptr) return b == nullptr;
852  if (b == nullptr) return false;
853  return *a == *b;
854  }
855 
856  template <class S>
857  V8_INLINE bool operator==(const Local<S>& that) const {
858  internal::Address* a = reinterpret_cast<internal::Address*>(val_);
859  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
860  if (a == nullptr) return b == nullptr;
861  if (b == nullptr) return false;
862  return *a == *b;
863  }
864 
865  template <class S>
866  V8_INLINE bool operator!=(const TracedReferenceBase<S>& that) const {
867  return !operator==(that);
868  }
869 
870  template <class S>
871  V8_INLINE bool operator!=(const Local<S>& that) const {
872  return !operator==(that);
873  }
874 
878  V8_INLINE void SetWrapperClassId(uint16_t class_id);
879 
884  V8_INLINE uint16_t WrapperClassId() const;
885 
897  void* parameter, WeakCallbackInfo<void>::Callback callback);
898 
899  template <class S>
901  return reinterpret_cast<TracedReferenceBase<S>&>(
902  const_cast<TracedReferenceBase<T>&>(*this));
903  }
904 
905  private:
906  enum DestructionMode { kWithDestructor, kWithoutDestructor };
907 
911  TracedReferenceBase() = default;
912 
913  V8_INLINE static T* New(Isolate* isolate, T* that, void* slot,
914  DestructionMode destruction_mode);
915 
916  T* val_ = nullptr;
917 
918  friend class EmbedderHeapTracer;
919  template <typename F>
920  friend class Local;
921  friend class Object;
922  template <typename F>
923  friend class TracedGlobal;
924  template <typename F>
925  friend class TracedReference;
926  template <typename F>
927  friend class ReturnValue;
928 };
929 
934 template <typename T>
935 class TracedGlobal : public TracedReferenceBase<T> {
936  public:
938 
942  ~TracedGlobal() { this->Reset(); }
943 
948 
955  template <class S>
957  this->val_ = this->New(isolate, that.val_, &this->val_,
959  TYPE_CHECK(T, S);
960  }
961 
966  // Forward to operator=.
967  *this = std::move(other);
968  }
969 
973  template <typename S>
975  // Forward to operator=.
976  *this = std::move(other);
977  }
978 
983  // Forward to operator=;
984  *this = other;
985  }
986 
990  template <typename S>
992  // Forward to operator=;
993  *this = other;
994  }
995 
1000 
1004  template <class S>
1006 
1014 
1021  template <class S>
1023 
1028  template <class S>
1029  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
1030 
1031  template <class S>
1033  return reinterpret_cast<TracedGlobal<S>&>(
1034  const_cast<TracedGlobal<T>&>(*this));
1035  }
1036 };
1037 
1044 template <typename T>
1045 class TracedReference : public TracedReferenceBase<T> {
1046  public:
1048 
1053 
1060  template <class S>
1062  this->val_ = this->New(isolate, that.val_, &this->val_,
1064  TYPE_CHECK(T, S);
1065  }
1066 
1072  // Forward to operator=.
1073  *this = std::move(other);
1074  }
1075 
1080  template <typename S>
1082  // Forward to operator=.
1083  *this = std::move(other);
1084  }
1085 
1091  // Forward to operator=;
1092  *this = other;
1093  }
1094 
1099  template <typename S>
1101  // Forward to operator=;
1102  *this = other;
1103  }
1104 
1109 
1113  template <class S>
1115 
1123 
1130  template <class S>
1132 
1137  template <class S>
1138  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
1139 
1140  template <class S>
1142  return reinterpret_cast<TracedReference<S>&>(
1143  const_cast<TracedReference<T>&>(*this));
1144  }
1145 };
1146 
1162  public:
1163  explicit HandleScope(Isolate* isolate);
1164 
1165  ~HandleScope();
1166 
1170  static int NumberOfHandles(Isolate* isolate);
1171 
1173  return reinterpret_cast<Isolate*>(isolate_);
1174  }
1175 
1176  HandleScope(const HandleScope&) = delete;
1177  void operator=(const HandleScope&) = delete;
1178 
1179  protected:
1180  V8_INLINE HandleScope() = default;
1181 
1182  void Initialize(Isolate* isolate);
1183 
1184  static internal::Address* CreateHandle(internal::Isolate* isolate,
1185  internal::Address value);
1186 
1187  private:
1188  // Declaring operator new and delete as deleted is not spec compliant.
1189  // Therefore declare them private instead to disable dynamic alloc
1190  void* operator new(size_t size);
1191  void* operator new[](size_t size);
1192  void operator delete(void*, size_t);
1193  void operator delete[](void*, size_t);
1194 
1195  internal::Isolate* isolate_;
1196  internal::Address* prev_next_;
1197  internal::Address* prev_limit_;
1198 
1199  // Local::New uses CreateHandle with an Isolate* parameter.
1200  template<class F> friend class Local;
1201 
1202  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
1203  // a HeapObject in their shortcuts.
1204  friend class Object;
1205  friend class Context;
1206 };
1207 
1208 
1214  public:
1215  explicit EscapableHandleScope(Isolate* isolate);
1216  V8_INLINE ~EscapableHandleScope() = default;
1217 
1222  template <class T>
1224  internal::Address* slot =
1225  Escape(reinterpret_cast<internal::Address*>(*value));
1226  return Local<T>(reinterpret_cast<T*>(slot));
1227  }
1228 
1229  template <class T>
1231  return Escape(value.FromMaybe(Local<T>()));
1232  }
1233 
1234  EscapableHandleScope(const EscapableHandleScope&) = delete;
1235  void operator=(const EscapableHandleScope&) = delete;
1236 
1237  private:
1238  // Declaring operator new and delete as deleted is not spec compliant.
1239  // Therefore declare them private instead to disable dynamic alloc
1240  void* operator new(size_t size);
1241  void* operator new[](size_t size);
1242  void operator delete(void*, size_t);
1243  void operator delete[](void*, size_t);
1244 
1245  internal::Address* Escape(internal::Address* escape_value);
1246  internal::Address* escape_slot_;
1247 };
1248 
1255  public:
1256  explicit SealHandleScope(Isolate* isolate);
1257  ~SealHandleScope();
1258 
1259  SealHandleScope(const SealHandleScope&) = delete;
1260  void operator=(const SealHandleScope&) = delete;
1261 
1262  private:
1263  // Declaring operator new and delete as deleted is not spec compliant.
1264  // Therefore declare them private instead to disable dynamic alloc
1265  void* operator new(size_t size);
1266  void* operator new[](size_t size);
1267  void operator delete(void*, size_t);
1268  void operator delete[](void*, size_t);
1269 
1270  internal::Isolate* const isolate_;
1271  internal::Address* prev_limit_;
1272  int prev_sealed_level_;
1273 };
1274 
1275 
1276 // --- Special objects ---
1277 
1282  private:
1283  Data();
1284 };
1285 
1293  public:
1298  Local<Value> GetResourceName();
1299 
1304  Local<PrimitiveArray> GetHostDefinedOptions();
1305 };
1306 
1316  public:
1317  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1318  int Length() const;
1319  void Set(Isolate* isolate, int index, Local<Primitive> item);
1320  Local<Primitive> Get(Isolate* isolate, int index);
1321 };
1322 
1327  public:
1328  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1329  bool is_opaque = false, bool is_wasm = false,
1330  bool is_module = false)
1331  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1332  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1333  (is_module ? kIsModule : 0)) {}
1335  : flags_(flags &
1336  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1337 
1338  bool IsSharedCrossOrigin() const {
1339  return (flags_ & kIsSharedCrossOrigin) != 0;
1340  }
1341  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1342  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1343  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1344 
1345  int Flags() const { return flags_; }
1346 
1347  private:
1348  enum {
1349  kIsSharedCrossOrigin = 1,
1350  kIsOpaque = 1 << 1,
1351  kIsWasm = 1 << 2,
1352  kIsModule = 1 << 3
1353  };
1354  const int flags_;
1355 };
1356 
1361  public:
1363  Local<Value> resource_name,
1364  Local<Integer> resource_line_offset = Local<Integer>(),
1365  Local<Integer> resource_column_offset = Local<Integer>(),
1366  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1367  Local<Integer> script_id = Local<Integer>(),
1368  Local<Value> source_map_url = Local<Value>(),
1369  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1370  Local<Boolean> is_wasm = Local<Boolean>(),
1371  Local<Boolean> is_module = Local<Boolean>(),
1372  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1373 
1380  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1381 
1382  private:
1383  Local<Value> resource_name_;
1384  Local<Integer> resource_line_offset_;
1385  Local<Integer> resource_column_offset_;
1386  ScriptOriginOptions options_;
1387  Local<Integer> script_id_;
1388  Local<Value> source_map_url_;
1389  Local<PrimitiveArray> host_defined_options_;
1390 };
1391 
1396  public:
1400  Local<Script> BindToCurrentContext();
1401 
1402  int GetId();
1403  Local<Value> GetScriptName();
1404 
1408  Local<Value> GetSourceURL();
1412  Local<Value> GetSourceMappingURL();
1413 
1418  int GetLineNumber(int code_pos);
1419 
1420  static const int kNoScriptId = 0;
1421 };
1422 
1427  // Only used as a container for code caching.
1428 };
1429 
1434  public:
1435  int GetLineNumber() { return line_number_; }
1436  int GetColumnNumber() { return column_number_; }
1437 
1438  Location(int line_number, int column_number)
1439  : line_number_(line_number), column_number_(column_number) {}
1440 
1441  private:
1442  int line_number_;
1443  int column_number_;
1444 };
1445 
1449 class V8_EXPORT Module : public Data {
1450  public:
1458  enum Status {
1464  kErrored
1465  };
1466 
1470  Status GetStatus() const;
1471 
1475  Local<Value> GetException() const;
1476 
1480  int GetModuleRequestsLength() const;
1481 
1486  Local<String> GetModuleRequest(int i) const;
1487 
1492  Location GetModuleRequestLocation(int i) const;
1493 
1497  int GetIdentityHash() const;
1498 
1499  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1500  Local<String> specifier,
1501  Local<Module> referrer);
1502 
1510  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1511  ResolveCallback callback);
1512 
1522 
1528  Local<Value> GetModuleNamespace();
1529 
1536  Local<UnboundModuleScript> GetUnboundModuleScript();
1537 
1538  /*
1539  * Callback defined in the embedder. This is responsible for setting
1540  * the module's exported values with calls to SetSyntheticModuleExport().
1541  * The callback must return a Value to indicate success (where no
1542  * exception was thrown) and return an empy MaybeLocal to indicate falure
1543  * (where an exception was thrown).
1544  */
1545  typedef MaybeLocal<Value> (*SyntheticModuleEvaluationSteps)(
1546  Local<Context> context, Local<Module> module);
1547 
1555  static Local<Module> CreateSyntheticModule(
1556  Isolate* isolate, Local<String> module_name,
1557  const std::vector<Local<String>>& export_names,
1558  SyntheticModuleEvaluationSteps evaluation_steps);
1559 
1566  void SetSyntheticModuleExport(Local<String> export_name,
1567  Local<Value> export_value);
1568 };
1569 
1575  public:
1580  Local<Context> context, Local<String> source,
1581  ScriptOrigin* origin = nullptr);
1582 
1589 
1593  Local<UnboundScript> GetUnboundScript();
1594 };
1595 
1596 
1601  public:
1612  BufferOwned
1613  };
1614 
1616  : data(nullptr),
1617  length(0),
1618  rejected(false),
1619  buffer_policy(BufferNotOwned) {}
1620 
1621  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1622  // data and guarantees that it stays alive until the CachedData object is
1623  // destroyed. If the policy is BufferOwned, the given data will be deleted
1624  // (with delete[]) when the CachedData object is destroyed.
1625  CachedData(const uint8_t* data, int length,
1626  BufferPolicy buffer_policy = BufferNotOwned);
1627  ~CachedData();
1628  // TODO(marja): Async compilation; add constructors which take a callback
1629  // which will be called when V8 no longer needs the data.
1630  const uint8_t* data;
1631  int length;
1632  bool rejected;
1634 
1635  // Prevent copying.
1636  CachedData(const CachedData&) = delete;
1637  CachedData& operator=(const CachedData&) = delete;
1638  };
1639 
1643  class Source {
1644  public:
1645  // Source takes ownership of CachedData.
1646  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1647  CachedData* cached_data = nullptr);
1648  V8_INLINE Source(Local<String> source_string,
1649  CachedData* cached_data = nullptr);
1650  V8_INLINE ~Source();
1651 
1652  // Ownership of the CachedData or its buffers is *not* transferred to the
1653  // caller. The CachedData object is alive as long as the Source object is
1654  // alive.
1655  V8_INLINE const CachedData* GetCachedData() const;
1656 
1657  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1658 
1659  // Prevent copying.
1660  Source(const Source&) = delete;
1661  Source& operator=(const Source&) = delete;
1662 
1663  private:
1664  friend class ScriptCompiler;
1665 
1666  Local<String> source_string;
1667 
1668  // Origin information
1669  Local<Value> resource_name;
1670  Local<Integer> resource_line_offset;
1671  Local<Integer> resource_column_offset;
1672  ScriptOriginOptions resource_options;
1673  Local<Value> source_map_url;
1674  Local<PrimitiveArray> host_defined_options;
1675 
1676  // Cached data from previous compilation (if a kConsume*Cache flag is
1677  // set), or hold newly generated cache data (kProduce*Cache flags) are
1678  // set when calling a compile method.
1679  CachedData* cached_data;
1680  };
1681 
1687  public:
1688  virtual ~ExternalSourceStream() = default;
1689 
1711  virtual size_t GetMoreData(const uint8_t** src) = 0;
1712 
1723  virtual bool SetBookmark();
1724 
1728  virtual void ResetToBookmark();
1729  };
1730 
1738  public:
1739  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1740 
1742  "This class takes ownership of source_stream, so use the constructor "
1743  "taking a unique_ptr to make these semantics clearer")
1744  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1745  StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream,
1746  Encoding encoding);
1747  ~StreamedSource();
1748 
1749  internal::ScriptStreamingData* impl() const { return impl_.get(); }
1750 
1751  // Prevent copying.
1752  StreamedSource(const StreamedSource&) = delete;
1753  StreamedSource& operator=(const StreamedSource&) = delete;
1754 
1755  private:
1756  std::unique_ptr<internal::ScriptStreamingData> impl_;
1757  };
1758 
1764  public:
1765  void Run();
1766 
1767  private:
1768  friend class ScriptCompiler;
1769 
1770  explicit ScriptStreamingTask(internal::ScriptStreamingData* data)
1771  : data_(data) {}
1772 
1773  internal::ScriptStreamingData* data_;
1774  };
1775 
1777  kNoCompileOptions = 0,
1779  kEagerCompile
1780  };
1781 
1786  kNoCacheNoReason = 0,
1800  kNoCacheBecauseDeferredProduceCodeCache
1801  };
1802 
1816  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1817  Isolate* isolate, Source* source,
1818  CompileOptions options = kNoCompileOptions,
1819  NoCacheReason no_cache_reason = kNoCacheNoReason);
1820 
1833  Local<Context> context, Source* source,
1834  CompileOptions options = kNoCompileOptions,
1835  NoCacheReason no_cache_reason = kNoCacheNoReason);
1836 
1848  static ScriptStreamingTask* StartStreamingScript(
1849  Isolate* isolate, StreamedSource* source,
1850  CompileOptions options = kNoCompileOptions);
1851 
1860  Local<Context> context, StreamedSource* source,
1861  Local<String> full_source_string, const ScriptOrigin& origin);
1862 
1881  static uint32_t CachedDataVersionTag();
1882 
1890  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1891  Isolate* isolate, Source* source,
1892  CompileOptions options = kNoCompileOptions,
1893  NoCacheReason no_cache_reason = kNoCacheNoReason);
1894 
1905  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1906  Local<Context> context, Source* source, size_t arguments_count,
1907  Local<String> arguments[], size_t context_extension_count,
1908  Local<Object> context_extensions[],
1909  CompileOptions options = kNoCompileOptions,
1910  NoCacheReason no_cache_reason = kNoCacheNoReason,
1911  Local<ScriptOrModule>* script_or_module_out = nullptr);
1912 
1918  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
1919 
1925  static CachedData* CreateCodeCache(
1926  Local<UnboundModuleScript> unbound_module_script);
1927 
1934  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
1935 
1936  private:
1937  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1938  Isolate* isolate, Source* source, CompileOptions options,
1939  NoCacheReason no_cache_reason);
1940 };
1941 
1942 
1947  public:
1948  Local<String> Get() const;
1949 
1953  Isolate* GetIsolate() const;
1954 
1956  Local<Context> context) const;
1957 
1962  ScriptOrigin GetScriptOrigin() const;
1963 
1968  Local<Value> GetScriptResourceName() const;
1969 
1975  Local<StackTrace> GetStackTrace() const;
1976 
1980  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1981 
1986  int GetStartPosition() const;
1987 
1992  int GetEndPosition() const;
1993 
1997  int ErrorLevel() const;
1998 
2003  int GetStartColumn() const;
2004  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
2005 
2010  int GetEndColumn() const;
2011  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
2012 
2017  bool IsSharedCrossOrigin() const;
2018  bool IsOpaque() const;
2019 
2020  // TODO(1245381): Print to a string instead of on a FILE.
2021  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
2022 
2023  static const int kNoLineNumberInfo = 0;
2024  static const int kNoColumnInfo = 0;
2025  static const int kNoScriptIdInfo = 0;
2026 };
2027 
2028 
2035  public:
2043  kLineNumber = 1,
2044  kColumnOffset = 1 << 1 | kLineNumber,
2045  kScriptName = 1 << 2,
2046  kFunctionName = 1 << 3,
2047  kIsEval = 1 << 4,
2048  kIsConstructor = 1 << 5,
2049  kScriptNameOrSourceURL = 1 << 6,
2050  kScriptId = 1 << 7,
2051  kExposeFramesAcrossSecurityOrigins = 1 << 8,
2052  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
2053  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
2054  };
2055 
2059  Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
2060 
2064  int GetFrameCount() const;
2065 
2073  static Local<StackTrace> CurrentStackTrace(
2074  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
2075 };
2076 
2077 
2082  public:
2089  int GetLineNumber() const;
2090 
2098  int GetColumn() const;
2099 
2106  int GetScriptId() const;
2107 
2112  Local<String> GetScriptName() const;
2113 
2120  Local<String> GetScriptNameOrSourceURL() const;
2121 
2125  Local<String> GetFunctionName() const;
2126 
2131  bool IsEval() const;
2132 
2137  bool IsConstructor() const;
2138 
2142  bool IsWasm() const;
2143 
2147  bool IsUserJavaScript() const;
2148 };
2149 
2150 
2151 // A StateTag represents a possible state of the VM.
2152 enum StateTag {
2161 };
2162 
2163 // A RegisterState represents the current state of registers used
2164 // by the sampling profiler API.
2166  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr), lr(nullptr) {}
2167  void* pc; // Instruction pointer.
2168  void* sp; // Stack pointer.
2169  void* fp; // Frame pointer.
2170  void* lr; // Link register (or nullptr on platforms without a link register).
2171 };
2172 
2173 // The output structure filled up by GetStackSample API function.
2174 struct SampleInfo {
2175  size_t frames_count; // Number of frames collected.
2176  StateTag vm_state; // Current VM state.
2177  void* external_callback_entry; // External callback address if VM is
2178  // executing an external callback.
2179  void* top_context; // Incumbent native context address.
2180 };
2181 
2182 struct MemoryRange {
2183  const void* start = nullptr;
2184  size_t length_in_bytes = 0;
2185 };
2186 
2187 struct JSEntryStub {
2189 };
2190 
2191 struct UnwindState {
2195 };
2196 
2201  public:
2211  Local<Context> context, Local<String> json_string);
2212 
2220  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
2221  Local<Context> context, Local<Value> json_object,
2222  Local<String> gap = Local<String>());
2223 };
2224 
2230  public:
2232  public:
2233  virtual ~Delegate() = default;
2234 
2240  virtual void ThrowDataCloneError(Local<String> message) = 0;
2241 
2247  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
2248 
2259  virtual Maybe<uint32_t> GetSharedArrayBufferId(
2260  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
2261 
2262  virtual Maybe<uint32_t> GetWasmModuleTransferId(
2263  Isolate* isolate, Local<WasmModuleObject> module);
2275  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
2276  size_t* actual_size);
2277 
2283  virtual void FreeBufferMemory(void* buffer);
2284  };
2285 
2286  explicit ValueSerializer(Isolate* isolate);
2287  ValueSerializer(Isolate* isolate, Delegate* delegate);
2288  ~ValueSerializer();
2289 
2293  void WriteHeader();
2294 
2299  Local<Value> value);
2300 
2307  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
2308 
2314  void TransferArrayBuffer(uint32_t transfer_id,
2315  Local<ArrayBuffer> array_buffer);
2316 
2317 
2325  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
2326 
2332  void WriteUint32(uint32_t value);
2333  void WriteUint64(uint64_t value);
2334  void WriteDouble(double value);
2335  void WriteRawBytes(const void* source, size_t length);
2336 
2337  ValueSerializer(const ValueSerializer&) = delete;
2338  void operator=(const ValueSerializer&) = delete;
2339 
2340  private:
2341  struct PrivateData;
2342  PrivateData* private_;
2343 };
2344 
2350  public:
2352  public:
2353  virtual ~Delegate() = default;
2354 
2360  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
2361 
2366  virtual MaybeLocal<WasmModuleObject> GetWasmModuleFromId(
2367  Isolate* isolate, uint32_t transfer_id);
2368 
2373  virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
2374  Isolate* isolate, uint32_t clone_id);
2375  };
2376 
2377  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2378  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2379  Delegate* delegate);
2380  ~ValueDeserializer();
2381 
2386  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2387 
2392 
2397  void TransferArrayBuffer(uint32_t transfer_id,
2398  Local<ArrayBuffer> array_buffer);
2399 
2405  void TransferSharedArrayBuffer(uint32_t id,
2406  Local<SharedArrayBuffer> shared_array_buffer);
2407 
2415  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2416 
2420  void SetExpectInlineWasm(bool allow_inline_wasm);
2421 
2427  uint32_t GetWireFormatVersion() const;
2428 
2434  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2435  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2436  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2437  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2438 
2439  ValueDeserializer(const ValueDeserializer&) = delete;
2440  void operator=(const ValueDeserializer&) = delete;
2441 
2442  private:
2443  struct PrivateData;
2444  PrivateData* private_;
2445 };
2446 
2447 
2448 // --- Value ---
2449 
2450 
2454 class V8_EXPORT Value : public Data {
2455  public:
2460  V8_INLINE bool IsUndefined() const;
2461 
2466  V8_INLINE bool IsNull() const;
2467 
2473  V8_INLINE bool IsNullOrUndefined() const;
2474 
2478  bool IsTrue() const;
2479 
2483  bool IsFalse() const;
2484 
2488  bool IsName() const;
2489 
2494  V8_INLINE bool IsString() const;
2495 
2499  bool IsSymbol() const;
2500 
2504  bool IsFunction() const;
2505 
2510  bool IsArray() const;
2511 
2515  bool IsObject() const;
2516 
2520  bool IsBigInt() const;
2521 
2525  bool IsBoolean() const;
2526 
2530  bool IsNumber() const;
2531 
2535  bool IsExternal() const;
2536 
2540  bool IsInt32() const;
2541 
2545  bool IsUint32() const;
2546 
2550  bool IsDate() const;
2551 
2555  bool IsArgumentsObject() const;
2556 
2560  bool IsBigIntObject() const;
2561 
2565  bool IsBooleanObject() const;
2566 
2570  bool IsNumberObject() const;
2571 
2575  bool IsStringObject() const;
2576 
2580  bool IsSymbolObject() const;
2581 
2585  bool IsNativeError() const;
2586 
2590  bool IsRegExp() const;
2591 
2595  bool IsAsyncFunction() const;
2596 
2600  bool IsGeneratorFunction() const;
2601 
2605  bool IsGeneratorObject() const;
2606 
2610  bool IsPromise() const;
2611 
2615  bool IsMap() const;
2616 
2620  bool IsSet() const;
2621 
2625  bool IsMapIterator() const;
2626 
2630  bool IsSetIterator() const;
2631 
2635  bool IsWeakMap() const;
2636 
2640  bool IsWeakSet() const;
2641 
2645  bool IsArrayBuffer() const;
2646 
2650  bool IsArrayBufferView() const;
2651 
2655  bool IsTypedArray() const;
2656 
2660  bool IsUint8Array() const;
2661 
2665  bool IsUint8ClampedArray() const;
2666 
2670  bool IsInt8Array() const;
2671 
2675  bool IsUint16Array() const;
2676 
2680  bool IsInt16Array() const;
2681 
2685  bool IsUint32Array() const;
2686 
2690  bool IsInt32Array() const;
2691 
2695  bool IsFloat32Array() const;
2696 
2700  bool IsFloat64Array() const;
2701 
2705  bool IsBigInt64Array() const;
2706 
2710  bool IsBigUint64Array() const;
2711 
2715  bool IsDataView() const;
2716 
2721  bool IsSharedArrayBuffer() const;
2722 
2726  bool IsProxy() const;
2727 
2728  bool IsWebAssemblyCompiledModule() const;
2729 
2733  bool IsModuleNamespaceObject() const;
2734 
2736  Local<Context> context) const;
2738  Local<Context> context) const;
2740  Local<Context> context) const;
2742  Local<Context> context) const;
2744  Local<Context> context) const;
2746  Local<Context> context) const;
2748  Local<Context> context) const;
2750 
2751  Local<Boolean> ToBoolean(Isolate* isolate) const;
2752 
2758  Local<Context> context) const;
2759 
2760  bool BooleanValue(Isolate* isolate) const;
2761 
2762  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2764  Local<Context> context) const;
2766  Local<Context> context) const;
2767  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2768 
2771  Local<Value> that) const;
2772  bool StrictEquals(Local<Value> that) const;
2773  bool SameValue(Local<Value> that) const;
2774 
2775  template <class T> V8_INLINE static Value* Cast(T* value);
2776 
2777  Local<String> TypeOf(Isolate*);
2778 
2779  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2780 
2781  private:
2782  V8_INLINE bool QuickIsUndefined() const;
2783  V8_INLINE bool QuickIsNull() const;
2784  V8_INLINE bool QuickIsNullOrUndefined() const;
2785  V8_INLINE bool QuickIsString() const;
2786  bool FullIsUndefined() const;
2787  bool FullIsNull() const;
2788  bool FullIsString() const;
2789 };
2790 
2791 
2795 class V8_EXPORT Primitive : public Value { };
2796 
2797 
2802 class V8_EXPORT Boolean : public Primitive {
2803  public:
2804  bool Value() const;
2805  V8_INLINE static Boolean* Cast(v8::Value* obj);
2806  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2807 
2808  private:
2809  static void CheckCast(v8::Value* obj);
2810 };
2811 
2812 
2816 class V8_EXPORT Name : public Primitive {
2817  public:
2825  int GetIdentityHash();
2826 
2827  V8_INLINE static Name* Cast(Value* obj);
2828 
2829  private:
2830  static void CheckCast(Value* obj);
2831 };
2832 
2839 enum class NewStringType {
2843  kNormal,
2844 
2851 };
2852 
2856 class V8_EXPORT String : public Name {
2857  public:
2858  static constexpr int kMaxLength = internal::kApiTaggedSize == 4
2859  ? (1 << 28) - 16
2860  : internal::kSmiMaxValue / 2 - 24;
2861 
2862  enum Encoding {
2863  UNKNOWN_ENCODING = 0x1,
2864  TWO_BYTE_ENCODING = 0x0,
2865  ONE_BYTE_ENCODING = 0x8
2866  };
2870  int Length() const;
2871 
2876  int Utf8Length(Isolate* isolate) const;
2877 
2884  bool IsOneByte() const;
2885 
2891  bool ContainsOnlyOneByte() const;
2892 
2919  NO_OPTIONS = 0,
2920  HINT_MANY_WRITES_EXPECTED = 1,
2921  NO_NULL_TERMINATION = 2,
2922  PRESERVE_ONE_BYTE_NULL = 4,
2923  // Used by WriteUtf8 to replace orphan surrogate code units with the
2924  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2925  // output.
2926  REPLACE_INVALID_UTF8 = 8
2927  };
2928 
2929  // 16-bit character codes.
2930  int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
2931  int options = NO_OPTIONS) const;
2932  // One byte characters.
2933  int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
2934  int length = -1, int options = NO_OPTIONS) const;
2935  // UTF-8 encoded characters.
2936  int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
2937  int* nchars_ref = nullptr, int options = NO_OPTIONS) const;
2938 
2942  V8_INLINE static Local<String> Empty(Isolate* isolate);
2943 
2947  bool IsExternal() const;
2948 
2952  bool IsExternalOneByte() const;
2953 
2955  public:
2956  virtual ~ExternalStringResourceBase() = default;
2957 
2963  virtual bool IsCacheable() const { return true; }
2964 
2965  // Disallow copying and assigning.
2967  void operator=(const ExternalStringResourceBase&) = delete;
2968 
2969  protected:
2970  ExternalStringResourceBase() = default;
2971 
2978  virtual void Dispose() { delete this; }
2979 
2991  virtual void Lock() const {}
2992 
2996  virtual void Unlock() const {}
2997 
2998  private:
2999  friend class internal::ExternalString;
3000  friend class v8::String;
3001  friend class internal::ScopedExternalStringLock;
3002  };
3003 
3011  : public ExternalStringResourceBase {
3012  public:
3017  ~ExternalStringResource() override = default;
3018 
3022  virtual const uint16_t* data() const = 0;
3023 
3027  virtual size_t length() const = 0;
3028 
3029  protected:
3030  ExternalStringResource() = default;
3031  };
3032 
3044  : public ExternalStringResourceBase {
3045  public:
3050  ~ExternalOneByteStringResource() override = default;
3052  virtual const char* data() const = 0;
3054  virtual size_t length() const = 0;
3055  protected:
3056  ExternalOneByteStringResource() = default;
3057  };
3058 
3064  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
3065  Encoding* encoding_out) const;
3066 
3071  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
3072 
3077  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
3078 
3079  V8_INLINE static String* Cast(v8::Value* obj);
3080 
3083  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
3084  Isolate* isolate, const char* data,
3085  NewStringType type = NewStringType::kNormal, int length = -1);
3086 
3089  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
3090  Isolate* isolate, const uint8_t* data,
3091  NewStringType type = NewStringType::kNormal, int length = -1);
3092 
3095  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
3096  Isolate* isolate, const uint16_t* data,
3097  NewStringType type = NewStringType::kNormal, int length = -1);
3098 
3103  static Local<String> Concat(Isolate* isolate, Local<String> left,
3104  Local<String> right);
3105 
3114  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
3115  Isolate* isolate, ExternalStringResource* resource);
3116 
3126  bool MakeExternal(ExternalStringResource* resource);
3127 
3136  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
3137  Isolate* isolate, ExternalOneByteStringResource* resource);
3138 
3148  bool MakeExternal(ExternalOneByteStringResource* resource);
3149 
3153  bool CanMakeExternal();
3154 
3158  bool StringEquals(Local<String> str);
3159 
3168  public:
3169  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
3170  ~Utf8Value();
3171  char* operator*() { return str_; }
3172  const char* operator*() const { return str_; }
3173  int length() const { return length_; }
3174 
3175  // Disallow copying and assigning.
3176  Utf8Value(const Utf8Value&) = delete;
3177  void operator=(const Utf8Value&) = delete;
3178 
3179  private:
3180  char* str_;
3181  int length_;
3182  };
3183 
3191  public:
3192  Value(Isolate* isolate, Local<v8::Value> obj);
3193  ~Value();
3194  uint16_t* operator*() { return str_; }
3195  const uint16_t* operator*() const { return str_; }
3196  int length() const { return length_; }
3197 
3198  // Disallow copying and assigning.
3199  Value(const Value&) = delete;
3200  void operator=(const Value&) = delete;
3201 
3202  private:
3203  uint16_t* str_;
3204  int length_;
3205  };
3206 
3207  private:
3208  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
3209  Encoding encoding) const;
3210  void VerifyExternalStringResource(ExternalStringResource* val) const;
3211  ExternalStringResource* GetExternalStringResourceSlow() const;
3212  ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
3213  String::Encoding* encoding_out) const;
3214 
3215  static void CheckCast(v8::Value* obj);
3216 };
3217 
3218 
3222 class V8_EXPORT Symbol : public Name {
3223  public:
3227  Local<Value> Name() const;
3228 
3232  static Local<Symbol> New(Isolate* isolate,
3233  Local<String> name = Local<String>());
3234 
3242  static Local<Symbol> For(Isolate *isolate, Local<String> name);
3243 
3248  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
3249 
3250  // Well-known symbols
3251  static Local<Symbol> GetAsyncIterator(Isolate* isolate);
3252  static Local<Symbol> GetHasInstance(Isolate* isolate);
3253  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
3254  static Local<Symbol> GetIterator(Isolate* isolate);
3255  static Local<Symbol> GetMatch(Isolate* isolate);
3256  static Local<Symbol> GetReplace(Isolate* isolate);
3257  static Local<Symbol> GetSearch(Isolate* isolate);
3258  static Local<Symbol> GetSplit(Isolate* isolate);
3259  static Local<Symbol> GetToPrimitive(Isolate* isolate);
3260  static Local<Symbol> GetToStringTag(Isolate* isolate);
3261  static Local<Symbol> GetUnscopables(Isolate* isolate);
3262 
3263  V8_INLINE static Symbol* Cast(Value* obj);
3264 
3265  private:
3266  Symbol();
3267  static void CheckCast(Value* obj);
3268 };
3269 
3270 
3276 class V8_EXPORT Private : public Data {
3277  public:
3281  Local<Value> Name() const;
3282 
3286  static Local<Private> New(Isolate* isolate,
3287  Local<String> name = Local<String>());
3288 
3298  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3299 
3300  V8_INLINE static Private* Cast(Data* data);
3301 
3302  private:
3303  Private();
3304 
3305  static void CheckCast(Data* that);
3306 };
3307 
3308 
3312 class V8_EXPORT Number : public Primitive {
3313  public:
3314  double Value() const;
3315  static Local<Number> New(Isolate* isolate, double value);
3316  V8_INLINE static Number* Cast(v8::Value* obj);
3317  private:
3318  Number();
3319  static void CheckCast(v8::Value* obj);
3320 };
3321 
3322 
3326 class V8_EXPORT Integer : public Number {
3327  public:
3328  static Local<Integer> New(Isolate* isolate, int32_t value);
3329  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3330  int64_t Value() const;
3331  V8_INLINE static Integer* Cast(v8::Value* obj);
3332  private:
3333  Integer();
3334  static void CheckCast(v8::Value* obj);
3335 };
3336 
3337 
3341 class V8_EXPORT Int32 : public Integer {
3342  public:
3343  int32_t Value() const;
3344  V8_INLINE static Int32* Cast(v8::Value* obj);
3345 
3346  private:
3347  Int32();
3348  static void CheckCast(v8::Value* obj);
3349 };
3350 
3351 
3355 class V8_EXPORT Uint32 : public Integer {
3356  public:
3357  uint32_t Value() const;
3358  V8_INLINE static Uint32* Cast(v8::Value* obj);
3359 
3360  private:
3361  Uint32();
3362  static void CheckCast(v8::Value* obj);
3363 };
3364 
3368 class V8_EXPORT BigInt : public Primitive {
3369  public:
3370  static Local<BigInt> New(Isolate* isolate, int64_t value);
3371  static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3379  static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
3380  int word_count, const uint64_t* words);
3381 
3388  uint64_t Uint64Value(bool* lossless = nullptr) const;
3389 
3395  int64_t Int64Value(bool* lossless = nullptr) const;
3396 
3401  int WordCount() const;
3402 
3411  void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
3412 
3413  V8_INLINE static BigInt* Cast(v8::Value* obj);
3414 
3415  private:
3416  BigInt();
3417  static void CheckCast(v8::Value* obj);
3418 };
3419 
3425  None = 0,
3427  ReadOnly = 1 << 0,
3429  DontEnum = 1 << 1,
3431  DontDelete = 1 << 2
3432 };
3433 
3439 typedef void (*AccessorGetterCallback)(
3440  Local<String> property,
3441  const PropertyCallbackInfo<Value>& info);
3443  Local<Name> property,
3444  const PropertyCallbackInfo<Value>& info);
3445 
3446 
3447 typedef void (*AccessorSetterCallback)(
3448  Local<String> property,
3449  Local<Value> value,
3450  const PropertyCallbackInfo<void>& info);
3452  Local<Name> property,
3453  Local<Value> value,
3454  const PropertyCallbackInfo<void>& info);
3455 
3456 
3467  DEFAULT = 0,
3469  ALL_CAN_WRITE = 1 << 1,
3471 };
3472 
3483 };
3484 
3495 enum class SideEffectType {
3499 };
3500 
3509 
3515 
3521 
3526 
3530 class V8_EXPORT Object : public Value {
3531  public:
3537  Local<Value> key, Local<Value> value);
3538 
3539  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3540  Local<Value> value);
3541 
3542  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3543  //
3544  // Defines a configurable, writable, enumerable property with the given value
3545  // on the object unless the property already exists and is not configurable
3546  // or the object is not extensible.
3547  //
3548  // Returns true on success.
3549  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3550  Local<Name> key,
3551  Local<Value> value);
3552  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3553  uint32_t index,
3554  Local<Value> value);
3555 
3556  // Implements DefineOwnProperty.
3557  //
3558  // In general, CreateDataProperty will be faster, however, does not allow
3559  // for specifying attributes.
3560  //
3561  // Returns true on success.
3562  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3563  Local<Context> context, Local<Name> key, Local<Value> value,
3564  PropertyAttribute attributes = None);
3565 
3566  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3567  //
3568  // The defineProperty function is used to add an own property or
3569  // update the attributes of an existing own property of an object.
3570  //
3571  // Both data and accessor descriptors can be used.
3572  //
3573  // In general, CreateDataProperty is faster, however, does not allow
3574  // for specifying attributes or an accessor descriptor.
3575  //
3576  // The PropertyDescriptor can change when redefining a property.
3577  //
3578  // Returns true on success.
3579  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3580  Local<Context> context, Local<Name> key,
3581  PropertyDescriptor& descriptor); // NOLINT(runtime/references)
3582 
3584  Local<Value> key);
3585 
3587  uint32_t index);
3588 
3594  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3595  Local<Context> context, Local<Value> key);
3596 
3600  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3601  Local<Context> context, Local<Name> key);
3602 
3619  Local<Value> key);
3620 
3622  Local<Value> key);
3623 
3624  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3625 
3627  uint32_t index);
3628 
3632  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
3633  Local<Context> context, Local<Name> name,
3635  AccessorNameSetterCallback setter = nullptr,
3637  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3638  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3639  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3640 
3641  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3642  Local<Function> setter = Local<Function>(),
3643  PropertyAttribute attribute = None,
3644  AccessControl settings = DEFAULT);
3645 
3650  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3651  Local<Context> context, Local<Name> name,
3653  AccessorNameSetterCallback setter = nullptr,
3654  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
3655  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3656  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3657 
3666  V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
3667  Local<Context> context, Local<Name> name,
3669  PropertyAttribute attributes = None,
3670  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3671  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3672 
3679  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3680  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3681  Local<Value> value);
3682  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3683  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3684 
3691  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3692  Local<Context> context);
3693  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3694  Local<Context> context, KeyCollectionMode mode,
3695  PropertyFilter property_filter, IndexFilter index_filter,
3697 
3703  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3704  Local<Context> context);
3705 
3712  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3713  Local<Context> context, PropertyFilter filter,
3715 
3721  Local<Value> GetPrototype();
3722 
3728  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3729  Local<Value> prototype);
3730 
3735  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3736 
3742  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3743  Local<Context> context);
3744 
3748  Local<String> GetConstructorName();
3749 
3753  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3754 
3756  int InternalFieldCount();
3757 
3760  const PersistentBase<Object>& object) {
3761  return object.val_->InternalFieldCount();
3762  }
3763 
3766  const TracedReferenceBase<Object>& object) {
3767  return object.val_->InternalFieldCount();
3768  }
3769 
3771  V8_INLINE Local<Value> GetInternalField(int index);
3772 
3774  void SetInternalField(int index, Local<Value> value);
3775 
3781  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3782 
3785  const PersistentBase<Object>& object, int index) {
3786  return object.val_->GetAlignedPointerFromInternalField(index);
3787  }
3788 
3791  const TracedReferenceBase<Object>& object, int index) {
3792  return object.val_->GetAlignedPointerFromInternalField(index);
3793  }
3794 
3800  void SetAlignedPointerInInternalField(int index, void* value);
3801  void SetAlignedPointerInInternalFields(int argc, int indices[],
3802  void* values[]);
3803 
3809  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3810  Local<Name> key);
3811  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3812  uint32_t index);
3826  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3827  Local<Name> key);
3828  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3829  Local<Context> context, uint32_t index);
3830  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3831  Local<Context> context, Local<Name> key);
3832 
3837  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3838  Local<Context> context, Local<Name> key);
3839 
3846  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3847  Local<Name> key);
3848 
3854  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3855  Local<Context> context, Local<Name> key);
3856 
3862  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3863  Local<Context> context, Local<Name> key);
3864 
3866  bool HasNamedLookupInterceptor();
3867 
3869  bool HasIndexedLookupInterceptor();
3870 
3878  int GetIdentityHash();
3879 
3884  // TODO(dcarney): take an isolate and optionally bail out?
3885  Local<Object> Clone();
3886 
3890  Local<Context> CreationContext();
3891 
3894  const PersistentBase<Object>& object) {
3895  return object.val_->CreationContext();
3896  }
3897 
3903  bool IsCallable();
3904 
3908  bool IsConstructor();
3909 
3917  bool IsApiWrapper();
3918 
3924  Local<Value> recv,
3925  int argc,
3926  Local<Value> argv[]);
3927 
3933  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3934  Local<Context> context, int argc, Local<Value> argv[]);
3935 
3939  Isolate* GetIsolate();
3940 
3950  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3951 
3952  static Local<Object> New(Isolate* isolate);
3953 
3962  static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null,
3963  Local<Name>* names, Local<Value>* values,
3964  size_t length);
3965 
3966  V8_INLINE static Object* Cast(Value* obj);
3967 
3968  private:
3969  Object();
3970  static void CheckCast(Value* obj);
3971  Local<Value> SlowGetInternalField(int index);
3972  void* SlowGetAlignedPointerFromInternalField(int index);
3973 };
3974 
3975 
3979 class V8_EXPORT Array : public Object {
3980  public:
3981  uint32_t Length() const;
3982 
3987  static Local<Array> New(Isolate* isolate, int length = 0);
3988 
3993  static Local<Array> New(Isolate* isolate, Local<Value>* elements,
3994  size_t length);
3995  V8_INLINE static Array* Cast(Value* obj);
3996  private:
3997  Array();
3998  static void CheckCast(Value* obj);
3999 };
4000 
4001 
4005 class V8_EXPORT Map : public Object {
4006  public:
4007  size_t Size() const;
4008  void Clear();
4010  Local<Value> key);
4012  Local<Value> key,
4013  Local<Value> value);
4015  Local<Value> key);
4017  Local<Value> key);
4018 
4023  Local<Array> AsArray() const;
4024 
4028  static Local<Map> New(Isolate* isolate);
4029 
4030  V8_INLINE static Map* Cast(Value* obj);
4031 
4032  private:
4033  Map();
4034  static void CheckCast(Value* obj);
4035 };
4036 
4037 
4041 class V8_EXPORT Set : public Object {
4042  public:
4043  size_t Size() const;
4044  void Clear();
4046  Local<Value> key);
4048  Local<Value> key);
4050  Local<Value> key);
4051 
4055  Local<Array> AsArray() const;
4056 
4060  static Local<Set> New(Isolate* isolate);
4061 
4062  V8_INLINE static Set* Cast(Value* obj);
4063 
4064  private:
4065  Set();
4066  static void CheckCast(Value* obj);
4067 };
4068 
4069 
4070 template<typename T>
4071 class ReturnValue {
4072  public:
4073  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
4074  : value_(that.value_) {
4075  TYPE_CHECK(T, S);
4076  }
4077  // Local setters
4078  template <typename S>
4079  V8_INLINE void Set(const Global<S>& handle);
4080  template <typename S>
4081  V8_INLINE void Set(const TracedReferenceBase<S>& handle);
4082  template <typename S>
4083  V8_INLINE void Set(const Local<S> handle);
4084  // Fast primitive setters
4085  V8_INLINE void Set(bool value);
4086  V8_INLINE void Set(double i);
4087  V8_INLINE void Set(int32_t i);
4088  V8_INLINE void Set(uint32_t i);
4089  // Fast JS primitive setters
4090  V8_INLINE void SetNull();
4091  V8_INLINE void SetUndefined();
4092  V8_INLINE void SetEmptyString();
4093  // Convenience getter for Isolate
4094  V8_INLINE Isolate* GetIsolate() const;
4095 
4096  // Pointer setter: Uncompilable to prevent inadvertent misuse.
4097  template <typename S>
4098  V8_INLINE void Set(S* whatever);
4099 
4100  // Getter. Creates a new Local<> so it comes with a certain performance
4101  // hit. If the ReturnValue was not yet set, this will return the undefined
4102  // value.
4103  V8_INLINE Local<Value> Get() const;
4104 
4105  private:
4106  template<class F> friend class ReturnValue;
4107  template<class F> friend class FunctionCallbackInfo;
4108  template<class F> friend class PropertyCallbackInfo;
4109  template <class F, class G, class H>
4111  V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
4112  V8_INLINE internal::Address GetDefaultValue();
4113  V8_INLINE explicit ReturnValue(internal::Address* slot);
4114  internal::Address* value_;
4115 };
4116 
4117 
4124 template<typename T>
4125 class FunctionCallbackInfo {
4126  public:
4128  V8_INLINE int Length() const;
4130  V8_INLINE Local<Value> operator[](int i) const;
4132  V8_INLINE Local<Object> This() const;
4143  V8_INLINE Local<Object> Holder() const;
4145  V8_INLINE Local<Value> NewTarget() const;
4147  V8_INLINE bool IsConstructCall() const;
4149  V8_INLINE Local<Value> Data() const;
4151  V8_INLINE Isolate* GetIsolate() const;
4153  V8_INLINE ReturnValue<T> GetReturnValue() const;
4154  // This shouldn't be public, but the arm compiler needs it.
4155  static const int kArgsLength = 6;
4156 
4157  protected:
4161  static const int kHolderIndex = 0;
4162  static const int kIsolateIndex = 1;
4163  static const int kReturnValueDefaultValueIndex = 2;
4164  static const int kReturnValueIndex = 3;
4165  static const int kDataIndex = 4;
4166  static const int kNewTargetIndex = 5;
4167 
4169  internal::Address* values, int length);
4172  int length_;
4173 };
4174 
4175 
4180 template<typename T>
4181 class PropertyCallbackInfo {
4182  public:
4186  V8_INLINE Isolate* GetIsolate() const;
4187 
4193  V8_INLINE Local<Value> Data() const;
4194 
4236  V8_INLINE Local<Object> This() const;
4237 
4247  V8_INLINE Local<Object> Holder() const;
4248 
4258 
4266  V8_INLINE bool ShouldThrowOnError() const;
4267 
4268  // This shouldn't be public, but the arm compiler needs it.
4269  static const int kArgsLength = 7;
4270 
4271  protected:
4272  friend class MacroAssembler;
4273  friend class internal::PropertyCallbackArguments;
4275  static const int kShouldThrowOnErrorIndex = 0;
4276  static const int kHolderIndex = 1;
4277  static const int kIsolateIndex = 2;
4278  static const int kReturnValueDefaultValueIndex = 3;
4279  static const int kReturnValueIndex = 4;
4280  static const int kDataIndex = 5;
4281  static const int kThisIndex = 6;
4282 
4285 };
4286 
4287 
4288 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
4289 
4291 
4295 class V8_EXPORT Function : public Object {
4296  public:
4301  static MaybeLocal<Function> New(
4302  Local<Context> context, FunctionCallback callback,
4303  Local<Value> data = Local<Value>(), int length = 0,
4305  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4306 
4308  Local<Context> context, int argc, Local<Value> argv[]) const;
4309 
4311  Local<Context> context) const {
4312  return NewInstance(context, 0, nullptr);
4313  }
4314 
4320  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
4321  Local<Context> context, int argc, Local<Value> argv[],
4322  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4323 
4325  Local<Value> recv, int argc,
4326  Local<Value> argv[]);
4327 
4328  void SetName(Local<String> name);
4329  Local<Value> GetName() const;
4330 
4337  Local<Value> GetInferredName() const;
4338 
4343  Local<Value> GetDebugName() const;
4344 
4349  Local<Value> GetDisplayName() const;
4350 
4355  int GetScriptLineNumber() const;
4360  int GetScriptColumnNumber() const;
4361 
4365  int ScriptId() const;
4366 
4371  Local<Value> GetBoundFunction() const;
4372 
4373  ScriptOrigin GetScriptOrigin() const;
4374  V8_INLINE static Function* Cast(Value* obj);
4375  static const int kLineOffsetNotFound;
4376 
4377  private:
4378  Function();
4379  static void CheckCast(Value* obj);
4380 };
4381 
4382 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4383 // The number of required internal fields can be defined by embedder.
4384 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4385 #endif
4386 
4390 class V8_EXPORT Promise : public Object {
4391  public:
4396  enum PromiseState { kPending, kFulfilled, kRejected };
4397 
4398  class V8_EXPORT Resolver : public Object {
4399  public:
4404  Local<Context> context);
4405 
4409  Local<Promise> GetPromise();
4410 
4416  Local<Value> value);
4417 
4419  Local<Value> value);
4420 
4421  V8_INLINE static Resolver* Cast(Value* obj);
4422 
4423  private:
4424  Resolver();
4425  static void CheckCast(Value* obj);
4426  };
4427 
4435  Local<Function> handler);
4436 
4438  Local<Function> handler);
4439 
4441  Local<Function> on_fulfilled,
4442  Local<Function> on_rejected);
4443 
4448  bool HasHandler();
4449 
4454  Local<Value> Result();
4455 
4459  PromiseState State();
4460 
4464  void MarkAsHandled();
4465 
4466  V8_INLINE static Promise* Cast(Value* obj);
4467 
4468  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4469 
4470  private:
4471  Promise();
4472  static void CheckCast(Value* obj);
4473 };
4474 
4504  public:
4505  // GenericDescriptor
4507 
4508  // DataDescriptor
4509  explicit PropertyDescriptor(Local<Value> value);
4510 
4511  // DataDescriptor with writable property
4512  PropertyDescriptor(Local<Value> value, bool writable);
4513 
4514  // AccessorDescriptor
4516 
4517  ~PropertyDescriptor();
4518 
4519  Local<Value> value() const;
4520  bool has_value() const;
4521 
4522  Local<Value> get() const;
4523  bool has_get() const;
4524  Local<Value> set() const;
4525  bool has_set() const;
4526 
4527  void set_enumerable(bool enumerable);
4528  bool enumerable() const;
4529  bool has_enumerable() const;
4530 
4531  void set_configurable(bool configurable);
4532  bool configurable() const;
4533  bool has_configurable() const;
4534 
4535  bool writable() const;
4536  bool has_writable() const;
4537 
4538  struct PrivateData;
4539  PrivateData* get_private() const { return private_; }
4540 
4541  PropertyDescriptor(const PropertyDescriptor&) = delete;
4542  void operator=(const PropertyDescriptor&) = delete;
4543 
4544  private:
4545  PrivateData* private_;
4546 };
4547 
4552 class V8_EXPORT Proxy : public Object {
4553  public:
4554  Local<Value> GetTarget();
4555  Local<Value> GetHandler();
4556  bool IsRevoked();
4557  void Revoke();
4558 
4562  static MaybeLocal<Proxy> New(Local<Context> context,
4563  Local<Object> local_target,
4564  Local<Object> local_handler);
4565 
4566  V8_INLINE static Proxy* Cast(Value* obj);
4567 
4568  private:
4569  Proxy();
4570  static void CheckCast(Value* obj);
4571 };
4572 
4583 template <typename T>
4585  public:
4587  constexpr MemorySpan() = default;
4588 
4589  constexpr MemorySpan(T* data, size_t size) : data_(data), size_(size) {}
4590 
4592  constexpr T* data() const { return data_; }
4594  constexpr size_t size() const { return size_; }
4595 
4596  private:
4597  T* data_ = nullptr;
4598  size_t size_ = 0;
4599 };
4600 
4604 struct OwnedBuffer {
4605  std::unique_ptr<const uint8_t[]> buffer;
4606  size_t size = 0;
4607  OwnedBuffer(std::unique_ptr<const uint8_t[]> buffer, size_t size)
4608  : buffer(std::move(buffer)), size(size) {}
4609  OwnedBuffer() = default;
4610 };
4611 
4612 // Wrapper around a compiled WebAssembly module, which is potentially shared by
4613 // different WasmModuleObjects.
4615  public:
4620  OwnedBuffer Serialize();
4621 
4625  MemorySpan<const uint8_t> GetWireBytesRef();
4626 
4627  private:
4628  explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>);
4629  friend class Utils;
4630 
4631  const std::shared_ptr<internal::wasm::NativeModule> native_module_;
4632 };
4633 
4634 // An instance of WebAssembly.Module.
4636  public:
4637  WasmModuleObject() = delete;
4638 
4643  using TransferrableModule V8_DEPRECATED("Use CompiledWasmModule directly") =
4645 
4651  V8_DEPRECATED("Use GetCompiledModule")
4652  TransferrableModule GetTransferrableModule();
4653 
4658  V8_DEPRECATED("Use FromCompiledModule")
4659  static MaybeLocal<WasmModuleObject> FromTransferrableModule(
4660  Isolate* isolate, const TransferrableModule&);
4661 
4666  static MaybeLocal<WasmModuleObject> FromCompiledModule(
4667  Isolate* isolate, const CompiledWasmModule&);
4668 
4673  CompiledWasmModule GetCompiledModule();
4674 
4679  static MaybeLocal<WasmModuleObject> DeserializeOrCompile(
4680  Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
4681  MemorySpan<const uint8_t> wire_bytes);
4682  V8_INLINE static WasmModuleObject* Cast(Value* obj);
4683 
4684  private:
4685  static MaybeLocal<WasmModuleObject> Deserialize(
4686  Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
4687  MemorySpan<const uint8_t> wire_bytes);
4688  static MaybeLocal<WasmModuleObject> Compile(Isolate* isolate,
4689  const uint8_t* start,
4690  size_t length);
4691 
4692  static void CheckCast(Value* obj);
4693 };
4694 
4702  public:
4703  class WasmStreamingImpl;
4704 
4708  class Client {
4709  public:
4710  virtual ~Client() = default;
4715  virtual void OnModuleCompiled(CompiledWasmModule compiled_module) = 0;
4716  };
4717 
4718  explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
4719 
4720  ~WasmStreaming();
4721 
4726  void OnBytesReceived(const uint8_t* bytes, size_t size);
4727 
4733  void Finish();
4734 
4740  void Abort(MaybeLocal<Value> exception);
4741 
4749  bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size);
4750 
4755  void SetClient(std::shared_ptr<Client> client);
4756 
4762  static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
4763  Local<Value> value);
4764 
4765  private:
4766  std::unique_ptr<WasmStreamingImpl> impl_;
4767 };
4768 
4769 // TODO(mtrofin): when streaming compilation is done, we can rename this
4770 // to simply WasmModuleObjectBuilder
4772  public:
4773  explicit WasmModuleObjectBuilderStreaming(Isolate* isolate);
4777  void OnBytesReceived(const uint8_t*, size_t size);
4778  void Finish();
4784  void Abort(MaybeLocal<Value> exception);
4785  Local<Promise> GetPromise();
4786 
4787  ~WasmModuleObjectBuilderStreaming() = default;
4788 
4789  private:
4791  delete;
4793  default;
4795  const WasmModuleObjectBuilderStreaming&) = delete;
4797  WasmModuleObjectBuilderStreaming&&) = default;
4798  Isolate* isolate_ = nullptr;
4799 
4800 #if V8_CC_MSVC
4801 
4809 #else
4810  Persistent<Promise> promise_;
4811 #endif
4812  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4813 };
4814 
4815 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4816 // The number of required internal fields can be defined by embedder.
4817 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4818 #endif
4819 
4820 
4822 
4832  public:
4833  ~BackingStore();
4834 
4840  void* Data() const;
4841 
4845  size_t ByteLength() const;
4846 
4847  private:
4848  BackingStore();
4849 };
4850 
4854 class V8_EXPORT ArrayBuffer : public Object {
4855  public:
4871  class V8_EXPORT Allocator { // NOLINT
4872  public:
4873  virtual ~Allocator() = default;
4874 
4879  virtual void* Allocate(size_t length) = 0;
4880 
4885  virtual void* AllocateUninitialized(size_t length) = 0;
4886 
4891  virtual void Free(void* data, size_t length) = 0;
4892 
4898  enum class AllocationMode { kNormal, kReservation };
4899 
4906  static Allocator* NewDefaultAllocator();
4907  };
4908 
4918  class V8_EXPORT Contents { // NOLINT
4919  public:
4920  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
4921 
4923  : data_(nullptr),
4924  byte_length_(0),
4925  allocation_base_(nullptr),
4926  allocation_length_(0),
4927  allocation_mode_(Allocator::AllocationMode::kNormal),
4928  deleter_(nullptr),
4929  deleter_data_(nullptr) {}
4930 
4931  void* AllocationBase() const { return allocation_base_; }
4932  size_t AllocationLength() const { return allocation_length_; }
4934  return allocation_mode_;
4935  }
4936 
4937  void* Data() const { return data_; }
4938  size_t ByteLength() const { return byte_length_; }
4939  DeleterCallback Deleter() const { return deleter_; }
4940  void* DeleterData() const { return deleter_data_; }
4941 
4942  private:
4943  Contents(void* data, size_t byte_length, void* allocation_base,
4944  size_t allocation_length,
4945  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
4946  void* deleter_data);
4947 
4948  void* data_;
4949  size_t byte_length_;
4950  void* allocation_base_;
4951  size_t allocation_length_;
4952  Allocator::AllocationMode allocation_mode_;
4953  DeleterCallback deleter_;
4954  void* deleter_data_;
4955 
4956  friend class ArrayBuffer;
4957  };
4958 
4959 
4963  size_t ByteLength() const;
4964 
4971  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4972 
4982  static Local<ArrayBuffer> New(
4983  Isolate* isolate, void* data, size_t byte_length,
4985 
4998  static Local<ArrayBuffer> New(Isolate* isolate,
4999  std::shared_ptr<BackingStore> backing_store);
5000 
5005  bool IsExternal() const;
5006 
5010  bool IsDetachable() const;
5011 
5018  void Detach();
5019 
5030  Contents Externalize();
5031 
5039  void Externalize(const std::shared_ptr<BackingStore>& backing_store);
5040 
5049  Contents GetContents();
5050 
5059  std::shared_ptr<BackingStore> GetBackingStore();
5060 
5061  V8_INLINE static ArrayBuffer* Cast(Value* obj);
5062 
5063  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5064  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5065 
5066  private:
5067  ArrayBuffer();
5068  static void CheckCast(Value* obj);
5069  Contents GetContents(bool externalize);
5070 };
5071 
5072 
5073 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
5074 // The number of required internal fields can be defined by embedder.
5075 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
5076 #endif
5077 
5078 
5084  public:
5088  Local<ArrayBuffer> Buffer();
5092  size_t ByteOffset();
5096  size_t ByteLength();
5097 
5107  size_t CopyContents(void* dest, size_t byte_length);
5108 
5113  bool HasBuffer() const;
5114 
5115  V8_INLINE static ArrayBufferView* Cast(Value* obj);
5116 
5117  static const int kInternalFieldCount =
5119  static const int kEmbedderFieldCount =
5121 
5122  private:
5123  ArrayBufferView();
5124  static void CheckCast(Value* obj);
5125 };
5126 
5127 
5133  public:
5134  /*
5135  * The largest typed array size that can be constructed using New.
5136  */
5137  static constexpr size_t kMaxLength = internal::kSmiMaxValue;
5138 
5143  size_t Length();
5144 
5145  V8_INLINE static TypedArray* Cast(Value* obj);
5146 
5147  private:
5148  TypedArray();
5149  static void CheckCast(Value* obj);
5150 };
5151 
5152 
5157  public:
5158  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
5159  size_t byte_offset, size_t length);
5160  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5161  size_t byte_offset, size_t length);
5162  V8_INLINE static Uint8Array* Cast(Value* obj);
5163 
5164  private:
5165  Uint8Array();
5166  static void CheckCast(Value* obj);
5167 };
5168 
5169 
5174  public:
5175  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
5176  size_t byte_offset, size_t length);
5177  static Local<Uint8ClampedArray> New(
5178  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
5179  size_t length);
5180  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
5181 
5182  private:
5184  static void CheckCast(Value* obj);
5185 };
5186 
5191  public:
5192  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
5193  size_t byte_offset, size_t length);
5194  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5195  size_t byte_offset, size_t length);
5196  V8_INLINE static Int8Array* Cast(Value* obj);
5197 
5198  private:
5199  Int8Array();
5200  static void CheckCast(Value* obj);
5201 };
5202 
5203 
5208  public:
5209  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
5210  size_t byte_offset, size_t length);
5211  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5212  size_t byte_offset, size_t length);
5213  V8_INLINE static Uint16Array* Cast(Value* obj);
5214 
5215  private:
5216  Uint16Array();
5217  static void CheckCast(Value* obj);
5218 };
5219 
5220 
5225  public:
5226  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
5227  size_t byte_offset, size_t length);
5228  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5229  size_t byte_offset, size_t length);
5230  V8_INLINE static Int16Array* Cast(Value* obj);
5231 
5232  private:
5233  Int16Array();
5234  static void CheckCast(Value* obj);
5235 };
5236 
5237 
5242  public:
5243  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
5244  size_t byte_offset, size_t length);
5245  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5246  size_t byte_offset, size_t length);
5247  V8_INLINE static Uint32Array* Cast(Value* obj);
5248 
5249  private:
5250  Uint32Array();
5251  static void CheckCast(Value* obj);
5252 };
5253 
5254 
5259  public:
5260  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
5261  size_t byte_offset, size_t length);
5262  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5263  size_t byte_offset, size_t length);
5264  V8_INLINE static Int32Array* Cast(Value* obj);
5265 
5266  private:
5267  Int32Array();
5268  static void CheckCast(Value* obj);
5269 };
5270 
5271 
5276  public:
5277  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
5278  size_t byte_offset, size_t length);
5279  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5280  size_t byte_offset, size_t length);
5281  V8_INLINE static Float32Array* Cast(Value* obj);
5282 
5283  private:
5284  Float32Array();
5285  static void CheckCast(Value* obj);
5286 };
5287 
5288 
5293  public:
5294  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
5295  size_t byte_offset, size_t length);
5296  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5297  size_t byte_offset, size_t length);
5298  V8_INLINE static Float64Array* Cast(Value* obj);
5299 
5300  private:
5301  Float64Array();
5302  static void CheckCast(Value* obj);
5303 };
5304 
5309  public:
5310  static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
5311  size_t byte_offset, size_t length);
5312  static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5313  size_t byte_offset, size_t length);
5314  V8_INLINE static BigInt64Array* Cast(Value* obj);
5315 
5316  private:
5317  BigInt64Array();
5318  static void CheckCast(Value* obj);
5319 };
5320 
5325  public:
5326  static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
5327  size_t byte_offset, size_t length);
5328  static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5329  size_t byte_offset, size_t length);
5330  V8_INLINE static BigUint64Array* Cast(Value* obj);
5331 
5332  private:
5333  BigUint64Array();
5334  static void CheckCast(Value* obj);
5335 };
5336 
5341  public:
5342  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
5343  size_t byte_offset, size_t length);
5344  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
5345  size_t byte_offset, size_t length);
5346  V8_INLINE static DataView* Cast(Value* obj);
5347 
5348  private:
5349  DataView();
5350  static void CheckCast(Value* obj);
5351 };
5352 
5353 
5359  public:
5371  class V8_EXPORT Contents { // NOLINT
5372  public:
5374  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
5375 
5377  : data_(nullptr),
5378  byte_length_(0),
5379  allocation_base_(nullptr),
5380  allocation_length_(0),
5381  allocation_mode_(Allocator::AllocationMode::kNormal),
5382  deleter_(nullptr),
5383  deleter_data_(nullptr) {}
5384 
5385  void* AllocationBase() const { return allocation_base_; }
5386  size_t AllocationLength() const { return allocation_length_; }
5388  return allocation_mode_;
5389  }
5390 
5391  void* Data() const { return data_; }
5392  size_t ByteLength() const { return byte_length_; }
5393  DeleterCallback Deleter() const { return deleter_; }
5394  void* DeleterData() const { return deleter_data_; }
5395 
5396  private:
5397  Contents(void* data, size_t byte_length, void* allocation_base,
5398  size_t allocation_length,
5399  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
5400  void* deleter_data);
5401 
5402  void* data_;
5403  size_t byte_length_;
5404  void* allocation_base_;
5405  size_t allocation_length_;
5406  Allocator::AllocationMode allocation_mode_;
5407  DeleterCallback deleter_;
5408  void* deleter_data_;
5409 
5410  friend class SharedArrayBuffer;
5411  };
5412 
5416  size_t ByteLength() const;
5417 
5424  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
5425 
5432  static Local<SharedArrayBuffer> New(
5433  Isolate* isolate, void* data, size_t byte_length,
5435 
5448  static Local<SharedArrayBuffer> New(
5449  Isolate* isolate, std::shared_ptr<BackingStore> backing_store);
5450 
5455  V8_DEPRECATED("Use New method with data, and byte_length instead.")
5456  static Local<SharedArrayBuffer> New(
5457  Isolate* isolate, const SharedArrayBuffer::Contents&,
5459 
5464  bool IsExternal() const;
5465 
5478  Contents Externalize();
5479 
5487  void Externalize(const std::shared_ptr<BackingStore>& backing_store);
5488 
5501  Contents GetContents();
5502 
5511  std::shared_ptr<BackingStore> GetBackingStore();
5512 
5513  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
5514 
5515  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5516 
5517  private:
5519  static void CheckCast(Value* obj);
5520  Contents GetContents(bool externalize);
5521 };
5522 
5523 
5527 class V8_EXPORT Date : public Object {
5528  public:
5530  double time);
5531 
5536  double ValueOf() const;
5537 
5538  V8_INLINE static Date* Cast(Value* obj);
5539 
5540  private:
5541  static void CheckCast(Value* obj);
5542 };
5543 
5544 
5549  public:
5550  static Local<Value> New(Isolate* isolate, double value);
5551 
5552  double ValueOf() const;
5553 
5554  V8_INLINE static NumberObject* Cast(Value* obj);
5555 
5556  private:
5557  static void CheckCast(Value* obj);
5558 };
5559 
5564  public:
5565  static Local<Value> New(Isolate* isolate, int64_t value);
5566 
5567  Local<BigInt> ValueOf() const;
5568 
5569  V8_INLINE static BigIntObject* Cast(Value* obj);
5570 
5571  private:
5572  static void CheckCast(Value* obj);
5573 };
5574 
5579  public:
5580  static Local<Value> New(Isolate* isolate, bool value);
5581 
5582  bool ValueOf() const;
5583 
5584  V8_INLINE static BooleanObject* Cast(Value* obj);
5585 
5586  private:
5587  static void CheckCast(Value* obj);
5588 };
5589 
5590 
5595  public:
5596  static Local<Value> New(Isolate* isolate, Local<String> value);
5597 
5598  Local<String> ValueOf() const;
5599 
5600  V8_INLINE static StringObject* Cast(Value* obj);
5601 
5602  private:
5603  static void CheckCast(Value* obj);
5604 };
5605 
5606 
5611  public:
5612  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
5613 
5614  Local<Symbol> ValueOf() const;
5615 
5616  V8_INLINE static SymbolObject* Cast(Value* obj);
5617 
5618  private:
5619  static void CheckCast(Value* obj);
5620 };
5621 
5622 
5626 class V8_EXPORT RegExp : public Object {
5627  public:
5632  enum Flags {
5633  kNone = 0,
5634  kGlobal = 1 << 0,
5635  kIgnoreCase = 1 << 1,
5636  kMultiline = 1 << 2,
5637  kSticky = 1 << 3,
5638  kUnicode = 1 << 4,
5639  kDotAll = 1 << 5,
5640  };
5641 
5642  static constexpr int kFlagCount = 6;
5643 
5655  Local<String> pattern,
5656  Flags flags);
5657 
5662  Local<String> GetSource() const;
5663 
5667  Flags GetFlags() const;
5668 
5669  V8_INLINE static RegExp* Cast(Value* obj);
5670 
5671  private:
5672  static void CheckCast(Value* obj);
5673 };
5674 
5681  public:
5698  static V8_WARN_UNUSED_RESULT Maybe<bool> Cleanup(
5699  Local<FinalizationGroup> finalization_group);
5700 };
5701 
5706 class V8_EXPORT External : public Value {
5707  public:
5708  static Local<External> New(Isolate* isolate, void* value);
5709  V8_INLINE static External* Cast(Value* obj);
5710  void* Value() const;
5711  private:
5712  static void CheckCast(v8::Value* obj);
5713 };
5714 
5715 #define V8_INTRINSICS_LIST(F) \
5716  F(ArrayProto_entries, array_entries_iterator) \
5717  F(ArrayProto_forEach, array_for_each_iterator) \
5718  F(ArrayProto_keys, array_keys_iterator) \
5719  F(ArrayProto_values, array_values_iterator) \
5720  F(ErrorPrototype, initial_error_prototype) \
5721  F(IteratorPrototype, initial_iterator_prototype)
5722 
5724 #define V8_DECL_INTRINSIC(name, iname) k##name,
5726 #undef V8_DECL_INTRINSIC
5727 };
5728 
5729 
5730 // --- Templates ---
5731 
5732 
5736 class V8_EXPORT Template : public Data {
5737  public:
5743  void Set(Local<Name> name, Local<Data> value,
5744  PropertyAttribute attributes = None);
5745  void SetPrivate(Local<Private> name, Local<Data> value,
5746  PropertyAttribute attributes = None);
5747  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5748 
5749  void SetAccessorProperty(
5750  Local<Name> name,
5753  PropertyAttribute attribute = None,
5754  AccessControl settings = DEFAULT);
5755 
5783  void SetNativeDataProperty(
5785  AccessorSetterCallback setter = nullptr,
5786  // TODO(dcarney): gcc can't handle Local below
5787  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5789  AccessControl settings = DEFAULT,
5790  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5791  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5792  void SetNativeDataProperty(
5794  AccessorNameSetterCallback setter = nullptr,
5795  // TODO(dcarney): gcc can't handle Local below
5796  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5798  AccessControl settings = DEFAULT,
5799  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5800  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5801 
5806  void SetLazyDataProperty(
5808  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5809  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5810  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5811 
5816  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5817  PropertyAttribute attribute = None);
5818 
5819  private:
5820  Template();
5821 
5822  friend class ObjectTemplate;
5823  friend class FunctionTemplate;
5824 };
5825 
5826 // TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
5827 // NamedPropertyFooCallback.
5828 
5866  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5867 
5890  Local<Name> property, Local<Value> value,
5891  const PropertyCallbackInfo<Value>& info);
5892 
5915  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5916 
5939  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5940 
5948  const PropertyCallbackInfo<Array>& info);
5949 
5971  Local<Name> property, const PropertyDescriptor& desc,
5972  const PropertyCallbackInfo<Value>& info);
5973 
5994  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5995 
6000  uint32_t index,
6001  const PropertyCallbackInfo<Value>& info);
6002 
6007  uint32_t index,
6008  Local<Value> value,
6009  const PropertyCallbackInfo<Value>& info);
6010 
6015  uint32_t index,
6016  const PropertyCallbackInfo<Integer>& info);
6017 
6022  uint32_t index,
6023  const PropertyCallbackInfo<Boolean>& info);
6024 
6032  const PropertyCallbackInfo<Array>& info);
6033 
6038  uint32_t index, const PropertyDescriptor& desc,
6039  const PropertyCallbackInfo<Value>& info);
6040 
6045  uint32_t index, const PropertyCallbackInfo<Value>& info);
6046 
6056 };
6057 
6058 
6063 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
6064  Local<Object> accessed_object,
6065  Local<Value> data);
6066 
6168  public:
6170  static Local<FunctionTemplate> New(
6171  Isolate* isolate, FunctionCallback callback = nullptr,
6172  Local<Value> data = Local<Value>(),
6173  Local<Signature> signature = Local<Signature>(), int length = 0,
6175  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
6176 
6178  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
6179  size_t index);
6180 
6184  static Local<FunctionTemplate> NewWithCache(
6185  Isolate* isolate, FunctionCallback callback,
6186  Local<Private> cache_property, Local<Value> data = Local<Value>(),
6187  Local<Signature> signature = Local<Signature>(), int length = 0,
6188  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
6189 
6192  Local<Context> context);
6193 
6201  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
6202 
6208  void SetCallHandler(
6209  FunctionCallback callback, Local<Value> data = Local<Value>(),
6210  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
6211 
6213  void SetLength(int length);
6214 
6216  Local<ObjectTemplate> InstanceTemplate();
6217 
6223  void Inherit(Local<FunctionTemplate> parent);
6224 
6229  Local<ObjectTemplate> PrototypeTemplate();
6230 
6237  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
6238 
6244  void SetClassName(Local<String> name);
6245 
6246 
6251  void SetAcceptAnyReceiver(bool value);
6252 
6257  void ReadOnlyPrototype();
6258 
6263  void RemovePrototype();
6264 
6269  bool HasInstance(Local<Value> object);
6270 
6271  V8_INLINE static FunctionTemplate* Cast(Data* data);
6272 
6273  private:
6274  FunctionTemplate();
6275 
6276  static void CheckCast(Data* that);
6277  friend class Context;
6278  friend class ObjectTemplate;
6279 };
6280 
6289  kNone = 0,
6290 
6294  kAllCanRead = 1,
6295 
6300  kNonMasking = 1 << 1,
6301 
6306  kOnlyInterceptStrings = 1 << 2,
6307 
6311  kHasNoSideEffect = 1 << 3,
6312 };
6313 
6323  Local<Value> data = Local<Value>(),
6325  : getter(getter),
6326  setter(setter),
6327  query(query),
6328  deleter(deleter),
6329  enumerator(enumerator),
6330  definer(definer),
6331  descriptor(descriptor),
6332  data(data),
6333  flags(flags) {}
6334 
6337  GenericNamedPropertyGetterCallback getter = nullptr,
6338  GenericNamedPropertySetterCallback setter = nullptr,
6339  GenericNamedPropertyQueryCallback query = nullptr,
6340  GenericNamedPropertyDeleterCallback deleter = nullptr,
6341  GenericNamedPropertyEnumeratorCallback enumerator = nullptr,
6342  Local<Value> data = Local<Value>(),
6344  : getter(getter),
6345  setter(setter),
6346  query(query),
6347  deleter(deleter),
6348  enumerator(enumerator),
6349  definer(nullptr),
6350  descriptor(nullptr),
6351  data(data),
6352  flags(flags) {}
6353 
6361  Local<Value> data = Local<Value>(),
6363  : getter(getter),
6364  setter(setter),
6365  query(nullptr),
6366  deleter(deleter),
6367  enumerator(enumerator),
6368  definer(definer),
6369  descriptor(descriptor),
6370  data(data),
6371  flags(flags) {}
6372 
6382 };
6383 
6384 
6393  Local<Value> data = Local<Value>(),
6395  : getter(getter),
6396  setter(setter),
6397  query(query),
6398  deleter(deleter),
6399  enumerator(enumerator),
6400  definer(definer),
6401  descriptor(descriptor),
6402  data(data),
6403  flags(flags) {}
6404 
6407  IndexedPropertyGetterCallback getter = nullptr,
6408  IndexedPropertySetterCallback setter = nullptr,
6409  IndexedPropertyQueryCallback query = nullptr,
6410  IndexedPropertyDeleterCallback deleter = nullptr,
6411  IndexedPropertyEnumeratorCallback enumerator = nullptr,
6412  Local<Value> data = Local<Value>(),
6414  : getter(getter),
6415  setter(setter),
6416  query(query),
6417  deleter(deleter),
6418  enumerator(enumerator),
6419  definer(nullptr),
6420  descriptor(nullptr),
6421  data(data),
6422  flags(flags) {}
6423 
6431  Local<Value> data = Local<Value>(),
6433  : getter(getter),
6434  setter(setter),
6435  query(nullptr),
6436  deleter(deleter),
6437  enumerator(enumerator),
6438  definer(definer),
6439  descriptor(descriptor),
6440  data(data),
6441  flags(flags) {}
6442 
6452 };
6453 
6454 
6462  public:
6464  static Local<ObjectTemplate> New(
6465  Isolate* isolate,
6467 
6469  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
6470  size_t index);
6471 
6474 
6504  void SetAccessor(
6506  AccessorSetterCallback setter = nullptr,
6507  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
6508  PropertyAttribute attribute = None,
6510  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6511  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6512  void SetAccessor(
6514  AccessorNameSetterCallback setter = nullptr,
6515  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
6516  PropertyAttribute attribute = None,
6518  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6519  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6520 
6532  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
6533 
6550  // TODO(dcarney): deprecate
6553  IndexedPropertySetterCallback setter = nullptr,
6554  IndexedPropertyQueryCallback query = nullptr,
6555  IndexedPropertyDeleterCallback deleter = nullptr,
6556  IndexedPropertyEnumeratorCallback enumerator = nullptr,
6557  Local<Value> data = Local<Value>()) {
6558  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
6559  deleter, enumerator, data));
6560  }
6561 
6572  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
6573 
6580  void SetCallAsFunctionHandler(FunctionCallback callback,
6581  Local<Value> data = Local<Value>());
6582 
6591  void MarkAsUndetectable();
6592 
6601  void SetAccessCheckCallback(AccessCheckCallback callback,
6602  Local<Value> data = Local<Value>());
6603 
6610  void SetAccessCheckCallbackAndHandler(
6611  AccessCheckCallback callback,
6612  const NamedPropertyHandlerConfiguration& named_handler,
6613  const IndexedPropertyHandlerConfiguration& indexed_handler,
6614  Local<Value> data = Local<Value>());
6615 
6620  int InternalFieldCount();
6621 
6626  void SetInternalFieldCount(int value);
6627 
6631  bool IsImmutableProto();
6632 
6637  void SetImmutableProto();
6638 
6639  V8_INLINE static ObjectTemplate* Cast(Data* data);
6640 
6641  private:
6642  ObjectTemplate();
6643  static Local<ObjectTemplate> New(internal::Isolate* isolate,
6644  Local<FunctionTemplate> constructor);
6645  static void CheckCast(Data* that);
6646  friend class FunctionTemplate;
6647 };
6648 
6657 class V8_EXPORT Signature : public Data {
6658  public:
6659  static Local<Signature> New(
6660  Isolate* isolate,
6662 
6663  V8_INLINE static Signature* Cast(Data* data);
6664 
6665  private:
6666  Signature();
6667 
6668  static void CheckCast(Data* that);
6669 };
6670 
6671 
6677  public:
6678  static Local<AccessorSignature> New(
6679  Isolate* isolate,
6681 
6682  V8_INLINE static AccessorSignature* Cast(Data* data);
6683 
6684  private:
6686 
6687  static void CheckCast(Data* that);
6688 };
6689 
6690 
6691 // --- Extensions ---
6692 
6696 class V8_EXPORT Extension { // NOLINT
6697  public:
6698  // Note that the strings passed into this constructor must live as long
6699  // as the Extension itself.
6700  Extension(const char* name, const char* source = nullptr, int dep_count = 0,
6701  const char** deps = nullptr, int source_length = -1);
6702  virtual ~Extension() { delete source_; }
6704  Isolate* isolate, Local<String> name) {
6705  return Local<FunctionTemplate>();
6706  }
6707 
6708  const char* name() const { return name_; }
6709  size_t source_length() const { return source_length_; }
6711  return source_;
6712  }
6713  int dependency_count() const { return dep_count_; }
6714  const char** dependencies() const { return deps_; }
6715  void set_auto_enable(bool value) { auto_enable_ = value; }
6716  bool auto_enable() { return auto_enable_; }
6717 
6718  // Disallow copying and assigning.
6719  Extension(const Extension&) = delete;
6720  void operator=(const Extension&) = delete;
6721 
6722  private:
6723  const char* name_;
6724  size_t source_length_; // expected to initialize before source_
6726  int dep_count_;
6727  const char** deps_;
6728  bool auto_enable_;
6729 };
6730 
6731 void V8_EXPORT RegisterExtension(std::unique_ptr<Extension>);
6732 
6733 // --- Statics ---
6734 
6735 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6736 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6737 V8_INLINE Local<Boolean> True(Isolate* isolate);
6738 V8_INLINE Local<Boolean> False(Isolate* isolate);
6739 
6755  public:
6774  void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
6775  size_t maximum_heap_size_in_bytes);
6776 
6786  void ConfigureDefaults(uint64_t physical_memory,
6787  uint64_t virtual_memory_limit);
6788 
6792  uint32_t* stack_limit() const { return stack_limit_; }
6793  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6794 
6799  size_t code_range_size_in_bytes() const { return code_range_size_; }
6800  void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
6801 
6810  return max_old_generation_size_;
6811  }
6813  max_old_generation_size_ = limit;
6814  }
6815 
6822  return max_young_generation_size_;
6823  }
6825  max_young_generation_size_ = limit;
6826  }
6827 
6829  return initial_old_generation_size_;
6830  }
6831  void set_initial_old_generation_size_in_bytes(size_t initial_size) {
6832  initial_old_generation_size_ = initial_size;
6833  }
6834 
6836  return initial_young_generation_size_;
6837  }
6839  initial_young_generation_size_ = initial_size;
6840  }
6841 
6845  V8_DEPRECATE_SOON("Use code_range_size_in_bytes.")
6846  size_t code_range_size() const { return code_range_size_ / kMB; }
6847  V8_DEPRECATE_SOON("Use set_code_range_size_in_bytes.")
6848  void set_code_range_size(size_t limit_in_mb) {
6849  code_range_size_ = limit_in_mb * kMB;
6850  }
6851  V8_DEPRECATE_SOON("Use max_young_generation_size_in_bytes.")
6852  size_t max_semi_space_size_in_kb() const;
6853  V8_DEPRECATE_SOON("Use set_max_young_generation_size_in_bytes.")
6854  void set_max_semi_space_size_in_kb(size_t limit_in_kb);
6855  V8_DEPRECATE_SOON("Use max_old_generation_size_in_bytes.")
6856  size_t max_old_space_size() const { return max_old_generation_size_ / kMB; }
6857  V8_DEPRECATE_SOON("Use set_max_old_generation_size_in_bytes.")
6858  void set_max_old_space_size(size_t limit_in_mb) {
6859  max_old_generation_size_ = limit_in_mb * kMB;
6860  }
6861  V8_DEPRECATE_SOON("Zone does not pool memory any more.")
6862  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6863  V8_DEPRECATE_SOON("Zone does not pool memory any more.")
6864  void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; }
6865 
6866  private:
6867  static constexpr size_t kMB = 1048576u;
6868  size_t code_range_size_ = 0;
6869  size_t max_old_generation_size_ = 0;
6870  size_t max_young_generation_size_ = 0;
6871  size_t max_zone_pool_size_ = 0;
6872  size_t initial_old_generation_size_ = 0;
6873  size_t initial_young_generation_size_ = 0;
6874  uint32_t* stack_limit_ = nullptr;
6875 };
6876 
6877 
6878 // --- Exceptions ---
6879 
6880 
6881 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6882 
6883 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6884 
6885 typedef void (*DcheckErrorCallback)(const char* file, int line,
6886  const char* message);
6887 
6888 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6889 
6890 // --- Tracing ---
6891 
6892 typedef void (*LogEventCallback)(const char* name, int event);
6893 
6899  public:
6900  static Local<Value> RangeError(Local<String> message);
6901  static Local<Value> ReferenceError(Local<String> message);
6902  static Local<Value> SyntaxError(Local<String> message);
6903  static Local<Value> TypeError(Local<String> message);
6904  static Local<Value> Error(Local<String> message);
6905 
6911  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6912 
6917  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6918 };
6919 
6920 
6921 // --- Counters Callbacks ---
6922 
6923 typedef int* (*CounterLookupCallback)(const char* name);
6924 
6925 typedef void* (*CreateHistogramCallback)(const char* name,
6926  int min,
6927  int max,
6928  size_t buckets);
6929 
6930 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6931 
6932 // --- Crashkeys Callback ---
6933 enum class CrashKeyId {
6938  kDumpType,
6939 };
6940 
6941 typedef void (*AddCrashKeyCallback)(CrashKeyId id, const std::string& value);
6942 
6943 // --- Enter/Leave Script Callback ---
6945 typedef void (*CallCompletedCallback)(Isolate*);
6946 
6960 
6982  Local<Context> context, Local<ScriptOrModule> referrer,
6983  Local<String> specifier);
6984 
6996  Local<Module> module,
6997  Local<Object> meta);
6998 
7007  Local<Value> error,
7008  Local<Array> sites);
7009 
7027 
7028 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
7029  Local<Value> parent);
7030 
7031 // --- Promise Reject Callback ---
7037 };
7038 
7040  public:
7042  Local<Value> value)
7043  : promise_(promise), event_(event), value_(value) {}
7044 
7045  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
7046  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
7047  V8_INLINE Local<Value> GetValue() const { return value_; }
7048 
7049  private:
7050  Local<Promise> promise_;
7051  PromiseRejectEvent event_;
7052  Local<Value> value_;
7053 };
7054 
7056 
7057 // --- Microtasks Callbacks ---
7058 V8_DEPRECATE_SOON("Use *WithData version.")
7061 typedef void (*MicrotaskCallback)(void* data);
7062 
7063 
7072 
7089  public:
7093  static std::unique_ptr<MicrotaskQueue> New(
7094  Isolate* isolate, MicrotasksPolicy policy = MicrotasksPolicy::kAuto);
7095 
7096  virtual ~MicrotaskQueue() = default;
7097 
7101  virtual void EnqueueMicrotask(Isolate* isolate,
7102  Local<Function> microtask) = 0;
7103 
7107  virtual void EnqueueMicrotask(v8::Isolate* isolate,
7108  MicrotaskCallback callback,
7109  void* data = nullptr) = 0;
7110 
7123  virtual void AddMicrotasksCompletedCallback(
7124  MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
7125 
7129  virtual void RemoveMicrotasksCompletedCallback(
7130  MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
7131 
7135  virtual void PerformCheckpoint(Isolate* isolate) = 0;
7136 
7140  virtual bool IsRunningMicrotasks() const = 0;
7141 
7146  virtual int GetMicrotasksScopeDepth() const = 0;
7147 
7148  MicrotaskQueue(const MicrotaskQueue&) = delete;
7149  MicrotaskQueue& operator=(const MicrotaskQueue&) = delete;
7150 
7151  private:
7152  friend class internal::MicrotaskQueue;
7153  MicrotaskQueue() = default;
7154 };
7155 
7166  public:
7167  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
7168 
7169  MicrotasksScope(Isolate* isolate, Type type);
7170  MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
7171  ~MicrotasksScope();
7172 
7176  static void PerformCheckpoint(Isolate* isolate);
7177 
7181  static int GetCurrentDepth(Isolate* isolate);
7182 
7186  static bool IsRunningMicrotasks(Isolate* isolate);
7187 
7188  // Prevent copying.
7189  MicrotasksScope(const MicrotasksScope&) = delete;
7190  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
7191 
7192  private:
7193  internal::Isolate* const isolate_;
7194  internal::MicrotaskQueue* const microtask_queue_;
7195  bool run_;
7196 };
7197 
7198 
7199 // --- Failed Access Check Callback ---
7201  AccessType type,
7202  Local<Value> data);
7203 
7204 // --- AllowCodeGenerationFromStrings callbacks ---
7205 
7211  Local<String> source);
7213  Local<Context> context, Local<Value> source);
7214 
7215 // --- WebAssembly compilation callbacks ---
7217 
7219  Local<String> source);
7220 
7221 // --- Callback for APIs defined on v8-supported objects, but implemented
7222 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
7224 
7225 // --- Callback for WebAssembly.compileStreaming ---
7227 
7228 // --- Callback for checking if WebAssembly threads are enabled ---
7230 
7231 // --- Callback for loading source map file for WASM profiling support
7233  const char* name);
7234 
7235 // --- Garbage Collection Callbacks ---
7236 
7244 enum GCType {
7251 };
7252 
7275 };
7276 
7277 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
7278 
7279 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
7280 
7288 typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
7289  size_t initial_heap_limit);
7290 
7298  public:
7299  HeapStatistics();
7300  size_t total_heap_size() { return total_heap_size_; }
7301  size_t total_heap_size_executable() { return total_heap_size_executable_; }
7302  size_t total_physical_size() { return total_physical_size_; }
7303  size_t total_available_size() { return total_available_size_; }
7304  size_t used_heap_size() { return used_heap_size_; }
7305  size_t heap_size_limit() { return heap_size_limit_; }
7306  size_t malloced_memory() { return malloced_memory_; }
7307  size_t external_memory() { return external_memory_; }
7308  size_t peak_malloced_memory() { return peak_malloced_memory_; }
7309  size_t number_of_native_contexts() { return number_of_native_contexts_; }
7310  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
7311 
7316  size_t does_zap_garbage() { return does_zap_garbage_; }
7317 
7318  private:
7319  size_t total_heap_size_;
7320  size_t total_heap_size_executable_;
7321  size_t total_physical_size_;
7322  size_t total_available_size_;
7323  size_t used_heap_size_;
7324  size_t heap_size_limit_;
7325  size_t malloced_memory_;
7326  size_t external_memory_;
7327  size_t peak_malloced_memory_;
7328  bool does_zap_garbage_;
7329  size_t number_of_native_contexts_;
7330  size_t number_of_detached_contexts_;
7331 
7332  friend class V8;
7333  friend class Isolate;
7334 };
7335 
7336 
7338  public:
7340  const char* space_name() { return space_name_; }
7341  size_t space_size() { return space_size_; }
7342  size_t space_used_size() { return space_used_size_; }
7343  size_t space_available_size() { return space_available_size_; }
7344  size_t physical_space_size() { return physical_space_size_; }
7345 
7346  private:
7347  const char* space_name_;
7348  size_t space_size_;
7349  size_t space_used_size_;
7350  size_t space_available_size_;
7351  size_t physical_space_size_;
7352 
7353  friend class Isolate;
7354 };
7355 
7356 
7358  public:
7360  const char* object_type() { return object_type_; }
7361  const char* object_sub_type() { return object_sub_type_; }
7362  size_t object_count() { return object_count_; }
7363  size_t object_size() { return object_size_; }
7364 
7365  private:
7366  const char* object_type_;
7367  const char* object_sub_type_;
7368  size_t object_count_;
7369  size_t object_size_;
7370 
7371  friend class Isolate;
7372 };
7373 
7375  public:
7377  size_t code_and_metadata_size() { return code_and_metadata_size_; }
7378  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
7379  size_t external_script_source_size() { return external_script_source_size_; }
7380 
7381  private:
7382  size_t code_and_metadata_size_;
7383  size_t bytecode_and_metadata_size_;
7384  size_t external_script_source_size_;
7385 
7386  friend class Isolate;
7387 };
7388 
7395  enum EventType {
7401  CODE_END_LINE_INFO_RECORDING
7402  };
7403  // Definition of the code position type. The "POSITION" type means the place
7404  // in the source code which are of interest when making stack traces to
7405  // pin-point the source location of a stack frame as close as possible.
7406  // The "STATEMENT_POSITION" means the place at the beginning of each
7407  // statement, and is used to indicate possible break locations.
7408  enum PositionType { POSITION, STATEMENT_POSITION };
7409 
7410  // There are two different kinds of JitCodeEvents, one for JIT code generated
7411  // by the optimizing compiler, and one for byte code generated for the
7412  // interpreter. For JIT_CODE events, the |code_start| member of the event
7413  // points to the beginning of jitted assembly code, while for BYTE_CODE
7414  // events, |code_start| points to the first bytecode of the interpreted
7415  // function.
7416  enum CodeType { BYTE_CODE, JIT_CODE };
7417 
7418  // Type of event.
7421  // Start of the instructions.
7422  void* code_start;
7423  // Size of the instructions.
7424  size_t code_len;
7425  // Script info for CODE_ADDED event.
7427  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
7428  // code line information which is returned from the
7429  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
7430  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
7431  void* user_data;
7432 
7433  struct name_t {
7434  // Name of the object associated with the code, note that the string is not
7435  // zero-terminated.
7436  const char* str;
7437  // Number of chars in str.
7438  size_t len;
7439  };
7440 
7441  struct line_info_t {
7442  // PC offset
7443  size_t offset;
7444  // Code position
7445  size_t pos;
7446  // The position type.
7448  };
7449 
7450  union {
7451  // Only valid for CODE_ADDED.
7452  struct name_t name;
7453 
7454  // Only valid for CODE_ADD_LINE_POS_INFO
7455  struct line_info_t line_info;
7456 
7457  // New location of instructions. Only valid for CODE_MOVED.
7459  };
7460 
7462 };
7463 
7469 enum RAILMode : unsigned {
7470  // Response performance mode: In this mode very low virtual machine latency
7471  // is provided. V8 will try to avoid JavaScript execution interruptions.
7472  // Throughput may be throttled.
7474  // Animation performance mode: In this mode low virtual machine latency is
7475  // provided. V8 will try to avoid as many JavaScript execution interruptions
7476  // as possible. Throughput may be throttled. This is the default mode.
7478  // Idle performance mode: The embedder is idle. V8 can complete deferred work
7479  // in this mode.
7481  // Load performance mode: In this mode high throughput is provided. V8 may
7482  // turn off latency optimizations.
7484 };
7485 
7491  // Generate callbacks for already existent code.
7493 };
7494 
7495 
7501 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
7502 
7506 #if defined(V8_OS_WIN)
7507 typedef int (*UnhandledExceptionCallback)(
7508  _EXCEPTION_POINTERS* exception_pointers);
7509 #endif
7510 
7515  public:
7516  virtual ~ExternalResourceVisitor() = default;
7517  virtual void VisitExternalString(Local<String> string) {}
7518 };
7519 
7520 
7525  public:
7526  virtual ~PersistentHandleVisitor() = default;
7528  uint16_t class_id) {}
7529 };
7530 
7540 
7549  public:
7550  enum TraceFlags : uint64_t {
7551  kNoFlags = 0,
7552  kReduceMemory = 1 << 0,
7553  };
7554 
7555  // Indicator for the stack state of the embedder.
7560  };
7561 
7566  public:
7567  virtual ~TracedGlobalHandleVisitor() = default;
7568  virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& handle) {}
7569  virtual void VisitTracedReference(const TracedReference<Value>& handle) {}
7570  };
7571 
7576  struct TraceSummary {
7581  double time = 0.0;
7582 
7587  size_t allocated_size = 0;
7588  };
7589 
7590  virtual ~EmbedderHeapTracer() = default;
7591 
7596  void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor);
7597 
7604  virtual void RegisterV8References(
7605  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
7606 
7607  V8_DEPRECATE_SOON("Use version taking TracedReferenceBase<v8::Data> argument")
7608  void RegisterEmbedderReference(const TracedReferenceBase<v8::Value>& ref);
7609  void RegisterEmbedderReference(const TracedReferenceBase<v8::Data>& ref);
7610 
7614  virtual void TracePrologue(TraceFlags flags) {}
7615 
7626  virtual bool AdvanceTracing(double deadline_in_ms) = 0;
7627 
7628  /*
7629  * Returns true if there no more tracing work to be done (see AdvanceTracing)
7630  * and false otherwise.
7631  */
7632  virtual bool IsTracingDone() = 0;
7633 
7641  V8_DEPRECATED("Use version with parameter.") virtual void TraceEpilogue() {}
7642  virtual void TraceEpilogue(TraceSummary* trace_summary);
7643 
7648  virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
7649 
7650  /*
7651  * Called by the embedder to request immediate finalization of the currently
7652  * running tracing phase that has been started with TracePrologue and not
7653  * yet finished with TraceEpilogue.
7654  *
7655  * Will be a noop when currently not in tracing.
7656  *
7657  * This is an experimental feature.
7658  */
7659  void FinalizeTracing();
7660 
7678  virtual bool IsRootForNonTracingGC(
7679  const v8::TracedReference<v8::Value>& handle);
7680  virtual bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>& handle);
7681 
7691  virtual void ResetHandleInNonTracingGC(
7692  const v8::TracedReference<v8::Value>& handle);
7694  "Use TracedReference version when not requiring destructors.")
7695  virtual void ResetHandleInNonTracingGC(
7696  const v8::TracedGlobal<v8::Value>& handle);
7697 
7698  /*
7699  * Called by the embedder to immediately perform a full garbage collection.
7700  *
7701  * Should only be used in testing code.
7702  */
7703  void GarbageCollectionForTesting(EmbedderStackState stack_state);
7704 
7705  /*
7706  * Called by the embedder to signal newly allocated or freed memory. Not bound
7707  * to tracing phases. Embedders should trade off when increments are reported
7708  * as V8 may consult global heuristics on whether to trigger garbage
7709  * collection on this change.
7710  */
7711  void IncreaseAllocatedSize(size_t bytes);
7712  void DecreaseAllocatedSize(size_t bytes);
7713 
7714  /*
7715  * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
7716  * is not attached to any v8::Isolate.
7717  */
7718  v8::Isolate* isolate() const { return isolate_; }
7719 
7720  protected:
7721  v8::Isolate* isolate_ = nullptr;
7722 
7723  friend class internal::LocalEmbedderHeapTracer;
7724 };
7725 
7735  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
7736  void* data);
7737  SerializeInternalFieldsCallback(CallbackFunction function = nullptr,
7738  void* data_arg = nullptr)
7739  : callback(function), data(data_arg) {}
7740  CallbackFunction callback;
7741  void* data;
7742 };
7743 // Note that these fields are called "internal fields" in the API and called
7744 // "embedder fields" within V8.
7746 
7752  typedef void (*CallbackFunction)(Local<Object> holder, int index,
7753  StartupData payload, void* data);
7754  DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
7755  void* data_arg = nullptr)
7756  : callback(function), data(data_arg) {}
7757  void (*callback)(Local<Object> holder, int index, StartupData payload,
7758  void* data);
7759  void* data;
7760 };
7762 
7764 
7774  public:
7778  struct CreateParams {
7780  : code_event_handler(nullptr),
7781  snapshot_blob(nullptr),
7782  counter_lookup_callback(nullptr),
7783  create_histogram_callback(nullptr),
7784  add_histogram_sample_callback(nullptr),
7785  array_buffer_allocator(nullptr),
7786  external_references(nullptr),
7787  allow_atomics_wait(true),
7788  only_terminate_in_safe_scope(false) {}
7789 
7795 
7800 
7805 
7806 
7812 
7821 
7827 
7834  const intptr_t* external_references;
7835 
7841 
7846  };
7847 
7848 
7854  public:
7855  explicit Scope(Isolate* isolate) : isolate_(isolate) {
7856  isolate->Enter();
7857  }
7858 
7859  ~Scope() { isolate_->Exit(); }
7860 
7861  // Prevent copying of Scope objects.
7862  Scope(const Scope&) = delete;
7863  Scope& operator=(const Scope&) = delete;
7864 
7865  private:
7866  Isolate* const isolate_;
7867  };
7868 
7869 
7874  public:
7875  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
7876 
7877  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
7879 
7880  // Prevent copying of Scope objects.
7882  delete;
7884  const DisallowJavascriptExecutionScope&) = delete;
7885 
7886  private:
7887  OnFailure on_failure_;
7888  void* internal_;
7889  };
7890 
7891 
7896  public:
7897  explicit AllowJavascriptExecutionScope(Isolate* isolate);
7899 
7900  // Prevent copying of Scope objects.
7902  delete;
7903  AllowJavascriptExecutionScope& operator=(
7904  const AllowJavascriptExecutionScope&) = delete;
7905 
7906  private:
7907  void* internal_throws_;
7908  void* internal_assert_;
7909  void* internal_dump_;
7910  };
7911 
7917  public:
7918  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7919  explicit SuppressMicrotaskExecutionScope(MicrotaskQueue* microtask_queue);
7921 
7922  // Prevent copying of Scope objects.
7924  delete;
7926  const SuppressMicrotaskExecutionScope&) = delete;
7927 
7928  private:
7929  internal::Isolate* const isolate_;
7930  internal::MicrotaskQueue* const microtask_queue_;
7931  internal::Address previous_stack_height_;
7932 
7933  friend class internal::ThreadLocalTop;
7934  };
7935 
7941  public:
7942  explicit SafeForTerminationScope(v8::Isolate* isolate);
7944 
7945  // Prevent copying of Scope objects.
7947  SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
7948 
7949  private:
7950  internal::Isolate* isolate_;
7951  bool prev_value_;
7952  };
7953 
7960  kMinorGarbageCollection
7961  };
7962 
7969  kUseAsm = 0,
7970  kBreakIterator = 1,
7971  kLegacyConst = 2,
7972  kMarkDequeOverflow = 3,
7973  kStoreBufferOverflow = 4,
7974  kSlotsBufferOverflow = 5,
7975  kObjectObserve = 6,
7976  kForcedGC = 7,
7977  kSloppyMode = 8,
7978  kStrictMode = 9,
7979  kStrongMode = 10,
7980  kRegExpPrototypeStickyGetter = 11,
7981  kRegExpPrototypeToString = 12,
7982  kRegExpPrototypeUnicodeGetter = 13,
7983  kIntlV8Parse = 14,
7984  kIntlPattern = 15,
7985  kIntlResolved = 16,
7986  kPromiseChain = 17,
7987  kPromiseAccept = 18,
7988  kPromiseDefer = 19,
7989  kHtmlCommentInExternalScript = 20,
7990  kHtmlComment = 21,
7991  kSloppyModeBlockScopedFunctionRedefinition = 22,
7992  kForInInitializer = 23,
7993  kArrayProtectorDirtied = 24,
7994  kArraySpeciesModified = 25,
7995  kArrayPrototypeConstructorModified = 26,
7996  kArrayInstanceProtoModified = 27,
7997  kArrayInstanceConstructorModified = 28,
7998  kLegacyFunctionDeclaration = 29,
7999  kRegExpPrototypeSourceGetter = 30,
8000  kRegExpPrototypeOldFlagGetter = 31,
8001  kDecimalWithLeadingZeroInStrictMode = 32,
8002  kLegacyDateParser = 33,
8003  kDefineGetterOrSetterWouldThrow = 34,
8004  kFunctionConstructorReturnedUndefined = 35,
8005  kAssigmentExpressionLHSIsCallInSloppy = 36,
8006  kAssigmentExpressionLHSIsCallInStrict = 37,
8007  kPromiseConstructorReturnedUndefined = 38,
8008  kConstructorNonUndefinedPrimitiveReturn = 39,
8009  kLabeledExpressionStatement = 40,
8010  kLineOrParagraphSeparatorAsLineTerminator = 41,
8011  kIndexAccessor = 42,
8012  kErrorCaptureStackTrace = 43,
8013  kErrorPrepareStackTrace = 44,
8014  kErrorStackTraceLimit = 45,
8015  kWebAssemblyInstantiation = 46,
8016  kDeoptimizerDisableSpeculation = 47,
8017  kArrayPrototypeSortJSArrayModifiedPrototype = 48,
8018  kFunctionTokenOffsetTooLongForToString = 49,
8019  kWasmSharedMemory = 50,
8020  kWasmThreadOpcodes = 51,
8021  kAtomicsNotify = 52,
8022  kAtomicsWake = 53,
8023  kCollator = 54,
8024  kNumberFormat = 55,
8025  kDateTimeFormat = 56,
8026  kPluralRules = 57,
8027  kRelativeTimeFormat = 58,
8028  kLocale = 59,
8029  kListFormat = 60,
8030  kSegmenter = 61,
8031  kStringLocaleCompare = 62,
8032  kStringToLocaleUpperCase = 63,
8033  kStringToLocaleLowerCase = 64,
8034  kNumberToLocaleString = 65,
8035  kDateToLocaleString = 66,
8036  kDateToLocaleDateString = 67,
8037  kDateToLocaleTimeString = 68,
8038  kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
8039  kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
8040  kOptimizedFunctionWithOneShotBytecode = 71,
8041  kRegExpMatchIsTrueishOnNonJSRegExp = 72,
8042  kRegExpMatchIsFalseishOnJSRegExp = 73,
8043  kDateGetTimezoneOffset = 74,
8044  kStringNormalize = 75,
8045  kCallSiteAPIGetFunctionSloppyCall = 76,
8046  kCallSiteAPIGetThisSloppyCall = 77,
8047  kRegExpMatchAllWithNonGlobalRegExp = 78,
8048 
8049  // If you add new values here, you'll also need to update Chromium's:
8050  // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
8051  // this list need to be landed first, then changes on the Chromium side.
8052  kUseCounterFeatureCount // This enum value must be last.
8053  };
8054 
8056  kMessageLog = (1 << 0),
8057  kMessageDebug = (1 << 1),
8058  kMessageInfo = (1 << 2),
8059  kMessageError = (1 << 3),
8060  kMessageWarning = (1 << 4),
8061  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
8062  kMessageWarning,
8063  };
8064 
8065  typedef void (*UseCounterCallback)(Isolate* isolate,
8066  UseCounterFeature feature);
8067 
8082  static Isolate* Allocate();
8083 
8087  static void Initialize(Isolate* isolate, const CreateParams& params);
8088 
8098  static Isolate* New(const CreateParams& params);
8099 
8106  static Isolate* GetCurrent();
8107 
8118  void ClearKeptObjects();
8119 
8129  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
8130  void SetAbortOnUncaughtExceptionCallback(
8131  AbortOnUncaughtExceptionCallback callback);
8132 
8138  void SetHostCleanupFinalizationGroupCallback(
8140 
8145  void SetHostImportModuleDynamicallyCallback(
8147 
8152  void SetHostInitializeImportMetaObjectCallback(
8154 
8159  void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
8160 
8167  void MemoryPressureNotification(MemoryPressureLevel level);
8168 
8179  void Enter();
8180 
8188  void Exit();
8189 
8194  void Dispose();
8195 
8200  void DumpAndResetStats();
8201 
8209  void DiscardThreadSpecificMetadata();
8210 
8215  V8_INLINE void SetData(uint32_t slot, void* data);
8216 
8221  V8_INLINE void* GetData(uint32_t slot);
8222 
8227  V8_INLINE static uint32_t GetNumberOfDataSlots();
8228 
8234  template <class T>
8235  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
8236 
8240  void GetHeapStatistics(HeapStatistics* heap_statistics);
8241 
8245  size_t NumberOfHeapSpaces();
8246 
8256  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
8257  size_t index);
8258 
8262  size_t NumberOfTrackedHeapObjectTypes();
8263 
8273  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
8274  size_t type_index);
8275 
8283  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
8284 
8294  MeasureMemoryMode mode);
8295 
8308  void GetStackSample(const RegisterState& state, void** frames,
8309  size_t frames_limit, SampleInfo* sample_info);
8310 
8324  V8_INLINE int64_t
8325  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
8326 
8331  size_t NumberOfPhantomHandleResetsSinceLastCall();
8332 
8337  HeapProfiler* GetHeapProfiler();
8338 
8342  void SetIdle(bool is_idle);
8343 
8345  ArrayBuffer::Allocator* GetArrayBufferAllocator();
8346 
8348  bool InContext();
8349 
8354  Local<Context> GetCurrentContext();
8355 
8357  V8_DEPRECATED("Use GetEnteredOrMicrotaskContext().")
8358  Local<Context> GetEnteredContext();
8359 
8366  Local<Context> GetEnteredOrMicrotaskContext();
8367 
8372  Local<Context> GetIncumbentContext();
8373 
8380  Local<Value> ThrowException(Local<Value> exception);
8381 
8382  typedef void (*GCCallback)(Isolate* isolate, GCType type,
8383  GCCallbackFlags flags);
8384  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
8385  GCCallbackFlags flags, void* data);
8386 
8396  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
8397  GCType gc_type_filter = kGCTypeAll);
8398  void AddGCPrologueCallback(GCCallback callback,
8399  GCType gc_type_filter = kGCTypeAll);
8400 
8405  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
8406  void RemoveGCPrologueCallback(GCCallback callback);
8407 
8411  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
8412 
8413  /*
8414  * Gets the currently active heap tracer for the isolate.
8415  */
8416  EmbedderHeapTracer* GetEmbedderHeapTracer();
8417 
8421  enum class AtomicsWaitEvent {
8423  kStartWait,
8425  kWokenUp,
8427  kTimedOut,
8429  kTerminatedExecution,
8431  kAPIStopped,
8433  kNotEqual
8434  };
8435 
8441  public:
8456  void Wake();
8457  };
8458 
8482  typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event,
8483  Local<SharedArrayBuffer> array_buffer,
8484  size_t offset_in_bytes, int64_t value,
8485  double timeout_in_ms,
8486  AtomicsWaitWakeHandle* stop_handle,
8487  void* data);
8488 
8495  void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
8496 
8506  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
8507  GCType gc_type_filter = kGCTypeAll);
8508  void AddGCEpilogueCallback(GCCallback callback,
8509  GCType gc_type_filter = kGCTypeAll);
8510 
8515  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
8516  void* data = nullptr);
8517  void RemoveGCEpilogueCallback(GCCallback callback);
8518 
8519  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
8520 
8527  void SetGetExternallyAllocatedMemoryInBytesCallback(
8528  GetExternallyAllocatedMemoryInBytesCallback callback);
8529 
8537  void TerminateExecution();
8538 
8547  bool IsExecutionTerminating();
8548 
8563  void CancelTerminateExecution();
8564 
8573  void RequestInterrupt(InterruptCallback callback, void* data);
8574 
8585  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
8586 
8590  void SetEventLogger(LogEventCallback that);
8591 
8598  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
8599 
8603  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
8604 
8612  void AddCallCompletedCallback(CallCompletedCallback callback);
8613 
8617  void RemoveCallCompletedCallback(CallCompletedCallback callback);
8618 
8623  void SetPromiseHook(PromiseHook hook);
8624 
8629  void SetPromiseRejectCallback(PromiseRejectCallback callback);
8630 
8635  void RunMicrotasks();
8636 
8640  void EnqueueMicrotask(Local<Function> microtask);
8641 
8645  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
8646 
8650  void SetMicrotasksPolicy(MicrotasksPolicy policy);
8651 
8655  MicrotasksPolicy GetMicrotasksPolicy() const;
8656 
8670  V8_DEPRECATE_SOON("Use *WithData version.")
8671  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8672  void AddMicrotasksCompletedCallback(
8673  MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
8674 
8678  V8_DEPRECATE_SOON("Use *WithData version.")
8679  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8680  void RemoveMicrotasksCompletedCallback(
8681  MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
8682 
8686  void SetUseCounterCallback(UseCounterCallback callback);
8687 
8692  void SetCounterFunction(CounterLookupCallback);
8693 
8700  void SetCreateHistogramFunction(CreateHistogramCallback);
8701  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
8702 
8708  void SetAddCrashKeyCallback(AddCrashKeyCallback);
8709 
8724  bool IdleNotificationDeadline(double deadline_in_seconds);
8725 
8730  void LowMemoryNotification();
8731 
8741  int ContextDisposedNotification(bool dependant_context = true);
8742 
8747  void IsolateInForegroundNotification();
8748 
8753  void IsolateInBackgroundNotification();
8754 
8760  void EnableMemorySavingsMode();
8761 
8765  void DisableMemorySavingsMode();
8766 
8774  void SetRAILMode(RAILMode rail_mode);
8775