V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
v8.h
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 <utility>
23 #include <vector>
24 
25 #include "v8-internal.h" // NOLINT(build/include)
26 #include "v8-version.h" // NOLINT(build/include)
27 #include "v8config.h" // NOLINT(build/include)
28 
29 // We reserve the V8_* prefix for macros defined in V8 public API and
30 // assume there are no name conflicts with the embedder's code.
31 
35 namespace v8 {
36 
37 class AccessorSignature;
38 class Array;
39 class ArrayBuffer;
40 class BigInt;
41 class BigIntObject;
42 class Boolean;
43 class BooleanObject;
44 class Context;
45 class Data;
46 class Date;
47 class External;
48 class Function;
49 class FunctionTemplate;
50 class HeapProfiler;
51 class ImplementationUtilities;
52 class Int32;
53 class Integer;
54 class Isolate;
55 template <class T>
56 class Maybe;
57 class Name;
58 class Number;
59 class NumberObject;
60 class Object;
61 class ObjectOperationDescriptor;
62 class ObjectTemplate;
63 class Platform;
64 class Primitive;
65 class Promise;
66 class PropertyDescriptor;
67 class Proxy;
68 class RawOperationDescriptor;
69 class Script;
70 class SharedArrayBuffer;
71 class Signature;
72 class StartupData;
73 class StackFrame;
74 class StackTrace;
75 class String;
76 class StringObject;
77 class Symbol;
78 class SymbolObject;
79 class PrimitiveArray;
80 class Private;
81 class Uint32;
82 class Utils;
83 class Value;
84 class WasmCompiledModule;
85 template <class T> class Local;
86 template <class T>
87 class MaybeLocal;
88 template <class T> class Eternal;
89 template<class T> class NonCopyablePersistentTraits;
90 template<class T> class PersistentBase;
91 template <class T, class M = NonCopyablePersistentTraits<T> >
92 class Persistent;
93 template <class T>
94 class Global;
95 template<class K, class V, class T> class PersistentValueMap;
96 template <class K, class V, class T>
98 template <class K, class V, class T>
99 class GlobalValueMap;
100 template<class V, class T> class PersistentValueVector;
101 template<class T, class P> class WeakCallbackObject;
102 class FunctionTemplate;
103 class ObjectTemplate;
104 template<typename T> class FunctionCallbackInfo;
105 template<typename T> class PropertyCallbackInfo;
106 class StackTrace;
107 class StackFrame;
108 class Isolate;
109 class CallHandlerHelper;
111 template<typename T> class ReturnValue;
112 
113 namespace internal {
114 class Arguments;
115 class DeferredHandles;
116 class Heap;
117 class HeapObject;
118 class Isolate;
119 class LocalEmbedderHeapTracer;
120 class NeverReadOnlySpaceObject;
121 struct ScriptStreamingData;
122 template<typename T> class CustomArguments;
125 class GlobalHandles;
127 
128 namespace wasm {
129 class NativeModule;
130 class StreamingDecoder;
131 } // namespace wasm
132 
133 } // namespace internal
134 
135 namespace debug {
136 class ConsoleCallArguments;
137 } // namespace debug
138 
139 // --- Handles ---
140 
141 #define TYPE_CHECK(T, S) \
142  while (false) { \
143  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
144  }
145 
177 template <class T>
178 class Local {
179  public:
180  V8_INLINE Local() : val_(nullptr) {}
181  template <class S>
182  V8_INLINE Local(Local<S> that)
183  : val_(reinterpret_cast<T*>(*that)) {
189  TYPE_CHECK(T, S);
190  }
191 
195  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
196 
200  V8_INLINE void Clear() { val_ = nullptr; }
201 
202  V8_INLINE T* operator->() const { return val_; }
203 
204  V8_INLINE T* operator*() const { return val_; }
205 
212  template <class S>
213  V8_INLINE bool operator==(const Local<S>& that) const {
214  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
215  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
216  if (a == nullptr) return b == nullptr;
217  if (b == nullptr) return false;
218  return *a == *b;
219  }
220 
221  template <class S> V8_INLINE bool operator==(
222  const PersistentBase<S>& that) const {
223  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
224  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
225  if (a == nullptr) return b == nullptr;
226  if (b == nullptr) return false;
227  return *a == *b;
228  }
229 
236  template <class S>
237  V8_INLINE bool operator!=(const Local<S>& that) const {
238  return !operator==(that);
239  }
240 
241  template <class S> V8_INLINE bool operator!=(
242  const Persistent<S>& that) const {
243  return !operator==(that);
244  }
245 
251  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
252 #ifdef V8_ENABLE_CHECKS
253  // If we're going to perform the type check then we have to check
254  // that the handle isn't empty before doing the checked cast.
255  if (that.IsEmpty()) return Local<T>();
256 #endif
257  return Local<T>(T::Cast(*that));
258  }
259 
265  template <class S>
266  V8_INLINE Local<S> As() const {
267  return Local<S>::Cast(*this);
268  }
269 
275  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
276  V8_INLINE static Local<T> New(Isolate* isolate,
277  const PersistentBase<T>& that);
278 
279  private:
280  friend class Utils;
281  template<class F> friend class Eternal;
282  template<class F> friend class PersistentBase;
283  template<class F, class M> friend class Persistent;
284  template<class F> friend class Local;
285  template <class F>
286  friend class MaybeLocal;
287  template<class F> friend class FunctionCallbackInfo;
288  template<class F> friend class PropertyCallbackInfo;
289  friend class String;
290  friend class Object;
291  friend class Context;
292  friend class Isolate;
293  friend class Private;
294  template<class F> friend class internal::CustomArguments;
295  friend Local<Primitive> Undefined(Isolate* isolate);
296  friend Local<Primitive> Null(Isolate* isolate);
297  friend Local<Boolean> True(Isolate* isolate);
298  friend Local<Boolean> False(Isolate* isolate);
299  friend class HandleScope;
300  friend class EscapableHandleScope;
301  template <class F1, class F2, class F3>
302  friend class PersistentValueMapBase;
303  template<class F1, class F2> friend class PersistentValueVector;
304  template <class F>
305  friend class ReturnValue;
306 
307  explicit V8_INLINE Local(T* that) : val_(that) {}
308  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
309  T* val_;
310 };
311 
312 
313 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
314 // Handle is an alias for Local for historical reasons.
315 template <class T>
316 using Handle = Local<T>;
317 #endif
318 
319 
330 template <class T>
331 class MaybeLocal {
332  public:
333  V8_INLINE MaybeLocal() : val_(nullptr) {}
334  template <class S>
335  V8_INLINE MaybeLocal(Local<S> that)
336  : val_(reinterpret_cast<T*>(*that)) {
337  TYPE_CHECK(T, S);
338  }
339 
340  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
341 
346  template <class S>
347  V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
348  out->val_ = IsEmpty() ? nullptr : this->val_;
349  return !IsEmpty();
350  }
351 
356  V8_INLINE Local<T> ToLocalChecked();
357 
362  template <class S>
363  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
364  return IsEmpty() ? default_value : Local<S>(val_);
365  }
366 
367  private:
368  T* val_;
369 };
370 
375 template <class T> class Eternal {
376  public:
377  V8_INLINE Eternal() : val_(nullptr) {}
378  template <class S>
379  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
380  Set(isolate, handle);
381  }
382  // Can only be safely called if already set.
383  V8_INLINE Local<T> Get(Isolate* isolate) const;
384  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
385  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
386 
387  private:
388  T* val_;
389 };
390 
391 
392 static const int kInternalFieldsInWeakCallback = 2;
393 static const int kEmbedderFieldsInWeakCallback = 2;
394 
395 template <typename T>
397  public:
398  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
399 
400  WeakCallbackInfo(Isolate* isolate, T* parameter,
401  void* embedder_fields[kEmbedderFieldsInWeakCallback],
402  Callback* callback)
403  : isolate_(isolate), parameter_(parameter), callback_(callback) {
404  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
405  embedder_fields_[i] = embedder_fields[i];
406  }
407  }
408 
409  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
410  V8_INLINE T* GetParameter() const { return parameter_; }
411  V8_INLINE void* GetInternalField(int index) const;
412 
413  // When first called, the embedder MUST Reset() the Global which triggered the
414  // callback. The Global itself is unusable for anything else. No v8 other api
415  // calls may be called in the first callback. Should additional work be
416  // required, the embedder must set a second pass callback, which will be
417  // called after all the initial callbacks are processed.
418  // Calling SetSecondPassCallback on the second pass will immediately crash.
419  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
420 
421  private:
422  Isolate* isolate_;
423  T* parameter_;
424  Callback* callback_;
425  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
426 };
427 
428 
429 // kParameter will pass a void* parameter back to the callback, kInternalFields
430 // will pass the first two internal fields back to the callback, kFinalizer
431 // will pass a void* parameter back, but is invoked before the object is
432 // actually collected, so it can be resurrected. In the last case, it is not
433 // possible to request a second pass callback.
434 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };
435 
449 template <class T> class PersistentBase {
450  public:
455  V8_INLINE void Reset();
460  template <class S>
461  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
462 
467  template <class S>
468  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
469 
470  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
471  V8_INLINE void Empty() { val_ = 0; }
472 
473  V8_INLINE Local<T> Get(Isolate* isolate) const {
474  return Local<T>::New(isolate, *this);
475  }
476 
477  template <class S>
478  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
479  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
480  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
481  if (a == nullptr) return b == nullptr;
482  if (b == nullptr) return false;
483  return *a == *b;
484  }
485 
486  template <class S>
487  V8_INLINE bool operator==(const Local<S>& that) const {
488  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
489  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
490  if (a == nullptr) return b == nullptr;
491  if (b == nullptr) return false;
492  return *a == *b;
493  }
494 
495  template <class S>
496  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
497  return !operator==(that);
498  }
499 
500  template <class S>
501  V8_INLINE bool operator!=(const Local<S>& that) const {
502  return !operator==(that);
503  }
504 
512  template <typename P>
513  V8_INLINE void SetWeak(P* parameter,
514  typename WeakCallbackInfo<P>::Callback callback,
515  WeakCallbackType type);
516 
524  V8_INLINE void SetWeak();
525 
526  template<typename P>
527  V8_INLINE P* ClearWeak();
528 
529  // TODO(dcarney): remove this.
530  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
531 
538  V8_INLINE void AnnotateStrongRetainer(const char* label);
539 
545  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
546 
554  "Objects are always considered independent. "
555  "Use MarkActive to avoid collecting otherwise dead weak handles.",
556  V8_INLINE void MarkIndependent());
557 
565  V8_INLINE void MarkActive();
566 
567  V8_DEPRECATE_SOON("See MarkIndependent.",
568  V8_INLINE bool IsIndependent() const);
569 
571  V8_INLINE bool IsNearDeath() const;
572 
574  V8_INLINE bool IsWeak() const;
575 
580  V8_INLINE void SetWrapperClassId(uint16_t class_id);
581 
586  V8_INLINE uint16_t WrapperClassId() const;
587 
588  PersistentBase(const PersistentBase& other) = delete; // NOLINT
589  void operator=(const PersistentBase&) = delete;
590 
591  private:
592  friend class Isolate;
593  friend class Utils;
594  template<class F> friend class Local;
595  template<class F1, class F2> friend class Persistent;
596  template <class F>
597  friend class Global;
598  template<class F> friend class PersistentBase;
599  template<class F> friend class ReturnValue;
600  template <class F1, class F2, class F3>
601  friend class PersistentValueMapBase;
602  template<class F1, class F2> friend class PersistentValueVector;
603  friend class Object;
604 
605  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
606  V8_INLINE static T* New(Isolate* isolate, T* that);
607 
608  T* val_;
609 };
610 
611 
618 template<class T>
619 class NonCopyablePersistentTraits {
620  public:
621  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
622  static const bool kResetInDestructor = false;
623  template<class S, class M>
624  V8_INLINE static void Copy(const Persistent<S, M>& source,
625  NonCopyablePersistent* dest) {
626  Uncompilable<Object>();
627  }
628  // TODO(dcarney): come up with a good compile error here.
629  template<class O> V8_INLINE static void Uncompilable() {
630  TYPE_CHECK(O, Primitive);
631  }
632 };
633 
634 
639 template<class T>
642  static const bool kResetInDestructor = true;
643  template<class S, class M>
644  static V8_INLINE void Copy(const Persistent<S, M>& source,
645  CopyablePersistent* dest) {
646  // do nothing, just allow copy
647  }
648 };
649 
650 
659 template <class T, class M> class Persistent : public PersistentBase<T> {
660  public:
664  V8_INLINE Persistent() : PersistentBase<T>(nullptr) {}
670  template <class S>
671  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
672  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
673  TYPE_CHECK(T, S);
674  }
680  template <class S, class M2>
681  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
682  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
683  TYPE_CHECK(T, S);
684  }
691  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(nullptr) {
692  Copy(that);
693  }
694  template <class S, class M2>
695  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
696  Copy(that);
697  }
698  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
699  Copy(that);
700  return *this;
701  }
702  template <class S, class M2>
703  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
704  Copy(that);
705  return *this;
706  }
712  V8_INLINE ~Persistent() {
713  if (M::kResetInDestructor) this->Reset();
714  }
715 
716  // TODO(dcarney): this is pretty useless, fix or remove
717  template <class S>
718  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
719 #ifdef V8_ENABLE_CHECKS
720  // If we're going to perform the type check then we have to check
721  // that the handle isn't empty before doing the checked cast.
722  if (!that.IsEmpty()) T::Cast(*that);
723 #endif
724  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
725  }
726 
727  // TODO(dcarney): this is pretty useless, fix or remove
728  template <class S>
729  V8_INLINE Persistent<S>& As() const { // NOLINT
730  return Persistent<S>::Cast(*this);
731  }
732 
733  private:
734  friend class Isolate;
735  friend class Utils;
736  template<class F> friend class Local;
737  template<class F1, class F2> friend class Persistent;
738  template<class F> friend class ReturnValue;
739 
740  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
741  V8_INLINE T* operator*() const { return this->val_; }
742  template<class S, class M2>
743  V8_INLINE void Copy(const Persistent<S, M2>& that);
744 };
745 
746 
752 template <class T>
753 class Global : public PersistentBase<T> {
754  public:
758  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
764  template <class S>
765  V8_INLINE Global(Isolate* isolate, Local<S> that)
766  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
767  TYPE_CHECK(T, S);
768  }
774  template <class S>
775  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
776  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
777  TYPE_CHECK(T, S);
778  }
782  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
783  other.val_ = nullptr;
784  }
785  V8_INLINE ~Global() { this->Reset(); }
789  template <class S>
790  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
791  TYPE_CHECK(T, S);
792  if (this != &rhs) {
793  this->Reset();
794  this->val_ = rhs.val_;
795  rhs.val_ = nullptr;
796  }
797  return *this;
798  }
802  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
803 
804  /*
805  * For compatibility with Chromium's base::Bind (base::Passed).
806  */
807  typedef void MoveOnlyTypeForCPP03;
808 
809  Global(const Global&) = delete;
810  void operator=(const Global&) = delete;
811 
812  private:
813  template <class F>
814  friend class ReturnValue;
815  V8_INLINE T* operator*() const { return this->val_; }
816 };
817 
818 
819 // UniquePersistent is an alias for Global for historical reason.
820 template <class T>
821 using UniquePersistent = Global<T>;
822 
823 
838 class V8_EXPORT HandleScope {
839  public:
840  explicit HandleScope(Isolate* isolate);
841 
842  ~HandleScope();
843 
847  static int NumberOfHandles(Isolate* isolate);
848 
849  V8_INLINE Isolate* GetIsolate() const {
850  return reinterpret_cast<Isolate*>(isolate_);
851  }
852 
853  HandleScope(const HandleScope&) = delete;
854  void operator=(const HandleScope&) = delete;
855 
856  protected:
857  V8_INLINE HandleScope() = default;
858 
859  void Initialize(Isolate* isolate);
860 
861  static internal::Address* CreateHandle(internal::Isolate* isolate,
862  internal::Address value);
863 
864  private:
865  // Declaring operator new and delete as deleted is not spec compliant.
866  // Therefore declare them private instead to disable dynamic alloc
867  void* operator new(size_t size);
868  void* operator new[](size_t size);
869  void operator delete(void*, size_t);
870  void operator delete[](void*, size_t);
871 
872  // Uses heap_object to obtain the current Isolate.
873  static internal::Address* CreateHandle(
875 
876  internal::Isolate* isolate_;
877  internal::Address* prev_next_;
878  internal::Address* prev_limit_;
879 
880  // Local::New uses CreateHandle with an Isolate* parameter.
881  template<class F> friend class Local;
882 
883  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
884  // a HeapObject* in their shortcuts.
885  friend class Object;
886  friend class Context;
887 };
888 
889 
894 class V8_EXPORT EscapableHandleScope : public HandleScope {
895  public:
896  explicit EscapableHandleScope(Isolate* isolate);
897  V8_INLINE ~EscapableHandleScope() = default;
898 
903  template <class T>
904  V8_INLINE Local<T> Escape(Local<T> value) {
905  internal::Address* slot =
906  Escape(reinterpret_cast<internal::Address*>(*value));
907  return Local<T>(reinterpret_cast<T*>(slot));
908  }
909 
910  template <class T>
911  V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) {
912  return Escape(value.FromMaybe(Local<T>()));
913  }
914 
915  EscapableHandleScope(const EscapableHandleScope&) = delete;
916  void operator=(const EscapableHandleScope&) = delete;
917 
918  private:
919  // Declaring operator new and delete as deleted is not spec compliant.
920  // Therefore declare them private instead to disable dynamic alloc
921  void* operator new(size_t size);
922  void* operator new[](size_t size);
923  void operator delete(void*, size_t);
924  void operator delete[](void*, size_t);
925 
926  internal::Address* Escape(internal::Address* escape_value);
927  internal::Address* escape_slot_;
928 };
929 
935 class V8_EXPORT SealHandleScope {
936  public:
937  explicit SealHandleScope(Isolate* isolate);
938  ~SealHandleScope();
939 
940  SealHandleScope(const SealHandleScope&) = delete;
941  void operator=(const SealHandleScope&) = delete;
942 
943  private:
944  // Declaring operator new and delete as deleted is not spec compliant.
945  // Therefore declare them private instead to disable dynamic alloc
946  void* operator new(size_t size);
947  void* operator new[](size_t size);
948  void operator delete(void*, size_t);
949  void operator delete[](void*, size_t);
950 
951  internal::Isolate* const isolate_;
952  internal::Address* prev_limit_;
953  int prev_sealed_level_;
954 };
955 
956 
957 // --- Special objects ---
958 
959 
963 class V8_EXPORT Data {
964  private:
965  Data();
966 };
967 
974 class V8_EXPORT ScriptOrModule {
975  public:
980  Local<Value> GetResourceName();
981 
986  Local<PrimitiveArray> GetHostDefinedOptions();
987 };
988 
997 class V8_EXPORT PrimitiveArray {
998  public:
999  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1000  int Length() const;
1001  void Set(Isolate* isolate, int index, Local<Primitive> item);
1002  Local<Primitive> Get(Isolate* isolate, int index);
1003 };
1004 
1009  public:
1010  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1011  bool is_opaque = false, bool is_wasm = false,
1012  bool is_module = false)
1013  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1014  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1015  (is_module ? kIsModule : 0)) {}
1016  V8_INLINE ScriptOriginOptions(int flags)
1017  : flags_(flags &
1018  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1019 
1020  bool IsSharedCrossOrigin() const {
1021  return (flags_ & kIsSharedCrossOrigin) != 0;
1022  }
1023  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1024  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1025  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1026 
1027  int Flags() const { return flags_; }
1028 
1029  private:
1030  enum {
1031  kIsSharedCrossOrigin = 1,
1032  kIsOpaque = 1 << 1,
1033  kIsWasm = 1 << 2,
1034  kIsModule = 1 << 3
1035  };
1036  const int flags_;
1037 };
1038 
1043  public:
1044  V8_INLINE ScriptOrigin(
1045  Local<Value> resource_name,
1046  Local<Integer> resource_line_offset = Local<Integer>(),
1047  Local<Integer> resource_column_offset = Local<Integer>(),
1048  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1049  Local<Integer> script_id = Local<Integer>(),
1050  Local<Value> source_map_url = Local<Value>(),
1051  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1052  Local<Boolean> is_wasm = Local<Boolean>(),
1053  Local<Boolean> is_module = Local<Boolean>(),
1054  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1055 
1056  V8_INLINE Local<Value> ResourceName() const;
1057  V8_INLINE Local<Integer> ResourceLineOffset() const;
1058  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1059  V8_INLINE Local<Integer> ScriptID() const;
1060  V8_INLINE Local<Value> SourceMapUrl() const;
1061  V8_INLINE Local<PrimitiveArray> HostDefinedOptions() const;
1062  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1063 
1064  private:
1065  Local<Value> resource_name_;
1066  Local<Integer> resource_line_offset_;
1067  Local<Integer> resource_column_offset_;
1068  ScriptOriginOptions options_;
1069  Local<Integer> script_id_;
1070  Local<Value> source_map_url_;
1071  Local<PrimitiveArray> host_defined_options_;
1072 };
1073 
1077 class V8_EXPORT UnboundScript {
1078  public:
1082  Local<Script> BindToCurrentContext();
1083 
1084  int GetId();
1085  Local<Value> GetScriptName();
1086 
1090  Local<Value> GetSourceURL();
1094  Local<Value> GetSourceMappingURL();
1095 
1100  int GetLineNumber(int code_pos);
1101 
1102  static const int kNoScriptId = 0;
1103 };
1104 
1108 class V8_EXPORT UnboundModuleScript {
1109  // Only used as a container for code caching.
1110 };
1111 
1115 class V8_EXPORT Location {
1116  public:
1117  int GetLineNumber() { return line_number_; }
1118  int GetColumnNumber() { return column_number_; }
1119 
1120  Location(int line_number, int column_number)
1121  : line_number_(line_number), column_number_(column_number) {}
1122 
1123  private:
1124  int line_number_;
1125  int column_number_;
1126 };
1127 
1131 class V8_EXPORT Module {
1132  public:
1140  enum Status {
1141  kUninstantiated,
1142  kInstantiating,
1143  kInstantiated,
1144  kEvaluating,
1145  kEvaluated,
1146  kErrored
1147  };
1148 
1152  Status GetStatus() const;
1153 
1157  Local<Value> GetException() const;
1158 
1162  int GetModuleRequestsLength() const;
1163 
1168  Local<String> GetModuleRequest(int i) const;
1169 
1174  Location GetModuleRequestLocation(int i) const;
1175 
1179  int GetIdentityHash() const;
1180 
1181  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1182  Local<String> specifier,
1183  Local<Module> referrer);
1184 
1192  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1193  ResolveCallback callback);
1194 
1203  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
1204 
1210  Local<Value> GetModuleNamespace();
1211 
1218  Local<UnboundModuleScript> GetUnboundModuleScript();
1219 };
1220 
1225 class V8_EXPORT Script {
1226  public:
1230  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1231  Local<Context> context, Local<String> source,
1232  ScriptOrigin* origin = nullptr);
1233 
1239  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1240 
1244  Local<UnboundScript> GetUnboundScript();
1245 };
1246 
1247 
1251 class V8_EXPORT ScriptCompiler {
1252  public:
1260  struct V8_EXPORT CachedData {
1261  enum BufferPolicy {
1262  BufferNotOwned,
1263  BufferOwned
1264  };
1265 
1266  CachedData()
1267  : data(nullptr),
1268  length(0),
1269  rejected(false),
1270  buffer_policy(BufferNotOwned) {}
1271 
1272  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1273  // data and guarantees that it stays alive until the CachedData object is
1274  // destroyed. If the policy is BufferOwned, the given data will be deleted
1275  // (with delete[]) when the CachedData object is destroyed.
1276  CachedData(const uint8_t* data, int length,
1277  BufferPolicy buffer_policy = BufferNotOwned);
1278  ~CachedData();
1279  // TODO(marja): Async compilation; add constructors which take a callback
1280  // which will be called when V8 no longer needs the data.
1281  const uint8_t* data;
1282  int length;
1283  bool rejected;
1284  BufferPolicy buffer_policy;
1285 
1286  // Prevent copying.
1287  CachedData(const CachedData&) = delete;
1288  CachedData& operator=(const CachedData&) = delete;
1289  };
1290 
1294  class Source {
1295  public:
1296  // Source takes ownership of CachedData.
1297  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1298  CachedData* cached_data = nullptr);
1299  V8_INLINE Source(Local<String> source_string,
1300  CachedData* cached_data = nullptr);
1301  V8_INLINE ~Source();
1302 
1303  // Ownership of the CachedData or its buffers is *not* transferred to the
1304  // caller. The CachedData object is alive as long as the Source object is
1305  // alive.
1306  V8_INLINE const CachedData* GetCachedData() const;
1307 
1308  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1309 
1310  // Prevent copying.
1311  Source(const Source&) = delete;
1312  Source& operator=(const Source&) = delete;
1313 
1314  private:
1315  friend class ScriptCompiler;
1316 
1317  Local<String> source_string;
1318 
1319  // Origin information
1320  Local<Value> resource_name;
1321  Local<Integer> resource_line_offset;
1322  Local<Integer> resource_column_offset;
1323  ScriptOriginOptions resource_options;
1324  Local<Value> source_map_url;
1325  Local<PrimitiveArray> host_defined_options;
1326 
1327  // Cached data from previous compilation (if a kConsume*Cache flag is
1328  // set), or hold newly generated cache data (kProduce*Cache flags) are
1329  // set when calling a compile method.
1330  CachedData* cached_data;
1331  };
1332 
1337  class V8_EXPORT ExternalSourceStream {
1338  public:
1339  virtual ~ExternalSourceStream() = default;
1340 
1362  virtual size_t GetMoreData(const uint8_t** src) = 0;
1363 
1374  virtual bool SetBookmark();
1375 
1379  virtual void ResetToBookmark();
1380  };
1381 
1388  class V8_EXPORT StreamedSource {
1389  public:
1390  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1391 
1392  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1393  ~StreamedSource();
1394 
1395  V8_DEPRECATED("No longer used", const CachedData* GetCachedData() const) {
1396  return nullptr;
1397  }
1398 
1399  internal::ScriptStreamingData* impl() const { return impl_.get(); }
1400 
1401  // Prevent copying.
1402  StreamedSource(const StreamedSource&) = delete;
1403  StreamedSource& operator=(const StreamedSource&) = delete;
1404 
1405  private:
1406  std::unique_ptr<internal::ScriptStreamingData> impl_;
1407  };
1408 
1413  class V8_EXPORT ScriptStreamingTask final {
1414  public:
1415  void Run();
1416 
1417  private:
1418  friend class ScriptCompiler;
1419 
1421  : data_(data) {}
1422 
1424  };
1425 
1426  enum CompileOptions {
1427  kNoCompileOptions = 0,
1428  kConsumeCodeCache,
1429  kEagerCompile
1430  };
1431 
1436  kNoCacheNoReason = 0,
1437  kNoCacheBecauseCachingDisabled,
1438  kNoCacheBecauseNoResource,
1439  kNoCacheBecauseInlineScript,
1440  kNoCacheBecauseModule,
1441  kNoCacheBecauseStreamingSource,
1442  kNoCacheBecauseInspector,
1443  kNoCacheBecauseScriptTooSmall,
1444  kNoCacheBecauseCacheTooCold,
1445  kNoCacheBecauseV8Extension,
1446  kNoCacheBecauseExtensionModule,
1447  kNoCacheBecausePacScript,
1448  kNoCacheBecauseInDocumentWrite,
1449  kNoCacheBecauseResourceWithNoCacheHandler,
1450  kNoCacheBecauseDeferredProduceCodeCache
1451  };
1452 
1466  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1467  Isolate* isolate, Source* source,
1468  CompileOptions options = kNoCompileOptions,
1469  NoCacheReason no_cache_reason = kNoCacheNoReason);
1470 
1482  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1483  Local<Context> context, Source* source,
1484  CompileOptions options = kNoCompileOptions,
1485  NoCacheReason no_cache_reason = kNoCacheNoReason);
1486 
1498  static ScriptStreamingTask* StartStreamingScript(
1499  Isolate* isolate, StreamedSource* source,
1500  CompileOptions options = kNoCompileOptions);
1501 
1509  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1510  Local<Context> context, StreamedSource* source,
1511  Local<String> full_source_string, const ScriptOrigin& origin);
1512 
1531  static uint32_t CachedDataVersionTag();
1532 
1540  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1541  Isolate* isolate, Source* source,
1542  CompileOptions options = kNoCompileOptions,
1543  NoCacheReason no_cache_reason = kNoCacheNoReason);
1544 
1555  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1556  Local<Context> context, Source* source, size_t arguments_count,
1557  Local<String> arguments[], size_t context_extension_count,
1558  Local<Object> context_extensions[],
1559  CompileOptions options = kNoCompileOptions,
1560  NoCacheReason no_cache_reason = kNoCacheNoReason);
1561 
1567  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
1568 
1574  static CachedData* CreateCodeCache(
1575  Local<UnboundModuleScript> unbound_module_script);
1576 
1583  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
1584 
1585  private:
1586  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1587  Isolate* isolate, Source* source, CompileOptions options,
1588  NoCacheReason no_cache_reason);
1589 };
1590 
1591 
1595 class V8_EXPORT Message {
1596  public:
1597  Local<String> Get() const;
1598 
1602  Isolate* GetIsolate() const;
1603 
1604  V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
1605  Local<Context> context) const;
1606 
1611  ScriptOrigin GetScriptOrigin() const;
1612 
1617  Local<Value> GetScriptResourceName() const;
1618 
1624  Local<StackTrace> GetStackTrace() const;
1625 
1629  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1630 
1635  int GetStartPosition() const;
1636 
1641  int GetEndPosition() const;
1642 
1646  int ErrorLevel() const;
1647 
1652  int GetStartColumn() const;
1653  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1654 
1659  int GetEndColumn() const;
1660  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1661 
1666  bool IsSharedCrossOrigin() const;
1667  bool IsOpaque() const;
1668 
1669  // TODO(1245381): Print to a string instead of on a FILE.
1670  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1671 
1672  static const int kNoLineNumberInfo = 0;
1673  static const int kNoColumnInfo = 0;
1674  static const int kNoScriptIdInfo = 0;
1675 };
1676 
1677 
1683 class V8_EXPORT StackTrace {
1684  public:
1692  kLineNumber = 1,
1693  kColumnOffset = 1 << 1 | kLineNumber,
1694  kScriptName = 1 << 2,
1695  kFunctionName = 1 << 3,
1696  kIsEval = 1 << 4,
1697  kIsConstructor = 1 << 5,
1698  kScriptNameOrSourceURL = 1 << 6,
1699  kScriptId = 1 << 7,
1700  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1701  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1702  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1703  };
1704 
1708  Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
1709 
1713  int GetFrameCount() const;
1714 
1722  static Local<StackTrace> CurrentStackTrace(
1723  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1724 };
1725 
1726 
1730 class V8_EXPORT StackFrame {
1731  public:
1738  int GetLineNumber() const;
1739 
1747  int GetColumn() const;
1748 
1755  int GetScriptId() const;
1756 
1761  Local<String> GetScriptName() const;
1762 
1769  Local<String> GetScriptNameOrSourceURL() const;
1770 
1774  Local<String> GetFunctionName() const;
1775 
1780  bool IsEval() const;
1781 
1786  bool IsConstructor() const;
1787 
1791  bool IsWasm() const;
1792 };
1793 
1794 
1795 // A StateTag represents a possible state of the VM.
1796 enum StateTag {
1797  JS,
1798  GC,
1799  PARSER,
1800  BYTECODE_COMPILER,
1801  COMPILER,
1802  OTHER,
1803  EXTERNAL,
1804  IDLE
1805 };
1806 
1807 // A RegisterState represents the current state of registers used
1808 // by the sampling profiler API.
1810  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1811  void* pc; // Instruction pointer.
1812  void* sp; // Stack pointer.
1813  void* fp; // Frame pointer.
1814 };
1815 
1816 // The output structure filled up by GetStackSample API function.
1817 struct SampleInfo {
1818  size_t frames_count; // Number of frames collected.
1819  StateTag vm_state; // Current VM state.
1820  void* external_callback_entry; // External callback address if VM is
1821  // executing an external callback.
1822 };
1823 
1824 struct MemoryRange {
1825  const void* start = nullptr;
1826  size_t length_in_bytes = 0;
1827 };
1828 
1829 struct JSEntryStub {
1830  MemoryRange code;
1831 };
1832 
1833 struct UnwindState {
1834  MemoryRange code_range;
1835  MemoryRange embedded_code_range;
1836  JSEntryStub js_entry_stub;
1837 };
1838 
1842 class V8_EXPORT JSON {
1843  public:
1851  static V8_DEPRECATED("Use the maybe version taking context",
1852  MaybeLocal<Value> Parse(Isolate* isolate,
1853  Local<String> json_string));
1854  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1855  Local<Context> context, Local<String> json_string);
1856 
1864  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1865  Local<Context> context, Local<Value> json_object,
1866  Local<String> gap = Local<String>());
1867 };
1868 
1877 class V8_EXPORT ValueSerializer {
1878  public:
1879  class V8_EXPORT Delegate {
1880  public:
1881  virtual ~Delegate() = default;
1882 
1888  virtual void ThrowDataCloneError(Local<String> message) = 0;
1889 
1895  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
1896 
1907  virtual Maybe<uint32_t> GetSharedArrayBufferId(
1908  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
1909 
1910  virtual Maybe<uint32_t> GetWasmModuleTransferId(
1911  Isolate* isolate, Local<WasmCompiledModule> module);
1923  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
1924  size_t* actual_size);
1925 
1931  virtual void FreeBufferMemory(void* buffer);
1932  };
1933 
1934  explicit ValueSerializer(Isolate* isolate);
1935  ValueSerializer(Isolate* isolate, Delegate* delegate);
1936  ~ValueSerializer();
1937 
1941  void WriteHeader();
1942 
1946  V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
1947  Local<Value> value);
1948 
1953  V8_DEPRECATED("Use Release()", std::vector<uint8_t> ReleaseBuffer());
1954 
1961  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
1962 
1968  void TransferArrayBuffer(uint32_t transfer_id,
1969  Local<ArrayBuffer> array_buffer);
1970 
1974  V8_DEPRECATED("Use Delegate::GetSharedArrayBufferId",
1975  void TransferSharedArrayBuffer(
1976  uint32_t transfer_id,
1977  Local<SharedArrayBuffer> shared_array_buffer));
1978 
1986  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
1987 
1993  void WriteUint32(uint32_t value);
1994  void WriteUint64(uint64_t value);
1995  void WriteDouble(double value);
1996  void WriteRawBytes(const void* source, size_t length);
1997 
1998  private:
1999  ValueSerializer(const ValueSerializer&) = delete;
2000  void operator=(const ValueSerializer&) = delete;
2001 
2002  struct PrivateData;
2003  PrivateData* private_;
2004 };
2005 
2014 class V8_EXPORT ValueDeserializer {
2015  public:
2016  class V8_EXPORT Delegate {
2017  public:
2018  virtual ~Delegate() = default;
2019 
2025  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
2026 
2031  virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
2032  Isolate* isolate, uint32_t transfer_id);
2033 
2038  virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
2039  Isolate* isolate, uint32_t clone_id);
2040  };
2041 
2042  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2043  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2044  Delegate* delegate);
2045  ~ValueDeserializer();
2046 
2051  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2052 
2056  V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
2057 
2062  void TransferArrayBuffer(uint32_t transfer_id,
2063  Local<ArrayBuffer> array_buffer);
2064 
2070  void TransferSharedArrayBuffer(uint32_t id,
2071  Local<SharedArrayBuffer> shared_array_buffer);
2072 
2080  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2081 
2085  void SetExpectInlineWasm(bool allow_inline_wasm);
2086 
2092  uint32_t GetWireFormatVersion() const;
2093 
2099  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2100  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2101  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2102  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2103 
2104  private:
2105  ValueDeserializer(const ValueDeserializer&) = delete;
2106  void operator=(const ValueDeserializer&) = delete;
2107 
2108  struct PrivateData;
2109  PrivateData* private_;
2110 };
2111 
2112 
2113 // --- Value ---
2114 
2115 
2119 class V8_EXPORT Value : public Data {
2120  public:
2125  V8_INLINE bool IsUndefined() const;
2126 
2131  V8_INLINE bool IsNull() const;
2132 
2138  V8_INLINE bool IsNullOrUndefined() const;
2139 
2143  bool IsTrue() const;
2144 
2148  bool IsFalse() const;
2149 
2153  bool IsName() const;
2154 
2159  V8_INLINE bool IsString() const;
2160 
2164  bool IsSymbol() const;
2165 
2169  bool IsFunction() const;
2170 
2175  bool IsArray() const;
2176 
2180  bool IsObject() const;
2181 
2185  bool IsBigInt() const;
2186 
2190  bool IsBoolean() const;
2191 
2195  bool IsNumber() const;
2196 
2200  bool IsExternal() const;
2201 
2205  bool IsInt32() const;
2206 
2210  bool IsUint32() const;
2211 
2215  bool IsDate() const;
2216 
2220  bool IsArgumentsObject() const;
2221 
2225  bool IsBigIntObject() const;
2226 
2230  bool IsBooleanObject() const;
2231 
2235  bool IsNumberObject() const;
2236 
2240  bool IsStringObject() const;
2241 
2245  bool IsSymbolObject() const;
2246 
2250  bool IsNativeError() const;
2251 
2255  bool IsRegExp() const;
2256 
2260  bool IsAsyncFunction() const;
2261 
2265  bool IsGeneratorFunction() const;
2266 
2270  bool IsGeneratorObject() const;
2271 
2275  bool IsPromise() const;
2276 
2280  bool IsMap() const;
2281 
2285  bool IsSet() const;
2286 
2290  bool IsMapIterator() const;
2291 
2295  bool IsSetIterator() const;
2296 
2300  bool IsWeakMap() const;
2301 
2305  bool IsWeakSet() const;
2306 
2310  bool IsArrayBuffer() const;
2311 
2315  bool IsArrayBufferView() const;
2316 
2320  bool IsTypedArray() const;
2321 
2325  bool IsUint8Array() const;
2326 
2330  bool IsUint8ClampedArray() const;
2331 
2335  bool IsInt8Array() const;
2336 
2340  bool IsUint16Array() const;
2341 
2345  bool IsInt16Array() const;
2346 
2350  bool IsUint32Array() const;
2351 
2355  bool IsInt32Array() const;
2356 
2360  bool IsFloat32Array() const;
2361 
2365  bool IsFloat64Array() const;
2366 
2370  bool IsBigInt64Array() const;
2371 
2375  bool IsBigUint64Array() const;
2376 
2380  bool IsDataView() const;
2381 
2386  bool IsSharedArrayBuffer() const;
2387 
2391  bool IsProxy() const;
2392 
2393  bool IsWebAssemblyCompiledModule() const;
2394 
2398  bool IsModuleNamespaceObject() const;
2399 
2400  V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
2401  Local<Context> context) const;
2402  V8_DEPRECATE_SOON("ToBoolean can never throw. Use Local version.",
2403  V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
2404  Local<Context> context) const);
2405  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
2406  Local<Context> context) const;
2407  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
2408  Local<Context> context) const;
2409  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
2410  Local<Context> context) const;
2411  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
2412  Local<Context> context) const;
2413  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
2414  Local<Context> context) const;
2415  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
2416  Local<Context> context) const;
2417  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
2418 
2419  Local<Boolean> ToBoolean(Isolate* isolate) const;
2420  V8_DEPRECATE_SOON("Use maybe version",
2421  Local<Number> ToNumber(Isolate* isolate) const);
2422  V8_DEPRECATE_SOON("Use maybe version",
2423  Local<String> ToString(Isolate* isolate) const);
2424  V8_DEPRECATE_SOON("Use maybe version",
2425  Local<Object> ToObject(Isolate* isolate) const);
2426  V8_DEPRECATE_SOON("Use maybe version",
2427  Local<Integer> ToInteger(Isolate* isolate) const);
2428  V8_DEPRECATE_SOON("Use maybe version",
2429  Local<Int32> ToInt32(Isolate* isolate) const);
2430 
2435  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
2436  Local<Context> context) const;
2437 
2438  bool BooleanValue(Isolate* isolate) const;
2439 
2440  V8_DEPRECATE_SOON("BooleanValue can never throw. Use Isolate version.",
2441  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(
2442  Local<Context> context) const);
2443  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2444  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2445  Local<Context> context) const;
2446  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2447  Local<Context> context) const;
2448  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2449 
2451  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2452  Local<Value> that) const;
2453  bool StrictEquals(Local<Value> that) const;
2454  bool SameValue(Local<Value> that) const;
2455 
2456  template <class T> V8_INLINE static Value* Cast(T* value);
2457 
2458  Local<String> TypeOf(Isolate*);
2459 
2460  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2461 
2462  private:
2463  V8_INLINE bool QuickIsUndefined() const;
2464  V8_INLINE bool QuickIsNull() const;
2465  V8_INLINE bool QuickIsNullOrUndefined() const;
2466  V8_INLINE bool QuickIsString() const;
2467  bool FullIsUndefined() const;
2468  bool FullIsNull() const;
2469  bool FullIsString() const;
2470 };
2471 
2472 
2476 class V8_EXPORT Primitive : public Value { };
2477 
2478 
2483 class V8_EXPORT Boolean : public Primitive {
2484  public:
2485  bool Value() const;
2486  V8_INLINE static Boolean* Cast(v8::Value* obj);
2487  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2488 
2489  private:
2490  static void CheckCast(v8::Value* obj);
2491 };
2492 
2493 
2497 class V8_EXPORT Name : public Primitive {
2498  public:
2506  int GetIdentityHash();
2507 
2508  V8_INLINE static Name* Cast(Value* obj);
2509 
2510  private:
2511  static void CheckCast(Value* obj);
2512 };
2513 
2520 enum class NewStringType {
2524  kNormal,
2525 
2532 };
2533 
2537 class V8_EXPORT String : public Name {
2538  public:
2539  static constexpr int kMaxLength = internal::kApiTaggedSize == 4
2540  ? (1 << 28) - 16
2541  : internal::kSmiMaxValue / 2 - 24;
2542 
2543  enum Encoding {
2544  UNKNOWN_ENCODING = 0x1,
2545  TWO_BYTE_ENCODING = 0x0,
2546  ONE_BYTE_ENCODING = 0x8
2547  };
2551  int Length() const;
2552 
2557  int Utf8Length(Isolate* isolate) const;
2558 
2565  bool IsOneByte() const;
2566 
2572  bool ContainsOnlyOneByte() const;
2573 
2600  NO_OPTIONS = 0,
2601  HINT_MANY_WRITES_EXPECTED = 1,
2602  NO_NULL_TERMINATION = 2,
2603  PRESERVE_ONE_BYTE_NULL = 4,
2604  // Used by WriteUtf8 to replace orphan surrogate code units with the
2605  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2606  // output.
2607  REPLACE_INVALID_UTF8 = 8
2608  };
2609 
2610  // 16-bit character codes.
2611  int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
2612  int options = NO_OPTIONS) const;
2613  // One byte characters.
2614  int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
2615  int length = -1, int options = NO_OPTIONS) const;
2616  // UTF-8 encoded characters.
2617  int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
2618  int* nchars_ref = nullptr, int options = NO_OPTIONS) const;
2619 
2623  V8_INLINE static Local<String> Empty(Isolate* isolate);
2624 
2628  bool IsExternal() const;
2629 
2633  bool IsExternalOneByte() const;
2634 
2635  class V8_EXPORT ExternalStringResourceBase { // NOLINT
2636  public:
2637  virtual ~ExternalStringResourceBase() = default;
2638 
2639  V8_DEPRECATED("Use IsCacheable().", virtual bool IsCompressible() const) {
2640  return false;
2641  }
2642 
2648  virtual bool IsCacheable() const { return true; }
2649 
2650  protected:
2651  ExternalStringResourceBase() = default;
2652 
2659  virtual void Dispose() { delete this; }
2660 
2672  virtual void Lock() const {}
2673 
2677  virtual void Unlock() const {}
2678 
2679  // Disallow copying and assigning.
2681  void operator=(const ExternalStringResourceBase&) = delete;
2682 
2683  private:
2684  friend class internal::Heap;
2685  friend class v8::String;
2687  };
2688 
2695  class V8_EXPORT ExternalStringResource
2696  : public ExternalStringResourceBase {
2697  public:
2702  ~ExternalStringResource() override = default;
2703 
2707  virtual const uint16_t* data() const = 0;
2708 
2712  virtual size_t length() const = 0;
2713 
2714  protected:
2715  ExternalStringResource() = default;
2716  };
2717 
2729  : public ExternalStringResourceBase {
2730  public:
2735  ~ExternalOneByteStringResource() override = default;
2737  virtual const char* data() const = 0;
2739  virtual size_t length() const = 0;
2740  protected:
2741  ExternalOneByteStringResource() = default;
2742  };
2743 
2749  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2750  Encoding* encoding_out) const;
2751 
2756  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2757 
2762  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2763 
2764  V8_INLINE static String* Cast(v8::Value* obj);
2765 
2766  // TODO(dcarney): remove with deprecation of New functions.
2767  enum NewStringType {
2768  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2769  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2770  };
2771 
2773  static V8_DEPRECATE_SOON(
2774  "Use maybe version",
2775  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2776  NewStringType type = kNormalString,
2777  int length = -1));
2778 
2781  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2782  Isolate* isolate, const char* data, v8::NewStringType type,
2783  int length = -1);
2784 
2787  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2788  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2789  int length = -1);
2790 
2792  static V8_DEPRECATE_SOON(
2793  "Use maybe version",
2794  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2795  NewStringType type = kNormalString,
2796  int length = -1));
2797 
2800  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2801  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2802  int length = -1);
2803 
2808  static Local<String> Concat(Isolate* isolate, Local<String> left,
2809  Local<String> right);
2810 
2819  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2820  Isolate* isolate, ExternalStringResource* resource);
2821 
2831  bool MakeExternal(ExternalStringResource* resource);
2832 
2841  static V8_DEPRECATE_SOON(
2842  "Use maybe version",
2843  Local<String> NewExternal(Isolate* isolate,
2844  ExternalOneByteStringResource* resource));
2845  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2846  Isolate* isolate, ExternalOneByteStringResource* resource);
2847 
2857  bool MakeExternal(ExternalOneByteStringResource* resource);
2858 
2862  bool CanMakeExternal();
2863 
2867  bool StringEquals(Local<String> str);
2868 
2876  class V8_EXPORT Utf8Value {
2877  public:
2878  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2879  ~Utf8Value();
2880  char* operator*() { return str_; }
2881  const char* operator*() const { return str_; }
2882  int length() const { return length_; }
2883 
2884  // Disallow copying and assigning.
2885  Utf8Value(const Utf8Value&) = delete;
2886  void operator=(const Utf8Value&) = delete;
2887 
2888  private:
2889  char* str_;
2890  int length_;
2891  };
2892 
2899  class V8_EXPORT Value {
2900  public:
2901  Value(Isolate* isolate, Local<v8::Value> obj);
2902  ~Value();
2903  uint16_t* operator*() { return str_; }
2904  const uint16_t* operator*() const { return str_; }
2905  int length() const { return length_; }
2906 
2907  // Disallow copying and assigning.
2908  Value(const Value&) = delete;
2909  void operator=(const Value&) = delete;
2910 
2911  private:
2912  uint16_t* str_;
2913  int length_;
2914  };
2915 
2916  private:
2917  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2918  Encoding encoding) const;
2919  void VerifyExternalStringResource(ExternalStringResource* val) const;
2920  ExternalStringResource* GetExternalStringResourceSlow() const;
2921  ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
2922  String::Encoding* encoding_out) const;
2923 
2924  static void CheckCast(v8::Value* obj);
2925 };
2926 
2927 
2931 class V8_EXPORT Symbol : public Name {
2932  public:
2936  Local<Value> Name() const;
2937 
2941  static Local<Symbol> New(Isolate* isolate,
2942  Local<String> name = Local<String>());
2943 
2951  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2952 
2957  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2958 
2959  // Well-known symbols
2960  static Local<Symbol> GetAsyncIterator(Isolate* isolate);
2961  static Local<Symbol> GetHasInstance(Isolate* isolate);
2962  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
2963  static Local<Symbol> GetIterator(Isolate* isolate);
2964  static Local<Symbol> GetMatch(Isolate* isolate);
2965  static Local<Symbol> GetReplace(Isolate* isolate);
2966  static Local<Symbol> GetSearch(Isolate* isolate);
2967  static Local<Symbol> GetSplit(Isolate* isolate);
2968  static Local<Symbol> GetToPrimitive(Isolate* isolate);
2969  static Local<Symbol> GetToStringTag(Isolate* isolate);
2970  static Local<Symbol> GetUnscopables(Isolate* isolate);
2971 
2972  V8_INLINE static Symbol* Cast(Value* obj);
2973 
2974  private:
2975  Symbol();
2976  static void CheckCast(Value* obj);
2977 };
2978 
2979 
2985 class V8_EXPORT Private : public Data {
2986  public:
2990  Local<Value> Name() const;
2991 
2995  static Local<Private> New(Isolate* isolate,
2996  Local<String> name = Local<String>());
2997 
3007  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3008 
3009  V8_INLINE static Private* Cast(Data* data);
3010 
3011  private:
3012  Private();
3013 
3014  static void CheckCast(Data* that);
3015 };
3016 
3017 
3021 class V8_EXPORT Number : public Primitive {
3022  public:
3023  double Value() const;
3024  static Local<Number> New(Isolate* isolate, double value);
3025  V8_INLINE static Number* Cast(v8::Value* obj);
3026  private:
3027  Number();
3028  static void CheckCast(v8::Value* obj);
3029 };
3030 
3031 
3035 class V8_EXPORT Integer : public Number {
3036  public:
3037  static Local<Integer> New(Isolate* isolate, int32_t value);
3038  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3039  int64_t Value() const;
3040  V8_INLINE static Integer* Cast(v8::Value* obj);
3041  private:
3042  Integer();
3043  static void CheckCast(v8::Value* obj);
3044 };
3045 
3046 
3050 class V8_EXPORT Int32 : public Integer {
3051  public:
3052  int32_t Value() const;
3053  V8_INLINE static Int32* Cast(v8::Value* obj);
3054 
3055  private:
3056  Int32();
3057  static void CheckCast(v8::Value* obj);
3058 };
3059 
3060 
3064 class V8_EXPORT Uint32 : public Integer {
3065  public:
3066  uint32_t Value() const;
3067  V8_INLINE static Uint32* Cast(v8::Value* obj);
3068 
3069  private:
3070  Uint32();
3071  static void CheckCast(v8::Value* obj);
3072 };
3073 
3077 class V8_EXPORT BigInt : public Primitive {
3078  public:
3079  static Local<BigInt> New(Isolate* isolate, int64_t value);
3080  static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3088  static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
3089  int word_count, const uint64_t* words);
3090 
3097  uint64_t Uint64Value(bool* lossless = nullptr) const;
3098 
3104  int64_t Int64Value(bool* lossless = nullptr) const;
3105 
3110  int WordCount() const;
3111 
3120  void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
3121 
3122  V8_INLINE static BigInt* Cast(v8::Value* obj);
3123 
3124  private:
3125  BigInt();
3126  static void CheckCast(v8::Value* obj);
3127 };
3128 
3134  None = 0,
3136  ReadOnly = 1 << 0,
3138  DontEnum = 1 << 1,
3140  DontDelete = 1 << 2
3141 };
3142 
3148 typedef void (*AccessorGetterCallback)(
3149  Local<String> property,
3150  const PropertyCallbackInfo<Value>& info);
3151 typedef void (*AccessorNameGetterCallback)(
3152  Local<Name> property,
3153  const PropertyCallbackInfo<Value>& info);
3154 
3155 
3156 typedef void (*AccessorSetterCallback)(
3157  Local<String> property,
3158  Local<Value> value,
3159  const PropertyCallbackInfo<void>& info);
3160 typedef void (*AccessorNameSetterCallback)(
3161  Local<Name> property,
3162  Local<Value> value,
3163  const PropertyCallbackInfo<void>& info);
3164 
3165 
3176  DEFAULT = 0,
3177  ALL_CAN_READ = 1,
3178  ALL_CAN_WRITE = 1 << 1,
3179  PROHIBITS_OVERWRITING = 1 << 2
3180 };
3181 
3186  ALL_PROPERTIES = 0,
3187  ONLY_WRITABLE = 1,
3188  ONLY_ENUMERABLE = 2,
3189  ONLY_CONFIGURABLE = 4,
3190  SKIP_STRINGS = 8,
3191  SKIP_SYMBOLS = 16
3192 };
3193 
3204 enum class SideEffectType {
3205  kHasSideEffect,
3206  kHasNoSideEffect,
3207  kHasSideEffectToReceiver
3208 };
3209 
3217 enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes };
3218 
3223 enum class IndexFilter { kIncludeIndices, kSkipIndices };
3224 
3229 enum class KeyConversionMode { kConvertToString, kKeepNumbers };
3230 
3234 enum class IntegrityLevel { kFrozen, kSealed };
3235 
3239 class V8_EXPORT Object : public Value {
3240  public:
3241  V8_DEPRECATE_SOON("Use maybe version",
3242  bool Set(Local<Value> key, Local<Value> value));
3243  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
3244  Local<Value> key, Local<Value> value);
3245 
3246  V8_DEPRECATE_SOON("Use maybe version",
3247  bool Set(uint32_t index, Local<Value> value));
3248  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3249  Local<Value> value);
3250 
3251  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3252  //
3253  // Defines a configurable, writable, enumerable property with the given value
3254  // on the object unless the property already exists and is not configurable
3255  // or the object is not extensible.
3256  //
3257  // Returns true on success.
3258  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3259  Local<Name> key,
3260  Local<Value> value);
3261  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3262  uint32_t index,
3263  Local<Value> value);
3264 
3265  // Implements DefineOwnProperty.
3266  //
3267  // In general, CreateDataProperty will be faster, however, does not allow
3268  // for specifying attributes.
3269  //
3270  // Returns true on success.
3271  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3272  Local<Context> context, Local<Name> key, Local<Value> value,
3273  PropertyAttribute attributes = None);
3274 
3275  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3276  //
3277  // The defineProperty function is used to add an own property or
3278  // update the attributes of an existing own property of an object.
3279  //
3280  // Both data and accessor descriptors can be used.
3281  //
3282  // In general, CreateDataProperty is faster, however, does not allow
3283  // for specifying attributes or an accessor descriptor.
3284  //
3285  // The PropertyDescriptor can change when redefining a property.
3286  //
3287  // Returns true on success.
3288  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3289  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3290 
3291  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3292  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3293  Local<Value> key);
3294 
3295  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3296  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3297  uint32_t index);
3298 
3304  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3305  Local<Context> context, Local<Value> key);
3306 
3310  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3311  Local<Context> context, Local<Name> key);
3312 
3313  V8_DEPRECATED("Use maybe version", bool Has(Local<Value> key));
3329  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3330  Local<Value> key);
3331 
3332  V8_DEPRECATED("Use maybe version", bool Delete(Local<Value> key));
3333  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3334  Local<Value> key);
3335 
3336  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3337 
3338  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3339  uint32_t index);
3340 
3344  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
3345  Local<Context> context, Local<Name> name,
3346  AccessorNameGetterCallback getter,
3347  AccessorNameSetterCallback setter = nullptr,
3349  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3350  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3351  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3352 
3353  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3354  Local<Function> setter = Local<Function>(),
3355  PropertyAttribute attribute = None,
3356  AccessControl settings = DEFAULT);
3357 
3362  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3363  Local<Context> context, Local<Name> name,
3364  AccessorNameGetterCallback getter,
3365  AccessorNameSetterCallback setter = nullptr,
3366  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
3367  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3368  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3369 
3378  V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
3379  Local<Context> context, Local<Name> name,
3380  AccessorNameGetterCallback getter, Local<Value> data = Local<Value>(),
3381  PropertyAttribute attributes = None,
3382  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3383  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3384 
3391  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3392  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3393  Local<Value> value);
3394  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3395  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3396 
3403  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3404  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3405  Local<Context> context);
3406  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3407  Local<Context> context, KeyCollectionMode mode,
3408  PropertyFilter property_filter, IndexFilter index_filter,
3409  KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
3410 
3416  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3417  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3418  Local<Context> context);
3419 
3426  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3427  Local<Context> context, PropertyFilter filter,
3428  KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
3429 
3435  Local<Value> GetPrototype();
3436 
3442  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3443  Local<Value> prototype);
3444 
3449  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3450 
3456  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3457  Local<Context> context);
3458 
3462  Local<String> GetConstructorName();
3463 
3467  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3468 
3470  int InternalFieldCount();
3471 
3473  V8_INLINE static int InternalFieldCount(
3474  const PersistentBase<Object>& object) {
3475  return object.val_->InternalFieldCount();
3476  }
3477 
3479  V8_INLINE Local<Value> GetInternalField(int index);
3480 
3482  void SetInternalField(int index, Local<Value> value);
3483 
3489  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3490 
3492  V8_INLINE static void* GetAlignedPointerFromInternalField(
3493  const PersistentBase<Object>& object, int index) {
3494  return object.val_->GetAlignedPointerFromInternalField(index);
3495  }
3496 
3502  void SetAlignedPointerInInternalField(int index, void* value);
3503  void SetAlignedPointerInInternalFields(int argc, int indices[],
3504  void* values[]);
3505 
3511  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3512  Local<Name> key);
3513  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3514  uint32_t index);
3515  V8_DEPRECATE_SOON("Use maybe version",
3516  bool HasRealNamedProperty(Local<String> key));
3530  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3531  Local<Name> key);
3532  V8_DEPRECATE_SOON("Use maybe version",
3533  bool HasRealIndexedProperty(uint32_t index));
3534  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3535  Local<Context> context, uint32_t index);
3536  V8_DEPRECATE_SOON("Use maybe version",
3537  bool HasRealNamedCallbackProperty(Local<String> key));
3538  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3539  Local<Context> context, Local<Name> key);
3540 
3545  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3546  Local<Context> context, Local<Name> key);
3547 
3553  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
3554  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3555  Local<Name> key);
3556 
3562  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3563  Local<Context> context, Local<Name> key);
3564 
3570  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3571  Local<Context> context, Local<Name> key);
3572 
3574  bool HasNamedLookupInterceptor();
3575 
3577  bool HasIndexedLookupInterceptor();
3578 
3586  int GetIdentityHash();
3587 
3592  // TODO(dcarney): take an isolate and optionally bail out?
3593  Local<Object> Clone();
3594 
3598  Local<Context> CreationContext();
3599 
3602  const PersistentBase<Object>& object) {
3603  return object.val_->CreationContext();
3604  }
3605 
3611  bool IsCallable();
3612 
3616  bool IsConstructor();
3617 
3622  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
3623  Local<Value> recv,
3624  int argc,
3625  Local<Value> argv[]);
3626 
3632  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3633  Local<Context> context, int argc, Local<Value> argv[]);
3634 
3638  Isolate* GetIsolate();
3639 
3649  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3650 
3651  static Local<Object> New(Isolate* isolate);
3652 
3661  static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null,
3662  Local<Name>* names, Local<Value>* values,
3663  size_t length);
3664 
3665  V8_INLINE static Object* Cast(Value* obj);
3666 
3667  private:
3668  Object();
3669  static void CheckCast(Value* obj);
3670  Local<Value> SlowGetInternalField(int index);
3671  void* SlowGetAlignedPointerFromInternalField(int index);
3672 };
3673 
3674 
3678 class V8_EXPORT Array : public Object {
3679  public:
3680  uint32_t Length() const;
3681 
3686  static Local<Array> New(Isolate* isolate, int length = 0);
3687 
3692  static Local<Array> New(Isolate* isolate, Local<Value>* elements,
3693  size_t length);
3694  V8_INLINE static Array* Cast(Value* obj);
3695  private:
3696  Array();
3697  static void CheckCast(Value* obj);
3698 };
3699 
3700 
3704 class V8_EXPORT Map : public Object {
3705  public:
3706  size_t Size() const;
3707  void Clear();
3708  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3709  Local<Value> key);
3710  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
3711  Local<Value> key,
3712  Local<Value> value);
3713  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3714  Local<Value> key);
3715  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3716  Local<Value> key);
3717 
3722  Local<Array> AsArray() const;
3723 
3727  static Local<Map> New(Isolate* isolate);
3728 
3729  V8_INLINE static Map* Cast(Value* obj);
3730 
3731  private:
3732  Map();
3733  static void CheckCast(Value* obj);
3734 };
3735 
3736 
3740 class V8_EXPORT Set : public Object {
3741  public:
3742  size_t Size() const;
3743  void Clear();
3744  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3745  Local<Value> key);
3746  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3747  Local<Value> key);
3748  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3749  Local<Value> key);
3750 
3754  Local<Array> AsArray() const;
3755 
3759  static Local<Set> New(Isolate* isolate);
3760 
3761  V8_INLINE static Set* Cast(Value* obj);
3762 
3763  private:
3764  Set();
3765  static void CheckCast(Value* obj);
3766 };
3767 
3768 
3769 template<typename T>
3770 class ReturnValue {
3771  public:
3772  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3773  : value_(that.value_) {
3774  TYPE_CHECK(T, S);
3775  }
3776  // Local setters
3777  template <typename S>
3778  V8_INLINE V8_DEPRECATED("Use Global<> instead",
3779  void Set(const Persistent<S>& handle));
3780  template <typename S>
3781  V8_INLINE void Set(const Global<S>& handle);
3782  template <typename S>
3783  V8_INLINE void Set(const Local<S> handle);
3784  // Fast primitive setters
3785  V8_INLINE void Set(bool value);
3786  V8_INLINE void Set(double i);
3787  V8_INLINE void Set(int32_t i);
3788  V8_INLINE void Set(uint32_t i);
3789  // Fast JS primitive setters
3790  V8_INLINE void SetNull();
3791  V8_INLINE void SetUndefined();
3792  V8_INLINE void SetEmptyString();
3793  // Convenience getter for Isolate
3794  V8_INLINE Isolate* GetIsolate() const;
3795 
3796  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3797  template <typename S>
3798  V8_INLINE void Set(S* whatever);
3799 
3800  // Getter. Creates a new Local<> so it comes with a certain performance
3801  // hit. If the ReturnValue was not yet set, this will return the undefined
3802  // value.
3803  V8_INLINE Local<Value> Get() const;
3804 
3805  private:
3806  template<class F> friend class ReturnValue;
3807  template<class F> friend class FunctionCallbackInfo;
3808  template<class F> friend class PropertyCallbackInfo;
3809  template <class F, class G, class H>
3810  friend class PersistentValueMapBase;
3811  V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
3812  V8_INLINE internal::Address GetDefaultValue();
3813  V8_INLINE explicit ReturnValue(internal::Address* slot);
3814  internal::Address* value_;
3815 };
3816 
3817 
3824 template<typename T>
3825 class FunctionCallbackInfo {
3826  public:
3828  V8_INLINE int Length() const;
3830  V8_INLINE Local<Value> operator[](int i) const;
3832  V8_INLINE Local<Object> This() const;
3843  V8_INLINE Local<Object> Holder() const;
3845  V8_INLINE Local<Value> NewTarget() const;
3847  V8_INLINE bool IsConstructCall() const;
3849  V8_INLINE Local<Value> Data() const;
3851  V8_INLINE Isolate* GetIsolate() const;
3853  V8_INLINE ReturnValue<T> GetReturnValue() const;
3854  // This shouldn't be public, but the arm compiler needs it.
3855  static const int kArgsLength = 6;
3856 
3857  protected:
3858  friend class internal::FunctionCallbackArguments;
3859  friend class internal::CustomArguments<FunctionCallbackInfo>;
3860  friend class debug::ConsoleCallArguments;
3861  static const int kHolderIndex = 0;
3862  static const int kIsolateIndex = 1;
3863  static const int kReturnValueDefaultValueIndex = 2;
3864  static const int kReturnValueIndex = 3;
3865  static const int kDataIndex = 4;
3866  static const int kNewTargetIndex = 5;
3867 
3868  V8_INLINE FunctionCallbackInfo(internal::Address* implicit_args,
3869  internal::Address* values, int length);
3870  internal::Address* implicit_args_;
3871  internal::Address* values_;
3872  int length_;
3873 };
3874 
3875 
3880 template<typename T>
3881 class PropertyCallbackInfo {
3882  public:
3886  V8_INLINE Isolate* GetIsolate() const;
3887 
3893  V8_INLINE Local<Value> Data() const;
3894 
3936  V8_INLINE Local<Object> This() const;
3937 
3947  V8_INLINE Local<Object> Holder() const;
3948 
3957  V8_INLINE ReturnValue<T> GetReturnValue() const;
3958 
3966  V8_INLINE bool ShouldThrowOnError() const;
3967 
3968  // This shouldn't be public, but the arm compiler needs it.
3969  static const int kArgsLength = 7;
3970 
3971  protected:
3972  friend class MacroAssembler;
3973  friend class internal::PropertyCallbackArguments;
3974  friend class internal::CustomArguments<PropertyCallbackInfo>;
3975  static const int kShouldThrowOnErrorIndex = 0;
3976  static const int kHolderIndex = 1;
3977  static const int kIsolateIndex = 2;
3978  static const int kReturnValueDefaultValueIndex = 3;
3979  static const int kReturnValueIndex = 4;
3980  static const int kDataIndex = 5;
3981  static const int kThisIndex = 6;
3982 
3983  V8_INLINE PropertyCallbackInfo(internal::Address* args) : args_(args) {}
3984  internal::Address* args_;
3985 };
3986 
3987 
3988 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3989 
3990 enum class ConstructorBehavior { kThrow, kAllow };
3991 
3995 class V8_EXPORT Function : public Object {
3996  public:
4001  static MaybeLocal<Function> New(
4002  Local<Context> context, FunctionCallback callback,
4003  Local<Value> data = Local<Value>(), int length = 0,
4004  ConstructorBehavior behavior = ConstructorBehavior::kAllow,
4005  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4006  static V8_DEPRECATED("Use maybe version",
4007  Local<Function> New(Isolate* isolate,
4008  FunctionCallback callback,
4009  Local<Value> data = Local<Value>(),
4010  int length = 0));
4011 
4012  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
4013  Local<Context> context, int argc, Local<Value> argv[]) const;
4014 
4015  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
4016  Local<Context> context) const {
4017  return NewInstance(context, 0, nullptr);
4018  }
4019 
4025  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
4026  Local<Context> context, int argc, Local<Value> argv[],
4027  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4028 
4029  V8_DEPRECATED("Use maybe version",
4030  Local<Value> Call(Local<Value> recv, int argc,
4031  Local<Value> argv[]));
4032  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
4033  Local<Value> recv, int argc,
4034  Local<Value> argv[]);
4035 
4036  void SetName(Local<String> name);
4037  Local<Value> GetName() const;
4038 
4045  Local<Value> GetInferredName() const;
4046 
4051  Local<Value> GetDebugName() const;
4052 
4057  Local<Value> GetDisplayName() const;
4058 
4063  int GetScriptLineNumber() const;
4068  int GetScriptColumnNumber() const;
4069 
4073  int ScriptId() const;
4074 
4079  Local<Value> GetBoundFunction() const;
4080 
4081  ScriptOrigin GetScriptOrigin() const;
4082  V8_INLINE static Function* Cast(Value* obj);
4083  static const int kLineOffsetNotFound;
4084 
4085  private:
4086  Function();
4087  static void CheckCast(Value* obj);
4088 };
4089 
4090 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4091 // The number of required internal fields can be defined by embedder.
4092 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4093 #endif
4094 
4098 class V8_EXPORT Promise : public Object {
4099  public:
4104  enum PromiseState { kPending, kFulfilled, kRejected };
4105 
4106  class V8_EXPORT Resolver : public Object {
4107  public:
4111  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
4112  Local<Context> context);
4113 
4117  Local<Promise> GetPromise();
4118 
4123  V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context,
4124  Local<Value> value);
4125 
4126  V8_WARN_UNUSED_RESULT Maybe<bool> Reject(Local<Context> context,
4127  Local<Value> value);
4128 
4129  V8_INLINE static Resolver* Cast(Value* obj);
4130 
4131  private:
4132  Resolver();
4133  static void CheckCast(Value* obj);
4134  };
4135 
4142  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
4143  Local<Function> handler);
4144 
4145  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
4146  Local<Function> handler);
4147 
4152  bool HasHandler();
4153 
4158  Local<Value> Result();
4159 
4163  PromiseState State();
4164 
4168  void MarkAsHandled();
4169 
4170  V8_INLINE static Promise* Cast(Value* obj);
4171 
4172  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4173 
4174  private:
4175  Promise();
4176  static void CheckCast(Value* obj);
4177 };
4178 
4207 class V8_EXPORT PropertyDescriptor {
4208  public:
4209  // GenericDescriptor
4211 
4212  // DataDescriptor
4214 
4215  // DataDescriptor with writable property
4216  PropertyDescriptor(Local<Value> value, bool writable);
4217 
4218  // AccessorDescriptor
4220 
4221  ~PropertyDescriptor();
4222 
4223  Local<Value> value() const;
4224  bool has_value() const;
4225 
4226  Local<Value> get() const;
4227  bool has_get() const;
4228  Local<Value> set() const;
4229  bool has_set() const;
4230 
4231  void set_enumerable(bool enumerable);
4232  bool enumerable() const;
4233  bool has_enumerable() const;
4234 
4235  void set_configurable(bool configurable);
4236  bool configurable() const;
4237  bool has_configurable() const;
4238 
4239  bool writable() const;
4240  bool has_writable() const;
4241 
4242  struct PrivateData;
4243  PrivateData* get_private() const { return private_; }
4244 
4245  PropertyDescriptor(const PropertyDescriptor&) = delete;
4246  void operator=(const PropertyDescriptor&) = delete;
4247 
4248  private:
4249  PrivateData* private_;
4250 };
4251 
4256 class V8_EXPORT Proxy : public Object {
4257  public:
4258  Local<Value> GetTarget();
4259  Local<Value> GetHandler();
4260  bool IsRevoked();
4261  void Revoke();
4262 
4266  static MaybeLocal<Proxy> New(Local<Context> context,
4267  Local<Object> local_target,
4268  Local<Object> local_handler);
4269 
4270  V8_INLINE static Proxy* Cast(Value* obj);
4271 
4272  private:
4273  Proxy();
4274  static void CheckCast(Value* obj);
4275 };
4276 
4277 // TODO(mtrofin): rename WasmCompiledModule to WasmModuleObject, for
4278 // consistency with internal APIs.
4279 class V8_EXPORT WasmCompiledModule : public Object {
4280  public:
4281  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
4282 
4287  const uint8_t* start;
4288  size_t size;
4289  BufferReference(const uint8_t* start, size_t size)
4290  : start(start), size(size) {}
4291  };
4292 
4297  class TransferrableModule final {
4298  public:
4299  TransferrableModule(TransferrableModule&& src) = default;
4300  TransferrableModule(const TransferrableModule& src) = delete;
4301 
4302  TransferrableModule& operator=(TransferrableModule&& src) = default;
4303  TransferrableModule& operator=(const TransferrableModule& src) = delete;
4304 
4305  private:
4306  typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
4307  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
4308  friend class WasmCompiledModule;
4309  explicit TransferrableModule(SharedModule shared_module)
4310  : shared_module_(std::move(shared_module)) {}
4311  TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
4312  : serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
4313 
4314  SharedModule shared_module_;
4315  OwnedBuffer serialized_ = {nullptr, 0};
4316  OwnedBuffer wire_bytes_ = {nullptr, 0};
4317  };
4318 
4324  TransferrableModule GetTransferrableModule();
4325 
4330  static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
4331  Isolate* isolate, const TransferrableModule&);
4332 
4336  BufferReference GetWasmWireBytesRef();
4337 
4342  SerializedModule Serialize();
4343 
4348  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
4349  Isolate* isolate, BufferReference serialized_module,
4350  BufferReference wire_bytes);
4351  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
4352 
4353  private:
4354  static MaybeLocal<WasmCompiledModule> Deserialize(
4355  Isolate* isolate, BufferReference serialized_module,
4356  BufferReference wire_bytes);
4357  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
4358  const uint8_t* start,
4359  size_t length);
4360  static BufferReference AsReference(
4361  const TransferrableModule::OwnedBuffer& buff) {
4362  return {buff.first.get(), buff.second};
4363  }
4364 
4365  WasmCompiledModule();
4366  static void CheckCast(Value* obj);
4367 };
4368 
4375 class V8_EXPORT WasmStreaming final {
4376  public:
4377  class WasmStreamingImpl;
4378 
4379  WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
4380 
4381  ~WasmStreaming();
4382 
4387  void OnBytesReceived(const uint8_t* bytes, size_t size);
4388 
4394  void Finish();
4395 
4401  void Abort(MaybeLocal<Value> exception);
4402 
4407  typedef void (*ModuleCompiledCallback)(
4408  intptr_t data, Local<WasmCompiledModule> compiled_module);
4409 
4414  void SetModuleCompiledCallback(ModuleCompiledCallback callback,
4415  intptr_t data);
4416 
4424  bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size);
4425 
4431  static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
4432  Local<Value> value);
4433 
4434  private:
4435  std::unique_ptr<WasmStreamingImpl> impl_;
4436 };
4437 
4438 // TODO(mtrofin): when streaming compilation is done, we can rename this
4439 // to simply WasmModuleObjectBuilder
4440 class V8_EXPORT WasmModuleObjectBuilderStreaming final {
4441  public:
4442  explicit WasmModuleObjectBuilderStreaming(Isolate* isolate);
4446  void OnBytesReceived(const uint8_t*, size_t size);
4447  void Finish();
4453  void Abort(MaybeLocal<Value> exception);
4454  Local<Promise> GetPromise();
4455 
4456  ~WasmModuleObjectBuilderStreaming() = default;
4457 
4458  private:
4460  delete;
4462  default;
4464  const WasmModuleObjectBuilderStreaming&) = delete;
4466  WasmModuleObjectBuilderStreaming&&) = default;
4467  Isolate* isolate_ = nullptr;
4468 
4469 #if V8_CC_MSVC
4470 
4478 #else
4479  Persistent<Promise> promise_;
4480 #endif
4481  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4482 };
4483 
4484 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4485 // The number of required internal fields can be defined by embedder.
4486 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4487 #endif
4488 
4489 
4490 enum class ArrayBufferCreationMode { kInternalized, kExternalized };
4491 
4492 
4496 class V8_EXPORT ArrayBuffer : public Object {
4497  public:
4513  class V8_EXPORT Allocator { // NOLINT
4514  public:
4515  virtual ~Allocator() = default;
4516 
4521  virtual void* Allocate(size_t length) = 0;
4522 
4527  virtual void* AllocateUninitialized(size_t length) = 0;
4528 
4533  virtual void Free(void* data, size_t length) = 0;
4534 
4540  enum class AllocationMode { kNormal, kReservation };
4541 
4548  static Allocator* NewDefaultAllocator();
4549  };
4550 
4560  class V8_EXPORT Contents { // NOLINT
4561  public:
4562  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
4563 
4564  Contents()
4565  : data_(nullptr),
4566  byte_length_(0),
4567  allocation_base_(nullptr),
4568  allocation_length_(0),
4569  allocation_mode_(Allocator::AllocationMode::kNormal),
4570  deleter_(nullptr),
4571  deleter_data_(nullptr) {}
4572 
4573  void* AllocationBase() const { return allocation_base_; }
4574  size_t AllocationLength() const { return allocation_length_; }
4575  Allocator::AllocationMode AllocationMode() const {
4576  return allocation_mode_;
4577  }
4578 
4579  void* Data() const { return data_; }
4580  size_t ByteLength() const { return byte_length_; }
4581  DeleterCallback Deleter() const { return deleter_; }
4582  void* DeleterData() const { return deleter_data_; }
4583 
4584  private:
4585  Contents(void* data, size_t byte_length, void* allocation_base,
4586  size_t allocation_length,
4587  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
4588  void* deleter_data);
4589 
4590  void* data_;
4591  size_t byte_length_;
4592  void* allocation_base_;
4593  size_t allocation_length_;
4594  Allocator::AllocationMode allocation_mode_;
4595  DeleterCallback deleter_;
4596  void* deleter_data_;
4597 
4598  friend class ArrayBuffer;
4599  };
4600 
4601 
4605  size_t ByteLength() const;
4606 
4613  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4614 
4624  static Local<ArrayBuffer> New(
4625  Isolate* isolate, void* data, size_t byte_length,
4626  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
4627 
4632  bool IsExternal() const;
4633 
4637  bool IsNeuterable() const;
4638 
4645  void Neuter();
4646 
4657  Contents Externalize();
4658 
4667  Contents GetContents();
4668 
4669  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4670 
4671  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4672  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4673 
4674  private:
4675  ArrayBuffer();
4676  static void CheckCast(Value* obj);
4677 };
4678 
4679 
4680 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4681 // The number of required internal fields can be defined by embedder.
4682 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4683 #endif
4684 
4685 
4690 class V8_EXPORT ArrayBufferView : public Object {
4691  public:
4695  Local<ArrayBuffer> Buffer();
4699  size_t ByteOffset();
4703  size_t ByteLength();
4704 
4714  size_t CopyContents(void* dest, size_t byte_length);
4715 
4720  bool HasBuffer() const;
4721 
4722  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4723 
4724  static const int kInternalFieldCount =
4725  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4726  static const int kEmbedderFieldCount =
4727  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4728 
4729  private:
4730  ArrayBufferView();
4731  static void CheckCast(Value* obj);
4732 };
4733 
4734 
4739 class V8_EXPORT TypedArray : public ArrayBufferView {
4740  public:
4741  /*
4742  * The largest typed array size that can be constructed using New.
4743  */
4744  static constexpr size_t kMaxLength = internal::kSmiMaxValue;
4745 
4750  size_t Length();
4751 
4752  V8_INLINE static TypedArray* Cast(Value* obj);
4753 
4754  private:
4755  TypedArray();
4756  static void CheckCast(Value* obj);
4757 };
4758 
4759 
4763 class V8_EXPORT Uint8Array : public TypedArray {
4764  public:
4765  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4766  size_t byte_offset, size_t length);
4767  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4768  size_t byte_offset, size_t length);
4769  V8_INLINE static Uint8Array* Cast(Value* obj);
4770 
4771  private:
4772  Uint8Array();
4773  static void CheckCast(Value* obj);
4774 };
4775 
4776 
4780 class V8_EXPORT Uint8ClampedArray : public TypedArray {
4781  public:
4782  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4783  size_t byte_offset, size_t length);
4784  static Local<Uint8ClampedArray> New(
4785  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4786  size_t length);
4787  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4788 
4789  private:
4791  static void CheckCast(Value* obj);
4792 };
4793 
4797 class V8_EXPORT Int8Array : public TypedArray {
4798  public:
4799  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4800  size_t byte_offset, size_t length);
4801  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4802  size_t byte_offset, size_t length);
4803  V8_INLINE static Int8Array* Cast(Value* obj);
4804 
4805  private:
4806  Int8Array();
4807  static void CheckCast(Value* obj);
4808 };
4809 
4810 
4814 class V8_EXPORT Uint16Array : public TypedArray {
4815  public:
4816  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4817  size_t byte_offset, size_t length);
4818  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4819  size_t byte_offset, size_t length);
4820  V8_INLINE static Uint16Array* Cast(Value* obj);
4821 
4822  private:
4823  Uint16Array();
4824  static void CheckCast(Value* obj);
4825 };
4826 
4827 
4831 class V8_EXPORT Int16Array : public TypedArray {
4832  public:
4833  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4834  size_t byte_offset, size_t length);
4835  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4836  size_t byte_offset, size_t length);
4837  V8_INLINE static Int16Array* Cast(Value* obj);
4838 
4839  private:
4840  Int16Array();
4841  static void CheckCast(Value* obj);
4842 };
4843 
4844 
4848 class V8_EXPORT Uint32Array : public TypedArray {
4849  public:
4850  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4851  size_t byte_offset, size_t length);
4852  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4853  size_t byte_offset, size_t length);
4854  V8_INLINE static Uint32Array* Cast(Value* obj);
4855 
4856  private:
4857  Uint32Array();
4858  static void CheckCast(Value* obj);
4859 };
4860 
4861 
4865 class V8_EXPORT Int32Array : public TypedArray {
4866  public:
4867  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4868  size_t byte_offset, size_t length);
4869  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4870  size_t byte_offset, size_t length);
4871  V8_INLINE static Int32Array* Cast(Value* obj);
4872 
4873  private:
4874  Int32Array();
4875  static void CheckCast(Value* obj);
4876 };
4877 
4878 
4882 class V8_EXPORT Float32Array : public TypedArray {
4883  public:
4884  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4885  size_t byte_offset, size_t length);
4886  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4887  size_t byte_offset, size_t length);
4888  V8_INLINE static Float32Array* Cast(Value* obj);
4889 
4890  private:
4891  Float32Array();
4892  static void CheckCast(Value* obj);
4893 };
4894 
4895 
4899 class V8_EXPORT Float64Array : public TypedArray {
4900  public:
4901  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4902  size_t byte_offset, size_t length);
4903  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4904  size_t byte_offset, size_t length);
4905  V8_INLINE static Float64Array* Cast(Value* obj);
4906 
4907  private:
4908  Float64Array();
4909  static void CheckCast(Value* obj);
4910 };
4911 
4915 class V8_EXPORT BigInt64Array : public TypedArray {
4916  public:
4917  static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
4918  size_t byte_offset, size_t length);
4919  static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4920  size_t byte_offset, size_t length);
4921  V8_INLINE static BigInt64Array* Cast(Value* obj);
4922 
4923  private:
4924  BigInt64Array();
4925  static void CheckCast(Value* obj);
4926 };
4927 
4931 class V8_EXPORT BigUint64Array : public TypedArray {
4932  public:
4933  static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
4934  size_t byte_offset, size_t length);
4935  static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4936  size_t byte_offset, size_t length);
4937  V8_INLINE static BigUint64Array* Cast(Value* obj);
4938 
4939  private:
4940  BigUint64Array();
4941  static void CheckCast(Value* obj);
4942 };
4943 
4947 class V8_EXPORT DataView : public ArrayBufferView {
4948  public:
4949  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
4950  size_t byte_offset, size_t length);
4951  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
4952  size_t byte_offset, size_t length);
4953  V8_INLINE static DataView* Cast(Value* obj);
4954 
4955  private:
4956  DataView();
4957  static void CheckCast(Value* obj);
4958 };
4959 
4960 
4965 class V8_EXPORT SharedArrayBuffer : public Object {
4966  public:
4978  class V8_EXPORT Contents { // NOLINT
4979  public:
4981  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
4982 
4983  Contents()
4984  : data_(nullptr),
4985  byte_length_(0),
4986  allocation_base_(nullptr),
4987  allocation_length_(0),
4988  allocation_mode_(Allocator::AllocationMode::kNormal),
4989  deleter_(nullptr),
4990  deleter_data_(nullptr) {}
4991 
4992  void* AllocationBase() const { return allocation_base_; }
4993  size_t AllocationLength() const { return allocation_length_; }
4994  Allocator::AllocationMode AllocationMode() const {
4995  return allocation_mode_;
4996  }
4997 
4998  void* Data() const { return data_; }
4999  size_t ByteLength() const { return byte_length_; }
5000  DeleterCallback Deleter() const { return deleter_; }
5001  void* DeleterData() const { return deleter_data_; }
5002 
5003  private:
5004  Contents(void* data, size_t byte_length, void* allocation_base,
5005  size_t allocation_length,
5006  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
5007  void* deleter_data);
5008 
5009  void* data_;
5010  size_t byte_length_;
5011  void* allocation_base_;
5012  size_t allocation_length_;
5013  Allocator::AllocationMode allocation_mode_;
5014  DeleterCallback deleter_;
5015  void* deleter_data_;
5016 
5017  friend class SharedArrayBuffer;
5018  };
5019 
5023  size_t ByteLength() const;
5024 
5031  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
5032 
5039  static Local<SharedArrayBuffer> New(
5040  Isolate* isolate, void* data, size_t byte_length,
5041  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5042 
5047  bool IsExternal() const;
5048 
5061  Contents Externalize();
5062 
5075  Contents GetContents();
5076 
5077  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
5078 
5079  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5080 
5081  private:
5083  static void CheckCast(Value* obj);
5084 };
5085 
5086 
5090 class V8_EXPORT Date : public Object {
5091  public:
5092  static V8_DEPRECATED("Use maybe version.",
5093  Local<Value> New(Isolate* isolate, double time));
5094  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
5095  double time);
5096 
5101  double ValueOf() const;
5102 
5103  V8_INLINE static Date* Cast(Value* obj);
5104 
5117  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
5118 
5119  private:
5120  static void CheckCast(Value* obj);
5121 };
5122 
5123 
5127 class V8_EXPORT NumberObject : public Object {
5128  public:
5129  static Local<Value> New(Isolate* isolate, double value);
5130 
5131  double ValueOf() const;
5132 
5133  V8_INLINE static NumberObject* Cast(Value* obj);
5134 
5135  private:
5136  static void CheckCast(Value* obj);
5137 };
5138 
5142 class V8_EXPORT BigIntObject : public Object {
5143  public:
5144  static Local<Value> New(Isolate* isolate, int64_t value);
5145 
5146  Local<BigInt> ValueOf() const;
5147 
5148  V8_INLINE static BigIntObject* Cast(Value* obj);
5149 
5150  private:
5151  static void CheckCast(Value* obj);
5152 };
5153 
5157 class V8_EXPORT BooleanObject : public Object {
5158  public:
5159  static Local<Value> New(Isolate* isolate, bool value);
5160 
5161  bool ValueOf() const;
5162 
5163  V8_INLINE static BooleanObject* Cast(Value* obj);
5164 
5165  private:
5166  static void CheckCast(Value* obj);
5167 };
5168 
5169 
5173 class V8_EXPORT StringObject : public Object {
5174  public:
5175  static Local<Value> New(Isolate* isolate, Local<String> value);
5176 
5177  Local<String> ValueOf() const;
5178 
5179  V8_INLINE static StringObject* Cast(Value* obj);
5180 
5181  private:
5182  static void CheckCast(Value* obj);
5183 };
5184 
5185 
5189 class V8_EXPORT SymbolObject : public Object {
5190  public:
5191  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
5192 
5193  Local<Symbol> ValueOf() const;
5194 
5195  V8_INLINE static SymbolObject* Cast(Value* obj);
5196 
5197  private:
5198  static void CheckCast(Value* obj);
5199 };
5200 
5201 
5205 class V8_EXPORT RegExp : public Object {
5206  public:
5211  enum Flags {
5212  kNone = 0,
5213  kGlobal = 1 << 0,
5214  kIgnoreCase = 1 << 1,
5215  kMultiline = 1 << 2,
5216  kSticky = 1 << 3,
5217  kUnicode = 1 << 4,
5218  kDotAll = 1 << 5,
5219  };
5220 
5231  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
5232  Local<String> pattern,
5233  Flags flags);
5234 
5239  Local<String> GetSource() const;
5240 
5244  Flags GetFlags() const;
5245 
5246  V8_INLINE static RegExp* Cast(Value* obj);
5247 
5248  private:
5249  static void CheckCast(Value* obj);
5250 };
5251 
5252 
5257 class V8_EXPORT External : public Value {
5258  public:
5259  static Local<External> New(Isolate* isolate, void* value);
5260  V8_INLINE static External* Cast(Value* obj);
5261  void* Value() const;
5262  private:
5263  static void CheckCast(v8::Value* obj);
5264 };
5265 
5266 #define V8_INTRINSICS_LIST(F) \
5267  F(ArrayProto_entries, array_entries_iterator) \
5268  F(ArrayProto_forEach, array_for_each_iterator) \
5269  F(ArrayProto_keys, array_keys_iterator) \
5270  F(ArrayProto_values, array_values_iterator) \
5271  F(ErrorPrototype, initial_error_prototype) \
5272  F(IteratorPrototype, initial_iterator_prototype)
5273 
5274 enum Intrinsic {
5275 #define V8_DECL_INTRINSIC(name, iname) k##name,
5276  V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
5277 #undef V8_DECL_INTRINSIC
5278 };
5279 
5280 
5281 // --- Templates ---
5282 
5283 
5287 class V8_EXPORT Template : public Data {
5288  public:
5294  void Set(Local<Name> name, Local<Data> value,
5295  PropertyAttribute attributes = None);
5296  void SetPrivate(Local<Private> name, Local<Data> value,
5297  PropertyAttribute attributes = None);
5298  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5299 
5300  void SetAccessorProperty(
5301  Local<Name> name,
5304  PropertyAttribute attribute = None,
5305  AccessControl settings = DEFAULT);
5306 
5334  void SetNativeDataProperty(
5336  AccessorSetterCallback setter = nullptr,
5337  // TODO(dcarney): gcc can't handle Local below
5338  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5340  AccessControl settings = DEFAULT,
5341  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5342  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5343  void SetNativeDataProperty(
5344  Local<Name> name, AccessorNameGetterCallback getter,
5345  AccessorNameSetterCallback setter = nullptr,
5346  // TODO(dcarney): gcc can't handle Local below
5347  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5349  AccessControl settings = DEFAULT,
5350  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5351  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5352 
5357  void SetLazyDataProperty(
5358  Local<Name> name, AccessorNameGetterCallback getter,
5359  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5360  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5361  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5362 
5367  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5368  PropertyAttribute attribute = None);
5369 
5370  private:
5371  Template();
5372 
5373  friend class ObjectTemplate;
5374  friend class FunctionTemplate;
5375 };
5376 
5377 // TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
5378 // NamedPropertyFooCallback.
5379 
5417  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5418 
5441  Local<Name> property, Local<Value> value,
5442  const PropertyCallbackInfo<Value>& info);
5443 
5466  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5467 
5490  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5491 
5499  const PropertyCallbackInfo<Array>& info);
5500 
5522  Local<Name> property, const PropertyDescriptor& desc,
5523  const PropertyCallbackInfo<Value>& info);
5524 
5545  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5546 
5551  uint32_t index,
5552  const PropertyCallbackInfo<Value>& info);
5553 
5558  uint32_t index,
5559  Local<Value> value,
5560  const PropertyCallbackInfo<Value>& info);
5561 
5566  uint32_t index,
5567  const PropertyCallbackInfo<Integer>& info);
5568 
5573  uint32_t index,
5574  const PropertyCallbackInfo<Boolean>& info);
5575 
5583  const PropertyCallbackInfo<Array>& info);
5584 
5589  uint32_t index, const PropertyDescriptor& desc,
5590  const PropertyCallbackInfo<Value>& info);
5591 
5596  uint32_t index, const PropertyCallbackInfo<Value>& info);
5597 
5602  ACCESS_GET,
5603  ACCESS_SET,
5604  ACCESS_HAS,
5605  ACCESS_DELETE,
5606  ACCESS_KEYS
5607 };
5608 
5609 
5614 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5615  Local<Object> accessed_object,
5616  Local<Value> data);
5617 
5718 class V8_EXPORT FunctionTemplate : public Template {
5719  public:
5721  static Local<FunctionTemplate> New(
5722  Isolate* isolate, FunctionCallback callback = nullptr,
5723  Local<Value> data = Local<Value>(),
5724  Local<Signature> signature = Local<Signature>(), int length = 0,
5725  ConstructorBehavior behavior = ConstructorBehavior::kAllow,
5726  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5727 
5729  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5730  size_t index);
5731 
5735  static Local<FunctionTemplate> NewWithCache(
5736  Isolate* isolate, FunctionCallback callback,
5737  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5738  Local<Signature> signature = Local<Signature>(), int length = 0,
5739  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5740 
5742  V8_DEPRECATED("Use maybe version", Local<Function> GetFunction());
5743  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
5744  Local<Context> context);
5745 
5753  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5754 
5760  void SetCallHandler(
5761  FunctionCallback callback, Local<Value> data = Local<Value>(),
5762  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5763 
5765  void SetLength(int length);
5766 
5768  Local<ObjectTemplate> InstanceTemplate();
5769 
5775  void Inherit(Local<FunctionTemplate> parent);
5776 
5781  Local<ObjectTemplate> PrototypeTemplate();
5782 
5789  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5790 
5796  void SetClassName(Local<String> name);
5797 
5798 
5803  void SetAcceptAnyReceiver(bool value);
5804 
5817  void SetHiddenPrototype(bool value);
5818 
5823  void ReadOnlyPrototype();
5824 
5829  void RemovePrototype();
5830 
5835  bool HasInstance(Local<Value> object);
5836 
5837  V8_INLINE static FunctionTemplate* Cast(Data* data);
5838 
5839  private:
5840  FunctionTemplate();
5841 
5842  static void CheckCast(Data* that);
5843  friend class Context;
5844  friend class ObjectTemplate;
5845 };
5846 
5855  kNone = 0,
5856 
5860  kAllCanRead = 1,
5861 
5866  kNonMasking = 1 << 1,
5867 
5872  kOnlyInterceptStrings = 1 << 2,
5873 
5877  kHasNoSideEffect = 1 << 3,
5878 };
5879 
5889  Local<Value> data = Local<Value>(),
5891  : getter(getter),
5892  setter(setter),
5893  query(query),
5894  deleter(deleter),
5895  enumerator(enumerator),
5896  definer(definer),
5897  descriptor(descriptor),
5898  data(data),
5899  flags(flags) {}
5900 
5903  GenericNamedPropertyGetterCallback getter = nullptr,
5904  GenericNamedPropertySetterCallback setter = nullptr,
5905  GenericNamedPropertyQueryCallback query = nullptr,
5906  GenericNamedPropertyDeleterCallback deleter = nullptr,
5907  GenericNamedPropertyEnumeratorCallback enumerator = nullptr,
5908  Local<Value> data = Local<Value>(),
5910  : getter(getter),
5911  setter(setter),
5912  query(query),
5913  deleter(deleter),
5914  enumerator(enumerator),
5915  definer(nullptr),
5916  descriptor(nullptr),
5917  data(data),
5918  flags(flags) {}
5919 
5927  Local<Value> data = Local<Value>(),
5929  : getter(getter),
5930  setter(setter),
5931  query(nullptr),
5932  deleter(deleter),
5933  enumerator(enumerator),
5934  definer(definer),
5935  descriptor(descriptor),
5936  data(data),
5937  flags(flags) {}
5938 
5946  Local<Value> data;
5947  PropertyHandlerFlags flags;
5948 };
5949 
5950 
5959  Local<Value> data = Local<Value>(),
5961  : getter(getter),
5962  setter(setter),
5963  query(query),
5964  deleter(deleter),
5965  enumerator(enumerator),
5966  definer(definer),
5967  descriptor(descriptor),
5968  data(data),
5969  flags(flags) {}
5970 
5973  IndexedPropertyGetterCallback getter = nullptr,
5974  IndexedPropertySetterCallback setter = nullptr,
5975  IndexedPropertyQueryCallback query = nullptr,
5976  IndexedPropertyDeleterCallback deleter = nullptr,
5977  IndexedPropertyEnumeratorCallback enumerator = nullptr,
5978  Local<Value> data = Local<Value>(),
5980  : getter(getter),
5981  setter(setter),
5982  query(query),
5983  deleter(deleter),
5984  enumerator(enumerator),
5985  definer(nullptr),
5986  descriptor(nullptr),
5987  data(data),
5988  flags(flags) {}
5989 
5997  Local<Value> data = Local<Value>(),
5999  : getter(getter),
6000  setter(setter),
6001  query(nullptr),
6002  deleter(deleter),
6003  enumerator(enumerator),
6004  definer(definer),
6005  descriptor(descriptor),
6006  data(data),
6007  flags(flags) {}
6008 
6016  Local<Value> data;
6017  PropertyHandlerFlags flags;
6018 };
6019 
6020 
6027 class V8_EXPORT ObjectTemplate : public Template {
6028  public:
6030  static Local<ObjectTemplate> New(
6031  Isolate* isolate,
6033 
6035  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
6036  size_t index);
6037 
6039  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance());
6040  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
6041 
6071  void SetAccessor(
6073  AccessorSetterCallback setter = nullptr,
6074  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
6075  PropertyAttribute attribute = None,
6077  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6078  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6079  void SetAccessor(
6080  Local<Name> name, AccessorNameGetterCallback getter,
6081  AccessorNameSetterCallback setter = nullptr,
6082  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
6083  PropertyAttribute attribute = None,
6085  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6086  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6087 
6099  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
6100 
6117  // TODO(dcarney): deprecate
6120  IndexedPropertySetterCallback setter = nullptr,
6121  IndexedPropertyQueryCallback query = nullptr,
6122  IndexedPropertyDeleterCallback deleter = nullptr,
6123  IndexedPropertyEnumeratorCallback enumerator = nullptr,
6124  Local<Value> data = Local<Value>()) {
6125  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
6126  deleter, enumerator, data));
6127  }
6128 
6139  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
6140 
6147  void SetCallAsFunctionHandler(FunctionCallback callback,
6148  Local<Value> data = Local<Value>());
6149 
6158  void MarkAsUndetectable();
6159 
6168  void SetAccessCheckCallback(AccessCheckCallback callback,
6169  Local<Value> data = Local<Value>());
6170 
6177  void SetAccessCheckCallbackAndHandler(
6178  AccessCheckCallback callback,
6179  const NamedPropertyHandlerConfiguration& named_handler,
6180  const IndexedPropertyHandlerConfiguration& indexed_handler,
6181  Local<Value> data = Local<Value>());
6182 
6187  int InternalFieldCount();
6188 
6193  void SetInternalFieldCount(int value);
6194 
6198  bool IsImmutableProto();
6199 
6204  void SetImmutableProto();
6205 
6206  V8_INLINE static ObjectTemplate* Cast(Data* data);
6207 
6208  private:
6209  ObjectTemplate();
6210  static Local<ObjectTemplate> New(internal::Isolate* isolate,
6211  Local<FunctionTemplate> constructor);
6212  static void CheckCast(Data* that);
6213  friend class FunctionTemplate;
6214 };
6215 
6224 class V8_EXPORT Signature : public Data {
6225  public:
6226  static Local<Signature> New(
6227  Isolate* isolate,
6229 
6230  V8_INLINE static Signature* Cast(Data* data);
6231 
6232  private:
6233  Signature();
6234 
6235  static void CheckCast(Data* that);
6236 };
6237 
6238 
6243 class V8_EXPORT AccessorSignature : public Data {
6244  public:
6245  static Local<AccessorSignature> New(
6246  Isolate* isolate,
6248 
6249  V8_INLINE static AccessorSignature* Cast(Data* data);
6250 
6251  private:
6253 
6254  static void CheckCast(Data* that);
6255 };
6256 
6257 
6258 // --- Extensions ---
6259 V8_DEPRECATED("Implementation detail", class)
6260 V8_EXPORT ExternalOneByteStringResourceImpl
6261  : public String::ExternalOneByteStringResource {
6262  public:
6263  ExternalOneByteStringResourceImpl() : data_(nullptr), length_(0) {}
6264  ExternalOneByteStringResourceImpl(const char* data, size_t length)
6265  : data_(data), length_(length) {}
6266  const char* data() const override { return data_; }
6267  size_t length() const override { return length_; }
6268 
6269  private:
6270  const char* data_;
6271  size_t length_;
6272 };
6273 
6277 class V8_EXPORT Extension { // NOLINT
6278  public:
6279  // Note that the strings passed into this constructor must live as long
6280  // as the Extension itself.
6281  Extension(const char* name, const char* source = nullptr, int dep_count = 0,
6282  const char** deps = nullptr, int source_length = -1);
6283  virtual ~Extension() { delete source_; }
6284  virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
6285  Isolate* isolate, Local<String> name) {
6286  return Local<FunctionTemplate>();
6287  }
6288 
6289  const char* name() const { return name_; }
6290  size_t source_length() const { return source_length_; }
6291  const String::ExternalOneByteStringResource* source() const {
6292  return source_;
6293  }
6294  int dependency_count() { return dep_count_; }
6295  const char** dependencies() { return deps_; }
6296  void set_auto_enable(bool value) { auto_enable_ = value; }
6297  bool auto_enable() { return auto_enable_; }
6298 
6299  // Disallow copying and assigning.
6300  Extension(const Extension&) = delete;
6301  void operator=(const Extension&) = delete;
6302 
6303  private:
6304  const char* name_;
6305  size_t source_length_; // expected to initialize before source_
6306  String::ExternalOneByteStringResource* source_;
6307  int dep_count_;
6308  const char** deps_;
6309  bool auto_enable_;
6310 };
6311 
6312 
6313 void V8_EXPORT RegisterExtension(Extension* extension);
6314 
6315 
6316 // --- Statics ---
6317 
6318 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6319 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6320 V8_INLINE Local<Boolean> True(Isolate* isolate);
6321 V8_INLINE Local<Boolean> False(Isolate* isolate);
6322 
6337 class V8_EXPORT ResourceConstraints {
6338  public:
6339  ResourceConstraints();
6340 
6350  void ConfigureDefaults(uint64_t physical_memory,
6351  uint64_t virtual_memory_limit);
6352 
6353  // Returns the max semi-space size in MB.
6354  V8_DEPRECATED("Use max_semi_space_size_in_kb()",
6355  size_t max_semi_space_size()) {
6356  return max_semi_space_size_in_kb_ / 1024;
6357  }
6358 
6359  // Sets the max semi-space size in MB.
6360  V8_DEPRECATED("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6361  void set_max_semi_space_size(size_t limit_in_mb)) {
6362  max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6363  }
6364 
6365  // Returns the max semi-space size in KB.
6366  size_t max_semi_space_size_in_kb() const {
6367  return max_semi_space_size_in_kb_;
6368  }
6369 
6370  // Sets the max semi-space size in KB.
6371  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6372  max_semi_space_size_in_kb_ = limit_in_kb;
6373  }
6374 
6375  size_t max_old_space_size() const { return max_old_space_size_; }
6376  void set_max_old_space_size(size_t limit_in_mb) {
6377  max_old_space_size_ = limit_in_mb;
6378  }
6379  V8_DEPRECATED("max_executable_size_ is subsumed by max_old_space_size_",
6380  size_t max_executable_size() const) {
6381  return max_executable_size_;
6382  }
6383  V8_DEPRECATED("max_executable_size_ is subsumed by max_old_space_size_",
6384  void set_max_executable_size(size_t limit_in_mb)) {
6385  max_executable_size_ = limit_in_mb;
6386  }
6387  uint32_t* stack_limit() const { return stack_limit_; }
6388  // Sets an address beyond which the VM's stack may not grow.
6389  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6390  size_t code_range_size() const { return code_range_size_; }
6391  void set_code_range_size(size_t limit_in_mb) {
6392  code_range_size_ = limit_in_mb;
6393  }
6394  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6395  void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; }
6396 
6397  private:
6398  // max_semi_space_size_ is in KB
6399  size_t max_semi_space_size_in_kb_;
6400 
6401  // The remaining limits are in MB
6402  size_t max_old_space_size_;
6403  size_t max_executable_size_;
6404  uint32_t* stack_limit_;
6405  size_t code_range_size_;
6406  size_t max_zone_pool_size_;
6407 };
6408 
6409 
6410 // --- Exceptions ---
6411 
6412 
6413 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6414 
6415 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6416 
6417 typedef void (*DcheckErrorCallback)(const char* file, int line,
6418  const char* message);
6419 
6420 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6421 
6422 // --- Tracing ---
6423 
6424 typedef void (*LogEventCallback)(const char* name, int event);
6425 
6430 class V8_EXPORT Exception {
6431  public:
6432  static Local<Value> RangeError(Local<String> message);
6433  static Local<Value> ReferenceError(Local<String> message);
6434  static Local<Value> SyntaxError(Local<String> message);
6435  static Local<Value> TypeError(Local<String> message);
6436  static Local<Value> Error(Local<String> message);
6437 
6443  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6444 
6449  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6450 };
6451 
6452 
6453 // --- Counters Callbacks ---
6454 
6455 typedef int* (*CounterLookupCallback)(const char* name);
6456 
6457 typedef void* (*CreateHistogramCallback)(const char* name,
6458  int min,
6459  int max,
6460  size_t buckets);
6461 
6462 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6463 
6464 // --- Enter/Leave Script Callback ---
6465 typedef void (*BeforeCallEnteredCallback)(Isolate*);
6466 typedef void (*CallCompletedCallback)(Isolate*);
6467 
6488 typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)(
6489  Local<Context> context, Local<ScriptOrModule> referrer,
6490  Local<String> specifier);
6491 
6502 typedef void (*HostInitializeImportMetaObjectCallback)(Local<Context> context,
6503  Local<Module> module,
6504  Local<Object> meta);
6505 
6513 typedef MaybeLocal<Value> (*PrepareStackTraceCallback)(Local<Context> context,
6514  Local<Value> error,
6515  Local<Array> sites);
6516 
6533 enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
6534 
6535 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6536  Local<Value> parent);
6537 
6538 // --- Promise Reject Callback ---
6539 enum PromiseRejectEvent {
6540  kPromiseRejectWithNoHandler = 0,
6541  kPromiseHandlerAddedAfterReject = 1,
6542  kPromiseRejectAfterResolved = 2,
6543  kPromiseResolveAfterResolved = 3,
6544 };
6545 
6546 class PromiseRejectMessage {
6547  public:
6548  PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
6549  Local<Value> value, Local<StackTrace> stack_trace)
6550  : promise_(promise),
6551  event_(event),
6552  value_(value),
6553  stack_trace_(stack_trace) {}
6554 
6555  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6556  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6557  V8_INLINE Local<Value> GetValue() const { return value_; }
6558 
6559  private:
6560  Local<Promise> promise_;
6561  PromiseRejectEvent event_;
6562  Local<Value> value_;
6563  Local<StackTrace> stack_trace_;
6564 };
6565 
6566 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
6567 
6568 // --- Microtasks Callbacks ---
6569 typedef void (*MicrotasksCompletedCallback)(Isolate*);
6570 typedef void (*MicrotaskCallback)(void* data);
6571 
6572 
6580 enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
6581 
6582 
6592 class V8_EXPORT MicrotasksScope {
6593  public:
6594  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6595 
6596  MicrotasksScope(Isolate* isolate, Type type);
6597  ~MicrotasksScope();
6598 
6602  static void PerformCheckpoint(Isolate* isolate);
6603 
6607  static int GetCurrentDepth(Isolate* isolate);
6608 
6612  static bool IsRunningMicrotasks(Isolate* isolate);
6613 
6614  // Prevent copying.
6615  MicrotasksScope(const MicrotasksScope&) = delete;
6616  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6617 
6618  private:
6619  internal::Isolate* const isolate_;
6620  bool run_;
6621 };
6622 
6623 
6624 // --- Failed Access Check Callback ---
6625 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
6626  AccessType type,
6627  Local<Value> data);
6628 
6629 // --- AllowCodeGenerationFromStrings callbacks ---
6630 
6635 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context,
6636  Local<String> source);
6637 
6638 // --- WebAssembly compilation callbacks ---
6639 typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
6640 
6641 typedef bool (*AllowWasmCodeGenerationCallback)(Local<Context> context,
6642  Local<String> source);
6643 
6644 // --- Callback for APIs defined on v8-supported objects, but implemented
6645 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6646 typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&);
6647 
6648 // --- Callback for WebAssembly.compileStreaming ---
6649 typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo<Value>&);
6650 
6651 // --- Callback for checking if WebAssembly threads are enabled ---
6652 typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context);
6653 
6654 // --- Garbage Collection Callbacks ---
6655 
6663 enum GCType {
6664  kGCTypeScavenge = 1 << 0,
6665  kGCTypeMarkSweepCompact = 1 << 1,
6666  kGCTypeIncrementalMarking = 1 << 2,
6667  kGCTypeProcessWeakCallbacks = 1 << 3,
6668  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
6669  kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
6670 };
6671 
6686 enum GCCallbackFlags {
6687  kNoGCCallbackFlags = 0,
6688  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
6689  kGCCallbackFlagForced = 1 << 2,
6690  kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
6691  kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
6692  kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
6693  kGCCallbackScheduleIdleGarbageCollection = 1 << 6,
6694 };
6695 
6696 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6697 
6698 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6699 
6707 typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
6708  size_t initial_heap_limit);
6709 
6716 class V8_EXPORT HeapStatistics {
6717  public:
6718  HeapStatistics();
6719  size_t total_heap_size() { return total_heap_size_; }
6720  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6721  size_t total_physical_size() { return total_physical_size_; }
6722  size_t total_available_size() { return total_available_size_; }
6723  size_t used_heap_size() { return used_heap_size_; }
6724  size_t heap_size_limit() { return heap_size_limit_; }
6725  size_t malloced_memory() { return malloced_memory_; }
6726  size_t external_memory() { return external_memory_; }
6727  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6728  size_t number_of_native_contexts() { return number_of_native_contexts_; }
6729  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
6730 
6735  size_t does_zap_garbage() { return does_zap_garbage_; }
6736 
6737  private:
6738  size_t total_heap_size_;
6739  size_t total_heap_size_executable_;
6740  size_t total_physical_size_;
6741  size_t total_available_size_;
6742  size_t used_heap_size_;
6743  size_t heap_size_limit_;
6744  size_t malloced_memory_;
6745  size_t external_memory_;
6746  size_t peak_malloced_memory_;
6747  bool does_zap_garbage_;
6748  size_t number_of_native_contexts_;
6749  size_t number_of_detached_contexts_;
6750 
6751  friend class V8;
6752  friend class Isolate;
6753 };
6754 
6755 
6756 class V8_EXPORT HeapSpaceStatistics {
6757  public:
6758  HeapSpaceStatistics();
6759  const char* space_name() { return space_name_; }
6760  size_t space_size() { return space_size_; }
6761  size_t space_used_size() { return space_used_size_; }
6762  size_t space_available_size() { return space_available_size_; }
6763  size_t physical_space_size() { return physical_space_size_; }
6764 
6765  private:
6766  const char* space_name_;
6767  size_t space_size_;
6768  size_t space_used_size_;
6769  size_t space_available_size_;
6770  size_t physical_space_size_;
6771 
6772  friend class Isolate;
6773 };
6774 
6775 
6776 class V8_EXPORT HeapObjectStatistics {
6777  public:
6778  HeapObjectStatistics();
6779  const char* object_type() { return object_type_; }
6780  const char* object_sub_type() { return object_sub_type_; }
6781  size_t object_count() { return object_count_; }
6782  size_t object_size() { return object_size_; }
6783 
6784  private:
6785  const char* object_type_;
6786  const char* object_sub_type_;
6787  size_t object_count_;
6788  size_t object_size_;
6789 
6790  friend class Isolate;
6791 };
6792 
6793 class V8_EXPORT HeapCodeStatistics {
6794  public:
6795  HeapCodeStatistics();
6796  size_t code_and_metadata_size() { return code_and_metadata_size_; }
6797  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
6798  size_t external_script_source_size() { return external_script_source_size_; }
6799 
6800  private:
6801  size_t code_and_metadata_size_;
6802  size_t bytecode_and_metadata_size_;
6803  size_t external_script_source_size_;
6804 
6805  friend class Isolate;
6806 };
6807 
6808 class RetainedObjectInfo;
6809 
6810 
6822 typedef void (*FunctionEntryHook)(uintptr_t function,
6823  uintptr_t return_addr_location);
6824 
6830 struct JitCodeEvent {
6831  enum EventType {
6832  CODE_ADDED,
6833  CODE_MOVED,
6834  CODE_REMOVED,
6835  CODE_ADD_LINE_POS_INFO,
6836  CODE_START_LINE_INFO_RECORDING,
6837  CODE_END_LINE_INFO_RECORDING
6838  };
6839  // Definition of the code position type. The "POSITION" type means the place
6840  // in the source code which are of interest when making stack traces to
6841  // pin-point the source location of a stack frame as close as possible.
6842  // The "STATEMENT_POSITION" means the place at the beginning of each
6843  // statement, and is used to indicate possible break locations.
6844  enum PositionType { POSITION, STATEMENT_POSITION };
6845 
6846  // There are two different kinds of JitCodeEvents, one for JIT code generated
6847  // by the optimizing compiler, and one for byte code generated for the
6848  // interpreter. For JIT_CODE events, the |code_start| member of the event
6849  // points to the beginning of jitted assembly code, while for BYTE_CODE
6850  // events, |code_start| points to the first bytecode of the interpreted
6851  // function.
6852  enum CodeType { BYTE_CODE, JIT_CODE };
6853 
6854  // Type of event.
6855  EventType type;
6856  CodeType code_type;
6857  // Start of the instructions.
6858  void* code_start;
6859  // Size of the instructions.
6860  size_t code_len;
6861  // Script info for CODE_ADDED event.
6862  Local<UnboundScript> script;
6863  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
6864  // code line information which is returned from the
6865  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
6866  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
6867  void* user_data;
6868 
6869  struct name_t {
6870  // Name of the object associated with the code, note that the string is not
6871  // zero-terminated.
6872  const char* str;
6873  // Number of chars in str.
6874  size_t len;
6875  };
6876 
6877  struct line_info_t {
6878  // PC offset
6879  size_t offset;
6880  // Code position
6881  size_t pos;
6882  // The position type.
6883  PositionType position_type;
6884  };
6885 
6886  union {
6887  // Only valid for CODE_ADDED.
6888  struct name_t name;
6889 
6890  // Only valid for CODE_ADD_LINE_POS_INFO
6891  struct line_info_t line_info;
6892 
6893  // New location of instructions. Only valid for CODE_MOVED.
6894  void* new_code_start;
6895  };
6896 
6897  Isolate* isolate;
6898 };
6899 
6905 enum RAILMode {
6906  // Response performance mode: In this mode very low virtual machine latency
6907  // is provided. V8 will try to avoid JavaScript execution interruptions.
6908  // Throughput may be throttled.
6909  PERFORMANCE_RESPONSE,
6910  // Animation performance mode: In this mode low virtual machine latency is
6911  // provided. V8 will try to avoid as many JavaScript execution interruptions
6912  // as possible. Throughput may be throttled. This is the default mode.
6913  PERFORMANCE_ANIMATION,
6914  // Idle performance mode: The embedder is idle. V8 can complete deferred work
6915  // in this mode.
6916  PERFORMANCE_IDLE,
6917  // Load performance mode: In this mode high throughput is provided. V8 may
6918  // turn off latency optimizations.
6919  PERFORMANCE_LOAD
6920 };
6921 
6925 enum JitCodeEventOptions {
6926  kJitCodeEventDefault = 0,
6927  // Generate callbacks for already existent code.
6928  kJitCodeEventEnumExisting = 1
6929 };
6930 
6931 
6937 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
6938 
6939 
6943 class V8_EXPORT ExternalResourceVisitor { // NOLINT
6944  public:
6945  virtual ~ExternalResourceVisitor() = default;
6946  virtual void VisitExternalString(Local<String> string) {}
6947 };
6948 
6949 
6953 class V8_EXPORT PersistentHandleVisitor { // NOLINT
6954  public:
6955  virtual ~PersistentHandleVisitor() = default;
6956  virtual void VisitPersistentHandle(Persistent<Value>* value,
6957  uint16_t class_id) {}
6958 };
6959 
6968 enum class MemoryPressureLevel { kNone, kModerate, kCritical };
6969 
6977 class V8_EXPORT EmbedderHeapTracer {
6978  public:
6979  // Indicator for the stack state of the embedder.
6980  enum EmbedderStackState {
6981  kUnknown,
6982  kNonEmpty,
6983  kEmpty,
6984  };
6985 
6986  virtual ~EmbedderHeapTracer() = default;
6987 
6994  virtual void RegisterV8References(
6995  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
6996 
7000  virtual void TracePrologue() = 0;
7001 
7012  virtual bool AdvanceTracing(double deadline_in_ms) = 0;
7013 
7014  /*
7015  * Returns true if there no more tracing work to be done (see AdvanceTracing)
7016  * and false otherwise.
7017  */
7018  virtual bool IsTracingDone() = 0;
7019 
7025  virtual void TraceEpilogue() = 0;
7026 
7031  virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
7032 
7039  V8_DEPRECATED("Obsolete as V8 will not abort tracing anymore.",
7040  virtual void AbortTracing()) {}
7041 
7042  /*
7043  * Called by the embedder to request immediate finalization of the currently
7044  * running tracing phase that has been started with TracePrologue and not
7045  * yet finished with TraceEpilogue.
7046  *
7047  * Will be a noop when currently not in tracing.
7048  *
7049  * This is an experimental feature.
7050  */
7051  void FinalizeTracing();
7052 
7053  /*
7054  * Called by the embedder to immediately perform a full garbage collection.
7055  *
7056  * Should only be used in testing code.
7057  */
7058  void GarbageCollectionForTesting(EmbedderStackState stack_state);
7059 
7060  /*
7061  * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
7062  * is not attached to any v8::Isolate.
7063  */
7064  v8::Isolate* isolate() const { return isolate_; }
7065 
7066  protected:
7067  v8::Isolate* isolate_ = nullptr;
7068 
7069  friend class internal::LocalEmbedderHeapTracer;
7070 };
7071 
7080 struct SerializeInternalFieldsCallback {
7081  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
7082  void* data);
7083  SerializeInternalFieldsCallback(CallbackFunction function = nullptr,
7084  void* data_arg = nullptr)
7085  : callback(function), data(data_arg) {}
7086  CallbackFunction callback;
7087  void* data;
7088 };
7089 // Note that these fields are called "internal fields" in the API and called
7090 // "embedder fields" within V8.
7091 typedef SerializeInternalFieldsCallback SerializeEmbedderFieldsCallback;
7092 
7097 struct DeserializeInternalFieldsCallback {
7098  typedef void (*CallbackFunction)(Local<Object> holder, int index,
7099  StartupData payload, void* data);
7100  DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
7101  void* data_arg = nullptr)
7102  : callback(function), data(data_arg) {}
7103  void (*callback)(Local<Object> holder, int index, StartupData payload,
7104  void* data);
7105  void* data;
7106 };
7107 typedef DeserializeInternalFieldsCallback DeserializeEmbedderFieldsCallback;
7108 
7117 class V8_EXPORT Isolate {
7118  public:
7122  struct CreateParams {
7123  CreateParams()
7124  : entry_hook(nullptr),
7125  code_event_handler(nullptr),
7126  snapshot_blob(nullptr),
7127  counter_lookup_callback(nullptr),
7128  create_histogram_callback(nullptr),
7129  add_histogram_sample_callback(nullptr),
7130  array_buffer_allocator(nullptr),
7131  external_references(nullptr),
7132  allow_atomics_wait(true),
7133  only_terminate_in_safe_scope(false) {}
7134 
7144  FunctionEntryHook entry_hook;
7145 
7150  JitCodeEventHandler code_event_handler;
7151 
7155  ResourceConstraints constraints;
7156 
7160  StartupData* snapshot_blob;
7161 
7162 
7167  CounterLookupCallback counter_lookup_callback;
7168 
7175  CreateHistogramCallback create_histogram_callback;
7176  AddHistogramSampleCallback add_histogram_sample_callback;
7177 
7183 
7190  const intptr_t* external_references;
7191 
7197 
7202  };
7203 
7204 
7209  class V8_EXPORT Scope {
7210  public:
7211  explicit Scope(Isolate* isolate) : isolate_(isolate) {
7212  isolate->Enter();
7213  }
7214 
7215  ~Scope() { isolate_->Exit(); }
7216 
7217  // Prevent copying of Scope objects.
7218  Scope(const Scope&) = delete;
7219  Scope& operator=(const Scope&) = delete;
7220 
7221  private:
7222  Isolate* const isolate_;
7223  };
7224 
7225 
7230  public:
7231  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
7232 
7233  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
7235 
7236  // Prevent copying of Scope objects.
7238  delete;
7240  const DisallowJavascriptExecutionScope&) = delete;
7241 
7242  private:
7243  OnFailure on_failure_;
7244  void* internal_;
7245  };
7246 
7247 
7252  public:
7253  explicit AllowJavascriptExecutionScope(Isolate* isolate);
7255 
7256  // Prevent copying of Scope objects.
7258  delete;
7259  AllowJavascriptExecutionScope& operator=(
7260  const AllowJavascriptExecutionScope&) = delete;
7261 
7262  private:
7263  void* internal_throws_;
7264  void* internal_assert_;
7265  void* internal_dump_;
7266  };
7267 
7273  public:
7274  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7276 
7277  // Prevent copying of Scope objects.
7279  delete;
7281  const SuppressMicrotaskExecutionScope&) = delete;
7282 
7283  private:
7284  internal::Isolate* const isolate_;
7285  };
7286 
7291  class V8_EXPORT SafeForTerminationScope {
7292  public:
7293  explicit SafeForTerminationScope(v8::Isolate* isolate);
7295 
7296  // Prevent copying of Scope objects.
7298  SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
7299 
7300  private:
7301  internal::Isolate* isolate_;
7302  bool prev_value_;
7303  };
7304 
7309  enum GarbageCollectionType {
7310  kFullGarbageCollection,
7311  kMinorGarbageCollection
7312  };
7313 
7319  enum UseCounterFeature {
7320  kUseAsm = 0,
7321  kBreakIterator = 1,
7322  kLegacyConst = 2,
7323  kMarkDequeOverflow = 3,
7324  kStoreBufferOverflow = 4,
7325  kSlotsBufferOverflow = 5,
7326  kObjectObserve = 6,
7327  kForcedGC = 7,
7328  kSloppyMode = 8,
7329  kStrictMode = 9,
7330  kStrongMode = 10,
7331  kRegExpPrototypeStickyGetter = 11,
7332  kRegExpPrototypeToString = 12,
7333  kRegExpPrototypeUnicodeGetter = 13,
7334  kIntlV8Parse = 14,
7335  kIntlPattern = 15,
7336  kIntlResolved = 16,
7337  kPromiseChain = 17,
7338  kPromiseAccept = 18,
7339  kPromiseDefer = 19,
7340  kHtmlCommentInExternalScript = 20,
7341  kHtmlComment = 21,
7342  kSloppyModeBlockScopedFunctionRedefinition = 22,
7343  kForInInitializer = 23,
7344  kArrayProtectorDirtied = 24,
7345  kArraySpeciesModified = 25,
7346  kArrayPrototypeConstructorModified = 26,
7347  kArrayInstanceProtoModified = 27,
7348  kArrayInstanceConstructorModified = 28,
7349  kLegacyFunctionDeclaration = 29,
7350  kRegExpPrototypeSourceGetter = 30,
7351  kRegExpPrototypeOldFlagGetter = 31,
7352  kDecimalWithLeadingZeroInStrictMode = 32,
7353  kLegacyDateParser = 33,
7354  kDefineGetterOrSetterWouldThrow = 34,
7355  kFunctionConstructorReturnedUndefined = 35,
7356  kAssigmentExpressionLHSIsCallInSloppy = 36,
7357  kAssigmentExpressionLHSIsCallInStrict = 37,
7358  kPromiseConstructorReturnedUndefined = 38,
7359  kConstructorNonUndefinedPrimitiveReturn = 39,
7360  kLabeledExpressionStatement = 40,
7361  kLineOrParagraphSeparatorAsLineTerminator = 41,
7362  kIndexAccessor = 42,
7363  kErrorCaptureStackTrace = 43,
7364  kErrorPrepareStackTrace = 44,
7365  kErrorStackTraceLimit = 45,
7366  kWebAssemblyInstantiation = 46,
7367  kDeoptimizerDisableSpeculation = 47,
7368  kArrayPrototypeSortJSArrayModifiedPrototype = 48,
7369  kFunctionTokenOffsetTooLongForToString = 49,
7370  kWasmSharedMemory = 50,
7371  kWasmThreadOpcodes = 51,
7372  kAtomicsNotify = 52,
7373  kAtomicsWake = 53,
7374  kCollator = 54,
7375  kNumberFormat = 55,
7376  kDateTimeFormat = 56,
7377  kPluralRules = 57,
7378  kRelativeTimeFormat = 58,
7379  kLocale = 59,
7380  kListFormat = 60,
7381  kSegmenter = 61,
7382  kStringLocaleCompare = 62,
7383  kStringToLocaleUpperCase = 63,
7384  kStringToLocaleLowerCase = 64,
7385  kNumberToLocaleString = 65,
7386  kDateToLocaleString = 66,
7387  kDateToLocaleDateString = 67,
7388  kDateToLocaleTimeString = 68,
7389  kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
7390  kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
7391  kOptimizedFunctionWithOneShotBytecode = 71,
7392 
7393  // If you add new values here, you'll also need to update Chromium's:
7394  // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to
7395  // this list need to be landed first, then changes on the Chromium side.
7396  kUseCounterFeatureCount // This enum value must be last.
7397  };
7398 
7399  enum MessageErrorLevel {
7400  kMessageLog = (1 << 0),
7401  kMessageDebug = (1 << 1),
7402  kMessageInfo = (1 << 2),
7403  kMessageError = (1 << 3),
7404  kMessageWarning = (1 << 4),
7405  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7406  kMessageWarning,
7407  };
7408 
7409  typedef void (*UseCounterCallback)(Isolate* isolate,
7410  UseCounterFeature feature);
7411 
7426  static Isolate* Allocate();
7427 
7431  static void Initialize(Isolate* isolate, const CreateParams& params);
7432 
7442  static Isolate* New(const CreateParams& params);
7443 
7450  static Isolate* GetCurrent();
7451 
7461  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7462  void SetAbortOnUncaughtExceptionCallback(
7463  AbortOnUncaughtExceptionCallback callback);
7464 
7469  void SetHostImportModuleDynamicallyCallback(
7470  HostImportModuleDynamicallyCallback callback);
7471 
7476  void SetHostInitializeImportMetaObjectCallback(
7477  HostInitializeImportMetaObjectCallback callback);
7478 
7483  void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
7484 
7491  void MemoryPressureNotification(MemoryPressureLevel level);
7492 
7503  void Enter();
7504 
7512  void Exit();
7513 
7518  void Dispose();
7519 
7524  void DumpAndResetStats();
7525 
7533  void DiscardThreadSpecificMetadata();
7534 
7539  V8_INLINE void SetData(uint32_t slot, void* data);
7540 
7545  V8_INLINE void* GetData(uint32_t slot);
7546 
7551  V8_INLINE static uint32_t GetNumberOfDataSlots();
7552 
7558  template <class T>
7559  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
7560 
7564  void GetHeapStatistics(HeapStatistics* heap_statistics);
7565 
7569  size_t NumberOfHeapSpaces();
7570 
7580  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7581  size_t index);
7582 
7586  size_t NumberOfTrackedHeapObjectTypes();
7587 
7597  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7598  size_t type_index);
7599 
7607  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7608 
7621  void GetStackSample(const RegisterState& state, void** frames,
7622  size_t frames_limit, SampleInfo* sample_info);
7623 
7637  V8_INLINE int64_t
7638  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7639 
7644  size_t NumberOfPhantomHandleResetsSinceLastCall();
7645 
7650  HeapProfiler* GetHeapProfiler();
7651 
7655  void SetIdle(bool is_idle);
7656 
7658  bool InContext();
7659 
7664  Local<Context> GetCurrentContext();
7665 
7667  Local<Context> GetEnteredContext();
7668 
7675  Local<Context> GetEnteredOrMicrotaskContext();
7676 
7681  Local<Context> GetIncumbentContext();
7682 
7689  Local<Value> ThrowException(Local<Value> exception);
7690 
7691  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7692  GCCallbackFlags flags);
7693  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7694  GCCallbackFlags flags, void* data);
7695 
7705  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
7706  GCType gc_type_filter = kGCTypeAll);
7707  void AddGCPrologueCallback(GCCallback callback,
7708  GCType gc_type_filter = kGCTypeAll);
7709 
7714  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
7715  void RemoveGCPrologueCallback(GCCallback callback);
7716 
7720  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7721 
7722  /*
7723  * Gets the currently active heap tracer for the isolate.
7724  */
7725  EmbedderHeapTracer* GetEmbedderHeapTracer();
7726 
7730  enum class AtomicsWaitEvent {
7732  kStartWait,
7734  kWokenUp,
7736  kTimedOut,
7738  kTerminatedExecution,
7740  kAPIStopped,
7742  kNotEqual
7743  };
7744 
7749  class V8_EXPORT AtomicsWaitWakeHandle {
7750  public:
7765  void Wake();
7766  };
7767 
7791  typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event,
7792  Local<SharedArrayBuffer> array_buffer,
7793  size_t offset_in_bytes, int32_t value,
7794  double timeout_in_ms,
7795  AtomicsWaitWakeHandle* stop_handle,
7796  void* data);
7797 
7804  void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
7805 
7815  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
7816  GCType gc_type_filter = kGCTypeAll);
7817  void AddGCEpilogueCallback(GCCallback callback,
7818  GCType gc_type_filter = kGCTypeAll);
7819 
7824  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
7825  void* data = nullptr);
7826  void RemoveGCEpilogueCallback(GCCallback callback);
7827 
7828  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7829 
7836  void SetGetExternallyAllocatedMemoryInBytesCallback(
7837  GetExternallyAllocatedMemoryInBytesCallback callback);
7838 
7846  void TerminateExecution();
7847 
7856  bool IsExecutionTerminating();
7857 
7872  void CancelTerminateExecution();
7873 
7882  void RequestInterrupt(InterruptCallback callback, void* data);
7883 
7894  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
7895 
7899  void SetEventLogger(LogEventCallback that);
7900 
7907  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7908 
7912  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7913 
7921  void AddCallCompletedCallback(CallCompletedCallback callback);
7922 
7926  void RemoveCallCompletedCallback(CallCompletedCallback callback);
7927 
7932  void SetPromiseHook(PromiseHook hook);
7933 
7938  void SetPromiseRejectCallback(PromiseRejectCallback callback);
7939 
7944  void RunMicrotasks();
7945 
7949  void EnqueueMicrotask(Local<Function> microtask);
7950 
7954  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
7955 
7959  void SetMicrotasksPolicy(MicrotasksPolicy policy);
7960 
7964  MicrotasksPolicy GetMicrotasksPolicy() const;
7965 
7978  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7979 
7983  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7984 
7988  void SetUseCounterCallback(UseCounterCallback callback);
7989 
7994  void SetCounterFunction(CounterLookupCallback);
7995 
8002  void SetCreateHistogramFunction(CreateHistogramCallback);
8003  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
8004 
8019  bool IdleNotificationDeadline(double deadline_in_seconds);
8020 
8025  void LowMemoryNotification();
8026 
8036  int ContextDisposedNotification(bool dependant_context = true);
8037 
8042  void IsolateInForegroundNotification();
8043 
8048  void IsolateInBackgroundNotification();
8049 
8055  void EnableMemorySavingsMode();
8056 
8060  void DisableMemorySavingsMode();
8061 
8069  void SetRAILMode(RAILMode rail_mode);
8070 
8075  void IncreaseHeapLimitForDebugging();
8076 
8080  void RestoreOriginalHeapLimit();
8081 
8086  bool IsHeapLimitIncreasedForDebugging();
8087 
8110  void SetJitCodeEventHandler(JitCodeEventOptions options,
8111  JitCodeEventHandler event_handler);
8112 
8122  void SetStackLimit(uintptr_t stack_limit);
8123 
8139  void GetCodeRange(void** start, size_t* length_in_bytes);
8140 
8144  UnwindState GetUnwindState();
8145 
8147  void SetFatalErrorHandler(FatalErrorCallback that);
8148 
8150  void SetOOMErrorHandler(OOMErrorCallback that);
8151 
8157  void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
8158 
8166  void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
8167  size_t heap_limit);
8168 
8173  void SetAllowCodeGenerationFromStringsCallback(
8174  AllowCodeGenerationFromStringsCallback callback);
8175 
8180  void SetAllowWasmCodeGenerationCallback(
8181  AllowWasmCodeGenerationCallback callback);
8182 
8187  void SetWasmModuleCallback(ExtensionCallback callback);
8188  void SetWasmInstanceCallback(ExtensionCallback callback);
8189 
8190  V8_DEPRECATE_SOON(
8191  "The callback set in SetWasmStreamingCallback is used now",
8192  void SetWasmCompileStreamingCallback(ApiImplementationCallback callback));
8193 
8194  void SetWasmStreamingCallback(WasmStreamingCallback callback);
8195 
8196  void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback);
8197 
8202  bool IsDead();
8203 
8213  bool AddMessageListener(MessageCallback that,
8214  Local<Value> data = Local<Value>());
8215 
8227  bool AddMessageListenerWithErrorLevel(MessageCallback that,
8228  int message_levels,
8229  Local<Value> data = Local<Value>());
8230 
8234  void RemoveMessageListeners(MessageCallback that);
8235 
8237  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
8238 
8243  void SetCaptureStackTraceForUncaughtExceptions(
8244  bool capture, int frame_limit = 10,
8245  StackTrace::StackTraceOptions options = StackTrace::kOverview);
8246 
8252  void VisitExternalResources(ExternalResourceVisitor* visitor);
8253 
8258  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
8259 
8267  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
8268 
8274  void VisitWeakHandles(PersistentHandleVisitor* visitor);
8275 
8280  bool IsInUse();
8281 
8287  void SetAllowAtomicsWait(bool allow);
8288 
8289  Isolate() = delete;
8290  ~Isolate() = delete;
8291  Isolate(const Isolate&) = delete;
8292  Isolate& operator=(const Isolate&) = delete;
8293  // Deleting operator new and delete here is allowed as ctor and dtor is also
8294  // deleted.
8295  void* operator new(size_t size) = delete;
8296  void* operator new[](size_t size) = delete;
8297  void operator delete(void*, size_t) = delete;
8298  void operator delete[](void*, size_t) = delete;
8299 
8300  private:
8301  template <class K, class V, class Traits>
8302  friend class PersistentValueMapBase;
8303 
8304  internal::Address* GetDataFromSnapshotOnce(size_t index);
8305  void ReportExternalAllocationLimitReached();
8306  void CheckMemoryPressure();
8307 };
8308 
8309 class V8_EXPORT StartupData {
8310  public:
8311  const char* data;
8312  int raw_size;
8313 };
8314 
8315 
8320 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
8321 
8335 typedef uintptr_t (*ReturnAddressLocationResolver)(
8336  uintptr_t return_addr_location);
8337 
8338 
8342 class V8_EXPORT V8 {
8343  public:
8359  static void SetNativesDataBlob(StartupData* startup_blob);
8360  static void SetSnapshotDataBlob(StartupData* startup_blob);
8361 
8363  static void SetDcheckErrorHandler(DcheckErrorCallback that);
8364 
8365 
8369  static void SetFlagsFromString(const char* str, int length);
8370 
8374  static void SetFlagsFromCommandLine(int* argc,
8375  char** argv,
8376  bool remove_flags);
8377 
8379  static const char* GetVersion();
8380 
8385  static bool Initialize();
8386 
8391  static void SetEntropySource(EntropySource source);
8392 
8397  static void SetReturnAddressLocationResolver(
8398  ReturnAddressLocationResolver return_address_resolver);
8399 
8409  static bool Dispose();
8410 
8418  static bool InitializeICU(const char* icu_data_file = nullptr);
8419 
8432  static bool InitializeICUDefaultLocation(const char* exec_path,
8433  const char* icu_data_file = nullptr);
8434 
8451  static void InitializeExternalStartupData(const char* directory_path);
8452  static void InitializeExternalStartupData(const char* natives_blob,
8453  const char* snapshot_blob);
8458  static void InitializePlatform(Platform* platform);
8459 
8464  static void ShutdownPlatform();
8465 
8466 #if V8_OS_POSIX
8467 
8486  V8_DEPRECATE_SOON("Use TryHandleWebAssemblyTrapPosix",
8487  static bool TryHandleSignal(int signal_number, void* info,
8488  void* context));
8489 #endif // V8_OS_POSIX
8490 
8495  V8_DEPRECATED("Use EnableWebAssemblyTrapHandler",
8496  static bool RegisterDefaultSignalHandler());
8497 
8504  static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
8505 
8506  private:
8507  V8();
8508 
8509  static internal::Address* GlobalizeReference(internal::Isolate* isolate,
8510  internal::Address* handle);
8511  static internal::Address* CopyPersistent(internal::Address* handle);
8512  static void DisposeGlobal(internal::Address* global_handle);
8513  static void MakeWeak(internal::Address* location, void* data,
8514  WeakCallbackInfo<void>::Callback weak_callback,
8515  WeakCallbackType type);
8516  static void MakeWeak(internal::Address** location_addr);
8517  static void* ClearWeak(internal::Address* location);
8518  static void AnnotateStrongRetainer(internal::Address* location,
8519  const char* label);
8520  static Value* Eternalize(Isolate* isolate, Value* handle);
8521 
8522  static void RegisterExternallyReferencedObject(internal::Address* location,
8523  internal::Isolate* isolate);
8524 
8525  template <class K, class V, class T>
8526  friend class PersistentValueMapBase;
8527 
8528  static void FromJustIsNothing();
8529  static void ToLocalEmpty();
8530  static void InternalFieldOutOfBounds(int index);
8531  template <class T> friend class Local;
8532  template <class T>
8533  friend class MaybeLocal;
8534  template <class T>
8535  friend class Maybe;
8536  template <class T>
8537  friend class WeakCallbackInfo;
8538  template <class T> friend class Eternal;
8539  template <class T> friend class PersistentBase;
8540  template <class T, class M> friend class Persistent;
8541  friend class Context;
8542 };
8543 
8547 class V8_EXPORT SnapshotCreator {
8548  public:
8549  enum class FunctionCodeHandling { kClear, kKeep };
8550 
8559  SnapshotCreator(Isolate* isolate,
8560  const intptr_t* external_references = nullptr,
8561  StartupData* existing_blob = nullptr);
8562 
8571  SnapshotCreator(const intptr_t* external_references = nullptr,
8572  StartupData* existing_blob = nullptr);
8573 
8574  ~SnapshotCreator();
8575 
8579  Isolate* GetIsolate();
8580 
8588  void SetDefaultContext(Local<Context> context,
8589  SerializeInternalFieldsCallback callback =
8590  SerializeInternalFieldsCallback());
8591 
8600  size_t AddContext(Local<Context> context,
8601  SerializeInternalFieldsCallback callback =
8602  SerializeInternalFieldsCallback());
8603 
8608  size_t AddTemplate(Local<Template> template_obj);
8609 
8616  template <class T>
8617  V8_INLINE size_t AddData(Local<Context> context, Local<T> object);
8618 
8625  template <class T>
8626  V8_INLINE size_t AddData(Local<T> object);
8627 
8636  StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8637 
8638  // Disallow copying and assigning.
8639  SnapshotCreator(const SnapshotCreator&) = delete;
8640  void operator=(const SnapshotCreator&) = delete;
8641 
8642  private:
8643  size_t AddData(Local<Context> context, internal::Address object);
8644  size_t AddData(internal::Address object);
8645 
8646  void* data_;
8647 };
8648 
8659 template <class T>
8660 class Maybe {
8661  public:
8662  V8_INLINE bool IsNothing() const { return !has_value_; }
8663  V8_INLINE bool IsJust() const { return has_value_; }
8664 
8668  V8_INLINE T ToChecked() const { return FromJust(); }
8669 
8674  V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
8675  if (V8_LIKELY(IsJust())) *out = value_;
8676  return IsJust();
8677  }
8678 
8683  V8_INLINE T FromJust() const {
8684  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8685  return value_;
8686  }
8687 
8692  V8_INLINE T FromMaybe(const T& default_value) const {
8693  return has_value_ ? value_ : default_value;
8694  }
8695 
8696  V8_INLINE bool operator==(const Maybe& other) const {
8697  return (IsJust() == other.IsJust()) &&
8698  (!IsJust() || FromJust() == other.FromJust());
8699  }
8700 
8701  V8_INLINE bool operator!=(const Maybe& other) const {
8702  return !operator==(other);
8703  }
8704 
8705  private:
8706  Maybe() : has_value_(false) {}
8707  explicit Maybe(const T& t) : has_value_(true), value_(t) {}
8708 
8709  bool has_value_;
8710  T value_;
8711 
8712  template <class U>
8713  friend Maybe<U> Nothing();
8714  template <class U>
8715  friend Maybe<U> Just(const U& u);
8716 };
8717 
8718 template <class T>
8719 inline Maybe<T> Nothing() {
8720  return Maybe<T>();
8721 }
8722 
8723 template <class T>
8724 inline Maybe<T> Just(const T& t) {
8725  return Maybe<T>(t);
8726 }
8727 
8728 // A template specialization of Maybe<T> for the case of T = void.
8729 template <>
8730 class Maybe<void> {
8731  public:
8732  V8_INLINE bool IsNothing() const { return !is_valid_; }
8733  V8_INLINE bool IsJust() const { return is_valid_; }
8734 
8735  V8_INLINE bool operator==(const Maybe& other) const {
8736  return IsJust() == other.IsJust();
8737  }
8738 
8739  V8_INLINE bool operator!=(const Maybe& other) const {
8740  return !operator==(other);
8741  }
8742 
8743  private:
8744  struct JustTag {};
8745 
8746  Maybe() : is_valid_(false) {}
8747  explicit Maybe(JustTag) : is_valid_(true) {}
8748 
8749  bool is_valid_;
8750 
8751  template <class U>
8752  friend Maybe<U> Nothing();
8753  friend Maybe<void> JustVoid();
8754 };
8755 
8756 inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); }
8757 
8761 class V8_EXPORT TryCatch {
8762  public:
8768  explicit TryCatch(Isolate* isolate);
8769 
8773  ~TryCatch();
8774 
8778  bool HasCaught() const;
8779 
8788  bool CanContinue() const;
8789 
8802  bool HasTerminated() const;
8803 
8811  Local<Value> ReThrow();
8812 
8819  Local<Value> Exception() const;
8820 
8825  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
8826  Local<Context> context) const;
8827 
8835  Local<v8::Message> Message() const;
8836 
8847  void Reset();
8848 
8857  void SetVerbose(bool value);
8858 
8862  bool IsVerbose() const;
8863 
8869  void SetCaptureMessage(bool value);
8870 
8882  static void* JSStackComparableAddress(TryCatch* handler) {
8883  if (handler == nullptr) return nullptr;
8884  return handler->js_stack_comparable_address_;
8885  }
8886 
8887  TryCatch(const TryCatch&) = delete;
8888  void operator=(const TryCatch&) = delete;
8889 
8890  private:
8891  // Declaring operator new and delete as deleted is not spec compliant.
8892  // Therefore declare them private instead to disable dynamic alloc
8893  void* operator new(size_t size);
8894  void* operator new[](size_t size);
8895  void operator delete(void*, size_t);
8896  void operator delete[](void*, size_t);
8897 
8898  void ResetInternal();
8899 
8900  internal::Isolate* isolate_;
8901  TryCatch* next_;
8902  void* exception_;
8903  void* message_obj_;
8904  void* js_stack_comparable_address_;
8905  bool is_verbose_ : 1;
8906  bool can_continue_ : 1;
8907  bool capture_message_ : 1;
8908  bool rethrow_ : 1;
8909  bool has_terminated_ : 1;
8910 
8911  friend class internal::Isolate;
8912 };
8913 
8914 
8915 // --- Context ---
8916 
8917 
8921 class V8_EXPORT ExtensionConfiguration {
8922  public:
8923  ExtensionConfiguration() : name_count_(0), names_(nullptr) {}
8924  ExtensionConfiguration(int name_count, const char* names[])
8925  : name_count_(name_count), names_(names) { }
8926 
8927  const char** begin() const { return &names_[0]; }
8928  const char** end() const { return &names_[name_count_]; }
8929 
8930  private:
8931  const int name_count_;
8932  const char** names_;
8933 };
8934 
8939 class V8_EXPORT Context {
8940  public:
8953  Local<Object> Global();
8954 
8959  void DetachGlobal();
8960 
8979  static Local<Context> New(
8980  Isolate* isolate, ExtensionConfiguration* extensions = nullptr,
8981  MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(),
8982  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
8983  DeserializeInternalFieldsCallback internal_fields_deserializer =
8984  DeserializeInternalFieldsCallback());
8985 
9005  static MaybeLocal<Context> FromSnapshot(
9006  Isolate* isolate, size_t context_snapshot_index,
9007  DeserializeInternalFieldsCallback embedder_fields_deserializer =
9008  DeserializeInternalFieldsCallback(),
9009  ExtensionConfiguration* extensions = nullptr,
9010  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9011 
9029  static MaybeLocal<Object> NewRemoteContext(
9030  Isolate* isolate, Local<ObjectTemplate> global_template,
9031  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9032 
9037  void SetSecurityToken(Local<Value> token);
9038 
9040  void UseDefaultSecurityToken();
9041 
9043  Local<Value> GetSecurityToken();
9044 
9051  void Enter();
9052 
9057  void Exit();
9058 
9060  Isolate* GetIsolate();
9061 
9066  enum EmbedderDataFields { kDebugIdIndex = 0 };
9067 
9071  uint32_t GetNumberOfEmbedderDataFields();
9072 
9077  V8_INLINE Local<Value> GetEmbedderData(int index);
9078 
9085  Local<Object> GetExtrasBindingObject();
9086 
9092  void SetEmbedderData(int index, Local<Value> value);
9093 
9100  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
9101 
9107  void SetAlignedPointerInEmbedderData(int index, void* value);
9108 
9122  void AllowCodeGenerationFromStrings(bool allow);
9123 
9128  bool IsCodeGenerationFromStringsAllowed();
9129 
9135  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
9136 
9142  template <class T>
9143  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
9144 
9149  class Scope {
9150  public:
9151  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
9152  context_->Enter();
9153  }
9154  V8_INLINE ~Scope() { context_->Exit(); }
9155 
9156  private:
9157  Local<Context> context_;
9158  };
9159 
9165  class V8_EXPORT BackupIncumbentScope {
9166  public:
9171  explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
9173 
9174  private:
9175  friend class internal::Isolate;
9176 
9177  Local<Context> backup_incumbent_context_;
9178  const BackupIncumbentScope* prev_ = nullptr;
9179  };
9180 
9181  private:
9182  friend class Value;
9183  friend class Script;
9184  friend class Object;
9185  friend class Function;
9186 
9187  internal::Address* GetDataFromSnapshotOnce(size_t index);
9188  Local<Value> SlowGetEmbedderData(int index);
9189  void* SlowGetAlignedPointerFromEmbedderData(int index);
9190 };
9191 
9192 
9269 class V8_EXPORT Unlocker {
9270  public:
9274  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
9275 
9276  ~Unlocker();
9277  private:
9278  void Initialize(Isolate* isolate);
9279 
9280  internal::Isolate* isolate_;
9281 };
9282 
9283 
9284 class V8_EXPORT Locker {
9285  public:
9289  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
9290 
9291  ~Locker();
9292 
9297  static bool IsLocked(Isolate* isolate);
9298 
9302  static bool IsActive();
9303 
9304  // Disallow copying and assigning.
9305  Locker(const Locker&) = delete;
9306  void operator=(const Locker&) = delete;
9307 
9308  private:
9309  void Initialize(Isolate* isolate);
9310 
9311  bool has_lock_;
9312  bool top_level_;
9313  internal::Isolate* isolate_;
9314 };
9315 
9321 class V8_EXPORT Unwinder {
9322  public:
9347  static bool TryUnwindV8Frames(const UnwindState& unwind_state,
9348  RegisterState* register_state,
9349  const void* stack_base);
9350 
9359  static bool PCIsInV8(const UnwindState& unwind_state, void* pc);
9360 };
9361 
9362 // --- Implementation ---
9363 
9364 template <class T>
9365 Local<T> Local<T>::New(Isolate* isolate, Local<T> that) {
9366  return New(isolate, that.val_);
9367 }
9368 
9369 template <class T>
9370 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
9371  return New(isolate, that.val_);
9372 }
9373 
9374 
9375 template <class T>
9376 Local<T> Local<T>::New(Isolate* isolate, T* that) {
9377  if (that == nullptr) return Local<T>();
9378  T* that_ptr = that;
9379  internal::Address* p = reinterpret_cast<internal::Address*>(that_ptr);
9380  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
9381  reinterpret_cast<internal::Isolate*>(isolate), *p)));
9382 }
9383 
9384 
9385 template<class T>
9386 template<class S>
9387 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
9388  TYPE_CHECK(T, S);
9389  val_ = reinterpret_cast<T*>(
9390  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
9391 }
9392 
9393 template <class T>
9394 Local<T> Eternal<T>::Get(Isolate* isolate) const {
9395  // The eternal handle will never go away, so as with the roots, we don't even
9396  // need to open a handle.
9397  return Local<T>(val_);
9398 }
9399 
9400 
9401 template <class T>
9403  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
9404  return Local<T>(val_);
9405 }
9406 
9407 
9408 template <class T>
9409 void* WeakCallbackInfo<T>::GetInternalField(int index) const {
9410 #ifdef V8_ENABLE_CHECKS
9411  if (index < 0 || index >= kEmbedderFieldsInWeakCallback) {
9412  V8::InternalFieldOutOfBounds(index);
9413  }
9414 #endif
9415  return embedder_fields_[index];
9416 }
9417 
9418 
9419 template <class T>
9420 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
9421  if (that == nullptr) return nullptr;
9422  internal::Address* p = reinterpret_cast<internal::Address*>(that);
9423  return reinterpret_cast<T*>(
9424  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
9425  p));
9426 }
9427 
9428 
9429 template <class T, class M>
9430 template <class S, class M2>
9431 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
9432  TYPE_CHECK(T, S);
9433  this->Reset();
9434  if (that.IsEmpty()) return;
9435  internal::Address* p = reinterpret_cast<internal::Address*>(that.val_);
9436  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
9437  M::Copy(that, this);
9438 }
9439 
9440 template <class T>
9441 bool PersistentBase<T>::IsIndependent() const {
9442  typedef internal::Internals I;
9443  if (this->IsEmpty()) return false;
9444  return I::GetNodeFlag(reinterpret_cast<internal::Address*>(this->val_),
9445  I::kNodeIsIndependentShift);
9446 }
9447 
9448 template <class T>
9450  typedef internal::Internals I;
9451  if (this->IsEmpty()) return false;
9452  uint8_t node_state =
9453  I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_));
9454  return node_state == I::kNodeStateIsNearDeathValue ||
9455  node_state == I::kNodeStateIsPendingValue;
9456 }
9457 
9458 
9459 template <class T>
9461  typedef internal::Internals I;
9462  if (this->IsEmpty()) return false;
9463  return I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_)) ==
9464  I::kNodeStateIsWeakValue;
9465 }
9466 
9467 
9468 template <class T>
9470  if (this->IsEmpty()) return;
9471  V8::DisposeGlobal(reinterpret_cast<internal::Address*>(this->val_));
9472  val_ = nullptr;
9473 }
9474 
9475 
9476 template <class T>
9477 template <class S>
9478 void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
9479  TYPE_CHECK(T, S);
9480  Reset();
9481  if (other.IsEmpty()) return;
9482  this->val_ = New(isolate, other.val_);
9483 }
9484 
9485 
9486 template <class T>
9487 template <class S>
9488 void PersistentBase<T>::Reset(Isolate* isolate,
9489  const PersistentBase<S>& other) {
9490  TYPE_CHECK(T, S);
9491  Reset();
9492  if (other.IsEmpty()) return;
9493  this->val_ = New(isolate, other.val_);
9494 }
9495 
9496 
9497 template <class T>
9498 template <typename P>
9500  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
9501  WeakCallbackType type) {
9502  typedef typename WeakCallbackInfo<void>::Callback Callback;
9503  V8::MakeWeak(reinterpret_cast<internal::Address*>(this->val_), parameter,
9504  reinterpret_cast<Callback>(callback), type);
9505 }
9506 
9507 template <class T>
9509  V8::MakeWeak(reinterpret_cast<internal::Address**>(&this->val_));
9510 }
9511 
9512 template <class T>
9513 template <typename P>
9515  return reinterpret_cast<P*>(
9516  V8::ClearWeak(reinterpret_cast<internal::Address*>(this->val_)));
9517 }
9518 
9519 template <class T>
9521  V8::AnnotateStrongRetainer(reinterpret_cast<internal::Address*>(this->val_),
9522  label);
9523 }
9524 
9525 template <class T>
9526 void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
9527  if (IsEmpty()) return;
9528  V8::RegisterExternallyReferencedObject(
9529  reinterpret_cast<internal::Address*>(this->val_),
9530  reinterpret_cast<internal::Isolate*>(isolate));
9531 }
9532 
9533 template <class T>
9535  typedef internal::Internals I;
9536  if (this->IsEmpty()) return;
9537  I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
9538  I::kNodeIsIndependentShift);
9539 }
9540 
9541 template <class T>
9543  typedef internal::Internals I;
9544  if (this->IsEmpty()) return;
9545  I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
9546  I::kNodeIsActiveShift);
9547 }
9548 
9549 
9550 template <class T>
9551 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
9552  typedef internal::Internals I;
9553  if (this->IsEmpty()) return;
9554  internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_);
9555  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9556  *reinterpret_cast<uint16_t*>(addr) = class_id;
9557 }
9558 
9559 
9560 template <class T>
9562  typedef internal::Internals I;
9563  if (this->IsEmpty()) return 0;
9564  internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_);
9565  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9566  return *reinterpret_cast<uint16_t*>(addr);
9567 }
9568 
9569 template <typename T>
9570 ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {}
9571 
9572 template<typename T>
9573 template<typename S>
9574 void ReturnValue<T>::Set(const Persistent<S>& handle) {
9575  TYPE_CHECK(T, S);
9576  if (V8_UNLIKELY(handle.IsEmpty())) {
9577  *value_ = GetDefaultValue();
9578  } else {
9579  *value_ = *reinterpret_cast<internal::Address*>(*handle);
9580  }
9581 }
9582 
9583 template <typename T>
9584 template <typename S>
9585 void ReturnValue<T>::Set(const Global<S>& handle) {
9586  TYPE_CHECK(T, S);
9587  if (V8_UNLIKELY(handle.IsEmpty())) {
9588  *value_ = GetDefaultValue();
9589  } else {
9590  *value_ = *reinterpret_cast<internal::Address*>(*handle);
9591  }
9592 }
9593 
9594 template <typename T>
9595 template <typename S>
9596 void ReturnValue<T>::Set(const Local<S> handle) {
9597  TYPE_CHECK(T, S);
9598  if (V8_UNLIKELY(handle.IsEmpty())) {
9599  *value_ = GetDefaultValue();
9600  } else {
9601  *value_ = *reinterpret_cast<internal::Address*>(*handle);
9602  }
9603 }
9604 
9605 template<typename T>
9606 void ReturnValue<T>::Set(double i) {
9607  TYPE_CHECK(T, Number);
9608  Set(Number::New(GetIsolate(), i));
9609 }
9610 
9611 template<typename T>
9612 void ReturnValue<T>::Set(int32_t i) {
9613  TYPE_CHECK(T, Integer);
9614  typedef internal::Internals I;
9615  if (V8_LIKELY(I::IsValidSmi(i))) {
9616  *value_ = I::IntToSmi(i);
9617  return;
9618  }
9619  Set(Integer::New(GetIsolate(), i));
9620 }
9621 
9622 template<typename T>
9623 void ReturnValue<T>::Set(uint32_t i) {
9624  TYPE_CHECK(T, Integer);
9625  // Can't simply use INT32_MAX here for whatever reason.
9626  bool fits_into_int32_t = (i & (1U << 31)) == 0;
9627  if (V8_LIKELY(fits_into_int32_t)) {
9628  Set(static_cast<int32_t>(i));
9629  return;
9630  }
9631  Set(Integer::NewFromUnsigned(GetIsolate(), i));
9632 }
9633 
9634 template<typename T>
9635 void ReturnValue<T>::Set(bool value) {
9636  TYPE_CHECK(T, Boolean);
9637  typedef internal::Internals I;
9638  int root_index;
9639  if (value) {
9640  root_index = I::kTrueValueRootIndex;
9641  } else {
9642  root_index = I::kFalseValueRootIndex;
9643  }
9644  *value_ = *I::GetRoot(GetIsolate(), root_index);
9645 }
9646 
9647 template<typename T>
9648 void ReturnValue<T>::SetNull() {
9649  TYPE_CHECK(T, Primitive);
9650  typedef internal::Internals I;
9651  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
9652 }
9653 
9654 template<typename T>
9655 void ReturnValue<T>::SetUndefined() {
9656  TYPE_CHECK(T, Primitive);
9657  typedef internal::Internals I;
9658  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
9659 }
9660 
9661 template<typename T>
9662 void ReturnValue<T>::SetEmptyString() {
9663  TYPE_CHECK(T, String);
9664  typedef internal::Internals I;
9665  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
9666 }
9667 
9668 template <typename T>
9669 Isolate* ReturnValue<T>::GetIsolate() const {
9670  // Isolate is always the pointer below the default value on the stack.
9671  return *reinterpret_cast<Isolate**>(&value_[-2]);
9672 }
9673 
9674 template <typename T>
9675 Local<Value> ReturnValue<T>::Get() const {
9676  typedef internal::Internals I;
9677  if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex))
9678  return Local<Value>(*Undefined(GetIsolate()));
9679  return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
9680 }
9681 
9682 template <typename T>
9683 template <typename S>
9684 void ReturnValue<T>::Set(S* whatever) {
9685  // Uncompilable to prevent inadvertent misuse.
9686  TYPE_CHECK(S*, Primitive);
9687 }
9688 
9689 template <typename T>
9690 internal::Address ReturnValue<T>::GetDefaultValue() {
9691  // Default value is always the pointer below value_ on the stack.
9692  return value_[-1];
9693 }
9694 
9695 template <typename T>
9696 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Address* implicit_args,
9697  internal::Address* values,
9698  int length)
9699  : implicit_args_(implicit_args), values_(values), length_(length) {}
9700 
9701 template<typename T>
9703  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
9704  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
9705 }
9706 
9707 
9708 template<typename T>
9710  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
9711 }
9712 
9713 
9714 template<typename T>
9716  return Local<Object>(reinterpret_cast<Object*>(
9717  &implicit_args_[kHolderIndex]));
9718 }
9719 
9720 template <typename T>
9722  return Local<Value>(
9723  reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex]));
9724 }
9725 
9726 template <typename T>
9728  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
9729 }
9730 
9731 
9732 template<typename T>
9734  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
9735 }
9736 
9737 
9738 template<typename T>
9740  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
9741 }
9742 
9743 
9744 template<typename T>
9746  return !NewTarget()->IsUndefined();
9747 }
9748 
9749 
9750 template<typename T>
9752  return length_;
9753 }
9754 
9755 ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
9756  Local<Integer> resource_line_offset,
9757  Local<Integer> resource_column_offset,
9758  Local<Boolean> resource_is_shared_cross_origin,
9759  Local<Integer> script_id,
9760  Local<Value> source_map_url,
9761  Local<Boolean> resource_is_opaque,
9762  Local<Boolean> is_wasm, Local<Boolean> is_module,
9763  Local<PrimitiveArray> host_defined_options)
9764  : resource_name_(resource_name),
9765  resource_line_offset_(resource_line_offset),
9766  resource_column_offset_(resource_column_offset),
9767  options_(!resource_is_shared_cross_origin.IsEmpty() &&
9768  resource_is_shared_cross_origin->IsTrue(),
9769  !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue(),
9770  !is_wasm.IsEmpty() && is_wasm->IsTrue(),
9771  !is_module.IsEmpty() && is_module->IsTrue()),
9772  script_id_(script_id),
9773  source_map_url_(source_map_url),
9774  host_defined_options_(host_defined_options) {}
9775 
9776 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
9777 
9778 Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions() const {
9779  return host_defined_options_;
9780 }
9781 
9782 Local<Integer> ScriptOrigin::ResourceLineOffset() const {
9783  return resource_line_offset_;
9784 }
9785 
9786 
9787 Local<Integer> ScriptOrigin::ResourceColumnOffset() const {
9788  return resource_column_offset_;
9789 }
9790 
9791 
9792 Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
9793 
9794 
9795 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
9796 
9797 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
9798  CachedData* data)
9799  : source_string(string),
9800  resource_name(origin.ResourceName()),
9801  resource_line_offset(origin.ResourceLineOffset()),
9802  resource_column_offset(origin.ResourceColumnOffset()),
9803  resource_options(origin.Options()),
9804  source_map_url(origin.SourceMapUrl()),
9805  host_defined_options(origin.HostDefinedOptions()),
9806  cached_data(data) {}
9807 
9808 ScriptCompiler::Source::Source(Local<String> string,
9809  CachedData* data)
9810  : source_string(string), cached_data(data) {}
9811 
9812 
9813 ScriptCompiler::Source::~Source() {
9814  delete cached_data;
9815 }
9816 
9817 
9818 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
9819  const {
9820  return cached_data;
9821 }
9822 
9823 const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
9824  return resource_options;
9825 }
9826 
9827 Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
9828  return value ? True(isolate) : False(isolate);
9829 }
9830 
9831 void Template::Set(Isolate* isolate, const char* name, Local<Data> value) {
9832  Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized)
9833  .ToLocalChecked(),
9834  value);
9835 }
9836 
9837 FunctionTemplate* FunctionTemplate::Cast(Data* data) {
9838 #ifdef V8_ENABLE_CHECKS
9839  CheckCast(data);
9840 #endif
9841  return reinterpret_cast<FunctionTemplate*>(data);
9842 }
9843 
9844 ObjectTemplate* ObjectTemplate::Cast(Data* data) {
9845 #ifdef V8_ENABLE_CHECKS
9846  CheckCast(data);
9847 #endif
9848  return reinterpret_cast<ObjectTemplate*>(data);
9849 }
9850 
9851 Signature* Signature::Cast(Data* data) {
9852 #ifdef V8_ENABLE_CHECKS
9853  CheckCast(data);
9854 #endif
9855  return reinterpret_cast<Signature*>(data);
9856 }
9857 
9858 AccessorSignature* AccessorSignature::Cast(Data* data) {
9859 #ifdef V8_ENABLE_CHECKS
9860  CheckCast(data);
9861 #endif
9862  return reinterpret_cast<AccessorSignature*>(data);
9863 }
9864 
9865 Local<Value> Object::GetInternalField(int index) {
9866 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
9867  typedef internal::Address A;
9868  typedef internal::Internals I;
9869  A obj = *reinterpret_cast<A*>(this);
9870  // Fast path: If the object is a plain JSObject, which is the common case, we
9871  // know where to find the internal fields and can return the value directly.
9872  auto instance_type = I::GetInstanceType(obj);
9873  if (instance_type == I::kJSObjectType ||
9874  instance_type == I::kJSApiObjectType ||
9875  instance_type == I::kJSSpecialApiObjectType) {
9876  int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
9877  A value = I::ReadField<A>(obj, offset);
9878  A* result = HandleScope::CreateHandle(
9879  reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value);
9880  return Local<Value>(reinterpret_cast<Value*>(result));
9881  }
9882 #endif
9883  return SlowGetInternalField(index);
9884 }
9885 
9886 
9887 void* Object::GetAlignedPointerFromInternalField(int index) {
9888 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
9889  typedef internal::Address A;
9890  typedef internal::Internals I;
9891  A obj = *reinterpret_cast<A*>(this);
9892  // Fast path: If the object is a plain JSObject, which is the common case, we
9893  // know where to find the internal fields and can return the value directly.
9894  auto instance_type = I::GetInstanceType(obj);
9895  if (V8_LIKELY(instance_type == I::kJSObjectType ||
9896  instance_type == I::kJSApiObjectType ||
9897  instance_type == I::kJSSpecialApiObjectType)) {
9898  int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
9899  return I::ReadField<void*>(obj, offset);
9900  }
9901 #endif
9902  return SlowGetAlignedPointerFromInternalField(index);
9903 }
9904 
9905 String* String::Cast(v8::Value* value) {
9906 #ifdef V8_ENABLE_CHECKS
9907  CheckCast(value);
9908 #endif
9909  return static_cast<String*>(value);
9910 }
9911 
9912 
9913 Local<String> String::Empty(Isolate* isolate) {
9914  typedef internal::Address S;
9915  typedef internal::Internals I;
9916  I::CheckInitialized(isolate);
9917  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
9918  return Local<String>(reinterpret_cast<String*>(slot));
9919 }
9920 
9921 
9922 String::ExternalStringResource* String::GetExternalStringResource() const {
9923  typedef internal::Address A;
9924  typedef internal::Internals I;
9925  A obj = *reinterpret_cast<const A*>(this);
9926 
9927  ExternalStringResource* result;
9928  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
9929  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
9930  result = reinterpret_cast<String::ExternalStringResource*>(value);
9931  } else {
9932  result = GetExternalStringResourceSlow();
9933  }
9934 #ifdef V8_ENABLE_CHECKS
9935  VerifyExternalStringResource(result);
9936 #endif
9937  return result;
9938 }
9939 
9940 
9941 String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
9942  String::Encoding* encoding_out) const {
9943  typedef internal::Address A;
9944  typedef internal::Internals I;
9945  A obj = *reinterpret_cast<const A*>(this);
9946  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
9947  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
9948  ExternalStringResourceBase* resource;
9949  if (type == I::kExternalOneByteRepresentationTag ||
9950  type == I::kExternalTwoByteRepresentationTag) {
9951  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
9952  resource = static_cast<ExternalStringResourceBase*>(value);
9953  } else {
9954  resource = GetExternalStringResourceBaseSlow(encoding_out);
9955  }
9956 #ifdef V8_ENABLE_CHECKS
9957  VerifyExternalStringResourceBase(resource, *encoding_out);
9958 #endif
9959  return resource;
9960 }
9961 
9962 
9963 bool Value::IsUndefined() const {
9964 #ifdef V8_ENABLE_CHECKS
9965  return FullIsUndefined();
9966 #else
9967  return QuickIsUndefined();
9968 #endif
9969 }
9970 
9971 bool Value::QuickIsUndefined() const {
9972  typedef internal::Address A;
9973  typedef internal::Internals I;
9974  A obj = *reinterpret_cast<const A*>(this);
9975  if (!I::HasHeapObjectTag(obj)) return false;
9976  if (I::GetInstanceType(obj) != I::kOddballType) return false;
9977  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
9978 }
9979 
9980 
9981 bool Value::IsNull() const {
9982 #ifdef V8_ENABLE_CHECKS
9983  return FullIsNull();
9984 #else
9985  return QuickIsNull();
9986 #endif
9987 }
9988 
9989 bool Value::QuickIsNull() const {
9990  typedef internal::Address A;
9991  typedef internal::Internals I;
9992  A obj = *reinterpret_cast<const A*>(this);
9993  if (!I::HasHeapObjectTag(obj)) return false;
9994  if (I::GetInstanceType(obj) != I::kOddballType) return false;
9995  return (I::GetOddballKind(obj) == I::kNullOddballKind);
9996 }
9997 
9998 bool Value::IsNullOrUndefined() const {
9999 #ifdef V8_ENABLE_CHECKS
10000  return FullIsNull() || FullIsUndefined();
10001 #else
10002  return QuickIsNullOrUndefined();
10003 #endif
10004 }
10005 
10006 bool Value::QuickIsNullOrUndefined() const {
10007  typedef internal::Address A;
10008  typedef internal::Internals I;
10009  A obj = *reinterpret_cast<const A*>(this);
10010  if (!I::HasHeapObjectTag(obj)) return false;
10011  if (I::GetInstanceType(obj) != I::kOddballType) return false;
10012  int kind = I::GetOddballKind(obj);
10013  return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
10014 }
10015 
10016 bool Value::IsString() const {
10017 #ifdef V8_ENABLE_CHECKS
10018  return FullIsString();
10019 #else
10020  return QuickIsString();
10021 #endif
10022 }
10023 
10024 bool Value::QuickIsString() const {
10025  typedef internal::Address A;
10026  typedef internal::Internals I;
10027  A obj = *reinterpret_cast<const A*>(this);
10028  if (!I::HasHeapObjectTag(obj)) return false;
10029  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
10030 }
10031 
10032 
10033 template <class T> Value* Value::Cast(T* value) {
10034  return static_cast<Value*>(value);
10035 }
10036 
10037 
10038 Boolean* Boolean::Cast(v8::Value* value) {
10039 #ifdef V8_ENABLE_CHECKS
10040  CheckCast(value);
10041 #endif
10042  return static_cast<Boolean*>(value);
10043 }
10044 
10045 
10046 Name* Name::Cast(v8::Value* value) {
10047 #ifdef V8_ENABLE_CHECKS
10048  CheckCast(value);
10049 #endif
10050  return static_cast<Name*>(value);
10051 }
10052 
10053 
10054 Symbol* Symbol::Cast(v8::Value* value) {
10055 #ifdef V8_ENABLE_CHECKS
10056  CheckCast(value);
10057 #endif
10058  return static_cast<Symbol*>(value);
10059 }
10060 
10061 
10062 Private* Private::Cast(Data* data) {
10063 #ifdef V8_ENABLE_CHECKS
10064  CheckCast(data);
10065 #endif
10066  return reinterpret_cast<Private*>(data);
10067 }
10068 
10069 
10070 Number* Number::Cast(v8::Value* value) {
10071 #ifdef V8_ENABLE_CHECKS
10072  CheckCast(value);
10073 #endif
10074  return static_cast<Number*>(value);
10075 }
10076 
10077 
10078 Integer* Integer::Cast(v8::Value* value) {
10079 #ifdef V8_ENABLE_CHECKS
10080  CheckCast(value);
10081 #endif
10082  return static_cast<Integer*>(value);
10083 }
10084 
10085 
10086 Int32* Int32::Cast(v8::Value* value) {
10087 #ifdef V8_ENABLE_CHECKS
10088  CheckCast(value);
10089 #endif
10090  return static_cast<Int32*>(value);
10091 }
10092 
10093 
10094 Uint32* Uint32::Cast(v8::Value* value) {
10095 #ifdef V8_ENABLE_CHECKS
10096  CheckCast(value);
10097 #endif
10098  return static_cast<Uint32*>(value);
10099 }
10100 
10101 BigInt* BigInt::Cast(v8::Value* value) {
10102 #ifdef V8_ENABLE_CHECKS
10103  CheckCast(value);
10104 #endif
10105  return static_cast<BigInt*>(value);
10106 }
10107 
10108 Date* Date::Cast(v8::Value* value) {
10109 #ifdef V8_ENABLE_CHECKS
10110  CheckCast(value);
10111 #endif
10112  return static_cast<Date*>(value);
10113 }
10114 
10115 
10116 StringObject* StringObject::Cast(v8::Value* value) {
10117 #ifdef V8_ENABLE_CHECKS
10118  CheckCast(value);
10119 #endif
10120  return static_cast<StringObject*>(value);
10121 }
10122 
10123 
10124 SymbolObject* SymbolObject::Cast(v8::Value* value) {
10125 #ifdef V8_ENABLE_CHECKS
10126  CheckCast(value);
10127 #endif
10128  return static_cast<SymbolObject*>(value);
10129 }
10130 
10131 
10132 NumberObject* NumberObject::Cast(v8::Value* value) {
10133 #ifdef V8_ENABLE_CHECKS
10134  CheckCast(value);
10135 #endif
10136  return static_cast<NumberObject*>(value);
10137 }
10138 
10139 BigIntObject* BigIntObject::Cast(v8::Value* value) {
10140 #ifdef V8_ENABLE_CHECKS
10141  CheckCast(value);
10142 #endif
10143  return static_cast<BigIntObject*>(value);
10144 }
10145 
10146 BooleanObject* BooleanObject::Cast(v8::Value* value) {
10147 #ifdef V8_ENABLE_CHECKS
10148  CheckCast(value);
10149 #endif
10150  return static_cast<BooleanObject*>(value);
10151 }
10152 
10153 
10154 RegExp* RegExp::Cast(v8::Value* value) {
10155 #ifdef V8_ENABLE_CHECKS
10156  CheckCast(value);
10157 #endif
10158  return static_cast<RegExp*>(value);
10159 }
10160 
10161 
10162 Object* Object::Cast(v8::Value* value) {
10163 #ifdef V8_ENABLE_CHECKS
10164  CheckCast(value);
10165 #endif
10166  return static_cast<Object*>(value);
10167 }
10168 
10169 
10170 Array* Array::Cast(v8::Value* value) {
10171 #ifdef V8_ENABLE_CHECKS
10172  CheckCast(value);
10173 #endif
10174  return static_cast<Array*>(value);
10175 }
10176 
10177 
10178 Map* Map::Cast(v8::Value* value) {
10179 #ifdef V8_ENABLE_CHECKS
10180  CheckCast(value);
10181 #endif
10182  return static_cast<Map*>(value);
10183 }
10184 
10185 
10186 Set* Set::Cast(v8::Value* value) {
10187 #ifdef V8_ENABLE_CHECKS
10188  CheckCast(value);
10189 #endif
10190  return static_cast<Set*>(value);
10191 }
10192 
10193 
10194 Promise* Promise::Cast(v8::Value* value) {
10195 #ifdef V8_ENABLE_CHECKS
10196  CheckCast(value);
10197 #endif
10198  return static_cast<Promise*>(value);
10199 }
10200 
10201 
10202 Proxy* Proxy::Cast(v8::Value* value) {
10203 #ifdef V8_ENABLE_CHECKS
10204  CheckCast(value);
10205 #endif
10206  return static_cast<Proxy*>(value);
10207 }
10208 
10209 WasmCompiledModule* WasmCompiledModule::Cast(v8::Value* value) {
10210 #ifdef V8_ENABLE_CHECKS
10211  CheckCast(value);
10212 #endif
10213  return static_cast<WasmCompiledModule*>(value);
10214 }
10215 
10216 Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
10217 #ifdef V8_ENABLE_CHECKS
10218  CheckCast(value);
10219 #endif
10220  return static_cast<Promise::Resolver*>(value);
10221 }
10222 
10223 
10224 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
10225 #ifdef V8_ENABLE_CHECKS
10226  CheckCast(value);
10227 #endif
10228  return static_cast<ArrayBuffer*>(value);
10229 }
10230 
10231 
10232 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
10233 #ifdef V8_ENABLE_CHECKS
10234  CheckCast(value);
10235 #endif
10236  return static_cast<ArrayBufferView*>(value);
10237 }
10238 
10239 
10240 TypedArray* TypedArray::Cast(v8::Value* value) {
10241 #ifdef V8_ENABLE_CHECKS
10242  CheckCast(value);
10243 #endif
10244  return static_cast<TypedArray*>(value);
10245 }
10246 
10247 
10248 Uint8Array* Uint8Array::Cast(v8::Value* value) {
10249 #ifdef V8_ENABLE_CHECKS
10250  CheckCast(value);
10251 #endif
10252  return static_cast<Uint8Array*>(value);
10253 }
10254 
10255 
10256 Int8Array* Int8Array::Cast(v8::Value* value) {
10257 #ifdef V8_ENABLE_CHECKS
10258  CheckCast(value);
10259 #endif
10260  return static_cast<Int8Array*>(value);
10261 }
10262 
10263 
10264 Uint16Array* Uint16Array::Cast(v8::Value* value) {
10265 #ifdef V8_ENABLE_CHECKS
10266  CheckCast(value);
10267 #endif
10268  return static_cast<Uint16Array*>(value);
10269 }
10270 
10271 
10272 Int16Array* Int16Array::Cast(v8::Value* value) {
10273 #ifdef V8_ENABLE_CHECKS
10274  CheckCast(value);
10275 #endif
10276  return static_cast<Int16Array*>(value);
10277 }
10278 
10279 
10280 Uint32Array* Uint32Array::Cast(v8::Value* value) {
10281 #ifdef V8_ENABLE_CHECKS
10282  CheckCast(value);
10283 #endif
10284  return static_cast<Uint32Array*>(value);
10285 }
10286 
10287 
10288 Int32Array* Int32Array::Cast(v8::Value* value) {
10289 #ifdef V8_ENABLE_CHECKS
10290  CheckCast(value);
10291 #endif
10292  return static_cast<Int32Array*>(value);
10293 }
10294 
10295 
10296 Float32Array* Float32Array::Cast(v8::Value* value) {
10297 #ifdef V8_ENABLE_CHECKS
10298  CheckCast(value);
10299 #endif
10300  return static_cast<Float32Array*>(value);
10301 }
10302 
10303 
10304 Float64Array* Float64Array::Cast(v8::Value* value) {
10305 #ifdef V8_ENABLE_CHECKS
10306  CheckCast(value);
10307 #endif
10308  return static_cast<Float64Array*>(value);
10309 }
10310 
10311 BigInt64Array* BigInt64Array::Cast(v8::Value* value) {
10312 #ifdef V8_ENABLE_CHECKS
10313  CheckCast(value);
10314 #endif
10315  return static_cast<BigInt64Array*>(value);
10316 }
10317 
10318 BigUint64Array* BigUint64Array::Cast(v8::Value* value) {
10319 #ifdef V8_ENABLE_CHECKS
10320  CheckCast(value);
10321 #endif
10322  return static_cast<BigUint64Array*>(value);
10323 }
10324 
10325 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
10326 #ifdef V8_ENABLE_CHECKS
10327  CheckCast(value);
10328 #endif
10329  return static_cast<Uint8ClampedArray*>(value);
10330 }
10331 
10332 
10333 DataView* DataView::Cast(v8::Value* value) {
10334 #ifdef V8_ENABLE_CHECKS
10335  CheckCast(value);
10336 #endif
10337  return static_cast<DataView*>(value);
10338 }
10339 
10340 
10341 SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
10342 #ifdef V8_ENABLE_CHECKS
10343  CheckCast(value);
10344 #endif
10345  return static_cast<SharedArrayBuffer*>(value);
10346 }
10347 
10348 
10349 Function* Function::Cast(v8::Value* value) {
10350 #ifdef V8_ENABLE_CHECKS
10351  CheckCast(value);
10352 #endif
10353  return static_cast<Function*>(value);
10354 }
10355 
10356 
10357 External* External::Cast(v8::Value* value) {
10358 #ifdef V8_ENABLE_CHECKS
10359  CheckCast(value);
10360 #endif
10361  return static_cast<External*>(value);
10362 }
10363 
10364 
10365 template<typename T>
10367  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
10368 }
10369 
10370 
10371 template<typename T>
10373  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
10374 }
10375 
10376 
10377 template<typename T>
10379  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
10380 }
10381 
10382 
10383 template<typename T>
10385  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
10386 }
10387 
10388 
10389 template<typename T>
10391  return ReturnValue<T>(&args_[kReturnValueIndex]);
10392 }
10393 
10394 template <typename T>
10396  typedef internal::Internals I;
10397  return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(0);
10398 }
10399 
10400 
10401 Local<Primitive> Undefined(Isolate* isolate) {
10402  typedef internal::Address S;
10403  typedef internal::Internals I;
10404  I::CheckInitialized(isolate);
10405  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
10406  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10407 }
10408 
10409 
10410 Local<Primitive> Null(Isolate* isolate) {
10411  typedef internal::Address S;
10412  typedef internal::Internals I;
10413  I::CheckInitialized(isolate);
10414  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
10415  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10416 }
10417 
10418 
10419 Local<Boolean> True(Isolate* isolate) {
10420  typedef internal::Address S;
10421  typedef internal::Internals I;
10422  I::CheckInitialized(isolate);
10423  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
10424  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
10425 }
10426 
10427 
10428 Local<Boolean> False(Isolate* isolate) {
10429  typedef internal::Address S;
10430  typedef internal::Internals I;
10431  I::CheckInitialized(isolate);
10432  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
10433  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
10434 }
10435 
10436 
10437 void Isolate::SetData(uint32_t slot, void* data) {
10438  typedef internal::Internals I;
10439  I::SetEmbedderData(this, slot, data);
10440 }
10441 
10442 
10443 void* Isolate::GetData(uint32_t slot) {
10444  typedef internal::Internals I;
10445  return I::GetEmbedderData(this, slot);
10446 }
10447 
10448 
10449 uint32_t Isolate::GetNumberOfDataSlots() {
10450  typedef internal::Internals I;
10451  return I::kNumIsolateDataSlots;
10452 }
10453 
10454 template <class T>
10455 MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
10456  T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
10457  if (data) internal::PerformCastCheck(data);
10458  return Local<T>(data);
10459 }
10460 
10461 int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
10462  int64_t change_in_bytes) {
10463  typedef internal::Internals I;
10464  constexpr int64_t kMemoryReducerActivationLimit = 32 * 1024 * 1024;
10465  int64_t* external_memory = reinterpret_cast<int64_t*>(
10466  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
10467  int64_t* external_memory_limit = reinterpret_cast<int64_t*>(
10468  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
10469  int64_t* external_memory_at_last_mc =
10470  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
10471  I::kExternalMemoryAtLastMarkCompactOffset);
10472 
10473  const int64_t amount = *external_memory + change_in_bytes;
10474  *external_memory = amount;
10475 
10476  int64_t allocation_diff_since_last_mc =
10477  *external_memory - *external_memory_at_last_mc;
10478  // Only check memory pressure and potentially trigger GC if the amount of
10479  // external memory increased.
10480  if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) {
10481  CheckMemoryPressure();
10482  }
10483 
10484  if (change_in_bytes < 0) {
10485  const int64_t lower_limit = *external_memory_limit + change_in_bytes;
10486  if (lower_limit > I::kExternalAllocationSoftLimit)
10487  *external_memory_limit = lower_limit;
10488  } else if (change_in_bytes > 0 && amount > *external_memory_limit) {
10489  ReportExternalAllocationLimitReached();
10490  }
10491  return *external_memory;
10492 }
10493 
10494 Local<Value> Context::GetEmbedderData(int index) {
10495 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
10496  typedef internal::Address A;
10497  typedef internal::Internals I;
10498  auto* context = *reinterpret_cast<internal::NeverReadOnlySpaceObject**>(this);
10499  A* result =
10500  HandleScope::CreateHandle(context, I::ReadEmbedderData<A>(this, index));
10501  return Local<Value>(reinterpret_cast<Value*>(result));
10502 #else
10503  return SlowGetEmbedderData(index);
10504 #endif
10505 }
10506 
10507 
10508 void* Context::GetAlignedPointerFromEmbedderData(int index) {
10509 #if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
10510  typedef internal::Internals I;
10511  return I::ReadEmbedderData<void*>(this, index);
10512 #else
10513  return SlowGetAlignedPointerFromEmbedderData(index);
10514 #endif
10515 }
10516 
10517 template <class T>
10518 MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
10519  T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
10520  if (data) internal::PerformCastCheck(data);
10521  return Local<T>(data);
10522 }
10523 
10524 template <class T>
10525 size_t SnapshotCreator::AddData(Local<Context> context, Local<T> object) {
10526  T* object_ptr = *object;
10527  internal::Address* p = reinterpret_cast<internal::Address*>(object_ptr);
10528  return AddData(context, *p);
10529 }
10530 
10531 template <class T>
10532 size_t SnapshotCreator::AddData(Local<T> object) {
10533  T* object_ptr = *object;
10534  internal::Address* p = reinterpret_cast<internal::Address*>(object_ptr);
10535  return AddData(*p);
10536 }
10537 
10550 } // namespace v8
10551 
10552 
10553 #undef TYPE_CHECK
10554 
10555 
10556 #endif // INCLUDE_V8_H_
V8_INLINE bool IsNearDeath() const
Definition: v8.h:9449
V8_INLINE uint16_t WrapperClassId() const
Definition: v8.h:9561
virtual void Unlock() const
Definition: v8.h:2677
IntegrityLevel
Definition: v8.h:3234
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:5572
KeyConversionMode
Definition: v8.h:3229
static V8_INLINE Local< Context > CreationContext(const PersistentBase< Object > &object)
Definition: v8.h:3601
bool only_terminate_in_safe_scope
Definition: v8.h:7201
WriteOptions
Definition: v8.h:2599
NewStringType
Definition: v8.h:2520
void(* GenericNamedPropertyDefinerCallback)(Local< Name > property, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5521
Definition: v8.h:94
V8_INLINE void Clear()
Definition: v8.h:200
V8_INLINE Local< T > Escape(Local< T > value)
Definition: v8.h:904
IndexFilter
Definition: v8.h:3223
PropertyAttribute
Definition: v8.h:3132
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
Definition: v8.h:3473
virtual bool IsCacheable() const
Definition: v8.h:2648
V8_INLINE int Length() const
Definition: v8.h:9751
static V8_INLINE Local< T > Cast(Local< S > that)
Definition: v8.h:251
KeyCollectionMode
Definition: v8.h:3217
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
Definition: v8.h:775
V8_INLINE bool IsWeak() const
Definition: v8.h:9460
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Definition: v8.h:3492
void(* GenericNamedPropertyDeleterCallback)(Local< Name > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:5489
Definition: v8.h:56
void(* IndexedPropertyDescriptorCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5595
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:3148
Definition: v8.h:2497
V8_INLINE bool IsEmpty() const
Definition: v8.h:195
Definition: v8.h:2119
V8_INLINE Local< Object > Holder() const
Definition: v8.h:9715
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
Definition: v8.h:671
V8_INLINE Local< Value > NewTarget() const
Definition: v8.h:9721
V8_INLINE Isolate * GetIsolate() const
Definition: v8.h:10366
V8_INLINE T FromJust() const
Definition: v8.h:8683
V8_INLINE bool ShouldThrowOnError() const
Definition: v8.h:10395
V8_INLINE void SetWeak()
Definition: v8.h:9508
PropertyHandlerFlags
Definition: v8.h:5851
V8_INLINE Local< S > As() const
Definition: v8.h:266
Definition: v8.h:85
void(* IndexedPropertyDefinerCallback)(uint32_t index, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5588
V8_INLINE Global()
Definition: v8.h:758
void SetIndexedPropertyHandler(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter=nullptr, IndexedPropertyQueryCallback query=nullptr, IndexedPropertyDeleterCallback deleter=nullptr, IndexedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >())
Definition: v8.h:6118
V8_INLINE Persistent(const Persistent &that)
Definition: v8.h:691
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
Definition: v8.h:347
bool(* AccessCheckCallback)(Local< Context > accessing_context, Local< Object > accessed_object, Local< Value > data)
Definition: v8.h:5614
CreateHistogramCallback create_histogram_callback
Definition: v8.h:7175
void(* GenericNamedPropertyQueryCallback)(Local< Name > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:5465
Definition: v8.h:3678
V8_DEPRECATE_SOON("Objects are always considered independent. " "Use MarkActive to avoid collecting otherwise dead weak handles.", V8_INLINE void MarkIndependent())
void(* GenericNamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:5498
StartupData * snapshot_blob
Definition: v8.h:7160
Definition: libplatform.h:13
Definition: v8.h:88
NamedPropertyHandlerConfiguration(GenericNamedPropertyGetterCallback getter=nullptr, GenericNamedPropertySetterCallback setter=nullptr, GenericNamedPropertyQueryCallback query=nullptr, GenericNamedPropertyDeleterCallback deleter=nullptr, GenericNamedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
Definition: v8.h:5901
V8_INLINE Local< Value > operator[](int i) const
Definition: v8.h:9702
Definition: api.h:126
V8_INLINE Global & operator=(Global< S > &&rhs)
Definition: v8.h:790
V8_INLINE bool operator!=(const Local< S > &that) const
Definition: v8.h:237
CounterLookupCallback counter_lookup_callback
Definition: v8.h:7167
AccessType
Definition: v8.h:5601
void(* GenericNamedPropertyDescriptorCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5544
V8_INLINE bool operator==(const Local< S > &that) const
Definition: v8.h:213
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5550
V8_INLINE Local< T > ToLocalChecked()
Definition: v8.h:9402
V8_INLINE Local< Value > Data() const
Definition: v8.h:9727
V8_INLINE ReturnValue< T > GetReturnValue() const
Definition: v8.h:10390
V8_WARN_UNUSED_RESULT V8_INLINE bool To(T *out) const
Definition: v8.h:8674
FunctionEntryHook entry_hook
Definition: v8.h:7144
V8_INLINE Persistent()
Definition: v8.h:664
V8_INLINE void MarkActive()
Definition: v8.h:9542
V8_INLINE Local< Value > Data() const
Definition: v8.h:10372
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5557
Definition: v8.h:3134
Definition: v8.h:3740
V8_INLINE Local(Local< S > that)
Definition: v8.h:182
IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback getter=nullptr, IndexedPropertySetterCallback setter=nullptr, IndexedPropertyQueryCallback query=nullptr, IndexedPropertyDeleterCallback deleter=nullptr, IndexedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
Definition: v8.h:5971
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:5582
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:5565
Definition: v8.h:4256
const intptr_t * external_references
Definition: v8.h:7190
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Definition: v8.h:681
V8_INLINE Global(Isolate *isolate, Local< S > that)
Definition: v8.h:765
V8_INLINE Local< Object > Holder() const
Definition: v8.h:10384
V8_INLINE ReturnValue< T > GetReturnValue() const
Definition: v8.h:9739
SideEffectType
Definition: v8.h:3204
V8_INLINE void SetWrapperClassId(uint16_t class_id)
Definition: v8.h:9551
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8.h:9365
V8_INLINE T FromMaybe(const T &default_value) const
Definition: v8.h:8692
void(* GenericNamedPropertyGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5416
virtual void Lock() const
Definition: v8.h:2672
StackTraceOptions
Definition: v8.h:1691
JitCodeEventHandler code_event_handler
Definition: v8.h:7150
Definition: v8.h:5090
V8_INLINE Global(Global &&other)
Definition: v8.h:782
ArrayBuffer::Allocator * array_buffer_allocator
Definition: v8.h:7182
V8_INLINE void RegisterExternalReference(Isolate *isolate) const
Definition: v8.h:9526
Definition: v8.h:1842
V8_INLINE Local< Object > This() const
Definition: v8.h:10378
V8_INLINE void AnnotateStrongRetainer(const char *label)
Definition: v8.h:9520
Definition: v8.h:963
V8_INLINE bool IsConstructCall() const
Definition: v8.h:9745
V8_INLINE T ToChecked() const
Definition: v8.h:8668
V8_INLINE Local< S > FromMaybe(Local< S > default_value) const
Definition: v8.h:363
void(* GenericNamedPropertySetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5440
V8_INLINE Local< Object > This() const
Definition: v8.h:9709
Status
Definition: v8.h:1140
Definition: v8.h:3050
PromiseState
Definition: v8.h:4104
V8_INLINE void Reset()
Definition: v8.h:9469
AccessControl
Definition: v8.h:3175
Global Pass()
Definition: v8.h:802
V8_INLINE Isolate * GetIsolate() const
Definition: v8.h:9733
PropertyFilter
Definition: v8.h:3185
ResourceConstraints constraints
Definition: v8.h:7155
Definition: v8.h:3704
V8_INLINE ~Persistent()
Definition: v8.h:712