v8  6.8.275(node10.15.3)
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 CpuProfiler;
75 class Data;
76 class Date;
77 class External;
78 class Function;
79 class FunctionTemplate;
80 class HeapProfiler;
81 class ImplementationUtilities;
82 class Int32;
83 class Integer;
84 class Isolate;
85 template <class T>
86 class Maybe;
87 class Name;
88 class Number;
89 class NumberObject;
90 class Object;
91 class ObjectOperationDescriptor;
92 class ObjectTemplate;
93 class Platform;
94 class Primitive;
95 class Promise;
96 class PropertyDescriptor;
97 class Proxy;
98 class RawOperationDescriptor;
99 class Script;
100 class SharedArrayBuffer;
101 class Signature;
102 class StartupData;
103 class StackFrame;
104 class StackTrace;
105 class String;
106 class StringObject;
107 class Symbol;
108 class SymbolObject;
109 class PrimitiveArray;
110 class Private;
111 class Uint32;
112 class Utils;
113 class Value;
114 class WasmCompiledModule;
115 template <class T> class Local;
116 template <class T>
118 template <class T> class Eternal;
119 template<class T> class NonCopyablePersistentTraits;
120 template<class T> class PersistentBase;
121 template <class T, class M = NonCopyablePersistentTraits<T> >
123 template <class T>
124 class Global;
125 template<class K, class V, class T> class PersistentValueMap;
126 template <class K, class V, class T>
128 template <class K, class V, class T>
129 class GlobalValueMap;
130 template<class V, class T> class PersistentValueVector;
131 template<class T, class P> class WeakCallbackObject;
132 class FunctionTemplate;
133 class ObjectTemplate;
134 template<typename T> class FunctionCallbackInfo;
135 template<typename T> class PropertyCallbackInfo;
136 class StackTrace;
137 class StackFrame;
138 class Isolate;
139 class CallHandlerHelper;
141 template<typename T> class ReturnValue;
142 
143 namespace internal {
144 class Arguments;
145 class DeferredHandles;
146 class Heap;
147 class HeapObject;
148 class Isolate;
149 class Object;
150 struct ScriptStreamingData;
151 template<typename T> class CustomArguments;
152 class PropertyCallbackArguments;
153 class FunctionCallbackArguments;
154 class GlobalHandles;
155 
156 namespace wasm {
157 class StreamingDecoder;
158 } // namespace wasm
159 
163 const int kApiPointerSize = sizeof(void*); // NOLINT
164 const int kApiDoubleSize = sizeof(double); // NOLINT
165 const int kApiIntSize = sizeof(int); // NOLINT
166 const int kApiInt64Size = sizeof(int64_t); // NOLINT
167 
168 // Tag information for HeapObject.
169 const int kHeapObjectTag = 1;
170 const int kWeakHeapObjectTag = 3;
171 const int kHeapObjectTagSize = 2;
172 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
173 
174 // Tag information for Smi.
175 const int kSmiTag = 0;
176 const int kSmiTagSize = 1;
177 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
178 
179 template <size_t ptr_size>
180 struct SmiTagging;
181 
182 template <int kSmiShiftSize>
183 V8_INLINE internal::Object* IntToSmi(int value) {
184  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
185  uintptr_t tagged_value =
186  (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
187  return reinterpret_cast<internal::Object*>(tagged_value);
188 }
189 
190 // Smi constants for 32-bit systems.
191 template <>
192 struct SmiTagging<4> {
193  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
194  static int SmiShiftSize() { return kSmiShiftSize; }
195  static int SmiValueSize() { return kSmiValueSize; }
196  V8_INLINE static int SmiToInt(const internal::Object* value) {
197  int shift_bits = kSmiTagSize + kSmiShiftSize;
198  // Throw away top 32 bits and shift down (requires >> to be sign extending).
199  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
200  }
201  V8_INLINE static internal::Object* IntToSmi(int value) {
202  return internal::IntToSmi<kSmiShiftSize>(value);
203  }
204  V8_INLINE static bool IsValidSmi(intptr_t value) {
205  // To be representable as an tagged small integer, the two
206  // most-significant bits of 'value' must be either 00 or 11 due to
207  // sign-extension. To check this we add 01 to the two
208  // most-significant bits, and check if the most-significant bit is 0
209  //
210  // CAUTION: The original code below:
211  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
212  // may lead to incorrect results according to the C language spec, and
213  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
214  // compiler may produce undefined results in case of signed integer
215  // overflow. The computation must be done w/ unsigned ints.
216  return static_cast<uintptr_t>(value) + 0x40000000U < 0x80000000U;
217  }
218 };
219 
220 // Smi constants for 64-bit systems.
221 template <>
222 struct SmiTagging<8> {
223  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
224  static int SmiShiftSize() { return kSmiShiftSize; }
225  static int SmiValueSize() { return kSmiValueSize; }
226  V8_INLINE static int SmiToInt(const internal::Object* value) {
227  int shift_bits = kSmiTagSize + kSmiShiftSize;
228  // Shift down and throw away top 32 bits.
229  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
230  }
231  V8_INLINE static internal::Object* IntToSmi(int value) {
232  return internal::IntToSmi<kSmiShiftSize>(value);
233  }
234  V8_INLINE static bool IsValidSmi(intptr_t value) {
235  // To be representable as a long smi, the value must be a 32-bit integer.
236  return (value == static_cast<int32_t>(value));
237  }
238 };
239 
243 const int kSmiMinValue = (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
244 const int kSmiMaxValue = -(kSmiMinValue + 1);
245 constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
246 constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
247 
248 } // namespace internal
249 
250 namespace debug {
251 class ConsoleCallArguments;
252 } // namespace debug
253 
254 // --- Handles ---
255 
256 #define TYPE_CHECK(T, S) \
257  while (false) { \
258  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
259  }
260 
292 template <class T>
293 class Local {
294  public:
295  V8_INLINE Local() : val_(0) {}
296  template <class S>
298  : val_(reinterpret_cast<T*>(*that)) {
304  TYPE_CHECK(T, S);
305  }
306 
310  V8_INLINE bool IsEmpty() const { return val_ == 0; }
311 
315  V8_INLINE void Clear() { val_ = 0; }
316 
317  V8_INLINE T* operator->() const { return val_; }
318 
319  V8_INLINE T* operator*() const { return val_; }
320 
327  template <class S>
328  V8_INLINE bool operator==(const Local<S>& that) const {
329  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
330  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
331  if (a == 0) return b == 0;
332  if (b == 0) return false;
333  return *a == *b;
334  }
335 
336  template <class S> V8_INLINE bool operator==(
337  const PersistentBase<S>& that) const {
338  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
339  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
340  if (a == 0) return b == 0;
341  if (b == 0) return false;
342  return *a == *b;
343  }
344 
351  template <class S>
352  V8_INLINE bool operator!=(const Local<S>& that) const {
353  return !operator==(that);
354  }
355 
356  template <class S> V8_INLINE bool operator!=(
357  const Persistent<S>& that) const {
358  return !operator==(that);
359  }
360 
366  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
367 #ifdef V8_ENABLE_CHECKS
368  // If we're going to perform the type check then we have to check
369  // that the handle isn't empty before doing the checked cast.
370  if (that.IsEmpty()) return Local<T>();
371 #endif
372  return Local<T>(T::Cast(*that));
373  }
374 
380  template <class S>
382  return Local<S>::Cast(*this);
383  }
384 
390  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
391  V8_INLINE static Local<T> New(Isolate* isolate,
392  const PersistentBase<T>& that);
393 
394  private:
395  friend class Utils;
396  template<class F> friend class Eternal;
397  template<class F> friend class PersistentBase;
398  template<class F, class M> friend class Persistent;
399  template<class F> friend class Local;
400  template <class F>
401  friend class MaybeLocal;
402  template<class F> friend class FunctionCallbackInfo;
403  template<class F> friend class PropertyCallbackInfo;
404  friend class String;
405  friend class Object;
406  friend class Context;
407  friend class Isolate;
408  friend class Private;
409  template<class F> friend class internal::CustomArguments;
410  friend Local<Primitive> Undefined(Isolate* isolate);
411  friend Local<Primitive> Null(Isolate* isolate);
412  friend Local<Boolean> True(Isolate* isolate);
413  friend Local<Boolean> False(Isolate* isolate);
414  friend class HandleScope;
415  friend class EscapableHandleScope;
416  template <class F1, class F2, class F3>
418  template<class F1, class F2> friend class PersistentValueVector;
419  template <class F>
420  friend class ReturnValue;
421 
422  explicit V8_INLINE Local(T* that) : val_(that) {}
423  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
424  T* val_;
425 };
426 
427 
428 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
429 // Handle is an alias for Local for historical reasons.
430 template <class T>
431 using Handle = Local<T>;
432 #endif
433 
434 
445 template <class T>
446 class MaybeLocal {
447  public:
448  V8_INLINE MaybeLocal() : val_(nullptr) {}
449  template <class S>
451  : val_(reinterpret_cast<T*>(*that)) {
452  TYPE_CHECK(T, S);
453  }
454 
455  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
456 
461  template <class S>
463  out->val_ = IsEmpty() ? nullptr : this->val_;
464  return !IsEmpty();
465  }
466 
472 
477  template <class S>
478  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
479  return IsEmpty() ? default_value : Local<S>(val_);
480  }
481 
482  private:
483  T* val_;
484 };
485 
490 template <class T> class Eternal {
491  public:
492  V8_INLINE Eternal() : val_(nullptr) {}
493  template <class S>
494  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
495  Set(isolate, handle);
496  }
497  // Can only be safely called if already set.
498  V8_INLINE Local<T> Get(Isolate* isolate) const;
499  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
500  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
501 
502  private:
503  T* val_;
504 };
505 
506 
507 static const int kInternalFieldsInWeakCallback = 2;
508 static const int kEmbedderFieldsInWeakCallback = 2;
509 
510 template <typename T>
512  public:
513  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
514 
515  WeakCallbackInfo(Isolate* isolate, T* parameter,
516  void* embedder_fields[kEmbedderFieldsInWeakCallback],
517  Callback* callback)
518  : isolate_(isolate), parameter_(parameter), callback_(callback) {
519  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
520  embedder_fields_[i] = embedder_fields[i];
521  }
522  }
523 
524  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
525  V8_INLINE T* GetParameter() const { return parameter_; }
526  V8_INLINE void* GetInternalField(int index) const;
527 
528  // When first called, the embedder MUST Reset() the Global which triggered the
529  // callback. The Global itself is unusable for anything else. No v8 other api
530  // calls may be called in the first callback. Should additional work be
531  // required, the embedder must set a second pass callback, which will be
532  // called after all the initial callbacks are processed.
533  // Calling SetSecondPassCallback on the second pass will immediately crash.
534  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
535 
536  private:
537  Isolate* isolate_;
538  T* parameter_;
539  Callback* callback_;
540  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
541 };
542 
543 
544 // kParameter will pass a void* parameter back to the callback, kInternalFields
545 // will pass the first two internal fields back to the callback, kFinalizer
546 // will pass a void* parameter back, but is invoked before the object is
547 // actually collected, so it can be resurrected. In the last case, it is not
548 // possible to request a second pass callback.
550 
564 template <class T> class PersistentBase {
565  public:
570  V8_INLINE void Reset();
575  template <class S>
576  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
577 
582  template <class S>
583  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
584 
585  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
586  V8_INLINE void Empty() { val_ = 0; }
587 
588  V8_INLINE Local<T> Get(Isolate* isolate) const {
589  return Local<T>::New(isolate, *this);
590  }
591 
592  template <class S>
593  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
594  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
595  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
596  if (a == NULL) return b == NULL;
597  if (b == NULL) return false;
598  return *a == *b;
599  }
600 
601  template <class S>
602  V8_INLINE bool operator==(const Local<S>& that) const {
603  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
604  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
605  if (a == NULL) return b == NULL;
606  if (b == NULL) return false;
607  return *a == *b;
608  }
609 
610  template <class S>
611  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
612  return !operator==(that);
613  }
614 
615  template <class S>
616  V8_INLINE bool operator!=(const Local<S>& that) const {
617  return !operator==(that);
618  }
619 
627  template <typename P>
628  V8_INLINE void SetWeak(P* parameter,
629  typename WeakCallbackInfo<P>::Callback callback,
630  WeakCallbackType type);
631 
639  V8_INLINE void SetWeak();
640 
641  template<typename P>
642  V8_INLINE P* ClearWeak();
643 
644  // TODO(dcarney): remove this.
645  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
646 
653  V8_INLINE void AnnotateStrongRetainer(const char* label);
654 
660  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
661 
669  "Objects are always considered independent. "
670  "Use MarkActive to avoid collecting otherwise dead weak handles.",
671  V8_INLINE void MarkIndependent());
672 
680  V8_INLINE void MarkActive();
681 
682  V8_DEPRECATE_SOON("See MarkIndependent.",
683  V8_INLINE bool IsIndependent() const);
684 
686  V8_INLINE bool IsNearDeath() const;
687 
689  V8_INLINE bool IsWeak() const;
690 
695  V8_INLINE void SetWrapperClassId(uint16_t class_id);
696 
701  V8_INLINE uint16_t WrapperClassId() const;
702 
703  PersistentBase(const PersistentBase& other) = delete; // NOLINT
704  void operator=(const PersistentBase&) = delete;
705 
706  private:
707  friend class Isolate;
708  friend class Utils;
709  template<class F> friend class Local;
710  template<class F1, class F2> friend class Persistent;
711  template <class F>
712  friend class Global;
713  template<class F> friend class PersistentBase;
714  template<class F> friend class ReturnValue;
715  template <class F1, class F2, class F3>
717  template<class F1, class F2> friend class PersistentValueVector;
718  friend class Object;
719 
720  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
721  V8_INLINE static T* New(Isolate* isolate, T* that);
722 
723  T* val_;
724 };
725 
726 
733 template<class T>
734 class NonCopyablePersistentTraits {
735  public:
737  static const bool kResetInDestructor = false;
738  template<class S, class M>
739  V8_INLINE static void Copy(const Persistent<S, M>& source,
740  NonCopyablePersistent* dest) {
741  Uncompilable<Object>();
742  }
743  // TODO(dcarney): come up with a good compile error here.
744  template<class O> V8_INLINE static void Uncompilable() {
745  TYPE_CHECK(O, Primitive);
746  }
747 };
748 
749 
754 template<class T>
757  static const bool kResetInDestructor = true;
758  template<class S, class M>
759  static V8_INLINE void Copy(const Persistent<S, M>& source,
760  CopyablePersistent* dest) {
761  // do nothing, just allow copy
762  }
763 };
764 
765 
774 template <class T, class M> class Persistent : public PersistentBase<T> {
775  public:
785  template <class S>
787  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
788  TYPE_CHECK(T, S);
789  }
795  template <class S, class M2>
797  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
798  TYPE_CHECK(T, S);
799  }
807  Copy(that);
808  }
809  template <class S, class M2>
811  Copy(that);
812  }
813  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
814  Copy(that);
815  return *this;
816  }
817  template <class S, class M2>
819  Copy(that);
820  return *this;
821  }
828  if (M::kResetInDestructor) this->Reset();
829  }
830 
831  // TODO(dcarney): this is pretty useless, fix or remove
832  template <class S>
833  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
834 #ifdef V8_ENABLE_CHECKS
835  // If we're going to perform the type check then we have to check
836  // that the handle isn't empty before doing the checked cast.
837  if (!that.IsEmpty()) T::Cast(*that);
838 #endif
839  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
840  }
841 
842  // TODO(dcarney): this is pretty useless, fix or remove
843  template <class S>
844  V8_INLINE Persistent<S>& As() const { // NOLINT
845  return Persistent<S>::Cast(*this);
846  }
847 
848  private:
849  friend class Isolate;
850  friend class Utils;
851  template<class F> friend class Local;
852  template<class F1, class F2> friend class Persistent;
853  template<class F> friend class ReturnValue;
854 
855  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
856  V8_INLINE T* operator*() const { return this->val_; }
857  template<class S, class M2>
858  V8_INLINE void Copy(const Persistent<S, M2>& that);
859 };
860 
861 
867 template <class T>
868 class Global : public PersistentBase<T> {
869  public:
873  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
879  template <class S>
881  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
882  TYPE_CHECK(T, S);
883  }
889  template <class S>
890  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
891  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
892  TYPE_CHECK(T, S);
893  }
897  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
898  other.val_ = nullptr;
899  }
900  V8_INLINE ~Global() { this->Reset(); }
904  template <class S>
905  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
906  TYPE_CHECK(T, S);
907  if (this != &rhs) {
908  this->Reset();
909  this->val_ = rhs.val_;
910  rhs.val_ = nullptr;
911  }
912  return *this;
913  }
917  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
918 
919  /*
920  * For compatibility with Chromium's base::Bind (base::Passed).
921  */
922  typedef void MoveOnlyTypeForCPP03;
923 
924  Global(const Global&) = delete;
925  void operator=(const Global&) = delete;
926 
927  private:
928  template <class F>
929  friend class ReturnValue;
930  V8_INLINE T* operator*() const { return this->val_; }
931 };
932 
933 
934 // UniquePersistent is an alias for Global for historical reason.
935 template <class T>
937 
938 
954  public:
955  explicit HandleScope(Isolate* isolate);
956 
957  ~HandleScope();
958 
962  static int NumberOfHandles(Isolate* isolate);
963 
965  return reinterpret_cast<Isolate*>(isolate_);
966  }
967 
968  HandleScope(const HandleScope&) = delete;
969  void operator=(const HandleScope&) = delete;
970 
971  protected:
973 
974  void Initialize(Isolate* isolate);
975 
976  static internal::Object** CreateHandle(internal::Isolate* isolate,
977  internal::Object* value);
978 
979  private:
980  // Declaring operator new and delete as deleted is not spec compliant.
981  // Therefore declare them private instead to disable dynamic alloc
982  void* operator new(size_t size);
983  void* operator new[](size_t size);
984  void operator delete(void*, size_t);
985  void operator delete[](void*, size_t);
986 
987  // Uses heap_object to obtain the current Isolate.
988  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
989  internal::Object* value);
990 
991  internal::Isolate* isolate_;
992  internal::Object** prev_next_;
993  internal::Object** prev_limit_;
994 
995  // Local::New uses CreateHandle with an Isolate* parameter.
996  template<class F> friend class Local;
997 
998  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
999  // a HeapObject* in their shortcuts.
1000  friend class Object;
1001  friend class Context;
1002 };
1003 
1004 
1010  public:
1011  explicit EscapableHandleScope(Isolate* isolate);
1013 
1018  template <class T>
1020  internal::Object** slot =
1021  Escape(reinterpret_cast<internal::Object**>(*value));
1022  return Local<T>(reinterpret_cast<T*>(slot));
1023  }
1024 
1025  EscapableHandleScope(const EscapableHandleScope&) = delete;
1026  void operator=(const EscapableHandleScope&) = delete;
1027 
1028  private:
1029  // Declaring operator new and delete as deleted is not spec compliant.
1030  // Therefore declare them private instead to disable dynamic alloc
1031  void* operator new(size_t size);
1032  void* operator new[](size_t size);
1033  void operator delete(void*, size_t);
1034  void operator delete[](void*, size_t);
1035 
1036  internal::Object** Escape(internal::Object** escape_value);
1037  internal::Object** escape_slot_;
1038 };
1039 
1046  public:
1047  explicit SealHandleScope(Isolate* isolate);
1048  ~SealHandleScope();
1049 
1050  SealHandleScope(const SealHandleScope&) = delete;
1051  void operator=(const SealHandleScope&) = delete;
1052 
1053  private:
1054  // Declaring operator new and delete as deleted is not spec compliant.
1055  // Therefore declare them private instead to disable dynamic alloc
1056  void* operator new(size_t size);
1057  void* operator new[](size_t size);
1058  void operator delete(void*, size_t);
1059  void operator delete[](void*, size_t);
1060 
1061  internal::Isolate* const isolate_;
1062  internal::Object** prev_limit_;
1063  int prev_sealed_level_;
1064 };
1065 
1066 
1067 // --- Special objects ---
1068 
1069 
1074  private:
1075  Data();
1076 };
1077 
1085  public:
1090  Local<Value> GetResourceName();
1091 
1096  Local<PrimitiveArray> GetHostDefinedOptions();
1097 };
1098 
1108  public:
1109  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1110  int Length() const;
1111  void Set(int index, Local<Primitive> item);
1112  Local<Primitive> Get(int index);
1113 };
1114 
1119  public:
1120  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1121  bool is_opaque = false, bool is_wasm = false,
1122  bool is_module = false)
1123  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1124  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1125  (is_module ? kIsModule : 0)) {}
1127  : flags_(flags &
1128  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1129 
1130  bool IsSharedCrossOrigin() const {
1131  return (flags_ & kIsSharedCrossOrigin) != 0;
1132  }
1133  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1134  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1135  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1136 
1137  int Flags() const { return flags_; }
1138 
1139  private:
1140  enum {
1141  kIsSharedCrossOrigin = 1,
1142  kIsOpaque = 1 << 1,
1143  kIsWasm = 1 << 2,
1144  kIsModule = 1 << 3
1145  };
1146  const int flags_;
1147 };
1148 
1153  public:
1155  Local<Value> resource_name,
1156  Local<Integer> resource_line_offset = Local<Integer>(),
1157  Local<Integer> resource_column_offset = Local<Integer>(),
1158  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1159  Local<Integer> script_id = Local<Integer>(),
1160  Local<Value> source_map_url = Local<Value>(),
1161  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1162  Local<Boolean> is_wasm = Local<Boolean>(),
1163  Local<Boolean> is_module = Local<Boolean>(),
1164  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1165 
1172  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1173 
1174  private:
1175  Local<Value> resource_name_;
1176  Local<Integer> resource_line_offset_;
1177  Local<Integer> resource_column_offset_;
1178  ScriptOriginOptions options_;
1179  Local<Integer> script_id_;
1180  Local<Value> source_map_url_;
1181  Local<PrimitiveArray> host_defined_options_;
1182 };
1183 
1188  public:
1192  Local<Script> BindToCurrentContext();
1193 
1194  int GetId();
1195  Local<Value> GetScriptName();
1196 
1200  Local<Value> GetSourceURL();
1204  Local<Value> GetSourceMappingURL();
1205 
1210  int GetLineNumber(int code_pos);
1211 
1212  static const int kNoScriptId = 0;
1213 };
1214 
1219  // Only used as a container for code caching.
1220 };
1221 
1226  public:
1227  int GetLineNumber() { return line_number_; }
1228  int GetColumnNumber() { return column_number_; }
1229 
1230  Location(int line_number, int column_number)
1231  : line_number_(line_number), column_number_(column_number) {}
1232 
1233  private:
1234  int line_number_;
1235  int column_number_;
1236 };
1237 
1242  public:
1250  enum Status {
1256  kErrored
1257  };
1258 
1262  Status GetStatus() const;
1263 
1267  Local<Value> GetException() const;
1268 
1272  int GetModuleRequestsLength() const;
1273 
1278  Local<String> GetModuleRequest(int i) const;
1279 
1284  Location GetModuleRequestLocation(int i) const;
1285 
1289  int GetIdentityHash() const;
1290 
1291  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1292  Local<String> specifier,
1293  Local<Module> referrer);
1294 
1302  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1303  ResolveCallback callback);
1304 
1314 
1320  Local<Value> GetModuleNamespace();
1321 
1328  Local<UnboundModuleScript> GetUnboundModuleScript();
1329 };
1330 
1336  public:
1340  static V8_DEPRECATED("Use maybe version",
1341  Local<Script> Compile(Local<String> source,
1342  ScriptOrigin* origin = nullptr));
1344  Local<Context> context, Local<String> source,
1345  ScriptOrigin* origin = nullptr);
1346 
1347  static Local<Script> V8_DEPRECATED("Use maybe version",
1348  Compile(Local<String> source,
1349  Local<String> file_name));
1350 
1356  V8_DEPRECATED("Use maybe version", Local<Value> Run());
1358 
1362  Local<UnboundScript> GetUnboundScript();
1363 };
1364 
1365 
1370  public:
1381  BufferOwned
1382  };
1383 
1385  : data(NULL),
1386  length(0),
1387  rejected(false),
1388  buffer_policy(BufferNotOwned) {}
1389 
1390  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1391  // data and guarantees that it stays alive until the CachedData object is
1392  // destroyed. If the policy is BufferOwned, the given data will be deleted
1393  // (with delete[]) when the CachedData object is destroyed.
1394  CachedData(const uint8_t* data, int length,
1395  BufferPolicy buffer_policy = BufferNotOwned);
1396  ~CachedData();
1397  // TODO(marja): Async compilation; add constructors which take a callback
1398  // which will be called when V8 no longer needs the data.
1399  const uint8_t* data;
1400  int length;
1401  bool rejected;
1403 
1404  // Prevent copying.
1405  CachedData(const CachedData&) = delete;
1406  CachedData& operator=(const CachedData&) = delete;
1407  };
1408 
1412  class Source {
1413  public:
1414  // Source takes ownership of CachedData.
1415  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1416  CachedData* cached_data = NULL);
1417  V8_INLINE Source(Local<String> source_string,
1418  CachedData* cached_data = NULL);
1419  V8_INLINE ~Source();
1420 
1421  // Ownership of the CachedData or its buffers is *not* transferred to the
1422  // caller. The CachedData object is alive as long as the Source object is
1423  // alive.
1424  V8_INLINE const CachedData* GetCachedData() const;
1425 
1426  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1427 
1428  // Prevent copying.
1429  Source(const Source&) = delete;
1430  Source& operator=(const Source&) = delete;
1431 
1432  private:
1433  friend class ScriptCompiler;
1434 
1435  Local<String> source_string;
1436 
1437  // Origin information
1438  Local<Value> resource_name;
1439  Local<Integer> resource_line_offset;
1440  Local<Integer> resource_column_offset;
1441  ScriptOriginOptions resource_options;
1442  Local<Value> source_map_url;
1443  Local<PrimitiveArray> host_defined_options;
1444 
1445  // Cached data from previous compilation (if a kConsume*Cache flag is
1446  // set), or hold newly generated cache data (kProduce*Cache flags) are
1447  // set when calling a compile method.
1448  CachedData* cached_data;
1449  };
1450 
1456  public:
1458 
1476  virtual size_t GetMoreData(const uint8_t** src) = 0;
1477 
1488  virtual bool SetBookmark();
1489 
1493  virtual void ResetToBookmark();
1494  };
1495 
1496 
1504  public:
1505  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1506 
1507  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1508  ~StreamedSource();
1509 
1510  // Ownership of the CachedData or its buffers is *not* transferred to the
1511  // caller. The CachedData object is alive as long as the StreamedSource
1512  // object is alive.
1513  const CachedData* GetCachedData() const;
1514 
1515  internal::ScriptStreamingData* impl() const { return impl_; }
1516 
1517  // Prevent copying.
1518  StreamedSource(const StreamedSource&) = delete;
1519  StreamedSource& operator=(const StreamedSource&) = delete;
1520 
1521  private:
1522  internal::ScriptStreamingData* impl_;
1523  };
1524 
1530  public:
1532  virtual void Run() = 0;
1533  };
1534 
1536  kNoCompileOptions = 0,
1542  kEagerCompile
1543  };
1544 
1549  kNoCacheNoReason = 0,
1563  kNoCacheBecauseDeferredProduceCodeCache
1564  };
1565 
1579  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1580  Isolate* isolate, Source* source,
1581  CompileOptions options = kNoCompileOptions,
1582  NoCacheReason no_cache_reason = kNoCacheNoReason);
1583 
1596  Local<Context> context, Source* source,
1597  CompileOptions options = kNoCompileOptions,
1598  NoCacheReason no_cache_reason = kNoCacheNoReason);
1599 
1611  static ScriptStreamingTask* StartStreamingScript(
1612  Isolate* isolate, StreamedSource* source,
1613  CompileOptions options = kNoCompileOptions);
1614 
1623  Local<Context> context, StreamedSource* source,
1624  Local<String> full_source_string, const ScriptOrigin& origin);
1625 
1644  static uint32_t CachedDataVersionTag();
1645 
1653  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1654  Isolate* isolate, Source* source);
1655 
1666  static V8_DEPRECATED("Use maybe version",
1667  Local<Function> CompileFunctionInContext(
1668  Isolate* isolate, Source* source,
1669  Local<Context> context, size_t arguments_count,
1670  Local<String> arguments[],
1671  size_t context_extension_count,
1672  Local<Object> context_extensions[]));
1673  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1674  Local<Context> context, Source* source, size_t arguments_count,
1675  Local<String> arguments[], size_t context_extension_count,
1676  Local<Object> context_extensions[],
1677  CompileOptions options = kNoCompileOptions,
1678  NoCacheReason no_cache_reason = kNoCacheNoReason);
1679 
1685  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
1686 
1692  static CachedData* CreateCodeCache(
1693  Local<UnboundModuleScript> unbound_module_script);
1694 
1695  V8_DEPRECATED("Source string is no longer required",
1696  static CachedData* CreateCodeCache(
1697  Local<UnboundScript> unbound_script, Local<String> source));
1698 
1705  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
1706 
1707  V8_DEPRECATED("Source string is no longer required",
1708  static CachedData* CreateCodeCacheForFunction(
1709  Local<Function> function, Local<String> source));
1710 
1711  private:
1712  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1713  Isolate* isolate, Source* source, CompileOptions options,
1714  NoCacheReason no_cache_reason);
1715 };
1716 
1717 
1722  public:
1723  Local<String> Get() const;
1724 
1725  V8_DEPRECATED("Use maybe version", Local<String> GetSourceLine() const);
1727  Local<Context> context) const;
1728 
1733  ScriptOrigin GetScriptOrigin() const;
1734 
1739  Local<Value> GetScriptResourceName() const;
1740 
1746  Local<StackTrace> GetStackTrace() const;
1747 
1751  V8_DEPRECATED("Use maybe version", int GetLineNumber() const);
1752  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1753 
1758  int GetStartPosition() const;
1759 
1764  int GetEndPosition() const;
1765 
1769  int ErrorLevel() const;
1770 
1775  int GetStartColumn() const;
1776  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1777 
1782  int GetEndColumn() const;
1783  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1784 
1789  bool IsSharedCrossOrigin() const;
1790  bool IsOpaque() const;
1791 
1792  // TODO(1245381): Print to a string instead of on a FILE.
1793  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1794 
1795  static const int kNoLineNumberInfo = 0;
1796  static const int kNoColumnInfo = 0;
1797  static const int kNoScriptIdInfo = 0;
1798 };
1799 
1800 
1807  public:
1815  kLineNumber = 1,
1816  kColumnOffset = 1 << 1 | kLineNumber,
1817  kScriptName = 1 << 2,
1818  kFunctionName = 1 << 3,
1819  kIsEval = 1 << 4,
1820  kIsConstructor = 1 << 5,
1821  kScriptNameOrSourceURL = 1 << 6,
1822  kScriptId = 1 << 7,
1823  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1824  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1825  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1826  };
1827 
1831  Local<StackFrame> GetFrame(uint32_t index) const;
1832 
1836  int GetFrameCount() const;
1837 
1845  static Local<StackTrace> CurrentStackTrace(
1846  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1847 };
1848 
1849 
1854  public:
1861  int GetLineNumber() const;
1862 
1870  int GetColumn() const;
1871 
1878  int GetScriptId() const;
1879 
1884  Local<String> GetScriptName() const;
1885 
1892  Local<String> GetScriptNameOrSourceURL() const;
1893 
1897  Local<String> GetFunctionName() const;
1898 
1903  bool IsEval() const;
1904 
1909  bool IsConstructor() const;
1910 
1914  bool IsWasm() const;
1915 };
1916 
1917 
1918 // A StateTag represents a possible state of the VM.
1919 enum StateTag {
1928 };
1929 
1930 // A RegisterState represents the current state of registers used
1931 // by the sampling profiler API.
1933  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1934  void* pc; // Instruction pointer.
1935  void* sp; // Stack pointer.
1936  void* fp; // Frame pointer.
1937 };
1938 
1939 // The output structure filled up by GetStackSample API function.
1940 struct SampleInfo {
1941  size_t frames_count; // Number of frames collected.
1942  StateTag vm_state; // Current VM state.
1943  void* external_callback_entry; // External callback address if VM is
1944  // executing an external callback.
1945 };
1946 
1951  public:
1959  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1960  MaybeLocal<Value> Parse(Isolate* isolate,
1961  Local<String> json_string));
1963  Local<Context> context, Local<String> json_string);
1964 
1972  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1973  Local<Context> context, Local<Value> json_object,
1974  Local<String> gap = Local<String>());
1975 };
1976 
1986  public:
1988  public:
1989  virtual ~Delegate() {}
1990 
1996  virtual void ThrowDataCloneError(Local<String> message) = 0;
1997 
2003  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
2004 
2015  virtual Maybe<uint32_t> GetSharedArrayBufferId(
2016  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
2017 
2018  virtual Maybe<uint32_t> GetWasmModuleTransferId(
2019  Isolate* isolate, Local<WasmCompiledModule> module);
2031  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
2032  size_t* actual_size);
2033 
2039  virtual void FreeBufferMemory(void* buffer);
2040  };
2041 
2042  explicit ValueSerializer(Isolate* isolate);
2043  ValueSerializer(Isolate* isolate, Delegate* delegate);
2044  ~ValueSerializer();
2045 
2049  void WriteHeader();
2050 
2055  Local<Value> value);
2056 
2061  V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
2062 
2069  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
2070 
2076  void TransferArrayBuffer(uint32_t transfer_id,
2077  Local<ArrayBuffer> array_buffer);
2078 
2082  V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
2083  void TransferSharedArrayBuffer(
2084  uint32_t transfer_id,
2085  Local<SharedArrayBuffer> shared_array_buffer));
2086 
2094  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
2095 
2101  void WriteUint32(uint32_t value);
2102  void WriteUint64(uint64_t value);
2103  void WriteDouble(double value);
2104  void WriteRawBytes(const void* source, size_t length);
2105 
2106  private:
2107  ValueSerializer(const ValueSerializer&) = delete;
2108  void operator=(const ValueSerializer&) = delete;
2109 
2110  struct PrivateData;
2111  PrivateData* private_;
2112 };
2113 
2123  public:
2125  public:
2126  virtual ~Delegate() {}
2127 
2133  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
2134 
2139  virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
2140  Isolate* isolate, uint32_t transfer_id);
2141 
2146  virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
2147  Isolate* isolate, uint32_t clone_id);
2148  };
2149 
2150  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2151  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2152  Delegate* delegate);
2153  ~ValueDeserializer();
2154 
2159  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2160 
2165 
2170  void TransferArrayBuffer(uint32_t transfer_id,
2171  Local<ArrayBuffer> array_buffer);
2172 
2178  void TransferSharedArrayBuffer(uint32_t id,
2179  Local<SharedArrayBuffer> shared_array_buffer);
2180 
2188  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2189 
2193  void SetExpectInlineWasm(bool allow_inline_wasm);
2194 
2200  uint32_t GetWireFormatVersion() const;
2201 
2207  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2208  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2209  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2210  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2211 
2212  private:
2213  ValueDeserializer(const ValueDeserializer&) = delete;
2214  void operator=(const ValueDeserializer&) = delete;
2215 
2216  struct PrivateData;
2217  PrivateData* private_;
2218 };
2219 
2220 
2221 // --- Value ---
2222 
2223 
2227 class V8_EXPORT Value : public Data {
2228  public:
2233  V8_INLINE bool IsUndefined() const;
2234 
2239  V8_INLINE bool IsNull() const;
2240 
2246  V8_INLINE bool IsNullOrUndefined() const;
2247 
2251  bool IsTrue() const;
2252 
2256  bool IsFalse() const;
2257 
2261  bool IsName() const;
2262 
2267  V8_INLINE bool IsString() const;
2268 
2272  bool IsSymbol() const;
2273 
2277  bool IsFunction() const;
2278 
2283  bool IsArray() const;
2284 
2288  bool IsObject() const;
2289 
2293  bool IsBigInt() const;
2294 
2298  bool IsBoolean() const;
2299 
2303  bool IsNumber() const;
2304 
2308  bool IsExternal() const;
2309 
2313  bool IsInt32() const;
2314 
2318  bool IsUint32() const;
2319 
2323  bool IsDate() const;
2324 
2328  bool IsArgumentsObject() const;
2329 
2333  bool IsBigIntObject() const;
2334 
2338  bool IsBooleanObject() const;
2339 
2343  bool IsNumberObject() const;
2344 
2348  bool IsStringObject() const;
2349 
2353  bool IsSymbolObject() const;
2354 
2358  bool IsNativeError() const;
2359 
2363  bool IsRegExp() const;
2364 
2368  bool IsAsyncFunction() const;
2369 
2373  bool IsGeneratorFunction() const;
2374 
2378  bool IsGeneratorObject() const;
2379 
2383  bool IsPromise() const;
2384 
2388  bool IsMap() const;
2389 
2393  bool IsSet() const;
2394 
2398  bool IsMapIterator() const;
2399 
2403  bool IsSetIterator() const;
2404 
2408  bool IsWeakMap() const;
2409 
2413  bool IsWeakSet() const;
2414 
2418  bool IsArrayBuffer() const;
2419 
2423  bool IsArrayBufferView() const;
2424 
2428  bool IsTypedArray() const;
2429 
2433  bool IsUint8Array() const;
2434 
2438  bool IsUint8ClampedArray() const;
2439 
2443  bool IsInt8Array() const;
2444 
2448  bool IsUint16Array() const;
2449 
2453  bool IsInt16Array() const;
2454 
2458  bool IsUint32Array() const;
2459 
2463  bool IsInt32Array() const;
2464 
2468  bool IsFloat32Array() const;
2469 
2473  bool IsFloat64Array() const;
2474 
2478  bool IsBigInt64Array() const;
2479 
2483  bool IsBigUint64Array() const;
2484 
2488  bool IsDataView() const;
2489 
2494  bool IsSharedArrayBuffer() const;
2495 
2499  bool IsProxy() const;
2500 
2501  bool IsWebAssemblyCompiledModule() const;
2502 
2506  bool IsModuleNamespaceObject() const;
2507 
2509  Local<Context> context) const;
2511  Local<Context> context) const;
2513  Local<Context> context) const;
2515  Local<Context> context) const;
2517  Local<Context> context) const;
2519  Local<Context> context) const;
2521  Local<Context> context) const;
2523  Local<Context> context) const;
2525 
2526  V8_DEPRECATE_SOON("Use maybe version",
2527  Local<Boolean> ToBoolean(Isolate* isolate) const);
2528  V8_DEPRECATE_SOON("Use maybe version",
2529  Local<Number> ToNumber(Isolate* isolate) const);
2530  V8_DEPRECATE_SOON("Use maybe version",
2531  Local<String> ToString(Isolate* isolate) const);
2532  V8_DEPRECATE_SOON("Use maybe version",
2533  Local<Object> ToObject(Isolate* isolate) const);
2534  V8_DEPRECATE_SOON("Use maybe version",
2535  Local<Integer> ToInteger(Isolate* isolate) const);
2536  V8_DEPRECATE_SOON("Use maybe version",
2537  Local<Int32> ToInt32(Isolate* isolate) const);
2538 
2539  inline V8_DEPRECATE_SOON("Use maybe version",
2540  Local<Boolean> ToBoolean() const);
2541  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
2542  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
2543  inline V8_DEPRECATE_SOON("Use maybe version",
2544  Local<Integer> ToInteger() const);
2545 
2551  Local<Context> context) const;
2552 
2553  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2554  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2556  Local<Context> context) const;
2558  Local<Context> context) const;
2559  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2560 
2561  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2562  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2563  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2564  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2565  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2566 
2568  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2570  Local<Value> that) const;
2571  bool StrictEquals(Local<Value> that) const;
2572  bool SameValue(Local<Value> that) const;
2573 
2574  template <class T> V8_INLINE static Value* Cast(T* value);
2575 
2576  Local<String> TypeOf(Isolate*);
2577 
2578  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2579 
2580  private:
2581  V8_INLINE bool QuickIsUndefined() const;
2582  V8_INLINE bool QuickIsNull() const;
2583  V8_INLINE bool QuickIsNullOrUndefined() const;
2584  V8_INLINE bool QuickIsString() const;
2585  bool FullIsUndefined() const;
2586  bool FullIsNull() const;
2587  bool FullIsString() const;
2588 };
2589 
2590 
2594 class V8_EXPORT Primitive : public Value { };
2595 
2596 
2601 class V8_EXPORT Boolean : public Primitive {
2602  public:
2603  bool Value() const;
2604  V8_INLINE static Boolean* Cast(v8::Value* obj);
2605  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2606 
2607  private:
2608  static void CheckCast(v8::Value* obj);
2609 };
2610 
2611 
2615 class V8_EXPORT Name : public Primitive {
2616  public:
2624  int GetIdentityHash();
2625 
2626  V8_INLINE static Name* Cast(Value* obj);
2627 
2628  private:
2629  static void CheckCast(Value* obj);
2630 };
2631 
2638 enum class NewStringType {
2642  kNormal,
2643 
2650 };
2651 
2655 class V8_EXPORT String : public Name {
2656  public:
2657  static constexpr int kMaxLength = internal::kApiPointerSize == 4
2658  ? (1 << 28) - 16
2659  : internal::kSmiMaxValue / 2 - 24;
2660 
2661  enum Encoding {
2662  UNKNOWN_ENCODING = 0x1,
2663  TWO_BYTE_ENCODING = 0x0,
2664  ONE_BYTE_ENCODING = 0x8
2665  };
2669  int Length() const;
2670 
2675  int Utf8Length() const;
2676 
2683  bool IsOneByte() const;
2684 
2690  bool ContainsOnlyOneByte() const;
2691 
2718  NO_OPTIONS = 0,
2719  HINT_MANY_WRITES_EXPECTED = 1,
2720  NO_NULL_TERMINATION = 2,
2721  PRESERVE_ONE_BYTE_NULL = 4,
2722  // Used by WriteUtf8 to replace orphan surrogate code units with the
2723  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2724  // output.
2725  REPLACE_INVALID_UTF8 = 8
2726  };
2727 
2728  // 16-bit character codes.
2729  int Write(uint16_t* buffer,
2730  int start = 0,
2731  int length = -1,
2732  int options = NO_OPTIONS) const;
2733  // One byte characters.
2734  int WriteOneByte(uint8_t* buffer,
2735  int start = 0,
2736  int length = -1,
2737  int options = NO_OPTIONS) const;
2738  // UTF-8 encoded characters.
2739  int WriteUtf8(char* buffer,
2740  int length = -1,
2741  int* nchars_ref = NULL,
2742  int options = NO_OPTIONS) const;
2743 
2747  V8_INLINE static Local<String> Empty(Isolate* isolate);
2748 
2752  bool IsExternal() const;
2753 
2757  bool IsExternalOneByte() const;
2758 
2760  public:
2762 
2763  virtual bool IsCompressible() const { return false; }
2764 
2765  protected:
2767 
2774  virtual void Dispose() { delete this; }
2775 
2776  // Disallow copying and assigning.
2778  void operator=(const ExternalStringResourceBase&) = delete;
2779 
2780  private:
2781  friend class internal::Heap;
2782  friend class v8::String;
2783  };
2784 
2792  : public ExternalStringResourceBase {
2793  public:
2799 
2803  virtual const uint16_t* data() const = 0;
2804 
2808  virtual size_t length() const = 0;
2809 
2810  protected:
2812  };
2813 
2825  : public ExternalStringResourceBase {
2826  public:
2833  virtual const char* data() const = 0;
2835  virtual size_t length() const = 0;
2836  protected:
2838  };
2839 
2845  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2846  Encoding* encoding_out) const;
2847 
2852  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2853 
2858  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2859 
2860  V8_INLINE static String* Cast(v8::Value* obj);
2861 
2862  // TODO(dcarney): remove with deprecation of New functions.
2864  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2865  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2866  };
2867 
2869  static V8_DEPRECATE_SOON(
2870  "Use maybe version",
2871  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2872  NewStringType type = kNormalString,
2873  int length = -1));
2874 
2877  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2878  Isolate* isolate, const char* data, v8::NewStringType type,
2879  int length = -1);
2880 
2883  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2884  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2885  int length = -1);
2886 
2888  static V8_DEPRECATE_SOON(
2889  "Use maybe version",
2890  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2891  NewStringType type = kNormalString,
2892  int length = -1));
2893 
2896  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2897  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2898  int length = -1);
2899 
2904  static Local<String> Concat(Local<String> left, Local<String> right);
2905 
2914  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2915  Isolate* isolate, ExternalStringResource* resource);
2916 
2926  bool MakeExternal(ExternalStringResource* resource);
2927 
2936  static V8_DEPRECATE_SOON(
2937  "Use maybe version",
2938  Local<String> NewExternal(Isolate* isolate,
2939  ExternalOneByteStringResource* resource));
2940  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2941  Isolate* isolate, ExternalOneByteStringResource* resource);
2942 
2952  bool MakeExternal(ExternalOneByteStringResource* resource);
2953 
2957  bool CanMakeExternal();
2958 
2967  public:
2968  V8_DEPRECATED("Use Isolate version",
2969  explicit Utf8Value(Local<v8::Value> obj));
2970  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2971  ~Utf8Value();
2972  char* operator*() { return str_; }
2973  const char* operator*() const { return str_; }
2974  int length() const { return length_; }
2975 
2976  // Disallow copying and assigning.
2977  Utf8Value(const Utf8Value&) = delete;
2978  void operator=(const Utf8Value&) = delete;
2979 
2980  private:
2981  char* str_;
2982  int length_;
2983  };
2984 
2992  public:
2993  V8_DEPRECATED("Use Isolate version", explicit Value(Local<v8::Value> obj));
2994  Value(Isolate* isolate, Local<v8::Value> obj);
2995  ~Value();
2996  uint16_t* operator*() { return str_; }
2997  const uint16_t* operator*() const { return str_; }
2998  int length() const { return length_; }
2999 
3000  // Disallow copying and assigning.
3001  Value(const Value&) = delete;
3002  void operator=(const Value&) = delete;
3003 
3004  private:
3005  uint16_t* str_;
3006  int length_;
3007  };
3008 
3009  private:
3010  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
3011  Encoding encoding) const;
3012  void VerifyExternalStringResource(ExternalStringResource* val) const;
3013  static void CheckCast(v8::Value* obj);
3014 };
3015 
3016 
3020 class V8_EXPORT Symbol : public Name {
3021  public:
3025  Local<Value> Name() const;
3026 
3030  static Local<Symbol> New(Isolate* isolate,
3031  Local<String> name = Local<String>());
3032 
3040  static Local<Symbol> For(Isolate *isolate, Local<String> name);
3041 
3046  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
3047 
3048  // Well-known symbols
3049  static Local<Symbol> GetHasInstance(Isolate* isolate);
3050  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
3051  static Local<Symbol> GetIterator(Isolate* isolate);
3052  static Local<Symbol> GetMatch(Isolate* isolate);
3053  static Local<Symbol> GetReplace(Isolate* isolate);
3054  static Local<Symbol> GetSearch(Isolate* isolate);
3055  static Local<Symbol> GetSplit(Isolate* isolate);
3056  static Local<Symbol> GetToPrimitive(Isolate* isolate);
3057  static Local<Symbol> GetToStringTag(Isolate* isolate);
3058  static Local<Symbol> GetUnscopables(Isolate* isolate);
3059 
3060  V8_INLINE static Symbol* Cast(Value* obj);
3061 
3062  private:
3063  Symbol();
3064  static void CheckCast(Value* obj);
3065 };
3066 
3067 
3073 class V8_EXPORT Private : public Data {
3074  public:
3078  Local<Value> Name() const;
3079 
3083  static Local<Private> New(Isolate* isolate,
3084  Local<String> name = Local<String>());
3085 
3095  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3096 
3097  V8_INLINE static Private* Cast(Data* data);
3098 
3099  private:
3100  Private();
3101 
3102  static void CheckCast(Data* that);
3103 };
3104 
3105 
3109 class V8_EXPORT Number : public Primitive {
3110  public:
3111  double Value() const;
3112  static Local<Number> New(Isolate* isolate, double value);
3113  V8_INLINE static Number* Cast(v8::Value* obj);
3114  private:
3115  Number();
3116  static void CheckCast(v8::Value* obj);
3117 };
3118 
3119 
3123 class V8_EXPORT Integer : public Number {
3124  public:
3125  static Local<Integer> New(Isolate* isolate, int32_t value);
3126  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3127  int64_t Value() const;
3128  V8_INLINE static Integer* Cast(v8::Value* obj);
3129  private:
3130  Integer();
3131  static void CheckCast(v8::Value* obj);
3132 };
3133 
3134 
3138 class V8_EXPORT Int32 : public Integer {
3139  public:
3140  int32_t Value() const;
3141  V8_INLINE static Int32* Cast(v8::Value* obj);
3142 
3143  private:
3144  Int32();
3145  static void CheckCast(v8::Value* obj);
3146 };
3147 
3148 
3152 class V8_EXPORT Uint32 : public Integer {
3153  public:
3154  uint32_t Value() const;
3155  V8_INLINE static Uint32* Cast(v8::Value* obj);
3156 
3157  private:
3158  Uint32();
3159  static void CheckCast(v8::Value* obj);
3160 };
3161 
3165 class V8_EXPORT BigInt : public Primitive {
3166  public:
3167  static Local<BigInt> New(Isolate* isolate, int64_t value);
3168  V8_INLINE static BigInt* Cast(v8::Value* obj);
3169 
3170  private:
3171  BigInt();
3172  static void CheckCast(v8::Value* obj);
3173 };
3174 
3180  None = 0,
3182  ReadOnly = 1 << 0,
3184  DontEnum = 1 << 1,
3186  DontDelete = 1 << 2
3187 };
3188 
3194 typedef void (*AccessorGetterCallback)(
3195  Local<String> property,
3196  const PropertyCallbackInfo<Value>& info);
3198  Local<Name> property,
3199  const PropertyCallbackInfo<Value>& info);
3200 
3201 
3202 typedef void (*AccessorSetterCallback)(
3203  Local<String> property,
3204  Local<Value> value,
3205  const PropertyCallbackInfo<void>& info);
3207  Local<Name> property,
3208  Local<Value> value,
3209  const PropertyCallbackInfo<void>& info);
3210 
3211 
3222  DEFAULT = 0,
3224  ALL_CAN_WRITE = 1 << 1,
3226 };
3227 
3238 };
3239 
3248 
3257 
3263 
3269 
3274 
3278 class V8_EXPORT Object : public Value {
3279  public:
3280  V8_DEPRECATE_SOON("Use maybe version",
3281  bool Set(Local<Value> key, Local<Value> value));
3283  Local<Value> key, Local<Value> value);
3284 
3285  V8_DEPRECATE_SOON("Use maybe version",
3286  bool Set(uint32_t index, Local<Value> value));
3287  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3288  Local<Value> value);
3289 
3290  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3291  //
3292  // Defines a configurable, writable, enumerable property with the given value
3293  // on the object unless the property already exists and is not configurable
3294  // or the object is not extensible.
3295  //
3296  // Returns true on success.
3297  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3298  Local<Name> key,
3299  Local<Value> value);
3300  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3301  uint32_t index,
3302  Local<Value> value);
3303 
3304  // Implements DefineOwnProperty.
3305  //
3306  // In general, CreateDataProperty will be faster, however, does not allow
3307  // for specifying attributes.
3308  //
3309  // Returns true on success.
3310  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3311  Local<Context> context, Local<Name> key, Local<Value> value,
3312  PropertyAttribute attributes = None);
3313 
3314  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3315  //
3316  // The defineProperty function is used to add an own property or
3317  // update the attributes of an existing own property of an object.
3318  //
3319  // Both data and accessor descriptors can be used.
3320  //
3321  // In general, CreateDataProperty is faster, however, does not allow
3322  // for specifying attributes or an accessor descriptor.
3323  //
3324  // The PropertyDescriptor can change when redefining a property.
3325  //
3326  // Returns true on success.
3327  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3328  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3329 
3330  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3332  Local<Value> key);
3333 
3334  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3336  uint32_t index);
3337 
3343  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3344  Local<Context> context, Local<Value> key);
3345 
3349  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3350  Local<Context> context, Local<Name> key);
3351 
3352  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
3369  Local<Value> key);
3370 
3371  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3373  Local<Value> key);
3374 
3375  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3376 
3378  uint32_t index);
3379 
3383  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
3384  Local<Context> context, Local<Name> name,
3387  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3388  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3389 
3390  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3391  Local<Function> setter = Local<Function>(),
3392  PropertyAttribute attribute = None,
3393  AccessControl settings = DEFAULT);
3394 
3399  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3400  Local<Context> context, Local<Name> name,
3402  AccessorNameSetterCallback setter = nullptr,
3403  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
3404  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3405 
3414  V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
3415  Local<Context> context, Local<Name> name,
3417  PropertyAttribute attributes = None,
3418  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3419 
3426  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3427  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3428  Local<Value> value);
3429  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3430  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3431 
3438  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3439  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3440  Local<Context> context);
3441  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3442  Local<Context> context, KeyCollectionMode mode,
3443  PropertyFilter property_filter, IndexFilter index_filter,
3445 
3451  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3452  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3453  Local<Context> context);
3454 
3461  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3462  Local<Context> context, PropertyFilter filter,
3464 
3470  Local<Value> GetPrototype();
3471 
3477  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3478  Local<Value> prototype);
3479 
3484  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3485 
3491  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3492  Local<Context> context);
3493 
3497  Local<String> GetConstructorName();
3498 
3502  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3503 
3505  int InternalFieldCount();
3506 
3509  const PersistentBase<Object>& object) {
3510  return object.val_->InternalFieldCount();
3511  }
3512 
3514  V8_INLINE Local<Value> GetInternalField(int index);
3515 
3517  void SetInternalField(int index, Local<Value> value);
3518 
3524  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3525 
3528  const PersistentBase<Object>& object, int index) {
3529  return object.val_->GetAlignedPointerFromInternalField(index);
3530  }
3531 
3537  void SetAlignedPointerInInternalField(int index, void* value);
3538  void SetAlignedPointerInInternalFields(int argc, int indices[],
3539  void* values[]);
3540 
3546  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3547  Local<Name> key);
3548  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3549  uint32_t index);
3550  V8_DEPRECATE_SOON("Use maybe version",
3551  bool HasRealNamedProperty(Local<String> key));
3565  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3566  Local<Name> key);
3567  V8_DEPRECATE_SOON("Use maybe version",
3568  bool HasRealIndexedProperty(uint32_t index));
3569  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3570  Local<Context> context, uint32_t index);
3571  V8_DEPRECATE_SOON("Use maybe version",
3572  bool HasRealNamedCallbackProperty(Local<String> key));
3573  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3574  Local<Context> context, Local<Name> key);
3575 
3580  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3581  Local<Context> context, Local<Name> key);
3582 
3589  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3590  Local<Name> key);
3591 
3597  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3598  Local<Context> context, Local<Name> key);
3599 
3605  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3606  Local<Context> context, Local<Name> key);
3607 
3609  bool HasNamedLookupInterceptor();
3610 
3612  bool HasIndexedLookupInterceptor();
3613 
3621  int GetIdentityHash();
3622 
3627  // TODO(dcarney): take an isolate and optionally bail out?
3628  Local<Object> Clone();
3629 
3633  Local<Context> CreationContext();
3634 
3637  const PersistentBase<Object>& object) {
3638  return object.val_->CreationContext();
3639  }
3640 
3646  bool IsCallable();
3647 
3651  bool IsConstructor();
3652 
3658  Local<Value> recv,
3659  int argc,
3660  Local<Value> argv[]);
3661 
3667  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3668  Local<Context> context, int argc, Local<Value> argv[]);
3669 
3673  Isolate* GetIsolate();
3674 
3684  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3685 
3686  static Local<Object> New(Isolate* isolate);
3687 
3688  V8_INLINE static Object* Cast(Value* obj);
3689 
3690  private:
3691  Object();
3692  static void CheckCast(Value* obj);
3693  Local<Value> SlowGetInternalField(int index);
3694  void* SlowGetAlignedPointerFromInternalField(int index);
3695 };
3696 
3697 
3701 class V8_EXPORT Array : public Object {
3702  public:
3703  uint32_t Length() const;
3704 
3709  static Local<Array> New(Isolate* isolate, int length = 0);
3710 
3711  V8_INLINE static Array* Cast(Value* obj);
3712  private:
3713  Array();
3714  static void CheckCast(Value* obj);
3715 };
3716 
3717 
3721 class V8_EXPORT Map : public Object {
3722  public:
3723  size_t Size() const;
3724  void Clear();
3726  Local<Value> key);
3728  Local<Value> key,
3729  Local<Value> value);
3731  Local<Value> key);
3733  Local<Value> key);
3734 
3739  Local<Array> AsArray() const;
3740 
3744  static Local<Map> New(Isolate* isolate);
3745 
3746  V8_INLINE static Map* Cast(Value* obj);
3747 
3748  private:
3749  Map();
3750  static void CheckCast(Value* obj);
3751 };
3752 
3753 
3757 class V8_EXPORT Set : public Object {
3758  public:
3759  size_t Size() const;
3760  void Clear();
3762  Local<Value> key);
3764  Local<Value> key);
3766  Local<Value> key);
3767 
3771  Local<Array> AsArray() const;
3772 
3776  static Local<Set> New(Isolate* isolate);
3777 
3778  V8_INLINE static Set* Cast(Value* obj);
3779 
3780  private:
3781  Set();
3782  static void CheckCast(Value* obj);
3783 };
3784 
3785 
3786 template<typename T>
3787 class ReturnValue {
3788  public:
3789  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3790  : value_(that.value_) {
3791  TYPE_CHECK(T, S);
3792  }
3793  // Local setters
3794  template <typename S>
3795  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3796  void Set(const Persistent<S>& handle));
3797  template <typename S>
3798  V8_INLINE void Set(const Global<S>& handle);
3799  template <typename S>
3800  V8_INLINE void Set(const Local<S> handle);
3801  // Fast primitive setters
3802  V8_INLINE void Set(bool value);
3803  V8_INLINE void Set(double i);
3804  V8_INLINE void Set(int32_t i);
3805  V8_INLINE void Set(uint32_t i);
3806  // Fast JS primitive setters
3807  V8_INLINE void SetNull();
3808  V8_INLINE void SetUndefined();
3809  V8_INLINE void SetEmptyString();
3810  // Convenience getter for Isolate
3811  V8_INLINE Isolate* GetIsolate() const;
3812 
3813  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3814  template <typename S>
3815  V8_INLINE void Set(S* whatever);
3816 
3817  // Getter. Creates a new Local<> so it comes with a certain performance
3818  // hit. If the ReturnValue was not yet set, this will return the undefined
3819  // value.
3820  V8_INLINE Local<Value> Get() const;
3821 
3822  private:
3823  template<class F> friend class ReturnValue;
3824  template<class F> friend class FunctionCallbackInfo;
3825  template<class F> friend class PropertyCallbackInfo;
3826  template <class F, class G, class H>
3828  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3829  V8_INLINE internal::Object* GetDefaultValue();
3830  V8_INLINE explicit ReturnValue(internal::Object** slot);
3831  internal::Object** value_;
3832 };
3833 
3834 
3841 template<typename T>
3842 class FunctionCallbackInfo {
3843  public:
3845  V8_INLINE int Length() const;
3847  V8_INLINE Local<Value> operator[](int i) const;
3849  V8_INLINE Local<Object> This() const;
3860  V8_INLINE Local<Object> Holder() const;
3862  V8_INLINE Local<Value> NewTarget() const;
3864  V8_INLINE bool IsConstructCall() const;
3866  V8_INLINE Local<Value> Data() const;
3868  V8_INLINE Isolate* GetIsolate() const;
3870  V8_INLINE ReturnValue<T> GetReturnValue() const;
3871  // This shouldn't be public, but the arm compiler needs it.
3872  static const int kArgsLength = 6;
3873 
3874  protected:
3878  static const int kHolderIndex = 0;
3879  static const int kIsolateIndex = 1;
3880  static const int kReturnValueDefaultValueIndex = 2;
3881  static const int kReturnValueIndex = 3;
3882  static const int kDataIndex = 4;
3883  static const int kNewTargetIndex = 5;
3884 
3885  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3886  internal::Object** values, int length);
3887  internal::Object** implicit_args_;
3888  internal::Object** values_;
3889  int length_;
3890 };
3891 
3892 
3897 template<typename T>
3898 class PropertyCallbackInfo {
3899  public:
3903  V8_INLINE Isolate* GetIsolate() const;
3904 
3910  V8_INLINE Local<Value> Data() const;
3911 
3953  V8_INLINE Local<Object> This() const;
3954 
3964  V8_INLINE Local<Object> Holder() const;
3965 
3975 
3983  V8_INLINE bool ShouldThrowOnError() const;
3984 
3985  // This shouldn't be public, but the arm compiler needs it.
3986  static const int kArgsLength = 7;
3987 
3988  protected:
3989  friend class MacroAssembler;
3990  friend class internal::PropertyCallbackArguments;
3992  static const int kShouldThrowOnErrorIndex = 0;
3993  static const int kHolderIndex = 1;
3994  static const int kIsolateIndex = 2;
3995  static const int kReturnValueDefaultValueIndex = 3;
3996  static const int kReturnValueIndex = 4;
3997  static const int kDataIndex = 5;
3998  static const int kThisIndex = 6;
3999 
4000  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
4001  internal::Object** args_;
4002 };
4003 
4004 
4005 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
4006 
4008 
4012 class V8_EXPORT Function : public Object {
4013  public:
4018  static MaybeLocal<Function> New(
4019  Local<Context> context, FunctionCallback callback,
4020  Local<Value> data = Local<Value>(), int length = 0,
4022  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4023  static V8_DEPRECATE_SOON(
4024  "Use maybe version",
4025  Local<Function> New(Isolate* isolate, FunctionCallback callback,
4026  Local<Value> data = Local<Value>(), int length = 0));
4027 
4029  Local<Context> context, int argc, Local<Value> argv[]) const;
4030 
4032  Local<Context> context) const {
4033  return NewInstance(context, 0, nullptr);
4034  }
4035 
4041  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
4042  Local<Context> context, int argc, Local<Value> argv[],
4043  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4044 
4045  V8_DEPRECATE_SOON("Use maybe version",
4046  Local<Value> Call(Local<Value> recv, int argc,
4047  Local<Value> argv[]));
4049  Local<Value> recv, int argc,
4050  Local<Value> argv[]);
4051 
4052  void SetName(Local<String> name);
4053  Local<Value> GetName() const;
4054 
4061  Local<Value> GetInferredName() const;
4062 
4067  Local<Value> GetDebugName() const;
4068 
4073  Local<Value> GetDisplayName() const;
4074 
4079  int GetScriptLineNumber() const;
4084  int GetScriptColumnNumber() const;
4085 
4089  int ScriptId() const;
4090 
4095  Local<Value> GetBoundFunction() const;
4096 
4097  ScriptOrigin GetScriptOrigin() const;
4098  V8_INLINE static Function* Cast(Value* obj);
4099  static const int kLineOffsetNotFound;
4100 
4101  private:
4102  Function();
4103  static void CheckCast(Value* obj);
4104 };
4105 
4106 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4107 // The number of required internal fields can be defined by embedder.
4108 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4109 #endif
4110 
4114 class V8_EXPORT Promise : public Object {
4115  public:
4120  enum PromiseState { kPending, kFulfilled, kRejected };
4121 
4122  class V8_EXPORT Resolver : public Object {
4123  public:
4127  static V8_DEPRECATED("Use maybe version",
4128  Local<Resolver> New(Isolate* isolate));
4130  Local<Context> context);
4131 
4135  Local<Promise> GetPromise();
4136 
4141  V8_DEPRECATED("Use maybe version", void Resolve(Local<Value> value));
4143  Local<Value> value);
4144 
4145  V8_DEPRECATED("Use maybe version", void Reject(Local<Value> value));
4147  Local<Value> value);
4148 
4149  V8_INLINE static Resolver* Cast(Value* obj);
4150 
4151  private:
4152  Resolver();
4153  static void CheckCast(Value* obj);
4154  };
4155 
4163  Local<Function> handler);
4164 
4166  Local<Function> handler);
4167 
4172  bool HasHandler();
4173 
4178  Local<Value> Result();
4179 
4183  PromiseState State();
4184 
4185  V8_INLINE static Promise* Cast(Value* obj);
4186 
4187  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4188 
4189  private:
4190  Promise();
4191  static void CheckCast(Value* obj);
4192 };
4193 
4223  public:
4224  // GenericDescriptor
4226 
4227  // DataDescriptor
4229 
4230  // DataDescriptor with writable property
4231  PropertyDescriptor(Local<Value> value, bool writable);
4232 
4233  // AccessorDescriptor
4235 
4236  ~PropertyDescriptor();
4237 
4238  Local<Value> value() const;
4239  bool has_value() const;
4240 
4241  Local<Value> get() const;
4242  bool has_get() const;
4243  Local<Value> set() const;
4244  bool has_set() const;
4245 
4246  void set_enumerable(bool enumerable);
4247  bool enumerable() const;
4248  bool has_enumerable() const;
4249 
4250  void set_configurable(bool configurable);
4251  bool configurable() const;
4252  bool has_configurable() const;
4253 
4254  bool writable() const;
4255  bool has_writable() const;
4256 
4257  struct PrivateData;
4258  PrivateData* get_private() const { return private_; }
4259 
4260  PropertyDescriptor(const PropertyDescriptor&) = delete;
4261  void operator=(const PropertyDescriptor&) = delete;
4262 
4263  private:
4264  PrivateData* private_;
4265 };
4266 
4271 class V8_EXPORT Proxy : public Object {
4272  public:
4273  Local<Value> GetTarget();
4274  Local<Value> GetHandler();
4275  bool IsRevoked();
4276  void Revoke();
4277 
4281  static MaybeLocal<Proxy> New(Local<Context> context,
4282  Local<Object> local_target,
4283  Local<Object> local_handler);
4284 
4285  V8_INLINE static Proxy* Cast(Value* obj);
4286 
4287  private:
4288  Proxy();
4289  static void CheckCast(Value* obj);
4290 };
4291 
4292 // TODO(mtrofin): rename WasmCompiledModule to WasmModuleObject, for
4293 // consistency with internal APIs.
4295  public:
4296  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
4300  typedef std::pair<const uint8_t*, size_t> CallerOwnedBuffer;
4301 
4306  class TransferrableModule final {
4307  public:
4308  TransferrableModule(TransferrableModule&& src) = default;
4309  TransferrableModule(const TransferrableModule& src) = delete;
4310 
4311  TransferrableModule& operator=(TransferrableModule&& src) = default;
4312  TransferrableModule& operator=(const TransferrableModule& src) = delete;
4313 
4314  private:
4315  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
4316  friend class WasmCompiledModule;
4317  TransferrableModule(OwnedBuffer&& code, OwnedBuffer&& bytes)
4318  : compiled_code(std::move(code)), wire_bytes(std::move(bytes)) {}
4319 
4320  OwnedBuffer compiled_code = {nullptr, 0};
4321  OwnedBuffer wire_bytes = {nullptr, 0};
4322  };
4323 
4329  TransferrableModule GetTransferrableModule();
4330 
4335  static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
4336  Isolate* isolate, const TransferrableModule&);
4337 
4341  Local<String> GetWasmWireBytes();
4342 
4347  SerializedModule Serialize();
4348 
4353  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
4354  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
4355  const CallerOwnedBuffer& wire_bytes);
4356  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
4357 
4358  private:
4359  static MaybeLocal<WasmCompiledModule> Deserialize(
4360  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
4361  const CallerOwnedBuffer& wire_bytes);
4362  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
4363  const uint8_t* start,
4364  size_t length);
4365  static CallerOwnedBuffer AsCallerOwned(
4366  const TransferrableModule::OwnedBuffer& buff) {
4367  return {buff.first.get(), buff.second};
4368  }
4369 
4370  WasmCompiledModule();
4371  static void CheckCast(Value* obj);
4372 };
4373 
4374 // TODO(mtrofin): when streaming compilation is done, we can rename this
4375 // to simply WasmModuleObjectBuilder
4377  public:
4378  explicit WasmModuleObjectBuilderStreaming(Isolate* isolate);
4382  void OnBytesReceived(const uint8_t*, size_t size);
4383  void Finish();
4389  void Abort(MaybeLocal<Value> exception);
4390  Local<Promise> GetPromise();
4391 
4393 
4394  private:
4396  delete;
4398  default;
4400  const WasmModuleObjectBuilderStreaming&) = delete;
4402  WasmModuleObjectBuilderStreaming&&) = default;
4403  Isolate* isolate_ = nullptr;
4404 
4405 #if V8_CC_MSVC
4406 
4414 #else
4415  Persistent<Promise> promise_;
4416 #endif
4417  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4418 };
4419 
4420 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4421 // The number of required internal fields can be defined by embedder.
4422 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4423 #endif
4424 
4425 
4427 
4428 
4432 class V8_EXPORT ArrayBuffer : public Object {
4433  public:
4449  class V8_EXPORT Allocator { // NOLINT
4450  public:
4451  virtual ~Allocator() {}
4452 
4457  virtual void* Allocate(size_t length) = 0;
4458 
4463  virtual void* AllocateUninitialized(size_t length) = 0;
4464 
4469  virtual void Free(void* data, size_t length) = 0;
4470 
4476  enum class AllocationMode { kNormal, kReservation };
4477 
4484  static Allocator* NewDefaultAllocator();
4485  };
4486 
4495  class V8_EXPORT Contents { // NOLINT
4496  public:
4498  : data_(nullptr),
4499  byte_length_(0),
4500  allocation_base_(nullptr),
4501  allocation_length_(0),
4502  allocation_mode_(Allocator::AllocationMode::kNormal) {}
4503 
4504  void* AllocationBase() const { return allocation_base_; }
4505  size_t AllocationLength() const { return allocation_length_; }
4507  return allocation_mode_;
4508  }
4509 
4510  void* Data() const { return data_; }
4511  size_t ByteLength() const { return byte_length_; }
4512 
4513  private:
4514  void* data_;
4515  size_t byte_length_;
4516  void* allocation_base_;
4517  size_t allocation_length_;
4518  Allocator::AllocationMode allocation_mode_;
4519 
4520  friend class ArrayBuffer;
4521  };
4522 
4523 
4527  size_t ByteLength() const;
4528 
4535  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4536 
4546  static Local<ArrayBuffer> New(
4547  Isolate* isolate, void* data, size_t byte_length,
4549 
4554  bool IsExternal() const;
4555 
4559  bool IsNeuterable() const;
4560 
4567  void Neuter();
4568 
4578  Contents Externalize();
4579 
4590  Contents GetContents();
4591 
4592  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4593 
4594  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4595  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4596 
4597  private:
4598  ArrayBuffer();
4599  static void CheckCast(Value* obj);
4600 };
4601 
4602 
4603 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4604 // The number of required internal fields can be defined by embedder.
4605 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4606 #endif
4607 
4608 
4614  public:
4618  Local<ArrayBuffer> Buffer();
4622  size_t ByteOffset();
4626  size_t ByteLength();
4627 
4637  size_t CopyContents(void* dest, size_t byte_length);
4638 
4643  bool HasBuffer() const;
4644 
4645  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4646 
4647  static const int kInternalFieldCount =
4649  static const int kEmbedderFieldCount =
4651 
4652  private:
4653  ArrayBufferView();
4654  static void CheckCast(Value* obj);
4655 };
4656 
4657 
4663  public:
4664  /*
4665  * The largest typed array size that can be constructed using New.
4666  */
4667  static constexpr size_t kMaxLength = internal::kSmiMaxValue;
4668 
4673  size_t Length();
4674 
4675  V8_INLINE static TypedArray* Cast(Value* obj);
4676 
4677  private:
4678  TypedArray();
4679  static void CheckCast(Value* obj);
4680 };
4681 
4682 
4687  public:
4688  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4689  size_t byte_offset, size_t length);
4690  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4691  size_t byte_offset, size_t length);
4692  V8_INLINE static Uint8Array* Cast(Value* obj);
4693 
4694  private:
4695  Uint8Array();
4696  static void CheckCast(Value* obj);
4697 };
4698 
4699 
4704  public:
4705  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4706  size_t byte_offset, size_t length);
4707  static Local<Uint8ClampedArray> New(
4708  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4709  size_t length);
4710  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4711 
4712  private:
4714  static void CheckCast(Value* obj);
4715 };
4716 
4721  public:
4722  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4723  size_t byte_offset, size_t length);
4724  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4725  size_t byte_offset, size_t length);
4726  V8_INLINE static Int8Array* Cast(Value* obj);
4727 
4728  private:
4729  Int8Array();
4730  static void CheckCast(Value* obj);
4731 };
4732 
4733 
4738  public:
4739  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4740  size_t byte_offset, size_t length);
4741  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4742  size_t byte_offset, size_t length);
4743  V8_INLINE static Uint16Array* Cast(Value* obj);
4744 
4745  private:
4746  Uint16Array();
4747  static void CheckCast(Value* obj);
4748 };
4749 
4750 
4755  public:
4756  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4757  size_t byte_offset, size_t length);
4758  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4759  size_t byte_offset, size_t length);
4760  V8_INLINE static Int16Array* Cast(Value* obj);
4761 
4762  private:
4763  Int16Array();
4764  static void CheckCast(Value* obj);
4765 };
4766 
4767 
4772  public:
4773  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4774  size_t byte_offset, size_t length);
4775  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4776  size_t byte_offset, size_t length);
4777  V8_INLINE static Uint32Array* Cast(Value* obj);
4778 
4779  private:
4780  Uint32Array();
4781  static void CheckCast(Value* obj);
4782 };
4783 
4784 
4789  public:
4790  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4791  size_t byte_offset, size_t length);
4792  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4793  size_t byte_offset, size_t length);
4794  V8_INLINE static Int32Array* Cast(Value* obj);
4795 
4796  private:
4797  Int32Array();
4798  static void CheckCast(Value* obj);
4799 };
4800 
4801 
4806  public:
4807  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4808  size_t byte_offset, size_t length);
4809  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4810  size_t byte_offset, size_t length);
4811  V8_INLINE static Float32Array* Cast(Value* obj);
4812 
4813  private:
4814  Float32Array();
4815  static void CheckCast(Value* obj);
4816 };
4817 
4818 
4823  public:
4824  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4825  size_t byte_offset, size_t length);
4826  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4827  size_t byte_offset, size_t length);
4828  V8_INLINE static Float64Array* Cast(Value* obj);
4829 
4830  private:
4831  Float64Array();
4832  static void CheckCast(Value* obj);
4833 };
4834 
4839  public:
4840  static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
4841  size_t byte_offset, size_t length);
4842  static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4843  size_t byte_offset, size_t length);
4844  V8_INLINE static BigInt64Array* Cast(Value* obj);
4845 
4846  private:
4847  BigInt64Array();
4848  static void CheckCast(Value* obj);
4849 };
4850 
4855  public:
4856  static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
4857  size_t byte_offset, size_t length);
4858  static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4859  size_t byte_offset, size_t length);
4860  V8_INLINE static BigUint64Array* Cast(Value* obj);
4861 
4862  private:
4863  BigUint64Array();
4864  static void CheckCast(Value* obj);
4865 };
4866 
4871  public:
4872  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
4873  size_t byte_offset, size_t length);
4874  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
4875  size_t byte_offset, size_t length);
4876  V8_INLINE static DataView* Cast(Value* obj);
4877 
4878  private:
4879  DataView();
4880  static void CheckCast(Value* obj);
4881 };
4882 
4883 
4889  public:
4901  class V8_EXPORT Contents { // NOLINT
4902  public:
4904  : data_(nullptr),
4905  byte_length_(0),
4906  allocation_base_(nullptr),
4907  allocation_length_(0),
4908  allocation_mode_(ArrayBuffer::Allocator::AllocationMode::kNormal) {}
4909 
4910  void* AllocationBase() const { return allocation_base_; }
4911  size_t AllocationLength() const { return allocation_length_; }
4913  return allocation_mode_;
4914  }
4915 
4916  void* Data() const { return data_; }
4917  size_t ByteLength() const { return byte_length_; }
4918 
4919  private:
4920  void* data_;
4921  size_t byte_length_;
4922  void* allocation_base_;
4923  size_t allocation_length_;
4924  ArrayBuffer::Allocator::AllocationMode allocation_mode_;
4925 
4926  friend class SharedArrayBuffer;
4927  };
4928 
4929 
4933  size_t ByteLength() const;
4934 
4941  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
4942 
4949  static Local<SharedArrayBuffer> New(
4950  Isolate* isolate, void* data, size_t byte_length,
4952 
4957  bool IsExternal() const;
4958 
4971  Contents Externalize();
4972 
4985  Contents GetContents();
4986 
4987  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
4988 
4989  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4990 
4991  private:
4993  static void CheckCast(Value* obj);
4994 };
4995 
4996 
5000 class V8_EXPORT Date : public Object {
5001  public:
5002  static V8_DEPRECATE_SOON("Use maybe version.",
5003  Local<Value> New(Isolate* isolate, double time));
5005  double time);
5006 
5011  double ValueOf() const;
5012 
5013  V8_INLINE static Date* Cast(Value* obj);
5014 
5027  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
5028 
5029  private:
5030  static void CheckCast(Value* obj);
5031 };
5032 
5033 
5038  public:
5039  static Local<Value> New(Isolate* isolate, double value);
5040 
5041  double ValueOf() const;
5042 
5043  V8_INLINE static NumberObject* Cast(Value* obj);
5044 
5045  private:
5046  static void CheckCast(Value* obj);
5047 };
5048 
5053  public:
5054  static Local<Value> New(Isolate* isolate, int64_t value);
5055 
5056  Local<BigInt> ValueOf() const;
5057 
5058  V8_INLINE static BigIntObject* Cast(Value* obj);
5059 
5060  private:
5061  static void CheckCast(Value* obj);
5062 };
5063 
5068  public:
5069  static Local<Value> New(Isolate* isolate, bool value);
5070 
5071  bool ValueOf() const;
5072 
5073  V8_INLINE static BooleanObject* Cast(Value* obj);
5074 
5075  private:
5076  static void CheckCast(Value* obj);
5077 };
5078 
5079 
5084  public:
5085  static Local<Value> New(Local<String> value);
5086 
5087  Local<String> ValueOf() const;
5088 
5089  V8_INLINE static StringObject* Cast(Value* obj);
5090 
5091  private:
5092  static void CheckCast(Value* obj);
5093 };
5094 
5095 
5100  public:
5101  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
5102 
5103  Local<Symbol> ValueOf() const;
5104 
5105  V8_INLINE static SymbolObject* Cast(Value* obj);
5106 
5107  private:
5108  static void CheckCast(Value* obj);
5109 };
5110 
5111 
5115 class V8_EXPORT RegExp : public Object {
5116  public:
5121  enum Flags {
5122  kNone = 0,
5123  kGlobal = 1 << 0,
5124  kIgnoreCase = 1 << 1,
5125  kMultiline = 1 << 2,
5126  kSticky = 1 << 3,
5127  kUnicode = 1 << 4,
5128  kDotAll = 1 << 5,
5129  };
5130 
5141  static V8_DEPRECATED("Use maybe version",
5142  Local<RegExp> New(Local<String> pattern, Flags flags));
5144  Local<String> pattern,
5145  Flags flags);
5146 
5151  Local<String> GetSource() const;
5152 
5156  Flags GetFlags() const;
5157 
5158  V8_INLINE static RegExp* Cast(Value* obj);
5159 
5160  private:
5161  static void CheckCast(Value* obj);
5162 };
5163 
5164 
5169 class V8_EXPORT External : public Value {
5170  public:
5171  static Local<External> New(Isolate* isolate, void* value);
5172  V8_INLINE static External* Cast(Value* obj);
5173  void* Value() const;
5174  private:
5175  static void CheckCast(v8::Value* obj);
5176 };
5177 
5178 #define V8_INTRINSICS_LIST(F) \
5179  F(ArrayProto_entries, array_entries_iterator) \
5180  F(ArrayProto_forEach, array_for_each_iterator) \
5181  F(ArrayProto_keys, array_keys_iterator) \
5182  F(ArrayProto_values, array_values_iterator) \
5183  F(ErrorPrototype, initial_error_prototype) \
5184  F(IteratorPrototype, initial_iterator_prototype)
5185 
5187 #define V8_DECL_INTRINSIC(name, iname) k##name,
5189 #undef V8_DECL_INTRINSIC
5190 };
5191 
5192 
5193 // --- Templates ---
5194 
5195 
5199 class V8_EXPORT Template : public Data {
5200  public:
5206  void Set(Local<Name> name, Local<Data> value,
5207  PropertyAttribute attributes = None);
5208  void SetPrivate(Local<Private> name, Local<Data> value,
5209  PropertyAttribute attributes = None);
5210  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5211 
5212  void SetAccessorProperty(
5213  Local<Name> name,
5216  PropertyAttribute attribute = None,
5217  AccessControl settings = DEFAULT);
5218 
5246  void SetNativeDataProperty(
5248  AccessorSetterCallback setter = 0,
5249  // TODO(dcarney): gcc can't handle Local below
5250  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5252  AccessControl settings = DEFAULT,
5253  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5254  void SetNativeDataProperty(
5256  AccessorNameSetterCallback setter = 0,
5257  // TODO(dcarney): gcc can't handle Local below
5258  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5260  AccessControl settings = DEFAULT,
5261  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5262 
5267  void SetLazyDataProperty(
5269  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5270  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5271 
5276  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5277  PropertyAttribute attribute = None);
5278 
5279  private:
5280  Template();
5281 
5282  friend class ObjectTemplate;
5283  friend class FunctionTemplate;
5284 };
5285 
5286 
5292  Local<String> property,
5293  const PropertyCallbackInfo<Value>& info);
5294 
5295 
5301  Local<String> property,
5302  Local<Value> value,
5303  const PropertyCallbackInfo<Value>& info);
5304 
5305 
5312  Local<String> property,
5313  const PropertyCallbackInfo<Integer>& info);
5314 
5315 
5322  Local<String> property,
5323  const PropertyCallbackInfo<Boolean>& info);
5324 
5332  const PropertyCallbackInfo<Array>& info);
5333 
5334 
5335 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
5336 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
5337 
5375  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5376 
5399  Local<Name> property, Local<Value> value,
5400  const PropertyCallbackInfo<Value>& info);
5401 
5424  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5425 
5448  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5449 
5457  const PropertyCallbackInfo<Array>& info);
5458 
5480  Local<Name> property, const PropertyDescriptor& desc,
5481  const PropertyCallbackInfo<Value>& info);
5482 
5503  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5504 
5509  uint32_t index,
5510  const PropertyCallbackInfo<Value>& info);
5511 
5516  uint32_t index,
5517  Local<Value> value,
5518  const PropertyCallbackInfo<Value>& info);
5519 
5524  uint32_t index,
5525  const PropertyCallbackInfo<Integer>& info);
5526 
5531  uint32_t index,
5532  const PropertyCallbackInfo<Boolean>& info);
5533 
5541  const PropertyCallbackInfo<Array>& info);
5542 
5547  uint32_t index, const PropertyDescriptor& desc,
5548  const PropertyCallbackInfo<Value>& info);
5549 
5554  uint32_t index, const PropertyCallbackInfo<Value>& info);
5555 
5565 };
5566 
5567 
5572 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5573  Local<Object> accessed_object,
5574  Local<Value> data);
5575 
5677  public:
5679  static Local<FunctionTemplate> New(
5680  Isolate* isolate, FunctionCallback callback = 0,
5681  Local<Value> data = Local<Value>(),
5682  Local<Signature> signature = Local<Signature>(), int length = 0,
5684  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5685 
5687  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5688  size_t index);
5689 
5693  static Local<FunctionTemplate> NewWithCache(
5694  Isolate* isolate, FunctionCallback callback,
5695  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5696  Local<Signature> signature = Local<Signature>(), int length = 0,
5697  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5698 
5700  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5702  Local<Context> context);
5703 
5711  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5712 
5718  void SetCallHandler(
5719  FunctionCallback callback, Local<Value> data = Local<Value>(),
5720  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5721 
5723  void SetLength(int length);
5724 
5726  Local<ObjectTemplate> InstanceTemplate();
5727 
5733  void Inherit(Local<FunctionTemplate> parent);
5734 
5739  Local<ObjectTemplate> PrototypeTemplate();
5740 
5747  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5748 
5754  void SetClassName(Local<String> name);
5755 
5756 
5761  void SetAcceptAnyReceiver(bool value);
5762 
5775  void SetHiddenPrototype(bool value);
5776 
5781  void ReadOnlyPrototype();
5782 
5787  void RemovePrototype();
5788 
5793  bool HasInstance(Local<Value> object);
5794 
5795  V8_INLINE static FunctionTemplate* Cast(Data* data);
5796 
5797  private:
5798  FunctionTemplate();
5799 
5800  static void CheckCast(Data* that);
5801  friend class Context;
5802  friend class ObjectTemplate;
5803 };
5804 
5813  kNone = 0,
5814 
5818  kAllCanRead = 1,
5819 
5824  kNonMasking = 1 << 1,
5825 
5830  kOnlyInterceptStrings = 1 << 2,
5831 
5835  kHasNoSideEffect = 1 << 3,
5836 };
5837 
5848  : getter(getter),
5849  setter(setter),
5850  query(query),
5851  deleter(deleter),
5853  definer(0),
5854  descriptor(0),
5855  data(data),
5856  flags(flags) {}
5857 
5867  : getter(getter),
5868  setter(setter),
5869  query(0),
5870  deleter(deleter),
5872  definer(definer),
5874  data(data),
5875  flags(flags) {}
5876 
5886 };
5887 
5888 
5899  : getter(getter),
5900  setter(setter),
5901  query(query),
5902  deleter(deleter),
5904  definer(0),
5905  descriptor(0),
5906  data(data),
5907  flags(flags) {}
5908 
5918  : getter(getter),
5919  setter(setter),
5920  query(0),
5921  deleter(deleter),
5923  definer(definer),
5925  data(data),
5926  flags(flags) {}
5927 
5937 };
5938 
5939 
5947  public:
5949  static Local<ObjectTemplate> New(
5950  Isolate* isolate,
5952 
5954  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
5955  size_t index);
5956 
5958  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
5960 
5990  void SetAccessor(
5992  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
5993  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
5995  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5996  void SetAccessor(
5999  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
6001  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
6002 
6025  V8_DEPRECATED(
6026  "Use SetHandler(const NamedPropertyHandlerConfiguration) "
6027  "with the kOnlyInterceptStrings flag set.",
6028  void SetNamedPropertyHandler(
6030  NamedPropertySetterCallback setter = 0,
6031  NamedPropertyQueryCallback query = 0,
6032  NamedPropertyDeleterCallback deleter = 0,
6033  NamedPropertyEnumeratorCallback enumerator = 0,
6034  Local<Value> data = Local<Value>()));
6035 
6047  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
6048 
6065  // TODO(dcarney): deprecate
6068  IndexedPropertySetterCallback setter = 0,
6069  IndexedPropertyQueryCallback query = 0,
6070  IndexedPropertyDeleterCallback deleter = 0,
6071  IndexedPropertyEnumeratorCallback enumerator = 0,
6072  Local<Value> data = Local<Value>()) {
6073  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
6074  deleter, enumerator, data));
6075  }
6076 
6087  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
6088 
6095  void SetCallAsFunctionHandler(FunctionCallback callback,
6096  Local<Value> data = Local<Value>());
6097 
6106  void MarkAsUndetectable();
6107 
6116  void SetAccessCheckCallback(AccessCheckCallback callback,
6117  Local<Value> data = Local<Value>());
6118 
6125  void SetAccessCheckCallbackAndHandler(
6126  AccessCheckCallback callback,
6127  const NamedPropertyHandlerConfiguration& named_handler,
6128  const IndexedPropertyHandlerConfiguration& indexed_handler,
6129  Local<Value> data = Local<Value>());
6130 
6135  int InternalFieldCount();
6136 
6141  void SetInternalFieldCount(int value);
6142 
6146  bool IsImmutableProto();
6147 
6152  void SetImmutableProto();
6153 
6154  V8_INLINE static ObjectTemplate* Cast(Data* data);
6155 
6156  private:
6157  ObjectTemplate();
6158  static Local<ObjectTemplate> New(internal::Isolate* isolate,
6159  Local<FunctionTemplate> constructor);
6160  static void CheckCast(Data* that);
6161  friend class FunctionTemplate;
6162 };
6163 
6172 class V8_EXPORT Signature : public Data {
6173  public:
6174  static Local<Signature> New(
6175  Isolate* isolate,
6177 
6178  V8_INLINE static Signature* Cast(Data* data);
6179 
6180  private:
6181  Signature();
6182 
6183  static void CheckCast(Data* that);
6184 };
6185 
6186 
6192  public:
6193  static Local<AccessorSignature> New(
6194  Isolate* isolate,
6196 
6197  V8_INLINE static AccessorSignature* Cast(Data* data);
6198 
6199  private:
6201 
6202  static void CheckCast(Data* that);
6203 };
6204 
6205 
6206 // --- Extensions ---
6207 
6210  public:
6211  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
6212  ExternalOneByteStringResourceImpl(const char* data, size_t length)
6213  : data_(data), length_(length) {}
6214  const char* data() const { return data_; }
6215  size_t length() const { return length_; }
6216 
6217  private:
6218  const char* data_;
6219  size_t length_;
6220 };
6221 
6225 class V8_EXPORT Extension { // NOLINT
6226  public:
6227  // Note that the strings passed into this constructor must live as long
6228  // as the Extension itself.
6229  Extension(const char* name,
6230  const char* source = 0,
6231  int dep_count = 0,
6232  const char** deps = 0,
6233  int source_length = -1);
6234  virtual ~Extension() { }
6236  Isolate* isolate, Local<String> name) {
6237  return Local<FunctionTemplate>();
6238  }
6239 
6240  const char* name() const { return name_; }
6241  size_t source_length() const { return source_length_; }
6243  return &source_; }
6244  int dependency_count() { return dep_count_; }
6245  const char** dependencies() { return deps_; }
6246  void set_auto_enable(bool value) { auto_enable_ = value; }
6247  bool auto_enable() { return auto_enable_; }
6248 
6249  // Disallow copying and assigning.
6250  Extension(const Extension&) = delete;
6251  void operator=(const Extension&) = delete;
6252 
6253  private:
6254  const char* name_;
6255  size_t source_length_; // expected to initialize before source_
6257  int dep_count_;
6258  const char** deps_;
6259  bool auto_enable_;
6260 };
6261 
6262 
6263 void V8_EXPORT RegisterExtension(Extension* extension);
6264 
6265 
6266 // --- Statics ---
6267 
6268 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6269 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6270 V8_INLINE Local<Boolean> True(Isolate* isolate);
6271 V8_INLINE Local<Boolean> False(Isolate* isolate);
6272 
6288  public:
6290 
6300  void ConfigureDefaults(uint64_t physical_memory,
6301  uint64_t virtual_memory_limit);
6302 
6303  // Returns the max semi-space size in MB.
6304  V8_DEPRECATE_SOON("Use max_semi_space_size_in_kb()",
6305  size_t max_semi_space_size()) {
6306  return max_semi_space_size_in_kb_ / 1024;
6307  }
6308 
6309  // Sets the max semi-space size in MB.
6310  V8_DEPRECATE_SOON("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6311  void set_max_semi_space_size(size_t limit_in_mb)) {
6312  max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6313  }
6314 
6315  // Returns the max semi-space size in KB.
6316  size_t max_semi_space_size_in_kb() const {
6317  return max_semi_space_size_in_kb_;
6318  }
6319 
6320  // Sets the max semi-space size in KB.
6321  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6322  max_semi_space_size_in_kb_ = limit_in_kb;
6323  }
6324 
6325  size_t max_old_space_size() const { return max_old_space_size_; }
6326  void set_max_old_space_size(size_t limit_in_mb) {
6327  max_old_space_size_ = limit_in_mb;
6328  }
6329  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6330  size_t max_executable_size() const) {
6331  return max_executable_size_;
6332  }
6333  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6334  void set_max_executable_size(size_t limit_in_mb)) {
6335  max_executable_size_ = limit_in_mb;
6336  }
6337  uint32_t* stack_limit() const { return stack_limit_; }
6338  // Sets an address beyond which the VM's stack may not grow.
6339  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6340  size_t code_range_size() const { return code_range_size_; }
6341  void set_code_range_size(size_t limit_in_mb) {
6342  code_range_size_ = limit_in_mb;
6343  }
6344  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6345  void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; }
6346 
6347  private:
6348  // max_semi_space_size_ is in KB
6349  size_t max_semi_space_size_in_kb_;
6350 
6351  // The remaining limits are in MB
6352  size_t max_old_space_size_;
6353  size_t max_executable_size_;
6354  uint32_t* stack_limit_;
6355  size_t code_range_size_;
6356  size_t max_zone_pool_size_;
6357 };
6358 
6359 
6360 // --- Exceptions ---
6361 
6362 
6363 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6364 
6365 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6366 
6367 typedef void (*DcheckErrorCallback)(const char* file, int line,
6368  const char* message);
6369 
6370 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6371 
6372 // --- Tracing ---
6373 
6374 typedef void (*LogEventCallback)(const char* name, int event);
6375 
6381  public:
6382  static Local<Value> RangeError(Local<String> message);
6383  static Local<Value> ReferenceError(Local<String> message);
6384  static Local<Value> SyntaxError(Local<String> message);
6385  static Local<Value> TypeError(Local<String> message);
6386  static Local<Value> Error(Local<String> message);
6387 
6393  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6394 
6399  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6400 };
6401 
6402 
6403 // --- Counters Callbacks ---
6404 
6405 typedef int* (*CounterLookupCallback)(const char* name);
6406 
6407 typedef void* (*CreateHistogramCallback)(const char* name,
6408  int min,
6409  int max,
6410  size_t buckets);
6411 
6412 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6413 
6414 // --- Enter/Leave Script Callback ---
6416 typedef void (*CallCompletedCallback)(Isolate*);
6418 
6440  Local<Context> context, Local<ScriptOrModule> referrer,
6441  Local<String> specifier);
6442 
6454  Local<Module> module,
6455  Local<Object> meta);
6456 
6474 
6475 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6476  Local<Value> parent);
6477 
6478 // --- Promise Reject Callback ---
6482 };
6483 
6485  public:
6487  Local<Value> value, Local<StackTrace> stack_trace)
6488  : promise_(promise),
6489  event_(event),
6490  value_(value),
6491  stack_trace_(stack_trace) {}
6492 
6493  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6494  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6495  V8_INLINE Local<Value> GetValue() const { return value_; }
6496 
6497  private:
6498  Local<Promise> promise_;
6499  PromiseRejectEvent event_;
6500  Local<Value> value_;
6501  Local<StackTrace> stack_trace_;
6502 };
6503 
6505 
6506 // --- Microtasks Callbacks ---
6508 typedef void (*MicrotaskCallback)(void* data);
6509 
6510 
6519 
6520 
6531  public:
6532  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6533 
6534  MicrotasksScope(Isolate* isolate, Type type);
6535  ~MicrotasksScope();
6536 
6540  static void PerformCheckpoint(Isolate* isolate);
6541 
6545  static int GetCurrentDepth(Isolate* isolate);
6546 
6550  static bool IsRunningMicrotasks(Isolate* isolate);
6551 
6552  // Prevent copying.
6553  MicrotasksScope(const MicrotasksScope&) = delete;
6554  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6555 
6556  private:
6557  internal::Isolate* const isolate_;
6558  bool run_;
6559 };
6560 
6561 
6562 // --- Failed Access Check Callback ---
6564  AccessType type,
6565  Local<Value> data);
6566 
6567 // --- AllowCodeGenerationFromStrings callbacks ---
6568 
6574  Local<String> source);
6575 
6576 // --- WebAssembly compilation callbacks ---
6578 
6580  Local<String> source);
6581 
6582 // --- Callback for APIs defined on v8-supported objects, but implemented
6583 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6585 
6586 // --- Garbage Collection Callbacks ---
6587 
6595 enum GCType {
6602 };
6603 
6626 };
6627 
6628 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6629 
6630 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6631 
6639 typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
6640  size_t initial_heap_limit);
6641 
6649  public:
6650  HeapStatistics();
6651  size_t total_heap_size() { return total_heap_size_; }
6652  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6653  size_t total_physical_size() { return total_physical_size_; }
6654  size_t total_available_size() { return total_available_size_; }
6655  size_t used_heap_size() { return used_heap_size_; }
6656  size_t heap_size_limit() { return heap_size_limit_; }
6657  size_t malloced_memory() { return malloced_memory_; }
6658  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6659  size_t number_of_native_contexts() { return number_of_native_contexts_; }
6660  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
6661 
6666  size_t does_zap_garbage() { return does_zap_garbage_; }
6667 
6668  private:
6669  size_t total_heap_size_;
6670  size_t total_heap_size_executable_;
6671  size_t total_physical_size_;
6672  size_t total_available_size_;
6673  size_t used_heap_size_;
6674  size_t heap_size_limit_;
6675  size_t malloced_memory_;
6676  size_t peak_malloced_memory_;
6677  bool does_zap_garbage_;
6678  size_t number_of_native_contexts_;
6679  size_t number_of_detached_contexts_;
6680 
6681  friend class V8;
6682  friend class Isolate;
6683 };
6684 
6685 
6687  public:
6689  const char* space_name() { return space_name_; }
6690  size_t space_size() { return space_size_; }
6691  size_t space_used_size() { return space_used_size_; }
6692  size_t space_available_size() { return space_available_size_; }
6693  size_t physical_space_size() { return physical_space_size_; }
6694 
6695  private:
6696  const char* space_name_;
6697  size_t space_size_;
6698  size_t space_used_size_;
6699  size_t space_available_size_;
6700  size_t physical_space_size_;
6701 
6702  friend class Isolate;
6703 };
6704 
6705 
6707  public:
6709  const char* object_type() { return object_type_; }
6710  const char* object_sub_type() { return object_sub_type_; }
6711  size_t object_count() { return object_count_; }
6712  size_t object_size() { return object_size_; }
6713 
6714  private:
6715  const char* object_type_;
6716  const char* object_sub_type_;
6717  size_t object_count_;
6718  size_t object_size_;
6719 
6720  friend class Isolate;
6721 };
6722 
6724  public:
6726  size_t code_and_metadata_size() { return code_and_metadata_size_; }
6727  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
6728  size_t external_script_source_size() { return external_script_source_size_; }
6729 
6730  private:
6731  size_t code_and_metadata_size_;
6732  size_t bytecode_and_metadata_size_;
6733  size_t external_script_source_size_;
6734 
6735  friend class Isolate;
6736 };
6737 
6738 class RetainedObjectInfo;
6739 
6740 
6752 typedef void (*FunctionEntryHook)(uintptr_t function,
6753  uintptr_t return_addr_location);
6754 
6761  enum EventType {
6768  };
6769  // Definition of the code position type. The "POSITION" type means the place
6770  // in the source code which are of interest when making stack traces to
6771  // pin-point the source location of a stack frame as close as possible.
6772  // The "STATEMENT_POSITION" means the place at the beginning of each
6773  // statement, and is used to indicate possible break locations.
6775 
6776  // There are two different kinds of JitCodeEvents, one for JIT code generated
6777  // by the optimizing compiler, and one for byte code generated for the
6778  // interpreter. For JIT_CODE events, the |code_start| member of the event
6779  // points to the beginning of jitted assembly code, while for BYTE_CODE
6780  // events, |code_start| points to the first bytecode of the interpreted
6781  // function.
6783 
6784  // Type of event.
6787  // Start of the instructions.
6788  void* code_start;
6789  // Size of the instructions.
6790  size_t code_len;
6791  // Script info for CODE_ADDED event.
6793  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
6794  // code line information which is returned from the
6795  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
6796  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
6797  void* user_data;
6798 
6799  struct name_t {
6800  // Name of the object associated with the code, note that the string is not
6801  // zero-terminated.
6802  const char* str;
6803  // Number of chars in str.
6804  size_t len;
6805  };
6806 
6807  struct line_info_t {
6808  // PC offset
6809  size_t offset;
6810  // Code position
6811  size_t pos;
6812  // The position type.
6814  };
6815 
6816  union {
6817  // Only valid for CODE_ADDED.
6818  struct name_t name;
6819 
6820  // Only valid for CODE_ADD_LINE_POS_INFO
6822 
6823  // New location of instructions. Only valid for CODE_MOVED.
6825  };
6826 };
6827 
6833 enum RAILMode {
6834  // Response performance mode: In this mode very low virtual machine latency
6835  // is provided. V8 will try to avoid JavaScript execution interruptions.
6836  // Throughput may be throttled.
6838  // Animation performance mode: In this mode low virtual machine latency is
6839  // provided. V8 will try to avoid as many JavaScript execution interruptions
6840  // as possible. Throughput may be throttled. This is the default mode.
6842  // Idle performance mode: The embedder is idle. V8 can complete deferred work
6843  // in this mode.
6845  // Load performance mode: In this mode high throughput is provided. V8 may
6846  // turn off latency optimizations.
6848 };
6849 
6855  // Generate callbacks for already existent code.
6857 };
6858 
6859 
6865 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
6866 
6867 
6872  public:
6874  virtual void VisitExternalString(Local<String> string) {}
6875 };
6876 
6877 
6882  public:
6885  uint16_t class_id) {}
6886 };
6887 
6897 
6910  public:
6911  enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
6912 
6914  explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
6915  : force_completion(force_completion_) {}
6916 
6918  };
6919 
6926  virtual void RegisterV8References(
6927  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
6928 
6932  virtual void TracePrologue() = 0;
6933 
6944  virtual bool AdvanceTracing(double deadline_in_ms,
6945  AdvanceTracingActions actions) = 0;
6946 
6952  virtual void TraceEpilogue() = 0;
6953 
6958  virtual void EnterFinalPause() = 0;
6959 
6966  virtual void AbortTracing() = 0;
6967 
6971  virtual size_t NumberOfWrappersToTrace() { return 0; }
6972 
6973  protected:
6974  virtual ~EmbedderHeapTracer() = default;
6975 };
6976 
6982  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
6983  void* data);
6985  void* data_arg = nullptr)
6986  : callback(function), data(data_arg) {}
6988  void* data;
6989 };
6990 // Note that these fields are called "internal fields" in the API and called
6991 // "embedder fields" within V8.
6993 
6999  typedef void (*CallbackFunction)(Local<Object> holder, int index,
7000  StartupData payload, void* data);
7002  void* data_arg = nullptr)
7003  : callback(function), data(data_arg) {}
7004  void (*callback)(Local<Object> holder, int index, StartupData payload,
7005  void* data);
7006  void* data;
7007 };
7009 
7019  public:
7023  struct CreateParams {
7025  : entry_hook(nullptr),
7026  code_event_handler(nullptr),
7027  snapshot_blob(nullptr),
7028  counter_lookup_callback(nullptr),
7029  create_histogram_callback(nullptr),
7030  add_histogram_sample_callback(nullptr),
7031  array_buffer_allocator(nullptr),
7032  external_references(nullptr),
7033  allow_atomics_wait(true),
7034  only_terminate_in_safe_scope(false) {}
7035 
7045 
7051 
7056 
7061 
7062 
7068 
7077 
7083 
7090  const intptr_t* external_references;
7091 
7097 
7102  };
7103 
7104 
7110  public:
7111  explicit Scope(Isolate* isolate) : isolate_(isolate) {
7112  isolate->Enter();
7113  }
7114 
7115  ~Scope() { isolate_->Exit(); }
7116 
7117  // Prevent copying of Scope objects.
7118  Scope(const Scope&) = delete;
7119  Scope& operator=(const Scope&) = delete;
7120 
7121  private:
7122  Isolate* const isolate_;
7123  };
7124 
7125 
7130  public:
7131  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
7132 
7133  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
7135 
7136  // Prevent copying of Scope objects.
7138  delete;
7140  const DisallowJavascriptExecutionScope&) = delete;
7141 
7142  private:
7143  bool on_failure_;
7144  void* internal_;
7145  };
7146 
7147 
7152  public:
7153  explicit AllowJavascriptExecutionScope(Isolate* isolate);
7155 
7156  // Prevent copying of Scope objects.
7158  delete;
7159  AllowJavascriptExecutionScope& operator=(
7160  const AllowJavascriptExecutionScope&) = delete;
7161 
7162  private:
7163  void* internal_throws_;
7164  void* internal_assert_;
7165  };
7166 
7172  public:
7173  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7175 
7176  // Prevent copying of Scope objects.
7178  delete;
7180  const SuppressMicrotaskExecutionScope&) = delete;
7181 
7182  private:
7183  internal::Isolate* const isolate_;
7184  };
7185 
7191  public:
7192  explicit SafeForTerminationScope(v8::Isolate* isolate);
7194 
7195  // Prevent copying of Scope objects.
7197  SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
7198 
7199  private:
7200  internal::Isolate* isolate_;
7201  bool prev_value_;
7202  };
7203 
7210  kMinorGarbageCollection
7211  };
7212 
7219  kUseAsm = 0,
7220  kBreakIterator = 1,
7221  kLegacyConst = 2,
7222  kMarkDequeOverflow = 3,
7223  kStoreBufferOverflow = 4,
7224  kSlotsBufferOverflow = 5,
7225  kObjectObserve = 6,
7226  kForcedGC = 7,
7227  kSloppyMode = 8,
7228  kStrictMode = 9,
7229  kStrongMode = 10,
7230  kRegExpPrototypeStickyGetter = 11,
7231  kRegExpPrototypeToString = 12,
7232  kRegExpPrototypeUnicodeGetter = 13,
7233  kIntlV8Parse = 14,
7234  kIntlPattern = 15,
7235  kIntlResolved = 16,
7236  kPromiseChain = 17,
7237  kPromiseAccept = 18,
7238  kPromiseDefer = 19,
7239  kHtmlCommentInExternalScript = 20,
7240  kHtmlComment = 21,
7241  kSloppyModeBlockScopedFunctionRedefinition = 22,
7242  kForInInitializer = 23,
7243  kArrayProtectorDirtied = 24,
7244  kArraySpeciesModified = 25,
7245  kArrayPrototypeConstructorModified = 26,
7246  kArrayInstanceProtoModified = 27,
7247  kArrayInstanceConstructorModified = 28,
7248  kLegacyFunctionDeclaration = 29,
7249  kRegExpPrototypeSourceGetter = 30,
7250  kRegExpPrototypeOldFlagGetter = 31,
7251  kDecimalWithLeadingZeroInStrictMode = 32,
7252  kLegacyDateParser = 33,
7253  kDefineGetterOrSetterWouldThrow = 34,
7254  kFunctionConstructorReturnedUndefined = 35,
7255  kAssigmentExpressionLHSIsCallInSloppy = 36,
7256  kAssigmentExpressionLHSIsCallInStrict = 37,
7257  kPromiseConstructorReturnedUndefined = 38,
7258  kConstructorNonUndefinedPrimitiveReturn = 39,
7259  kLabeledExpressionStatement = 40,
7260  kLineOrParagraphSeparatorAsLineTerminator = 41,
7261  kIndexAccessor = 42,
7262  kErrorCaptureStackTrace = 43,
7263  kErrorPrepareStackTrace = 44,
7264  kErrorStackTraceLimit = 45,
7265  kWebAssemblyInstantiation = 46,
7266  kDeoptimizerDisableSpeculation = 47,
7267  kArrayPrototypeSortJSArrayModifiedPrototype = 48,
7268 
7269  // If you add new values here, you'll also need to update Chromium's:
7270  // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to
7271  // this list need to be landed first, then changes on the Chromium side.
7272  kUseCounterFeatureCount // This enum value must be last.
7273  };
7274 
7276  kMessageLog = (1 << 0),
7277  kMessageDebug = (1 << 1),
7278  kMessageInfo = (1 << 2),
7279  kMessageError = (1 << 3),
7280  kMessageWarning = (1 << 4),
7281  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7282  kMessageWarning,
7283  };
7284 
7285  typedef void (*UseCounterCallback)(Isolate* isolate,
7286  UseCounterFeature feature);
7287 
7302  static Isolate* Allocate();
7303 
7307  static void Initialize(Isolate* isolate, const CreateParams& params);
7308 
7318  static Isolate* New(const CreateParams& params);
7319 
7326  static Isolate* GetCurrent();
7327 
7337  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7338  void SetAbortOnUncaughtExceptionCallback(
7339  AbortOnUncaughtExceptionCallback callback);
7340 
7345  void SetHostImportModuleDynamicallyCallback(
7347 
7352  void SetHostInitializeImportMetaObjectCallback(
7354 
7361  void MemoryPressureNotification(MemoryPressureLevel level);
7362 
7373  void Enter();
7374 
7382  void Exit();
7383 
7388  void Dispose();
7389 
7394  void DumpAndResetStats();
7395 
7403  void DiscardThreadSpecificMetadata();
7404 
7409  V8_INLINE void SetData(uint32_t slot, void* data);
7410 
7415  V8_INLINE void* GetData(uint32_t slot);
7416 
7421  V8_INLINE static uint32_t GetNumberOfDataSlots();
7422 
7428  template <class T>
7429  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
7430 
7434  void GetHeapStatistics(HeapStatistics* heap_statistics);
7435 
7439  size_t NumberOfHeapSpaces();
7440 
7450  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7451  size_t index);
7452 
7456  size_t NumberOfTrackedHeapObjectTypes();
7457 
7467  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7468  size_t type_index);
7469 
7477  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7478 
7491  void GetStackSample(const RegisterState& state, void** frames,
7492  size_t frames_limit, SampleInfo* sample_info);
7493 
7507  V8_INLINE int64_t
7508  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7509 
7514  size_t NumberOfPhantomHandleResetsSinceLastCall();
7515 
7520  HeapProfiler* GetHeapProfiler();
7521 
7527  V8_DEPRECATED("CpuProfiler should be created with CpuProfiler::New call.",
7528  CpuProfiler* GetCpuProfiler());
7529 
7533  void SetIdle(bool is_idle);
7534 
7536  bool InContext();
7537 
7542  Local<Context> GetCurrentContext();
7543 
7549  V8_DEPRECATED(
7550  "Calling context concept is not compatible with tail calls, and will be "
7551  "removed.",
7552  Local<Context> GetCallingContext());
7553 
7555  Local<Context> GetEnteredContext();
7556 
7563  Local<Context> GetEnteredOrMicrotaskContext();
7564 
7569  Local<Context> GetIncumbentContext();
7570 
7577  Local<Value> ThrowException(Local<Value> exception);
7578 
7579  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7580  GCCallbackFlags flags);
7581  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7582  GCCallbackFlags flags, void* data);
7583 
7593  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
7594  GCType gc_type_filter = kGCTypeAll);
7595  void AddGCPrologueCallback(GCCallback callback,
7596  GCType gc_type_filter = kGCTypeAll);
7597 
7602  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
7603  void RemoveGCPrologueCallback(GCCallback callback);
7604 
7608  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7609 
7619  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
7620  GCType gc_type_filter = kGCTypeAll);
7621  void AddGCEpilogueCallback(GCCallback callback,
7622  GCType gc_type_filter = kGCTypeAll);
7623 
7628  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
7629  void* data = nullptr);
7630  void RemoveGCEpilogueCallback(GCCallback callback);
7631 
7632  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7633 
7640  void SetGetExternallyAllocatedMemoryInBytesCallback(
7641  GetExternallyAllocatedMemoryInBytesCallback callback);
7642 
7650  void TerminateExecution();
7651 
7660  bool IsExecutionTerminating();
7661 
7676  void CancelTerminateExecution();
7677 
7686  void RequestInterrupt(InterruptCallback callback, void* data);
7687 
7698  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
7699 
7703  void SetEventLogger(LogEventCallback that);
7704 
7711  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7712 
7716  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7717 
7725  void AddCallCompletedCallback(CallCompletedCallback callback);
7726  V8_DEPRECATED(
7727  "Use callback with parameter",
7728  void AddCallCompletedCallback(DeprecatedCallCompletedCallback callback));
7729 
7733  void RemoveCallCompletedCallback(CallCompletedCallback callback);
7734  V8_DEPRECATED("Use callback with parameter",
7735  void RemoveCallCompletedCallback(
7737 
7742  void SetPromiseHook(PromiseHook hook);
7743 
7748  void SetPromiseRejectCallback(PromiseRejectCallback callback);
7749 
7754  void RunMicrotasks();
7755 
7759  void EnqueueMicrotask(Local<Function> microtask);
7760 
7764  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
7765 
7769  void SetMicrotasksPolicy(MicrotasksPolicy policy);
7770  V8_DEPRECATED("Use SetMicrotasksPolicy",
7771  void SetAutorunMicrotasks(bool autorun));
7772 
7776  MicrotasksPolicy GetMicrotasksPolicy() const;
7777  V8_DEPRECATED("Use GetMicrotasksPolicy", bool WillAutorunMicrotasks() const);
7778 
7791  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7792 
7796  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7797 
7801  void SetUseCounterCallback(UseCounterCallback callback);
7802 
7807  void SetCounterFunction(CounterLookupCallback);
7808 
7815  void SetCreateHistogramFunction(CreateHistogramCallback);
7816  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
7817 
7832  bool IdleNotificationDeadline(double deadline_in_seconds);
7833 
7838  void LowMemoryNotification();
7839 
7849  int ContextDisposedNotification(bool dependant_context = true);
7850 
7855  void IsolateInForegroundNotification();
7856 
7861  void IsolateInBackgroundNotification();
7862 
7870  void SetRAILMode(RAILMode rail_mode);
7871 
7876  void IncreaseHeapLimitForDebugging();
7877 
7881  void RestoreOriginalHeapLimit();
7882 
7887  bool IsHeapLimitIncreasedForDebugging();
7888 
7911  void SetJitCodeEventHandler(JitCodeEventOptions options,
7912  JitCodeEventHandler event_handler);
7913 
7923  void SetStackLimit(uintptr_t stack_limit);
7924 
7938  void GetCodeRange(void** start, size_t* length_in_bytes);
7939 
7941  void SetFatalErrorHandler(FatalErrorCallback that);
7942 
7944  void SetOOMErrorHandler(OOMErrorCallback that);
7945 
7951  void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
7952 
7960  void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
7961  size_t heap_limit);
7962 
7967  void SetAllowCodeGenerationFromStringsCallback(
7969 
7974  void SetAllowWasmCodeGenerationCallback(
7976 
7981  void SetWasmModuleCallback(ExtensionCallback callback);
7982  void SetWasmInstanceCallback(ExtensionCallback callback);
7983 
7984  void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
7985 
7990  bool IsDead();
7991 
8001  bool AddMessageListener(MessageCallback that,
8002  Local<Value> data = Local<Value>());
8003 
8015  bool AddMessageListenerWithErrorLevel(MessageCallback that,
8016  int message_levels,
8017  Local<Value> data = Local<Value>());
8018 
8022  void RemoveMessageListeners(MessageCallback that);
8023 
8025  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
8026 
8031  void SetCaptureStackTraceForUncaughtExceptions(
8032  bool capture, int frame_limit = 10,
8034 
8040  void VisitExternalResources(ExternalResourceVisitor* visitor);
8041 
8046  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
8047 
8055  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
8056 
8062  void VisitWeakHandles(PersistentHandleVisitor* visitor);
8063 
8068  bool IsInUse();
8069 
8075  void SetAllowAtomicsWait(bool allow);
8076 
8077  Isolate() = delete;
8078  ~Isolate() = delete;
8079  Isolate(const Isolate&) = delete;
8080  Isolate& operator=(const Isolate&) = delete;
8081  // Deleting operator new and delete here is allowed as ctor and dtor is also
8082  // deleted.
8083  void* operator new(size_t size) = delete;
8084  void* operator new[](size_t size) = delete;
8085  void operator delete(void*, size_t) = delete;
8086  void operator delete[](void*, size_t) = delete;
8087 
8088  private:
8089  template <class K, class V, class Traits>
8091 
8092  internal::Object** GetDataFromSnapshotOnce(size_t index);
8093  void ReportExternalAllocationLimitReached();
8094  void CheckMemoryPressure();
8095 };
8096 
8098  public:
8099  const char* data;
8101 };
8102 
8103 
8108 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
8109 
8123 typedef uintptr_t (*ReturnAddressLocationResolver)(
8124  uintptr_t return_addr_location);
8125 
8126 
8130 class V8_EXPORT V8 {
8131  public:
8147  static void SetNativesDataBlob(StartupData* startup_blob);
8148  static void SetSnapshotDataBlob(StartupData* startup_blob);
8149 
8156  V8_DEPRECATED("Use SnapshotCreator",
8157  static StartupData CreateSnapshotDataBlob(
8158  const char* embedded_source = NULL));
8159 
8168  V8_DEPRECATED("Use SnapshotCreator",
8169  static StartupData WarmUpSnapshotDataBlob(
8170  StartupData cold_startup_blob, const char* warmup_source));
8171 
8173  static void SetDcheckErrorHandler(DcheckErrorCallback that);
8174 
8175 
8179  static void SetFlagsFromString(const char* str, int length);
8180 
8184  static void SetFlagsFromCommandLine(int* argc,
8185  char** argv,
8186  bool remove_flags);
8187 
8189  static const char* GetVersion();
8190 
8195  static bool Initialize();
8196 
8201  static void SetEntropySource(EntropySource source);
8202 
8207  static void SetReturnAddressLocationResolver(
8208  ReturnAddressLocationResolver return_address_resolver);
8209 
8219  static bool Dispose();
8220 
8228  static bool InitializeICU(const char* icu_data_file = nullptr);
8229 
8242  static bool InitializeICUDefaultLocation(const char* exec_path,
8243  const char* icu_data_file = nullptr);
8244 
8261  static void InitializeExternalStartupData(const char* directory_path);
8262  static void InitializeExternalStartupData(const char* natives_blob,
8263  const char* snapshot_blob);
8268  static void InitializePlatform(Platform* platform);
8269 
8274  static void ShutdownPlatform();
8275 
8276 #if V8_OS_POSIX
8277 
8296  static bool TryHandleSignal(int signal_number, void* info, void* context);
8297 #endif // V8_OS_POSIX
8298 
8303  V8_DEPRECATE_SOON("Use EnableWebAssemblyTrapHandler",
8304  static bool RegisterDefaultSignalHandler());
8305 
8312  static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
8313 
8314  private:
8315  V8();
8316 
8317  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
8318  internal::Object** handle);
8319  static internal::Object** CopyPersistent(internal::Object** handle);
8320  static void DisposeGlobal(internal::Object** global_handle);
8321  static void MakeWeak(internal::Object** location, void* data,
8322  WeakCallbackInfo<void>::Callback weak_callback,
8323  WeakCallbackType type);
8324  static void MakeWeak(internal::Object** location, void* data,
8325  // Must be 0 or -1.
8326  int internal_field_index1,
8327  // Must be 1 or -1.
8328  int internal_field_index2,
8329  WeakCallbackInfo<void>::Callback weak_callback);
8330  static void MakeWeak(internal::Object*** location_addr);
8331  static void* ClearWeak(internal::Object** location);
8332  static void AnnotateStrongRetainer(internal::Object** location,
8333  const char* label);
8334  static Value* Eternalize(Isolate* isolate, Value* handle);
8335 
8336  static void RegisterExternallyReferencedObject(internal::Object** object,
8337  internal::Isolate* isolate);
8338 
8339  template <class K, class V, class T>
8341 
8342  static void FromJustIsNothing();
8343  static void ToLocalEmpty();
8344  static void InternalFieldOutOfBounds(int index);
8345  template <class T> friend class Local;
8346  template <class T>
8347  friend class MaybeLocal;
8348  template <class T>
8349  friend class Maybe;
8350  template <class T>
8351  friend class WeakCallbackInfo;
8352  template <class T> friend class Eternal;
8353  template <class T> friend class PersistentBase;
8354  template <class T, class M> friend class Persistent;
8355  friend class Context;
8356 };
8357 
8362  public:
8363  enum class FunctionCodeHandling { kClear, kKeep };
8364 
8373  SnapshotCreator(Isolate* isolate,
8374  const intptr_t* external_references = nullptr,
8375  StartupData* existing_blob = nullptr);
8376 
8385  SnapshotCreator(const intptr_t* external_references = nullptr,
8386  StartupData* existing_blob = nullptr);
8387 
8388  ~SnapshotCreator();
8389 
8393  Isolate* GetIsolate();
8394 
8402  void SetDefaultContext(Local<Context> context,
8405 
8414  size_t AddContext(Local<Context> context,
8417 
8422  size_t AddTemplate(Local<Template> template_obj);
8423 
8430  template <class T>
8431  V8_INLINE size_t AddData(Local<Context> context, Local<T> object);
8432 
8439  template <class T>
8440  V8_INLINE size_t AddData(Local<T> object);
8441 
8450  StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8451 
8452  // Disallow copying and assigning.
8453  SnapshotCreator(const SnapshotCreator&) = delete;
8454  void operator=(const SnapshotCreator&) = delete;
8455 
8456  private:
8457  size_t AddData(Local<Context> context, internal::Object* object);
8458  size_t AddData(internal::Object* object);
8459 
8460  void* data_;
8461 };
8462 
8473 template <class T>
8474 class Maybe {
8475  public:
8476  V8_INLINE bool IsNothing() const { return !has_value_; }
8477  V8_INLINE bool IsJust() const { return has_value_; }
8478 
8482  V8_INLINE T ToChecked() const { return FromJust(); }
8483 
8488  V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
8489  if (V8_LIKELY(IsJust())) *out = value_;
8490  return IsJust();
8491  }
8492 
8497  V8_INLINE T FromJust() const {
8498  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8499  return value_;
8500  }
8501 
8506  V8_INLINE T FromMaybe(const T& default_value) const {
8507  return has_value_ ? value_ : default_value;
8508  }
8509 
8510  V8_INLINE bool operator==(const Maybe& other) const {
8511  return (IsJust() == other.IsJust()) &&
8512  (!IsJust() || FromJust() == other.FromJust());
8513  }
8514 
8515  V8_INLINE bool operator!=(const Maybe& other) const {
8516  return !operator==(other);
8517  }
8518 
8519  private:
8520  Maybe() : has_value_(false) {}
8521  explicit Maybe(const T& t) : has_value_(true), value_(t) {}
8522 
8523  bool has_value_;
8524  T value_;
8525 
8526  template <class U>
8527  friend Maybe<U> Nothing();
8528  template <class U>
8529  friend Maybe<U> Just(const U& u);
8530 };
8531 
8532 template <class T>
8533 inline Maybe<T> Nothing() {
8534  return Maybe<T>();
8535 }
8536 
8537 template <class T>
8538 inline Maybe<T> Just(const T& t) {
8539  return Maybe<T>(t);
8540 }
8541 
8542 // A template specialization of Maybe<T> for the case of T = void.
8543 template <>
8544 class Maybe<void> {
8545  public:
8546  V8_INLINE bool IsNothing() const { return !is_valid_; }
8547  V8_INLINE bool IsJust() const { return is_valid_; }
8548 
8549  V8_INLINE bool operator==(const Maybe& other) const {
8550  return IsJust() == other.IsJust();
8551  }
8552 
8553  V8_INLINE bool operator!=(const Maybe& other) const {
8554  return !operator==(other);
8555  }
8556 
8557  private:
8558  struct JustTag {};
8559 
8560  Maybe() : is_valid_(false) {}
8561  explicit Maybe(JustTag) : is_valid_(true) {}
8562 
8563  bool is_valid_;
8564 
8565  template <class U>
8566  friend Maybe<U> Nothing();
8567  friend Maybe<void> JustVoid();
8568 };
8569 
8571 
8576  public:
8582  explicit TryCatch(Isolate* isolate);
8583 
8587  ~TryCatch();
8588 
8592  bool HasCaught() const;
8593 
8602  bool CanContinue() const;
8603 
8616  bool HasTerminated() const;
8617 
8625  Local<Value> ReThrow();
8626 
8633  Local<Value> Exception() const;
8634 
8639  V8_DEPRECATED("Use maybe version.", Local<Value> StackTrace() const);
8641  Local<Context> context) const;
8642 
8650  Local<v8::Message> Message() const;
8651 
8662  void Reset();
8663 
8672  void SetVerbose(bool value);
8673 
8677  bool IsVerbose() const;
8678 
8684  void SetCaptureMessage(bool value);
8685 
8697  static void* JSStackComparableAddress(TryCatch* handler) {
8698  if (handler == NULL) return NULL;
8699  return handler->js_stack_comparable_address_;
8700  }
8701 
8702  TryCatch(const TryCatch&) = delete;
8703  void operator=(const TryCat