v8  7.0.276(node11.14.0)
V8 is Google's open source JavaScript engine
v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "v8-version.h" // NOLINT(build/include)
26 #include "v8config.h" // NOLINT(build/include)
27 
28 // We reserve the V8_* prefix for macros defined in V8 public API and
29 // assume there are no name conflicts with the embedder's code.
30 
31 #ifdef V8_OS_WIN
32 
33 // Setup for Windows DLL export/import. When building the V8 DLL the
34 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
35 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
36 // static library or building a program which uses the V8 static library neither
37 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
38 #ifdef BUILDING_V8_SHARED
39 # define V8_EXPORT __declspec(dllexport)
40 #elif USING_V8_SHARED
41 # define V8_EXPORT __declspec(dllimport)
42 #else
43 # define V8_EXPORT
44 #endif // BUILDING_V8_SHARED
45 
46 #else // V8_OS_WIN
47 
48 // Setup for Linux shared library export.
49 #if V8_HAS_ATTRIBUTE_VISIBILITY
50 # ifdef BUILDING_V8_SHARED
51 # define V8_EXPORT __attribute__ ((visibility("default")))
52 # else
53 # define V8_EXPORT
54 # endif
55 #else
56 # define V8_EXPORT
57 #endif
58 
59 #endif // V8_OS_WIN
60 
64 namespace v8 {
65 
66 class AccessorSignature;
67 class Array;
68 class ArrayBuffer;
69 class BigInt;
70 class BigIntObject;
71 class Boolean;
72 class BooleanObject;
73 class Context;
74 class Data;
75 class Date;
76 class External;
77 class Function;
78 class FunctionTemplate;
79 class HeapProfiler;
80 class ImplementationUtilities;
81 class Int32;
82 class Integer;
83 class Isolate;
84 template <class T>
85 class Maybe;
86 class Name;
87 class Number;
88 class NumberObject;
89 class Object;
90 class ObjectOperationDescriptor;
91 class ObjectTemplate;
92 class Platform;
93 class Primitive;
94 class Promise;
95 class PropertyDescriptor;
96 class Proxy;
97 class RawOperationDescriptor;
98 class Script;
99 class SharedArrayBuffer;
100 class Signature;
101 class StartupData;
102 class StackFrame;
103 class StackTrace;
104 class String;
105 class StringObject;
106 class Symbol;
107 class SymbolObject;
108 class PrimitiveArray;
109 class Private;
110 class Uint32;
111 class Utils;
112 class Value;
113 class WasmCompiledModule;
114 template <class T> class Local;
115 template <class T>
117 template <class T> class Eternal;
118 template<class T> class NonCopyablePersistentTraits;
119 template<class T> class PersistentBase;
120 template <class T, class M = NonCopyablePersistentTraits<T> >
122 template <class T>
123 class Global;
124 template<class K, class V, class T> class PersistentValueMap;
125 template <class K, class V, class T>
127 template <class K, class V, class T>
128 class GlobalValueMap;
129 template<class V, class T> class PersistentValueVector;
130 template<class T, class P> class WeakCallbackObject;
131 class FunctionTemplate;
132 class ObjectTemplate;
133 template<typename T> class FunctionCallbackInfo;
134 template<typename T> class PropertyCallbackInfo;
135 class StackTrace;
136 class StackFrame;
137 class Isolate;
138 class CallHandlerHelper;
140 template<typename T> class ReturnValue;
141 
142 namespace internal {
143 class Arguments;
144 class DeferredHandles;
145 class Heap;
146 class HeapObject;
147 class Isolate;
148 class LocalEmbedderHeapTracer;
149 class NeverReadOnlySpaceObject;
150 class Object;
151 struct ScriptStreamingData;
152 template<typename T> class CustomArguments;
153 class PropertyCallbackArguments;
154 class FunctionCallbackArguments;
155 class GlobalHandles;
156 
157 namespace wasm {
158 class NativeModule;
159 class StreamingDecoder;
160 } // namespace wasm
161 
165 const int kApiPointerSize = sizeof(void*); // NOLINT
166 const int kApiDoubleSize = sizeof(double); // NOLINT
167 const int kApiIntSize = sizeof(int); // NOLINT
168 const int kApiInt64Size = sizeof(int64_t); // NOLINT
169 
170 // Tag information for HeapObject.
171 const int kHeapObjectTag = 1;
172 const int kWeakHeapObjectTag = 3;
173 const int kHeapObjectTagSize = 2;
174 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
175 
176 // Tag information for Smi.
177 const int kSmiTag = 0;
178 const int kSmiTagSize = 1;
179 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
180 
181 template <size_t tagged_ptr_size>
182 struct SmiTagging;
183 
184 template <int kSmiShiftSize>
185 V8_INLINE internal::Object* IntToSmi(int value) {
186  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
187  intptr_t tagged_value =
188  (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
189  return reinterpret_cast<internal::Object*>(tagged_value);
190 }
191 
192 // Smi constants for systems where tagged pointer is a 32-bit value.
193 template <>
194 struct SmiTagging<4> {
195  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
196  static int SmiShiftSize() { return kSmiShiftSize; }
197  static int SmiValueSize() { return kSmiValueSize; }
198  V8_INLINE static int SmiToInt(const internal::Object* value) {
199  int shift_bits = kSmiTagSize + kSmiShiftSize;
200  // Throw away top 32 bits and shift down (requires >> to be sign extending).
201  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
202  }
203  V8_INLINE static internal::Object* IntToSmi(int value) {
204  return internal::IntToSmi<kSmiShiftSize>(value);
205  }
206  V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
207  // To be representable as an tagged small integer, the two
208  // most-significant bits of 'value' must be either 00 or 11 due to
209  // sign-extension. To check this we add 01 to the two
210  // most-significant bits, and check if the most-significant bit is 0
211  //
212  // CAUTION: The original code below:
213  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
214  // may lead to incorrect results according to the C language spec, and
215  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
216  // compiler may produce undefined results in case of signed integer
217  // overflow. The computation must be done w/ unsigned ints.
218  return static_cast<uintptr_t>(value) + 0x40000000U < 0x80000000U;
219  }
220 };
221 
222 // Smi constants for systems where tagged pointer is a 64-bit value.
223 template <>
224 struct SmiTagging<8> {
225  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
226  static int SmiShiftSize() { return kSmiShiftSize; }
227  static int SmiValueSize() { return kSmiValueSize; }
228  V8_INLINE static int SmiToInt(const internal::Object* value) {
229  int shift_bits = kSmiTagSize + kSmiShiftSize;
230  // Shift down and throw away top 32 bits.
231  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
232  }
233  V8_INLINE static internal::Object* IntToSmi(int value) {
234  return internal::IntToSmi<kSmiShiftSize>(value);
235  }
236  V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
237  // To be representable as a long smi, the value must be a 32-bit integer.
238  return (value == static_cast<int32_t>(value));
239  }
240 };
241 
242 #if V8_COMPRESS_POINTERS
243 static_assert(
245  "Pointer compression can be enabled only for 64-bit architectures");
246 typedef SmiTagging<4> PlatformSmiTagging;
247 #else
249 #endif
250 
253 const int kSmiMinValue = (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
254 const int kSmiMaxValue = -(kSmiMinValue + 1);
255 constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
256 constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
257 
258 } // namespace internal
259 
260 namespace debug {
261 class ConsoleCallArguments;
262 } // namespace debug
263 
264 // --- Handles ---
265 
266 #define TYPE_CHECK(T, S) \
267  while (false) { \
268  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
269  }
270 
302 template <class T>
303 class Local {
304  public:
305  V8_INLINE Local() : val_(0) {}
306  template <class S>
308  : val_(reinterpret_cast<T*>(*that)) {
314  TYPE_CHECK(T, S);
315  }
316 
320  V8_INLINE bool IsEmpty() const { return val_ == 0; }
321 
325  V8_INLINE void Clear() { val_ = 0; }
326 
327  V8_INLINE T* operator->() const { return val_; }
328 
329  V8_INLINE T* operator*() const { return val_; }
330 
337  template <class S>
338  V8_INLINE bool operator==(const Local<S>& that) const {
339  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
340  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
341  if (a == 0) return b == 0;
342  if (b == 0) return false;
343  return *a == *b;
344  }
345 
346  template <class S> V8_INLINE bool operator==(
347  const PersistentBase<S>& that) const {
348  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
349  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
350  if (a == 0) return b == 0;
351  if (b == 0) return false;
352  return *a == *b;
353  }
354 
361  template <class S>
362  V8_INLINE bool operator!=(const Local<S>& that) const {
363  return !operator==(that);
364  }
365 
366  template <class S> V8_INLINE bool operator!=(
367  const Persistent<S>& that) const {
368  return !operator==(that);
369  }
370 
376  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
377 #ifdef V8_ENABLE_CHECKS
378  // If we're going to perform the type check then we have to check
379  // that the handle isn't empty before doing the checked cast.
380  if (that.IsEmpty()) return Local<T>();
381 #endif
382  return Local<T>(T::Cast(*that));
383  }
384 
390  template <class S>
392  return Local<S>::Cast(*this);
393  }
394 
400  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
401  V8_INLINE static Local<T> New(Isolate* isolate,
402  const PersistentBase<T>& that);
403 
404  private:
405  friend class Utils;
406  template<class F> friend class Eternal;
407  template<class F> friend class PersistentBase;
408  template<class F, class M> friend class Persistent;
409  template<class F> friend class Local;
410  template <class F>
411  friend class MaybeLocal;
412  template<class F> friend class FunctionCallbackInfo;
413  template<class F> friend class PropertyCallbackInfo;
414  friend class String;
415  friend class Object;
416  friend class Context;
417  friend class Isolate;
418  friend class Private;
419  template<class F> friend class internal::CustomArguments;
420  friend Local<Primitive> Undefined(Isolate* isolate);
421  friend Local<Primitive> Null(Isolate* isolate);
422  friend Local<Boolean> True(Isolate* isolate);
423  friend Local<Boolean> False(Isolate* isolate);
424  friend class HandleScope;
425  friend class EscapableHandleScope;
426  template <class F1, class F2, class F3>
428  template<class F1, class F2> friend class PersistentValueVector;
429  template <class F>
430  friend class ReturnValue;
431 
432  explicit V8_INLINE Local(T* that) : val_(that) {}
433  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
434  T* val_;
435 };
436 
437 
438 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
439 // Handle is an alias for Local for historical reasons.
440 template <class T>
441 using Handle = Local<T>;
442 #endif
443 
444 
455 template <class T>
456 class MaybeLocal {
457  public:
458  V8_INLINE MaybeLocal() : val_(nullptr) {}
459  template <class S>
461  : val_(reinterpret_cast<T*>(*that)) {
462  TYPE_CHECK(T, S);
463  }
464 
465  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
466 
471  template <class S>
473  out->val_ = IsEmpty() ? nullptr : this->val_;
474  return !IsEmpty();
475  }
476 
482 
487  template <class S>
488  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
489  return IsEmpty() ? default_value : Local<S>(val_);
490  }
491 
492  private:
493  T* val_;
494 };
495 
500 template <class T> class Eternal {
501  public:
502  V8_INLINE Eternal() : val_(nullptr) {}
503  template <class S>
504  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
505  Set(isolate, handle);
506  }
507  // Can only be safely called if already set.
508  V8_INLINE Local<T> Get(Isolate* isolate) const;
509  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
510  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
511 
512  private:
513  T* val_;
514 };
515 
516 
517 static const int kInternalFieldsInWeakCallback = 2;
518 static const int kEmbedderFieldsInWeakCallback = 2;
519 
520 template <typename T>
522  public:
523  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
524 
525  WeakCallbackInfo(Isolate* isolate, T* parameter,
526  void* embedder_fields[kEmbedderFieldsInWeakCallback],
527  Callback* callback)
528  : isolate_(isolate), parameter_(parameter), callback_(callback) {
529  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
530  embedder_fields_[i] = embedder_fields[i];
531  }
532  }
533 
534  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
535  V8_INLINE T* GetParameter() const { return parameter_; }
536  V8_INLINE void* GetInternalField(int index) const;
537 
538  // When first called, the embedder MUST Reset() the Global which triggered the
539  // callback. The Global itself is unusable for anything else. No v8 other api
540  // calls may be called in the first callback. Should additional work be
541  // required, the embedder must set a second pass callback, which will be
542  // called after all the initial callbacks are processed.
543  // Calling SetSecondPassCallback on the second pass will immediately crash.
544  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
545 
546  private:
547  Isolate* isolate_;
548  T* parameter_;
549  Callback* callback_;
550  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
551 };
552 
553 
554 // kParameter will pass a void* parameter back to the callback, kInternalFields
555 // will pass the first two internal fields back to the callback, kFinalizer
556 // will pass a void* parameter back, but is invoked before the object is
557 // actually collected, so it can be resurrected. In the last case, it is not
558 // possible to request a second pass callback.
560 
574 template <class T> class PersistentBase {
575  public:
580  V8_INLINE void Reset();
585  template <class S>
586  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
587 
592  template <class S>
593  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
594 
595  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
596  V8_INLINE void Empty() { val_ = 0; }
597 
598  V8_INLINE Local<T> Get(Isolate* isolate) const {
599  return Local<T>::New(isolate, *this);
600  }
601 
602  template <class S>
603  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
604  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
605  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
606  if (a == NULL) return b == NULL;
607  if (b == NULL) return false;
608  return *a == *b;
609  }
610 
611  template <class S>
612  V8_INLINE bool operator==(const Local<S>& that) const {
613  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
614  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
615  if (a == NULL) return b == NULL;
616  if (b == NULL) return false;
617  return *a == *b;
618  }
619 
620  template <class S>
621  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
622  return !operator==(that);
623  }
624 
625  template <class S>
626  V8_INLINE bool operator!=(const Local<S>& that) const {
627  return !operator==(that);
628  }
629 
637  template <typename P>
638  V8_INLINE void SetWeak(P* parameter,
639  typename WeakCallbackInfo<P>::Callback callback,
640  WeakCallbackType type);
641 
649  V8_INLINE void SetWeak();
650 
651  template<typename P>
652  V8_INLINE P* ClearWeak();
653 
654  // TODO(dcarney): remove this.
655  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
656 
663  V8_INLINE void AnnotateStrongRetainer(const char* label);
664 
670  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
671 
679  "Objects are always considered independent. "
680  "Use MarkActive to avoid collecting otherwise dead weak handles.",
681  V8_INLINE void MarkIndependent());
682 
690  V8_INLINE void MarkActive();
691 
692  V8_DEPRECATE_SOON("See MarkIndependent.",
693  V8_INLINE bool IsIndependent() const);
694 
696  V8_INLINE bool IsNearDeath() const;
697 
699  V8_INLINE bool IsWeak() const;
700 
705  V8_INLINE void SetWrapperClassId(uint16_t class_id);
706 
711  V8_INLINE uint16_t WrapperClassId() const;
712 
713  PersistentBase(const PersistentBase& other) = delete; // NOLINT
714  void operator=(const PersistentBase&) = delete;
715 
716  private:
717  friend class Isolate;
718  friend class Utils;
719  template<class F> friend class Local;
720  template<class F1, class F2> friend class Persistent;
721  template <class F>
722  friend class Global;
723  template<class F> friend class PersistentBase;
724  template<class F> friend class ReturnValue;
725  template <class F1, class F2, class F3>
727  template<class F1, class F2> friend class PersistentValueVector;
728  friend class Object;
729 
730  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
731  V8_INLINE static T* New(Isolate* isolate, T* that);
732 
733  T* val_;
734 };
735 
736 
743 template<class T>
744 class NonCopyablePersistentTraits {
745  public:
747  static const bool kResetInDestructor = false;
748  template<class S, class M>
749  V8_INLINE static void Copy(const Persistent<S, M>& source,
750  NonCopyablePersistent* dest) {
751  Uncompilable<Object>();
752  }
753  // TODO(dcarney): come up with a good compile error here.
754  template<class O> V8_INLINE static void Uncompilable() {
755  TYPE_CHECK(O, Primitive);
756  }
757 };
758 
759 
764 template<class T>
767  static const bool kResetInDestructor = true;
768  template<class S, class M>
769  static V8_INLINE void Copy(const Persistent<S, M>& source,
770  CopyablePersistent* dest) {
771  // do nothing, just allow copy
772  }
773 };
774 
775 
784 template <class T, class M> class Persistent : public PersistentBase<T> {
785  public:
795  template <class S>
797  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
798  TYPE_CHECK(T, S);
799  }
805  template <class S, class M2>
807  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
808  TYPE_CHECK(T, S);
809  }
817  Copy(that);
818  }
819  template <class S, class M2>
821  Copy(that);
822  }
823  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
824  Copy(that);
825  return *this;
826  }
827  template <class S, class M2>
829  Copy(that);
830  return *this;
831  }
838  if (M::kResetInDestructor) this->Reset();
839  }
840 
841  // TODO(dcarney): this is pretty useless, fix or remove
842  template <class S>
843  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
844 #ifdef V8_ENABLE_CHECKS
845  // If we're going to perform the type check then we have to check
846  // that the handle isn't empty before doing the checked cast.
847  if (!that.IsEmpty()) T::Cast(*that);
848 #endif
849  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
850  }
851 
852  // TODO(dcarney): this is pretty useless, fix or remove
853  template <class S>
854  V8_INLINE Persistent<S>& As() const { // NOLINT
855  return Persistent<S>::Cast(*this);
856  }
857 
858  private:
859  friend class Isolate;
860  friend class Utils;
861  template<class F> friend class Local;
862  template<class F1, class F2> friend class Persistent;
863  template<class F> friend class ReturnValue;
864 
865  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
866  V8_INLINE T* operator*() const { return this->val_; }
867  template<class S, class M2>
868  V8_INLINE void Copy(const Persistent<S, M2>& that);
869 };
870 
871 
877 template <class T>
878 class Global : public PersistentBase<T> {
879  public:
883  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
889  template <class S>
891  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
892  TYPE_CHECK(T, S);
893  }
899  template <class S>
900  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
901  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
902  TYPE_CHECK(T, S);
903  }
907  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
908  other.val_ = nullptr;
909  }
910  V8_INLINE ~Global() { this->Reset(); }
914  template <class S>
915  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
916  TYPE_CHECK(T, S);
917  if (this != &rhs) {
918  this->Reset();
919  this->val_ = rhs.val_;
920  rhs.val_ = nullptr;
921  }
922  return *this;
923  }
927  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
928 
929  /*
930  * For compatibility with Chromium's base::Bind (base::Passed).
931  */
932  typedef void MoveOnlyTypeForCPP03;
933 
934  Global(const Global&) = delete;
935  void operator=(const Global&) = delete;
936 
937  private:
938  template <class F>
939  friend class ReturnValue;
940  V8_INLINE T* operator*() const { return this->val_; }
941 };
942 
943 
944 // UniquePersistent is an alias for Global for historical reason.
945 template <class T>
947 
948 
964  public:
965  explicit HandleScope(Isolate* isolate);
966 
967  ~HandleScope();
968 
972  static int NumberOfHandles(Isolate* isolate);
973 
974  V8_INLINE Isolate* GetIsolate() const {
975  return reinterpret_cast<Isolate*>(isolate_);
976  }
977 
978  HandleScope(const HandleScope&) = delete;
979  void operator=(const HandleScope&) = delete;
980 
981  protected:
983 
984  void Initialize(Isolate* isolate);
985 
986  static internal::Object** CreateHandle(internal::Isolate* isolate,
987  internal::Object* value);
988 
989  private:
990  // Declaring operator new and delete as deleted is not spec compliant.
991  // Therefore declare them private instead to disable dynamic alloc
992  void* operator new(size_t size);
993  void* operator new[](size_t size);
994  void operator delete(void*, size_t);
995  void operator delete[](void*, size_t);
996 
997  // Uses heap_object to obtain the current Isolate.
998  static internal::Object** CreateHandle(
999  internal::NeverReadOnlySpaceObject* heap_object, internal::Object* value);
1000 
1001  internal::Isolate* isolate_;
1002  internal::Object** prev_next_;
1003  internal::Object** prev_limit_;
1004 
1005  // Local::New uses CreateHandle with an Isolate* parameter.
1006  template<class F> friend class Local;
1007 
1008  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
1009  // a HeapObject* in their shortcuts.
1010  friend class Object;
1011  friend class Context;
1012 };
1013 
1014 
1020  public:
1021  explicit EscapableHandleScope(Isolate* isolate);
1023 
1028  template <class T>
1030  internal::Object** slot =
1031  Escape(reinterpret_cast<internal::Object**>(*value));
1032  return Local<T>(reinterpret_cast<T*>(slot));
1033  }
1034 
1035  template <class T>
1037  return Escape(value.FromMaybe(Local<T>()));
1038  }
1039 
1040  EscapableHandleScope(const EscapableHandleScope&) = delete;
1041  void operator=(const EscapableHandleScope&) = delete;
1042 
1043  private:
1044  // Declaring operator new and delete as deleted is not spec compliant.
1045  // Therefore declare them private instead to disable dynamic alloc
1046  void* operator new(size_t size);
1047  void* operator new[](size_t size);
1048  void operator delete(void*, size_t);
1049  void operator delete[](void*, size_t);
1050 
1051  internal::Object** Escape(internal::Object** escape_value);
1052  internal::Object** escape_slot_;
1053 };
1054 
1061  public:
1062  explicit SealHandleScope(Isolate* isolate);
1063  ~SealHandleScope();
1064 
1065  SealHandleScope(const SealHandleScope&) = delete;
1066  void operator=(const SealHandleScope&) = delete;
1067 
1068  private:
1069  // Declaring operator new and delete as deleted is not spec compliant.
1070  // Therefore declare them private instead to disable dynamic alloc
1071  void* operator new(size_t size);
1072  void* operator new[](size_t size);
1073  void operator delete(void*, size_t);
1074  void operator delete[](void*, size_t);
1075 
1076  internal::Isolate* const isolate_;
1077  internal::Object** prev_limit_;
1078  int prev_sealed_level_;
1079 };
1080 
1081 
1082 // --- Special objects ---
1083 
1084 
1089  private:
1090  Data();
1091 };
1092 
1100  public:
1105  Local<Value> GetResourceName();
1106 
1111  Local<PrimitiveArray> GetHostDefinedOptions();
1112 };
1113 
1123  public:
1124  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1125  int Length() const;
1126  void Set(Isolate* isolate, int index, Local<Primitive> item);
1127  Local<Primitive> Get(Isolate* isolate, int index);
1128 };
1129 
1134  public:
1135  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1136  bool is_opaque = false, bool is_wasm = false,
1137  bool is_module = false)
1138  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1139  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1140  (is_module ? kIsModule : 0)) {}
1142  : flags_(flags &
1143  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1144 
1145  bool IsSharedCrossOrigin() const {
1146  return (flags_ & kIsSharedCrossOrigin) != 0;
1147  }
1148  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1149  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1150  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1151 
1152  int Flags() const { return flags_; }
1153 
1154  private:
1155  enum {
1156  kIsSharedCrossOrigin = 1,
1157  kIsOpaque = 1 << 1,
1158  kIsWasm = 1 << 2,
1159  kIsModule = 1 << 3
1160  };
1161  const int flags_;
1162 };
1163 
1168  public:
1170  Local<Value> resource_name,
1171  Local<Integer> resource_line_offset = Local<Integer>(),
1172  Local<Integer> resource_column_offset = Local<Integer>(),
1173  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1174  Local<Integer> script_id = Local<Integer>(),
1175  Local<Value> source_map_url = Local<Value>(),
1176  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1177  Local<Boolean> is_wasm = Local<Boolean>(),
1178  Local<Boolean> is_module = Local<Boolean>(),
1179  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1180 
1187  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1188 
1189  private:
1190  Local<Value> resource_name_;
1191  Local<Integer> resource_line_offset_;
1192  Local<Integer> resource_column_offset_;
1193  ScriptOriginOptions options_;
1194  Local<Integer> script_id_;
1195  Local<Value> source_map_url_;
1196  Local<PrimitiveArray> host_defined_options_;
1197 };
1198 
1203  public:
1207  Local<Script> BindToCurrentContext();
1208 
1209  int GetId();
1210  Local<Value> GetScriptName();
1211 
1215  Local<Value> GetSourceURL();
1219  Local<Value> GetSourceMappingURL();
1220 
1225  int GetLineNumber(int code_pos);
1226 
1227  static const int kNoScriptId = 0;
1228 };
1229 
1234  // Only used as a container for code caching.
1235 };
1236 
1241  public:
1242  int GetLineNumber() { return line_number_; }
1243  int GetColumnNumber() { return column_number_; }
1244 
1245  Location(int line_number, int column_number)
1246  : line_number_(line_number), column_number_(column_number) {}
1247 
1248  private:
1249  int line_number_;
1250  int column_number_;
1251 };
1252 
1257  public:
1265  enum Status {
1271  kErrored
1272  };
1273 
1277  Status GetStatus() const;
1278 
1282  Local<Value> GetException() const;
1283 
1287  int GetModuleRequestsLength() const;
1288 
1293  Local<String> GetModuleRequest(int i) const;
1294 
1299  Location GetModuleRequestLocation(int i) const;
1300 
1304  int GetIdentityHash() const;
1305 
1306  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1307  Local<String> specifier,
1308  Local<Module> referrer);
1309 
1317  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1318  ResolveCallback callback);
1319 
1329 
1335  Local<Value> GetModuleNamespace();
1336 
1343  Local<UnboundModuleScript> GetUnboundModuleScript();
1344 };
1345 
1351  public:
1356  Local<Context> context, Local<String> source,
1357  ScriptOrigin* origin = nullptr);
1358 
1365 
1369  Local<UnboundScript> GetUnboundScript();
1370 };
1371 
1372 
1377  public:
1388  BufferOwned
1389  };
1390 
1392  : data(NULL),
1393  length(0),
1394  rejected(false),
1395  buffer_policy(BufferNotOwned) {}
1396 
1397  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1398  // data and guarantees that it stays alive until the CachedData object is
1399  // destroyed. If the policy is BufferOwned, the given data will be deleted
1400  // (with delete[]) when the CachedData object is destroyed.
1401  CachedData(const uint8_t* data, int length,
1402  BufferPolicy buffer_policy = BufferNotOwned);
1403  ~CachedData();
1404  // TODO(marja): Async compilation; add constructors which take a callback
1405  // which will be called when V8 no longer needs the data.
1406  const uint8_t* data;
1407  int length;
1408  bool rejected;
1410 
1411  // Prevent copying.
1412  CachedData(const CachedData&) = delete;
1413  CachedData& operator=(const CachedData&) = delete;
1414  };
1415 
1419  class Source {
1420  public:
1421  // Source takes ownership of CachedData.
1422  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1423  CachedData* cached_data = NULL);
1424  V8_INLINE Source(Local<String> source_string,
1425  CachedData* cached_data = NULL);
1426  V8_INLINE ~Source();
1427 
1428  // Ownership of the CachedData or its buffers is *not* transferred to the
1429  // caller. The CachedData object is alive as long as the Source object is
1430  // alive.
1431  V8_INLINE const CachedData* GetCachedData() const;
1432 
1433  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1434 
1435  // Prevent copying.
1436  Source(const Source&) = delete;
1437  Source& operator=(const Source&) = delete;
1438 
1439  private:
1440  friend class ScriptCompiler;
1441 
1442  Local<String> source_string;
1443 
1444  // Origin information
1445  Local<Value> resource_name;
1446  Local<Integer> resource_line_offset;
1447  Local<Integer> resource_column_offset;
1448  ScriptOriginOptions resource_options;
1449  Local<Value> source_map_url;
1450  Local<PrimitiveArray> host_defined_options;
1451 
1452  // Cached data from previous compilation (if a kConsume*Cache flag is
1453  // set), or hold newly generated cache data (kProduce*Cache flags) are
1454  // set when calling a compile method.
1455  CachedData* cached_data;
1456  };
1457 
1463  public:
1465 
1487  virtual size_t GetMoreData(const uint8_t** src) = 0;
1488 
1499  virtual bool SetBookmark();
1500 
1504  virtual void ResetToBookmark();
1505  };
1506 
1507 
1515  public:
1516  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1517 
1518  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1519  ~StreamedSource();
1520 
1521  // Ownership of the CachedData or its buffers is *not* transferred to the
1522  // caller. The CachedData object is alive as long as the StreamedSource
1523  // object is alive.
1524  const CachedData* GetCachedData() const;
1525 
1526  internal::ScriptStreamingData* impl() const { return impl_; }
1527 
1528  // Prevent copying.
1529  StreamedSource(const StreamedSource&) = delete;
1530  StreamedSource& operator=(const StreamedSource&) = delete;
1531 
1532  private:
1533  internal::ScriptStreamingData* impl_;
1534  };
1535 
1541  public:
1543  virtual void Run() = 0;
1544  };
1545 
1547  kNoCompileOptions = 0,
1553  kEagerCompile
1554  };
1555 
1560  kNoCacheNoReason = 0,
1574  kNoCacheBecauseDeferredProduceCodeCache
1575  };
1576 
1590  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1591  Isolate* isolate, Source* source,
1592  CompileOptions options = kNoCompileOptions,
1593  NoCacheReason no_cache_reason = kNoCacheNoReason);
1594 
1607  Local<Context> context, Source* source,
1608  CompileOptions options = kNoCompileOptions,
1609  NoCacheReason no_cache_reason = kNoCacheNoReason);
1610 
1622  static ScriptStreamingTask* StartStreamingScript(
1623  Isolate* isolate, StreamedSource* source,
1624  CompileOptions options = kNoCompileOptions);
1625 
1634  Local<Context> context, StreamedSource* source,
1635  Local<String> full_source_string, const ScriptOrigin& origin);
1636 
1655  static uint32_t CachedDataVersionTag();
1656 
1664  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1665  Isolate* isolate, Source* source,
1666  CompileOptions options = kNoCompileOptions,
1667  NoCacheReason no_cache_reason = kNoCacheNoReason);
1668 
1679  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1680  Local<Context> context, Source* source, size_t arguments_count,
1681  Local<String> arguments[], size_t context_extension_count,
1682  Local<Object> context_extensions[],
1683  CompileOptions options = kNoCompileOptions,
1684  NoCacheReason no_cache_reason = kNoCacheNoReason);
1685 
1691  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
1692 
1698  static CachedData* CreateCodeCache(
1699  Local<UnboundModuleScript> unbound_module_script);
1700 
1707  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
1708 
1709  private:
1710  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1711  Isolate* isolate, Source* source, CompileOptions options,
1712  NoCacheReason no_cache_reason);
1713 };
1714 
1715 
1720  public:
1721  Local<String> Get() const;
1722 
1726  Isolate* GetIsolate() const;
1727 
1729  Local<Context> context) const;
1730 
1735  ScriptOrigin GetScriptOrigin() const;
1736 
1741  Local<Value> GetScriptResourceName() const;
1742 
1748  Local<StackTrace> GetStackTrace() const;
1749 
1753  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1754 
1759  int GetStartPosition() const;
1760 
1765  int GetEndPosition() const;
1766 
1770  int ErrorLevel() const;
1771 
1776  int GetStartColumn() const;
1777  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1778 
1783  int GetEndColumn() const;
1784  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1785 
1790  bool IsSharedCrossOrigin() const;
1791  bool IsOpaque() const;
1792 
1793  // TODO(1245381): Print to a string instead of on a FILE.
1794  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1795 
1796  static const int kNoLineNumberInfo = 0;
1797  static const int kNoColumnInfo = 0;
1798  static const int kNoScriptIdInfo = 0;
1799 };
1800 
1801 
1808  public:
1816  kLineNumber = 1,
1817  kColumnOffset = 1 << 1 | kLineNumber,
1818  kScriptName = 1 << 2,
1819  kFunctionName = 1 << 3,
1820  kIsEval = 1 << 4,
1821  kIsConstructor = 1 << 5,
1822  kScriptNameOrSourceURL = 1 << 6,
1823  kScriptId = 1 << 7,
1824  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1825  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1826  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1827  };
1828 
1832  Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
1833 
1837  int GetFrameCount() const;
1838 
1846  static Local<StackTrace> CurrentStackTrace(
1847  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1848 };
1849 
1850 
1855  public:
1862  int GetLineNumber() const;
1863 
1871  int GetColumn() const;
1872 
1879  int GetScriptId() const;
1880 
1885  Local<String> GetScriptName() const;
1886 
1893  Local<String> GetScriptNameOrSourceURL() const;
1894 
1898  Local<String> GetFunctionName() const;
1899 
1904  bool IsEval() const;
1905 
1910  bool IsConstructor() const;
1911 
1915  bool IsWasm() const;
1916 };
1917 
1918 
1919 // A StateTag represents a possible state of the VM.
1920 enum StateTag {
1929 };
1930 
1931 // A RegisterState represents the current state of registers used
1932 // by the sampling profiler API.
1934  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1935  void* pc; // Instruction pointer.
1936  void* sp; // Stack pointer.
1937  void* fp; // Frame pointer.
1938 };
1939 
1940 // The output structure filled up by GetStackSample API function.
1941 struct SampleInfo {
1942  size_t frames_count; // Number of frames collected.
1943  StateTag vm_state; // Current VM state.
1944  void* external_callback_entry; // External callback address if VM is
1945  // executing an external callback.
1946 };
1947 
1952  public:
1960  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1961  MaybeLocal<Value> Parse(Isolate* isolate,
1962  Local<String> json_string));
1964  Local<Context> context, Local<String> json_string);
1965 
1973  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1974  Local<Context> context, Local<Value> json_object,
1975  Local<String> gap = Local<String>());
1976 };
1977 
1987  public:
1989  public:
1990  virtual ~Delegate() {}
1991 
1997  virtual void ThrowDataCloneError(Local<String> message) = 0;
1998 
2004  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
2005 
2016  virtual Maybe<uint32_t> GetSharedArrayBufferId(
2017  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
2018 
2019  virtual Maybe<uint32_t> GetWasmModuleTransferId(
2020  Isolate* isolate, Local<WasmCompiledModule> module);
2032  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
2033  size_t* actual_size);
2034 
2040  virtual void FreeBufferMemory(void* buffer);
2041  };
2042 
2043  explicit ValueSerializer(Isolate* isolate);
2044  ValueSerializer(Isolate* isolate, Delegate* delegate);
2045  ~ValueSerializer();
2046 
2050  void WriteHeader();
2051 
2056  Local<Value> value);
2057 
2062  V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
2063 
2070  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
2071 
2077  void TransferArrayBuffer(uint32_t transfer_id,
2078  Local<ArrayBuffer> array_buffer);
2079 
2083  V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
2084  void TransferSharedArrayBuffer(
2085  uint32_t transfer_id,
2086  Local<SharedArrayBuffer> shared_array_buffer));
2087 
2095  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
2096 
2102  void WriteUint32(uint32_t value);
2103  void WriteUint64(uint64_t value);
2104  void WriteDouble(double value);
2105  void WriteRawBytes(const void* source, size_t length);
2106 
2107  private:
2108  ValueSerializer(const ValueSerializer&) = delete;
2109  void operator=(const ValueSerializer&) = delete;
2110 
2111  struct PrivateData;
2112  PrivateData* private_;
2113 };
2114 
2124  public:
2126  public:
2127  virtual ~Delegate() {}
2128 
2134  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
2135 
2140  virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
2141  Isolate* isolate, uint32_t transfer_id);
2142 
2147  virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
2148  Isolate* isolate, uint32_t clone_id);
2149  };
2150 
2151  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2152  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2153  Delegate* delegate);
2154  ~ValueDeserializer();
2155 
2160  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2161 
2166 
2171  void TransferArrayBuffer(uint32_t transfer_id,
2172  Local<ArrayBuffer> array_buffer);
2173 
2179  void TransferSharedArrayBuffer(uint32_t id,
2180  Local<SharedArrayBuffer> shared_array_buffer);
2181 
2189  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2190 
2194  void SetExpectInlineWasm(bool allow_inline_wasm);
2195 
2201  uint32_t GetWireFormatVersion() const;
2202 
2208  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2209  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2210  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2211  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2212 
2213  private:
2214  ValueDeserializer(const ValueDeserializer&) = delete;
2215  void operator=(const ValueDeserializer&) = delete;
2216 
2217  struct PrivateData;
2218  PrivateData* private_;
2219 };
2220 
2221 
2222 // --- Value ---
2223 
2224 
2228 class V8_EXPORT Value : public Data {
2229  public:
2234  V8_INLINE bool IsUndefined() const;
2235 
2240  V8_INLINE bool IsNull() const;
2241 
2247  V8_INLINE bool IsNullOrUndefined() const;
2248 
2252  bool IsTrue() const;
2253 
2257  bool IsFalse() const;
2258 
2262  bool IsName() const;
2263 
2268  V8_INLINE bool IsString() const;
2269 
2273  bool IsSymbol() const;
2274 
2278  bool IsFunction() const;
2279 
2284  bool IsArray() const;
2285 
2289  bool IsObject() const;
2290 
2294  bool IsBigInt() const;
2295 
2299  bool IsBoolean() const;
2300 
2304  bool IsNumber() const;
2305 
2309  bool IsExternal() const;
2310 
2314  bool IsInt32() const;
2315 
2319  bool IsUint32() const;
2320 
2324  bool IsDate() const;
2325 
2329  bool IsArgumentsObject() const;
2330 
2334  bool IsBigIntObject() const;
2335 
2339  bool IsBooleanObject() const;
2340 
2344  bool IsNumberObject() const;
2345 
2349  bool IsStringObject() const;
2350 
2354  bool IsSymbolObject() const;
2355 
2359  bool IsNativeError() const;
2360 
2364  bool IsRegExp() const;
2365 
2369  bool IsAsyncFunction() const;
2370 
2374  bool IsGeneratorFunction() const;
2375 
2379  bool IsGeneratorObject() const;
2380 
2384  bool IsPromise() const;
2385 
2389  bool IsMap() const;
2390 
2394  bool IsSet() const;
2395 
2399  bool IsMapIterator() const;
2400 
2404  bool IsSetIterator() const;
2405 
2409  bool IsWeakMap() const;
2410 
2414  bool IsWeakSet() const;
2415 
2419  bool IsArrayBuffer() const;
2420 
2424  bool IsArrayBufferView() const;
2425 
2429  bool IsTypedArray() const;
2430 
2434  bool IsUint8Array() const;
2435 
2439  bool IsUint8ClampedArray() const;
2440 
2444  bool IsInt8Array() const;
2445 
2449  bool IsUint16Array() const;
2450 
2454  bool IsInt16Array() const;
2455 
2459  bool IsUint32Array() const;
2460 
2464  bool IsInt32Array() const;
2465 
2469  bool IsFloat32Array() const;
2470 
2474  bool IsFloat64Array() const;
2475 
2479  bool IsBigInt64Array() const;
2480 
2484  bool IsBigUint64Array() const;
2485 
2489  bool IsDataView() const;
2490 
2495  bool IsSharedArrayBuffer() const;
2496 
2500  bool IsProxy() const;
2501 
2502  bool IsWebAssemblyCompiledModule() const;
2503 
2507  bool IsModuleNamespaceObject() const;
2508 
2510  Local<Context> context) const;
2512  Local<Context> context) const;
2514  Local<Context> context) const;
2516  Local<Context> context) const;
2518  Local<Context> context) const;
2520  Local<Context> context) const;
2522  Local<Context> context) const;
2524  Local<Context> context) const;
2526 
2527  V8_DEPRECATE_SOON("Use maybe version",
2528  Local<Boolean> ToBoolean(Isolate* isolate) const);
2529  V8_DEPRECATE_SOON("Use maybe version",
2530  Local<Number> ToNumber(Isolate* isolate) const);
2531  V8_DEPRECATE_SOON("Use maybe version",
2532  Local<String> ToString(Isolate* isolate) const);
2533  V8_DEPRECATE_SOON("Use maybe version",
2534  Local<Object> ToObject(Isolate* isolate) const);
2535  V8_DEPRECATE_SOON("Use maybe version",
2536  Local<Integer> ToInteger(Isolate* isolate) const);
2537  V8_DEPRECATE_SOON("Use maybe version",
2538  Local<Int32> ToInt32(Isolate* isolate) const);
2539 
2545  Local<Context> context) const;
2546 
2547  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2548  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2550  Local<Context> context) const;
2552  Local<Context> context) const;
2553  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2554 
2557  Local<Value> that) const;
2558  bool StrictEquals(Local<Value> that) const;
2559  bool SameValue(Local<Value> that) const;
2560 
2561  template <class T> V8_INLINE static Value* Cast(T* value);
2562 
2563  Local<String> TypeOf(Isolate*);
2564 
2565  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2566 
2567  private:
2568  V8_INLINE bool QuickIsUndefined() const;
2569  V8_INLINE bool QuickIsNull() const;
2570  V8_INLINE bool QuickIsNullOrUndefined() const;
2571  V8_INLINE bool QuickIsString() const;
2572  bool FullIsUndefined() const;
2573  bool FullIsNull() const;
2574  bool FullIsString() const;
2575 };
2576 
2577 
2581 class V8_EXPORT Primitive : public Value { };
2582 
2583 
2588 class V8_EXPORT Boolean : public Primitive {
2589  public:
2590  bool Value() const;
2591  V8_INLINE static Boolean* Cast(v8::Value* obj);
2592  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2593 
2594  private:
2595  static void CheckCast(v8::Value* obj);
2596 };
2597 
2598 
2602 class V8_EXPORT Name : public Primitive {
2603  public:
2611  int GetIdentityHash();
2612 
2613  V8_INLINE static Name* Cast(Value* obj);
2614 
2615  private:
2616  static void CheckCast(Value* obj);
2617 };
2618 
2625 enum class NewStringType {
2629  kNormal,
2630 
2637 };
2638 
2642 class V8_EXPORT String : public Name {
2643  public:
2644  static constexpr int kMaxLength = internal::kApiPointerSize == 4
2645  ? (1 << 28) - 16
2646  : internal::kSmiMaxValue / 2 - 24;
2647 
2648  enum Encoding {
2649  UNKNOWN_ENCODING = 0x1,
2650  TWO_BYTE_ENCODING = 0x0,
2651  ONE_BYTE_ENCODING = 0x8
2652  };
2656  int Length() const;
2657 
2662  int Utf8Length(Isolate* isolate) const;
2663 
2670  bool IsOneByte() const;
2671 
2677  bool ContainsOnlyOneByte() const;
2678 
2705  NO_OPTIONS = 0,
2706  HINT_MANY_WRITES_EXPECTED = 1,
2707  NO_NULL_TERMINATION = 2,
2708  PRESERVE_ONE_BYTE_NULL = 4,
2709  // Used by WriteUtf8 to replace orphan surrogate code units with the
2710  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2711  // output.
2712  REPLACE_INVALID_UTF8 = 8
2713  };
2714 
2715  // 16-bit character codes.
2716  int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
2717  int options = NO_OPTIONS) const;
2718  // One byte characters.
2719  int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
2720  int length = -1, int options = NO_OPTIONS) const;
2721  // UTF-8 encoded characters.
2722  int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
2723  int* nchars_ref = NULL, int options = NO_OPTIONS) const;
2724 
2728  V8_INLINE static Local<String> Empty(Isolate* isolate);
2729 
2733  bool IsExternal() const;
2734 
2738  bool IsExternalOneByte() const;
2739 
2741  public:
2743 
2744  virtual bool IsCompressible() const { return false; }
2745 
2746  protected:
2748 
2755  virtual void Dispose() { delete this; }
2756 
2757  // Disallow copying and assigning.
2759  void operator=(const ExternalStringResourceBase&) = delete;
2760 
2761  private:
2762  friend class internal::Heap;
2763  friend class v8::String;
2764  };
2765 
2773  : public ExternalStringResourceBase {
2774  public:
2780 
2784  virtual const uint16_t* data() const = 0;
2785 
2789  virtual size_t length() const = 0;
2790 
2791  protected:
2793  };
2794 
2806  : public ExternalStringResourceBase {
2807  public:
2814  virtual const char* data() const = 0;
2816  virtual size_t length() const = 0;
2817  protected:
2819  };
2820 
2826  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2827  Encoding* encoding_out) const;
2828 
2833  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2834 
2839  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2840 
2841  V8_INLINE static String* Cast(v8::Value* obj);
2842 
2843  // TODO(dcarney): remove with deprecation of New functions.
2845  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2846  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2847  };
2848 
2850  static V8_DEPRECATE_SOON(
2851  "Use maybe version",
2852  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2853  NewStringType type = kNormalString,
2854  int length = -1));
2855 
2858  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2859  Isolate* isolate, const char* data, v8::NewStringType type,
2860  int length = -1);
2861 
2864  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2865  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2866  int length = -1);
2867 
2869  static V8_DEPRECATE_SOON(
2870  "Use maybe version",
2871  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2872  NewStringType type = kNormalString,
2873  int length = -1));
2874 
2877  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2878  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2879  int length = -1);
2880 
2885  static Local<String> Concat(Isolate* isolate, Local<String> left,
2886  Local<String> right);
2887 
2896  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2897  Isolate* isolate, ExternalStringResource* resource);
2898 
2908  bool MakeExternal(ExternalStringResource* resource);
2909 
2918  static V8_DEPRECATE_SOON(
2919  "Use maybe version",
2920  Local<String> NewExternal(Isolate* isolate,
2921  ExternalOneByteStringResource* resource));
2922  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2923  Isolate* isolate, ExternalOneByteStringResource* resource);
2924 
2934  bool MakeExternal(ExternalOneByteStringResource* resource);
2935 
2939  bool CanMakeExternal();
2940 
2944  bool StringEquals(Local<String> str);
2945 
2954  public:
2955  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2956  ~Utf8Value();
2957  char* operator*() { return str_; }
2958  const char* operator*() const { return str_; }
2959  int length() const { return length_; }
2960 
2961  // Disallow copying and assigning.
2962  Utf8Value(const Utf8Value&) = delete;
2963  void operator=(const Utf8Value&) = delete;
2964 
2965  private:
2966  char* str_;
2967  int length_;
2968  };
2969 
2977  public:
2978  Value(Isolate* isolate, Local<v8::Value> obj);
2979  ~Value();
2980  uint16_t* operator*() { return str_; }
2981  const uint16_t* operator*() const { return str_; }
2982  int length() const { return length_; }
2983 
2984  // Disallow copying and assigning.
2985  Value(const Value&) = delete;
2986  void operator=(const Value&) = delete;
2987 
2988  private:
2989  uint16_t* str_;
2990  int length_;
2991  };
2992 
2993  private:
2994  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2995  Encoding encoding) const;
2996  void VerifyExternalStringResource(ExternalStringResource* val) const;
2997  ExternalStringResource* GetExternalStringResourceSlow() const;
2998  ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
2999  String::Encoding* encoding_out) const;
3000  const ExternalOneByteStringResource* GetExternalOneByteStringResourceSlow()
3001  const;
3002 
3003  static void CheckCast(v8::Value* obj);
3004 };
3005 
3006 
3010 class V8_EXPORT Symbol : public Name {
3011  public:
3015  Local<Value> Name() const;
3016 
3020  static Local<Symbol> New(Isolate* isolate,
3021  Local<String> name = Local<String>());
3022 
3030  static Local<Symbol> For(Isolate *isolate, Local<String> name);
3031 
3036  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
3037 
3038  // Well-known symbols
3039  static Local<Symbol> GetHasInstance(Isolate* isolate);
3040  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
3041  static Local<Symbol> GetIterator(Isolate* isolate);
3042  static Local<Symbol> GetMatch(Isolate* isolate);
3043  static Local<Symbol> GetReplace(Isolate* isolate);
3044  static Local<Symbol> GetSearch(Isolate* isolate);
3045  static Local<Symbol> GetSplit(Isolate* isolate);
3046  static Local<Symbol> GetToPrimitive(Isolate* isolate);
3047  static Local<Symbol> GetToStringTag(Isolate* isolate);
3048  static Local<Symbol> GetUnscopables(Isolate* isolate);
3049 
3050  V8_INLINE static Symbol* Cast(Value* obj);
3051 
3052  private:
3053  Symbol();
3054  static void CheckCast(Value* obj);
3055 };
3056 
3057 
3063 class V8_EXPORT Private : public Data {
3064  public:
3068  Local<Value> Name() const;
3069 
3073  static Local<Private> New(Isolate* isolate,
3074  Local<String> name = Local<String>());
3075 
3085  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3086 
3087  V8_INLINE static Private* Cast(Data* data);
3088 
3089  private:
3090  Private();
3091 
3092  static void CheckCast(Data* that);
3093 };
3094 
3095 
3099 class V8_EXPORT Number : public Primitive {
3100  public:
3101  double Value() const;
3102  static Local<Number> New(Isolate* isolate, double value);
3103  V8_INLINE static Number* Cast(v8::Value* obj);
3104  private:
3105  Number();
3106  static void CheckCast(v8::Value* obj);
3107 };
3108 
3109 
3113 class V8_EXPORT Integer : public Number {
3114  public:
3115  static Local<Integer> New(Isolate* isolate, int32_t value);
3116  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3117  int64_t Value() const;
3118  V8_INLINE static Integer* Cast(v8::Value* obj);
3119  private:
3120  Integer();
3121  static void CheckCast(v8::Value* obj);
3122 };
3123 
3124 
3128 class V8_EXPORT Int32 : public Integer {
3129  public:
3130  int32_t Value() const;
3131  V8_INLINE static Int32* Cast(v8::Value* obj);
3132 
3133  private:
3134  Int32();
3135  static void CheckCast(v8::Value* obj);
3136 };
3137 
3138 
3142 class V8_EXPORT Uint32 : public Integer {
3143  public:
3144  uint32_t Value() const;
3145  V8_INLINE static Uint32* Cast(v8::Value* obj);
3146 
3147  private:
3148  Uint32();
3149  static void CheckCast(v8::Value* obj);
3150 };
3151 
3155 class V8_EXPORT BigInt : public Primitive {
3156  public:
3157  static Local<BigInt> New(Isolate* isolate, int64_t value);
3158  static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3166  static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
3167  int word_count, const uint64_t* words);
3168 
3175  uint64_t Uint64Value(bool* lossless = nullptr) const;
3176 
3182  int64_t Int64Value(bool* lossless = nullptr) const;
3183 
3188  int WordCount() const;
3189 
3198  void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
3199 
3200  V8_INLINE static BigInt* Cast(v8::Value* obj);
3201 
3202  private:
3203  BigInt();
3204  static void CheckCast(v8::Value* obj);
3205 };
3206 
3212  None = 0,
3214  ReadOnly = 1 << 0,
3216  DontEnum = 1 << 1,
3218  DontDelete = 1 << 2
3219 };
3220 
3226 typedef void (*AccessorGetterCallback)(
3227  Local<String> property,
3228  const PropertyCallbackInfo<Value>& info);
3230  Local<Name> property,
3231  const PropertyCallbackInfo<Value>& info);
3232 
3233 
3234 typedef void (*AccessorSetterCallback)(
3235  Local<String> property,
3236  Local<Value> value,
3237  const PropertyCallbackInfo<void>& info);
3239  Local<Name> property,
3240  Local<Value> value,
3241  const PropertyCallbackInfo<void>& info);
3242 
3243 
3254  DEFAULT = 0,
3256  ALL_CAN_WRITE = 1 << 1,
3258 };
3259 
3270 };
3271 
3280 
3289 
3295 
3301 
3306 
3310 class V8_EXPORT Object : public Value {
3311  public:
3312  V8_DEPRECATE_SOON("Use maybe version",
3313  bool Set(Local<Value> key, Local<Value> value));
3315  Local<Value> key, Local<Value> value);
3316 
3317  V8_DEPRECATE_SOON("Use maybe version",
3318  bool Set(uint32_t index, Local<Value> value));
3319  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3320  Local<Value> value);
3321 
3322  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3323  //
3324  // Defines a configurable, writable, enumerable property with the given value
3325  // on the object unless the property already exists and is not configurable
3326  // or the object is not extensible.
3327  //
3328  // Returns true on success.
3329  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3330  Local<Name> key,
3331  Local<Value> value);
3332  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3333  uint32_t index,
3334  Local<Value> value);
3335 
3336  // Implements DefineOwnProperty.
3337  //
3338  // In general, CreateDataProperty will be faster, however, does not allow
3339  // for specifying attributes.
3340  //
3341  // Returns true on success.
3342  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3343  Local<Context> context, Local<Name> key, Local<Value> value,
3344  PropertyAttribute attributes = None);
3345 
3346  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3347  //
3348  // The defineProperty function is used to add an own property or
3349  // update the attributes of an existing own property of an object.
3350  //
3351  // Both data and accessor descriptors can be used.
3352  //
3353  // In general, CreateDataProperty is faster, however, does not allow
3354  // for specifying attributes or an accessor descriptor.
3355  //
3356  // The PropertyDescriptor can change when redefining a property.
3357  //
3358  // Returns true on success.
3359  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3360  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3361 
3362  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3364  Local<Value> key);
3365 
3366  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3368  uint32_t index);
3369 
3375  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3376  Local<Context> context, Local<Value> key);
3377 
3381  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3382  Local<Context> context, Local<Name> key);
3383 
3384  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
3401  Local<Value> key);
3402 
3403  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3405  Local<Value> key);
3406 
3407  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3408 
3410  uint32_t index);
3411 
3415  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
3416  Local<Context> context, Local<Name> name,
3419  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3420  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3421 
3422  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3423  Local<Function> setter = Local<Function>(),
3424  PropertyAttribute attribute = None,
3425  AccessControl settings = DEFAULT);
3426 
3431  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3432  Local<Context> context, Local<Name> name,
3434  AccessorNameSetterCallback setter = nullptr,
3436  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3437 
3446  V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
3447  Local<Context> context, Local<Name> name,
3449  PropertyAttribute attributes = None,
3450  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3451 
3458  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3459  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3460  Local<Value> value);
3461  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3462  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3463 
3470  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3471  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3472  Local<Context> context);
3473  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3474  Local<Context> context, KeyCollectionMode mode,
3475  PropertyFilter property_filter, IndexFilter index_filter,
3477 
3483  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3484  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3485  Local<Context> context);
3486 
3493  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3494  Local<Context> context, PropertyFilter filter,
3496 
3502  Local<Value> GetPrototype();
3503 
3509  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3510  Local<Value> prototype);
3511 
3516  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3517 
3523  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3524  Local<Context> context);
3525 
3529  Local<String> GetConstructorName();
3530 
3534  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3535 
3537  int InternalFieldCount();
3538 
3541  const PersistentBase<Object>& object) {
3542  return object.val_->InternalFieldCount();
3543  }
3544 
3546  V8_INLINE Local<Value> GetInternalField(int index);
3547 
3549  void SetInternalField(int index, Local<Value> value);
3550 
3556  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3557 
3560  const PersistentBase<Object>& object, int index) {
3561  return object.val_->GetAlignedPointerFromInternalField(index);
3562  }
3563 
3569  void SetAlignedPointerInInternalField(int index, void* value);
3570  void SetAlignedPointerInInternalFields(int argc, int indices[],
3571  void* values[]);
3572 
3578  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3579  Local<Name> key);
3580  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3581  uint32_t index);
3582  V8_DEPRECATE_SOON("Use maybe version",
3583  bool HasRealNamedProperty(Local<String> key));
3597  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3598  Local<Name> key);
3599  V8_DEPRECATE_SOON("Use maybe version",
3600  bool HasRealIndexedProperty(uint32_t index));
3601  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3602  Local<Context> context, uint32_t index);
3603  V8_DEPRECATE_SOON("Use maybe version",
3604  bool HasRealNamedCallbackProperty(Local<String> key));
3605  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3606  Local<Context> context, Local<Name> key);
3607 
3612  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3613  Local<Context> context, Local<Name> key);
3614 
3621  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3622  Local<Name> key);
3623 
3629  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3630  Local<Context> context, Local<Name> key);
3631 
3637  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3638  Local<Context> context, Local<Name> key);
3639 
3641  bool HasNamedLookupInterceptor();
3642 
3644  bool HasIndexedLookupInterceptor();
3645 
3653  int GetIdentityHash();
3654 
3659  // TODO(dcarney): take an isolate and optionally bail out?
3660  Local<Object> Clone();
3661 
3665  Local<Context> CreationContext();
3666 
3669  const PersistentBase<Object>& object) {
3670  return object.val_->CreationContext();
3671  }
3672 
3678  bool IsCallable();
3679 
3683  bool IsConstructor();
3684 
3690  Local<Value> recv,
3691  int argc,
3692  Local<Value> argv[]);
3693 
3699  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3700  Local<Context> context, int argc, Local<Value> argv[]);
3701 
3705  Isolate* GetIsolate();
3706 
3716  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3717 
3718  static Local<Object> New(Isolate* isolate);
3719 
3720  V8_INLINE static Object* Cast(Value* obj);
3721 
3722  private:
3723  Object();
3724  static void CheckCast(Value* obj);
3725  Local<Value> SlowGetInternalField(int index);
3726  void* SlowGetAlignedPointerFromInternalField(int index);
3727 };
3728 
3729 
3733 class V8_EXPORT Array : public Object {
3734  public:
3735  uint32_t Length() const;
3736 
3741  static Local<Array> New(Isolate* isolate, int length = 0);
3742 
3743  V8_INLINE static Array* Cast(Value* obj);
3744  private:
3745  Array();
3746  static void CheckCast(Value* obj);
3747 };
3748 
3749 
3753 class V8_EXPORT Map : public Object {
3754  public:
3755  size_t Size() const;
3756  void Clear();
3758  Local<Value> key);
3760  Local<Value> key,
3761  Local<Value> value);
3763  Local<Value> key);
3765  Local<Value> key);
3766 
3771  Local<Array> AsArray() const;
3772 
3776  static Local<Map> New(Isolate* isolate);
3777 
3778  V8_INLINE static Map* Cast(Value* obj);
3779 
3780  private:
3781  Map();
3782  static void CheckCast(Value* obj);
3783 };
3784 
3785 
3789 class V8_EXPORT Set : public Object {
3790  public:
3791  size_t Size() const;
3792  void Clear();
3794  Local<Value> key);
3796  Local<Value> key);
3798  Local<Value> key);
3799 
3803  Local<Array> AsArray() const;
3804 
3808  static Local<Set> New(Isolate* isolate);
3809 
3810  V8_INLINE static Set* Cast(Value* obj);
3811 
3812  private:
3813  Set();
3814  static void CheckCast(Value* obj);
3815 };
3816 
3817 
3818 template<typename T>
3819 class ReturnValue {
3820  public:
3821  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3822  : value_(that.value_) {
3823  TYPE_CHECK(T, S);
3824  }
3825  // Local setters
3826  template <typename S>
3827  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3828  void Set(const Persistent<S>& handle));
3829  template <typename S>
3830  V8_INLINE void Set(const Global<S>& handle);
3831  template <typename S>
3832  V8_INLINE void Set(const Local<S> handle);
3833  // Fast primitive setters
3834  V8_INLINE void Set(bool value);
3835  V8_INLINE void Set(double i);
3836  V8_INLINE void Set(int32_t i);
3837  V8_INLINE void Set(uint32_t i);
3838  // Fast JS primitive setters
3839  V8_INLINE void SetNull();
3840  V8_INLINE void SetUndefined();
3841  V8_INLINE void SetEmptyString();
3842  // Convenience getter for Isolate
3843  V8_INLINE Isolate* GetIsolate() const;
3844 
3845  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3846  template <typename S>
3847  V8_INLINE void Set(S* whatever);
3848 
3849  // Getter. Creates a new Local<> so it comes with a certain performance
3850  // hit. If the ReturnValue was not yet set, this will return the undefined
3851  // value.
3852  V8_INLINE Local<Value> Get() const;
3853 
3854  private:
3855  template<class F> friend class ReturnValue;
3856  template<class F> friend class FunctionCallbackInfo;
3857  template<class F> friend class PropertyCallbackInfo;
3858  template <class F, class G, class H>
3860  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3861  V8_INLINE internal::Object* GetDefaultValue();
3862  V8_INLINE explicit ReturnValue(internal::Object** slot);
3863  internal::Object** value_;
3864 };
3865 
3866 
3873 template<typename T>
3874 class FunctionCallbackInfo {
3875  public:
3877  V8_INLINE int Length() const;
3879  V8_INLINE Local<Value> operator[](int i) const;
3881  V8_INLINE Local<Object> This() const;
3892  V8_INLINE Local<Object> Holder() const;
3894  V8_INLINE Local<Value> NewTarget() const;
3896  V8_INLINE bool IsConstructCall() const;
3898  V8_INLINE Local<Value> Data() const;
3900  V8_INLINE Isolate* GetIsolate() const;
3902  V8_INLINE ReturnValue<T> GetReturnValue() const;
3903  // This shouldn't be public, but the arm compiler needs it.
3904  static const int kArgsLength = 6;
3905 
3906  protected:
3910  static const int kHolderIndex = 0;
3911  static const int kIsolateIndex = 1;
3912  static const int kReturnValueDefaultValueIndex = 2;
3913  static const int kReturnValueIndex = 3;
3914  static const int kDataIndex = 4;
3915  static const int kNewTargetIndex = 5;
3916 
3917  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3918  internal::Object** values, int length);
3919  internal::Object** implicit_args_;
3920  internal::Object** values_;
3921  int length_;
3922 };
3923 
3924 
3929 template<typename T>
3930 class PropertyCallbackInfo {
3931  public:
3935  V8_INLINE Isolate* GetIsolate() const;
3936 
3942  V8_INLINE Local<Value> Data() const;
3943 
3985  V8_INLINE Local<Object> This() const;
3986 
3996  V8_INLINE Local<Object> Holder() const;
3997 
4007 
4015  V8_INLINE bool ShouldThrowOnError() const;
4016 
4017  // This shouldn't be public, but the arm compiler needs it.
4018  static const int kArgsLength = 7;
4019 
4020  protected:
4021  friend class MacroAssembler;
4022  friend class internal::PropertyCallbackArguments;
4024  static const int kShouldThrowOnErrorIndex = 0;
4025  static const int kHolderIndex = 1;
4026  static const int kIsolateIndex = 2;
4027  static const int kReturnValueDefaultValueIndex = 3;
4028  static const int kReturnValueIndex = 4;
4029  static const int kDataIndex = 5;
4030  static const int kThisIndex = 6;
4031 
4032  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
4033  internal::Object** args_;
4034 };
4035 
4036 
4037 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
4038 
4040 
4044 class V8_EXPORT Function : public Object {
4045  public:
4050  static MaybeLocal<Function> New(
4051  Local<Context> context, FunctionCallback callback,
4052  Local<Value> data = Local<Value>(), int length = 0,
4054  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4055  static V8_DEPRECATE_SOON(
4056  "Use maybe version",
4057  Local<Function> New(Isolate* isolate, FunctionCallback callback,
4058  Local<Value> data = Local<Value>(), int length = 0));
4059 
4061  Local<Context> context, int argc, Local<Value> argv[]) const;
4062 
4064  Local<Context> context) const {
4065  return NewInstance(context, 0, nullptr);
4066  }
4067 
4073  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
4074  Local<Context> context, int argc, Local<Value> argv[],
4075  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4076 
4077  V8_DEPRECATE_SOON("Use maybe version",
4078  Local<Value> Call(Local<Value> recv, int argc,
4079  Local<Value> argv[]));
4081  Local<Value> recv, int argc,
4082  Local<Value> argv[]);
4083 
4084  void SetName(Local<String> name);
4085  Local<Value> GetName() const;
4086 
4093  Local<Value> GetInferredName() const;
4094 
4099  Local<Value> GetDebugName() const;
4100 
4105  Local<Value> GetDisplayName() const;
4106 
4111  int GetScriptLineNumber() const;
4116  int GetScriptColumnNumber() const;
4117 
4121  int ScriptId() const;
4122 
4127  Local<Value> GetBoundFunction() const;
4128 
4129  ScriptOrigin GetScriptOrigin() const;
4130  V8_INLINE static Function* Cast(Value* obj);
4131  static const int kLineOffsetNotFound;
4132 
4133  private:
4134  Function();
4135  static void CheckCast(Value* obj);
4136 };
4137 
4138 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4139 // The number of required internal fields can be defined by embedder.
4140 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4141 #endif
4142 
4146 class V8_EXPORT Promise : public Object {
4147  public:
4152  enum PromiseState { kPending, kFulfilled, kRejected };
4153 
4154  class V8_EXPORT Resolver : public Object {
4155  public:
4160  Local<Context> context);
4161 
4165  Local<Promise> GetPromise();
4166 
4172  Local<Value> value);
4173 
4175  Local<Value> value);
4176 
4177  V8_INLINE static Resolver* Cast(Value* obj);
4178 
4179  private:
4180  Resolver();
4181  static void CheckCast(Value* obj);
4182  };
4183 
4191  Local<Function> handler);
4192 
4194  Local<Function> handler);
4195 
4200  bool HasHandler();
4201 
4206  Local<Value> Result();
4207 
4211  PromiseState State();
4212 
4213  V8_INLINE static Promise* Cast(Value* obj);
4214 
4215  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4216 
4217  private:
4218  Promise();
4219  static void CheckCast(Value* obj);
4220 };
4221 
4251  public:
4252  // GenericDescriptor
4254 
4255  // DataDescriptor
4257 
4258  // DataDescriptor with writable property
4259  PropertyDescriptor(Local<Value> value, bool writable);
4260 
4261  // AccessorDescriptor
4263 
4264  ~PropertyDescriptor();
4265 
4266  Local<Value> value() const;
4267  bool has_value() const;
4268 
4269  Local<Value> get() const;
4270  bool has_get() const;
4271  Local<Value> set() const;
4272  bool has_set() const;
4273 
4274  void set_enumerable(bool enumerable);
4275  bool enumerable() const;
4276  bool has_enumerable() const;
4277 
4278  void set_configurable(bool configurable);
4279  bool configurable() const;
4280  bool has_configurable() const;
4281 
4282  bool writable() const;
4283  bool has_writable() const;
4284 
4285  struct PrivateData;
4286  PrivateData* get_private() const { return private_; }
4287 
4288  PropertyDescriptor(const PropertyDescriptor&) = delete;
4289  void operator=(const PropertyDescriptor&) = delete;
4290 
4291  private:
4292  PrivateData* private_;
4293 };
4294 
4299 class V8_EXPORT Proxy : public Object {
4300  public:
4301  Local<Value> GetTarget();
4302  Local<Value> GetHandler();
4303  bool IsRevoked();
4304  void Revoke();
4305 
4309  static MaybeLocal<Proxy> New(Local<Context> context,
4310  Local<Object> local_target,
4311  Local<Object> local_handler);
4312 
4313  V8_INLINE static Proxy* Cast(Value* obj);
4314 
4315  private:
4316  Proxy();
4317  static void CheckCast(Value* obj);
4318 };
4319 
4320 // TODO(mtrofin): rename WasmCompiledModule to WasmModuleObject, for
4321 // consistency with internal APIs.
4323  public:
4324  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
4325 
4326 // The COMMA macro allows us to use ',' inside of the V8_DEPRECATED macro.
4327 #define COMMA ,
4328  V8_DEPRECATED(
4329  "Use BufferReference.",
4330  typedef std::pair<const uint8_t * COMMA size_t> CallerOwnedBuffer);
4331 #undef COMMA
4332 
4337  const uint8_t* start;
4338  size_t size;
4339  BufferReference(const uint8_t* start, size_t size)
4340  : start(start), size(size) {}
4341  // Temporarily allow conversion to and from CallerOwnedBuffer.
4342  V8_DEPRECATED(
4343  "Use BufferReference directly.",
4344  inline BufferReference(CallerOwnedBuffer)); // NOLINT(runtime/explicit)
4345  V8_DEPRECATED("Use BufferReference directly.",
4346  inline operator CallerOwnedBuffer());
4347  };
4348 
4353  class TransferrableModule final {
4354  public:
4355  TransferrableModule(TransferrableModule&& src) = default;
4356  TransferrableModule(const TransferrableModule& src) = delete;
4357 
4358  TransferrableModule& operator=(TransferrableModule&& src) = default;
4359  TransferrableModule& operator=(const TransferrableModule& src) = delete;
4360 
4361  private:
4362  typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
4363  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
4364  friend class WasmCompiledModule;
4365  explicit TransferrableModule(SharedModule shared_module)
4366  : shared_module_(std::move(shared_module)) {}
4367  TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
4368  : serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
4369 
4370  SharedModule shared_module_;
4371  OwnedBuffer serialized_ = {nullptr, 0};
4372  OwnedBuffer wire_bytes_ = {nullptr, 0};
4373  };
4374 
4380  TransferrableModule GetTransferrableModule();
4381 
4386  static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
4387  Isolate* isolate, const TransferrableModule&);
4388 
4392  BufferReference GetWasmWireBytesRef();
4393  V8_DEPRECATED("Use GetWasmWireBytesRef version.",
4394  Local<String> GetWasmWireBytes());
4395 
4400  SerializedModule Serialize();
4401 
4406  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
4407  Isolate* isolate, BufferReference serialized_module,
4408  BufferReference wire_bytes);
4409  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
4410 
4411  private:
4412  static MaybeLocal<WasmCompiledModule> Deserialize(
4413  Isolate* isolate, BufferReference serialized_module,
4414  BufferReference wire_bytes);
4415  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
4416  const uint8_t* start,
4417  size_t length);
4418  static BufferReference AsReference(
4419  const TransferrableModule::OwnedBuffer& buff) {
4420  return {buff.first.get(), buff.second};
4421  }
4422 
4423  WasmCompiledModule();
4424  static void CheckCast(Value* obj);
4425 };
4426 
4427 // TODO(clemensh): Remove after M70 branch.
4429  WasmCompiledModule::CallerOwnedBuffer buf)
4430  : BufferReference(buf.first, buf.second) {}
4431 WasmCompiledModule::BufferReference::
4432 operator WasmCompiledModule::CallerOwnedBuffer() {
4433  return {start, size};
4434 }
4435 
4443  public:
4444  class WasmStreamingImpl;
4445 
4446  WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
4447 
4448  ~WasmStreaming();
4449 
4454  void OnBytesReceived(const uint8_t* bytes, size_t size);
4455 
4461  void Finish();
4462 
4468  void Abort(MaybeLocal<Value> exception);
4469 
4475  static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
4476  Local<Value> value);
4477 
4478  private:
4479  std::unique_ptr<WasmStreamingImpl> impl_;
4480 };
4481 
4482 // TODO(mtrofin): when streaming compilation is done, we can rename this
4483 // to simply WasmModuleObjectBuilder
4485  public:
4486  explicit WasmModuleObjectBuilderStreaming(Isolate* isolate);
4490  void OnBytesReceived(const uint8_t*, size_t size);
4491  void Finish();
4497  void Abort(MaybeLocal<Value> exception);
4498  Local<Promise> GetPromise();
4499 
4501 
4502  private:
4504  delete;
4506  default;
4508  const WasmModuleObjectBuilderStreaming&) = delete;
4510  WasmModuleObjectBuilderStreaming&&) = default;
4511  Isolate* isolate_ = nullptr;
4512 
4513 #if V8_CC_MSVC
4514 
4522 #else
4523  Persistent<Promise> promise_;
4524 #endif
4525  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4526 };
4527 
4528 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4529 // The number of required internal fields can be defined by embedder.
4530 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4531 #endif
4532 
4533 
4535 
4536 
4540 class V8_EXPORT ArrayBuffer : public Object {
4541  public:
4557  class V8_EXPORT Allocator { // NOLINT
4558  public:
4559  virtual ~Allocator() {}
4560 
4565  virtual void* Allocate(size_t length) = 0;
4566 
4571  virtual void* AllocateUninitialized(size_t length) = 0;
4572 
4577  virtual void Free(void* data, size_t length) = 0;
4578 
4584  enum class AllocationMode { kNormal, kReservation };
4585 
4592  static Allocator* NewDefaultAllocator();
4593  };
4594 
4604  class V8_EXPORT Contents { // NOLINT
4605  public:
4606  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
4607 
4609  : data_(nullptr),
4610  byte_length_(0),
4611  allocation_base_(nullptr),
4612  allocation_length_(0),
4613  allocation_mode_(Allocator::AllocationMode::kNormal),
4614  deleter_(nullptr),
4615  deleter_data_(nullptr) {}
4616 
4617  void* AllocationBase() const { return allocation_base_; }
4618  size_t AllocationLength() const { return allocation_length_; }
4620  return allocation_mode_;
4621  }
4622 
4623  void* Data() const { return data_; }
4624  size_t ByteLength() const { return byte_length_; }
4625  DeleterCallback Deleter() const { return deleter_; }
4626  void* DeleterData() const { return deleter_data_; }
4627 
4628  private:
4629  Contents(void* data, size_t byte_length, void* allocation_base,
4630  size_t allocation_length,
4631  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
4632  void* deleter_data);
4633 
4634  void* data_;
4635  size_t byte_length_;
4636  void* allocation_base_;
4637  size_t allocation_length_;
4638  Allocator::AllocationMode allocation_mode_;
4639  DeleterCallback deleter_;
4640  void* deleter_data_;
4641 
4642  friend class ArrayBuffer;
4643  };
4644 
4645 
4649  size_t ByteLength() const;
4650 
4657  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4658 
4668  static Local<ArrayBuffer> New(
4669  Isolate* isolate, void* data, size_t byte_length,
4671 
4676  bool IsExternal() const;
4677 
4681  bool IsNeuterable() const;
4682 
4689  void Neuter();
4690 
4701  Contents Externalize();
4702 
4711  Contents GetContents();
4712 
4713  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4714 
4715  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4716  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4717 
4718  private:
4719  ArrayBuffer();
4720  static void CheckCast(Value* obj);
4721 };
4722 
4723 
4724 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4725 // The number of required internal fields can be defined by embedder.
4726 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4727 #endif
4728 
4729 
4735  public:
4739  Local<ArrayBuffer> Buffer();
4743  size_t ByteOffset();
4747  size_t ByteLength();
4748 
4758  size_t CopyContents(void* dest, size_t byte_length);
4759 
4764  bool HasBuffer() const;
4765 
4766  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4767 
4768  static const int kInternalFieldCount =
4770  static const int kEmbedderFieldCount =
4772 
4773  private:
4774  ArrayBufferView();
4775  static void CheckCast(Value* obj);
4776 };
4777 
4778 
4784  public:
4785  /*
4786  * The largest typed array size that can be constructed using New.
4787  */
4788  static constexpr size_t kMaxLength = internal::kSmiMaxValue;
4789 
4794  size_t Length();
4795 
4796  V8_INLINE static TypedArray* Cast(Value* obj);
4797 
4798  private:
4799  TypedArray();
4800  static void CheckCast(Value* obj);
4801 };
4802 
4803 
4808  public:
4809  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4810  size_t byte_offset, size_t length);
4811  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4812  size_t byte_offset, size_t length);
4813  V8_INLINE static Uint8Array* Cast(Value* obj);
4814 
4815  private:
4816  Uint8Array();
4817  static void CheckCast(Value* obj);
4818 };
4819 
4820 
4825  public:
4826  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4827  size_t byte_offset, size_t length);
4829  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4830  size_t length);
4831  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4832 
4833  private:
4835  static void CheckCast(Value* obj);
4836 };
4837 
4842  public:
4843  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4844  size_t byte_offset, size_t length);
4845  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4846  size_t byte_offset, size_t length);
4847  V8_INLINE static Int8Array* Cast(Value* obj);
4848 
4849  private:
4850  Int8Array();
4851  static void CheckCast(Value* obj);
4852 };
4853 
4854 
4859  public:
4860  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4861  size_t byte_offset, size_t length);
4862  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4863  size_t byte_offset, size_t length);
4864  V8_INLINE static Uint16Array* Cast(Value* obj);
4865 
4866  private:
4867  Uint16Array();
4868  static void CheckCast(Value* obj);
4869 };
4870 
4871 
4876  public:
4877  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4878  size_t byte_offset, size_t length);
4879  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4880  size_t byte_offset, size_t length);
4881  V8_INLINE static Int16Array* Cast(Value* obj);
4882 
4883  private:
4884  Int16Array();
4885  static void CheckCast(Value* obj);
4886 };
4887 
4888 
4893  public:
4894  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4895  size_t byte_offset, size_t length);
4896  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4897  size_t byte_offset, size_t length);
4898  V8_INLINE static Uint32Array* Cast(Value* obj);
4899 
4900  private:
4901  Uint32Array();
4902  static void CheckCast(Value* obj);
4903 };
4904 
4905 
4910  public:
4911  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4912  size_t byte_offset, size_t length);
4913  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4914  size_t byte_offset, size_t length);
4915  V8_INLINE static Int32Array* Cast(Value* obj);
4916 
4917  private:
4918  Int32Array();
4919  static void CheckCast(Value* obj);
4920 };
4921 
4922 
4927  public:
4928  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4929  size_t byte_offset, size_t length);
4930  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4931  size_t byte_offset, size_t length);
4932  V8_INLINE static Float32Array* Cast(Value* obj);
4933 
4934  private:
4935  Float32Array();
4936  static void CheckCast(Value* obj);
4937 };
4938 
4939 
4944  public:
4945  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4946  size_t byte_offset, size_t length);
4947  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4948  size_t byte_offset, size_t length);
4949  V8_INLINE static Float64Array* Cast(Value* obj);
4950 
4951  private:
4952  Float64Array();
4953  static void CheckCast(Value* obj);
4954 };
4955 
4960  public:
4961  static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
4962  size_t byte_offset, size_t length);
4963  static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4964  size_t byte_offset, size_t length);
4965  V8_INLINE static BigInt64Array* Cast(Value* obj);
4966 
4967  private:
4968  BigInt64Array();
4969  static void CheckCast(Value* obj);
4970 };
4971 
4976  public:
4977  static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
4978  size_t byte_offset, size_t length);
4979  static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4980  size_t byte_offset, size_t length);
4981  V8_INLINE static BigUint64Array* Cast(Value* obj);
4982 
4983  private:
4984  BigUint64Array();
4985  static void CheckCast(Value* obj);
4986 };
4987 
4992  public:
4993  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
4994  size_t byte_offset, size_t length);
4995  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
4996  size_t byte_offset, size_t length);
4997  V8_INLINE static DataView* Cast(Value* obj);
4998 
4999  private:
5000  DataView();
5001  static void CheckCast(Value* obj);
5002 };
5003 
5004 
5010  public:
5022  class V8_EXPORT Contents { // NOLINT
5023  public:
5025  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
5026 
5028  : data_(nullptr),
5029  byte_length_(0),
5030  allocation_base_(nullptr),
5031  allocation_length_(0),
5032  allocation_mode_(Allocator::AllocationMode::kNormal),
5033  deleter_(nullptr),
5034  deleter_data_(nullptr) {}
5035 
5036  void* AllocationBase() const { return allocation_base_; }
5037  size_t AllocationLength() const { return allocation_length_; }
5039  return allocation_mode_;
5040  }
5041 
5042  void* Data() const { return data_; }
5043  size_t ByteLength() const { return byte_length_; }
5044  DeleterCallback Deleter() const { return deleter_; }
5045  void* DeleterData() const { return deleter_data_; }
5046 
5047  private:
5048  Contents(void* data, size_t byte_length, void* allocation_base,
5049  size_t allocation_length,
5050  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
5051  void* deleter_data);
5052 
5053  void* data_;
5054  size_t byte_length_;
5055  void* allocation_base_;
5056  size_t allocation_length_;
5057  Allocator::AllocationMode allocation_mode_;
5058  DeleterCallback deleter_;
5059  void* deleter_data_;
5060 
5061  friend class SharedArrayBuffer;
5062  };
5063 
5067  size_t ByteLength() const;
5068 
5075  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
5076 
5084  Isolate* isolate, void* data, size_t byte_length,
5086 
5091  bool IsExternal() const;
5092 
5105  Contents Externalize();
5106 
5119  Contents GetContents();
5120 
5121  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
5122 
5123  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5124 
5125  private:
5127  static void CheckCast(Value* obj);
5128 };
5129 
5130 
5134 class V8_EXPORT Date : public Object {
5135  public:
5136  static V8_DEPRECATE_SOON("Use maybe version.",
5137  Local<Value> New(Isolate* isolate, double time));
5139  double time);
5140 
5145  double ValueOf() const;
5146 
5147  V8_INLINE static Date* Cast(Value* obj);
5148 
5161  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
5162 
5163  private:
5164  static void CheckCast(Value* obj);
5165 };
5166 
5167 
5172  public:
5173  static Local<Value> New(Isolate* isolate, double value);
5174 
5175  double ValueOf() const;
5176 
5177  V8_INLINE static NumberObject* Cast(Value* obj);
5178 
5179  private:
5180  static void CheckCast(Value* obj);
5181 };
5182 
5187  public:
5188  static Local<Value> New(Isolate* isolate, int64_t value);
5189 
5190  Local<BigInt> ValueOf() const;
5191 
5192  V8_INLINE static BigIntObject* Cast(Value* obj);
5193 
5194  private:
5195  static void CheckCast(Value* obj);
5196 };
5197 
5202  public:
5203  static Local<Value> New(Isolate* isolate, bool value);
5204 
5205  bool ValueOf() const;
5206 
5207  V8_INLINE static BooleanObject* Cast(Value* obj);
5208 
5209  private:
5210  static void CheckCast(Value* obj);
5211 };
5212 
5213 
5218  public:
5219  static Local<Value> New(Isolate* isolate, Local<String> value);
5220 
5221  Local<String> ValueOf() const;
5222 
5223  V8_INLINE static StringObject* Cast(Value* obj);
5224 
5225  private:
5226  static void CheckCast(Value* obj);
5227 };
5228 
5229 
5234  public:
5235  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
5236 
5237  Local<Symbol> ValueOf() const;
5238 
5239  V8_INLINE static SymbolObject* Cast(Value* obj);
5240 
5241  private:
5242  static void CheckCast(Value* obj);
5243 };
5244 
5245 
5249 class V8_EXPORT RegExp : public Object {
5250  public:
5255  enum Flags {
5256  kNone = 0,
5257  kGlobal = 1 << 0,
5258  kIgnoreCase = 1 << 1,
5259  kMultiline = 1 << 2,
5260  kSticky = 1 << 3,
5261  kUnicode = 1 << 4,
5262  kDotAll = 1 << 5,
5263  };
5264 
5276  Local<String> pattern,
5277  Flags flags);
5278 
5283  Local<String> GetSource() const;
5284 
5288  Flags GetFlags() const;
5289 
5290  V8_INLINE static RegExp* Cast(Value* obj);
5291 
5292  private:
5293  static void CheckCast(Value* obj);
5294 };
5295 
5296 
5301 class V8_EXPORT External : public Value {
5302  public:
5303  static Local<External> New(Isolate* isolate, void* value);
5304  V8_INLINE static External* Cast(Value* obj);
5305  void* Value() const;
5306  private:
5307  static void CheckCast(v8::Value* obj);
5308 };
5309 
5310 #define V8_INTRINSICS_LIST(F) \
5311  F(ArrayProto_entries, array_entries_iterator) \
5312  F(ArrayProto_forEach, array_for_each_iterator) \
5313  F(ArrayProto_keys, array_keys_iterator) \
5314  F(ArrayProto_values, array_values_iterator) \
5315  F(ErrorPrototype, initial_error_prototype) \
5316  F(IteratorPrototype, initial_iterator_prototype)
5317 
5319 #define V8_DECL_INTRINSIC(name, iname) k##name,
5321 #undef V8_DECL_INTRINSIC
5322 };
5323 
5324 
5325 // --- Templates ---
5326 
5327 
5331 class V8_EXPORT Template : public Data {
5332  public:
5338  void Set(Local<Name> name, Local<Data> value,
5339  PropertyAttribute attributes = None);
5340  void SetPrivate(Local<Private> name, Local<Data> value,
5341  PropertyAttribute attributes = None);
5342  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5343 
5344  void SetAccessorProperty(
5345  Local<Name> name,
5348  PropertyAttribute attribute = None,
5349  AccessControl settings = DEFAULT);
5350 
5378  void SetNativeDataProperty(
5380  AccessorSetterCallback setter = 0,
5381  // TODO(dcarney): gcc can't handle Local below
5384  AccessControl settings = DEFAULT,
5385  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5386  void SetNativeDataProperty(
5388  AccessorNameSetterCallback setter = 0,
5389  // TODO(dcarney): gcc can't handle Local below
5392  AccessControl settings = DEFAULT,
5393  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5394 
5399  void SetLazyDataProperty(
5402  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5403 
5408  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5409  PropertyAttribute attribute = None);
5410 
5411  private:
5412  Template();
5413 
5414  friend class ObjectTemplate;
5415  friend class FunctionTemplate;
5416 };
5417 
5418 // TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
5419 // NamedPropertyFooCallback.
5420 
5458  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5459 
5482  Local<Name> property, Local<Value> value,
5483  const PropertyCallbackInfo<Value>& info);
5484 
5507  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5508 
5531  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5532 
5540  const PropertyCallbackInfo<Array>& info);
5541 
5563  Local<Name> property, const PropertyDescriptor& desc,
5564  const PropertyCallbackInfo<Value>& info);
5565 
5586  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5587 
5592  uint32_t index,
5593  const PropertyCallbackInfo<Value>& info);
5594 
5599  uint32_t index,
5600  Local<Value> value,
5601  const PropertyCallbackInfo<Value>& info);
5602 
5607  uint32_t index,
5608  const PropertyCallbackInfo<Integer>& info);
5609 
5614  uint32_t index,
5615  const PropertyCallbackInfo<Boolean>& info);
5616 
5624  const PropertyCallbackInfo<Array>& info);
5625 
5630  uint32_t index, const PropertyDescriptor& desc,
5631  const PropertyCallbackInfo<Value>& info);
5632 
5637  uint32_t index, const PropertyCallbackInfo<Value>& info);
5638 
5648 };
5649 
5650 
5655 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5656  Local<Object> accessed_object,
5657  Local<Value> data);
5658 
5760  public:
5763  Isolate* isolate, FunctionCallback callback = 0,
5765  Local<Signature> signature = Local<Signature>(), int length = 0,
5767  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5768 
5770  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5771  size_t index);
5772 
5776  static Local<FunctionTemplate> NewWithCache(
5777  Isolate* isolate, FunctionCallback callback,
5778  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5779  Local<Signature> signature = Local<Signature>(), int length = 0,
5780  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5781 
5783  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5785  Local<Context> context);
5786 
5794  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5795 
5801  void SetCallHandler(
5803  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5804 
5806  void SetLength(int length);
5807 
5809  Local<ObjectTemplate> InstanceTemplate();
5810 
5816  void Inherit(Local<FunctionTemplate> parent);
5817 
5822  Local<ObjectTemplate> PrototypeTemplate();
5823 
5830  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5831 
5837  void SetClassName(Local<String> name);
5838 
5839 
5844  void SetAcceptAnyReceiver(bool value);
5845 
5858  void SetHiddenPrototype(bool value);
5859 
5864  void ReadOnlyPrototype();
5865 
5870  void RemovePrototype();
5871 
5876  bool HasInstance(Local<Value> object);
5877 
5879 
5880  private:
5881  FunctionTemplate();
5882 
5883  static void CheckCast(Data* that);
5884  friend class Context;
5885  friend class ObjectTemplate;
5886 };
5887 
5896  kNone = 0,
5897 
5901  kAllCanRead = 1,
5902 
5907  kNonMasking = 1 << 1,
5908 
5913  kOnlyInterceptStrings = 1 << 2,
5914 
5918  kHasNoSideEffect = 1 << 3,
5919 };
5920 
5932  : getter(getter),
5933  setter(setter),
5934  query(query),
5935  deleter(deleter),
5936  enumerator(enumerator),
5937  definer(definer),
5938  descriptor(descriptor),
5939  data(data),
5940  flags(flags) {}
5941 
5951  : getter(getter),
5952  setter(setter),
5953  query(query),
5954  deleter(deleter),
5955  enumerator(enumerator),
5956  definer(0),
5957  descriptor(0),
5958  data(data),
5959  flags(flags) {}
5960 
5970  : getter(getter),
5971  setter(setter),
5972  query(0),
5973  deleter(deleter),
5974  enumerator(enumerator),
5975  definer(definer),
5976  descriptor(descriptor),
5977  data(data),
5978  flags(flags) {}
5979 
5989 };
5990 
5991 
6002  : getter(getter),
6003  setter(setter),
6004  query(query),
6005  deleter(deleter),
6006  enumerator(enumerator),
6007  definer(definer),
6008  descriptor(descriptor),
6009  data(data),
6010  flags(flags) {}
6011 
6014  IndexedPropertyGetterCallback getter = 0,
6015  IndexedPropertySetterCallback setter = 0,
6016  IndexedPropertyQueryCallback query = 0,
6017  IndexedPropertyDeleterCallback deleter = 0,
6018  IndexedPropertyEnumeratorCallback enumerator = 0,
6021  : getter(getter),
6022  setter(setter),
6023  query(query),
6024  deleter(deleter),
6025  enumerator(enumerator),
6026  definer(0),
6027  descriptor(0),
6028  data(data),
6029  flags(flags) {}
6030 
6040  : getter(getter),
6041  setter(setter),
6042  query(0),
6043  deleter(deleter),
6044  enumerator(enumerator),
6045  definer(definer),
6046  descriptor(descriptor),
6047  data(data),
6048  flags(flags) {}
6049 
6059 };
6060 
6061 
6069  public:
6071  static Local<ObjectTemplate> New(
6072  Isolate* isolate,
6074 
6076  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
6077  size_t index);
6078 
6080  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
6082 
6112  void SetAccessor(
6115  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
6117  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
6118  void SetAccessor(
6121  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
6123  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
6124 
6136  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
6137 
6154  // TODO(dcarney): deprecate
6157  IndexedPropertySetterCallback setter = 0,
6158  IndexedPropertyQueryCallback query = 0,
6159  IndexedPropertyDeleterCallback deleter = 0,
6160  IndexedPropertyEnumeratorCallback enumerator = 0,
6162  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
6163  deleter, enumerator, data));
6164  }
6165 
6176  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
6177 
6184  void SetCallAsFunctionHandler(FunctionCallback callback,
6186 
6195  void MarkAsUndetectable();
6196 
6205  void SetAccessCheckCallback(AccessCheckCallback callback,
6207 
6214  void SetAccessCheckCallbackAndHandler(
6215  AccessCheckCallback callback,
6216  const NamedPropertyHandlerConfiguration& named_handler,
6217  const IndexedPropertyHandlerConfiguration& indexed_handler,
6219 
6224  int InternalFieldCount();
6225 
6230  void SetInternalFieldCount(int value);
6231 
6235  bool IsImmutableProto();
6236 
6241  void SetImmutableProto();
6242 
6244 
6245  private:
6246  ObjectTemplate();
6247  static Local<ObjectTemplate> New(internal::Isolate* isolate,
6248  Local<FunctionTemplate> constructor);
6249  static void CheckCast(Data* that);
6250  friend class FunctionTemplate;
6251 };
6252 
6261 class V8_EXPORT Signature : public Data {
6262  public:
6263  static Local<Signature> New(
6264  Isolate* isolate,
6266 
6267  V8_INLINE static Signature* Cast(Data* data);
6268 
6269  private:
6270  Signature();
6271 
6272  static void CheckCast(Data* that);
6273 };
6274 
6275 
6281  public:
6283  Isolate* isolate,
6285 
6287 
6288  private:
6290 
6291  static void CheckCast(Data* that);
6292 };
6293 
6294 
6295 // --- Extensions ---
6296 V8_DEPRECATE_SOON("Implementation detail", class)
6298  : public String::ExternalOneByteStringResource {
6299  public:
6300  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
6302  : data_(data), length_(length) {}
6303  const char* data() const { return data_; }
6304  size_t length() const { return length_; }
6305 
6306  private:
6307  const char* data_;
6308  size_t length_;
6309 };
6310 
6314 class V8_EXPORT Extension { // NOLINT
6315  public:
6316  // Note that the strings passed into this constructor must live as long
6317  // as the Extension itself.
6318  Extension(const char* name,
6319  const char* source = 0,
6320  int dep_count = 0,
6321  const char** deps = 0,
6322  int source_length = -1);
6323  virtual ~Extension() { delete source_; }
6324  virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
6325  Isolate* isolate, Local<String> name) {
6326  return Local<FunctionTemplate>();
6327  }
6328 
6329  const char* name() const { return name_; }
6330  size_t source_length() const { return source_length_; }
6331  const String::ExternalOneByteStringResource* source() const {
6332  return source_;
6333  }
6334  int dependency_count() { return dep_count_; }
6335  const char** dependencies() { return deps_; }
6336  void set_auto_enable(bool value) { auto_enable_ = value; }
6337  bool auto_enable() { return auto_enable_; }
6338 
6339  // Disallow copying and assigning.
6340  Extension(const Extension&) = delete;
6341  void operator=(const Extension&) = delete;
6342 
6343  private:
6344  const char* name_;
6345  size_t source_length_; // expected to initialize before source_
6346  String::ExternalOneByteStringResource* source_;
6347  int dep_count_;
6348  const char** deps_;
6349  bool auto_enable_;
6350 };
6351 
6352 
6353 void V8_EXPORT RegisterExtension(Extension* extension);
6354 
6355 
6356 // --- Statics ---
6357 
6358 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6359 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6360 V8_INLINE Local<Boolean> True(Isolate* isolate);
6361 V8_INLINE Local<Boolean> False(Isolate* isolate);
6362 
6377 class V8_EXPORT ResourceConstraints {
6378  public:
6379  ResourceConstraints();
6380 
6390  void ConfigureDefaults(uint64_t physical_memory,
6391  uint64_t virtual_memory_limit);
6392 
6393  // Returns the max semi-space size in MB.
6394  V8_DEPRECATE_SOON("Use max_semi_space_size_in_kb()",
6395  size_t max_semi_space_size()) {
6396  return max_semi_space_size_in_kb_ / 1024;
6397  }
6398 
6399  // Sets the max semi-space size in MB.
6400  V8_DEPRECATE_SOON("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6401  void set_max_semi_space_size(size_t limit_in_mb)) {
6402  max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6403  }
6404 
6405  // Returns the max semi-space size in KB.
6406  size_t max_semi_space_size_in_kb() const {
6407  return max_semi_space_size_in_kb_;
6408  }
6409 
6410  // Sets the max semi-space size in KB.
6411  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6412  max_semi_space_size_in_kb_ = limit_in_kb;
6413  }
6414 
6415  size_t max_old_space_size() const { return max_old_space_size_; }
6416  void set_max_old_space_size(size_t limit_in_mb) {
6417  max_old_space_size_ = limit_in_mb;
6418  }
6419  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6420  size_t max_executable_size() const) {
6421  return max_executable_size_;
6422  }
6423  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6424  void set_max_executable_size(size_t limit_in_mb)) {
6425  max_executable_size_ = limit_in_mb;
6426  }
6427  uint32_t* stack_limit() const { return stack_limit_; }
6428  // Sets an address beyond which the VM's stack may not grow.
6429  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6430  size_t code_range_size() const { return code_range_size_; }
6431  void set_code_range_size(size_t limit_in_mb) {
6432  code_range_size_ = limit_in_mb;
6433  }
6434  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6435  void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; }
6436 
6437  private:
6438  // max_semi_space_size_ is in KB
6439  size_t max_semi_space_size_in_kb_;
6440 
6441  // The remaining limits are in MB
6442  size_t max_old_space_size_;
6443  size_t max_executable_size_;
6444  uint32_t* stack_limit_;
6445  size_t code_range_size_;
6446  size_t max_zone_pool_size_;
6447 };
6448 
6449 
6450 // --- Exceptions ---
6451 
6452 
6453 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6454 
6455 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6456 
6457 typedef void (*DcheckErrorCallback)(const char* file, int line,
6458  const char* message);
6459 
6460 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6461 
6462 // --- Tracing ---
6463 
6464 typedef void (*LogEventCallback)(const char* name, int event);
6465 
6470 class V8_EXPORT Exception {
6471  public:
6472  static Local<Value> RangeError(Local<String> message);
6473  static Local<Value> ReferenceError(Local<String> message);
6474  static Local<Value> SyntaxError(Local<String> message);
6475  static Local<Value> TypeError(Local<String> message);
6476  static Local<Value> Error(Local<String> message);
6477 
6483  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6484 
6489  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6490 };
6491 
6492 
6493 // --- Counters Callbacks ---
6494 
6495 typedef int* (*CounterLookupCallback)(const char* name);
6496 
6497 typedef void* (*CreateHistogramCallback)(const char* name,
6498  int min,
6499  int max,
6500  size_t buckets);
6501 
6502 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6503 
6504 // --- Enter/Leave Script Callback ---
6505 typedef void (*BeforeCallEnteredCallback)(Isolate*);
6506 typedef void (*CallCompletedCallback)(Isolate*);
6507 
6528 typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)(
6529  Local<Context> context, Local<ScriptOrModule> referrer,
6530  Local<String> specifier);
6531 
6542 typedef void (*HostInitializeImportMetaObjectCallback)(Local<Context> context,
6543  Local<Module> module,
6544  Local<Object> meta);
6545 
6562 enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
6563 
6564 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6565  Local<Value> parent);
6566 
6567 // --- Promise Reject Callback ---
6568 enum PromiseRejectEvent {
6569  kPromiseRejectWithNoHandler = 0,
6570  kPromiseHandlerAddedAfterReject = 1,
6571  kPromiseRejectAfterResolved = 2,
6572  kPromiseResolveAfterResolved = 3,
6573 };
6574 
6575 class PromiseRejectMessage {
6576  public:
6577  PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
6578  Local<Value> value, Local<StackTrace> stack_trace)
6579  : promise_(promise),
6580  event_(event),
6581  value_(value),
6582  stack_trace_(stack_trace) {}
6583 
6584  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6585  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6586  V8_INLINE Local<Value> GetValue() const { return value_; }
6587 
6588  private:
6589  Local<Promise> promise_;
6590  PromiseRejectEvent event_;
6591  Local<Value> value_;
6592  Local<StackTrace> stack_trace_;
6593 };
6594 
6595 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
6596 
6597 // --- Microtasks Callbacks ---
6598 typedef void (*MicrotasksCompletedCallback)(Isolate*);
6599 typedef void (*MicrotaskCallback)(void* data);
6600 
6601 
6609 enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
6610 
6611 
6621 class V8_EXPORT MicrotasksScope {
6622  public:
6623  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6624 
6625  MicrotasksScope(Isolate* isolate, Type type);
6626  ~MicrotasksScope();
6627 
6631  static void PerformCheckpoint(Isolate* isolate);
6632 
6636  static int GetCurrentDepth(Isolate* isolate);
6637 
6641  static bool IsRunningMicrotasks(Isolate* isolate);
6642 
6643  // Prevent copying.
6644  MicrotasksScope(const MicrotasksScope&) = delete;
6645  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6646 
6647  private:
6648  internal::Isolate* const isolate_;
6649  bool run_;
6650 };
6651 
6652 
6653 // --- Failed Access Check Callback ---
6654 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
6655  AccessType type,
6656  Local<Value> data);
6657 
6658 // --- AllowCodeGenerationFromStrings callbacks ---
6659 
6664 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context,
6665  Local<String> source);
6666 
6667 // --- WebAssembly compilation callbacks ---
6668 typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
6669 
6670 typedef bool (*AllowWasmCodeGenerationCallback)(Local<Context> context,
6671  Local<String> source);
6672 
6673 // --- Callback for APIs defined on v8-supported objects, but implemented
6674 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6675 typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&);
6676 
6677 // --- Callback for WebAssembly.compileStreaming ---
6678 typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo<Value>&);
6679 
6680 // --- Callback for checking if WebAssembly threads are enabled ---
6681 typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context);
6682 
6683 // --- Garbage Collection Callbacks ---
6684 
6692 enum GCType {
6693  kGCTypeScavenge = 1 << 0,
6694  kGCTypeMarkSweepCompact = 1 << 1,
6695  kGCTypeIncrementalMarking = 1 << 2,
6696  kGCTypeProcessWeakCallbacks = 1 << 3,
6697  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
6698  kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
6699 };
6700 
6715 enum GCCallbackFlags {
6716  kNoGCCallbackFlags = 0,
6717  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
6718  kGCCallbackFlagForced = 1 << 2,
6719  kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
6720  kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
6721  kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
6722  kGCCallbackScheduleIdleGarbageCollection = 1 << 6,
6723 };
6724 
6725 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6726 
6727 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6728 
6736 typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
6737  size_t initial_heap_limit);
6738 
6745 class V8_EXPORT HeapStatistics {
6746  public:
6747  HeapStatistics();
6748  size_t total_heap_size() { return total_heap_size_; }
6749  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6750  size_t total_physical_size() { return total_physical_size_; }
6751  size_t total_available_size() { return total_available_size_; }
6752  size_t used_heap_size() { return used_heap_size_; }
6753  size_t heap_size_limit() { return heap_size_limit_; }
6754  size_t malloced_memory() { return malloced_memory_; }
6755  size_t external_memory() { return external_memory_; }
6756  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6757  size_t number_of_native_contexts() { return number_of_native_contexts_; }
6758  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
6759 
6764  size_t does_zap_garbage() { return does_zap_garbage_; }
6765 
6766  private:
6767  size_t total_heap_size_;
6768  size_t total_heap_size_executable_;
6769  size_t total_physical_size_;
6770  size_t total_available_size_;
6771  size_t used_heap_size_;
6772  size_t heap_size_limit_;
6773  size_t malloced_memory_;
6774  size_t external_memory_;
6775  size_t peak_malloced_memory_;
6776  bool does_zap_garbage_;
6777  size_t number_of_native_contexts_;
6778  size_t number_of_detached_contexts_;
6779 
6780  friend class V8;
6781  friend class Isolate;
6782 };
6783 
6784 
6785 class V8_EXPORT HeapSpaceStatistics {
6786  public:
6787  HeapSpaceStatistics();
6788  const char* space_name() { return space_name_; }
6789  size_t space_size() { return space_size_; }
6790  size_t space_used_size() { return space_used_size_; }
6791  size_t space_available_size() { return space_available_size_; }
6792  size_t physical_space_size() { return physical_space_size_; }
6793 
6794  private:
6795  const char* space_name_;
6796  size_t space_size_;
6797  size_t space_used_size_;
6798  size_t space_available_size_;
6799  size_t physical_space_size_;
6800 
6801  friend class Isolate;
6802 };
6803 
6804 
6805 class V8_EXPORT HeapObjectStatistics {
6806  public:
6807  HeapObjectStatistics();
6808  const char* object_type() { return object_type_; }
6809  const char* object_sub_type() { return object_sub_type_; }
6810  size_t object_count() { return object_count_; }
6811  size_t object_size() { return object_size_; }
6812 
6813  private:
6814  const char* object_type_;
6815  const char* object_sub_type_;
6816  size_t object_count_;
6817  size_t object_size_;
6818 
6819  friend class Isolate;
6820 };
6821 
6822 class V8_EXPORT HeapCodeStatistics {
6823  public:
6824  HeapCodeStatistics();
6825  size_t code_and_metadata_size() { return code_and_metadata_size_; }
6826  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
6827  size_t external_script_source_size() { return external_script_source_size_; }
6828 
6829  private:
6830  size_t code_and_metadata_size_;
6831  size_t bytecode_and_metadata_size_;
6832  size_t external_script_source_size_;
6833 
6834  friend class Isolate;
6835 };
6836 
6837 class RetainedObjectInfo;
6838 
6839 
6851 typedef void (*FunctionEntryHook)(uintptr_t function,
6852  uintptr_t return_addr_location);
6853 
6859 struct JitCodeEvent {
6860  enum EventType {
6861  CODE_ADDED,
6862  CODE_MOVED,
6863  CODE_REMOVED,
6864  CODE_ADD_LINE_POS_INFO,
6865  CODE_START_LINE_INFO_RECORDING,
6866  CODE_END_LINE_INFO_RECORDING
6867  };
6868  // Definition of the code position type. The "POSITION" type means the place
6869  // in the source code which are of interest when making stack traces to
6870  // pin-point the source location of a stack frame as close as possible.
6871  // The "STATEMENT_POSITION" means the place at the beginning of each
6872  // statement, and is used to indicate possible break locations.
6873  enum PositionType { POSITION, STATEMENT_POSITION };
6874 
6875  // There are two different kinds of JitCodeEvents, one for JIT code generated
6876  // by the optimizing compiler, and one for byte code generated for the
6877  // interpreter. For JIT_CODE events, the |code_start| member of the event
6878  // points to the beginning of jitted assembly code, while for BYTE_CODE
6879  // events, |code_start| points to the first bytecode of the interpreted
6880  // function.
6881  enum CodeType { BYTE_CODE, JIT_CODE };
6882 
6883  // Type of event.
6884  EventType type;
6885  CodeType code_type;
6886  // Start of the instructions.
6887  void* code_start;
6888  // Size of the instructions.
6889  size_t code_len;
6890  // Script info for CODE_ADDED event.
6891  Local<UnboundScript> script;
6892  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
6893  // code line information which is returned from the
6894  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
6895  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
6896  void* user_data;
6897 
6898  struct name_t {
6899  // Name of the object associated with the code, note that the string is not
6900  // zero-terminated.
6901  const char* str;
6902  // Number of chars in str.
6903  size_t len;
6904  };
6905 
6906  struct line_info_t {
6907  // PC offset
6908  size_t offset;
6909  // Code position
6910  size_t pos;
6911  // The position type.
6912  PositionType position_type;
6913  };
6914 
6915  union {
6916  // Only valid for CODE_ADDED.
6917  struct name_t name;
6918 
6919  // Only valid for CODE_ADD_LINE_POS_INFO
6920  struct line_info_t line_info;
6921 
6922  // New location of instructions. Only valid for CODE_MOVED.
6923  void* new_code_start;
6924  };
6925 
6926  Isolate* isolate;
6927 };
6928 
6934 enum RAILMode {
6935  // Response performance mode: In this mode very low virtual machine latency
6936  // is provided. V8 will try to avoid JavaScript execution interruptions.
6937  // Throughput may be throttled.
6938  PERFORMANCE_RESPONSE,
6939  // Animation performance mode: In this mode low virtual machine latency is
6940  // provided. V8 will try to avoid as many JavaScript execution interruptions
6941  // as possible. Throughput may be throttled. This is the default mode.
6942  PERFORMANCE_ANIMATION,
6943  // Idle performance mode: The embedder is idle. V8 can complete deferred work
6944  // in this mode.
6945  PERFORMANCE_IDLE,
6946  // Load performance mode: In this mode high throughput is provided. V8 may
6947  // turn off latency optimizations.
6948  PERFORMANCE_LOAD
6949 };
6950 
6954 enum JitCodeEventOptions {
6955  kJitCodeEventDefault = 0,
6956  // Generate callbacks for already existent code.
6957  kJitCodeEventEnumExisting = 1
6958 };
6959 
6960 
6966 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
6967 
6968 
6972 class V8_EXPORT ExternalResourceVisitor { // NOLINT
6973  public:
6974  virtual ~ExternalResourceVisitor() {}
6975  virtual void VisitExternalString(Local<String> string) {}
6976 };
6977 
6978 
6982 class V8_EXPORT PersistentHandleVisitor { // NOLINT
6983  public:
6984  virtual ~PersistentHandleVisitor() {}
6985  virtual void VisitPersistentHandle(Persistent<Value>* value,
6986  uint16_t class_id) {}
6987 };
6988 
6997 enum class MemoryPressureLevel { kNone, kModerate, kCritical };
6998 
7006 class V8_EXPORT EmbedderHeapTracer {
7007  public:
7008  // Indicator for the stack state of the embedder.
7009  enum EmbedderStackState {
7010  kUnknown,
7011  kNonEmpty,
7012  kEmpty,
7013  };
7014 
7015  enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
7016 
7018  explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
7019  : force_completion(force_completion_) {}
7020 
7021  ForceCompletionAction force_completion;
7022  };
7023 
7024  virtual ~EmbedderHeapTracer() = default;
7025 
7032  virtual void RegisterV8References(
7033  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
7034 
7038  virtual void TracePrologue() = 0;
7039 
7053  V8_DEPRECATE_SOON("Use void AdvanceTracing(deadline_in_ms)",
7054  virtual bool AdvanceTracing(
7055  double deadline_in_ms, AdvanceTracingActions actions)) {
7056  return false;
7057  }
7058 
7072  virtual bool AdvanceTracing(double deadline_in_ms);
7073 
7074  /*
7075  * Returns true if there no more tracing work to be done (see AdvanceTracing)
7076  * and false otherwise.
7077  */
7078  virtual bool IsTracingDone();
7079 
7085  virtual void TraceEpilogue() = 0;
7086 
7094  V8_DEPRECATE_SOON("Use void EnterFinalPause(EmbedderStackState)",
7095  virtual void EnterFinalPause()) {}
7096  virtual void EnterFinalPause(EmbedderStackState stack_state);
7097 
7104  virtual void AbortTracing() = 0;
7105 
7106  /*
7107  * Called by the embedder to request immediate finalization of the currently
7108  * running tracing phase that has been started with TracePrologue and not
7109  * yet finished with TraceEpilogue.
7110  *
7111  * Will be a noop when currently not in tracing.
7112  *
7113  * This is an experimental feature.
7114  */
7115  void FinalizeTracing();
7116 
7117  /*
7118  * Called by the embedder to immediately perform a full garbage collection.
7119  *
7120  * Should only be used in testing code.
7121  */
7122  void GarbageCollectionForTesting(EmbedderStackState stack_state);
7123 
7124  /*
7125  * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
7126  * is not attached to any v8::Isolate.
7127  */
7128  v8::Isolate* isolate() const { return isolate_; }
7129 
7133  V8_DEPRECATE_SOON("Use IsTracingDone",
7134  virtual size_t NumberOfWrappersToTrace()) {
7135  return 0;
7136  }
7137 
7138  protected:
7139  v8::Isolate* isolate_ = nullptr;
7140 
7141  friend class internal::LocalEmbedderHeapTracer;
7142 };
7143 
7148 struct SerializeInternalFieldsCallback {
7149  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
7150  void* data);
7151  SerializeInternalFieldsCallback(CallbackFunction function = nullptr,
7152  void* data_arg = nullptr)
7153  : callback(function), data(data_arg) {}
7154  CallbackFunction callback;
7155  void* data;
7156 };
7157 // Note that these fields are called "internal fields" in the API and called
7158 // "embedder fields" within V8.
7159 typedef SerializeInternalFieldsCallback SerializeEmbedderFieldsCallback;
7160 
7165 struct DeserializeInternalFieldsCallback {
7166  typedef void (*CallbackFunction)(Local<Object> holder, int index,
7167  StartupData payload, void* data);
7168  DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
7169  void* data_arg = nullptr)
7170  : callback(function), data(data_arg) {}
7171  void (*callback)(Local<Object> holder, int index, StartupData payload,
7172  void* data);
7173  void* data;
7174 };
7175 typedef DeserializeInternalFieldsCallback DeserializeEmbedderFieldsCallback;
7176 
7185 class V8_EXPORT Isolate {
7186  public:
7190  struct CreateParams {
7192  : entry_hook(nullptr),
7193  code_event_handler(nullptr),
7194  snapshot_blob(nullptr),
7195  counter_lookup_callback(nullptr),
7196  create_histogram_callback(nullptr),
7197  add_histogram_sample_callback(nullptr),
7198  array_buffer_allocator(nullptr),
7199  external_references(nullptr),
7200  allow_atomics_wait(true),
7201  only_terminate_in_safe_scope(false) {}
7202 
7211  FunctionEntryHook entry_hook;
7212 
7217  JitCodeEventHandler code_event_handler;
7218 
7222  ResourceConstraints constraints;
7223 
7227  StartupData* snapshot_blob;
7228 
7229 
7234  CounterLookupCallback counter_lookup_callback;
7235 
7242  CreateHistogramCallback create_histogram_callback;
7243  AddHistogramSampleCallback add_histogram_sample_callback;
7244 
7250 
7257  const intptr_t* external_references;
7258 
7264 
7269  };
7270 
7271 
7277  public:
7278  explicit Scope(Isolate* isolate) : isolate_(isolate) {
7279  isolate->Enter();
7280  }
7281 
7282  ~Scope() { isolate_->Exit(); }
7283 
7284  // Prevent copying of Scope objects.
7285  Scope(const Scope&) = delete;
7286  Scope& operator=(const Scope&) = delete;
7287 
7288  private:
7289  Isolate* const isolate_;
7290  };
7291 
7292 
7297  public:
7298  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
7299 
7300  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
7302 
7303  // Prevent copying of Scope objects.
7305  delete;
7307  const DisallowJavascriptExecutionScope&) = delete;
7308 
7309  private:
7310  bool on_failure_;
7311  void* internal_;
7312  };
7313 
7314 
7319  public:
7320  explicit AllowJavascriptExecutionScope(Isolate* isolate);
7322 
7323  // Prevent copying of Scope objects.
7325  delete;
7326  AllowJavascriptExecutionScope& operator=(
7327  const AllowJavascriptExecutionScope&) = delete;
7328 
7329  private:
7330  void* internal_throws_;
7331  void* internal_assert_;
7332  };
7333 
7339  public:
7340  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7342 
7343  // Prevent copying of Scope objects.
7345  delete;
7347  const SuppressMicrotaskExecutionScope&) = delete;
7348 
7349  private:
7350  internal::Isolate* const isolate_;
7351  };
7352 
7358  public:
7359  explicit SafeForTerminationScope(v8::Isolate* isolate);
7361 
7362  // Prevent copying of Scope objects.
7364  SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
7365 
7366  private:
7367  internal::Isolate* isolate_;
7368  bool prev_value_;
7369  };
7370 
7375  enum GarbageCollectionType {
7376  kFullGarbageCollection,
7377  kMinorGarbageCollection
7378  };
7379 
7385  enum UseCounterFeature {
7386  kUseAsm = 0,
7387  kBreakIterator = 1,
7388  kLegacyConst = 2,
7389  kMarkDequeOverflow = 3,
7390  kStoreBufferOverflow = 4,
7391  kSlotsBufferOverflow = 5,
7392  kObjectObserve = 6,
7393  kForcedGC = 7,
7394  kSloppyMode = 8,
7395  kStrictMode = 9,
7396  kStrongMode = 10,
7397  kRegExpPrototypeStickyGetter = 11,
7398  kRegExpPrototypeToString = 12,
7399  kRegExpPrototypeUnicodeGetter = 13,
7400  kIntlV8Parse = 14,
7401  kIntlPattern = 15,
7402  kIntlResolved = 16,
7403  kPromiseChain = 17,
7404  kPromiseAccept = 18,
7405  kPromiseDefer = 19,
7406  kHtmlCommentInExternalScript = 20,
7407  kHtmlComment = 21,
7408  kSloppyModeBlockScopedFunctionRedefinition = 22,
7409  kForInInitializer = 23,
7410  kArrayProtectorDirtied = 24,
7411  kArraySpeciesModified = 25,
7412  kArrayPrototypeConstructorModified = 26,
7413  kArrayInstanceProtoModified = 27,
7414  kArrayInstanceConstructorModified = 28,
7415  kLegacyFunctionDeclaration = 29,
7416  kRegExpPrototypeSourceGetter = 30,
7417  kRegExpPrototypeOldFlagGetter = 31,
7418  kDecimalWithLeadingZeroInStrictMode = 32,
7419  kLegacyDateParser = 33,
7420  kDefineGetterOrSetterWouldThrow = 34,
7421  kFunctionConstructorReturnedUndefined = 35,
7422  kAssigmentExpressionLHSIsCallInSloppy = 36,
7423  kAssigmentExpressionLHSIsCallInStrict = 37,
7424  kPromiseConstructorReturnedUndefined = 38,
7425  kConstructorNonUndefinedPrimitiveReturn = 39,
7426  kLabeledExpressionStatement = 40,
7427  kLineOrParagraphSeparatorAsLineTerminator = 41,
7428  kIndexAccessor = 42,
7429  kErrorCaptureStackTrace = 43,
7430  kErrorPrepareStackTrace = 44,
7431  kErrorStackTraceLimit = 45,
7432  kWebAssemblyInstantiation = 46,
7433  kDeoptimizerDisableSpeculation = 47,
7434  kArrayPrototypeSortJSArrayModifiedPrototype = 48,
7435  kFunctionTokenOffsetTooLongForToString = 49,
7436  kWasmSharedMemory = 50,
7437  kWasmThreadOpcodes = 51,
7438 
7439  // If you add new values here, you'll also need to update Chromium's:
7440  // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to
7441  // this list need to be landed first, then changes on the Chromium side.
7442  kUseCounterFeatureCount // This enum value must be last.
7443  };
7444 
7445  enum MessageErrorLevel {
7446  kMessageLog = (1 << 0),
7447  kMessageDebug = (1 << 1),
7448  kMessageInfo = (1 << 2),
7449  kMessageError = (1 << 3),
7450  kMessageWarning = (1 << 4),
7451  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7452  kMessageWarning,
7453  };
7454 
7455  typedef void (*UseCounterCallback)(Isolate* isolate,
7456  UseCounterFeature feature);
7457 
7472  static Isolate* Allocate();
7473 
7477  static void Initialize(Isolate* isolate, const CreateParams& params);
7478 
7488  static Isolate* New(const CreateParams& params);
7489 
7496  static Isolate* GetCurrent();
7497 
7507  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7508  void SetAbortOnUncaughtExceptionCallback(
7509  AbortOnUncaughtExceptionCallback callback);
7510 
7515  void SetHostImportModuleDynamicallyCallback(
7516  HostImportModuleDynamicallyCallback callback);
7517 
7522  void SetHostInitializeImportMetaObjectCallback(
7523  HostInitializeImportMetaObjectCallback callback);
7524 
7531  void MemoryPressureNotification(MemoryPressureLevel level);
7532 
7543  void Enter();
7544 
7552  void Exit();
7553 
7558  void Dispose();
7559 
7564  void DumpAndResetStats();
7565 
7573  void DiscardThreadSpecificMetadata();
7574 
7579  V8_INLINE void SetData(uint32_t slot, void* data);
7580 
7585  V8_INLINE void* GetData(uint32_t slot);
7586 
7591  V8_INLINE static uint32_t GetNumberOfDataSlots();
7592 
7598  template <class T>
7599  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
7600 
7604  void GetHeapStatistics(HeapStatistics* heap_statistics);
7605 
7609  size_t NumberOfHeapSpaces();
7610 
7620  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7621  size_t index);
7622 
7626  size_t NumberOfTrackedHeapObjectTypes();
7627 
7637  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7638  size_t type_index);
7639 
7647  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7648 
7661  void GetStackSample(const RegisterState& state, void** frames,
7662  size_t frames_limit, SampleInfo* sample_info);
7663 
7677  V8_INLINE int64_t
7678  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7679 
7684  size_t NumberOfPhantomHandleResetsSinceLastCall();
7685 
7690  HeapProfiler* GetHeapProfiler();
7691 
7695  void SetIdle(bool is_idle);
7696 
7698  bool InContext();
7699 
7704  Local<Context> GetCurrentContext();
7705 
7707  Local<Context> GetEnteredContext();
7708 
7715  Local<Context> GetEnteredOrMicrotaskContext();
7716 
7721  Local<Context> GetIncumbentContext();
7722 
7729  Local<Value> ThrowException(Local<Value> exception);
7730 
7731  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7732  GCCallbackFlags flags);
7733  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7734  GCCallbackFlags flags, void* data);
7735 
7745  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
7746  GCType gc_type_filter = kGCTypeAll);
7747  void AddGCPrologueCallback(GCCallback callback,
7748  GCType gc_type_filter = kGCTypeAll);
7749 
7754  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
7755  void RemoveGCPrologueCallback(GCCallback callback);
7756 
7760  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7761 
7765  enum class AtomicsWaitEvent {
7767  kStartWait,
7769  kWokenUp,
7771  kTimedOut,
7773  kTerminatedExecution,
7775  kAPIStopped,
7777  kNotEqual
7778  };
7779 
7785  public:
7800  void Wake();
7801  };
7802 
7826  typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event,
7827  Local<SharedArrayBuffer> array_buffer,
7828  size_t offset_in_bytes, int32_t value,
7829  double timeout_in_ms,
7830  AtomicsWaitWakeHandle* stop_handle,
7831  void* data);
7832 
7839  void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
7840 
7850  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
7851  GCType gc_type_filter = kGCTypeAll);
7852  void AddGCEpilogueCallback(GCCallback callback,
7853  GCType gc_type_filter = kGCTypeAll);
7854 
7859  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
7860  void* data = nullptr);
7861  void RemoveGCEpilogueCallback(GCCallback callback);
7862 
7863  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7864 
7871  void SetGetExternallyAllocatedMemoryInBytesCallback(
7872  GetExternallyAllocatedMemoryInBytesCallback callback);
7873 
7881  void TerminateExecution();
7882 
7891  bool IsExecutionTerminating();
7892 
7907  void CancelTerminateExecution();
7908 
7917  void RequestInterrupt(InterruptCallback callback, void* data);
7918 
7929  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
7930 
7934  void SetEventLogger(LogEventCallback that);
7935 
7942  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7943 
7947  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7948 
7956  void AddCallCompletedCallback(CallCompletedCallback callback);
7957 
7961  void RemoveCallCompletedCallback(CallCompletedCallback callback);
7962 
7967  void SetPromiseHook(PromiseHook hook);
7968 
7973  void SetPromiseRejectCallback(PromiseRejectCallback callback);
7974 
7979  void RunMicrotasks();
7980 
7984  void EnqueueMicrotask(Local<Function> microtask);
7985 
7989  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
7990 
7994  void SetMicrotasksPolicy(MicrotasksPolicy policy);
7995 
7999  MicrotasksPolicy GetMicrotasksPolicy() const;
8000 
8013  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8014 
8018  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8019 
8023  void SetUseCounterCallback(UseCounterCallback callback);
8024 
8029  void SetCounterFunction(CounterLookupCallback);
8030 
8037  void SetCreateHistogramFunction(CreateHistogramCallback);
8038  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
8039 
8054  bool IdleNotificationDeadline(double deadline_in_seconds);
8055 
8060  void LowMemoryNotification();
8061 
8071  int ContextDisposedNotification(bool dependant_context = true);
8072 
8077  void IsolateInForegroundNotification();
8078 
8083  void IsolateInBackgroundNotification();
8084 
8090  void EnableMemorySavingsMode();
8091 
8095  void DisableMemorySavingsMode();
8096 
8104  void SetRAILMode(RAILMode rail_mode);
8105 
8110  void IncreaseHeapLimitForDebugging();
8111 
8115  void RestoreOriginalHeapLimit();
8116 
8121  bool IsHeapLimitIncreasedForDebugging();
8122 
8145  void SetJitCodeEventHandler(JitCodeEventOptions options,
8146  JitCodeEventHandler event_handler);
8147 
8157  void SetStackLimit(uintptr_t stack_limit);
8158 
8172  void GetCodeRange(void** start, size_t* length_in_bytes);
8173 
8175  void SetFatalErrorHandler(FatalErrorCallback that);
8176 
8178  void SetOOMErrorHandler(OOMErrorCallback that);
8179 
8185  void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
8186 
8194  void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
8195  size_t heap_limit);
8196 
8201  void SetAllowCodeGenerationFromStringsCallback(
8202  AllowCodeGenerationFromStringsCallback callback);
8203 
8208  void SetAllowWasmCodeGenerationCallback(
8209  AllowWasmCodeGenerationCallback callback);
8210 
8215  void SetWasmModuleCallback(ExtensionCallback callback);
8216  void SetWasmInstanceCallback(ExtensionCallback callback);
8217 
8218  void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
8219 
8220  void SetWasmStreamingCallback(WasmStreamingCallback callback);
8221 
8222  void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback);
8223 
8228  bool IsDead();
8229 
8239  bool AddMessageListener(MessageCallback that,
8241 
8253  bool AddMessageListenerWithErrorLevel(MessageCallback that,
8254  int message_levels,
8256 
8260  void RemoveMessageListeners(MessageCallback that);
8261 
8263  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
8264 
8269  void SetCaptureStackTraceForUncaughtExceptions(
8270  bool capture, int frame_limit = 10,
8272 
8278  void VisitExternalResources(ExternalResourceVisitor* visitor);
8279 
8284  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
8285 
8293  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
8294 
8300  void VisitWeakHandles(PersistentHandleVisitor* visitor);
8301 
8306  bool IsInUse();
8307 
8313  void SetAllowAtomicsWait(bool allow);
8314 
8315  Isolate() = delete;
8316  ~Isolate() = delete;
8317  Isolate(const Isolate&) = delete;
8318  Isolate& operator=(const Isolate&) = delete;
8319  // Deleting operator new and delete here is allowed as ctor and dtor is also
8320  // deleted.
8321  void* operator new(size_t size) = delete;
8322  void* operator new[](size_t size) = delete;
8323  void operator delete(void*, size_t) = delete;
8324  void operator delete[](void*, size_t) = delete;
8325 
8326  private:
8327  template <class K, class V, class Traits>
8328  friend class PersistentValueMapBase;
8329 
8330  internal::Object** GetDataFromSnapshotOnce(size_t index);
8331  void ReportExternalAllocationLimitReached();
8332  void CheckMemoryPressure();
8333 };
8334 
8335 class V8_EXPORT StartupData {
8336  public:
8337  const char* data;
8338  int raw_size;
8339 };
8340 
8341 
8346 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
8347 
8361 typedef uintptr_t (*ReturnAddressLocationResolver)(
8362  uintptr_t return_addr_location);
8363 
8364 
8368 class V8_EXPORT V8 {
8369  public:
8385  static void SetNativesDataBlob(StartupData* startup_blob);
8386  static void SetSnapshotDataBlob(StartupData* startup_blob);
8387 
8389  static void SetDcheckErrorHandler(DcheckErrorCallback that);
8390 
8391 
8395  static void SetFlagsFromString(const char* str, int length);
8396 
8400  static void SetFlagsFromCommandLine(int* argc,
8401  char** argv,
8402  bool remove_flags);
8403 
8405  static const char* GetVersion();
8406 
8411  static bool Initialize();
8412 
8417  static void SetEntropySource(EntropySource source);
8418 
8423  static void SetReturnAddressLocationResolver(
8424  ReturnAddressLocationResolver return_address_resolver);
8425 
8435  static bool Dispose();
8436 
8444  static bool InitializeICU(const char* icu_data_file = nullptr);
8445 
8458  static bool InitializeICUDefaultLocation(const char* exec_path,
8459  const char* icu_data_file = nullptr);
8460 
8477  static void InitializeExternalStartupData(const char* directory_path);
8478  static void InitializeExternalStartupData(const char* natives_blob,
8479  const char* snapshot_blob);
8484  static void InitializePlatform(Platform* platform);
8485 
8490  static void ShutdownPlatform();
8491 
8492 #if V8_OS_POSIX
8493 
8512  static bool TryHandleSignal(int signal_number, void* info, void* context);
8513 #endif // V8_OS_POSIX
8514 
8519  V8_DEPRECATE_SOON("Use EnableWebAssemblyTrapHandler",
8520  static bool RegisterDefaultSignalHandler());
8521 
8528  static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
8529 
8530  private:
8531  V8();
8532 
8533  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
8534  internal::Object** handle);
8535  static internal::Object** CopyPersistent(internal::Object** handle);
8536  static void DisposeGlobal(internal::Object** global_handle);
8537  static void MakeWeak(internal::Object** location, void* data,
8538  WeakCallbackInfo<void>::Callback weak_callback,
8539  WeakCallbackType type);
8540  static void MakeWeak(internal::Object** location, void* data,
8541  // Must be 0 or -1.
8542  int internal_field_index1,
8543  // Must be 1 or -1.
8544  int internal_field_index2,
8545  WeakCallbackInfo<void>::Callback weak_callback);
8546  static void MakeWeak(internal::Object*** location_addr);
8547  static void* ClearWeak(internal::Object** location);
8548  static void AnnotateStrongRetainer(internal::Object** location,
8549  const char* label);
8550  static Value* Eternalize(Isolate* isolate, Value* handle);
8551 
8552  static void RegisterExternallyReferencedObject(internal::Object** object,
8553  internal::Isolate* isolate);
8554 
8555  template <class K, class V, class T>
8556  friend class PersistentValueMapBase;
8557 
8558  static void FromJustIsNothing();
8559  static void ToLocalEmpty();
8560  static void InternalFieldOutOfBounds(int index);
8561  template <class T> friend class Local;
8562  template <class T>
8563  friend class MaybeLocal;
8564  template <class T>
8565  friend class Maybe;
8566  template <class T>
8567  friend class WeakCallbackInfo;
8568  template <class T> friend class Eternal;
8569  template <class T> friend class PersistentBase;
8570  template <class T, class M> friend class Persistent;
8571  friend class Context;
8572 };
8573 
8577 class V8_EXPORT SnapshotCreator {
8578  public:
8579  enum class FunctionCodeHandling { kClear, kKeep };
8580 
8589  SnapshotCreator(Isolate* isolate,
8590  const intptr_t* external_references = nullptr,
8591  StartupData* existing_blob = nullptr);
8592 
8601  SnapshotCreator(const intptr_t* external_references = nullptr,
8602  StartupData* existing_blob = nullptr);
8603 
8604  ~SnapshotCreator();
8605 
8609  Isolate* GetIsolate();
8610 
8618  void SetDefaultContext(Local<Context> context,
8619  SerializeInternalFieldsCallback callback =
8620  SerializeInternalFieldsCallback());
8621 
8630  size_t AddContext(Local<Context> context,
8631  SerializeInternalFieldsCallback callback =
8632  SerializeInternalFieldsCallback());
8633 
8638  size_t AddTemplate(Local<Template> template_obj);
8639 
8646  template <class T>
8647  V8_INLINE size_t AddData(Local<Context> context, Local<T> object);
8648 
8655  template <class T>
8656  V8_INLINE size_t AddData(Local<T> object);
8657 
8666  StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8667 
8668  // Disallow copying and assigning.
8669  SnapshotCreator(const SnapshotCreator&) = delete;
8670  void operator=(const SnapshotCreator&) = delete;
8671 
8672  private:
8673  size_t AddData(Local<Context> context, internal::Object* object);
8674  size_t AddData(internal::Object* object);
8675 
8676  void* data_;
8677 };
8678 
8689 template <class T>
8690 class Maybe {
8691  public:
8692  V8_INLINE bool IsNothing() const { return !has_value_; }
8693  V8_INLINE bool IsJust() const { return has_value_; }
8694 
8698  V8_INLINE T ToChecked() const { return FromJust(); }
8699 
8704  V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
8705  if (V8_LIKELY(IsJust())) *out = value_;
8706  return IsJust();
8707  }
8708 
8713  V8_INLINE T FromJust() const {
8714  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8715  return value_;
8716  }
8717 
8722  V8_INLINE T FromMaybe(const T& default_value) const {
8723  return has_value_ ? value_ : default_value;
8724  }
8725 
8726  V8_INLINE bool operator==(const Maybe& other) const {
8727  return (IsJust() == other.IsJust()) &&
8728  (!IsJust() || FromJust() == other.FromJust());
8729  }
8730 
8731  V8_INLINE bool operator!=(const Maybe& other) const {
8732  return !operator==(other);
8733  }
8734 
8735  private:
8736  Maybe() : has_value_(false) {}
8737  explicit Maybe(const T& t) : has_value_(true), value_(t) {}
8738 
8739  bool has_value_;
8740  T value_;
8741 
8742  template <class U>
8743  friend Maybe<U> Nothing();
8744  template <class U>
8745  friend Maybe<U> Just(const U& u);
8746 };
8747 
8748 template <class T>
8749 inline Maybe<T> Nothing() {
8750  return Maybe<T>();
8751 }
8752 
8753 template <class T>
8754 inline Maybe<T> Just(const T& t) {
8755  return Maybe<T>(t);
8756 }
8757 
8758 // A template specialization of Maybe<T> for the case of T = void.
8759 template <>
8760 class Maybe<void> {
8761  public:
8762  V8_INLINE bool IsNothing() const { return !is_valid_; }
8763  V8_INLINE bool IsJust() const { return is_valid_; }
8764 
8765  V8_INLINE bool operator==(const Maybe& other) const {
8766  return IsJust() == other.IsJust();
8767  }
8768 
8769  V8_INLINE bool operator!=(const Maybe& other) const {
8770  return !operator==(other);
8771  }
8772 
8773  private:
8774  struct JustTag {};
8775 
8776  Maybe() : is_valid_(false) {}
8777  explicit Maybe(JustTag) : is_valid_(true) {}
8778 
8779  bool is_valid_;
8780 
8781  template <class U>
8782  friend Maybe<U> Nothing();
8783  friend Maybe<void> JustVoid();
8784 };
8785 
8786 inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); }
8787 
8791 class V8_EXPORT TryCatch {
8792  public:
8798  explicit TryCatch(Isolate* isolate);
8799 
8803  ~TryCatch();
8804 
8808  bool HasCaught() const;
8809 
8818  bool CanContinue() const;
8819 
8832  bool HasTerminated() const;
8833 
8841  Local<Value> ReThrow();
8842 
8849  Local<Value> Exception() const;
8850 
8855  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
8856  Local<Context> context) const;
8857 
8865  Local<v8::Message> Message() const;
8866 
8877  void Reset();
8878 
8887  void SetVerbose(bool value);
8888 
8892  bool IsVerbose() const;
8893 
8899  void SetCaptureMessage(bool value);
8900 
8912  static void* JSStackComparableAddress(TryCatch* handler) {
8913  if (handler == NULL) return NULL;
8914  return handler->js_stack_comparable_address_;
8915  }
8916 
8917  TryCatch(const TryCatch&) = delete;
8918  void operator=(const TryCatch&) = delete;
8919 
8920  private:
8921  // Declaring operator new and delete as deleted is not spec compliant.
8922  // Therefore declare them private instead to disable dynamic alloc
8923  void* operator new(size_t size);
8924  void* operator new[](size_t size);
8925  void operator delete(void*, size_t);
8926  void operator delete[](void*, size_t);
8927 
8928  void ResetInternal();
8929 
8930  internal::Isolate* isolate_;
8931  TryCatch* next_;
8932  void* exception_;
8933  void* message_obj_;
8934  void* js_stack_comparable_address_;
8935  bool is_verbose_ : 1;
8936  bool can_continue_ : 1;
8937  bool capture_message_ : 1;
8938  bool rethrow_ : 1;
8939  bool has_terminated_ : 1;
8940 
8941  friend class internal::Isolate;
8942 };
8943 
8944 
8945 // --- Context ---
8946 
8947 
8951 class V8_EXPORT ExtensionConfiguration {
8952  public:
8953  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
8954  ExtensionConfiguration(int name_count, const char* names[])
8955  : name_count_(name_count), names_(names) { }
8956 
8957  const char** begin() const { return &names_[0]; }
8958  const char** end() const { return &names_[name_count_]; }
8959 
8960  private:
8961  const int name_count_;
8962  const char** names_;
8963 };
8964 
8969 class V8_EXPORT Context {
8970  public:
8983  Local<Object> Global();
8984 
8989  void DetachGlobal();
8990 
9009  static Local<Context> New(
9010  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
9011  MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(),
9012  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
9013  DeserializeInternalFieldsCallback internal_fields_deserializer =
9014  DeserializeInternalFieldsCallback());
9015 
9035  static MaybeLocal<Context> FromSnapshot(
9036  Isolate* isolate, size_t context_snapshot_index,
9037  DeserializeInternalFieldsCallback embedder_fields_deserializer =
9038  DeserializeInternalFieldsCallback(),
9039  ExtensionConfiguration* extensions = nullptr,
9040  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9041 
9059  static MaybeLocal<Object> NewRemoteContext(
9060  Isolate* isolate, Local<ObjectTemplate> global_template,
9061  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9062 
9067  void SetSecurityToken(Local<Value> token);
9068 
9070  void UseDefaultSecurityToken();
9071 
9073  Local<Value> GetSecurityToken();
9074 
9081  void Enter();
9082 
9087  void Exit();
9088 
9090  Isolate* GetIsolate();
9091 
9096  enum EmbedderDataFields { kDebugIdIndex = 0 };
9097 
9101  uint32_t GetNumberOfEmbedderDataFields();
9102 
9107  V8_INLINE Local<Value> GetEmbedderData(int index);
9108 
9115  Local<Object> GetExtrasBindingObject();
9116 
9122  void SetEmbedderData(int index, Local<Value> value);
9123 
9130  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
9131 
9137  void SetAlignedPointerInEmbedderData(int index, void* value);
9138 
9152  void AllowCodeGenerationFromStrings(bool allow);
9153 
9158  bool IsCodeGenerationFromStringsAllowed();
9159 
9165  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
9166 
9172  template <class T>
9173  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
9174 
9179  class Scope {
9180  public:
9181  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
9182  context_->Enter();
9183  }
9184  V8_INLINE ~Scope() { context_->Exit(); }
9185 
9186  private:
9187  Local<Context> context_;
9188  };
9189 
9196  public:
9201  explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
9203 
9204  private:
9205  friend class internal::Isolate;
9206 
9207  Local<Context> backup_incumbent_context_;
9208  const BackupIncumbentScope* prev_ = nullptr;
9209  };
9210 
9211  private:
9212  friend class Value;
9213  friend class Script;
9214  friend class Object;
9215  friend class Function;
9216 
9217  internal::Object** GetDataFromSnapshotOnce(size_t index);
9218  Local<Value> SlowGetEmbedderData(int index);
9219  void* SlowGetAlignedPointerFromEmbedderData(int index);
9220 };
9221 
9222 
9299 class V8_EXPORT Unlocker {
9300  public:
9304  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
9305 
9306  ~Unlocker();
9307  private:
9308  void Initialize(Isolate* isolate);
9309 
9310  internal::Isolate* isolate_;
9311 };
9312 
9313 
9314 class V8_EXPORT Locker {
9315  public:
9319  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
9320 
9321  ~Locker();
9322 
9327  static bool IsLocked(Isolate* isolate);
9328 
9332  static bool IsActive();
9333 
9334  // Disallow copying and assigning.
9335  Locker(const Locker&) = delete;
9336  void operator=(const Locker&) = delete;
9337 
9338  private:
9339  void Initialize(Isolate* isolate);
9340 
9341  bool has_lock_;
9342  bool top_level_;
9343  internal::Isolate* isolate_;
9344 };
9345 
9346 
9347 // --- Implementation ---
9348 
9349 
9350 namespace internal {
9351 
9357 class Internals {
9358  public:
9359  // These values match non-compiler-dependent values defined within
9360  // the implementation of v8.
9361  static const int kHeapObjectMapOffset = 0;
9362  static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
9363  static const int kStringResourceOffset = 3 * kApiPointerSize;
9364 
9365  static const int kOddballKindOffset = 4 * kApiPointerSize + kApiDoubleSize;
9366  static const int kForeignAddressOffset = kApiPointerSize;
9367  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
9368  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
9369  static const int kContextHeaderSize = 2 * kApiPointerSize;
9370  static const int kContextEmbedderDataIndex = 5;
9371  static const int kFullStringRepresentationMask = 0x0f;
9372  static const int kStringEncodingMask = 0x8;
9373  static const int kExternalTwoByteRepresentationTag = 0x02;
9374  static const int kExternalOneByteRepresentationTag = 0x0a;
9375 
9376  static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
9377  static const int kExternalMemoryOffset = 4 * kApiPointerSize;
9378  static const int kExternalMemoryLimitOffset =
9379  kExternalMemoryOffset + kApiInt64Size;
9380  static const int kExternalMemoryAtLastMarkCompactOffset =
9381  kExternalMemoryLimitOffset + kApiInt64Size;
9382  static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
9385  static const int kUndefinedValueRootIndex = 4;
9386  static const int kTheHoleValueRootIndex = 5;
9387  static const int kNullValueRootIndex = 6;
9388  static const int kTrueValueRootIndex = 7;
9389  static const int kFalseValueRootIndex = 8;
9390  static const int kEmptyStringRootIndex = 9;
9391 
9392  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
9393  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
9394  static const int kNodeStateMask = 0x7;
9395  static const int kNodeStateIsWeakValue = 2;
9396  static const int kNodeStateIsPendingValue = 3;
9397  static const int kNodeStateIsNearDeathValue = 4;
9398  static const int kNodeIsIndependentShift = 3;
9399  static const int kNodeIsActiveShift = 4;
9400 
9401  static const int kFirstNonstringType = 0x80;
9402  static const int kOddballType = 0x83;
9403  static const int kForeignType = 0x87;
9404  static const int kJSSpecialApiObjectType = 0x410;
9405  static const int kJSApiObjectType = 0x420;
9406  static const int kJSObjectType = 0x421;
9407 
9408  static const int kUndefinedOddballKind = 5;
9409  static const int kNullOddballKind = 3;
9410 
9411  static const uint32_t kNumIsolateDataSlots = 4;
9412 
9413  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
9414  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
9415 #ifdef V8_ENABLE_CHECKS
9416  CheckInitializedImpl(isolate);
9417 #endif
9418  }
9419 
9420  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
9421  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
9422  kHeapObjectTag);
9423  }
9424 
9425  V8_INLINE static int SmiValue(const internal::Object* value) {
9426  return PlatformSmiTagging::SmiToInt(value);
9427  }
9428 
9429  V8_INLINE static internal::Object* IntToSmi(int value) {
9430  return PlatformSmiTagging::IntToSmi(value);
9431  }
9432 
9433  V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
9434  return PlatformSmiTagging::IsValidSmi(value);
9435  }
9436 
9437  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
9438  typedef internal::Object O;
9439  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
9440  return ReadField<uint16_t>(map, kMapInstanceTypeOffset);
9441  }
9442 
9443  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
9444  typede