V8 API Reference Guide generated from the header files
v8.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "v8-version.h" // NOLINT(build/include)
26 #include "v8config.h" // NOLINT(build/include)
27 
28 // We reserve the V8_* prefix for macros defined in V8 public API and
29 // assume there are no name conflicts with the embedder's code.
30 
31 #ifdef V8_OS_WIN
32 
33 // Setup for Windows DLL export/import. When building the V8 DLL the
34 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
35 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
36 // static library or building a program which uses the V8 static library neither
37 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
38 #ifdef BUILDING_V8_SHARED
39 # define V8_EXPORT __declspec(dllexport)
40 #elif USING_V8_SHARED
41 # define V8_EXPORT __declspec(dllimport)
42 #else
43 # define V8_EXPORT
44 #endif // BUILDING_V8_SHARED
45 
46 #else // V8_OS_WIN
47 
48 // Setup for Linux shared library export.
49 #if V8_HAS_ATTRIBUTE_VISIBILITY
50 # ifdef BUILDING_V8_SHARED
51 # define V8_EXPORT __attribute__ ((visibility("default")))
52 # else
53 # define V8_EXPORT
54 # endif
55 #else
56 # define V8_EXPORT
57 #endif
58 
59 #endif // V8_OS_WIN
60 
64 namespace v8 {
65 
66 class AccessorSignature;
67 class Array;
68 class ArrayBuffer;
69 class BigInt;
70 class BigIntObject;
71 class Boolean;
72 class BooleanObject;
73 class Context;
74 class Data;
75 class Date;
76 class External;
77 class Function;
78 class FunctionTemplate;
79 class HeapProfiler;
80 class ImplementationUtilities;
81 class Int32;
82 class Integer;
83 class Isolate;
84 template <class T>
85 class Maybe;
86 class Name;
87 class Number;
88 class NumberObject;
89 class Object;
90 class ObjectOperationDescriptor;
91 class ObjectTemplate;
92 class Platform;
93 class Primitive;
94 class Promise;
95 class PropertyDescriptor;
96 class Proxy;
97 class RawOperationDescriptor;
98 class Script;
99 class SharedArrayBuffer;
100 class Signature;
101 class StartupData;
102 class StackFrame;
103 class StackTrace;
104 class String;
105 class StringObject;
106 class Symbol;
107 class SymbolObject;
108 class PrimitiveArray;
109 class Private;
110 class Uint32;
111 class Utils;
112 class Value;
113 class WasmCompiledModule;
114 template <class T> class Local;
115 template <class T>
117 template <class T> class Eternal;
118 template<class T> class NonCopyablePersistentTraits;
119 template<class T> class PersistentBase;
120 template <class T, class M = NonCopyablePersistentTraits<T> >
122 template <class T>
123 class Global;
124 template<class K, class V, class T> class PersistentValueMap;
125 template <class K, class V, class T>
127 template <class K, class V, class T>
128 class GlobalValueMap;
129 template<class V, class T> class PersistentValueVector;
130 template<class T, class P> class WeakCallbackObject;
131 class FunctionTemplate;
132 class ObjectTemplate;
133 template<typename T> class FunctionCallbackInfo;
134 template<typename T> class PropertyCallbackInfo;
135 class StackTrace;
136 class StackFrame;
137 class Isolate;
138 class CallHandlerHelper;
140 template<typename T> class ReturnValue;
141 
142 namespace internal {
143 class Arguments;
144 class DeferredHandles;
145 class Heap;
146 class HeapObject;
147 class Isolate;
148 class LocalEmbedderHeapTracer;
149 class 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 CompilationResultResolver;
158 class StreamingDecoder;
159 } // namespace wasm
160 
164 const int kApiPointerSize = sizeof(void*); // NOLINT
165 const int kApiDoubleSize = sizeof(double); // NOLINT
166 const int kApiIntSize = sizeof(int); // NOLINT
167 const int kApiInt64Size = sizeof(int64_t); // NOLINT
168 
169 // Tag information for HeapObject.
170 const int kHeapObjectTag = 1;
171 const int kWeakHeapObjectTag = 3;
172 const int kHeapObjectTagSize = 2;
173 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
174 
175 // Tag information for Smi.
176 const int kSmiTag = 0;
177 const int kSmiTagSize = 1;
178 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
179 
180 template <size_t tagged_ptr_size>
181 struct SmiTagging;
182 
183 template <int kSmiShiftSize>
184 V8_INLINE internal::Object* IntToSmi(int value) {
185  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
186  intptr_t tagged_value =
187  (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
188  return reinterpret_cast<internal::Object*>(tagged_value);
189 }
190 
191 // Smi constants for systems where tagged pointer is a 32-bit value.
192 template <>
193 struct SmiTagging<4> {
194  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
195  static int SmiShiftSize() { return kSmiShiftSize; }
196  static int SmiValueSize() { return kSmiValueSize; }
197  V8_INLINE static int SmiToInt(const internal::Object* value) {
198  int shift_bits = kSmiTagSize + kSmiShiftSize;
199  // Throw away top 32 bits and shift down (requires >> to be sign extending).
200  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
201  }
202  V8_INLINE static internal::Object* IntToSmi(int value) {
203  return internal::IntToSmi<kSmiShiftSize>(value);
204  }
205  V8_INLINE static bool IsValidSmi(intptr_t value) {
206  // To be representable as an tagged small integer, the two
207  // most-significant bits of 'value' must be either 00 or 11 due to
208  // sign-extension. To check this we add 01 to the two
209  // most-significant bits, and check if the most-significant bit is 0
210  //
211  // CAUTION: The original code below:
212  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
213  // may lead to incorrect results according to the C language spec, and
214  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
215  // compiler may produce undefined results in case of signed integer
216  // overflow. The computation must be done w/ unsigned ints.
217  return static_cast<uintptr_t>(value) + 0x40000000U < 0x80000000U;
218  }
219 };
220 
221 // Smi constants for systems where tagged pointer is a 64-bit value.
222 template <>
223 struct SmiTagging<8> {
224  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
225  static int SmiShiftSize() { return kSmiShiftSize; }
226  static int SmiValueSize() { return kSmiValueSize; }
227  V8_INLINE static int SmiToInt(const internal::Object* value) {
228  int shift_bits = kSmiTagSize + kSmiShiftSize;
229  // Shift down and throw away top 32 bits.
230  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
231  }
232  V8_INLINE static internal::Object* IntToSmi(int value) {
233  return internal::IntToSmi<kSmiShiftSize>(value);
234  }
235  V8_INLINE static bool IsValidSmi(intptr_t value) {
236  // To be representable as a long smi, the value must be a 32-bit integer.
237  return (value == static_cast<int32_t>(value));
238  }
239 };
240 
241 #if V8_COMPRESS_POINTERS
242 static_assert(
243  kApiPointerSize == kApiInt64Size,
244  "Pointer compression can be enabled only for 64-bit architectures");
246 #else
248 #endif
249 
250 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
251 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
252 const int kSmiMinValue = (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
253 const int kSmiMaxValue = -(kSmiMinValue + 1);
254 constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
255 constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
256 
257 } // namespace internal
258 
259 namespace debug {
260 class ConsoleCallArguments;
261 } // namespace debug
262 
263 // --- Handles ---
264 
265 #define TYPE_CHECK(T, S) \
266  while (false) { \
267  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
268  }
269 
301 template <class T>
302 class Local {
303  public:
304  V8_INLINE Local() : val_(0) {}
305  template <class S>
306  V8_INLINE Local(Local<S> that)
307  : val_(reinterpret_cast<T*>(*that)) {
313  TYPE_CHECK(T, S);
314  }
315 
319  V8_INLINE bool IsEmpty() const { return val_ == 0; }
320 
324  V8_INLINE void Clear() { val_ = 0; }
325 
326  V8_INLINE T* operator->() const { return val_; }
327 
328  V8_INLINE T* operator*() const { return val_; }
329 
336  template <class S>
337  V8_INLINE bool operator==(const Local<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 
345  template <class S> V8_INLINE bool operator==(
346  const PersistentBase<S>& that) const {
347  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
348  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
349  if (a == 0) return b == 0;
350  if (b == 0) return false;
351  return *a == *b;
352  }
353 
360  template <class S>
361  V8_INLINE bool operator!=(const Local<S>& that) const {
362  return !operator==(that);
363  }
364 
365  template <class S> V8_INLINE bool operator!=(
366  const Persistent<S>& that) const {
367  return !operator==(that);
368  }
369 
375  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
376 #ifdef V8_ENABLE_CHECKS
377  // If we're going to perform the type check then we have to check
378  // that the handle isn't empty before doing the checked cast.
379  if (that.IsEmpty()) return Local<T>();
380 #endif
381  return Local<T>(T::Cast(*that));
382  }
383 
389  template <class S>
390  V8_INLINE Local<S> As() const {
391  return Local<S>::Cast(*this);
392  }
393 
399  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
400  V8_INLINE static Local<T> New(Isolate* isolate,
401  const PersistentBase<T>& that);
402 
403  private:
404  friend class Utils;
405  template<class F> friend class Eternal;
406  template<class F> friend class PersistentBase;
407  template<class F, class M> friend class Persistent;
408  template<class F> friend class Local;
409  template <class F>
410  friend class MaybeLocal;
411  template<class F> friend class FunctionCallbackInfo;
412  template<class F> friend class PropertyCallbackInfo;
413  friend class String;
414  friend class Object;
415  friend class Context;
416  friend class Isolate;
417  friend class Private;
418  template<class F> friend class internal::CustomArguments;
419  friend Local<Primitive> Undefined(Isolate* isolate);
420  friend Local<Primitive> Null(Isolate* isolate);
421  friend Local<Boolean> True(Isolate* isolate);
422  friend Local<Boolean> False(Isolate* isolate);
423  friend class HandleScope;
424  friend class EscapableHandleScope;
425  template <class F1, class F2, class F3>
426  friend class PersistentValueMapBase;
427  template<class F1, class F2> friend class PersistentValueVector;
428  template <class F>
429  friend class ReturnValue;
430 
431  explicit V8_INLINE Local(T* that) : val_(that) {}
432  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
433  T* val_;
434 };
435 
436 
437 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
438 // Handle is an alias for Local for historical reasons.
439 template <class T>
440 using Handle = Local<T>;
441 #endif
442 
443 
454 template <class T>
455 class MaybeLocal {
456  public:
457  V8_INLINE MaybeLocal() : val_(nullptr) {}
458  template <class S>
459  V8_INLINE MaybeLocal(Local<S> that)
460  : val_(reinterpret_cast<T*>(*that)) {
461  TYPE_CHECK(T, S);
462  }
463 
464  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
465 
470  template <class S>
471  V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
472  out->val_ = IsEmpty() ? nullptr : this->val_;
473  return !IsEmpty();
474  }
475 
480  V8_INLINE Local<T> ToLocalChecked();
481 
486  template <class S>
487  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
488  return IsEmpty() ? default_value : Local<S>(val_);
489  }
490 
491  private:
492  T* val_;
493 };
494 
499 template <class T> class Eternal {
500  public:
501  V8_INLINE Eternal() : val_(nullptr) {}
502  template <class S>
503  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
504  Set(isolate, handle);
505  }
506  // Can only be safely called if already set.
507  V8_INLINE Local<T> Get(Isolate* isolate) const;
508  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
509  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
510 
511  private:
512  T* val_;
513 };
514 
515 
516 static const int kInternalFieldsInWeakCallback = 2;
517 static const int kEmbedderFieldsInWeakCallback = 2;
518 
519 template <typename T>
521  public:
522  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
523 
524  WeakCallbackInfo(Isolate* isolate, T* parameter,
525  void* embedder_fields[kEmbedderFieldsInWeakCallback],
526  Callback* callback)
527  : isolate_(isolate), parameter_(parameter), callback_(callback) {
528  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
529  embedder_fields_[i] = embedder_fields[i];
530  }
531  }
532 
533  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
534  V8_INLINE T* GetParameter() const { return parameter_; }
535  V8_INLINE void* GetInternalField(int index) const;
536 
537  // When first called, the embedder MUST Reset() the Global which triggered the
538  // callback. The Global itself is unusable for anything else. No v8 other api
539  // calls may be called in the first callback. Should additional work be
540  // required, the embedder must set a second pass callback, which will be
541  // called after all the initial callbacks are processed.
542  // Calling SetSecondPassCallback on the second pass will immediately crash.
543  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
544 
545  private:
546  Isolate* isolate_;
547  T* parameter_;
548  Callback* callback_;
549  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
550 };
551 
552 
553 // kParameter will pass a void* parameter back to the callback, kInternalFields
554 // will pass the first two internal fields back to the callback, kFinalizer
555 // will pass a void* parameter back, but is invoked before the object is
556 // actually collected, so it can be resurrected. In the last case, it is not
557 // possible to request a second pass callback.
558 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };
559 
573 template <class T> class PersistentBase {
574  public:
579  V8_INLINE void Reset();
584  template <class S>
585  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
586 
591  template <class S>
592  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
593 
594  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
595  V8_INLINE void Empty() { val_ = 0; }
596 
597  V8_INLINE Local<T> Get(Isolate* isolate) const {
598  return Local<T>::New(isolate, *this);
599  }
600 
601  template <class S>
602  V8_INLINE bool operator==(const PersistentBase<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 Local<S>& that) const {
612  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
613  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
614  if (a == NULL) return b == NULL;
615  if (b == NULL) return false;
616  return *a == *b;
617  }
618 
619  template <class S>
620  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
621  return !operator==(that);
622  }
623 
624  template <class S>
625  V8_INLINE bool operator!=(const Local<S>& that) const {
626  return !operator==(that);
627  }
628 
636  template <typename P>
637  V8_INLINE void SetWeak(P* parameter,
638  typename WeakCallbackInfo<P>::Callback callback,
639  WeakCallbackType type);
640 
648  V8_INLINE void SetWeak();
649 
650  template<typename P>
651  V8_INLINE P* ClearWeak();
652 
653  // TODO(dcarney): remove this.
654  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
655 
662  V8_INLINE void AnnotateStrongRetainer(const char* label);
663 
669  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
670 
678  "Objects are always considered independent. "
679  "Use MarkActive to avoid collecting otherwise dead weak handles.",
680  V8_INLINE void MarkIndependent());
681 
689  V8_INLINE void MarkActive();
690 
691  V8_DEPRECATE_SOON("See MarkIndependent.",
692  V8_INLINE bool IsIndependent() const);
693 
695  V8_INLINE bool IsNearDeath() const;
696 
698  V8_INLINE bool IsWeak() const;
699 
704  V8_INLINE void SetWrapperClassId(uint16_t class_id);
705 
710  V8_INLINE uint16_t WrapperClassId() const;
711 
712  PersistentBase(const PersistentBase& other) = delete; // NOLINT
713  void operator=(const PersistentBase&) = delete;
714 
715  private:
716  friend class Isolate;
717  friend class Utils;
718  template<class F> friend class Local;
719  template<class F1, class F2> friend class Persistent;
720  template <class F>
721  friend class Global;
722  template<class F> friend class PersistentBase;
723  template<class F> friend class ReturnValue;
724  template <class F1, class F2, class F3>
725  friend class PersistentValueMapBase;
726  template<class F1, class F2> friend class PersistentValueVector;
727  friend class Object;
728 
729  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
730  V8_INLINE static T* New(Isolate* isolate, T* that);
731 
732  T* val_;
733 };
734 
735 
742 template<class T>
743 class NonCopyablePersistentTraits {
744  public:
745  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
746  static const bool kResetInDestructor = false;
747  template<class S, class M>
748  V8_INLINE static void Copy(const Persistent<S, M>& source,
749  NonCopyablePersistent* dest) {
750  Uncompilable<Object>();
751  }
752  // TODO(dcarney): come up with a good compile error here.
753  template<class O> V8_INLINE static void Uncompilable() {
754  TYPE_CHECK(O, Primitive);
755  }
756 };
757 
758 
763 template<class T>
766  static const bool kResetInDestructor = true;
767  template<class S, class M>
768  static V8_INLINE void Copy(const Persistent<S, M>& source,
769  CopyablePersistent* dest) {
770  // do nothing, just allow copy
771  }
772 };
773 
774 
783 template <class T, class M> class Persistent : public PersistentBase<T> {
784  public:
788  V8_INLINE Persistent() : PersistentBase<T>(0) { }
794  template <class S>
795  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
796  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
797  TYPE_CHECK(T, S);
798  }
804  template <class S, class M2>
805  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
806  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
807  TYPE_CHECK(T, S);
808  }
815  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
816  Copy(that);
817  }
818  template <class S, class M2>
819  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
820  Copy(that);
821  }
822  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
823  Copy(that);
824  return *this;
825  }
826  template <class S, class M2>
827  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
828  Copy(that);
829  return *this;
830  }
836  V8_INLINE ~Persistent() {
837  if (M::kResetInDestructor) this->Reset();
838  }
839 
840  // TODO(dcarney): this is pretty useless, fix or remove
841  template <class S>
842  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
843 #ifdef V8_ENABLE_CHECKS
844  // If we're going to perform the type check then we have to check
845  // that the handle isn't empty before doing the checked cast.
846  if (!that.IsEmpty()) T::Cast(*that);
847 #endif
848  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
849  }
850 
851  // TODO(dcarney): this is pretty useless, fix or remove
852  template <class S>
853  V8_INLINE Persistent<S>& As() const { // NOLINT
854  return Persistent<S>::Cast(*this);
855  }
856 
857  private:
858  friend class Isolate;
859  friend class Utils;
860  template<class F> friend class Local;
861  template<class F1, class F2> friend class Persistent;
862  template<class F> friend class ReturnValue;
863 
864  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
865  V8_INLINE T* operator*() const { return this->val_; }
866  template<class S, class M2>
867  V8_INLINE void Copy(const Persistent<S, M2>& that);
868 };
869 
870 
876 template <class T>
877 class Global : public PersistentBase<T> {
878  public:
882  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
888  template <class S>
889  V8_INLINE Global(Isolate* isolate, Local<S> that)
890  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
891  TYPE_CHECK(T, S);
892  }
898  template <class S>
899  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
900  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
901  TYPE_CHECK(T, S);
902  }
906  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
907  other.val_ = nullptr;
908  }
909  V8_INLINE ~Global() { this->Reset(); }
913  template <class S>
914  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
915  TYPE_CHECK(T, S);
916  if (this != &rhs) {
917  this->Reset();
918  this->val_ = rhs.val_;
919  rhs.val_ = nullptr;
920  }
921  return *this;
922  }
926  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
927 
928  /*
929  * For compatibility with Chromium's base::Bind (base::Passed).
930  */
931  typedef void MoveOnlyTypeForCPP03;
932 
933  Global(const Global&) = delete;
934  void operator=(const Global&) = delete;
935 
936  private:
937  template <class F>
938  friend class ReturnValue;
939  V8_INLINE T* operator*() const { return this->val_; }
940 };
941 
942 
943 // UniquePersistent is an alias for Global for historical reason.
944 template <class T>
945 using UniquePersistent = Global<T>;
946 
947 
962 class V8_EXPORT HandleScope {
963  public:
964  explicit HandleScope(Isolate* isolate);
965 
966  ~HandleScope();
967 
971  static int NumberOfHandles(Isolate* isolate);
972 
973  V8_INLINE Isolate* GetIsolate() const {
974  return reinterpret_cast<Isolate*>(isolate_);
975  }
976 
977  HandleScope(const HandleScope&) = delete;
978  void operator=(const HandleScope&) = delete;
979 
980  protected:
981  V8_INLINE HandleScope() {}
982 
983  void Initialize(Isolate* isolate);
984 
985  static internal::Object** CreateHandle(internal::Isolate* isolate,
986  internal::Object* value);
987 
988  private:
989  // Declaring operator new and delete as deleted is not spec compliant.
990  // Therefore declare them private instead to disable dynamic alloc
991  void* operator new(size_t size);
992  void* operator new[](size_t size);
993  void operator delete(void*, size_t);
994  void operator delete[](void*, size_t);
995 
996  // Uses heap_object to obtain the current Isolate.
997  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
998  internal::Object* value);
999 
1000  internal::Isolate* isolate_;
1001  internal::Object** prev_next_;
1002  internal::Object** prev_limit_;
1003 
1004  // Local::New uses CreateHandle with an Isolate* parameter.
1005  template<class F> friend class Local;
1006 
1007  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
1008  // a HeapObject* in their shortcuts.
1009  friend class Object;
1010  friend class Context;
1011 };
1012 
1013 
1018 class V8_EXPORT EscapableHandleScope : public HandleScope {
1019  public:
1020  explicit EscapableHandleScope(Isolate* isolate);
1021  V8_INLINE ~EscapableHandleScope() {}
1022 
1027  template <class T>
1028  V8_INLINE Local<T> Escape(Local<T> value) {
1029  internal::Object** slot =
1030  Escape(reinterpret_cast<internal::Object**>(*value));
1031  return Local<T>(reinterpret_cast<T*>(slot));
1032  }
1033 
1034  template <class T>
1035  V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) {
1036  return Escape(value.FromMaybe(Local<T>()));
1037  }
1038 
1039  EscapableHandleScope(const EscapableHandleScope&) = delete;
1040  void operator=(const EscapableHandleScope&) = delete;
1041 
1042  private:
1043  // Declaring operator new and delete as deleted is not spec compliant.
1044  // Therefore declare them private instead to disable dynamic alloc
1045  void* operator new(size_t size);
1046  void* operator new[](size_t size);
1047  void operator delete(void*, size_t);
1048  void operator delete[](void*, size_t);
1049 
1050  internal::Object** Escape(internal::Object** escape_value);
1051  internal::Object** escape_slot_;
1052 };
1053 
1059 class V8_EXPORT SealHandleScope {
1060  public:
1061  explicit SealHandleScope(Isolate* isolate);
1062  ~SealHandleScope();
1063 
1064  SealHandleScope(const SealHandleScope&) = delete;
1065  void operator=(const SealHandleScope&) = delete;
1066 
1067  private:
1068  // Declaring operator new and delete as deleted is not spec compliant.
1069  // Therefore declare them private instead to disable dynamic alloc
1070  void* operator new(size_t size);
1071  void* operator new[](size_t size);
1072  void operator delete(void*, size_t);
1073  void operator delete[](void*, size_t);
1074 
1075  internal::Isolate* const isolate_;
1076  internal::Object** prev_limit_;
1077  int prev_sealed_level_;
1078 };
1079 
1080 
1081 // --- Special objects ---
1082 
1083 
1087 class V8_EXPORT Data {
1088  private:
1089  Data();
1090 };
1091 
1098 class V8_EXPORT ScriptOrModule {
1099  public:
1104  Local<Value> GetResourceName();
1105 
1110  Local<PrimitiveArray> GetHostDefinedOptions();
1111 };
1112 
1121 class V8_EXPORT PrimitiveArray {
1122  public:
1123  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1124  int Length() const;
1125  void Set(int index, Local<Primitive> item);
1126  Local<Primitive> Get(int index);
1127 };
1128 
1133  public:
1134  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1135  bool is_opaque = false, bool is_wasm = false,
1136  bool is_module = false)
1137  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1138  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1139  (is_module ? kIsModule : 0)) {}
1140  V8_INLINE ScriptOriginOptions(int flags)
1141  : flags_(flags &
1142  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1143 
1144  bool IsSharedCrossOrigin() const {
1145  return (flags_ & kIsSharedCrossOrigin) != 0;
1146  }
1147  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1148  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1149  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1150 
1151  int Flags() const { return flags_; }
1152 
1153  private:
1154  enum {
1155  kIsSharedCrossOrigin = 1,
1156  kIsOpaque = 1 << 1,
1157  kIsWasm = 1 << 2,
1158  kIsModule = 1 << 3
1159  };
1160  const int flags_;
1161 };
1162 
1167  public:
1168  V8_INLINE ScriptOrigin(
1169  Local<Value> resource_name,
1170  Local<Integer> resource_line_offset = Local<Integer>(),
1171  Local<Integer> resource_column_offset = Local<Integer>(),
1172  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1173  Local<Integer> script_id = Local<Integer>(),
1174  Local<Value> source_map_url = Local<Value>(),
1175  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1176  Local<Boolean> is_wasm = Local<Boolean>(),
1177  Local<Boolean> is_module = Local<Boolean>(),
1178  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1179 
1180  V8_INLINE Local<Value> ResourceName() const;
1181  V8_INLINE Local<Integer> ResourceLineOffset() const;
1182  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1183  V8_INLINE Local<Integer> ScriptID() const;
1184  V8_INLINE Local<Value> SourceMapUrl() const;
1185  V8_INLINE Local<PrimitiveArray> HostDefinedOptions() const;
1186  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1187 
1188  private:
1189  Local<Value> resource_name_;
1190  Local<Integer> resource_line_offset_;
1191  Local<Integer> resource_column_offset_;
1192  ScriptOriginOptions options_;
1193  Local<Integer> script_id_;
1194  Local<Value> source_map_url_;
1195  Local<PrimitiveArray> host_defined_options_;
1196 };
1197 
1201 class V8_EXPORT UnboundScript {
1202  public:
1206  Local<Script> BindToCurrentContext();
1207 
1208  int GetId();
1209  Local<Value> GetScriptName();
1210 
1214  Local<Value> GetSourceURL();
1218  Local<Value> GetSourceMappingURL();
1219 
1224  int GetLineNumber(int code_pos);
1225 
1226  static const int kNoScriptId = 0;
1227 };
1228 
1232 class V8_EXPORT UnboundModuleScript {
1233  // Only used as a container for code caching.
1234 };
1235 
1239 class V8_EXPORT Location {
1240  public:
1241  int GetLineNumber() { return line_number_; }
1242  int GetColumnNumber() { return column_number_; }
1243 
1244  Location(int line_number, int column_number)
1245  : line_number_(line_number), column_number_(column_number) {}
1246 
1247  private:
1248  int line_number_;
1249  int column_number_;
1250 };
1251 
1255 class V8_EXPORT Module {
1256  public:
1264  enum Status {
1265  kUninstantiated,
1266  kInstantiating,
1267  kInstantiated,
1268  kEvaluating,
1269  kEvaluated,
1270  kErrored
1271  };
1272 
1276  Status GetStatus() const;
1277 
1281  Local<Value> GetException() const;
1282 
1286  int GetModuleRequestsLength() const;
1287 
1292  Local<String> GetModuleRequest(int i) const;
1293 
1298  Location GetModuleRequestLocation(int i) const;
1299 
1303  int GetIdentityHash() const;
1304 
1305  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1306  Local<String> specifier,
1307  Local<Module> referrer);
1308 
1316  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1317  ResolveCallback callback);
1318 
1327  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
1328 
1334  Local<Value> GetModuleNamespace();
1335 
1342  Local<UnboundModuleScript> GetUnboundModuleScript();
1343 };
1344 
1349 class V8_EXPORT Script {
1350  public:
1354  static V8_DEPRECATED("Use maybe version",
1355  Local<Script> Compile(Local<String> source,
1356  ScriptOrigin* origin = nullptr));
1357  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1358  Local<Context> context, Local<String> source,
1359  ScriptOrigin* origin = nullptr);
1360 
1361  static Local<Script> V8_DEPRECATED("Use maybe version",
1362  Compile(Local<String> source,
1363  Local<String> file_name));
1364 
1370  V8_DEPRECATED("Use maybe version", Local<Value> Run());
1371  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1372 
1376  Local<UnboundScript> GetUnboundScript();
1377 };
1378 
1379 
1383 class V8_EXPORT ScriptCompiler {
1384  public:
1392  struct V8_EXPORT CachedData {
1393  enum BufferPolicy {
1394  BufferNotOwned,
1395  BufferOwned
1396  };
1397 
1398  CachedData()
1399  : data(NULL),
1400  length(0),
1401  rejected(false),
1402  buffer_policy(BufferNotOwned) {}
1403 
1404  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1405  // data and guarantees that it stays alive until the CachedData object is
1406  // destroyed. If the policy is BufferOwned, the given data will be deleted
1407  // (with delete[]) when the CachedData object is destroyed.
1408  CachedData(const uint8_t* data, int length,
1409  BufferPolicy buffer_policy = BufferNotOwned);
1410  ~CachedData();
1411  // TODO(marja): Async compilation; add constructors which take a callback
1412  // which will be called when V8 no longer needs the data.
1413  const uint8_t* data;
1414  int length;
1415  bool rejected;
1416  BufferPolicy buffer_policy;
1417 
1418  // Prevent copying.
1419  CachedData(const CachedData&) = delete;
1420  CachedData& operator=(const CachedData&) = delete;
1421  };
1422 
1426  class Source {
1427  public:
1428  // Source takes ownership of CachedData.
1429  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1430  CachedData* cached_data = NULL);
1431  V8_INLINE Source(Local<String> source_string,
1432  CachedData* cached_data = NULL);
1433  V8_INLINE ~Source();
1434 
1435  // Ownership of the CachedData or its buffers is *not* transferred to the
1436  // caller. The CachedData object is alive as long as the Source object is
1437  // alive.
1438  V8_INLINE const CachedData* GetCachedData() const;
1439 
1440  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1441 
1442  // Prevent copying.
1443  Source(const Source&) = delete;
1444  Source& operator=(const Source&) = delete;
1445 
1446  private:
1447  friend class ScriptCompiler;
1448 
1449  Local<String> source_string;
1450 
1451  // Origin information
1452  Local<Value> resource_name;
1453  Local<Integer> resource_line_offset;
1454  Local<Integer> resource_column_offset;
1455  ScriptOriginOptions resource_options;
1456  Local<Value> source_map_url;
1457  Local<PrimitiveArray> host_defined_options;
1458 
1459  // Cached data from previous compilation (if a kConsume*Cache flag is
1460  // set), or hold newly generated cache data (kProduce*Cache flags) are
1461  // set when calling a compile method.
1462  CachedData* cached_data;
1463  };
1464 
1469  class V8_EXPORT ExternalSourceStream {
1470  public:
1471  virtual ~ExternalSourceStream() {}
1472 
1494  virtual size_t GetMoreData(const uint8_t** src) = 0;
1495 
1506  virtual bool SetBookmark();
1507 
1511  virtual void ResetToBookmark();
1512  };
1513 
1514 
1521  class V8_EXPORT StreamedSource {
1522  public:
1523  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1524 
1525  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1526  ~StreamedSource();
1527 
1528  // Ownership of the CachedData or its buffers is *not* transferred to the
1529  // caller. The CachedData object is alive as long as the StreamedSource
1530  // object is alive.
1531  const CachedData* GetCachedData() const;
1532 
1533  internal::ScriptStreamingData* impl() const { return impl_; }
1534 
1535  // Prevent copying.
1536  StreamedSource(const StreamedSource&) = delete;
1537  StreamedSource& operator=(const StreamedSource&) = delete;
1538 
1539  private:
1540  internal::ScriptStreamingData* impl_;
1541  };
1542 
1548  public:
1549  virtual ~ScriptStreamingTask() {}
1550  virtual void Run() = 0;
1551  };
1552 
1553  enum CompileOptions {
1554  kNoCompileOptions = 0,
1555  kProduceParserCache,
1556  kConsumeParserCache,
1557  kProduceCodeCache,
1558  kProduceFullCodeCache,
1559  kConsumeCodeCache,
1560  kEagerCompile
1561  };
1562 
1567  kNoCacheNoReason = 0,
1568  kNoCacheBecauseCachingDisabled,
1569  kNoCacheBecauseNoResource,
1570  kNoCacheBecauseInlineScript,
1571  kNoCacheBecauseModule,
1572  kNoCacheBecauseStreamingSource,
1573  kNoCacheBecauseInspector,
1574  kNoCacheBecauseScriptTooSmall,
1575  kNoCacheBecauseCacheTooCold,
1576  kNoCacheBecauseV8Extension,
1577  kNoCacheBecauseExtensionModule,
1578  kNoCacheBecausePacScript,
1579  kNoCacheBecauseInDocumentWrite,
1580  kNoCacheBecauseResourceWithNoCacheHandler,
1581  kNoCacheBecauseDeferredProduceCodeCache
1582  };
1583 
1597  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1598  Isolate* isolate, Source* source,
1599  CompileOptions options = kNoCompileOptions,
1600  NoCacheReason no_cache_reason = kNoCacheNoReason);
1601 
1613  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1614  Local<Context> context, Source* source,
1615  CompileOptions options = kNoCompileOptions,
1616  NoCacheReason no_cache_reason = kNoCacheNoReason);
1617 
1629  static ScriptStreamingTask* StartStreamingScript(
1630  Isolate* isolate, StreamedSource* source,
1631  CompileOptions options = kNoCompileOptions);
1632 
1640  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1641  Local<Context> context, StreamedSource* source,
1642  Local<String> full_source_string, const ScriptOrigin& origin);
1643 
1662  static uint32_t CachedDataVersionTag();
1663 
1671  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1672  Isolate* isolate, Source* source,
1673  CompileOptions options = kNoCompileOptions,
1674  NoCacheReason no_cache_reason = kNoCacheNoReason);
1675 
1686  static V8_DEPRECATED("Use maybe version",
1687  Local<Function> CompileFunctionInContext(
1688  Isolate* isolate, Source* source,
1689  Local<Context> context, size_t arguments_count,
1690  Local<String> arguments[],
1691  size_t context_extension_count,
1692  Local<Object> context_extensions[]));
1693  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1694  Local<Context> context, Source* source, size_t arguments_count,
1695  Local<String> arguments[], size_t context_extension_count,
1696  Local<Object> context_extensions[],
1697  CompileOptions options = kNoCompileOptions,
1698  NoCacheReason no_cache_reason = kNoCacheNoReason);
1699 
1705  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
1706 
1712  static CachedData* CreateCodeCache(
1713  Local<UnboundModuleScript> unbound_module_script);
1714 
1715  V8_DEPRECATED("Source string is no longer required",
1716  static CachedData* CreateCodeCache(
1717  Local<UnboundScript> unbound_script, Local<String> source));
1718 
1725  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
1726 
1727  V8_DEPRECATED("Source string is no longer required",
1728  static CachedData* CreateCodeCacheForFunction(
1729  Local<Function> function, Local<String> source));
1730 
1731  private:
1732  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1733  Isolate* isolate, Source* source, CompileOptions options,
1734  NoCacheReason no_cache_reason);
1735 };
1736 
1737 
1741 class V8_EXPORT Message {
1742  public:
1743  Local<String> Get() const;
1744 
1745  V8_DEPRECATED("Use maybe version", Local<String> GetSourceLine() const);
1746  V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
1747  Local<Context> context) const;
1748 
1753  ScriptOrigin GetScriptOrigin() const;
1754 
1759  Local<Value> GetScriptResourceName() const;
1760 
1766  Local<StackTrace> GetStackTrace() const;
1767 
1771  V8_DEPRECATED("Use maybe version", int GetLineNumber() const);
1772  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1773 
1778  int GetStartPosition() const;
1779 
1784  int GetEndPosition() const;
1785 
1789  int ErrorLevel() const;
1790 
1795  int GetStartColumn() const;
1796  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1797 
1802  int GetEndColumn() const;
1803  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1804 
1809  bool IsSharedCrossOrigin() const;
1810  bool IsOpaque() const;
1811 
1812  // TODO(1245381): Print to a string instead of on a FILE.
1813  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1814 
1815  static const int kNoLineNumberInfo = 0;
1816  static const int kNoColumnInfo = 0;
1817  static const int kNoScriptIdInfo = 0;
1818 };
1819 
1820 
1826 class V8_EXPORT StackTrace {
1827  public:
1835  kLineNumber = 1,
1836  kColumnOffset = 1 << 1 | kLineNumber,
1837  kScriptName = 1 << 2,
1838  kFunctionName = 1 << 3,
1839  kIsEval = 1 << 4,
1840  kIsConstructor = 1 << 5,
1841  kScriptNameOrSourceURL = 1 << 6,
1842  kScriptId = 1 << 7,
1843  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1844  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1845  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1846  };
1847 
1851  Local<StackFrame> GetFrame(uint32_t index) const;
1852 
1856  int GetFrameCount() const;
1857 
1865  static Local<StackTrace> CurrentStackTrace(
1866  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1867 };
1868 
1869 
1873 class V8_EXPORT StackFrame {
1874  public:
1881  int GetLineNumber() const;
1882 
1890  int GetColumn() const;
1891 
1898  int GetScriptId() const;
1899 
1904  Local<String> GetScriptName() const;
1905 
1912  Local<String> GetScriptNameOrSourceURL() const;
1913 
1917  Local<String> GetFunctionName() const;
1918 
1923  bool IsEval() const;
1924 
1929  bool IsConstructor() const;
1930 
1934  bool IsWasm() const;
1935 };
1936 
1937 
1938 // A StateTag represents a possible state of the VM.
1939 enum StateTag {
1940  JS,
1941  GC,
1942  PARSER,
1943  BYTECODE_COMPILER,
1944  COMPILER,
1945  OTHER,
1946  EXTERNAL,
1947  IDLE
1948 };
1949 
1950 // A RegisterState represents the current state of registers used
1951 // by the sampling profiler API.
1953  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1954  void* pc; // Instruction pointer.
1955  void* sp; // Stack pointer.
1956  void* fp; // Frame pointer.
1957 };
1958 
1959 // The output structure filled up by GetStackSample API function.
1960 struct SampleInfo {
1961  size_t frames_count; // Number of frames collected.
1962  StateTag vm_state; // Current VM state.
1963  void* external_callback_entry; // External callback address if VM is
1964  // executing an external callback.
1965 };
1966 
1970 class V8_EXPORT JSON {
1971  public:
1979  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1980  MaybeLocal<Value> Parse(Isolate* isolate,
1981  Local<String> json_string));
1982  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1983  Local<Context> context, Local<String> json_string);
1984 
1992  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1993  Local<Context> context, Local<Value> json_object,
1994  Local<String> gap = Local<String>());
1995 };
1996 
2005 class V8_EXPORT ValueSerializer {
2006  public:
2007  class V8_EXPORT Delegate {
2008  public:
2009  virtual ~Delegate() {}
2010 
2016  virtual void ThrowDataCloneError(Local<String> message) = 0;
2017 
2023  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
2024 
2035  virtual Maybe<uint32_t> GetSharedArrayBufferId(
2036  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
2037 
2038  virtual Maybe<uint32_t> GetWasmModuleTransferId(
2039  Isolate* isolate, Local<WasmCompiledModule> module);
2051  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
2052  size_t* actual_size);
2053 
2059  virtual void FreeBufferMemory(void* buffer);
2060  };
2061 
2062  explicit ValueSerializer(Isolate* isolate);
2063  ValueSerializer(Isolate* isolate, Delegate* delegate);
2064  ~ValueSerializer();
2065 
2069  void WriteHeader();
2070 
2074  V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
2075  Local<Value> value);
2076 
2081  V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
2082 
2089  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
2090 
2096  void TransferArrayBuffer(uint32_t transfer_id,
2097  Local<ArrayBuffer> array_buffer);
2098 
2102  V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
2103  void TransferSharedArrayBuffer(
2104  uint32_t transfer_id,
2105  Local<SharedArrayBuffer> shared_array_buffer));
2106 
2114  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
2115 
2121  void WriteUint32(uint32_t value);
2122  void WriteUint64(uint64_t value);
2123  void WriteDouble(double value);
2124  void WriteRawBytes(const void* source, size_t length);
2125 
2126  private:
2127  ValueSerializer(const ValueSerializer&) = delete;
2128  void operator=(const ValueSerializer&) = delete;
2129 
2130  struct PrivateData;
2131  PrivateData* private_;
2132 };
2133 
2142 class V8_EXPORT ValueDeserializer {
2143  public:
2144  class V8_EXPORT Delegate {
2145  public:
2146  virtual ~Delegate() {}
2147 
2153  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
2154 
2159  virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
2160  Isolate* isolate, uint32_t transfer_id);
2161 
2166  virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
2167  Isolate* isolate, uint32_t clone_id);
2168  };
2169 
2170  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2171  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2172  Delegate* delegate);
2173  ~ValueDeserializer();
2174 
2179  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2180 
2184  V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
2185 
2190  void TransferArrayBuffer(uint32_t transfer_id,
2191  Local<ArrayBuffer> array_buffer);
2192 
2198  void TransferSharedArrayBuffer(uint32_t id,
2199  Local<SharedArrayBuffer> shared_array_buffer);
2200 
2208  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2209 
2213  void SetExpectInlineWasm(bool allow_inline_wasm);
2214 
2220  uint32_t GetWireFormatVersion() const;
2221 
2227  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2228  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2229  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2230  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2231 
2232  private:
2233  ValueDeserializer(const ValueDeserializer&) = delete;
2234  void operator=(const ValueDeserializer&) = delete;
2235 
2236  struct PrivateData;
2237  PrivateData* private_;
2238 };
2239 
2240 
2241 // --- Value ---
2242 
2243 
2247 class V8_EXPORT Value : public Data {
2248  public:
2253  V8_INLINE bool IsUndefined() const;
2254 
2259  V8_INLINE bool IsNull() const;
2260 
2266  V8_INLINE bool IsNullOrUndefined() const;
2267 
2271  bool IsTrue() const;
2272 
2276  bool IsFalse() const;
2277 
2281  bool IsName() const;
2282 
2287  V8_INLINE bool IsString() const;
2288 
2292  bool IsSymbol() const;
2293 
2297  bool IsFunction() const;
2298 
2303  bool IsArray() const;
2304 
2308  bool IsObject() const;
2309 
2313  bool IsBigInt() const;
2314 
2318  bool IsBoolean() const;
2319 
2323  bool IsNumber() const;
2324 
2328  bool IsExternal() const;
2329 
2333  bool IsInt32() const;
2334 
2338  bool IsUint32() const;
2339 
2343  bool IsDate() const;
2344 
2348  bool IsArgumentsObject() const;
2349 
2353  bool IsBigIntObject() const;
2354 
2358  bool IsBooleanObject() const;
2359 
2363  bool IsNumberObject() const;
2364 
2368  bool IsStringObject() const;
2369 
2373  bool IsSymbolObject() const;
2374 
2378  bool IsNativeError() const;
2379 
2383  bool IsRegExp() const;
2384 
2388  bool IsAsyncFunction() const;
2389 
2393  bool IsGeneratorFunction() const;
2394 
2398  bool IsGeneratorObject() const;
2399 
2403  bool IsPromise() const;
2404 
2408  bool IsMap() const;
2409 
2413  bool IsSet() const;
2414 
2418  bool IsMapIterator() const;
2419 
2423  bool IsSetIterator() const;
2424 
2428  bool IsWeakMap() const;
2429 
2433  bool IsWeakSet() const;
2434 
2438  bool IsArrayBuffer() const;
2439 
2443  bool IsArrayBufferView() const;
2444 
2448  bool IsTypedArray() const;
2449 
2453  bool IsUint8Array() const;
2454 
2458  bool IsUint8ClampedArray() const;
2459 
2463  bool IsInt8Array() const;
2464 
2468  bool IsUint16Array() const;
2469 
2473  bool IsInt16Array() const;
2474 
2478  bool IsUint32Array() const;
2479 
2483  bool IsInt32Array() const;
2484 
2488  bool IsFloat32Array() const;
2489 
2493  bool IsFloat64Array() const;
2494 
2498  bool IsBigInt64Array() const;
2499 
2503  bool IsBigUint64Array() const;
2504 
2508  bool IsDataView() const;
2509 
2514  bool IsSharedArrayBuffer() const;
2515 
2519  bool IsProxy() const;
2520 
2521  bool IsWebAssemblyCompiledModule() const;
2522 
2526  bool IsModuleNamespaceObject() const;
2527 
2528  V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
2529  Local<Context> context) const;
2530  V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
2531  Local<Context> context) const;
2532  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
2533  Local<Context> context) const;
2534  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
2535  Local<Context> context) const;
2536  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
2537  Local<Context> context) const;
2538  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
2539  Local<Context> context) const;
2540  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
2541  Local<Context> context) const;
2542  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
2543  Local<Context> context) const;
2544  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
2545 
2546  V8_DEPRECATE_SOON("Use maybe version",
2547  Local<Boolean> ToBoolean(Isolate* isolate) const);
2548  V8_DEPRECATE_SOON("Use maybe version",
2549  Local<Number> ToNumber(Isolate* isolate) const);
2550  V8_DEPRECATE_SOON("Use maybe version",
2551  Local<String> ToString(Isolate* isolate) const);
2552  V8_DEPRECATE_SOON("Use maybe version",
2553  Local<Object> ToObject(Isolate* isolate) const);
2554  V8_DEPRECATE_SOON("Use maybe version",
2555  Local<Integer> ToInteger(Isolate* isolate) const);
2556  V8_DEPRECATE_SOON("Use maybe version",
2557  Local<Int32> ToInt32(Isolate* isolate) const);
2558 
2559  inline V8_DEPRECATE_SOON("Use maybe version",
2560  Local<Boolean> ToBoolean() const);
2561  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
2562  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
2563  inline V8_DEPRECATE_SOON("Use maybe version",
2564  Local<Integer> ToInteger() const);
2565 
2570  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
2571  Local<Context> context) const;
2572 
2573  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2574  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2575  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2576  Local<Context> context) const;
2577  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2578  Local<Context> context) const;
2579  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2580 
2581  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2582  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2583  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2584  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2585  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2586 
2588  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2589  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2590  Local<Value> that) const;
2591  bool StrictEquals(Local<Value> that) const;
2592  bool SameValue(Local<Value> that) const;
2593 
2594  template <class T> V8_INLINE static Value* Cast(T* value);
2595 
2596  Local<String> TypeOf(Isolate*);
2597 
2598  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2599 
2600  private:
2601  V8_INLINE bool QuickIsUndefined() const;
2602  V8_INLINE bool QuickIsNull() const;
2603  V8_INLINE bool QuickIsNullOrUndefined() const;
2604  V8_INLINE bool QuickIsString() const;
2605  bool FullIsUndefined() const;
2606  bool FullIsNull() const;
2607  bool FullIsString() const;
2608 };
2609 
2610 
2614 class V8_EXPORT Primitive : public Value { };
2615 
2616 
2621 class V8_EXPORT Boolean : public Primitive {
2622  public:
2623  bool Value() const;
2624  V8_INLINE static Boolean* Cast(v8::Value* obj);
2625  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2626 
2627  private:
2628  static void CheckCast(v8::Value* obj);
2629 };
2630 
2631 
2635 class V8_EXPORT Name : public Primitive {
2636  public:
2644  int GetIdentityHash();
2645 
2646  V8_INLINE static Name* Cast(Value* obj);
2647 
2648  private:
2649  static void CheckCast(Value* obj);
2650 };
2651 
2658 enum class NewStringType {
2662  kNormal,
2663 
2670 };
2671 
2675 class V8_EXPORT String : public Name {
2676  public:
2677  static constexpr int kMaxLength = internal::kApiPointerSize == 4
2678  ? (1 << 28) - 16
2679  : internal::kSmiMaxValue / 2 - 24;
2680 
2681  enum Encoding {
2682  UNKNOWN_ENCODING = 0x1,
2683  TWO_BYTE_ENCODING = 0x0,
2684  ONE_BYTE_ENCODING = 0x8
2685  };
2689  int Length() const;
2690 
2695  int Utf8Length() const;
2696 
2703  bool IsOneByte() const;
2704 
2710  bool ContainsOnlyOneByte() const;
2711 
2738  NO_OPTIONS = 0,
2739  HINT_MANY_WRITES_EXPECTED = 1,
2740  NO_NULL_TERMINATION = 2,
2741  PRESERVE_ONE_BYTE_NULL = 4,
2742  // Used by WriteUtf8 to replace orphan surrogate code units with the
2743  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2744  // output.
2745  REPLACE_INVALID_UTF8 = 8
2746  };
2747 
2748  // 16-bit character codes.
2749  int Write(uint16_t* buffer,
2750  int start = 0,
2751  int length = -1,
2752  int options = NO_OPTIONS) const;
2753  // One byte characters.
2754  int WriteOneByte(uint8_t* buffer,
2755  int start = 0,
2756  int length = -1,
2757  int options = NO_OPTIONS) const;
2758  // UTF-8 encoded characters.
2759  int WriteUtf8(char* buffer,
2760  int length = -1,
2761  int* nchars_ref = NULL,
2762  int options = NO_OPTIONS) const;
2763 
2767  V8_INLINE static Local<String> Empty(Isolate* isolate);
2768 
2772  bool IsExternal() const;
2773 
2777  bool IsExternalOneByte() const;
2778 
2779  class V8_EXPORT ExternalStringResourceBase { // NOLINT
2780  public:
2781  virtual ~ExternalStringResourceBase() {}
2782 
2783  virtual bool IsCompressible() const { return false; }
2784 
2785  protected:
2787 
2794  virtual void Dispose() { delete this; }
2795 
2796  // Disallow copying and assigning.
2798  void operator=(const ExternalStringResourceBase&) = delete;
2799 
2800  private:
2801  friend class internal::Heap;
2802  friend class v8::String;
2803  };
2804 
2811  class V8_EXPORT ExternalStringResource
2812  : public ExternalStringResourceBase {
2813  public:
2819 
2823  virtual const uint16_t* data() const = 0;
2824 
2828  virtual size_t length() const = 0;
2829 
2830  protected:
2832  };
2833 
2845  : public ExternalStringResourceBase {
2846  public:
2853  virtual const char* data() const = 0;
2855  virtual size_t length() const = 0;
2856  protected:
2858  };
2859 
2865  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2866  Encoding* encoding_out) const;
2867 
2872  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2873 
2878  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2879 
2880  V8_INLINE static String* Cast(v8::Value* obj);
2881 
2882  // TODO(dcarney): remove with deprecation of New functions.
2883  enum NewStringType {
2884  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2885  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2886  };
2887 
2889  static V8_DEPRECATE_SOON(
2890  "Use maybe version",
2891  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2892  NewStringType type = kNormalString,
2893  int length = -1));
2894 
2897  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2898  Isolate* isolate, const char* data, v8::NewStringType type,
2899  int length = -1);
2900 
2903  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2904  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2905  int length = -1);
2906 
2908  static V8_DEPRECATE_SOON(
2909  "Use maybe version",
2910  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2911  NewStringType type = kNormalString,
2912  int length = -1));
2913 
2916  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2917  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2918  int length = -1);
2919 
2924  static Local<String> Concat(Local<String> left, Local<String> right);
2925 
2934  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2935  Isolate* isolate, ExternalStringResource* resource);
2936 
2946  bool MakeExternal(ExternalStringResource* resource);
2947 
2956  static V8_DEPRECATE_SOON(
2957  "Use maybe version",
2958  Local<String> NewExternal(Isolate* isolate,
2959  ExternalOneByteStringResource* resource));
2960  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2961  Isolate* isolate, ExternalOneByteStringResource* resource);
2962 
2972  bool MakeExternal(ExternalOneByteStringResource* resource);
2973 
2977  bool CanMakeExternal();
2978 
2986  class V8_EXPORT Utf8Value {
2987  public:
2988  V8_DEPRECATED("Use Isolate version",
2989  explicit Utf8Value(Local<v8::Value> obj));
2990  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2991  ~Utf8Value();
2992  char* operator*() { return str_; }
2993  const char* operator*() const { return str_; }
2994  int length() const { return length_; }
2995 
2996  // Disallow copying and assigning.
2997  Utf8Value(const Utf8Value&) = delete;
2998  void operator=(const Utf8Value&) = delete;
2999 
3000  private:
3001  char* str_;
3002  int length_;
3003  };
3004 
3011  class V8_EXPORT Value {
3012  public:
3013  V8_DEPRECATED("Use Isolate version", explicit Value(Local<v8::Value> obj));
3014  Value(Isolate* isolate, Local<v8::Value> obj);
3015  ~Value();
3016  uint16_t* operator*() { return str_; }
3017  const uint16_t* operator*() const { return str_; }
3018  int length() const { return length_; }
3019 
3020  // Disallow copying and assigning.
3021  Value(const Value&) = delete;
3022  void operator=(const Value&) = delete;
3023 
3024  private:
3025  uint16_t* str_;
3026  int length_;
3027  };
3028 
3029  private:
3030  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
3031  Encoding encoding) const;
3032  void VerifyExternalStringResource(ExternalStringResource* val) const;
3033  static void CheckCast(v8::Value* obj);
3034 };
3035 
3036 
3040 class V8_EXPORT Symbol : public Name {
3041  public:
3045  Local<Value> Name() const;
3046 
3050  static Local<Symbol> New(Isolate* isolate,
3051  Local<String> name = Local<String>());
3052 
3060  static Local<Symbol> For(Isolate *isolate, Local<String> name);
3061 
3066  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
3067 
3068  // Well-known symbols
3069  static Local<Symbol> GetHasInstance(Isolate* isolate);
3070  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
3071  static Local<Symbol> GetIterator(Isolate* isolate);
3072  static Local<Symbol> GetMatch(Isolate* isolate);
3073  static Local<Symbol> GetReplace(Isolate* isolate);
3074  static Local<Symbol> GetSearch(Isolate* isolate);
3075  static Local<Symbol> GetSplit(Isolate* isolate);
3076  static Local<Symbol> GetToPrimitive(Isolate* isolate);
3077  static Local<Symbol> GetToStringTag(Isolate* isolate);
3078  static Local<Symbol> GetUnscopables(Isolate* isolate);
3079 
3080  V8_INLINE static Symbol* Cast(Value* obj);
3081 
3082  private:
3083  Symbol();
3084  static void CheckCast(Value* obj);
3085 };
3086 
3087 
3093 class V8_EXPORT Private : public Data {
3094  public:
3098  Local<Value> Name() const;
3099 
3103  static Local<Private> New(Isolate* isolate,
3104  Local<String> name = Local<String>());
3105 
3115  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3116 
3117  V8_INLINE static Private* Cast(Data* data);
3118 
3119  private:
3120  Private();
3121 
3122  static void CheckCast(Data* that);
3123 };
3124 
3125 
3129 class V8_EXPORT Number : public Primitive {
3130  public:
3131  double Value() const;
3132  static Local<Number> New(Isolate* isolate, double value);
3133  V8_INLINE static Number* Cast(v8::Value* obj);
3134  private:
3135  Number();
3136  static void CheckCast(v8::Value* obj);
3137 };
3138 
3139 
3143 class V8_EXPORT Integer : public Number {
3144  public:
3145  static Local<Integer> New(Isolate* isolate, int32_t value);
3146  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3147  int64_t Value() const;
3148  V8_INLINE static Integer* Cast(v8::Value* obj);
3149  private:
3150  Integer();
3151  static void CheckCast(v8::Value* obj);
3152 };
3153 
3154 
3158 class V8_EXPORT Int32 : public Integer {
3159  public:
3160  int32_t Value() const;
3161  V8_INLINE static Int32* Cast(v8::Value* obj);
3162 
3163  private:
3164  Int32();
3165  static void CheckCast(v8::Value* obj);
3166 };
3167 
3168 
3172 class V8_EXPORT Uint32 : public Integer {
3173  public:
3174  uint32_t Value() const;
3175  V8_INLINE static Uint32* Cast(v8::Value* obj);
3176 
3177  private:
3178  Uint32();
3179  static void CheckCast(v8::Value* obj);
3180 };
3181 
3185 class V8_EXPORT BigInt : public Primitive {
3186  public:
3187  static Local<BigInt> New(Isolate* isolate, int64_t value);
3188  static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3196  static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
3197  int word_count, const uint64_t* words);
3198 
3205  uint64_t Uint64Value(bool* lossless = nullptr) const;
3206 
3212  int64_t Int64Value(bool* lossless = nullptr) const;
3213 
3218  int WordCount() const;
3219 
3228  void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
3229 
3230  V8_INLINE static BigInt* Cast(v8::Value* obj);
3231 
3232  private:
3233  BigInt();
3234  static void CheckCast(v8::Value* obj);
3235 };
3236 
3242  None = 0,
3244  ReadOnly = 1 << 0,
3246  DontEnum = 1 << 1,
3248  DontDelete = 1 << 2
3249 };
3250 
3256 typedef void (*AccessorGetterCallback)(
3257  Local<String> property,
3258  const PropertyCallbackInfo<Value>& info);
3259 typedef void (*AccessorNameGetterCallback)(
3260  Local<Name> property,
3261  const PropertyCallbackInfo<Value>& info);
3262 
3263 
3264 typedef void (*AccessorSetterCallback)(
3265  Local<String> property,
3266  Local<Value> value,
3267  const PropertyCallbackInfo<void>& info);
3268 typedef void (*AccessorNameSetterCallback)(
3269  Local<Name> property,
3270  Local<Value> value,
3271  const PropertyCallbackInfo<void>& info);
3272 
3273 
3284  DEFAULT = 0,
3285  ALL_CAN_READ = 1,
3286  ALL_CAN_WRITE = 1 << 1,
3287  PROHIBITS_OVERWRITING = 1 << 2
3288 };
3289 
3294  ALL_PROPERTIES = 0,
3295  ONLY_WRITABLE = 1,
3296  ONLY_ENUMERABLE = 2,
3297  ONLY_CONFIGURABLE = 4,
3298  SKIP_STRINGS = 8,
3299  SKIP_SYMBOLS = 16
3300 };
3301 
3309 enum class SideEffectType { kHasSideEffect, kHasNoSideEffect };
3310 
3318 enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes };
3319 
3324 enum class IndexFilter { kIncludeIndices, kSkipIndices };
3325 
3330 enum class KeyConversionMode { kConvertToString, kKeepNumbers };
3331 
3335 enum class IntegrityLevel { kFrozen, kSealed };
3336 
3340 class V8_EXPORT Object : public Value {
3341  public:
3342  V8_DEPRECATE_SOON("Use maybe version",
3343  bool Set(Local<Value> key, Local<Value> value));
3344  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
3345  Local<Value> key, Local<Value> value);
3346 
3347  V8_DEPRECATE_SOON("Use maybe version",
3348  bool Set(uint32_t index, Local<Value> value));
3349  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3350  Local<Value> value);
3351 
3352  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3353  //
3354  // Defines a configurable, writable, enumerable property with the given value
3355  // on the object unless the property already exists and is not configurable
3356  // or the object is not extensible.
3357  //
3358  // Returns true on success.
3359  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3360  Local<Name> key,
3361  Local<Value> value);
3362  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3363  uint32_t index,
3364  Local<Value> value);
3365 
3366  // Implements DefineOwnProperty.
3367  //
3368  // In general, CreateDataProperty will be faster, however, does not allow
3369  // for specifying attributes.
3370  //
3371  // Returns true on success.
3372  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3373  Local<Context> context, Local<Name> key, Local<Value> value,
3374  PropertyAttribute attributes = None);
3375 
3376  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3377  //
3378  // The defineProperty function is used to add an own property or
3379  // update the attributes of an existing own property of an object.
3380  //
3381  // Both data and accessor descriptors can be used.
3382  //
3383  // In general, CreateDataProperty is faster, however, does not allow
3384  // for specifying attributes or an accessor descriptor.
3385  //
3386  // The PropertyDescriptor can change when redefining a property.
3387  //
3388  // Returns true on success.
3389  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3390  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3391 
3392  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3393  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3394  Local<Value> key);
3395 
3396  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3397  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3398  uint32_t index);
3399 
3405  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3406  Local<Context> context, Local<Value> key);
3407 
3411  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3412  Local<Context> context, Local<Name> key);
3413 
3414  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
3430  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3431  Local<Value> key);
3432 
3433  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3434  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3435  Local<Value> key);
3436 
3437  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3438 
3439  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3440  uint32_t index);
3441 
3445  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
3446  Local<Context> context, Local<Name> name,
3447  AccessorNameGetterCallback getter, AccessorNameSetterCallback setter = 0,
3449  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3450  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3451 
3452  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3453  Local<Function> setter = Local<Function>(),
3454  PropertyAttribute attribute = None,
3455  AccessControl settings = DEFAULT);
3456 
3461  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3462  Local<Context> context, Local<Name> name,
3463  AccessorNameGetterCallback getter,
3464  AccessorNameSetterCallback setter = nullptr,
3465  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
3466  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3467 
3476  V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
3477  Local<Context> context, Local<Name> name,
3478  AccessorNameGetterCallback getter, Local<Value> data = Local<Value>(),
3479  PropertyAttribute attributes = None,
3480  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3481 
3488  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3489  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3490  Local<Value> value);
3491  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3492  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3493 
3500  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3501  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3502  Local<Context> context);
3503  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3504  Local<Context> context, KeyCollectionMode mode,
3505  PropertyFilter property_filter, IndexFilter index_filter,
3506  KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
3507 
3513  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3514  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3515  Local<Context> context);
3516 
3523  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3524  Local<Context> context, PropertyFilter filter,
3525  KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
3526 
3532  Local<Value> GetPrototype();
3533 
3539  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3540  Local<Value> prototype);
3541 
3546  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3547 
3553  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3554  Local<Context> context);
3555 
3559  Local<String> GetConstructorName();
3560 
3564  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3565 
3567  int InternalFieldCount();
3568 
3570  V8_INLINE static int InternalFieldCount(
3571  const PersistentBase<Object>& object) {
3572  return object.val_->InternalFieldCount();
3573  }
3574 
3576  V8_INLINE Local<Value> GetInternalField(int index);
3577 
3579  void SetInternalField(int index, Local<Value> value);
3580 
3586  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3587 
3589  V8_INLINE static void* GetAlignedPointerFromInternalField(
3590  const PersistentBase<Object>& object, int index) {
3591  return object.val_->GetAlignedPointerFromInternalField(index);
3592  }
3593 
3599  void SetAlignedPointerInInternalField(int index, void* value);
3600  void SetAlignedPointerInInternalFields(int argc, int indices[],
3601  void* values[]);
3602 
3608  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3609  Local<Name> key);
3610  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3611  uint32_t index);
3612  V8_DEPRECATE_SOON("Use maybe version",
3613  bool HasRealNamedProperty(Local<String> key));
3627  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3628  Local<Name> key);
3629  V8_DEPRECATE_SOON("Use maybe version",
3630  bool HasRealIndexedProperty(uint32_t index));
3631  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3632  Local<Context> context, uint32_t index);
3633  V8_DEPRECATE_SOON("Use maybe version",
3634  bool HasRealNamedCallbackProperty(Local<String> key));
3635  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3636  Local<Context> context, Local<Name> key);
3637 
3642  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3643  Local<Context> context, Local<Name> key);
3644 
3650  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
3651  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3652  Local<Name> key);
3653 
3659  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3660  Local<Context> context, Local<Name> key);
3661 
3667  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3668  Local<Context> context, Local<Name> key);
3669 
3671  bool HasNamedLookupInterceptor();
3672 
3674  bool HasIndexedLookupInterceptor();
3675 
3683  int GetIdentityHash();
3684 
3689  // TODO(dcarney): take an isolate and optionally bail out?
3690  Local<Object> Clone();
3691 
3695  Local<Context> CreationContext();
3696 
3699  const PersistentBase<Object>& object) {
3700  return object.val_->CreationContext();
3701  }
3702 
3708  bool IsCallable();
3709 
3713  bool IsConstructor();
3714 
3719  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
3720  Local<Value> recv,
3721  int argc,
3722  Local<Value> argv[]);
3723 
3729  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3730  Local<Context> context, int argc, Local<Value> argv[]);
3731 
3735  Isolate* GetIsolate();
3736 
3746  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3747 
3748  static Local<Object> New(Isolate* isolate);
3749 
3750  V8_INLINE static Object* Cast(Value* obj);
3751 
3752  private:
3753  Object();
3754  static void CheckCast(Value* obj);
3755  Local<Value> SlowGetInternalField(int index);
3756  void* SlowGetAlignedPointerFromInternalField(int index);
3757 };
3758 
3759 
3763 class V8_EXPORT Array : public Object {
3764  public:
3765  uint32_t Length() const;
3766 
3771  static Local<Array> New(Isolate* isolate, int length = 0);
3772 
3773  V8_INLINE static Array* Cast(Value* obj);
3774  private:
3775  Array();
3776  static void CheckCast(Value* obj);
3777 };
3778 
3779 
3783 class V8_EXPORT Map : public Object {
3784  public:
3785  size_t Size() const;
3786  void Clear();
3787  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3788  Local<Value> key);
3789  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
3790  Local<Value> key,
3791  Local<Value> value);
3792  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3793  Local<Value> key);
3794  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3795  Local<Value> key);
3796 
3801  Local<Array> AsArray() const;
3802 
3806  static Local<Map> New(Isolate* isolate);
3807 
3808  V8_INLINE static Map* Cast(Value* obj);
3809 
3810  private:
3811  Map();
3812  static void CheckCast(Value* obj);
3813 };
3814 
3815 
3819 class V8_EXPORT Set : public Object {
3820  public:
3821  size_t Size() const;
3822  void Clear();
3823  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3824  Local<Value> key);
3825  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3826  Local<Value> key);
3827  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3828  Local<Value> key);
3829 
3833  Local<Array> AsArray() const;
3834 
3838  static Local<Set> New(Isolate* isolate);
3839 
3840  V8_INLINE static Set* Cast(Value* obj);
3841 
3842  private:
3843  Set();
3844  static void CheckCast(Value* obj);
3845 };
3846 
3847 
3848 template<typename T>
3849 class ReturnValue {
3850  public:
3851  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3852  : value_(that.value_) {
3853  TYPE_CHECK(T, S);
3854  }
3855  // Local setters
3856  template <typename S>
3857  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3858  void Set(const Persistent<S>& handle));
3859  template <typename S>
3860  V8_INLINE void Set(const Global<S>& handle);
3861  template <typename S>
3862  V8_INLINE void Set(const Local<S> handle);
3863  // Fast primitive setters
3864  V8_INLINE void Set(bool value);
3865  V8_INLINE void Set(double i);
3866  V8_INLINE void Set(int32_t i);
3867  V8_INLINE void Set(uint32_t i);
3868  // Fast JS primitive setters
3869  V8_INLINE void SetNull();
3870  V8_INLINE void SetUndefined();
3871  V8_INLINE void SetEmptyString();
3872  // Convenience getter for Isolate
3873  V8_INLINE Isolate* GetIsolate() const;
3874 
3875  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3876  template <typename S>
3877  V8_INLINE void Set(S* whatever);
3878 
3879  // Getter. Creates a new Local<> so it comes with a certain performance
3880  // hit. If the ReturnValue was not yet set, this will return the undefined
3881  // value.
3882  V8_INLINE Local<Value> Get() const;
3883 
3884  private:
3885  template<class F> friend class ReturnValue;
3886  template<class F> friend class FunctionCallbackInfo;
3887  template<class F> friend class PropertyCallbackInfo;
3888  template <class F, class G, class H>
3889  friend class PersistentValueMapBase;
3890  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3891  V8_INLINE internal::Object* GetDefaultValue();
3892  V8_INLINE explicit ReturnValue(internal::Object** slot);
3893  internal::Object** value_;
3894 };
3895 
3896 
3903 template<typename T>
3904 class FunctionCallbackInfo {
3905  public:
3907  V8_INLINE int Length() const;
3909  V8_INLINE Local<Value> operator[](int i) const;
3911  V8_INLINE Local<Object> This() const;
3922  V8_INLINE Local<Object> Holder() const;
3924  V8_INLINE Local<Value> NewTarget() const;
3926  V8_INLINE bool IsConstructCall() const;
3928  V8_INLINE Local<Value> Data() const;
3930  V8_INLINE Isolate* GetIsolate() const;
3932  V8_INLINE ReturnValue<T> GetReturnValue() const;
3933  // This shouldn't be public, but the arm compiler needs it.
3934  static const int kArgsLength = 6;
3935 
3936  protected:
3937  friend class internal::FunctionCallbackArguments;
3938  friend class internal::CustomArguments<FunctionCallbackInfo>;
3939  friend class debug::ConsoleCallArguments;
3940  static const int kHolderIndex = 0;
3941  static const int kIsolateIndex = 1;
3942  static const int kReturnValueDefaultValueIndex = 2;
3943  static const int kReturnValueIndex = 3;
3944  static const int kDataIndex = 4;
3945  static const int kNewTargetIndex = 5;
3946 
3947  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3948  internal::Object** values, int length);
3949  internal::Object** implicit_args_;
3950  internal::Object** values_;
3951  int length_;
3952 };
3953 
3954 
3959 template<typename T>
3960 class PropertyCallbackInfo {
3961  public:
3965  V8_INLINE Isolate* GetIsolate() const;
3966 
3972  V8_INLINE Local<Value> Data() const;
3973 
4015  V8_INLINE Local<Object> This() const;
4016 
4026  V8_INLINE Local<Object> Holder() const;
4027 
4036  V8_INLINE ReturnValue<T> GetReturnValue() const;
4037 
4045  V8_INLINE bool ShouldThrowOnError() const;
4046 
4047  // This shouldn't be public, but the arm compiler needs it.
4048  static const int kArgsLength = 7;
4049 
4050  protected:
4051  friend class MacroAssembler;
4052  friend class internal::PropertyCallbackArguments;
4053  friend class internal::CustomArguments<PropertyCallbackInfo>;
4054  static const int kShouldThrowOnErrorIndex = 0;
4055  static const int kHolderIndex = 1;
4056  static const int kIsolateIndex = 2;
4057  static const int kReturnValueDefaultValueIndex = 3;
4058  static const int kReturnValueIndex = 4;
4059  static const int kDataIndex = 5;
4060  static const int kThisIndex = 6;
4061 
4062  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
4063  internal::Object** args_;
4064 };
4065 
4066 
4067 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
4068 
4069 enum class ConstructorBehavior { kThrow, kAllow };
4070 
4074 class V8_EXPORT Function : public Object {
4075  public:
4080  static MaybeLocal<Function> New(
4081  Local<Context> context, FunctionCallback callback,
4082  Local<Value> data = Local<Value>(), int length = 0,
4083  ConstructorBehavior behavior = ConstructorBehavior::kAllow,
4084  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4085  static V8_DEPRECATE_SOON(
4086  "Use maybe version",
4087  Local<Function> New(Isolate* isolate, FunctionCallback callback,
4088  Local<Value> data = Local<Value>(), int length = 0));
4089 
4090  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
4091  Local<Context> context, int argc, Local<Value> argv[]) const;
4092 
4093  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
4094  Local<Context> context) const {
4095  return NewInstance(context, 0, nullptr);
4096  }
4097 
4103  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
4104  Local<Context> context, int argc, Local<Value> argv[],
4105  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4106 
4107  V8_DEPRECATE_SOON("Use maybe version",
4108  Local<Value> Call(Local<Value> recv, int argc,
4109  Local<Value> argv[]));
4110  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
4111  Local<Value> recv, int argc,
4112  Local<Value> argv[]);
4113 
4114  void SetName(Local<String> name);
4115  Local<Value> GetName() const;
4116 
4123  Local<Value> GetInferredName() const;
4124 
4129  Local<Value> GetDebugName() const;
4130 
4135  Local<Value> GetDisplayName() const;
4136 
4141  int GetScriptLineNumber() const;
4146  int GetScriptColumnNumber() const;
4147 
4151  int ScriptId() const;
4152 
4157  Local<Value> GetBoundFunction() const;
4158 
4159  ScriptOrigin GetScriptOrigin() const;
4160  V8_INLINE static Function* Cast(Value* obj);
4161  static const int kLineOffsetNotFound;
4162 
4163  private:
4164  Function();
4165  static void CheckCast(Value* obj);
4166 };
4167 
4168 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4169 // The number of required internal fields can be defined by embedder.
4170 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4171 #endif
4172 
4176 class V8_EXPORT Promise : public Object {
4177  public:
4182  enum PromiseState { kPending, kFulfilled, kRejected };
4183 
4184  class V8_EXPORT Resolver : public Object {
4185  public:
4189  static V8_DEPRECATED("Use maybe version",
4190  Local<Resolver> New(Isolate* isolate));
4191  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
4192  Local<Context> context);
4193 
4197  Local<Promise> GetPromise();
4198 
4203  V8_DEPRECATED("Use maybe version", void Resolve(Local<Value> value));
4204  V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context,
4205  Local<Value> value);
4206 
4207  V8_DEPRECATED("Use maybe version", void Reject(Local<Value> value));
4208  V8_WARN_UNUSED_RESULT Maybe<bool> Reject(Local<Context> context,
4209  Local<Value> value);
4210 
4211  V8_INLINE static Resolver* Cast(Value* obj);
4212 
4213  private:
4214  Resolver();
4215  static void CheckCast(Value* obj);
4216  };
4217 
4224  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
4225  Local<Function> handler);
4226 
4227  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
4228  Local<Function> handler);
4229 
4234  bool HasHandler();
4235 
4240  Local<Value> Result();
4241 
4245  PromiseState State();
4246 
4247  V8_INLINE static Promise* Cast(Value* obj);
4248 
4249  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4250 
4251  private:
4252  Promise();
4253  static void CheckCast(Value* obj);
4254 };
4255 
4284 class V8_EXPORT PropertyDescriptor {
4285  public:
4286  // GenericDescriptor
4288 
4289  // DataDescriptor
4291 
4292  // DataDescriptor with writable property
4293  PropertyDescriptor(Local<Value> value, bool writable);
4294 
4295  // AccessorDescriptor
4297 
4298  ~PropertyDescriptor();
4299 
4300  Local<Value> value() const;
4301  bool has_value() const;
4302 
4303  Local<Value> get() const;
4304  bool has_get() const;
4305  Local<Value> set() const;
4306  bool has_set() const;
4307 
4308  void set_enumerable(bool enumerable);
4309  bool enumerable() const;
4310  bool has_enumerable() const;
4311 
4312  void set_configurable(bool configurable);
4313  bool configurable() const;
4314  bool has_configurable() const;
4315 
4316  bool writable() const;
4317  bool has_writable() const;
4318 
4319  struct PrivateData;
4320  PrivateData* get_private() const { return private_; }
4321 
4322  PropertyDescriptor(const PropertyDescriptor&) = delete;
4323  void operator=(const PropertyDescriptor&) = delete;
4324 
4325  private:
4326  PrivateData* private_;
4327 };
4328 
4333 class V8_EXPORT Proxy : public Object {
4334  public:
4335  Local<Value> GetTarget();
4336  Local<Value> GetHandler();
4337  bool IsRevoked();
4338  void Revoke();
4339 
4343  static MaybeLocal<Proxy> New(Local<Context> context,
4344  Local<Object> local_target,
4345  Local<Object> local_handler);
4346 
4347  V8_INLINE static Proxy* Cast(Value* obj);
4348 
4349  private:
4350  Proxy();
4351  static void CheckCast(Value* obj);
4352 };
4353 
4354 // TODO(mtrofin): rename WasmCompiledModule to WasmModuleObject, for
4355 // consistency with internal APIs.
4356 class V8_EXPORT WasmCompiledModule : public Object {
4357  public:
4358  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
4359 
4360 // The COMMA macro allows us to use ',' inside of the V8_DEPRECATE_SOON macro.
4361 #define COMMA ,
4362  V8_DEPRECATE_SOON(
4363  "Use BufferReference.",
4364  typedef std::pair<const uint8_t * COMMA size_t> CallerOwnedBuffer);
4365 #undef COMMA
4366 
4371  const uint8_t* start;
4372  size_t size;
4373  BufferReference(const uint8_t* start, size_t size)
4374  : start(start), size(size) {}
4375  // Temporarily allow conversion to and from CallerOwnedBuffer.
4376  V8_DEPRECATE_SOON(
4377  "Use BufferReference directly.",
4378  inline BufferReference(CallerOwnedBuffer)); // NOLINT(runtime/explicit)
4379  V8_DEPRECATE_SOON("Use BufferReference directly.",
4380  inline operator CallerOwnedBuffer());
4381  };
4382 
4387  class TransferrableModule final {
4388  public:
4389  TransferrableModule(TransferrableModule&& src) = default;
4390  TransferrableModule(const TransferrableModule& src) = delete;
4391 
4392  TransferrableModule& operator=(TransferrableModule&& src) = default;
4393  TransferrableModule& operator=(const TransferrableModule& src) = delete;
4394 
4395  private:
4396  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
4397  friend class WasmCompiledModule;
4398  TransferrableModule(OwnedBuffer code, OwnedBuffer bytes)
4399  : compiled_code(std::move(code)), wire_bytes(std::move(bytes)) {}
4400 
4401  OwnedBuffer compiled_code = {nullptr, 0};
4402  OwnedBuffer wire_bytes = {nullptr, 0};
4403  };
4404 
4410  TransferrableModule GetTransferrableModule();
4411 
4416  static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
4417  Isolate* isolate, const TransferrableModule&);
4418 
4422  BufferReference GetWasmWireBytesRef();
4423  V8_DEPRECATE_SOON("Use GetWasmWireBytesRef version.",
4424  Local<String> GetWasmWireBytes());
4425 
4430  SerializedModule Serialize();
4431 
4436  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
4437  Isolate* isolate, BufferReference serialized_module,
4438  BufferReference wire_bytes);
4439  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
4440 
4441  private:
4442  static MaybeLocal<WasmCompiledModule> Deserialize(
4443  Isolate* isolate, BufferReference serialized_module,
4444  BufferReference wire_bytes);
4445  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
4446  const uint8_t* start,
4447  size_t length);
4448  static BufferReference AsReference(
4449  const TransferrableModule::OwnedBuffer& buff) {
4450  return {buff.first.get(), buff.second};
4451  }
4452 
4453  WasmCompiledModule();
4454  static void CheckCast(Value* obj);
4455 };
4456 
4457 // TODO(clemensh): Remove after M69 branch.
4458 WasmCompiledModule::BufferReference::BufferReference(
4459  WasmCompiledModule::CallerOwnedBuffer buf)
4460  : BufferReference(buf.first, buf.second) {}
4461 WasmCompiledModule::BufferReference::
4462 operator WasmCompiledModule::CallerOwnedBuffer() {
4463  return {start, size};
4464 }
4465 
4472 class V8_EXPORT WasmStreaming final {
4473  public:
4474  class WasmStreamingImpl;
4475 
4476  WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
4477 
4478  ~WasmStreaming();
4479 
4484  void OnBytesReceived(const uint8_t* bytes, size_t size);
4485 
4491  void Finish();
4492 
4498  void Abort(MaybeLocal<Value> exception);
4499 
4505  static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
4506  Local<Value> value);
4507 
4508  private:
4509  std::unique_ptr<WasmStreamingImpl> impl_;
4510 };
4511 
4512 // TODO(mtrofin): when streaming compilation is done, we can rename this
4513 // to simply WasmModuleObjectBuilder
4514 class V8_EXPORT WasmModuleObjectBuilderStreaming final {
4515  public:
4516  explicit WasmModuleObjectBuilderStreaming(Isolate* isolate);
4520  void OnBytesReceived(const uint8_t*, size_t size);
4521  void Finish();
4527  void Abort(MaybeLocal<Value> exception);
4528  Local<Promise> GetPromise();
4529 
4531 
4532  private:
4534  delete;
4536  default;
4538  const WasmModuleObjectBuilderStreaming&) = delete;
4540  WasmModuleObjectBuilderStreaming&&) = default;
4541  Isolate* isolate_ = nullptr;
4542 
4543 #if V8_CC_MSVC
4544 
4552 #else
4553  Persistent<Promise> promise_;
4554 #endif
4555  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4556 };
4557 
4558 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4559 // The number of required internal fields can be defined by embedder.
4560 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4561 #endif
4562 
4563 
4564 enum class ArrayBufferCreationMode { kInternalized, kExternalized };
4565 
4566 
4570 class V8_EXPORT ArrayBuffer : public Object {
4571  public:
4587  class V8_EXPORT Allocator { // NOLINT
4588  public:
4589  virtual ~Allocator() {}
4590 
4595  virtual void* Allocate(size_t length) = 0;
4596 
4601  virtual void* AllocateUninitialized(size_t length) = 0;
4602 
4607  virtual void Free(void* data, size_t length) = 0;
4608 
4614  enum class AllocationMode { kNormal, kReservation };
4615 
4622  static Allocator* NewDefaultAllocator();
4623  };
4624 
4633  class V8_EXPORT Contents { // NOLINT
4634  public:
4635  Contents()
4636  : data_(nullptr),
4637  byte_length_(0),
4638  allocation_base_(nullptr),
4639  allocation_length_(0),
4640  allocation_mode_(Allocator::AllocationMode::kNormal) {}
4641 
4642  void* AllocationBase() const { return allocation_base_; }
4643  size_t AllocationLength() const { return allocation_length_; }
4644  Allocator::AllocationMode AllocationMode() const {
4645  return allocation_mode_;
4646  }
4647 
4648  void* Data() const { return data_; }
4649  size_t ByteLength() const { return byte_length_; }
4650 
4651  private:
4652  void* data_;
4653  size_t byte_length_;
4654  void* allocation_base_;
4655  size_t allocation_length_;
4656  Allocator::AllocationMode allocation_mode_;
4657 
4658  friend class ArrayBuffer;
4659  };
4660 
4661 
4665  size_t ByteLength() const;
4666 
4673  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4674 
4684  static Local<ArrayBuffer> New(
4685  Isolate* isolate, void* data, size_t byte_length,
4686  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
4687 
4692  bool IsExternal() const;
4693 
4697  bool IsNeuterable() const;
4698 
4705  void Neuter();
4706 
4716  Contents Externalize();
4717 
4728  Contents GetContents();
4729 
4730  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4731 
4732  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4733  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4734 
4735  private:
4736  ArrayBuffer();
4737  static void CheckCast(Value* obj);
4738 };
4739 
4740 
4741 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4742 // The number of required internal fields can be defined by embedder.
4743 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4744 #endif
4745 
4746 
4751 class V8_EXPORT ArrayBufferView : public Object {
4752  public:
4756  Local<ArrayBuffer> Buffer();
4760  size_t ByteOffset();
4764  size_t ByteLength();
4765 
4775  size_t CopyContents(void* dest, size_t byte_length);
4776 
4781  bool HasBuffer() const;
4782 
4783  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4784 
4785  static const int kInternalFieldCount =
4786  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4787  static const int kEmbedderFieldCount =
4788  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4789 
4790  private:
4791  ArrayBufferView();
4792  static void CheckCast(Value* obj);
4793 };
4794 
4795 
4800 class V8_EXPORT TypedArray : public ArrayBufferView {
4801  public:
4802  /*
4803  * The largest typed array size that can be constructed using New.
4804  */
4805  static constexpr size_t kMaxLength = internal::kSmiMaxValue;
4806 
4811  size_t Length();
4812 
4813  V8_INLINE static TypedArray* Cast(Value* obj);
4814 
4815  private:
4816  TypedArray();
4817  static void CheckCast(Value* obj);
4818 };
4819 
4820 
4824 class V8_EXPORT Uint8Array : public TypedArray {
4825  public:
4826  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4827  size_t byte_offset, size_t length);
4828  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4829  size_t byte_offset, size_t length);
4830  V8_INLINE static Uint8Array* Cast(Value* obj);
4831 
4832  private:
4833  Uint8Array();
4834  static void CheckCast(Value* obj);
4835 };
4836 
4837 
4841 class V8_EXPORT Uint8ClampedArray : public TypedArray {
4842  public:
4843  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4844  size_t byte_offset, size_t length);
4845  static Local<Uint8ClampedArray> New(
4846  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4847  size_t length);
4848  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4849 
4850  private:
4852  static void CheckCast(Value* obj);
4853 };
4854 
4858 class V8_EXPORT Int8Array : public TypedArray {
4859  public:
4860  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4861  size_t byte_offset, size_t length);
4862  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4863  size_t byte_offset, size_t length);
4864  V8_INLINE static Int8Array* Cast(Value* obj);
4865 
4866  private:
4867  Int8Array();
4868  static void CheckCast(Value* obj);
4869 };
4870 
4871 
4875 class V8_EXPORT Uint16Array : public TypedArray {
4876  public:
4877  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4878  size_t byte_offset, size_t length);
4879  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4880  size_t byte_offset, size_t length);
4881  V8_INLINE static Uint16Array* Cast(Value* obj);
4882 
4883  private:
4884  Uint16Array();
4885  static void CheckCast(Value* obj);
4886 };
4887 
4888 
4892 class V8_EXPORT Int16Array : public TypedArray {
4893  public:
4894  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4895  size_t byte_offset, size_t length);
4896  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4897  size_t byte_offset, size_t length);
4898  V8_INLINE static Int16Array* Cast(Value* obj);
4899 
4900  private:
4901  Int16Array();
4902  static void CheckCast(Value* obj);
4903 };
4904 
4905 
4909 class V8_EXPORT Uint32Array : public TypedArray {
4910  public:
4911  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4912  size_t byte_offset, size_t length);
4913  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4914  size_t byte_offset, size_t length);
4915  V8_INLINE static Uint32Array* Cast(Value* obj);
4916 
4917  private:
4918  Uint32Array();
4919  static void CheckCast(Value* obj);
4920 };
4921 
4922 
4926 class V8_EXPORT Int32Array : public TypedArray {
4927  public:
4928  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4929  size_t byte_offset, size_t length);
4930  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4931  size_t byte_offset, size_t length);
4932  V8_INLINE static Int32Array* Cast(Value* obj);
4933 
4934  private:
4935  Int32Array();
4936  static void CheckCast(Value* obj);
4937 };
4938 
4939 
4943 class V8_EXPORT Float32Array : public TypedArray {
4944  public:
4945  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4946  size_t byte_offset, size_t length);
4947  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4948  size_t byte_offset, size_t length);
4949  V8_INLINE static Float32Array* Cast(Value* obj);
4950 
4951  private:
4952  Float32Array();
4953  static void CheckCast(Value* obj);
4954 };
4955 
4956 
4960 class V8_EXPORT Float64Array : public TypedArray {
4961  public:
4962  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4963  size_t byte_offset, size_t length);
4964  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4965  size_t byte_offset, size_t length);
4966  V8_INLINE static Float64Array* Cast(Value* obj);
4967 
4968  private:
4969  Float64Array();
4970  static void CheckCast(Value* obj);
4971 };
4972 
4976 class V8_EXPORT BigInt64Array : public TypedArray {
4977  public:
4978  static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
4979  size_t byte_offset, size_t length);
4980  static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4981  size_t byte_offset, size_t length);
4982  V8_INLINE static BigInt64Array* Cast(Value* obj);
4983 
4984  private:
4985  BigInt64Array();
4986  static void CheckCast(Value* obj);
4987 };
4988 
4992 class V8_EXPORT BigUint64Array : public TypedArray {
4993  public:
4994  static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
4995  size_t byte_offset, size_t length);
4996  static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4997  size_t byte_offset, size_t length);
4998  V8_INLINE static BigUint64Array* Cast(Value* obj);
4999 
5000  private:
5001  BigUint64Array();
5002  static void CheckCast(Value* obj);
5003 };
5004 
5008 class V8_EXPORT DataView : public ArrayBufferView {
5009  public:
5010  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
5011  size_t byte_offset, size_t length);
5012  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
5013  size_t byte_offset, size_t length);
5014  V8_INLINE static DataView* Cast(Value* obj);
5015 
5016  private:
5017  DataView();
5018  static void CheckCast(Value* obj);
5019 };
5020 
5021 
5026 class V8_EXPORT SharedArrayBuffer : public Object {
5027  public:
5039  class V8_EXPORT Contents { // NOLINT
5040  public:
5041  Contents()
5042  : data_(nullptr),
5043  byte_length_(0),
5044  allocation_base_(nullptr),
5045  allocation_length_(0),
5046  allocation_mode_(ArrayBuffer::Allocator::AllocationMode::kNormal) {}
5047 
5048  void* AllocationBase() const { return allocation_base_; }
5049  size_t AllocationLength() const { return allocation_length_; }
5050  ArrayBuffer::Allocator::AllocationMode AllocationMode() const {
5051  return allocation_mode_;
5052  }
5053 
5054  void* Data() const { return data_; }
5055  size_t ByteLength() const { return byte_length_; }
5056 
5057  private:
5058  void* data_;
5059  size_t byte_length_;
5060  void* allocation_base_;
5061  size_t allocation_length_;
5062  ArrayBuffer::Allocator::AllocationMode allocation_mode_;
5063 
5064  friend class SharedArrayBuffer;
5065  };
5066 
5067 
5071  size_t ByteLength() const;
5072 
5079  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
5080 
5087  static Local<SharedArrayBuffer> New(
5088  Isolate* isolate, void* data, size_t byte_length,
5089  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5090 
5095  bool IsExternal() const;
5096 
5109  Contents Externalize();
5110 
5123  Contents GetContents();
5124 
5125  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
5126 
5127  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5128 
5129  private:
5131  static void CheckCast(Value* obj);
5132 };
5133 
5134 
5138 class V8_EXPORT Date : public Object {
5139  public:
5140  static V8_DEPRECATE_SOON("Use maybe version.",
5141  Local<Value> New(Isolate* isolate, double time));
5142  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
5143  double time);
5144 
5149  double ValueOf() const;
5150 
5151  V8_INLINE static Date* Cast(Value* obj);
5152 
5165  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
5166 
5167  private:
5168  static void CheckCast(Value* obj);
5169 };
5170 
5171 
5175 class V8_EXPORT NumberObject : public Object {
5176  public:
5177  static Local<Value> New(Isolate* isolate, double value);
5178 
5179  double ValueOf() const;
5180 
5181  V8_INLINE static NumberObject* Cast(Value* obj);
5182 
5183  private:
5184  static void CheckCast(Value* obj);
5185 };
5186 
5190 class V8_EXPORT BigIntObject : public Object {
5191  public:
5192  static Local<Value> New(Isolate* isolate, int64_t value);
5193 
5194  Local<BigInt> ValueOf() const;
5195 
5196  V8_INLINE static BigIntObject* Cast(Value* obj);
5197 
5198  private:
5199  static void CheckCast(Value* obj);
5200 };
5201 
5205 class V8_EXPORT BooleanObject : public Object {
5206  public:
5207  static Local<Value> New(Isolate* isolate, bool value);
5208 
5209  bool ValueOf() const;
5210 
5211  V8_INLINE static BooleanObject* Cast(Value* obj);
5212 
5213  private:
5214  static void CheckCast(Value* obj);
5215 };
5216 
5217 
5221 class V8_EXPORT StringObject : public Object {
5222  public:
5223  static Local<Value> New(Local<String> value);
5224 
5225  Local<String> ValueOf() const;
5226 
5227  V8_INLINE static StringObject* Cast(Value* obj);
5228 
5229  private:
5230  static void CheckCast(Value* obj);
5231 };
5232 
5233 
5237 class V8_EXPORT SymbolObject : public Object {
5238  public:
5239  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
5240 
5241  Local<Symbol> ValueOf() const;
5242 
5243  V8_INLINE static SymbolObject* Cast(Value* obj);
5244 
5245  private:
5246  static void CheckCast(Value* obj);
5247 };
5248 
5249 
5253 class V8_EXPORT RegExp : public Object {
5254  public:
5259  enum Flags {
5260  kNone = 0,
5261  kGlobal = 1 << 0,
5262  kIgnoreCase = 1 << 1,
5263  kMultiline = 1 << 2,
5264  kSticky = 1 << 3,
5265  kUnicode = 1 << 4,
5266  kDotAll = 1 << 5,
5267  };
5268 
5279  static V8_DEPRECATED("Use maybe version",
5280  Local<RegExp> New(Local<String> pattern, Flags flags));
5281  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
5282  Local<String> pattern,
5283  Flags flags);
5284 
5289  Local<String> GetSource() const;
5290 
5294  Flags GetFlags() const;
5295 
5296  V8_INLINE static RegExp* Cast(Value* obj);
5297 
5298  private:
5299  static void CheckCast(Value* obj);
5300 };
5301 
5302 
5307 class V8_EXPORT External : public Value {
5308  public:
5309  static Local<External> New(Isolate* isolate, void* value);
5310  V8_INLINE static External* Cast(Value* obj);
5311  void* Value() const;
5312  private:
5313  static void CheckCast(v8::Value* obj);
5314 };
5315 
5316 #define V8_INTRINSICS_LIST(F) \
5317  F(ArrayProto_entries, array_entries_iterator) \
5318  F(ArrayProto_forEach, array_for_each_iterator) \
5319  F(ArrayProto_keys, array_keys_iterator) \
5320  F(ArrayProto_values, array_values_iterator) \
5321  F(ErrorPrototype, initial_error_prototype) \
5322  F(IteratorPrototype, initial_iterator_prototype)
5323 
5324 enum Intrinsic {
5325 #define V8_DECL_INTRINSIC(name, iname) k##name,
5326  V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
5327 #undef V8_DECL_INTRINSIC
5328 };
5329 
5330 
5331 // --- Templates ---
5332 
5333 
5337 class V8_EXPORT Template : public Data {
5338  public:
5344  void Set(Local<Name> name, Local<Data> value,
5345  PropertyAttribute attributes = None);
5346  void SetPrivate(Local<Private> name, Local<Data> value,
5347  PropertyAttribute attributes = None);
5348  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5349 
5350  void SetAccessorProperty(
5351  Local<Name> name,
5354  PropertyAttribute attribute = None,
5355  AccessControl settings = DEFAULT);
5356 
5384  void SetNativeDataProperty(
5386  AccessorSetterCallback setter = 0,
5387  // TODO(dcarney): gcc can't handle Local below
5388  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5390  AccessControl settings = DEFAULT,
5391  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5392  void SetNativeDataProperty(
5393  Local<Name> name, AccessorNameGetterCallback getter,
5394  AccessorNameSetterCallback setter = 0,
5395  // TODO(dcarney): gcc can't handle Local below
5396  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5398  AccessControl settings = DEFAULT,
5399  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5400 
5405  void SetLazyDataProperty(
5406  Local<Name> name, AccessorNameGetterCallback getter,
5407  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5408  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5409 
5414  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5415  PropertyAttribute attribute = None);
5416 
5417  private:
5418  Template();
5419 
5420  friend class ObjectTemplate;
5421  friend class FunctionTemplate;
5422 };
5423 
5424 
5430  Local<String> property,
5431  const PropertyCallbackInfo<Value>& info);
5432 
5433 
5439  Local<String> property,
5440  Local<Value> value,
5441  const PropertyCallbackInfo<Value>& info);
5442 
5443 
5450  Local<String> property,
5451  const PropertyCallbackInfo<Integer>& info);
5452 
5453 
5460  Local<String> property,
5461  const PropertyCallbackInfo<Boolean>& info);
5462 
5470  const PropertyCallbackInfo<Array>& info);
5471 
5472 
5473 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
5474 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
5475 
5513  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5514 
5537  Local<Name> property, Local<Value> value,
5538  const PropertyCallbackInfo<Value>& info);
5539 
5562  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5563 
5586  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5587 
5595  const PropertyCallbackInfo<Array>& info);
5596 
5618  Local<Name> property, const PropertyDescriptor& desc,
5619  const PropertyCallbackInfo<Value>& info);
5620 
5641  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5642 
5647  uint32_t index,
5648  const PropertyCallbackInfo<Value>& info);
5649 
5654  uint32_t index,
5655  Local<Value> value,
5656  const PropertyCallbackInfo<Value>& info);
5657 
5662  uint32_t index,
5663  const PropertyCallbackInfo<Integer>& info);
5664 
5669  uint32_t index,
5670  const PropertyCallbackInfo<Boolean>& info);
5671 
5679  const PropertyCallbackInfo<Array>& info);
5680 
5685  uint32_t index, const PropertyDescriptor& desc,
5686  const PropertyCallbackInfo<Value>& info);
5687 
5692  uint32_t index, const PropertyCallbackInfo<Value>& info);
5693 
5698  ACCESS_GET,
5699  ACCESS_SET,
5700  ACCESS_HAS,
5701  ACCESS_DELETE,
5702  ACCESS_KEYS
5703 };
5704 
5705 
5710 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5711  Local<Object> accessed_object,
5712  Local<Value> data);
5713 
5814 class V8_EXPORT FunctionTemplate : public Template {
5815  public:
5817  static Local<FunctionTemplate> New(
5818  Isolate* isolate, FunctionCallback callback = 0,
5819  Local<Value> data = Local<Value>(),
5820  Local<Signature> signature = Local<Signature>(), int length = 0,
5821  ConstructorBehavior behavior = ConstructorBehavior::kAllow,
5822  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5823 
5825  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5826  size_t index);
5827 
5831  static Local<FunctionTemplate> NewWithCache(
5832  Isolate* isolate, FunctionCallback callback,
5833  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5834  Local<Signature> signature = Local<Signature>(), int length = 0,
5835  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5836 
5838  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5839  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
5840  Local<Context> context);
5841 
5849  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5850 
5856  void SetCallHandler(
5857  FunctionCallback callback, Local<Value> data = Local<Value>(),
5858  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5859 
5861  void SetLength(int length);
5862 
5864  Local<ObjectTemplate> InstanceTemplate();
5865 
5871  void Inherit(Local<FunctionTemplate> parent);
5872 
5877  Local<ObjectTemplate> PrototypeTemplate();
5878 
5885  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5886 
5892  void SetClassName(Local<String> name);
5893 
5894 
5899  void SetAcceptAnyReceiver(bool value);
5900 
5913  void SetHiddenPrototype(bool value);
5914 
5919  void ReadOnlyPrototype();
5920 
5925  void RemovePrototype();
5926 
5931  bool HasInstance(Local<Value> object);
5932 
5933  V8_INLINE static FunctionTemplate* Cast(Data* data);
5934 
5935  private:
5936  FunctionTemplate();
5937 
5938  static void CheckCast(Data* that);
5939  friend class Context;
5940  friend class ObjectTemplate;
5941 };
5942 
5951  kNone = 0,
5952 
5956  kAllCanRead = 1,
5957 
5962  kNonMasking = 1 << 1,
5963 
5968  kOnlyInterceptStrings = 1 << 2,
5969 
5973  kHasNoSideEffect = 1 << 3,
5974 };
5975 
5984  Local<Value> data = Local<Value>(),
5986  : getter(getter),
5987  setter(setter),
5988  query(query),
5989  deleter(deleter),
5990  enumerator(enumerator),
5991  definer(0),
5992  descriptor(0),
5993  data(data),
5994  flags(flags) {}
5995 
6003  Local<Value> data = Local<Value>(),
6005  : getter(getter),
6006  setter(setter),
6007  query(0),
6008  deleter(deleter),
6009  enumerator(enumerator),
6010  definer(definer),
6011  descriptor(descriptor),
6012  data(data),
6013  flags(flags) {}
6014 
6022  Local<Value> data;
6023  PropertyHandlerFlags flags;
6024 };
6025 
6026 
6030  IndexedPropertyGetterCallback getter = 0,
6031  IndexedPropertySetterCallback setter = 0,
6032  IndexedPropertyQueryCallback query = 0,
6033  IndexedPropertyDeleterCallback deleter = 0,
6034  IndexedPropertyEnumeratorCallback enumerator = 0,
6035  Local<Value> data = Local<Value>(),
6037  : getter(getter),
6038  setter(setter),
6039  query(query),
6040  deleter(deleter),
6041  enumerator(enumerator),
6042  definer(0),
6043  descriptor(0),
6044  data(data),
6045  flags(flags) {}
6046 
6054  Local<Value> data = Local<Value>(),
6056  : getter(getter),
6057  setter(setter),
6058  query(0),
6059  deleter(deleter),
6060  enumerator(enumerator),
6061  definer(definer),
6062  descriptor(descriptor),
6063  data(data),
6064  flags(flags) {}
6065 
6073  Local<Value> data;
6074  PropertyHandlerFlags flags;
6075 };
6076 
6077 
6084 class V8_EXPORT ObjectTemplate : public Template {
6085  public:
6087  static Local<ObjectTemplate> New(
6088  Isolate* isolate,
6090 
6092  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
6093  size_t index);
6094 
6096  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
6097  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
6098 
6128  void SetAccessor(
6130  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
6131  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
6133  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
6134  void SetAccessor(
6135  Local<Name> name, AccessorNameGetterCallback getter,
6136  AccessorNameSetterCallback setter = 0, Local<Value> data = Local<Value>(),
6137  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
6139  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
6140 
6163  V8_DEPRECATED(
6164  "Use SetHandler(const NamedPropertyHandlerConfiguration) "
6165  "with the kOnlyInterceptStrings flag set.",
6166  void SetNamedPropertyHandler(
6168  NamedPropertySetterCallback setter = 0,
6169  NamedPropertyQueryCallback query = 0,
6170  NamedPropertyDeleterCallback deleter = 0,
6171  NamedPropertyEnumeratorCallback enumerator = 0,
6172  Local<Value> data = Local<Value>()));
6173 
6185  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
6186 
6203  // TODO(dcarney): deprecate
6206  IndexedPropertySetterCallback setter = 0,
6207  IndexedPropertyQueryCallback query = 0,
6208  IndexedPropertyDeleterCallback deleter = 0,
6209  IndexedPropertyEnumeratorCallback enumerator = 0,
6210  Local<Value> data = Local<Value>()) {
6211  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
6212  deleter, enumerator, data));
6213  }
6214 
6225  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
6226 
6233  void SetCallAsFunctionHandler(FunctionCallback callback,
6234  Local<Value> data = Local<Value>());
6235 
6244  void MarkAsUndetectable();
6245 
6254  void SetAccessCheckCallback(AccessCheckCallback callback,
6255  Local<Value> data = Local<Value>());
6256 
6263  void SetAccessCheckCallbackAndHandler(
6264  AccessCheckCallback callback,
6265  const NamedPropertyHandlerConfiguration& named_handler,
6266  const IndexedPropertyHandlerConfiguration& indexed_handler,
6267  Local<Value> data = Local<Value>());
6268 
6273  int InternalFieldCount();
6274 
6279  void SetInternalFieldCount(int value);
6280 
6284  bool IsImmutableProto();
6285 
6290  void SetImmutableProto();
6291 
6292  V8_INLINE static ObjectTemplate* Cast(Data* data);
6293 
6294  private:
6295  ObjectTemplate();
6296  static Local<ObjectTemplate> New(internal::Isolate* isolate,
6297  Local<FunctionTemplate> constructor);
6298  static void CheckCast(Data* that);
6299  friend class FunctionTemplate;
6300 };
6301 
6310 class V8_EXPORT Signature : public Data {
6311  public:
6312  static Local<Signature> New(
6313  Isolate* isolate,
6315 
6316  V8_INLINE static Signature* Cast(Data* data);
6317 
6318  private:
6319  Signature();
6320 
6321  static void CheckCast(Data* that);
6322 };
6323 
6324 
6329 class V8_EXPORT AccessorSignature : public Data {
6330  public:
6331  static Local<AccessorSignature> New(
6332  Isolate* isolate,
6334 
6335  V8_INLINE static AccessorSignature* Cast(Data* data);
6336 
6337  private:
6339 
6340  static void CheckCast(Data* that);
6341 };
6342 
6343 
6344 // --- Extensions ---
6345 V8_DEPRECATE_SOON("Implementation detail",
6349  public:
6350  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
6351  ExternalOneByteStringResourceImpl(const char* data, size_t length)
6352  : data_(data), length_(length) {}
6353  const char* data() const { return data_; }
6354  size_t length() const { return length_; }
6355 
6356  private:
6357  const char* data_;
6358  size_t length_;
6359 };
6360 
6364 class V8_EXPORT Extension { // NOLINT
6365  public:
6366  // Note that the strings passed into this constructor must live as long
6367  // as the Extension itself.
6368  Extension(const char* name,
6369  const char* source = 0,
6370  int dep_count = 0,
6371  const char** deps = 0,
6372  int source_length = -1);
6373  virtual ~Extension() { delete source_; }
6374  virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
6375  Isolate* isolate, Local<String> name) {
6376  return Local<FunctionTemplate>();
6377  }
6378 
6379  const char* name() const { return name_; }
6380  size_t source_length() const { return source_length_; }
6381  const String::ExternalOneByteStringResource* source() const {
6382  return source_;
6383  }
6384  int dependency_count() { return dep_count_; }
6385  const char** dependencies() { return deps_; }
6386  void set_auto_enable(bool value) { auto_enable_ = value; }
6387  bool auto_enable() { return auto_enable_; }
6388 
6389  // Disallow copying and assigning.
6390  Extension(const Extension&) = delete;
6391  void operator=(const Extension&) = delete;
6392 
6393  private:
6394  const char* name_;
6395  size_t source_length_; // expected to initialize before source_
6397  int dep_count_;
6398  const char** deps_;
6399  bool auto_enable_;
6400 };
6401 
6402 
6403 void V8_EXPORT RegisterExtension(Extension* extension);
6404 
6405 
6406 // --- Statics ---
6407 
6408 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6409 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6410 V8_INLINE Local<Boolean> True(Isolate* isolate);
6411 V8_INLINE Local<Boolean> False(Isolate* isolate);
6412 
6427 class V8_EXPORT ResourceConstraints {
6428  public:
6430 
6440  void ConfigureDefaults(uint64_t physical_memory,
6441  uint64_t virtual_memory_limit);
6442 
6443  // Returns the max semi-space size in MB.
6444  V8_DEPRECATE_SOON("Use max_semi_space_size_in_kb()",
6445  size_t max_semi_space_size()) {
6446  return max_semi_space_size_in_kb_ / 1024;
6447  }
6448 
6449  // Sets the max semi-space size in MB.
6450  V8_DEPRECATE_SOON("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6451  void set_max_semi_space_size(size_t limit_in_mb)) {
6452  max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6453  }
6454 
6455  // Returns the max semi-space size in KB.
6456  size_t max_semi_space_size_in_kb() const {
6457  return max_semi_space_size_in_kb_;
6458  }
6459 
6460  // Sets the max semi-space size in KB.
6461  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6462  max_semi_space_size_in_kb_ = limit_in_kb;
6463  }
6464 
6465  size_t max_old_space_size() const { return max_old_space_size_; }
6466  void set_max_old_space_size(size_t limit_in_mb) {
6467  max_old_space_size_ = limit_in_mb;
6468  }
6469  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6470  size_t max_executable_size() const) {
6471  return max_executable_size_;
6472  }
6473  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6474  void set_max_executable_size(size_t limit_in_mb)) {
6475  max_executable_size_ = limit_in_mb;
6476  }
6477  uint32_t* stack_limit() const { return stack_limit_; }
6478  // Sets an address beyond which the VM's stack may not grow.
6479  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6480  size_t code_range_size() const { return code_range_size_; }
6481  void set_code_range_size(size_t limit_in_mb) {
6482  code_range_size_ = limit_in_mb;
6483  }
6484  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6485  void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; }
6486 
6487  private:
6488  // max_semi_space_size_ is in KB
6489  size_t max_semi_space_size_in_kb_;
6490 
6491  // The remaining limits are in MB
6492  size_t max_old_space_size_;
6493  size_t max_executable_size_;
6494  uint32_t* stack_limit_;
6495  size_t code_range_size_;
6496  size_t max_zone_pool_size_;
6497 };
6498 
6499 
6500 // --- Exceptions ---
6501 
6502 
6503 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6504 
6505 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6506 
6507 typedef void (*DcheckErrorCallback)(const char* file, int line,
6508  const char* message);
6509 
6510 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6511 
6512 // --- Tracing ---
6513 
6514 typedef void (*LogEventCallback)(const char* name, int event);
6515 
6520 class V8_EXPORT Exception {
6521  public:
6522  static Local<Value> RangeError(Local<String> message);
6523  static Local<Value> ReferenceError(Local<String> message);
6524  static Local<Value> SyntaxError(Local<String> message);
6525  static Local<Value> TypeError(Local<String> message);
6526  static Local<Value> Error(Local<String> message);
6527 
6533  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6534 
6539  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6540 };
6541 
6542 
6543 // --- Counters Callbacks ---
6544 
6545 typedef int* (*CounterLookupCallback)(const char* name);
6546 
6547 typedef void* (*CreateHistogramCallback)(const char* name,
6548  int min,
6549  int max,
6550  size_t buckets);
6551 
6552 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6553 
6554 // --- Enter/Leave Script Callback ---
6555 typedef void (*BeforeCallEnteredCallback)(Isolate*);
6556 typedef void (*CallCompletedCallback)(Isolate*);
6557 typedef void (*DeprecatedCallCompletedCallback)();
6558 
6579 typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)(
6580  Local<Context> context, Local<ScriptOrModule> referrer,
6581  Local<String> specifier);
6582 
6594  Local<Module> module,
6595  Local<Object> meta);
6596 
6613 enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
6614 
6615 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6616  Local<Value> parent);
6617 
6618 // --- Promise Reject Callback ---
6619 enum PromiseRejectEvent {
6620  kPromiseRejectWithNoHandler = 0,
6621  kPromiseHandlerAddedAfterReject = 1,
6622  kPromiseRejectAfterResolved = 2,
6623  kPromiseResolveAfterResolved = 3,
6624 };
6625 
6627  public:
6628  PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
6629  Local<Value> value, Local<StackTrace> stack_trace)
6630  : promise_(promise),
6631  event_(event),
6632  value_(value),
6633  stack_trace_(stack_trace) {}
6634 
6635  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6636  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6637  V8_INLINE Local<Value> GetValue() const { return value_; }
6638 
6639  private:
6640  Local<Promise> promise_;
6641  PromiseRejectEvent event_;
6642  Local<Value> value_;
6643  Local<StackTrace> stack_trace_;
6644 };
6645 
6646 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
6647 
6648 // --- Microtasks Callbacks ---
6649 typedef void (*MicrotasksCompletedCallback)(Isolate*);
6650 typedef void (*MicrotaskCallback)(void* data);
6651 
6652 
6660 enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
6661 
6662 
6672 class V8_EXPORT MicrotasksScope {
6673  public:
6674  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6675 
6676  MicrotasksScope(Isolate* isolate, Type type);
6677  ~MicrotasksScope();
6678 
6682  static void PerformCheckpoint(Isolate* isolate);
6683 
6687  static int GetCurrentDepth(Isolate* isolate);
6688 
6692  static bool IsRunningMicrotasks(Isolate* isolate);
6693 
6694  // Prevent copying.
6695  MicrotasksScope(const MicrotasksScope&) = delete;
6696  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6697 
6698  private:
6699  internal::Isolate* const isolate_;
6700  bool run_;
6701 };
6702 
6703 
6704 // --- Failed Access Check Callback ---
6705 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
6706  AccessType type,
6707  Local<Value> data);
6708 
6709 // --- AllowCodeGenerationFromStrings callbacks ---
6710 
6716  Local<String> source);
6717 
6718 // --- WebAssembly compilation callbacks ---
6719 typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
6720 
6721 typedef bool (*AllowWasmCodeGenerationCallback)(Local<Context> context,
6722  Local<String> source);
6723 
6724 // --- Callback for APIs defined on v8-supported objects, but implemented
6725 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6726 typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&);
6727 
6728 // --- Callback for WebAssembly.compileStreaming ---
6729 typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo<Value>&);
6730 
6731 // --- Garbage Collection Callbacks ---
6732 
6740 enum GCType {
6741  kGCTypeScavenge = 1 << 0,
6742  kGCTypeMarkSweepCompact = 1 << 1,
6743  kGCTypeIncrementalMarking = 1 << 2,
6744  kGCTypeProcessWeakCallbacks = 1 << 3,
6745  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
6746  kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
6747 };
6748 
6764  kNoGCCallbackFlags = 0,
6765  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
6766  kGCCallbackFlagForced = 1 << 2,
6767  kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
6768  kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
6769  kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
6770  kGCCallbackScheduleIdleGarbageCollection = 1 << 6,
6771 };
6772 
6773 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6774 
6775 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6776 
6784 typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
6785  size_t initial_heap_limit);
6786 
6793 class V8_EXPORT HeapStatistics {
6794  public:
6795  HeapStatistics();
6796  size_t total_heap_size() { return total_heap_size_; }
6797  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6798  size_t total_physical_size() { return total_physical_size_; }
6799  size_t total_available_size() { return total_available_size_; }
6800  size_t used_heap_size() { return used_heap_size_; }
6801  size_t heap_size_limit() { return heap_size_limit_; }
6802  size_t malloced_memory() { return malloced_memory_; }
6803  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6804  size_t number_of_native_contexts() { return number_of_native_contexts_; }
6805  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
6806 
6811  size_t does_zap_garbage() { return does_zap_garbage_; }
6812 
6813  private:
6814  size_t total_heap_size_;
6815  size_t total_heap_size_executable_;
6816  size_t total_physical_size_;
6817  size_t total_available_size_;
6818  size_t used_heap_size_;
6819  size_t heap_size_limit_;
6820  size_t malloced_memory_;
6821  size_t peak_malloced_memory_;
6822  bool does_zap_garbage_;
6823  size_t number_of_native_contexts_;
6824  size_t number_of_detached_contexts_;
6825 
6826  friend class V8;
6827  friend class Isolate;
6828 };
6829 
6830 
6831 class V8_EXPORT HeapSpaceStatistics {
6832  public:
6834  const char* space_name() { return space_name_; }
6835  size_t space_size() { return space_size_; }
6836  size_t space_used_size() { return space_used_size_; }
6837  size_t space_available_size() { return space_available_size_; }
6838  size_t physical_space_size() { return physical_space_size_; }
6839 
6840  private:
6841  const char* space_name_;
6842  size_t space_size_;
6843  size_t space_used_size_;
6844  size_t space_available_size_;
6845  size_t physical_space_size_;
6846 
6847  friend class Isolate;
6848 };
6849 
6850 
6851 class V8_EXPORT HeapObjectStatistics {
6852  public:
6854  const char* object_type() { return object_type_; }
6855  const char* object_sub_type() { return object_sub_type_; }
6856  size_t object_count() { return object_count_; }
6857  size_t object_size() { return object_size_; }
6858 
6859  private:
6860  const char* object_type_;
6861  const char* object_sub_type_;
6862  size_t object_count_;
6863  size_t object_size_;
6864 
6865  friend class Isolate;
6866 };
6867 
6868 class V8_EXPORT HeapCodeStatistics {
6869  public:
6871  size_t code_and_metadata_size() { return code_and_metadata_size_; }
6872  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
6873  size_t external_script_source_size() { return external_script_source_size_; }
6874 
6875  private:
6876  size_t code_and_metadata_size_;
6877  size_t bytecode_and_metadata_size_;
6878  size_t external_script_source_size_;
6879 
6880  friend class Isolate;
6881 };
6882 
6883 class RetainedObjectInfo;
6884 
6885 
6897 typedef void (*FunctionEntryHook)(uintptr_t function,
6898  uintptr_t return_addr_location);
6899 
6906  enum EventType {
6907  CODE_ADDED,
6908  CODE_MOVED,
6909  CODE_REMOVED,
6910  CODE_ADD_LINE_POS_INFO,
6911  CODE_START_LINE_INFO_RECORDING,
6912  CODE_END_LINE_INFO_RECORDING
6913  };
6914  // Definition of the code position type. The "POSITION" type means the place
6915  // in the source code which are of interest when making stack traces to
6916  // pin-point the source location of a stack frame as close as possible.
6917  // The "STATEMENT_POSITION" means the place at the beginning of each
6918  // statement, and is used to indicate possible break locations.
6919  enum PositionType { POSITION, STATEMENT_POSITION };
6920 
6921  // There are two different kinds of JitCodeEvents, one for JIT code generated
6922  // by the optimizing compiler, and one for byte code generated for the
6923  // interpreter. For JIT_CODE events, the |code_start| member of the event
6924  // points to the beginning of jitted assembly code, while for BYTE_CODE
6925  // events, |code_start| points to the first bytecode of the interpreted
6926  // function.
6927  enum CodeType { BYTE_CODE, JIT_CODE };
6928 
6929  // Type of event.
6930  EventType type;
6931  CodeType code_type;
6932  // Start of the instructions.
6933  void* code_start;
6934  // Size of the instructions.
6935  size_t code_len;
6936  // Script info for CODE_ADDED event.
6937  Local<UnboundScript> script;
6938  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
6939  // code line information which is returned from the
6940  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
6941  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
6942  void* user_data;
6943 
6944  struct name_t {
6945  // Name of the object associated with the code, note that the string is not
6946  // zero-terminated.
6947  const char* str;
6948  // Number of chars in str.
6949  size_t len;
6950  };
6951 
6952  struct line_info_t {
6953  // PC offset
6954  size_t offset;
6955  // Code position
6956  size_t pos;
6957  // The position type.
6958  PositionType position_type;
6959  };
6960 
6961  union {
6962  // Only valid for CODE_ADDED.
6963  struct name_t name;
6964 
6965  // Only valid for CODE_ADD_LINE_POS_INFO
6966  struct line_info_t line_info;
6967 
6968  // New location of instructions. Only valid for CODE_MOVED.
6969  void* new_code_start;
6970  };
6971 };
6972 
6978 enum RAILMode {
6979  // Response performance mode: In this mode very low virtual machine latency
6980  // is provided. V8 will try to avoid JavaScript execution interruptions.
6981  // Throughput may be throttled.
6982  PERFORMANCE_RESPONSE,
6983  // Animation performance mode: In this mode low virtual machine latency is
6984  // provided. V8 will try to avoid as many JavaScript execution interruptions
6985  // as possible. Throughput may be throttled. This is the default mode.
6986  PERFORMANCE_ANIMATION,
6987  // Idle performance mode: The embedder is idle. V8 can complete deferred work
6988  // in this mode.
6989  PERFORMANCE_IDLE,
6990  // Load performance mode: In this mode high throughput is provided. V8 may
6991  // turn off latency optimizations.
6992  PERFORMANCE_LOAD
6993 };
6994 
6999  kJitCodeEventDefault = 0,
7000  // Generate callbacks for already existent code.
7001  kJitCodeEventEnumExisting = 1
7002 };
7003 
7004 
7010 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
7011 
7012 
7016 class V8_EXPORT ExternalResourceVisitor { // NOLINT
7017  public:
7018  virtual ~ExternalResourceVisitor() {}
7019  virtual void VisitExternalString(Local<String> string) {}
7020 };
7021 
7022 
7026 class V8_EXPORT PersistentHandleVisitor { // NOLINT
7027  public:
7028  virtual ~PersistentHandleVisitor() {}
7029  virtual void VisitPersistentHandle(Persistent<Value>* value,
7030  uint16_t class_id) {}
7031 };
7032 
7041 enum class MemoryPressureLevel { kNone, kModerate, kCritical };
7042 
7054 class V8_EXPORT EmbedderHeapTracer {
7055  public:
7056  enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
7057 
7059  explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
7060  : force_completion(force_completion_) {}
7061 
7062  ForceCompletionAction force_completion;
7063  };
7064 
7071  virtual void RegisterV8References(
7072  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
7073 
7077  virtual void TracePrologue() = 0;
7078 
7089  virtual bool AdvanceTracing(double deadline_in_ms,
7090  AdvanceTracingActions actions) = 0;
7091 
7092  /*
7093  * Returns true if there no more tracing work to be done (see AdvanceTracing)
7094  * and false otherwise.
7095  */
7096  virtual bool IsTracingDone() { return NumberOfWrappersToTrace() == 0; }
7097 
7103  virtual void TraceEpilogue() = 0;
7104 
7109  virtual void EnterFinalPause() = 0;
7110 
7117  virtual void AbortTracing() = 0;
7118 
7119  /*
7120  * Called by the embedder to request immediaet finalization of the currently
7121  * running tracing phase that has been started with TracePrologue and not
7122  * yet finished with TraceEpilogue.
7123  *
7124  * Will be a noop when currently not in tracing.
7125  *
7126  * This is an experimental feature.
7127  */
7128  void FinalizeTracing();
7129 
7130  /*
7131  * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
7132  * is not attached to any v8::Isolate.
7133  */
7134  v8::Isolate* isolate() const { return isolate_; }
7135 
7139  V8_DEPRECATE_SOON("Use IsTracingDone",
7140  virtual size_t NumberOfWrappersToTrace() { return 0; });
7141 
7142  protected:
7143  virtual ~EmbedderHeapTracer() = default;
7144 
7145  v8::Isolate* isolate_ = nullptr;
7146 
7147  friend class internal::LocalEmbedderHeapTracer;
7148 };
7149 
7155  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
7156  void* data);
7157  SerializeInternalFieldsCallback(CallbackFunction function = nullptr,
7158  void* data_arg = nullptr)
7159  : callback(function), data(data_arg) {}
7160  CallbackFunction callback;
7161  void* data;
7162 };
7163 // Note that these fields are called "internal fields" in the API and called
7164 // "embedder fields" within V8.
7166 
7172  typedef void (*CallbackFunction)(Local<Object> holder, int index,
7173  StartupData payload, void* data);
7174  DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
7175  void* data_arg = nullptr)
7176  : callback(function), data(data_arg) {}
7177  void (*callback)(Local<Object> holder, int index, StartupData payload,
7178  void* data);
7179  void* data;
7180 };
7182 
7191 class V8_EXPORT Isolate {
7192  public:
7196  struct CreateParams {
7197  CreateParams()
7198  : entry_hook(nullptr),
7199  code_event_handler(nullptr),
7200  snapshot_blob(nullptr),
7201  counter_lookup_callback(nullptr),
7202  create_histogram_callback(nullptr),
7203  add_histogram_sample_callback(nullptr),
7204  array_buffer_allocator(nullptr),
7205  external_references(nullptr),
7206  allow_atomics_wait(true),
7207  only_terminate_in_safe_scope(false) {}
7208 
7218 
7224 
7229 
7234 
7235 
7240  CounterLookupCallback counter_lookup_callback;
7241 
7248  CreateHistogramCallback create_histogram_callback;
7249  AddHistogramSampleCallback add_histogram_sample_callback;
7250 
7256 
7263  const intptr_t* external_references;
7264 
7270 
7275  };
7276 
7277 
7282  class V8_EXPORT Scope {
7283  public:
7284  explicit Scope(Isolate* isolate) : isolate_(isolate) {
7285  isolate->Enter();
7286  }
7287 
7288  ~Scope() { isolate_->Exit(); }
7289 
7290  // Prevent copying of Scope objects.
7291  Scope(const Scope&) = delete;
7292  Scope& operator=(const Scope&) = delete;
7293 
7294  private:
7295  Isolate* const isolate_;
7296  };
7297 
7298 
7303  public:
7304  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
7305 
7306  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
7308 
7309  // Prevent copying of Scope objects.
7311  delete;
7313  const DisallowJavascriptExecutionScope&) = delete;
7314 
7315  private:
7316  bool on_failure_;
7317  void* internal_;
7318  };
7319 
7320 
7325  public:
7326  explicit AllowJavascriptExecutionScope(Isolate* isolate);
7328 
7329  // Prevent copying of Scope objects.
7331  delete;
7332  AllowJavascriptExecutionScope& operator=(
7333  const AllowJavascriptExecutionScope&) = delete;
7334 
7335  private:
7336  void* internal_throws_;
7337  void* internal_assert_;
7338  };
7339 
7345  public:
7346  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7348 
7349  // Prevent copying of Scope objects.
7351  delete;
7353  const SuppressMicrotaskExecutionScope&) = delete;
7354 
7355  private:
7356  internal::Isolate* const isolate_;
7357  };
7358 
7363  class V8_EXPORT SafeForTerminationScope {
7364  public:
7365  explicit SafeForTerminationScope(v8::Isolate* isolate);
7367 
7368  // Prevent copying of Scope objects.
7370  SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
7371 
7372  private:
7373  internal::Isolate* isolate_;
7374  bool prev_value_;
7375  };
7376 
7382  kFullGarbageCollection,
7383  kMinorGarbageCollection
7384  };
7385 
7392  kUseAsm = 0,
7393  kBreakIterator = 1,
7394  kLegacyConst = 2,
7395  kMarkDequeOverflow = 3,
7396  kStoreBufferOverflow = 4,
7397  kSlotsBufferOverflow = 5,
7398  kObjectObserve = 6,
7399  kForcedGC = 7,
7400  kSloppyMode = 8,
7401  kStrictMode = 9,
7402  kStrongMode = 10,
7403  kRegExpPrototypeStickyGetter = 11,
7404  kRegExpPrototypeToString = 12,
7405  kRegExpPrototypeUnicodeGetter = 13,
7406  kIntlV8Parse = 14,
7407  kIntlPattern = 15,
7408  kIntlResolved = 16,
7409  kPromiseChain = 17,
7410  kPromiseAccept = 18,
7411  kPromiseDefer = 19,
7412  kHtmlCommentInExternalScript = 20,
7413  kHtmlComment = 21,
7414  kSloppyModeBlockScopedFunctionRedefinition = 22,
7415  kForInInitializer = 23,
7416  kArrayProtectorDirtied = 24,
7417  kArraySpeciesModified = 25,
7418  kArrayPrototypeConstructorModified = 26,
7419  kArrayInstanceProtoModified = 27,
7420  kArrayInstanceConstructorModified = 28,
7421  kLegacyFunctionDeclaration = 29,
7422  kRegExpPrototypeSourceGetter = 30,
7423  kRegExpPrototypeOldFlagGetter = 31,
7424  kDecimalWithLeadingZeroInStrictMode = 32,
7425  kLegacyDateParser = 33,
7426  kDefineGetterOrSetterWouldThrow = 34,
7427  kFunctionConstructorReturnedUndefined = 35,
7428  kAssigmentExpressionLHSIsCallInSloppy = 36,
7429  kAssigmentExpressionLHSIsCallInStrict = 37,
7430  kPromiseConstructorReturnedUndefined = 38,
7431  kConstructorNonUndefinedPrimitiveReturn = 39,
7432  kLabeledExpressionStatement = 40,
7433  kLineOrParagraphSeparatorAsLineTerminator = 41,
7434  kIndexAccessor = 42,
7435  kErrorCaptureStackTrace = 43,
7436  kErrorPrepareStackTrace = 44,
7437  kErrorStackTraceLimit = 45,
7438  kWebAssemblyInstantiation = 46,
7439  kDeoptimizerDisableSpeculation = 47,
7440  kArrayPrototypeSortJSArrayModifiedPrototype = 48,
7441  kFunctionTokenOffsetTooLongForToString = 49,
7442 
7443  // If you add new values here, you'll also need to update Chromium's:
7444  // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to
7445  // this list need to be landed first, then changes on the Chromium side.
7446  kUseCounterFeatureCount // This enum value must be last.
7447  };
7448 
7449  enum MessageErrorLevel {
7450  kMessageLog = (1 << 0),
7451  kMessageDebug = (1 << 1),
7452  kMessageInfo = (1 << 2),
7453  kMessageError = (1 << 3),
7454  kMessageWarning = (1 << 4),
7455  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7456  kMessageWarning,
7457  };
7458 
7459  typedef void (*UseCounterCallback)(Isolate* isolate,
7460  UseCounterFeature feature);
7461 
7476  static Isolate* Allocate();
7477 
7481  static void Initialize(Isolate* isolate, const CreateParams& params);
7482 
7492  static Isolate* New(const CreateParams& params);
7493 
7500  static Isolate* GetCurrent();
7501 
7511  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7512  void SetAbortOnUncaughtExceptionCallback(
7513  AbortOnUncaughtExceptionCallback callback);
7514 
7519  void SetHostImportModuleDynamicallyCallback(
7521 
7526  void SetHostInitializeImportMetaObjectCallback(
7528 
7535  void MemoryPressureNotification(MemoryPressureLevel level);
7536 
7547  void Enter();
7548 
7556  void Exit();
7557 
7562  void Dispose();
7563 
7568  void DumpAndResetStats();
7569 
7577  void DiscardThreadSpecificMetadata();
7578 
7583  V8_INLINE void SetData(uint32_t slot, void* data);
7584 
7589  V8_INLINE void* GetData(uint32_t slot);
7590 
7595  V8_INLINE static uint32_t GetNumberOfDataSlots();
7596 
7602  template <class T>
7603  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
7604 
7608  void GetHeapStatistics(HeapStatistics* heap_statistics);
7609 
7613  size_t NumberOfHeapSpaces();
7614 
7624  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7625  size_t index);
7626 
7630  size_t NumberOfTrackedHeapObjectTypes();
7631 
7641  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7642  size_t type_index);
7643 
7651  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7652 
7665  void GetStackSample(const RegisterState& state, void** frames,
7666  size_t frames_limit, SampleInfo* sample_info);
7667 
7681  V8_INLINE int64_t
7682  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7683 
7688  size_t NumberOfPhantomHandleResetsSinceLastCall();
7689 
7694  HeapProfiler* GetHeapProfiler();
7695 
7699  void SetIdle(bool is_idle);
7700 
7702  bool InContext();
7703 
7708  Local<Context> GetCurrentContext();
7709 
7715  V8_DEPRECATED(
7716  "Calling context concept is not compatible with tail calls, and will be "
7717  "removed.",
7718  Local<Context> GetCallingContext());
7719 
7721  Local<Context> GetEnteredContext();
7722 
7729  Local<Context> GetEnteredOrMicrotaskContext();
7730 
7735  Local<Context> GetIncumbentContext();
7736 
7743  Local<Value> ThrowException(Local<Value> exception);
7744 
7745  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7746  GCCallbackFlags flags);
7747  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7748  GCCallbackFlags flags, void* data);
7749 
7759  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
7760  GCType gc_type_filter = kGCTypeAll);
7761  void AddGCPrologueCallback(GCCallback callback,
7762  GCType gc_type_filter = kGCTypeAll);
7763 
7768  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
7769  void RemoveGCPrologueCallback(GCCallback callback);
7770 
7774  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7775 
7779  enum class AtomicsWaitEvent {
7781  kStartWait,
7783  kWokenUp,
7785  kTimedOut,
7787  kTerminatedExecution,
7789  kAPIStopped,
7791  kNotEqual
7792  };
7793 
7798  class V8_EXPORT AtomicsWaitWakeHandle {
7799  public:
7814  void Wake();
7815  };
7816 
7840  typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event,
7841  Local<SharedArrayBuffer> array_buffer,
7842  size_t offset_in_bytes, int32_t value,
7843  double timeout_in_ms,
7844  AtomicsWaitWakeHandle* stop_handle,
7845  void* data);
7846 
7853  void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
7854 
7864  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
7865  GCType gc_type_filter = kGCTypeAll);
7866  void AddGCEpilogueCallback(GCCallback callback,
7867  GCType gc_type_filter = kGCTypeAll);
7868 
7873  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
7874  void* data = nullptr);
7875  void RemoveGCEpilogueCallback(GCCallback callback);
7876 
7877  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7878 
7885  void SetGetExternallyAllocatedMemoryInBytesCallback(
7886  GetExternallyAllocatedMemoryInBytesCallback callback);
7887 
7895  void TerminateExecution();
7896 
7905  bool IsExecutionTerminating();
7906 
7921  void CancelTerminateExecution();
7922 
7931  void RequestInterrupt(InterruptCallback callback, void* data);
7932 
7943  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
7944 
7948  void SetEventLogger(LogEventCallback that);
7949 
7956  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7957 
7961  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7962 
7970  void AddCallCompletedCallback(CallCompletedCallback callback);
7971  V8_DEPRECATED(
7972  "Use callback with parameter",
7973  void AddCallCompletedCallback(DeprecatedCallCompletedCallback callback));
7974 
7978  void RemoveCallCompletedCallback(CallCompletedCallback callback);
7979  V8_DEPRECATED("Use callback with parameter",
7980  void RemoveCallCompletedCallback(
7981  DeprecatedCallCompletedCallback callback));
7982 
7987  void SetPromiseHook(PromiseHook hook);
7988 
7993  void SetPromiseRejectCallback(PromiseRejectCallback callback);
7994 
7999  void RunMicrotasks();
8000 
8004  void EnqueueMicrotask(Local<Function> microtask);
8005 
8009  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
8010 
8014  void SetMicrotasksPolicy(MicrotasksPolicy policy);
8015  V8_DEPRECATED("Use SetMicrotasksPolicy",
8016  void SetAutorunMicrotasks(bool autorun));
8017 
8021  MicrotasksPolicy GetMicrotasksPolicy() const;
8022  V8_DEPRECATED("Use GetMicrotasksPolicy", bool WillAutorunMicrotasks() const);
8023 
8036  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8037 
8041  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8042 
8046  void SetUseCounterCallback(UseCounterCallback callback);
8047 
8052  void SetCounterFunction(CounterLookupCallback);
8053 
8060  void SetCreateHistogramFunction(CreateHistogramCallback);
8061  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
8062 
8077  bool IdleNotificationDeadline(double deadline_in_seconds);
8078 
8083  void LowMemoryNotification();
8084 
8094  int ContextDisposedNotification(bool dependant_context = true);
8095 
8100  void IsolateInForegroundNotification();
8101 
8106  void IsolateInBackgroundNotification();
8107 
8113  void EnableMemorySavingsMode();
8114 
8118  void DisableMemorySavingsMode();
8119 
8127  void SetRAILMode(RAILMode rail_mode);
8128 
8133  void IncreaseHeapLimitForDebugging();
8134 
8138  void RestoreOriginalHeapLimit();
8139 
8144  bool IsHeapLimitIncreasedForDebugging();
8145 
8168  void SetJitCodeEventHandler(JitCodeEventOptions options,
8169  JitCodeEventHandler event_handler);
8170 
8180  void SetStackLimit(uintptr_t stack_limit);
8181 
8195  void GetCodeRange(void** start, size_t* length_in_bytes);
8196 
8198  void SetFatalErrorHandler(FatalErrorCallback that);
8199 
8201  void SetOOMErrorHandler(OOMErrorCallback that);
8202 
8208  void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
8209 
8217  void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
8218  size_t heap_limit);
8219 
8224  void SetAllowCodeGenerationFromStringsCallback(
8226 
8231  void SetAllowWasmCodeGenerationCallback(
8232  AllowWasmCodeGenerationCallback callback);
8233 
8238  void SetWasmModuleCallback(ExtensionCallback callback);
8239  void SetWasmInstanceCallback(ExtensionCallback callback);
8240 
8241  void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
8242 
8243  void SetWasmStreamingCallback(WasmStreamingCallback callback);
8244 
8249  bool IsDead();
8250 
8260  bool AddMessageListener(MessageCallback that,
8261  Local<Value> data = Local<Value>());
8262 
8274  bool AddMessageListenerWithErrorLevel(MessageCallback that,
8275  int message_levels,
8276  Local<Value> data = Local<Value>());
8277 
8281  void RemoveMessageListeners(MessageCallback that);
8282 
8284  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
8285 
8290  void SetCaptureStackTraceForUncaughtExceptions(
8291  bool capture, int frame_limit = 10,
8292  StackTrace::StackTraceOptions options = StackTrace::kOverview);
8293 
8299  void VisitExternalResources(ExternalResourceVisitor* visitor);
8300 
8305  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
8306 
8314  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
8315 
8321  void VisitWeakHandles(PersistentHandleVisitor* visitor);
8322 
8327  bool IsInUse();
8328 
8334  void SetAllowAtomicsWait(bool allow);
8335 
8336  Isolate() = delete;
8337  ~Isolate() = delete;
8338  Isolate(const Isolate&) = delete;
8339  Isolate& operator=(const Isolate&) = delete;
8340  // Deleting operator new and delete here is allowed as ctor and dtor is also
8341  // deleted.
8342  void* operator new(size_t size) = delete;
8343  void* operator new[](size_t size) = delete;
8344  void operator delete(void*, size_t) = delete;
8345  void operator delete[](void*, size_t) = delete;
8346 
8347  private:
8348  template <class K, class V, class Traits>
8349  friend class PersistentValueMapBase;
8350 
8351  internal::Object** GetDataFromSnapshotOnce(size_t index);
8352  void ReportExternalAllocationLimitReached();
8353  void CheckMemoryPressure();
8354 };
8355 
8356 class V8_EXPORT StartupData {
8357  public:
8358  const char* data;
8359  int raw_size;
8360 };
8361 
8362 
8367 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
8368 
8382 typedef uintptr_t (*ReturnAddressLocationResolver)(
8383  uintptr_t return_addr_location);
8384 
8385 
8389 class V8_EXPORT V8 {
8390  public:
8406  static void SetNativesDataBlob(StartupData* startup_blob);
8407  static void SetSnapshotDataBlob(StartupData* startup_blob);
8408 
8415  V8_DEPRECATED("Use SnapshotCreator",
8416  static StartupData CreateSnapshotDataBlob(
8417  const char* embedded_source = NULL));
8418 
8427  V8_DEPRECATED("Use SnapshotCreator",
8428  static StartupData WarmUpSnapshotDataBlob(
8429  StartupData cold_startup_blob, const char* warmup_source));
8430 
8432  static void SetDcheckErrorHandler(DcheckErrorCallback that);
8433 
8434 
8438  static void SetFlagsFromString(const char* str, int length);
8439 
8443  static void SetFlagsFromCommandLine(int* argc,
8444  char** argv,
8445  bool remove_flags);
8446 
8448  static const char* GetVersion();
8449 
8454  static bool Initialize();
8455 
8460  static void SetEntropySource(EntropySource source);
8461 
8466  static void SetReturnAddressLocationResolver(
8467  ReturnAddressLocationResolver return_address_resolver);
8468 
8478  static bool Dispose();
8479 
8487  static bool InitializeICU(const char* icu_data_file = nullptr);
8488 
8501  static bool InitializeICUDefaultLocation(const char* exec_path,
8502  const char* icu_data_file = nullptr);
8503 
8520  static void InitializeExternalStartupData(const char* directory_path);
8521  static void InitializeExternalStartupData(const char* natives_blob,
8522  const char* snapshot_blob);
8527  static void InitializePlatform(Platform* platform);
8528 
8533  static void ShutdownPlatform();
8534 
8535 #if V8_OS_POSIX
8536 
8555  static bool TryHandleSignal(int signal_number, void* info, void* context);
8556 #endif // V8_OS_POSIX
8557 
8562  V8_DEPRECATE_SOON("Use EnableWebAssemblyTrapHandler",
8563  static bool RegisterDefaultSignalHandler());
8564 
8571  static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
8572 
8573  private:
8574  V8();
8575 
8576  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
8577  internal::Object** handle);
8578  static internal::Object** CopyPersistent(internal::Object** handle);
8579  static void DisposeGlobal(internal::Object** global_handle);
8580  static void MakeWeak(internal::Object** location, void* data,
8581  WeakCallbackInfo<void>::Callback weak_callback,
8582  WeakCallbackType type);
8583  static void MakeWeak(internal::Object** location, void* data,
8584  // Must be 0 or -1.
8585  int internal_field_index1,
8586  // Must be 1 or -1.
8587  int internal_field_index2,
8588  WeakCallbackInfo<void>::Callback weak_callback);
8589  static void MakeWeak(internal::Object*** location_addr);
8590  static void* ClearWeak(internal::Object** location);
8591  static void AnnotateStrongRetainer(internal::Object** location,
8592  const char* label);
8593  static Value* Eternalize(Isolate* isolate, Value* handle);
8594 
8595  static void RegisterExternallyReferencedObject(internal::Object** object,
8596  internal::Isolate* isolate);
8597 
8598  template <class K, class V, class T>
8599  friend class PersistentValueMapBase;
8600 
8601  static void FromJustIsNothing();
8602  static void ToLocalEmpty();
8603  static void InternalFieldOutOfBounds(int index);
8604  template <class T> friend class Local;
8605  template <class T>
8606  friend class MaybeLocal;
8607  template <class T>
8608  friend class Maybe;
8609  template <class T>
8610  friend class WeakCallbackInfo;
8611  template <class T> friend class Eternal;
8612  template <class T> friend class PersistentBase;
8613  template <class T, class M> friend class Persistent;
8614  friend class Context;
8615 };
8616 
8620 class V8_EXPORT SnapshotCreator {
8621  public:
8622  enum class FunctionCodeHandling { kClear, kKeep };
8623 
8632  SnapshotCreator(Isolate* isolate,
8633  const intptr_t* external_references = nullptr,
8634  StartupData* existing_blob = nullptr);
8635 
8644  SnapshotCreator(const intptr_t* external_references = nullptr,
8645  StartupData* existing_blob = nullptr);
8646 
8647  ~SnapshotCreator();
8648 
8652  Isolate* GetIsolate();
8653 
8661  void SetDefaultContext(Local<Context> context,
8664 
8673  size_t AddContext(Local<Context> context,
8676 
8681  size_t AddTemplate(Local<Template> template_obj);
8682 
8689  template <class T>
8690  V8_INLINE size_t AddData(Local<Context> context, Local<T> object);
8691 
8698  template <class T>
8699  V8_INLINE size_t AddData(Local<T> object);
8700 
8709  StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8710 
8711  // Disallow copying and assigning.
8712  SnapshotCreator(const SnapshotCreator&) = delete;
8713  void operator=(const SnapshotCreator&) = delete;
8714 
8715  private:
8716  size_t AddData(Local<Context> context, internal::Object* object);
8717  size_t AddData(internal::Object* object);
8718 
8719  void* data_;
8720 };
8721 
8732 template <class T>
8733 class Maybe {
8734  public:
8735  V8_INLINE bool IsNothing() const { return !has_value_; }
8736  V8_INLINE bool IsJust() const { return has_value_; }
8737 
8741  V8_INLINE T ToChecked() const { return FromJust(); }
8742 
8747  V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
8748  if (V8_LIKELY(IsJust())) *out = value_;
8749  return IsJust();
8750  }
8751 
8756  V8_INLINE T FromJust() const {
8757  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8758  return value_;
8759  }
8760 
8765  V8_INLINE T FromMaybe(const T& default_value) const {
8766  return has_value_ ? value_ : default_value;
8767  }
8768 
8769  V8_INLINE bool operator==(const Maybe& other) const {
8770  return (IsJust() == other.IsJust()) &&
8771  (!IsJust() || FromJust() == other.FromJust());
8772  }
8773 
8774  V8_INLINE bool operator!=(const Maybe& other) const {
8775  return !operator==(other);
8776  }
8777 
8778  private:
8779  Maybe() : has_value_(false) {}
8780  explicit Maybe(const T& t) : has_value_(true), value_(t) {}
8781 
8782  bool has_value_;
8783  T value_;
8784 
8785  template <class U>
8786  friend Maybe<U> Nothing();
8787  template <class U>
8788  friend Maybe<U> Just(const U& u);
8789 };
8790 
8791 template <class T>
8792 inline Maybe<T> Nothing() {
8793  return Maybe<T>();
8794 }
8795 
8796 template <class T>
8797 inline Maybe<T> Just(const T& t) {
8798  return Maybe<T>(t);
8799 }
8800 
8801 // A template specialization of Maybe<T> for the case of T = void.
8802 template <>
8803 class Maybe<void> {
8804  public:
8805  V8_INLINE bool IsNothing() const { return !is_valid_; }
8806  V8_INLINE bool IsJust() const { return is_valid_; }
8807 
8808  V8_INLINE bool operator==(const Maybe& other) const {
8809  return IsJust() == other.IsJust();
8810  }
8811 
8812  V8_INLINE bool operator!=(const Maybe& other) const {
8813  return !operator==(other);
8814  }
8815 
8816  private:
8817  struct JustTag {};
8818 
8819  Maybe() : is_valid_(false) {}
8820  explicit Maybe(JustTag) : is_valid_(true) {}
8821 
8822  bool is_valid_;
8823 
8824  template <class U>
8825  friend Maybe<U> Nothing();
8826  friend Maybe<void> JustVoid();
8827 };
8828 
8829 inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); }
8830 
8834 class V8_EXPORT TryCatch {
8835  public:
8841  explicit TryCatch(Isolate* isolate);
8842 
8846  ~TryCatch();
8847 
8851  bool HasCaught() const;
8852 
8861  bool CanContinue() const;
8862 
8875  bool HasTerminated() const;
8876 
8884  Local<Value> ReThrow();
8885 
8892  Local<Value> Exception() const;
8893 
8898  V8_DEPRECATED("Use maybe version.", Local<Value> StackTrace() const);
8899  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
8900  Local<Context> context) const;
8901 
8909  Local<v8::Message> Message() const;
8910 
8921  void Reset();
8922 
8931  void SetVerbose(bool value);
8932 
8936  bool IsVerbose() const;
8937 
8943  void SetCaptureMessage(bool value);
8944 
8956  static void* JSStackComparableAddress(TryCatch* handler) {
8957  if (handler == NULL) return NULL;
8958  return handler->js_stack_comparable_address_;
8959  }
8960 
8961  TryCatch(const TryCatch&) = delete;
8962  void operator=(const TryCatch&) = delete;
8963 
8964  private:
8965  // Declaring operator new and delete as deleted is not spec compliant.
8966  // Therefore declare them private instead to disable dynamic alloc
8967  void* operator new(size_t size);
8968  void* operator new[](size_t size);
8969  void operator delete(void*, size_t);
8970  void operator delete[](void*, size_t);
8971 
8972  void ResetInternal();
8973 
8974  internal::Isolate* isolate_;
8975  TryCatch* next_;
8976  void* exception_;
8977  void* message_obj_;
8978  void* js_stack_comparable_address_;
8979  bool is_verbose_ : 1;
8980  bool can_continue_ : 1;
8981  bool capture_message_ : 1;
8982  bool rethrow_ : 1;
8983  bool has_terminated_ : 1;
8984 
8985  friend class internal::Isolate;
8986 };
8987 
8988 
8989 // --- Context ---
8990 
8991 
8995 class V8_EXPORT ExtensionConfiguration {
8996  public:
8997  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
8998  ExtensionConfiguration(int name_count, const char* names[])
8999  : name_count_(name_count), names_(names) { }
9000 
9001  const char** begin() const { return &names_[0]; }
9002  const char** end() const { return &names_[name_count_]; }
9003 
9004  private:
9005  const int name_count_;
9006  const char** names_;
9007 };
9008 
9013 class V8_EXPORT Context {
9014  public:
9028 
9033  void DetachGlobal();
9034 
9053  static Local<Context> New(
9054  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
9056  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
9057  DeserializeInternalFieldsCallback internal_fields_deserializer =
9059 
9079  static MaybeLocal<Context> FromSnapshot(
9080  Isolate* isolate, size_t context_snapshot_index,
9081  DeserializeInternalFieldsCallback embedder_fields_deserializer =
9083  ExtensionConfiguration* extensions = nullptr,
9084  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9085 
9103  static MaybeLocal<Object> NewRemoteContext(
9104  Isolate* isolate, Local<ObjectTemplate> global_template,
9105  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9106 
9111  void SetSecurityToken(Local<Value> token);
9112 
9114  void UseDefaultSecurityToken();
9115 
9117  Local<Value> GetSecurityToken();
9118 
9125  void Enter();
9126 
9131  void Exit();
9132 
9134  Isolate* GetIsolate();
9135 
9140  enum EmbedderDataFields { kDebugIdIndex = 0 };
9141 
9145  uint32_t GetNumberOfEmbedderDataFields();
9146 
9151  V8_INLINE Local<Value> GetEmbedderData(int index);
9152 
9159  Local<Object> GetExtrasBindingObject();
9160 
9166  void SetEmbedderData(int index, Local<Value> value);
9167 
9174  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
9175 
9181  void SetAlignedPointerInEmbedderData(int index, void* value);
9182 
9196  void AllowCodeGenerationFromStrings(bool allow);
9197 
9202  bool IsCodeGenerationFromStringsAllowed();
9203 
9209  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
9210 
9216  template <class T>
9217  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
9218 
9223  class Scope {
9224  public:
9225  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
9226  context_->Enter();
9227  }
9228  V8_INLINE ~Scope() { context_->Exit(); }
9229 
9230  private:
9231  Local<Context> context_;
9232  };
9233 
9239  class V8_EXPORT BackupIncumbentScope {
9240  public:
9245  explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
9247 
9248  private:
9249  friend class internal::Isolate;
9250 
9251  Local<Context> backup_incumbent_context_;
9252  const BackupIncumbentScope* prev_ = nullptr;
9253  };
9254 
9255  private:
9256  friend class Value;
9257  friend class Script;
9258  friend class Object;
9259  friend class Function;
9260 
9261  internal::Object** GetDataFromSnapshotOnce(size_t index);
9262  Local<Value> SlowGetEmbedderData(int index);
9263  void* SlowGetAlignedPointerFromEmbedderData(int index);
9264 };
9265 
9266 
9343 class V8_EXPORT Unlocker {
9344  public:
9348  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
9349 
9350  ~Unlocker();
9351  private:
9352  void Initialize(Isolate* isolate);
9353 
9354  internal::Isolate* isolate_;
9355 };
9356 
9357 
9358 class V8_EXPORT Locker {
9359  public:
9363  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
9364 
9365  ~Locker();
9366 
9371  static bool IsLocked(Isolate* isolate);
9372 
9376  static bool IsActive();
9377 
9378  // Disallow copying and assigning.
9379  Locker(const Locker&) = delete;
9380  void operator=(const Locker&) = delete;
9381 
9382  private:
9383  void Initialize(Isolate* isolate);
9384 
9385  bool has_lock_;
9386  bool top_level_;
9387  internal::Isolate* isolate_;
9388 };
9389 
9390 
9391 // --- Implementation ---
9392 
9393 
9394 namespace internal {
9395 
9401 class Internals {
9402  public:
9403  // These values match non-compiler-dependent values defined within
9404  // the implementation of v8.
9405  static const int kHeapObjectMapOffset = 0;
9406  static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
9407  static const int kStringResourceOffset = 3 * kApiPointerSize;
9408 
9409  static const int kOddballKindOffset = 4 * kApiPointerSize + kApiDoubleSize;
9410  static const int kForeignAddressOffset = kApiPointerSize;
9411  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
9412  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
9413  static const int kContextHeaderSize = 2 * kApiPointerSize;
9414  static const int kContextEmbedderDataIndex = 5;
9415  static const int kFullStringRepresentationMask = 0x0f;
9416  static const int kStringEncodingMask = 0x8;
9417  static const int kExternalTwoByteRepresentationTag = 0x02;
9418  static const int kExternalOneByteRepresentationTag = 0x0a;
9419 
9420  static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
9421  static const int kExternalMemoryOffset = 4 * kApiPointerSize;
9422  static const int kExternalMemoryLimitOffset =
9423  kExternalMemoryOffset + kApiInt64Size;
9424  static const int kExternalMemoryAtLastMarkCompactOffset =
9425  kExternalMemoryLimitOffset + kApiInt64Size;
9426  static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
9427  kApiInt64Size + kApiInt64Size +
9428  kApiPointerSize + kApiPointerSize;
9429  static const int kUndefinedValueRootIndex = 4;
9430  static const int kTheHoleValueRootIndex = 5;
9431  static const int kNullValueRootIndex = 6;
9432  static const int kTrueValueRootIndex = 7;
9433  static const int kFalseValueRootIndex = 8;
9434  static const int kEmptyStringRootIndex = 9;
9435 
9436  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
9437  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
9438  static const int kNodeStateMask = 0x7;
9439  static const int kNodeStateIsWeakValue = 2;
9440  static const int kNodeStateIsPendingValue = 3;
9441  static const int kNodeStateIsNearDeathValue = 4;
9442  static const int kNodeIsIndependentShift = 3;
9443  static const int kNodeIsActiveShift = 4;
9444 
9445  static const int kFirstNonstringType = 0x80;
9446  static const int kOddballType = 0x83;
9447  static const int kForeignType = 0x87;
9448  static const int kJSSpecialApiObjectType = 0x410;
9449  static const int kJSApiObjectType = 0x420;
9450  static const int kJSObjectType = 0x421;
9451 
9452  static const int kUndefinedOddballKind = 5;
9453  static const int kNullOddballKind = 3;
9454 
9455  static const uint32_t kNumIsolateDataSlots = 4;
9456 
9457  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
9458  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
9459 #ifdef V8_ENABLE_CHECKS
9460  CheckInitializedImpl(isolate);
9461 #endif
9462  }
9463 
9464  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
9465  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
9466  kHeapObjectTag);
9467  }
9468 
9469  V8_INLINE static int SmiValue(const internal::Object* value) {
9470  return PlatformSmiTagging::SmiToInt(value);
9471  }
9472 
9473  V8_INLINE static internal::Object* IntToSmi(int value) {
9474  return PlatformSmiTagging::IntToSmi(value);
9475  }
9476 
9477  V8_INLINE static bool IsValidSmi(intptr_t value) {
9478  return PlatformSmiTagging::IsValidSmi(value);
9479  }
9480 
9481  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
9482  typedef internal::Object O;
9483  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
9484  return ReadField<uint16_t>(map, kMapInstanceTypeOffset);
9485  }
9486 
9487  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
9488  typedef internal::Object O;
9489  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
9490  }
9491 
9492  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
9493  int representation = (instance_type & kFullStringRepresentationMask);
9494  return representation == kExternalTwoByteRepresentationTag;
9495  }
9496 
9497  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
9498  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9499  return *addr & static_cast<uint8_t>(1U << shift);
9500  }
9501 
9502  V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
9503  bool value, int shift) {
9504  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9505  uint8_t mask = static_cast<uint8_t>(1U << shift);
9506  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
9507  }
9508 
9509  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
9510  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9511  return *addr & kNodeStateMask;
9512  }
9513 
9514  V8_INLINE static void UpdateNodeState(internal::Object** obj,
9515  uint8_t value) {
9516  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9517  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
9518  }
9519 
9520  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
9521  uint32_t slot,
9522  void* data) {
9523  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
9524  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
9525  *reinterpret_cast<void**>(addr) = data;
9526  }
9527 
9528  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
9529  uint32_t slot) {
9530  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
9531  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
9532  return *reinterpret_cast<void* const*>(addr);
9533  }
9534 
9535  V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
9536  int index) {
9537  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
9538  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
9539  }
9540 
9541  template <typename T>
9542  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
9543  const uint8_t* addr =
9544  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
9545  return *reinterpret_cast<const T*>(addr);
9546  }
9547 
9548  template <typename T>
9549  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
9550  typedef internal::Object O;
9551  typedef internal::Internals I;
9552  O* ctx = *reinterpret_cast<O* const*>(context);
9553  int embedder_data_offset = I::kContextHeaderSize +
9554  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
9555  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
9556  int value_offset =
9557  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
9558  return I::ReadField<T>(embedder_data, value_offset);
9559  }
9560 };
9561 
9562 // Only perform cast check for types derived from v8::Data since
9563 // other types do not implement the Cast method.
9564 template <bool PerformCheck>
9565 struct CastCheck {
9566  template <class T>
9567  static void Perform(T* data);
9568 };
9569 
9570 template <>
9571 template <class T>
9572 void CastCheck<true>::Perform(T* data) {
9573  T::Cast(data);
9574 }
9575 
9576 template <>
9577 template <class T>
9578 void CastCheck<false>::Perform(T* data) {}
9579 
9580 template <class T>
9581 V8_INLINE void PerformCastCheck(T* data) {
9582  CastCheck<std::is_base_of<Data, T>::value>::Perform(data);
9583 }
9584 
9585 } // namespace internal
9586 
9587 
9588 template <class T>
9590  return New(isolate, that.val_);
9591 }
9592 
9593 template <class T>
9594 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
9595  return New(isolate, that.val_);
9596 }
9597 
9598 
9599 template <class T>
9600 Local<T> Local<T>::New(Isolate* isolate, T* that) {
9601  if (that == NULL) return Local<T>();
9602  T* that_ptr = that;
9603  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
9604  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
9605  reinterpret_cast<internal::Isolate*>(isolate), *p)));
9606 }
9607 
9608 
9609 template<class T>
9610 template<class S>
9611 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
9612  TYPE_CHECK(T, S);
9613  val_ = reinterpret_cast<T*>(
9614  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
9615 }
9616 
9617 template <class T>
9618 Local<T> Eternal<T>::Get(Isolate* isolate) const {
9619  // The eternal handle will never go away, so as with the roots, we don't even
9620  // need to open a handle.
9621  return Local<T>(val_);
9622 }
9623 
9624 
9625 template <class T>
9627  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
9628  return Local<T>(val_);
9629 }
9630 
9631 
9632 template <class T>
9633 void* WeakCallbackInfo<T>::GetInternalField(int index) const {
9634 #ifdef V8_ENABLE_CHECKS
9635  if (index < 0 || index >= kEmbedderFieldsInWeakCallback) {
9636  V8::InternalFieldOutOfBounds(index);
9637  }
9638 #endif
9639  return embedder_fields_[index];
9640 }
9641 
9642 
9643 template <class T>
9644 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
9645  if (that == NULL) return NULL;
9646  internal::Object** p = reinterpret_cast<internal::Object**>(that);
9647  return reinterpret_cast<T*>(
9648  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
9649  p));
9650 }
9651 
9652 
9653 template <class T, class M>
9654 template <class S, class M2>
9655 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
9656  TYPE_CHECK(T, S);
9657  this->Reset();
9658  if (that.IsEmpty()) return;
9659  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
9660  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
9661  M::Copy(that, this);
9662 }
9663 
9664 template <class T>
9665 bool PersistentBase<T>::IsIndependent() const {
9666  typedef internal::Internals I;
9667  if (this->IsEmpty()) return false;
9668  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
9669  I::kNodeIsIndependentShift);
9670 }
9671 
9672 template <class T>
9674  typedef internal::Internals I;
9675  if (this->IsEmpty()) return false;
9676  uint8_t node_state =
9677  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
9678  return node_state == I::kNodeStateIsNearDeathValue ||
9679  node_state == I::kNodeStateIsPendingValue;
9680 }
9681 
9682 
9683 template <class T>
9685  typedef internal::Internals I;
9686  if (this->IsEmpty()) return false;
9687  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
9688  I::kNodeStateIsWeakValue;
9689 }
9690 
9691 
9692 template <class T>
9694  if (this->IsEmpty()) return;
9695  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
9696  val_ = 0;
9697 }
9698 
9699 
9700 template <class T>
9701 template <class S>
9702 void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
9703  TYPE_CHECK(T, S);
9704  Reset();
9705  if (other.IsEmpty()) return;
9706  this->val_ = New(isolate, other.val_);
9707 }
9708 
9709 
9710 template <class T>
9711 template <class S>
9712 void PersistentBase<T>::Reset(Isolate* isolate,
9713  const PersistentBase<S>& other) {
9714  TYPE_CHECK(T, S);
9715  Reset();
9716  if (other.IsEmpty()) return;
9717  this->val_ = New(isolate, other.val_);
9718 }
9719 
9720 
9721 template <class T>
9722 template <typename P>
9724  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
9725  WeakCallbackType type) {
9726  typedef typename WeakCallbackInfo<void>::Callback Callback;
9727  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
9728  reinterpret_cast<Callback>(callback), type);
9729 }
9730 
9731 template <class T>
9733  V8::MakeWeak(reinterpret_cast<internal::Object***>(&this->val_));
9734 }
9735 
9736 template <class T>
9737 template <typename P>
9739  return reinterpret_cast<P*>(
9740  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
9741 }
9742 
9743 template <class T>
9745  V8::AnnotateStrongRetainer(reinterpret_cast<internal::Object**>(this->val_),
9746  label);
9747 }
9748 
9749 template <class T>
9751  if (IsEmpty()) return;
9752  V8::RegisterExternallyReferencedObject(
9753  reinterpret_cast<internal::Object**>(this->val_),
9754  reinterpret_cast<internal::Isolate*>(isolate));
9755 }
9756 
9757 template <class T>
9759  typedef internal::Internals I;
9760  if (this->IsEmpty()) return;
9761  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
9762  I::kNodeIsIndependentShift);
9763 }
9764 
9765 template <class T>
9767  typedef internal::Internals I;
9768  if (this->IsEmpty()) return;
9769  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
9770  I::kNodeIsActiveShift);
9771 }
9772 
9773 
9774 template <class T>
9775 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
9776  typedef internal::Internals I;
9777  if (this->IsEmpty()) return;
9778  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
9779  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9780  *reinterpret_cast<uint16_t*>(addr) = class_id;
9781 }
9782 
9783 
9784 template <class T>
9786  typedef internal::Internals I;
9787  if (this->IsEmpty()) return 0;
9788  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
9789  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9790  return *reinterpret_cast<uint16_t*>(addr);
9791 }
9792 
9793 
9794 template<typename T>
9795 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
9796 
9797 template<typename T>
9798 template<typename S>
9799 void ReturnValue<T>::Set(const Persistent<S>& handle) {
9800  TYPE_CHECK(T, S);
9801  if (V8_UNLIKELY(handle.IsEmpty())) {
9802  *value_ = GetDefaultValue();
9803  } else {
9804  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9805  }
9806 }
9807 
9808 template <typename T>
9809 template <typename S>
9810 void ReturnValue<T>::Set(const Global<S>& handle) {
9811  TYPE_CHECK(T, S);
9812  if (V8_UNLIKELY(handle.IsEmpty())) {
9813  *value_ = GetDefaultValue();
9814  } else {
9815  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9816  }
9817 }
9818 
9819 template <typename T>
9820 template <typename S>
9821 void ReturnValue<T>::Set(const Local<S> handle) {
9822  TYPE_CHECK(T, S);
9823  if (V8_UNLIKELY(handle.IsEmpty())) {
9824  *value_ = GetDefaultValue();
9825  } else {
9826  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9827  }
9828 }
9829 
9830 template<typename T>
9831 void ReturnValue<T>::Set(double i) {
9832  TYPE_CHECK(T, Number);
9833  Set(Number::New(GetIsolate(), i));
9834 }
9835 
9836 template<typename T>
9837 void ReturnValue<T>::Set(int32_t i) {
9838  TYPE_CHECK(T, Integer);
9839  typedef internal::Internals I;
9840  if (V8_LIKELY(I::IsValidSmi(i))) {
9841  *value_ = I::IntToSmi(i);
9842  return;
9843  }
9844  Set(Integer::New(GetIsolate(), i));
9845 }
9846 
9847 template<typename T>
9848 void ReturnValue<T>::Set(uint32_t i) {
9849  TYPE_CHECK(T, Integer);
9850  // Can't simply use INT32_MAX here for whatever reason.
9851  bool fits_into_int32_t = (i & (1U << 31)) == 0;
9852  if (V8_LIKELY(fits_into_int32_t)) {
9853  Set(static_cast<int32_t>(i));
9854  return;
9855  }
9856  Set(Integer::NewFromUnsigned(GetIsolate(), i));
9857 }
9858 
9859 template<typename T>
9860 void ReturnValue<T>::Set(bool value) {
9861  TYPE_CHECK(T, Boolean);
9862  typedef internal::Internals I;
9863  int root_index;
9864  if (value) {
9865  root_index = I::kTrueValueRootIndex;
9866  } else {
9867  root_index = I::kFalseValueRootIndex;
9868  }
9869  *value_ = *I::GetRoot(GetIsolate(), root_index);
9870 }
9871 
9872 template<typename T>
9873 void ReturnValue<T>::SetNull() {
9874  TYPE_CHECK(T, Primitive);
9875  typedef internal::Internals I;
9876  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
9877 }
9878 
9879 template<typename T>
9880 void ReturnValue<T>::SetUndefined() {
9881  TYPE_CHECK(T, Primitive);
9882  typedef internal::Internals I;
9883  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
9884 }
9885 
9886 template<typename T>
9887 void ReturnValue<T>::SetEmptyString() {
9888  TYPE_CHECK(T, String);
9889  typedef internal::Internals I;
9890  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
9891 }
9892 
9893 template <typename T>
9894 Isolate* ReturnValue<T>::GetIsolate() const {
9895  // Isolate is always the pointer below the default value on the stack.
9896  return *reinterpret_cast<Isolate**>(&value_[-2]);
9897 }
9898 
9899 template <typename T>
9900 Local<Value> ReturnValue<T>::Get() const {
9901  typedef internal::Internals I;
9902  if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex))
9903  return Local<Value>(*Undefined(GetIsolate()));
9904  return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
9905 }
9906 
9907 template <typename T>
9908 template <typename S>
9909 void ReturnValue<T>::Set(S* whatever) {
9910  // Uncompilable to prevent inadvertent misuse.
9911  TYPE_CHECK(S*, Primitive);
9912 }
9913 
9914 template<typename T>
9915 internal::Object* ReturnValue<T>::GetDefaultValue() {
9916  // Default value is always the pointer below value_ on the stack.
9917  return value_[-1];
9918 }
9919 
9920 template <typename T>
9921 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
9922  internal::Object** values,
9923  int length)
9924  : implicit_args_(implicit_args), values_(values), length_(length) {}
9925 
9926 template<typename T>
9928  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
9929  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
9930 }
9931 
9932 
9933 template<typename T>
9935  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
9936 }
9937 
9938 
9939 template<typename T>
9941  return Local<Object>(reinterpret_cast<Object*>(
9942  &implicit_args_[kHolderIndex]));
9943 }
9944 
9945 template <typename T>
9947  return Local<Value>(
9948  reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex]));
9949 }
9950 
9951 template <typename T>
9953  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
9954 }
9955 
9956 
9957 template<typename T>
9959  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
9960 }
9961 
9962 
9963 template<typename T>
9965  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
9966 }
9967 
9968 
9969 template<typename T>
9971  return !NewTarget()->IsUndefined();
9972 }
9973 
9974 
9975 template<typename T>
9977  return length_;
9978 }
9979 
9980 ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
9981  Local<Integer> resource_line_offset,
9982  Local<Integer> resource_column_offset,
9983  Local<Boolean> resource_is_shared_cross_origin,
9984  Local<Integer> script_id,
9985  Local<Value> source_map_url,
9986  Local<Boolean> resource_is_opaque,
9987  Local<Boolean> is_wasm, Local<Boolean> is_module,
9988  Local<PrimitiveArray> host_defined_options)
9989  : resource_name_(resource_name),
9990  resource_line_offset_(resource_line_offset),
9991  resource_column_offset_(resource_column_offset),
9992  options_(!resource_is_shared_cross_origin.IsEmpty() &&
9993  resource_is_shared_cross_origin->IsTrue(),
9994  !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue(),
9995  !is_wasm.IsEmpty() && is_wasm->IsTrue(),
9996  !is_module.IsEmpty() && is_module->IsTrue()),
9997  script_id_(script_id),
9998  source_map_url_(source_map_url),
9999  host_defined_options_(host_defined_options) {}
10000 
10001 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
10002 
10003 Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions() const {
10004  return host_defined_options_;
10005 }
10006 
10007 Local<Integer> ScriptOrigin::ResourceLineOffset() const {
10008  return resource_line_offset_;
10009 }
10010 
10011 
10012 Local<Integer> ScriptOrigin::ResourceColumnOffset() const {
10013  return resource_column_offset_;
10014 }
10015 
10016 
10017 Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
10018 
10019 
10020 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
10021 
10022 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
10023  CachedData* data)
10024  : source_string(string),
10025  resource_name(origin.ResourceName()),
10026  resource_line_offset(origin.ResourceLineOffset()),
10027  resource_column_offset(origin.ResourceColumnOffset()),
10028  resource_options(origin.Options()),
10029  source_map_url(origin.SourceMapUrl()),
10030  host_defined_options(origin.HostDefinedOptions()),
10031  cached_data(data) {}
10032 
10033 ScriptCompiler::Source::Source(Local<String> string,
10034  CachedData* data)
10035  : source_string(string), cached_data(data) {}
10036 
10037 
10038 ScriptCompiler::Source::~Source() {
10039  delete cached_data;
10040 }
10041 
10042 
10043 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
10044  const {
10045  return cached_data;
10046 }
10047 
10048 const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
10049  return resource_options;
10050 }
10051 
10052 Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
10053  return value ? True(isolate) : False(isolate);
10054 }
10055 
10056 void Template::Set(Isolate* isolate, const char* name, Local<Data> value) {
10058  .ToLocalChecked(),
10059  value);
10060 }
10061 
10062 FunctionTemplate* FunctionTemplate::Cast(Data* data) {
10063 #ifdef V8_ENABLE_CHECKS
10064  CheckCast(data);
10065 #endif
10066  return reinterpret_cast<FunctionTemplate*>(data);
10067 }
10068 
10069 ObjectTemplate* ObjectTemplate::Cast(Data* data) {
10070 #ifdef V8_ENABLE_CHECKS
10071  CheckCast(data);
10072 #endif
10073  return reinterpret_cast<ObjectTemplate*>(data);
10074 }
10075 
10076 Signature* Signature::Cast(Data* data) {
10077 #ifdef V8_ENABLE_CHECKS
10078  CheckCast(data);
10079 #endif
10080  return reinterpret_cast<Signature*>(data);
10081 }
10082 
10083 AccessorSignature* AccessorSignature::Cast(Data* data) {
10084 #ifdef V8_ENABLE_CHECKS
10085  CheckCast(data);
10086 #endif
10087  return reinterpret_cast<AccessorSignature*>(data);
10088 }
10089 
10091 #ifndef V8_ENABLE_CHECKS
10092  typedef internal::Object O;
10093  typedef internal::HeapObject HO;
10094  typedef internal::Internals I;
10095  O* obj = *reinterpret_cast<O**>(this);
10096  // Fast path: If the object is a plain JSObject, which is the common case, we
10097  // know where to find the internal fields and can return the value directly.
10098  auto instance_type = I::GetInstanceType(obj);
10099  if (instance_type == I::kJSObjectType ||
10100  instance_type == I::kJSApiObjectType ||
10101  instance_type == I::kJSSpecialApiObjectType) {
10102  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
10103  O* value = I::ReadField<O*>(obj, offset);
10104  O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
10105  return Local<Value>(reinterpret_cast<Value*>(result));
10106  }
10107 #endif
10108  return SlowGetInternalField(index);
10109 }
10110 
10111 
10113 #ifndef V8_ENABLE_CHECKS
10114  typedef internal::Object O;
10115  typedef internal::Internals I;
10116  O* obj = *reinterpret_cast<O**>(this);
10117  // Fast path: If the object is a plain JSObject, which is the common case, we
10118  // know where to find the internal fields and can return the value directly.
10119  auto instance_type = I::GetInstanceType(obj);
10120  if (V8_LIKELY(instance_type == I::kJSObjectType ||
10121  instance_type == I::kJSApiObjectType ||
10122  instance_type == I::kJSSpecialApiObjectType)) {
10123  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
10124  return I::ReadField<void*>(obj, offset);
10125  }
10126 #endif
10127  return SlowGetAlignedPointerFromInternalField(index);
10128 }
10129 
10130 String* String::Cast(v8::Value* value) {
10131 #ifdef V8_ENABLE_CHECKS
10132  CheckCast(value);
10133 #endif
10134  return static_cast<String*>(value);
10135 }
10136 
10137 
10139  typedef internal::Object* S;
10140  typedef internal::Internals I;
10141  I::CheckInitialized(isolate);
10142  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
10143  return Local<String>(reinterpret_cast<String*>(slot));
10144 }
10145 
10146 
10148  typedef internal::Object O;
10149  typedef internal::Internals I;
10150  O* obj = *reinterpret_cast<O* const*>(this);
10152  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
10153  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
10154  result = reinterpret_cast<String::ExternalStringResource*>(value);
10155  } else {
10156  result = NULL;
10157  }
10158 #ifdef V8_ENABLE_CHECKS
10159  VerifyExternalStringResource(result);
10160 #endif
10161  return result;
10162 }
10163 
10164 
10166  String::Encoding* encoding_out) const {
10167  typedef internal::Object O;
10168  typedef internal::Internals I;
10169  O* obj = *reinterpret_cast<O* const*>(this);
10170  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
10171  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
10172  ExternalStringResourceBase* resource = NULL;
10173  if (type == I::kExternalOneByteRepresentationTag ||
10174  type == I::kExternalTwoByteRepresentationTag) {
10175  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
10176  resource = static_cast<ExternalStringResourceBase*>(value);
10177  }
10178 #ifdef V8_ENABLE_CHECKS
10179  VerifyExternalStringResourceBase(resource, *encoding_out);
10180 #endif
10181  return resource;
10182 }
10183 
10184 
10185 bool Value::IsUndefined() const {
10186 #ifdef V8_ENABLE_CHECKS
10187  return FullIsUndefined();
10188 #else
10189  return QuickIsUndefined();
10190 #endif
10191 }
10192 
10193 bool Value::QuickIsUndefined() const {
10194  typedef internal::Object O;
10195  typedef internal::Internals I;
10196  O* obj = *reinterpret_cast<O* const*>(this);
10197  if (!I::HasHeapObjectTag(obj)) return false;
10198  if (I::GetInstanceType(obj) != I::kOddballType) return false;
10199  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
10200 }
10201 
10202 
10203 bool Value::IsNull() const {
10204 #ifdef V8_ENABLE_CHECKS
10205  return FullIsNull();
10206 #else
10207  return QuickIsNull();
10208 #endif
10209 }
10210 
10211 bool Value::QuickIsNull() const {
10212  typedef internal::Object O;
10213  typedef internal::Internals I;
10214  O* obj = *reinterpret_cast<O* const*>(this);
10215  if (!I::HasHeapObjectTag(obj)) return false;
10216  if (I::GetInstanceType(obj) != I::kOddballType) return false;
10217  return (I::GetOddballKind(obj) == I::kNullOddballKind);
10218 }
10219 
10221 #ifdef V8_ENABLE_CHECKS
10222  return FullIsNull() || FullIsUndefined();
10223 #else
10224  return QuickIsNullOrUndefined();
10225 #endif
10226 }
10227 
10228 bool Value::QuickIsNullOrUndefined() const {
10229  typedef internal::Object O;
10230  typedef internal::Internals I;
10231  O* obj = *reinterpret_cast<O* const*>(this);
10232  if (!I::HasHeapObjectTag(obj)) return false;
10233  if (I::GetInstanceType(obj) != I::kOddballType) return false;
10234  int kind = I::GetOddballKind(obj);
10235  return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
10236 }
10237 
10238 bool Value::IsString() const {
10239 #ifdef V8_ENABLE_CHECKS
10240  return FullIsString();
10241 #else
10242  return QuickIsString();
10243 #endif
10244 }
10245 
10246 bool Value::QuickIsString() const {
10247  typedef internal::Object O;
10248  typedef internal::Internals I;
10249  O* obj = *reinterpret_cast<O* const*>(this);
10250  if (!I::HasHeapObjectTag(obj)) return false;
10251  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
10252 }
10253 
10254 
10255 template <class T> Value* Value::Cast(T* value) {
10256  return static_cast<Value*>(value);
10257 }
10258 
10259 
10260 Local<Boolean> Value::ToBoolean() const {
10261  return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
10262  .FromMaybe(Local<Boolean>());
10263 }
10264 
10265 
10266 Local<String> Value::ToString() const {
10267  return ToString(Isolate::GetCurrent()->GetCurrentContext())
10268  .FromMaybe(Local<String>());
10269 }
10270 
10271 
10272 Local<Object> Value::ToObject() const {
10273  return ToObject(Isolate::GetCurrent()->GetCurrentContext())
10274  .FromMaybe(Local<Object>());
10275 }
10276 
10277 
10278 Local<Integer> Value::ToInteger() const {
10279  return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
10280  .FromMaybe(Local<Integer>());
10281 }
10282 
10283 
10284 Boolean* Boolean::Cast(v8::Value* value) {
10285 #ifdef V8_ENABLE_CHECKS
10286  CheckCast(value);
10287 #endif
10288  return static_cast<Boolean*>(value);
10289 }
10290 
10291 
10292 Name* Name::Cast(v8::Value* value) {
10293 #ifdef V8_ENABLE_CHECKS
10294  CheckCast(value);
10295 #endif
10296  return static_cast<Name*>(value);
10297 }
10298 
10299 
10300 Symbol* Symbol::Cast(v8::Value* value) {
10301 #ifdef V8_ENABLE_CHECKS
10302  CheckCast(value);
10303 #endif
10304  return static_cast<Symbol*>(value);
10305 }
10306 
10307 
10308 Private* Private::Cast(Data* data) {
10309 #ifdef V8_ENABLE_CHECKS
10310  CheckCast(data);
10311 #endif
10312  return reinterpret_cast<Private*>(data);
10313 }
10314 
10315 
10316 Number* Number::Cast(v8::Value* value) {
10317 #ifdef V8_ENABLE_CHECKS
10318  CheckCast(value);
10319 #endif
10320  return static_cast<Number*>(value);
10321 }
10322 
10323 
10324 Integer* Integer::Cast(v8::Value* value) {
10325 #ifdef V8_ENABLE_CHECKS
10326  CheckCast(value);
10327 #endif
10328  return static_cast<Integer*>(value);
10329 }
10330 
10331 
10332 Int32* Int32::Cast(v8::Value* value) {
10333 #ifdef V8_ENABLE_CHECKS
10334  CheckCast(value);
10335 #endif
10336  return static_cast<Int32*>(value);
10337 }
10338 
10339 
10340 Uint32* Uint32::Cast(v8::Value* value) {
10341 #ifdef V8_ENABLE_CHECKS
10342  CheckCast(value);
10343 #endif
10344  return static_cast<Uint32*>(value);
10345 }
10346 
10347 BigInt* BigInt::Cast(v8::Value* value) {
10348 #ifdef V8_ENABLE_CHECKS
10349  CheckCast(value);
10350 #endif
10351  return static_cast<BigInt*>(value);
10352 }
10353 
10354 Date* Date::Cast(v8::Value* value) {
10355 #ifdef V8_ENABLE_CHECKS
10356  CheckCast(value);
10357 #endif
10358  return static_cast<Date*>(value);
10359 }
10360 
10361 
10362 StringObject* StringObject::Cast(v8::Value* value) {
10363 #ifdef V8_ENABLE_CHECKS
10364  CheckCast(value);
10365 #endif
10366  return static_cast<StringObject*>(value);
10367 }
10368 
10369 
10370 SymbolObject* SymbolObject::Cast(v8::Value* value) {
10371 #ifdef V8_ENABLE_CHECKS
10372  CheckCast(value);
10373 #endif
10374  return static_cast<SymbolObject*>(value);
10375 }
10376 
10377 
10378 NumberObject* NumberObject::Cast(v8::Value* value) {
10379 #ifdef V8_ENABLE_CHECKS
10380  CheckCast(value);
10381 #endif
10382  return static_cast<NumberObject*>(value);
10383 }
10384 
10385 BigIntObject* BigIntObject::Cast(v8::Value* value) {
10386 #ifdef V8_ENABLE_CHECKS
10387  CheckCast(value);
10388 #endif
10389  return static_cast<BigIntObject*>(value);
10390 }
10391 
10392 BooleanObject* BooleanObject::Cast(v8::Value* value) {
10393 #ifdef V8_ENABLE_CHECKS
10394  CheckCast(value);
10395 #endif
10396  return static_cast<BooleanObject*>(value);
10397 }
10398 
10399 
10400 RegExp* RegExp::Cast(v8::Value* value) {
10401 #ifdef V8_ENABLE_CHECKS
10402  CheckCast(value);
10403 #endif
10404  return static_cast<RegExp*>(value);
10405 }
10406 
10407 
10408 Object* Object::Cast(v8::Value* value) {
10409 #ifdef V8_ENABLE_CHECKS
10410  CheckCast(value);
10411 #endif
10412  return static_cast<Object*>(value);
10413 }
10414 
10415 
10416 Array* Array::Cast(v8::Value* value) {
10417 #ifdef V8_ENABLE_CHECKS
10418  CheckCast(value);
10419 #endif
10420  return static_cast<Array*>(value);
10421 }
10422 
10423 
10424 Map* Map::Cast(v8::Value* value) {
10425 #ifdef V8_ENABLE_CHECKS
10426  CheckCast(value);
10427 #endif
10428  return static_cast<Map*>(value);
10429 }
10430 
10431 
10432 Set* Set::Cast(v8::Value* value) {
10433 #ifdef V8_ENABLE_CHECKS
10434  CheckCast(value);
10435 #endif
10436  return static_cast<Set*>(value);
10437 }
10438 
10439 
10440 Promise* Promise::Cast(v8::Value* value) {
10441 #ifdef V8_ENABLE_CHECKS
10442  CheckCast(value);
10443 #endif
10444  return static_cast<Promise*>(value);
10445 }
10446 
10447 
10448 Proxy* Proxy::Cast(v8::Value* value) {
10449 #ifdef V8_ENABLE_CHECKS
10450  CheckCast(value);
10451 #endif
10452  return static_cast<Proxy*>(value);
10453 }
10454 
10455 WasmCompiledModule* WasmCompiledModule::Cast(v8::Value* value) {
10456 #ifdef V8_ENABLE_CHECKS
10457  CheckCast(value);
10458 #endif
10459  return static_cast<WasmCompiledModule*>(value);
10460 }
10461 
10462 Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
10463 #ifdef V8_ENABLE_CHECKS
10464  CheckCast(value);
10465 #endif
10466  return static_cast<Promise::Resolver*>(value);
10467 }
10468 
10469 
10470 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
10471 #ifdef V8_ENABLE_CHECKS
10472  CheckCast(value);
10473 #endif
10474  return static_cast<ArrayBuffer*>(value);
10475 }
10476 
10477 
10478 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
10479 #ifdef V8_ENABLE_CHECKS
10480  CheckCast(value);
10481 #endif
10482  return static_cast<ArrayBufferView*>(value);
10483 }
10484 
10485 
10486 TypedArray* TypedArray::Cast(v8::Value* value) {
10487 #ifdef V8_ENABLE_CHECKS
10488  CheckCast(value);
10489 #endif
10490  return static_cast<TypedArray*>(value);
10491 }
10492 
10493 
10494 Uint8Array* Uint8Array::Cast(v8::Value* value) {
10495 #ifdef V8_ENABLE_CHECKS
10496  CheckCast(value);
10497 #endif
10498  return static_cast<Uint8Array*>(value);
10499 }
10500 
10501 
10502 Int8Array* Int8Array::Cast(v8::Value* value) {
10503 #ifdef V8_ENABLE_CHECKS
10504  CheckCast(value);
10505 #endif
10506  return static_cast<Int8Array*>(value);
10507 }
10508 
10509 
10510 Uint16Array* Uint16Array::Cast(v8::Value* value) {
10511 #ifdef V8_ENABLE_CHECKS
10512  CheckCast(value);
10513 #endif
10514  return static_cast<Uint16Array*>(value);
10515 }
10516 
10517 
10518 Int16Array* Int16Array::Cast(v8::Value* value) {
10519 #ifdef V8_ENABLE_CHECKS
10520  CheckCast(value);
10521 #endif
10522  return static_cast<Int16Array*>(value);
10523 }
10524 
10525 
10526 Uint32Array* Uint32Array::Cast(v8::Value* value) {
10527 #ifdef V8_ENABLE_CHECKS
10528  CheckCast(value);
10529 #endif
10530  return static_cast<Uint32Array*>(value);
10531 }
10532 
10533 
10534 Int32Array* Int32Array::Cast(v8::Value* value) {
10535 #ifdef V8_ENABLE_CHECKS
10536  CheckCast(value);
10537 #endif
10538  return static_cast<Int32Array*>(value);
10539 }
10540 
10541 
10542 Float32Array* Float32Array::Cast(v8::Value* value) {
10543 #ifdef V8_ENABLE_CHECKS
10544  CheckCast(value);
10545 #endif
10546  return static_cast<Float32Array*>(value);
10547 }
10548 
10549 
10550 Float64Array* Float64Array::Cast(v8::Value* value) {
10551 #ifdef V8_ENABLE_CHECKS
10552  CheckCast(value);
10553 #endif
10554  return static_cast<Float64Array*>(value);
10555 }
10556 
10557 BigInt64Array* BigInt64Array::Cast(v8::Value* value) {
10558 #ifdef V8_ENABLE_CHECKS
10559  CheckCast(value);
10560 #endif
10561  return static_cast<BigInt64Array*>(value);
10562 }
10563 
10564 BigUint64Array* BigUint64Array::Cast(v8::Value* value) {
10565 #ifdef V8_ENABLE_CHECKS
10566  CheckCast(value);
10567 #endif
10568  return static_cast<BigUint64Array*>(value);
10569 }
10570 
10571 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
10572 #ifdef V8_ENABLE_CHECKS
10573  CheckCast(value);
10574 #endif
10575  return static_cast<Uint8ClampedArray*>(value);
10576 }
10577 
10578 
10579 DataView* DataView::Cast(v8::Value* value) {
10580 #ifdef V8_ENABLE_CHECKS
10581  CheckCast(value);
10582 #endif
10583  return static_cast<DataView*>(value);
10584 }
10585 
10586 
10587 SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
10588 #ifdef V8_ENABLE_CHECKS
10589  CheckCast(value);
10590 #endif
10591  return static_cast<SharedArrayBuffer*>(value);
10592 }
10593 
10594 
10595 Function* Function::Cast(v8::Value* value) {
10596 #ifdef V8_ENABLE_CHECKS
10597  CheckCast(value);
10598 #endif
10599  return static_cast<Function*>(value);
10600 }
10601 
10602 
10603 External* External::Cast(v8::Value* value) {
10604 #ifdef V8_ENABLE_CHECKS
10605  CheckCast(value);
10606 #endif
10607  return static_cast<External*>(value);
10608 }
10609 
10610 
10611 template<typename T>
10613  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
10614 }
10615 
10616 
10617 template<typename T>
10619  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
10620 }
10621 
10622 
10623 template<typename T>
10625  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
10626 }
10627 
10628 
10629 template<typename T>
10631  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
10632 }
10633 
10634 
10635 template<typename T>
10637  return ReturnValue<T>(&args_[kReturnValueIndex]);
10638 }
10639 
10640 template <typename T>
10642  typedef internal::Internals I;
10643  return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(0);
10644 }
10645 
10646 
10647 Local<Primitive> Undefined(Isolate* isolate) {
10648  typedef internal::Object* S;
10649  typedef internal::Internals I;
10650  I::CheckInitialized(isolate);
10651  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
10652  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10653 }
10654 
10655 
10656 Local<Primitive> Null(Isolate* isolate) {
10657  typedef internal::Object* S;
10658  typedef internal::Internals I;
10659  I::CheckInitialized(isolate);
10660  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
10661  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10662 }
10663 
10664 
10665 Local<Boolean> True(Isolate* isolate) {
10666  typedef internal::Object* S;
10667  typedef internal::Internals I;
10668  I::CheckInitialized(isolate);
10669  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
10670  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
10671 }
10672 
10673 
10674 Local<Boolean> False(Isolate* isolate) {
10675  typedef internal::Object* S;
10676  typedef internal::Internals I;
10677  I::CheckInitialized(isolate);
10678  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
10679  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
10680 }
10681 
10682 
10683 void Isolate::SetData(uint32_t slot, void* data) {
10684  typedef internal::Internals I;
10685  I::SetEmbedderData(this, slot, data);
10686 }
10687 
10688 
10689 void* Isolate::GetData(uint32_t slot) {
10690  typedef internal::Internals I;
10691  return I::GetEmbedderData(this, slot);
10692 }
10693 
10694 
10696  typedef internal::Internals I;
10697  return I::kNumIsolateDataSlots;
10698 }
10699 
10700 template <class T>
10702  T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
10703  if (data) internal::PerformCastCheck(data);
10704  return Local<T>(data);
10705 }
10706 
10708  int64_t change_in_bytes) {
10709  typedef internal::Internals I;
10710  const int64_t kMemoryReducerActivationLimit = 32 * 1024 * 1024;
10711  int64_t* external_memory = reinterpret_cast<int64_t*>(
10712  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
10713  int64_t* external_memory_limit = reinterpret_cast<int64_t*>(
10714  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
10715  int64_t* external_memory_at_last_mc =
10716  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
10717  I::kExternalMemoryAtLastMarkCompactOffset);
10718  const int64_t amount = *external_memory + change_in_bytes;
10719 
10720  *external_memory = amount;
10721 
10722  int64_t allocation_diff_since_last_mc =
10723  *external_memory_at_last_mc - *external_memory;
10724  allocation_diff_since_last_mc = allocation_diff_since_last_mc < 0
10725  ? -allocation_diff_since_last_mc
10726  : allocation_diff_since_last_mc;
10727  if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) {
10728  CheckMemoryPressure();
10729  }
10730 
10731  if (change_in_bytes < 0) {
10732  *external_memory_limit += change_in_bytes;
10733  }
10734 
10735  if (change_in_bytes > 0 && amount > *external_memory_limit) {
10736  ReportExternalAllocationLimitReached();
10737  }
10738  return *external_memory;
10739 }
10740 
10742 #ifndef V8_ENABLE_CHECKS
10743  typedef internal::Object O;
10744  typedef internal::HeapObject HO;
10745  typedef internal::Internals I;
10746  HO* context = *reinterpret_cast<HO**>(this);
10747  O** result =
10748  HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
10749  return Local<Value>(reinterpret_cast<Value*>(result));
10750 #else
10751  return SlowGetEmbedderData(index);
10752 #endif
10753 }
10754 
10755 
10757 #ifndef V8_ENABLE_CHECKS
10758  typedef internal::Internals I;
10759  return I::ReadEmbedderData<void*>(this, index);
10760 #else
10761  return SlowGetAlignedPointerFromEmbedderData(index);
10762 #endif
10763 }
10764 
10765 template <class T>
10767  T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
10768  if (data) internal::PerformCastCheck(data);
10769  return Local<T>(data);
10770 }
10771 
10772 template <class T>
10773 size_t SnapshotCreator::AddData(Local<Context> context, Local<T> object) {
10774  T* object_ptr = *object;
10775  internal::Object** p = reinterpret_cast<internal::Object**>(object_ptr);
10776  return AddData(context, *p);
10777 }
10778 
10779 template <class T>
10780 size_t SnapshotCreator::AddData(Local<T> object) {
10781  T* object_ptr = *object;
10782  internal::Object** p = reinterpret_cast<internal::Object**>(object_ptr);
10783  return AddData(*p);
10784 }
10785 
10798 } // namespace v8
10799 
10800 
10801 #undef TYPE_CHECK
10802 
10803 
10804 #endif // INCLUDE_V8_H_
V8_INLINE bool IsNearDeath() const
Definition: v8.h:9673
V8_INLINE uint16_t WrapperClassId() const
Definition: v8.h:9785
Definition: v8.h:3129
Definition: v8.h:4841
Definition: v8.h:1349
void(* NamedPropertyDeleterCallback)(Local< String > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:5459
void(* HostInitializeImportMetaObjectCallback)(Local< Context > context, Local< Module > module, Local< Object > meta)
Definition: v8.h:6593
UseCounterFeature
Definition: v8.h:7391
IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback getter=0, IndexedPropertySetterCallback setter=0, IndexedPropertyQueryCallback query=0, IndexedPropertyDeleterCallback deleter=0, IndexedPropertyEnumeratorCallback enumerator=0, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
Definition: v8.h:6028
IntegrityLevel
Definition: v8.h:3335
Definition: v8.h:3185
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:5668
GCCallbackFlags
Definition: v8.h:6763
KeyConversionMode
Definition: v8.h:3330
Definition: v8.h:4943
static V8_INLINE Local< Context > CreationContext(const PersistentBase< Object > &object)
Definition: v8.h:3698
Definition: v8-profiler.h:962
bool only_terminate_in_safe_scope
Definition: v8.h:7274
Definition: v8.h:1201
V8_INLINE bool IsNullOrUndefined() const
Definition: v8.h:10220
Definition: v8.h:6672
void(* NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:5469
WriteOptions
Definition: v8.h:2737
NewStringType
Definition: v8.h:2658
Isolate * GetIsolate()
static Isolate * GetCurrent()
Definition: v8.h:2007
V8_INLINE MaybeLocal< T > GetDataFromSnapshotOnce(size_t index)
void(* GenericNamedPropertyDefinerCallback)(Local< Name > property, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5617
Definition: v8.h:3248
Definition: v8.h:123
Definition: v8.h:6851
Definition: v8.h:4892
int InternalFieldCount()
V8_INLINE void Clear()
Definition: v8.h:324
V8_INLINE bool IsString() const
Definition: v8.h:10238
Definition: v8.h:1121
virtual ~ExternalStringResource()
Definition: v8.h:2818
Definition: v8.h:9343
GarbageCollectionType
Definition: v8.h:7381
V8_INLINE Local< T > Escape(Local< T > value)
Definition: v8.h:1028
IndexFilter
Definition: v8.h:3324
Definition: v8.h:1166
PropertyAttribute
Definition: v8.h:3240
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
Definition: v8.h:3570
V8_INLINE int Length() const
Definition: v8.h:9976
static V8_INLINE Local< T > Cast(Local< S > that)
Definition: v8.h:375
KeyCollectionMode
Definition: v8.h:3318
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
Definition: v8.h:899
V8_INLINE bool IsWeak() const
Definition: v8.h:9684
Definition: v8.h:4176
Definition: v8.h:5008
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Definition: v8.h:3589
void(* GenericNamedPropertyDeleterCallback)(Local< Name > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:5585
void(* NamedPropertySetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5438
V8_WARN_UNUSED_RESULT Maybe< bool > SetNativeDataProperty(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect)
Definition: v8.h:9401
EmbedderDataFields
Definition: v8.h:9140
Definition: v8.h:3244
virtual ~ExternalOneByteStringResource()
Definition: v8.h:2851
Definition: v8.h:2005
Definition: v8.h:6626
Definition: v8.h:3093
Definition: v8.h:85
void(* IndexedPropertyDescriptorCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5691
size_t does_zap_garbage()
Definition: v8.h:6811
Definition: v8.h:5026
Definition: v8.h:4992
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:3256
Definition: v8.h:2635
Definition: v8.h:181
V8_INLINE bool IsEmpty() const
Definition: v8.h:319
Definition: v8.h:2247
Definition: v8.h:2621
Definition: v8.h:4976
Definition: v8-util.h:162
Definition: v8.h:1826
Definition: v8.h:4633
Definition: v8.h:1383
V8_INLINE Local< Object > Holder() const
Definition: v8.h:9940
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
Definition: v8.h:795
V8_INLINE Local< Value > NewTarget() const
Definition: v8.h:9946
Definition: v8.h:9013
V8_INLINE Isolate * GetIsolate() const
Definition: v8.h:10612
Definition: v8.h:140
V8_INLINE T FromJust() const
Definition: v8.h:8756
V8_INLINE bool ShouldThrowOnError() const
Definition: v8.h:10641
V8_INLINE void SetWeak()
Definition: v8.h:9732
PropertyHandlerFlags
Definition: v8.h:5947
Definition: v8.h:6310
Definition: v8.h:6952
JitCodeEventOptions
Definition: v8.h:6998
V8_INLINE Local< S > As() const
Definition: v8.h:390
static void * JSStackComparableAddress(TryCatch *handler)
Definition: v8.h:8956
Definition: v8.h:2675
Definition: v8-platform.h:247
bool(* EntropySource)(unsigned char *buffer, size_t length)
Definition: v8.h:8367
Definition: v8.h:1426
Definition: v8.h:1952
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, v8::NewStringType type, int length=-1)
Definition: v8.h:6793
Definition: v8.h:4858
Definition: v8.h:114
V8_INLINE void * GetAlignedPointerFromEmbedderData(int index)
Definition: v8.h:10756
Definition: v8.h:2142
void(* IndexedPropertyDefinerCallback)(uint32_t index, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5684
V8_INLINE Global()
Definition: v8.h:882
V8_INLINE Unlocker(Isolate *isolate)
Definition: v8.h:9348
Definition: v8.h:4472
V8_INLINE Persistent(const Persistent &that)
Definition: v8.h:815
Definition: v8.h:2614
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
Definition: v8.h:471
Definition: v8.h:7196
bool(* AccessCheckCallback)(Local< Context > accessing_context, Local< Object > accessed_object, Local< Value > data)
Definition: v8.h:5710
Definition: v8.h:2144
CreateHistogramCallback create_histogram_callback
Definition: v8.h:7248
void(* GenericNamedPropertyQueryCallback)(Local< Name > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:5561
Definition: v8.h:3763
V8_DEPRECATE_SOON("Objects are always considered independent. " "Use MarkActive to avoid collecting otherwise dead weak handles.", V8_INLINE void MarkIndependent())
Definition: v8.h:6905
void(* GenericNamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:5594
Definition: v8.h:1873
StartupData * snapshot_blob
Definition: v8.h:7233
Definition: v8.h:7282
Definition: v8.h:8803
Definition: v8.h:4284
V8_INLINE MaybeLocal< T > GetDataFromSnapshotOnce(size_t index)
Definition: v8-platform.h:16
Definition: v8.h:962
Definition: v8.h:5814
Definition: v8.h:117
V8_INLINE Local< Value > operator[](int i) const
Definition: v8.h:9927
Definition: v8.h:7016
Definition: v8.h:4570
V8_INLINE Global & operator=(Global< S > &&rhs)
Definition: v8.h:914
V8_INLINE bool operator!=(const Local< S > &that) const
Definition: v8.h:361
Definition: v8.h:6944
CounterLookupCallback counter_lookup_callback
Definition: v8.h:7240
AccessType
Definition: v8.h:5697
AtomicsWaitEvent
Definition: v8.h:7779
Definition: v8-util.h:426
void(* GenericNamedPropertyDescriptorCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5640
V8_INLINE bool operator==(const Local< S > &that) const
Definition: v8.h:337
Definition: v8.h:3011
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5646
V8_INLINE Local< Value > GetEmbedderData(int index)
Definition: v8.h:10741
V8_INLINE Local< T > ToLocalChecked()
Definition: v8.h:9626
V8_INLINE Local< Value > Data() const
Definition: v8.h:9952
Definition: v8.h:4074
V8_INLINE ReturnValue< T > GetReturnValue() const
Definition: v8.h:10636
void(* NamedPropertyGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5429
V8_WARN_UNUSED_RESULT V8_INLINE bool To(T *out) const
Definition: v8.h:8747
Definition: v8.h:6868
Definition: v8.h:520
V8_INLINE ExternalStringResourceBase * GetExternalStringResourceBase(Encoding *encoding_out) const
Definition: v8.h:10165
FunctionEntryHook entry_hook
Definition: v8.h:7217
Definition: v8.h:6520
V8_INLINE Persistent()
Definition: v8.h:788
Definition: v8.h:121
V8_INLINE void MarkActive()
Definition: v8.h:9766
V8_INLINE Local< Value > Data() const
Definition: v8.h:10618
Definition: v8.h:4875
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5653
Definition: v8.h:1741
Definition: v8.h:4184
size_t length() const
Definition: v8.h:6354
Definition: v8.h:3242
V8_WARN_UNUSED_RESULT Maybe< bool > SetAccessor(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=0, MaybeLocal< Value > data=MaybeLocal< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect)
Definition: v8.h:5175
Definition: v8.h:6329
Definition: v8.h:4909
Definition: v8.h:3819
Flags
Definition: v8.h:5259
V8_INLINE Local(Local< S > that)
Definition: v8.h:306
bool IsExternal() const
Definition: v8.h:1239
Definition: v8.h:2986
V8_INLINE Locker(Isolate *isolate)
Definition: v8.h:9363
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:5678
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:5661
Definition: v8.h:3246
bool allow_atomics_wait
Definition: v8.h:7269
Definition: v8.h:4333
Definition: v8.h:5039
Definition: v8.h:5337
const intptr_t * external_references
Definition: v8.h:7263
V8_INLINE void SetData(uint32_t slot, void *data)
Definition: v8.h:10683
void Set(Local< Name > name, Local< Data > value, PropertyAttribute attributes=None)
Definition: v8-util.h:569
void(* JitCodeEventHandler)(const JitCodeEvent *event)
Definition: v8.h:7010
Definition: v8.h:4751
Definition: v8.h:1132
size_t(* NearHeapLimitCallback)(void *data, size_t current_heap_limit, size_t initial_heap_limit)
Definition: v8.h:6784
Definition: v8.h:116
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Definition: v8.h:805
V8_INLINE Global(Isolate *isolate, Local< S > that)
Definition: v8.h:889
Definition: v8.h:4356
V8_INLINE Local< Object > Holder() const
Definition: v8.h:10630
static V8_INLINE uint32_t GetNumberOfDataSlots()
Definition: v8.h:10695
V8_INLINE ReturnValue< T > GetReturnValue() const
Definition: v8.h:9964
Definition: v8.h:6364
Definition: v8.h:1960
Definition: v8.h:8620
SideEffectType
Definition: v8.h:3309
V8_INLINE void SetWrapperClassId(uint16_t class_id)
Definition: v8.h:9775
V8_INLINE void * GetAlignedPointerFromInternalField(int index)
Definition: v8.h:10112
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8.h:9589
V8_INLINE T FromMaybe(const T &default_value) const
Definition: v8.h:8765
void(* GenericNamedPropertyGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5512
Definition: v8.h:8834
Definition: v8.h:5307
Definition: v8.h:1059
V8_INLINE ExternalStringResource * GetExternalStringResource() const
Definition: v8.h:10147
StackTraceOptions
Definition: v8.h:1834
JitCodeEventHandler code_event_handler
Definition: v8.h:7223
Definition: v8.h:4800
Definition: v8.h:1018
Definition: v8.h:5138
Definition: v8.h:5253
PromiseHookType
Definition: v8.h:6613
Definition: v8.h:3340
Definition: v8.h:764
Definition: v8.h:9223
V8_INLINE size_t AddData(Local< Context > context, Local< T > object)
static V8_INLINE Local< String > Empty(Isolate *isolate)
Definition: v8.h:10138
V8_INLINE Global(Global &&other)
Definition: v8.h:906
V8_INLINE void * GetData(uint32_t slot)
Definition: v8.h:10689
Definition: v8.h:133
ArrayBuffer::Allocator * array_buffer_allocator
Definition: v8.h:7255
V8_INLINE int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes)
Definition: v8.h:10707
Definition: v8.h:1232
void Enter()
Definition: v8.h:1098
V8_INLINE bool IsNull() const
Definition: v8.h:10203
Definition: v8.h:7026
Definition: v8.h:3040
bool(* AllowCodeGenerationFromStringsCallback)(Local< Context > context, Local< String > source)
Definition: v8.h:6715
V8_INLINE void RegisterExternalReference(Isolate *isolate) const
Definition: v8.h:9750
Definition: v8.h:7054
MemoryPressureLevel
Definition: v8.h:7041
Definition: v8.h:4587
Definition: v8.h:6084
Definition: v8.h:134
GCType
Definition: v8.h:6740
MicrotasksPolicy
Definition: v8.h:6660
const char * data() const
Definition: v8.h:6353
Definition: v8.h:1392
Definition: v8-profiler.h:719
Definition: v8.h:1970
Definition: v8.h:8356
Definition: v8.h:8389
Definition: v8.h:5237
V8_INLINE Local< Object > This() const
Definition: v8.h:10624
Definition: v8.h:130
Definition: v8.h:8995
MaybeLocal< Promise >(* HostImportModuleDynamicallyCallback)(Local< Context > context, Local< ScriptOrModule > referrer, Local< String > specifier)
Definition: v8.h:6579
Definition: v8.h:6831
V8_INLINE void AnnotateStrongRetainer(const char *label)
Definition: v8.h:9744
Definition: v8.h:1087
NoCacheReason
Definition: v8.h:1566
Definition: v8.h:4824
V8_INLINE bool IsUndefined() const
Definition: v8.h:10185
V8_INLINE bool IsConstructCall() const
Definition: v8.h:9970
V8_INLINE T ToChecked() const
Definition: v8.h:8741
V8_INLINE Local< S > FromMaybe(Local< S > default_value) const
Definition: v8.h:487
virtual void Dispose()
Definition: v8.h:2794
void(* GenericNamedPropertySetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5536
V8_INLINE Local< Object > This() const
Definition: v8.h:9934
Definition: v8.h:4926
AllocationMode
Definition: v8.h:4614
Definition: v8.h:6427
Definition: v8.h:5190
Definition: v8.h:5205
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
Definition: v8.h:8382
V8_WARN_UNUSED_RESULT Maybe< bool > SetLazyDataProperty(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect)
Status
Definition: v8.h:1264
Definition: v8.h:3158
PromiseState
Definition: v8.h:4182
V8_INLINE void Reset()
Definition: v8.h:9693
Definition: v8.h:9358
Definition: v8.h:7191
Definition: v8.h:5221
Definition: v8.h:3172
Definition: v8.h:1255
AccessControl
Definition: v8.h:3283
void(* FunctionEntryHook)(uintptr_t function, uintptr_t return_addr_location)
Definition: v8.h:6897
Definition: v8-util.h:354
Global Pass()
Definition: v8.h:926
Definition: v8.h:4960
V8_INLINE Isolate * GetIsolate() const
Definition: v8.h:9958
void(* NamedPropertyQueryCallback)(Local< String > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:5449
PropertyFilter
Definition: v8.h:3293
ResourceConstraints constraints
Definition: v8.h:7228
Definition: v8.h:3783
RAILMode
Definition: v8.h:6978
Definition: v8.h:3143
Definition: v8.h:9565
V8_INLINE Local< Value > GetInternalField(int index)
Definition: v8.h:10090
void SetIndexedPropertyHandler(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter=0, IndexedPropertyQueryCallback query=0, IndexedPropertyDeleterCallback deleter=0, IndexedPropertyEnumeratorCallback enumerator=0, Local< Value > data=Local< Value >())
Definition: v8.h:6204
Definition: v8.h:151
Definition: v8.h:193
Definition: v8.h:119
V8_INLINE ~Persistent()
Definition: v8.h:836
NamedPropertyHandlerConfiguration(GenericNamedPropertyGetterCallback getter=0, GenericNamedPropertySetterCallback setter=0, GenericNamedPropertyQueryCallback query=0, GenericNamedPropertyDeleterCallback deleter=0, GenericNamedPropertyEnumeratorCallback enumerator=0, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
Definition: v8.h:5977