My Project
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 NeverReadOnlySpaceObject;
150 class Object;
151 struct ScriptStreamingData;
152 template<typename T> class CustomArguments;
153 class PropertyCallbackArguments;
154 class FunctionCallbackArguments;
155 class GlobalHandles;
156 
157 namespace wasm {
158 class NativeModule;
159 class StreamingDecoder;
160 } // namespace wasm
161 
165 const int kApiPointerSize = sizeof(void*); // NOLINT
166 const int kApiDoubleSize = sizeof(double); // NOLINT
167 const int kApiIntSize = sizeof(int); // NOLINT
168 const int kApiInt64Size = sizeof(int64_t); // NOLINT
169 
170 // Tag information for HeapObject.
171 const int kHeapObjectTag = 1;
172 const int kWeakHeapObjectTag = 3;
173 const int kHeapObjectTagSize = 2;
174 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
175 
176 // Tag information for Smi.
177 const int kSmiTag = 0;
178 const int kSmiTagSize = 1;
179 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
180 
181 template <size_t tagged_ptr_size>
182 struct SmiTagging;
183 
184 template <int kSmiShiftSize>
185 V8_INLINE internal::Object* IntToSmi(int value) {
186  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
187  intptr_t tagged_value =
188  (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
189  return reinterpret_cast<internal::Object*>(tagged_value);
190 }
191 
192 // Smi constants for systems where tagged pointer is a 32-bit value.
193 template <>
194 struct SmiTagging<4> {
195  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
196  static int SmiShiftSize() { return kSmiShiftSize; }
197  static int SmiValueSize() { return kSmiValueSize; }
198  V8_INLINE static int SmiToInt(const internal::Object* value) {
199  int shift_bits = kSmiTagSize + kSmiShiftSize;
200  // Throw away top 32 bits and shift down (requires >> to be sign extending).
201  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
202  }
203  V8_INLINE static internal::Object* IntToSmi(int value) {
204  return internal::IntToSmi<kSmiShiftSize>(value);
205  }
206  V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
207  // To be representable as an tagged small integer, the two
208  // most-significant bits of 'value' must be either 00 or 11 due to
209  // sign-extension. To check this we add 01 to the two
210  // most-significant bits, and check if the most-significant bit is 0
211  //
212  // CAUTION: The original code below:
213  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
214  // may lead to incorrect results according to the C language spec, and
215  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
216  // compiler may produce undefined results in case of signed integer
217  // overflow. The computation must be done w/ unsigned ints.
218  return static_cast<uintptr_t>(value) + 0x40000000U < 0x80000000U;
219  }
220 };
221 
222 // Smi constants for systems where tagged pointer is a 64-bit value.
223 template <>
224 struct SmiTagging<8> {
225  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
226  static int SmiShiftSize() { return kSmiShiftSize; }
227  static int SmiValueSize() { return kSmiValueSize; }
228  V8_INLINE static int SmiToInt(const internal::Object* value) {
229  int shift_bits = kSmiTagSize + kSmiShiftSize;
230  // Shift down and throw away top 32 bits.
231  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
232  }
233  V8_INLINE static internal::Object* IntToSmi(int value) {
234  return internal::IntToSmi<kSmiShiftSize>(value);
235  }
236  V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
237  // To be representable as a long smi, the value must be a 32-bit integer.
238  return (value == static_cast<int32_t>(value));
239  }
240 };
241 
242 #if V8_COMPRESS_POINTERS
243 static_assert(
244  kApiPointerSize == kApiInt64Size,
245  "Pointer compression can be enabled only for 64-bit architectures");
247 #else
249 #endif
250 
251 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
252 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
253 const int kSmiMinValue = (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
254 const int kSmiMaxValue = -(kSmiMinValue + 1);
255 constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
256 constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
257 
258 } // namespace internal
259 
260 namespace debug {
261 class ConsoleCallArguments;
262 } // namespace debug
263 
264 // --- Handles ---
265 
266 #define TYPE_CHECK(T, S) \
267  while (false) { \
268  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
269  }
270 
302 template <class T>
303 class Local {
304  public:
305  V8_INLINE Local() : val_(0) {}
306  template <class S>
307  V8_INLINE Local(Local<S> that)
308  : val_(reinterpret_cast<T*>(*that)) {
314  TYPE_CHECK(T, S);
315  }
316 
320  V8_INLINE bool IsEmpty() const { return val_ == 0; }
321 
325  V8_INLINE void Clear() { val_ = 0; }
326 
327  V8_INLINE T* operator->() const { return val_; }
328 
329  V8_INLINE T* operator*() const { return val_; }
330 
337  template <class S>
338  V8_INLINE bool operator==(const Local<S>& that) const {
339  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
340  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
341  if (a == 0) return b == 0;
342  if (b == 0) return false;
343  return *a == *b;
344  }
345 
346  template <class S> V8_INLINE bool operator==(
347  const PersistentBase<S>& that) const {
348  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
349  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
350  if (a == 0) return b == 0;
351  if (b == 0) return false;
352  return *a == *b;
353  }
354 
361  template <class S>
362  V8_INLINE bool operator!=(const Local<S>& that) const {
363  return !operator==(that);
364  }
365 
366  template <class S> V8_INLINE bool operator!=(
367  const Persistent<S>& that) const {
368  return !operator==(that);
369  }
370 
376  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
377 #ifdef V8_ENABLE_CHECKS
378  // If we're going to perform the type check then we have to check
379  // that the handle isn't empty before doing the checked cast.
380  if (that.IsEmpty()) return Local<T>();
381 #endif
382  return Local<T>(T::Cast(*that));
383  }
384 
390  template <class S>
391  V8_INLINE Local<S> As() const {
392  return Local<S>::Cast(*this);
393  }
394 
400  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
401  V8_INLINE static Local<T> New(Isolate* isolate,
402  const PersistentBase<T>& that);
403 
404  private:
405  friend class Utils;
406  template<class F> friend class Eternal;
407  template<class F> friend class PersistentBase;
408  template<class F, class M> friend class Persistent;
409  template<class F> friend class Local;
410  template <class F>
411  friend class MaybeLocal;
412  template<class F> friend class FunctionCallbackInfo;
413  template<class F> friend class PropertyCallbackInfo;
414  friend class String;
415  friend class Object;
416  friend class Context;
417  friend class Isolate;
418  friend class Private;
419  template<class F> friend class internal::CustomArguments;
420  friend Local<Primitive> Undefined(Isolate* isolate);
421  friend Local<Primitive> Null(Isolate* isolate);
422  friend Local<Boolean> True(Isolate* isolate);
423  friend Local<Boolean> False(Isolate* isolate);
424  friend class HandleScope;
425  friend class EscapableHandleScope;
426  template <class F1, class F2, class F3>
427  friend class PersistentValueMapBase;
428  template<class F1, class F2> friend class PersistentValueVector;
429  template <class F>
430  friend class ReturnValue;
431 
432  explicit V8_INLINE Local(T* that) : val_(that) {}
433  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
434  T* val_;
435 };
436 
437 
438 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
439 // Handle is an alias for Local for historical reasons.
440 template <class T>
441 using Handle = Local<T>;
442 #endif
443 
444 
455 template <class T>
456 class MaybeLocal {
457  public:
458  V8_INLINE MaybeLocal() : val_(nullptr) {}
459  template <class S>
460  V8_INLINE MaybeLocal(Local<S> that)
461  : val_(reinterpret_cast<T*>(*that)) {
462  TYPE_CHECK(T, S);
463  }
464 
465  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
466 
471  template <class S>
472  V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
473  out->val_ = IsEmpty() ? nullptr : this->val_;
474  return !IsEmpty();
475  }
476 
481  V8_INLINE Local<T> ToLocalChecked();
482 
487  template <class S>
488  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
489  return IsEmpty() ? default_value : Local<S>(val_);
490  }
491 
492  private:
493  T* val_;
494 };
495 
500 template <class T> class Eternal {
501  public:
502  V8_INLINE Eternal() : val_(nullptr) {}
503  template <class S>
504  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
505  Set(isolate, handle);
506  }
507  // Can only be safely called if already set.
508  V8_INLINE Local<T> Get(Isolate* isolate) const;
509  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
510  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
511 
512  private:
513  T* val_;
514 };
515 
516 
517 static const int kInternalFieldsInWeakCallback = 2;
518 static const int kEmbedderFieldsInWeakCallback = 2;
519 
520 template <typename T>
522  public:
523  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
524 
525  WeakCallbackInfo(Isolate* isolate, T* parameter,
526  void* embedder_fields[kEmbedderFieldsInWeakCallback],
527  Callback* callback)
528  : isolate_(isolate), parameter_(parameter), callback_(callback) {
529  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
530  embedder_fields_[i] = embedder_fields[i];
531  }
532  }
533 
534  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
535  V8_INLINE T* GetParameter() const { return parameter_; }
536  V8_INLINE void* GetInternalField(int index) const;
537 
538  // When first called, the embedder MUST Reset() the Global which triggered the
539  // callback. The Global itself is unusable for anything else. No v8 other api
540  // calls may be called in the first callback. Should additional work be
541  // required, the embedder must set a second pass callback, which will be
542  // called after all the initial callbacks are processed.
543  // Calling SetSecondPassCallback on the second pass will immediately crash.
544  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
545 
546  private:
547  Isolate* isolate_;
548  T* parameter_;
549  Callback* callback_;
550  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
551 };
552 
553 
554 // kParameter will pass a void* parameter back to the callback, kInternalFields
555 // will pass the first two internal fields back to the callback, kFinalizer
556 // will pass a void* parameter back, but is invoked before the object is
557 // actually collected, so it can be resurrected. In the last case, it is not
558 // possible to request a second pass callback.
559 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };
560 
574 template <class T> class PersistentBase {
575  public:
580  V8_INLINE void Reset();
585  template <class S>
586  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
587 
592  template <class S>
593  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
594 
595  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
596  V8_INLINE void Empty() { val_ = 0; }
597 
598  V8_INLINE Local<T> Get(Isolate* isolate) const {
599  return Local<T>::New(isolate, *this);
600  }
601 
602  template <class S>
603  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
604  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
605  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
606  if (a == NULL) return b == NULL;
607  if (b == NULL) return false;
608  return *a == *b;
609  }
610 
611  template <class S>
612  V8_INLINE bool operator==(const Local<S>& that) const {
613  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
614  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
615  if (a == NULL) return b == NULL;
616  if (b == NULL) return false;
617  return *a == *b;
618  }
619 
620  template <class S>
621  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
622  return !operator==(that);
623  }
624 
625  template <class S>
626  V8_INLINE bool operator!=(const Local<S>& that) const {
627  return !operator==(that);
628  }
629 
637  template <typename P>
638  V8_INLINE void SetWeak(P* parameter,
639  typename WeakCallbackInfo<P>::Callback callback,
640  WeakCallbackType type);
641 
649  V8_INLINE void SetWeak();
650 
651  template<typename P>
652  V8_INLINE P* ClearWeak();
653 
654  // TODO(dcarney): remove this.
655  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
656 
663  V8_INLINE void AnnotateStrongRetainer(const char* label);
664 
670  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
671 
679  "Objects are always considered independent. "
680  "Use MarkActive to avoid collecting otherwise dead weak handles.",
681  V8_INLINE void MarkIndependent());
682 
690  V8_INLINE void MarkActive();
691 
692  V8_DEPRECATE_SOON("See MarkIndependent.",
693  V8_INLINE bool IsIndependent() const);
694 
696  V8_INLINE bool IsNearDeath() const;
697 
699  V8_INLINE bool IsWeak() const;
700 
705  V8_INLINE void SetWrapperClassId(uint16_t class_id);
706 
711  V8_INLINE uint16_t WrapperClassId() const;
712 
713  PersistentBase(const PersistentBase& other) = delete; // NOLINT
714  void operator=(const PersistentBase&) = delete;
715 
716  private:
717  friend class Isolate;
718  friend class Utils;
719  template<class F> friend class Local;
720  template<class F1, class F2> friend class Persistent;
721  template <class F>
722  friend class Global;
723  template<class F> friend class PersistentBase;
724  template<class F> friend class ReturnValue;
725  template <class F1, class F2, class F3>
726  friend class PersistentValueMapBase;
727  template<class F1, class F2> friend class PersistentValueVector;
728  friend class Object;
729 
730  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
731  V8_INLINE static T* New(Isolate* isolate, T* that);
732 
733  T* val_;
734 };
735 
736 
743 template<class T>
744 class NonCopyablePersistentTraits {
745  public:
746  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
747  static const bool kResetInDestructor = false;
748  template<class S, class M>
749  V8_INLINE static void Copy(const Persistent<S, M>& source,
750  NonCopyablePersistent* dest) {
751  Uncompilable<Object>();
752  }
753  // TODO(dcarney): come up with a good compile error here.
754  template<class O> V8_INLINE static void Uncompilable() {
755  TYPE_CHECK(O, Primitive);
756  }
757 };
758 
759 
764 template<class T>
767  static const bool kResetInDestructor = true;
768  template<class S, class M>
769  static V8_INLINE void Copy(const Persistent<S, M>& source,
770  CopyablePersistent* dest) {
771  // do nothing, just allow copy
772  }
773 };
774 
775 
784 template <class T, class M> class Persistent : public PersistentBase<T> {
785  public:
789  V8_INLINE Persistent() : PersistentBase<T>(0) { }
795  template <class S>
796  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
797  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
798  TYPE_CHECK(T, S);
799  }
805  template <class S, class M2>
806  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
807  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
808  TYPE_CHECK(T, S);
809  }
816  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
817  Copy(that);
818  }
819  template <class S, class M2>
820  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
821  Copy(that);
822  }
823  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
824  Copy(that);
825  return *this;
826  }
827  template <class S, class M2>
828  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
829  Copy(that);
830  return *this;
831  }
837  V8_INLINE ~Persistent() {
838  if (M::kResetInDestructor) this->Reset();
839  }
840 
841  // TODO(dcarney): this is pretty useless, fix or remove
842  template <class S>
843  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
844 #ifdef V8_ENABLE_CHECKS
845  // If we're going to perform the type check then we have to check
846  // that the handle isn't empty before doing the checked cast.
847  if (!that.IsEmpty()) T::Cast(*that);
848 #endif
849  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
850  }
851 
852  // TODO(dcarney): this is pretty useless, fix or remove
853  template <class S>
854  V8_INLINE Persistent<S>& As() const { // NOLINT
855  return Persistent<S>::Cast(*this);
856  }
857 
858  private:
859  friend class Isolate;
860  friend class Utils;
861  template<class F> friend class Local;
862  template<class F1, class F2> friend class Persistent;
863  template<class F> friend class ReturnValue;
864 
865  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
866  V8_INLINE T* operator*() const { return this->val_; }
867  template<class S, class M2>
868  V8_INLINE void Copy(const Persistent<S, M2>& that);
869 };
870 
871 
877 template <class T>
878 class Global : public PersistentBase<T> {
879  public:
883  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
889  template <class S>
890  V8_INLINE Global(Isolate* isolate, Local<S> that)
891  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
892  TYPE_CHECK(T, S);
893  }
899  template <class S>
900  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
901  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
902  TYPE_CHECK(T, S);
903  }
907  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
908  other.val_ = nullptr;
909  }
910  V8_INLINE ~Global() { this->Reset(); }
914  template <class S>
915  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
916  TYPE_CHECK(T, S);
917  if (this != &rhs) {
918  this->Reset();
919  this->val_ = rhs.val_;
920  rhs.val_ = nullptr;
921  }
922  return *this;
923  }
927  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
928 
929  /*
930  * For compatibility with Chromium's base::Bind (base::Passed).
931  */
932  typedef void MoveOnlyTypeForCPP03;
933 
934  Global(const Global&) = delete;
935  void operator=(const Global&) = delete;
936 
937  private:
938  template <class F>
939  friend class ReturnValue;
940  V8_INLINE T* operator*() const { return this->val_; }
941 };
942 
943 
944 // UniquePersistent is an alias for Global for historical reason.
945 template <class T>
946 using UniquePersistent = Global<T>;
947 
948 
963 class V8_EXPORT HandleScope {
964  public:
965  explicit HandleScope(Isolate* isolate);
966 
967  ~HandleScope();
968 
972  static int NumberOfHandles(Isolate* isolate);
973 
974  V8_INLINE Isolate* GetIsolate() const {
975  return reinterpret_cast<Isolate*>(isolate_);
976  }
977 
978  HandleScope(const HandleScope&) = delete;
979  void operator=(const HandleScope&) = delete;
980 
981  protected:
982  V8_INLINE HandleScope() {}
983 
984  void Initialize(Isolate* isolate);
985 
986  static internal::Object** CreateHandle(internal::Isolate* isolate,
987  internal::Object* value);
988 
989  private:
990  // Declaring operator new and delete as deleted is not spec compliant.
991  // Therefore declare them private instead to disable dynamic alloc
992  void* operator new(size_t size);
993  void* operator new[](size_t size);
994  void operator delete(void*, size_t);
995  void operator delete[](void*, size_t);
996 
997  // Uses heap_object to obtain the current Isolate.
998  static internal::Object** CreateHandle(
999  internal::NeverReadOnlySpaceObject* heap_object, internal::Object* value);
1000 
1001  internal::Isolate* isolate_;
1002  internal::Object** prev_next_;
1003  internal::Object** prev_limit_;
1004 
1005  // Local::New uses CreateHandle with an Isolate* parameter.
1006  template<class F> friend class Local;
1007 
1008  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
1009  // a HeapObject* in their shortcuts.
1010  friend class Object;
1011  friend class Context;
1012 };
1013 
1014 
1019 class V8_EXPORT EscapableHandleScope : public HandleScope {
1020  public:
1021  explicit EscapableHandleScope(Isolate* isolate);
1022  V8_INLINE ~EscapableHandleScope() {}
1023 
1028  template <class T>
1029  V8_INLINE Local<T> Escape(Local<T> value) {
1030  internal::Object** slot =
1031  Escape(reinterpret_cast<internal::Object**>(*value));
1032  return Local<T>(reinterpret_cast<T*>(slot));
1033  }
1034 
1035  template <class T>
1036  V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) {
1037  return Escape(value.FromMaybe(Local<T>()));
1038  }
1039 
1040  EscapableHandleScope(const EscapableHandleScope&) = delete;
1041  void operator=(const EscapableHandleScope&) = delete;
1042 
1043  private:
1044  // Declaring operator new and delete as deleted is not spec compliant.
1045  // Therefore declare them private instead to disable dynamic alloc
1046  void* operator new(size_t size);
1047  void* operator new[](size_t size);
1048  void operator delete(void*, size_t);
1049  void operator delete[](void*, size_t);
1050 
1051  internal::Object** Escape(internal::Object** escape_value);
1052  internal::Object** escape_slot_;
1053 };
1054 
1060 class V8_EXPORT SealHandleScope {
1061  public:
1062  explicit SealHandleScope(Isolate* isolate);
1063  ~SealHandleScope();
1064 
1065  SealHandleScope(const SealHandleScope&) = delete;
1066  void operator=(const SealHandleScope&) = delete;
1067 
1068  private:
1069  // Declaring operator new and delete as deleted is not spec compliant.
1070  // Therefore declare them private instead to disable dynamic alloc
1071  void* operator new(size_t size);
1072  void* operator new[](size_t size);
1073  void operator delete(void*, size_t);
1074  void operator delete[](void*, size_t);
1075 
1076  internal::Isolate* const isolate_;
1077  internal::Object** prev_limit_;
1078  int prev_sealed_level_;
1079 };
1080 
1081 
1082 // --- Special objects ---
1083 
1084 
1088 class V8_EXPORT Data {
1089  private:
1090  Data();
1091 };
1092 
1099 class V8_EXPORT ScriptOrModule {
1100  public:
1105  Local<Value> GetResourceName();
1106 
1111  Local<PrimitiveArray> GetHostDefinedOptions();
1112 };
1113 
1122 class V8_EXPORT PrimitiveArray {
1123  public:
1124  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1125  int Length() const;
1126  void Set(Isolate* isolate, int index, Local<Primitive> item);
1127  Local<Primitive> Get(Isolate* isolate, int index);
1128 
1129  V8_DEPRECATED("Use Isolate version",
1130  void Set(int index, Local<Primitive> item));
1131  V8_DEPRECATED("Use Isolate version", Local<Primitive> Get(int index));
1132 };
1133 
1138  public:
1139  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1140  bool is_opaque = false, bool is_wasm = false,
1141  bool is_module = false)
1142  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1143  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1144  (is_module ? kIsModule : 0)) {}
1145  V8_INLINE ScriptOriginOptions(int flags)
1146  : flags_(flags &
1147  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1148 
1149  bool IsSharedCrossOrigin() const {
1150  return (flags_ & kIsSharedCrossOrigin) != 0;
1151  }
1152  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1153  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1154  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1155 
1156  int Flags() const { return flags_; }
1157 
1158  private:
1159  enum {
1160  kIsSharedCrossOrigin = 1,
1161  kIsOpaque = 1 << 1,
1162  kIsWasm = 1 << 2,
1163  kIsModule = 1 << 3
1164  };
1165  const int flags_;
1166 };
1167 
1172  public:
1173  V8_INLINE ScriptOrigin(
1174  Local<Value> resource_name,
1175  Local<Integer> resource_line_offset = Local<Integer>(),
1176  Local<Integer> resource_column_offset = Local<Integer>(),
1177  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1178  Local<Integer> script_id = Local<Integer>(),
1179  Local<Value> source_map_url = Local<Value>(),
1180  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1181  Local<Boolean> is_wasm = Local<Boolean>(),
1182  Local<Boolean> is_module = Local<Boolean>(),
1183  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1184 
1185  V8_INLINE Local<Value> ResourceName() const;
1186  V8_INLINE Local<Integer> ResourceLineOffset() const;
1187  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1188  V8_INLINE Local<Integer> ScriptID() const;
1189  V8_INLINE Local<Value> SourceMapUrl() const;
1190  V8_INLINE Local<PrimitiveArray> HostDefinedOptions() const;
1191  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1192 
1193  private:
1194  Local<Value> resource_name_;
1195  Local<Integer> resource_line_offset_;
1196  Local<Integer> resource_column_offset_;
1197  ScriptOriginOptions options_;
1198  Local<Integer> script_id_;
1199  Local<Value> source_map_url_;
1200  Local<PrimitiveArray> host_defined_options_;
1201 };
1202 
1206 class V8_EXPORT UnboundScript {
1207  public:
1211  Local<Script> BindToCurrentContext();
1212 
1213  int GetId();
1214  Local<Value> GetScriptName();
1215 
1219  Local<Value> GetSourceURL();
1223  Local<Value> GetSourceMappingURL();
1224 
1229  int GetLineNumber(int code_pos);
1230 
1231  static const int kNoScriptId = 0;
1232 };
1233 
1237 class V8_EXPORT UnboundModuleScript {
1238  // Only used as a container for code caching.
1239 };
1240 
1244 class V8_EXPORT Location {
1245  public:
1246  int GetLineNumber() { return line_number_; }
1247  int GetColumnNumber() { return column_number_; }
1248 
1249  Location(int line_number, int column_number)
1250  : line_number_(line_number), column_number_(column_number) {}
1251 
1252  private:
1253  int line_number_;
1254  int column_number_;
1255 };
1256 
1260 class V8_EXPORT Module {
1261  public:
1269  enum Status {
1270  kUninstantiated,
1271  kInstantiating,
1272  kInstantiated,
1273  kEvaluating,
1274  kEvaluated,
1275  kErrored
1276  };
1277 
1281  Status GetStatus() const;
1282 
1286  Local<Value> GetException() const;
1287 
1291  int GetModuleRequestsLength() const;
1292 
1297  Local<String> GetModuleRequest(int i) const;
1298 
1303  Location GetModuleRequestLocation(int i) const;
1304 
1308  int GetIdentityHash() const;
1309 
1310  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1311  Local<String> specifier,
1312  Local<Module> referrer);
1313 
1321  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1322  ResolveCallback callback);
1323 
1332  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
1333 
1339  Local<Value> GetModuleNamespace();
1340 
1347  Local<UnboundModuleScript> GetUnboundModuleScript();
1348 };
1349 
1354 class V8_EXPORT Script {
1355  public:
1359  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1360  Local<Context> context, Local<String> source,
1361  ScriptOrigin* origin = nullptr);
1362 
1368  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1369 
1373  Local<UnboundScript> GetUnboundScript();
1374 };
1375 
1376 
1380 class V8_EXPORT ScriptCompiler {
1381  public:
1389  struct V8_EXPORT CachedData {
1390  enum BufferPolicy {
1391  BufferNotOwned,
1392  BufferOwned
1393  };
1394 
1395  CachedData()
1396  : data(NULL),
1397  length(0),
1398  rejected(false),
1399  buffer_policy(BufferNotOwned) {}
1400 
1401  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1402  // data and guarantees that it stays alive until the CachedData object is
1403  // destroyed. If the policy is BufferOwned, the given data will be deleted
1404  // (with delete[]) when the CachedData object is destroyed.
1405  CachedData(const uint8_t* data, int length,
1406  BufferPolicy buffer_policy = BufferNotOwned);
1407  ~CachedData();
1408  // TODO(marja): Async compilation; add constructors which take a callback
1409  // which will be called when V8 no longer needs the data.
1410  const uint8_t* data;
1411  int length;
1412  bool rejected;
1413  BufferPolicy buffer_policy;
1414 
1415  // Prevent copying.
1416  CachedData(const CachedData&) = delete;
1417  CachedData& operator=(const CachedData&) = delete;
1418  };
1419 
1423  class Source {
1424  public:
1425  // Source takes ownership of CachedData.
1426  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1427  CachedData* cached_data = NULL);
1428  V8_INLINE Source(Local<String> source_string,
1429  CachedData* cached_data = NULL);
1430  V8_INLINE ~Source();
1431 
1432  // Ownership of the CachedData or its buffers is *not* transferred to the
1433  // caller. The CachedData object is alive as long as the Source object is
1434  // alive.
1435  V8_INLINE const CachedData* GetCachedData() const;
1436 
1437  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1438 
1439  // Prevent copying.
1440  Source(const Source&) = delete;
1441  Source& operator=(const Source&) = delete;
1442 
1443  private:
1444  friend class ScriptCompiler;
1445 
1446  Local<String> source_string;
1447 
1448  // Origin information
1449  Local<Value> resource_name;
1450  Local<Integer> resource_line_offset;
1451  Local<Integer> resource_column_offset;
1452  ScriptOriginOptions resource_options;
1453  Local<Value> source_map_url;
1454  Local<PrimitiveArray> host_defined_options;
1455 
1456  // Cached data from previous compilation (if a kConsume*Cache flag is
1457  // set), or hold newly generated cache data (kProduce*Cache flags) are
1458  // set when calling a compile method.
1459  CachedData* cached_data;
1460  };
1461 
1466  class V8_EXPORT ExternalSourceStream {
1467  public:
1468  virtual ~ExternalSourceStream() {}
1469 
1491  virtual size_t GetMoreData(const uint8_t** src) = 0;
1492 
1503  virtual bool SetBookmark();
1504 
1508  virtual void ResetToBookmark();
1509  };
1510 
1511 
1518  class V8_EXPORT StreamedSource {
1519  public:
1520  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1521 
1522  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1523  ~StreamedSource();
1524 
1525  // Ownership of the CachedData or its buffers is *not* transferred to the
1526  // caller. The CachedData object is alive as long as the StreamedSource
1527  // object is alive.
1528  const CachedData* GetCachedData() const;
1529 
1530  internal::ScriptStreamingData* impl() const { return impl_; }
1531 
1532  // Prevent copying.
1533  StreamedSource(const StreamedSource&) = delete;
1534  StreamedSource& operator=(const StreamedSource&) = delete;
1535 
1536  private:
1537  internal::ScriptStreamingData* impl_;
1538  };
1539 
1545  public:
1546  virtual ~ScriptStreamingTask() {}
1547  virtual void Run() = 0;
1548  };
1549 
1550  enum CompileOptions {
1551  kNoCompileOptions = 0,
1552  kProduceParserCache,
1553  kConsumeParserCache,
1554  kProduceCodeCache,
1555  kProduceFullCodeCache,
1556  kConsumeCodeCache,
1557  kEagerCompile
1558  };
1559 
1564  kNoCacheNoReason = 0,
1565  kNoCacheBecauseCachingDisabled,
1566  kNoCacheBecauseNoResource,
1567  kNoCacheBecauseInlineScript,
1568  kNoCacheBecauseModule,
1569  kNoCacheBecauseStreamingSource,
1570  kNoCacheBecauseInspector,
1571  kNoCacheBecauseScriptTooSmall,
1572  kNoCacheBecauseCacheTooCold,
1573  kNoCacheBecauseV8Extension,
1574  kNoCacheBecauseExtensionModule,
1575  kNoCacheBecausePacScript,
1576  kNoCacheBecauseInDocumentWrite,
1577  kNoCacheBecauseResourceWithNoCacheHandler,
1578  kNoCacheBecauseDeferredProduceCodeCache
1579  };
1580 
1594  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1595  Isolate* isolate, Source* source,
1596  CompileOptions options = kNoCompileOptions,
1597  NoCacheReason no_cache_reason = kNoCacheNoReason);
1598 
1610  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1611  Local<Context> context, Source* source,
1612  CompileOptions options = kNoCompileOptions,
1613  NoCacheReason no_cache_reason = kNoCacheNoReason);
1614 
1626  static ScriptStreamingTask* StartStreamingScript(
1627  Isolate* isolate, StreamedSource* source,
1628  CompileOptions options = kNoCompileOptions);
1629 
1637  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1638  Local<Context> context, StreamedSource* source,
1639  Local<String> full_source_string, const ScriptOrigin& origin);
1640 
1659  static uint32_t CachedDataVersionTag();
1660 
1668  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1669  Isolate* isolate, Source* source,
1670  CompileOptions options = kNoCompileOptions,
1671  NoCacheReason no_cache_reason = kNoCacheNoReason);
1672 
1683  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1684  Local<Context> context, Source* source, size_t arguments_count,
1685  Local<String> arguments[], size_t context_extension_count,
1686  Local<Object> context_extensions[],
1687  CompileOptions options = kNoCompileOptions,
1688  NoCacheReason no_cache_reason = kNoCacheNoReason);
1689 
1695  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
1696 
1702  static CachedData* CreateCodeCache(
1703  Local<UnboundModuleScript> unbound_module_script);
1704 
1711  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
1712 
1713  private:
1714  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1715  Isolate* isolate, Source* source, CompileOptions options,
1716  NoCacheReason no_cache_reason);
1717 };
1718 
1719 
1723 class V8_EXPORT Message {
1724  public:
1725  Local<String> Get() const;
1726 
1730  Isolate* GetIsolate() const;
1731 
1732  V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
1733  Local<Context> context) const;
1734 
1739  ScriptOrigin GetScriptOrigin() const;
1740 
1745  Local<Value> GetScriptResourceName() const;
1746 
1752  Local<StackTrace> GetStackTrace() const;
1753 
1757  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1758 
1763  int GetStartPosition() const;
1764 
1769  int GetEndPosition() const;
1770 
1774  int ErrorLevel() const;
1775 
1780  int GetStartColumn() const;
1781  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1782 
1787  int GetEndColumn() const;
1788  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1789 
1794  bool IsSharedCrossOrigin() const;
1795  bool IsOpaque() const;
1796 
1797  // TODO(1245381): Print to a string instead of on a FILE.
1798  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1799 
1800  static const int kNoLineNumberInfo = 0;
1801  static const int kNoColumnInfo = 0;
1802  static const int kNoScriptIdInfo = 0;
1803 };
1804 
1805 
1811 class V8_EXPORT StackTrace {
1812  public:
1820  kLineNumber = 1,
1821  kColumnOffset = 1 << 1 | kLineNumber,
1822  kScriptName = 1 << 2,
1823  kFunctionName = 1 << 3,
1824  kIsEval = 1 << 4,
1825  kIsConstructor = 1 << 5,
1826  kScriptNameOrSourceURL = 1 << 6,
1827  kScriptId = 1 << 7,
1828  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1829  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1830  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1831  };
1832 
1836  V8_DEPRECATED("Use Isolate version",
1837  Local<StackFrame> GetFrame(uint32_t index) const);
1838  Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
1839 
1843  int GetFrameCount() const;
1844 
1852  static Local<StackTrace> CurrentStackTrace(
1853  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1854 };
1855 
1856 
1860 class V8_EXPORT StackFrame {
1861  public:
1868  int GetLineNumber() const;
1869 
1877  int GetColumn() const;
1878 
1885  int GetScriptId() const;
1886 
1891  Local<String> GetScriptName() const;
1892 
1899  Local<String> GetScriptNameOrSourceURL() const;
1900 
1904  Local<String> GetFunctionName() const;
1905 
1910  bool IsEval() const;
1911 
1916  bool IsConstructor() const;
1917 
1921  bool IsWasm() const;
1922 };
1923 
1924 
1925 // A StateTag represents a possible state of the VM.
1926 enum StateTag {
1927  JS,
1928  GC,
1929  PARSER,
1930  BYTECODE_COMPILER,
1931  COMPILER,
1932  OTHER,
1933  EXTERNAL,
1934  IDLE
1935 };
1936 
1937 // A RegisterState represents the current state of registers used
1938 // by the sampling profiler API.
1940  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1941  void* pc; // Instruction pointer.
1942  void* sp; // Stack pointer.
1943  void* fp; // Frame pointer.
1944 };
1945 
1946 // The output structure filled up by GetStackSample API function.
1947 struct SampleInfo {
1948  size_t frames_count; // Number of frames collected.
1949  StateTag vm_state; // Current VM state.
1950  void* external_callback_entry; // External callback address if VM is
1951  // executing an external callback.
1952 };
1953 
1957 class V8_EXPORT JSON {
1958  public:
1966  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1967  MaybeLocal<Value> Parse(Isolate* isolate,
1968  Local<String> json_string));
1969  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1970  Local<Context> context, Local<String> json_string);
1971 
1979  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1980  Local<Context> context, Local<Value> json_object,
1981  Local<String> gap = Local<String>());
1982 };
1983 
1992 class V8_EXPORT ValueSerializer {
1993  public:
1994  class V8_EXPORT Delegate {
1995  public:
1996  virtual ~Delegate() {}
1997 
2003  virtual void ThrowDataCloneError(Local<String> message) = 0;
2004 
2010  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
2011 
2022  virtual Maybe<uint32_t> GetSharedArrayBufferId(
2023  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
2024 
2025  virtual Maybe<uint32_t> GetWasmModuleTransferId(
2026  Isolate* isolate, Local<WasmCompiledModule> module);
2038  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
2039  size_t* actual_size);
2040 
2046  virtual void FreeBufferMemory(void* buffer);
2047  };
2048 
2049  explicit ValueSerializer(Isolate* isolate);
2050  ValueSerializer(Isolate* isolate, Delegate* delegate);
2051  ~ValueSerializer();
2052 
2056  void WriteHeader();
2057 
2061  V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
2062  Local<Value> value);
2063 
2068  V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
2069 
2076  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
2077 
2083  void TransferArrayBuffer(uint32_t transfer_id,
2084  Local<ArrayBuffer> array_buffer);
2085 
2089  V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
2090  void TransferSharedArrayBuffer(
2091  uint32_t transfer_id,
2092  Local<SharedArrayBuffer> shared_array_buffer));
2093 
2101  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
2102 
2108  void WriteUint32(uint32_t value);
2109  void WriteUint64(uint64_t value);
2110  void WriteDouble(double value);
2111  void WriteRawBytes(const void* source, size_t length);
2112 
2113  private:
2114  ValueSerializer(const ValueSerializer&) = delete;
2115  void operator=(const ValueSerializer&) = delete;
2116 
2117  struct PrivateData;
2118  PrivateData* private_;
2119 };
2120 
2129 class V8_EXPORT ValueDeserializer {
2130  public:
2131  class V8_EXPORT Delegate {
2132  public:
2133  virtual ~Delegate() {}
2134 
2140  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
2141 
2146  virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
2147  Isolate* isolate, uint32_t transfer_id);
2148 
2153  virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
2154  Isolate* isolate, uint32_t clone_id);
2155  };
2156 
2157  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2158  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2159  Delegate* delegate);
2160  ~ValueDeserializer();
2161 
2166  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2167 
2171  V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
2172 
2177  void TransferArrayBuffer(uint32_t transfer_id,
2178  Local<ArrayBuffer> array_buffer);
2179 
2185  void TransferSharedArrayBuffer(uint32_t id,
2186  Local<SharedArrayBuffer> shared_array_buffer);
2187 
2195  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2196 
2200  void SetExpectInlineWasm(bool allow_inline_wasm);
2201 
2207  uint32_t GetWireFormatVersion() const;
2208 
2214  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2215  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2216  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2217  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2218 
2219  private:
2220  ValueDeserializer(const ValueDeserializer&) = delete;
2221  void operator=(const ValueDeserializer&) = delete;
2222 
2223  struct PrivateData;
2224  PrivateData* private_;
2225 };
2226 
2227 
2228 // --- Value ---
2229 
2230 
2234 class V8_EXPORT Value : public Data {
2235  public:
2240  V8_INLINE bool IsUndefined() const;
2241 
2246  V8_INLINE bool IsNull() const;
2247 
2253  V8_INLINE bool IsNullOrUndefined() const;
2254 
2258  bool IsTrue() const;
2259 
2263  bool IsFalse() const;
2264 
2268  bool IsName() const;
2269 
2274  V8_INLINE bool IsString() const;
2275 
2279  bool IsSymbol() const;
2280 
2284  bool IsFunction() const;
2285 
2290  bool IsArray() const;
2291 
2295  bool IsObject() const;
2296 
2300  bool IsBigInt() const;
2301 
2305  bool IsBoolean() const;
2306 
2310  bool IsNumber() const;
2311 
2315  bool IsExternal() const;
2316 
2320  bool IsInt32() const;
2321 
2325  bool IsUint32() const;
2326 
2330  bool IsDate() const;
2331 
2335  bool IsArgumentsObject() const;
2336 
2340  bool IsBigIntObject() const;
2341 
2345  bool IsBooleanObject() const;
2346 
2350  bool IsNumberObject() const;
2351 
2355  bool IsStringObject() const;
2356 
2360  bool IsSymbolObject() const;
2361 
2365  bool IsNativeError() const;
2366 
2370  bool IsRegExp() const;
2371 
2375  bool IsAsyncFunction() const;
2376 
2380  bool IsGeneratorFunction() const;
2381 
2385  bool IsGeneratorObject() const;
2386 
2390  bool IsPromise() const;
2391 
2395  bool IsMap() const;
2396 
2400  bool IsSet() const;
2401 
2405  bool IsMapIterator() const;
2406 
2410  bool IsSetIterator() const;
2411 
2415  bool IsWeakMap() const;
2416 
2420  bool IsWeakSet() const;
2421 
2425  bool IsArrayBuffer() const;
2426 
2430  bool IsArrayBufferView() const;
2431 
2435  bool IsTypedArray() const;
2436 
2440  bool IsUint8Array() const;
2441 
2445  bool IsUint8ClampedArray() const;
2446 
2450  bool IsInt8Array() const;
2451 
2455  bool IsUint16Array() const;
2456 
2460  bool IsInt16Array() const;
2461 
2465  bool IsUint32Array() const;
2466 
2470  bool IsInt32Array() const;
2471 
2475  bool IsFloat32Array() const;
2476 
2480  bool IsFloat64Array() const;
2481 
2485  bool IsBigInt64Array() const;
2486 
2490  bool IsBigUint64Array() const;
2491 
2495  bool IsDataView() const;
2496 
2501  bool IsSharedArrayBuffer() const;
2502 
2506  bool IsProxy() const;
2507 
2508  bool IsWebAssemblyCompiledModule() const;
2509 
2513  bool IsModuleNamespaceObject() const;
2514 
2515  V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
2516  Local<Context> context) const;
2517  V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
2518  Local<Context> context) const;
2519  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
2520  Local<Context> context) const;
2521  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
2522  Local<Context> context) const;
2523  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
2524  Local<Context> context) const;
2525  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
2526  Local<Context> context) const;
2527  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
2528  Local<Context> context) const;
2529  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
2530  Local<Context> context) const;
2531  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
2532 
2533  V8_DEPRECATE_SOON("Use maybe version",
2534  Local<Boolean> ToBoolean(Isolate* isolate) const);
2535  V8_DEPRECATE_SOON("Use maybe version",
2536  Local<Number> ToNumber(Isolate* isolate) const);
2537  V8_DEPRECATE_SOON("Use maybe version",
2538  Local<String> ToString(Isolate* isolate) const);
2539  V8_DEPRECATE_SOON("Use maybe version",
2540  Local<Object> ToObject(Isolate* isolate) const);
2541  V8_DEPRECATE_SOON("Use maybe version",
2542  Local<Integer> ToInteger(Isolate* isolate) const);
2543  V8_DEPRECATE_SOON("Use maybe version",
2544  Local<Int32> ToInt32(Isolate* isolate) const);
2545 
2546  inline V8_DEPRECATED("Use maybe version", Local<Boolean> ToBoolean() const);
2547  inline V8_DEPRECATED("Use maybe version", Local<String> ToString() const);
2548  inline V8_DEPRECATED("Use maybe version", Local<Object> ToObject() const);
2549  inline V8_DEPRECATED("Use maybe version", Local<Integer> ToInteger() const);
2550 
2555  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
2556  Local<Context> context) const;
2557 
2558  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2559  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2560  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2561  Local<Context> context) const;
2562  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2563  Local<Context> context) const;
2564  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2565 
2566  V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
2567  V8_DEPRECATED("Use maybe version", double NumberValue() const);
2568  V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
2569  V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
2570  V8_DEPRECATED("Use maybe version", int32_t Int32Value() const);
2571 
2573  V8_DEPRECATED("Use maybe version", bool Equals(Local<Value> that) const);
2574  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2575  Local<Value> that) const;
2576  bool StrictEquals(Local<Value> that) const;
2577  bool SameValue(Local<Value> that) const;
2578 
2579  template <class T> V8_INLINE static Value* Cast(T* value);
2580 
2581  Local<String> TypeOf(Isolate*);
2582 
2583  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2584 
2585  private:
2586  V8_INLINE bool QuickIsUndefined() const;
2587  V8_INLINE bool QuickIsNull() const;
2588  V8_INLINE bool QuickIsNullOrUndefined() const;
2589  V8_INLINE bool QuickIsString() const;
2590  bool FullIsUndefined() const;
2591  bool FullIsNull() const;
2592  bool FullIsString() const;
2593 };
2594 
2595 
2599 class V8_EXPORT Primitive : public Value { };
2600 
2601 
2606 class V8_EXPORT Boolean : public Primitive {
2607  public:
2608  bool Value() const;
2609  V8_INLINE static Boolean* Cast(v8::Value* obj);
2610  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2611 
2612  private:
2613  static void CheckCast(v8::Value* obj);
2614 };
2615 
2616 
2620 class V8_EXPORT Name : public Primitive {
2621  public:
2629  int GetIdentityHash();
2630 
2631  V8_INLINE static Name* Cast(Value* obj);
2632 
2633  private:
2634  static void CheckCast(Value* obj);
2635 };
2636 
2643 enum class NewStringType {
2647  kNormal,
2648 
2655 };
2656 
2660 class V8_EXPORT String : public Name {
2661  public:
2662  static constexpr int kMaxLength = internal::kApiPointerSize == 4
2663  ? (1 << 28) - 16
2664  : internal::kSmiMaxValue / 2 - 24;
2665 
2666  enum Encoding {
2667  UNKNOWN_ENCODING = 0x1,
2668  TWO_BYTE_ENCODING = 0x0,
2669  ONE_BYTE_ENCODING = 0x8
2670  };
2674  int Length() const;
2675 
2680  V8_DEPRECATED("Use Isolate version instead", int Utf8Length() const);
2681 
2682  int Utf8Length(Isolate* isolate) const;
2683 
2690  bool IsOneByte() const;
2691 
2697  bool ContainsOnlyOneByte() const;
2698 
2725  NO_OPTIONS = 0,
2726  HINT_MANY_WRITES_EXPECTED = 1,
2727  NO_NULL_TERMINATION = 2,
2728  PRESERVE_ONE_BYTE_NULL = 4,
2729  // Used by WriteUtf8 to replace orphan surrogate code units with the
2730  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2731  // output.
2732  REPLACE_INVALID_UTF8 = 8
2733  };
2734 
2735  // 16-bit character codes.
2736  int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
2737  int options = NO_OPTIONS) const;
2738  V8_DEPRECATED("Use Isolate* version",
2739  int Write(uint16_t* buffer, int start = 0, int length = -1,
2740  int options = NO_OPTIONS) const);
2741  // One byte characters.
2742  int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
2743  int length = -1, int options = NO_OPTIONS) const;
2744  V8_DEPRECATED("Use Isolate* version",
2745  int WriteOneByte(uint8_t* buffer, int start = 0,
2746  int length = -1, int options = NO_OPTIONS)
2747  const);
2748  // UTF-8 encoded characters.
2749  int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
2750  int* nchars_ref = NULL, int options = NO_OPTIONS) const;
2751  V8_DEPRECATED("Use Isolate* version",
2752  int WriteUtf8(char* buffer, int length = -1,
2753  int* nchars_ref = NULL, int options = NO_OPTIONS)
2754  const);
2755 
2759  V8_INLINE static Local<String> Empty(Isolate* isolate);
2760 
2764  bool IsExternal() const;
2765 
2769  bool IsExternalOneByte() const;
2770 
2771  class V8_EXPORT ExternalStringResourceBase { // NOLINT
2772  public:
2773  virtual ~ExternalStringResourceBase() {}
2774 
2775  virtual bool IsCompressible() const { return false; }
2776 
2777  protected:
2779 
2786  virtual void Dispose() { delete this; }
2787 
2788  // Disallow copying and assigning.
2790  void operator=(const ExternalStringResourceBase&) = delete;
2791 
2792  private:
2793  friend class internal::Heap;
2794  friend class v8::String;
2795  };
2796 
2803  class V8_EXPORT ExternalStringResource
2804  : public ExternalStringResourceBase {
2805  public:
2811 
2815  virtual const uint16_t* data() const = 0;
2816 
2820  virtual size_t length() const = 0;
2821 
2822  protected:
2824  };
2825 
2837  : public ExternalStringResourceBase {
2838  public:
2845  virtual const char* data() const = 0;
2847  virtual size_t length() const = 0;
2848  protected:
2850  };
2851 
2857  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2858  Encoding* encoding_out) const;
2859 
2864  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2865 
2870  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2871 
2872  V8_INLINE static String* Cast(v8::Value* obj);
2873 
2874  // TODO(dcarney): remove with deprecation of New functions.
2875  enum NewStringType {
2876  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2877  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2878  };
2879 
2881  static V8_DEPRECATE_SOON(
2882  "Use maybe version",
2883  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2884  NewStringType type = kNormalString,
2885  int length = -1));
2886 
2889  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2890  Isolate* isolate, const char* data, v8::NewStringType type,
2891  int length = -1);
2892 
2895  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2896  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2897  int length = -1);
2898 
2900  static V8_DEPRECATE_SOON(
2901  "Use maybe version",
2902  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2903  NewStringType type = kNormalString,
2904  int length = -1));
2905 
2908  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2909  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2910  int length = -1);
2911 
2916  static Local<String> Concat(Isolate* isolate, Local<String> left,
2917  Local<String> right);
2918  static V8_DEPRECATED("Use Isolate* version",
2919  Local<String> Concat(Local<String> left,
2920  Local<String> right));
2921 
2930  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2931  Isolate* isolate, ExternalStringResource* resource);
2932 
2942  bool MakeExternal(ExternalStringResource* resource);
2943 
2952  static V8_DEPRECATE_SOON(
2953  "Use maybe version",
2954  Local<String> NewExternal(Isolate* isolate,
2955  ExternalOneByteStringResource* resource));
2956  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2957  Isolate* isolate, ExternalOneByteStringResource* resource);
2958 
2968  bool MakeExternal(ExternalOneByteStringResource* resource);
2969 
2973  bool CanMakeExternal();
2974 
2978  bool StringEquals(Local<String> str);
2979 
2987  class V8_EXPORT Utf8Value {
2988  public:
2989  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2990  ~Utf8Value();
2991  char* operator*() { return str_; }
2992  const char* operator*() const { return str_; }
2993  int length() const { return length_; }
2994 
2995  // Disallow copying and assigning.
2996  Utf8Value(const Utf8Value&) = delete;
2997  void operator=(const Utf8Value&) = delete;
2998 
2999  private:
3000  char* str_;
3001  int length_;
3002  };
3003 
3010  class V8_EXPORT Value {
3011  public:
3012  Value(Isolate* isolate, Local<v8::Value> obj);
3013  ~Value();
3014  uint16_t* operator*() { return str_; }
3015  const uint16_t* operator*() const { return str_; }
3016  int length() const { return length_; }
3017 
3018  // Disallow copying and assigning.
3019  Value(const Value&) = delete;
3020  void operator=(const Value&) = delete;
3021 
3022  private:
3023  uint16_t* str_;
3024  int length_;
3025  };
3026 
3027  private:
3028  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
3029  Encoding encoding) const;
3030  void VerifyExternalStringResource(ExternalStringResource* val) const;
3031  ExternalStringResource* GetExternalStringResourceSlow() const;
3032  ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
3033  String::Encoding* encoding_out) const;
3034  const ExternalOneByteStringResource* GetExternalOneByteStringResourceSlow()
3035  const;
3036 
3037  static void CheckCast(v8::Value* obj);
3038 };
3039 
3040 
3044 class V8_EXPORT Symbol : public Name {
3045  public:
3049  Local<Value> Name() const;
3050 
3054  static Local<Symbol> New(Isolate* isolate,
3055  Local<String> name = Local<String>());
3056 
3064  static Local<Symbol> For(Isolate *isolate, Local<String> name);
3065 
3070  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
3071 
3072  // Well-known symbols
3073  static Local<Symbol> GetHasInstance(Isolate* isolate);
3074  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
3075  static Local<Symbol> GetIterator(Isolate* isolate);
3076  static Local<Symbol> GetMatch(Isolate* isolate);
3077  static Local<Symbol> GetReplace(Isolate* isolate);
3078  static Local<Symbol> GetSearch(Isolate* isolate);
3079  static Local<Symbol> GetSplit(Isolate* isolate);
3080  static Local<Symbol> GetToPrimitive(Isolate* isolate);
3081  static Local<Symbol> GetToStringTag(Isolate* isolate);
3082  static Local<Symbol> GetUnscopables(Isolate* isolate);
3083 
3084  V8_INLINE static Symbol* Cast(Value* obj);
3085 
3086  private:
3087  Symbol();
3088  static void CheckCast(Value* obj);
3089 };
3090 
3091 
3097 class V8_EXPORT Private : public Data {
3098  public:
3102  Local<Value> Name() const;
3103 
3107  static Local<Private> New(Isolate* isolate,
3108  Local<String> name = Local<String>());
3109 
3119  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3120 
3121  V8_INLINE static Private* Cast(Data* data);
3122 
3123  private:
3124  Private();
3125 
3126  static void CheckCast(Data* that);
3127 };
3128 
3129 
3133 class V8_EXPORT Number : public Primitive {
3134  public:
3135  double Value() const;
3136  static Local<Number> New(Isolate* isolate, double value);
3137  V8_INLINE static Number* Cast(v8::Value* obj);
3138  private:
3139  Number();
3140  static void CheckCast(v8::Value* obj);
3141 };
3142 
3143 
3147 class V8_EXPORT Integer : public Number {
3148  public:
3149  static Local<Integer> New(Isolate* isolate, int32_t value);
3150  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3151  int64_t Value() const;
3152  V8_INLINE static Integer* Cast(v8::Value* obj);
3153  private:
3154  Integer();
3155  static void CheckCast(v8::Value* obj);
3156 };
3157 
3158 
3162 class V8_EXPORT Int32 : public Integer {
3163  public:
3164  int32_t Value() const;
3165  V8_INLINE static Int32* Cast(v8::Value* obj);
3166 
3167  private:
3168  Int32();
3169  static void CheckCast(v8::Value* obj);
3170 };
3171 
3172 
3176 class V8_EXPORT Uint32 : public Integer {
3177  public:
3178  uint32_t Value() const;
3179  V8_INLINE static Uint32* Cast(v8::Value* obj);
3180 
3181  private:
3182  Uint32();
3183  static void CheckCast(v8::Value* obj);
3184 };
3185 
3189 class V8_EXPORT BigInt : public Primitive {
3190  public:
3191  static Local<BigInt> New(Isolate* isolate, int64_t value);
3192  static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3200  static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
3201  int word_count, const uint64_t* words);
3202 
3209  uint64_t Uint64Value(bool* lossless = nullptr) const;
3210 
3216  int64_t Int64Value(bool* lossless = nullptr) const;
3217 
3222  int WordCount() const;
3223 
3232  void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
3233 
3234  V8_INLINE static BigInt* Cast(v8::Value* obj);
3235 
3236  private:
3237  BigInt();
3238  static void CheckCast(v8::Value* obj);
3239 };
3240 
3246  None = 0,
3248  ReadOnly = 1 << 0,
3250  DontEnum = 1 << 1,
3252  DontDelete = 1 << 2
3253 };
3254 
3260 typedef void (*AccessorGetterCallback)(
3261  Local<String> property,
3262  const PropertyCallbackInfo<Value>& info);
3263 typedef void (*AccessorNameGetterCallback)(
3264  Local<Name> property,
3265  const PropertyCallbackInfo<Value>& info);
3266 
3267 
3268 typedef void (*AccessorSetterCallback)(
3269  Local<String> property,
3270  Local<Value> value,
3271  const PropertyCallbackInfo<void>& info);
3272 typedef void (*AccessorNameSetterCallback)(
3273  Local<Name> property,
3274  Local<Value> value,
3275  const PropertyCallbackInfo<void>& info);
3276 
3277 
3288  DEFAULT = 0,
3289  ALL_CAN_READ = 1,
3290  ALL_CAN_WRITE = 1 << 1,
3291  PROHIBITS_OVERWRITING = 1 << 2
3292 };
3293 
3298  ALL_PROPERTIES = 0,
3299  ONLY_WRITABLE = 1,
3300  ONLY_ENUMERABLE = 2,
3301  ONLY_CONFIGURABLE = 4,
3302  SKIP_STRINGS = 8,
3303  SKIP_SYMBOLS = 16
3304 };
3305 
3313 enum class SideEffectType { kHasSideEffect, kHasNoSideEffect };
3314 
3322 enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes };
3323 
3328 enum class IndexFilter { kIncludeIndices, kSkipIndices };
3329 
3334 enum class KeyConversionMode { kConvertToString, kKeepNumbers };
3335 
3339 enum class IntegrityLevel { kFrozen, kSealed };
3340 
3344 class V8_EXPORT Object : public Value {
3345  public:
3346  V8_DEPRECATE_SOON("Use maybe version",
3347  bool Set(Local<Value> key, Local<Value> value));
3348  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
3349  Local<Value> key, Local<Value> value);
3350 
3351  V8_DEPRECATE_SOON("Use maybe version",
3352  bool Set(uint32_t index, Local<Value> value));
3353  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3354  Local<Value> value);
3355 
3356  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3357  //
3358  // Defines a configurable, writable, enumerable property with the given value
3359  // on the object unless the property already exists and is not configurable
3360  // or the object is not extensible.
3361  //
3362  // Returns true on success.
3363  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3364  Local<Name> key,
3365  Local<Value> value);
3366  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3367  uint32_t index,
3368  Local<Value> value);
3369 
3370  // Implements DefineOwnProperty.
3371  //
3372  // In general, CreateDataProperty will be faster, however, does not allow
3373  // for specifying attributes.
3374  //
3375  // Returns true on success.
3376  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3377  Local<Context> context, Local<Name> key, Local<Value> value,
3378  PropertyAttribute attributes = None);
3379 
3380  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3381  //
3382  // The defineProperty function is used to add an own property or
3383  // update the attributes of an existing own property of an object.
3384  //
3385  // Both data and accessor descriptors can be used.
3386  //
3387  // In general, CreateDataProperty is faster, however, does not allow
3388  // for specifying attributes or an accessor descriptor.
3389  //
3390  // The PropertyDescriptor can change when redefining a property.
3391  //
3392  // Returns true on success.
3393  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3394  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3395 
3396  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3397  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3398  Local<Value> key);
3399 
3400  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3401  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3402  uint32_t index);
3403 
3409  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3410  Local<Context> context, Local<Value> key);
3411 
3415  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3416  Local<Context> context, Local<Name> key);
3417 
3418  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
3434  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3435  Local<Value> key);
3436 
3437  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3438  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3439  Local<Value> key);
3440 
3441  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3442 
3443  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3444  uint32_t index);
3445 
3449  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
3450  Local<Context> context, Local<Name> name,
3451  AccessorNameGetterCallback getter, AccessorNameSetterCallback setter = 0,
3453  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3454  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3455 
3456  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3457  Local<Function> setter = Local<Function>(),
3458  PropertyAttribute attribute = None,
3459  AccessControl settings = DEFAULT);
3460 
3465  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3466  Local<Context> context, Local<Name> name,
3467  AccessorNameGetterCallback getter,
3468  AccessorNameSetterCallback setter = nullptr,
3469  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
3470  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3471 
3480  V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
3481  Local<Context> context, Local<Name> name,
3482  AccessorNameGetterCallback getter, Local<Value> data = Local<Value>(),
3483  PropertyAttribute attributes = None,
3484  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
3485 
3492  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3493  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3494  Local<Value> value);
3495  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3496  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3497 
3504  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3505  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3506  Local<Context> context);
3507  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3508  Local<Context> context, KeyCollectionMode mode,
3509  PropertyFilter property_filter, IndexFilter index_filter,
3510  KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
3511 
3517  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3518  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3519  Local<Context> context);
3520 
3527  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3528  Local<Context> context, PropertyFilter filter,
3529  KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
3530 
3536  Local<Value> GetPrototype();
3537 
3543  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3544  Local<Value> prototype);
3545 
3550  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3551 
3557  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3558  Local<Context> context);
3559 
3563  Local<String> GetConstructorName();
3564 
3568  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3569 
3571  int InternalFieldCount();
3572 
3574  V8_INLINE static int InternalFieldCount(
3575  const PersistentBase<Object>& object) {
3576  return object.val_->InternalFieldCount();
3577  }
3578 
3580  V8_INLINE Local<Value> GetInternalField(int index);
3581 
3583  void SetInternalField(int index, Local<Value> value);
3584 
3590  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3591 
3593  V8_INLINE static void* GetAlignedPointerFromInternalField(
3594  const PersistentBase<Object>& object, int index) {
3595  return object.val_->GetAlignedPointerFromInternalField(index);
3596  }
3597 
3603  void SetAlignedPointerInInternalField(int index, void* value);
3604  void SetAlignedPointerInInternalFields(int argc, int indices[],
3605  void* values[]);
3606 
3612  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3613  Local<Name> key);
3614  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3615  uint32_t index);
3616  V8_DEPRECATE_SOON("Use maybe version",
3617  bool HasRealNamedProperty(Local<String> key));
3631  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3632  Local<Name> key);
3633  V8_DEPRECATE_SOON("Use maybe version",
3634  bool HasRealIndexedProperty(uint32_t index));
3635  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3636  Local<Context> context, uint32_t index);
3637  V8_DEPRECATE_SOON("Use maybe version",
3638  bool HasRealNamedCallbackProperty(Local<String> key));
3639  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3640  Local<Context> context, Local<Name> key);
3641 
3646  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3647  Local<Context> context, Local<Name> key);
3648 
3654  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
3655  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3656  Local<Name> key);
3657 
3663  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3664  Local<Context> context, Local<Name> key);
3665 
3671  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3672  Local<Context> context, Local<Name> key);
3673 
3675  bool HasNamedLookupInterceptor();
3676 
3678  bool HasIndexedLookupInterceptor();
3679 
3687  int GetIdentityHash();
3688 
3693  // TODO(dcarney): take an isolate and optionally bail out?
3694  Local<Object> Clone();
3695 
3699  Local<Context> CreationContext();
3700 
3703  const PersistentBase<Object>& object) {
3704  return object.val_->CreationContext();
3705  }
3706 
3712  bool IsCallable();
3713 
3717  bool IsConstructor();
3718 
3723  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
3724  Local<Value> recv,
3725  int argc,
3726  Local<Value> argv[]);
3727 
3733  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3734  Local<Context> context, int argc, Local<Value> argv[]);
3735 
3739  Isolate* GetIsolate();
3740 
3750  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3751 
3752  static Local<Object> New(Isolate* isolate);
3753 
3754  V8_INLINE static Object* Cast(Value* obj);
3755 
3756  private:
3757  Object();
3758  static void CheckCast(Value* obj);
3759  Local<Value> SlowGetInternalField(int index);
3760  void* SlowGetAlignedPointerFromInternalField(int index);
3761 };
3762 
3763 
3767 class V8_EXPORT Array : public Object {
3768  public:
3769  uint32_t Length() const;
3770 
3775  static Local<Array> New(Isolate* isolate, int length = 0);
3776 
3777  V8_INLINE static Array* Cast(Value* obj);
3778  private:
3779  Array();
3780  static void CheckCast(Value* obj);
3781 };
3782 
3783 
3787 class V8_EXPORT Map : public Object {
3788  public:
3789  size_t Size() const;
3790  void Clear();
3791  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3792  Local<Value> key);
3793  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
3794  Local<Value> key,
3795  Local<Value> value);
3796  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3797  Local<Value> key);
3798  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3799  Local<Value> key);
3800 
3805  Local<Array> AsArray() const;
3806 
3810  static Local<Map> New(Isolate* isolate);
3811 
3812  V8_INLINE static Map* Cast(Value* obj);
3813 
3814  private:
3815  Map();
3816  static void CheckCast(Value* obj);
3817 };
3818 
3819 
3823 class V8_EXPORT Set : public Object {
3824  public:
3825  size_t Size() const;
3826  void Clear();
3827  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3828  Local<Value> key);
3829  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3830  Local<Value> key);
3831  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3832  Local<Value> key);
3833 
3837  Local<Array> AsArray() const;
3838 
3842  static Local<Set> New(Isolate* isolate);
3843 
3844  V8_INLINE static Set* Cast(Value* obj);
3845 
3846  private:
3847  Set();
3848  static void CheckCast(Value* obj);
3849 };
3850 
3851 
3852 template<typename T>
3853 class ReturnValue {
3854  public:
3855  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3856  : value_(that.value_) {
3857  TYPE_CHECK(T, S);
3858  }
3859  // Local setters
3860  template <typename S>
3861  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3862  void Set(const Persistent<S>& handle));
3863  template <typename S>
3864  V8_INLINE void Set(const Global<S>& handle);
3865  template <typename S>
3866  V8_INLINE void Set(const Local<S> handle);
3867  // Fast primitive setters
3868  V8_INLINE void Set(bool value);
3869  V8_INLINE void Set(double i);
3870  V8_INLINE void Set(int32_t i);
3871  V8_INLINE void Set(uint32_t i);
3872  // Fast JS primitive setters
3873  V8_INLINE void SetNull();
3874  V8_INLINE void SetUndefined();
3875  V8_INLINE void SetEmptyString();
3876  // Convenience getter for Isolate
3877  V8_INLINE Isolate* GetIsolate() const;
3878 
3879  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3880  template <typename S>
3881  V8_INLINE void Set(S* whatever);
3882 
3883  // Getter. Creates a new Local<> so it comes with a certain performance
3884  // hit. If the ReturnValue was not yet set, this will return the undefined
3885  // value.
3886  V8_INLINE Local<Value> Get() const;
3887 
3888  private:
3889  template<class F> friend class ReturnValue;
3890  template<class F> friend class FunctionCallbackInfo;
3891  template<class F> friend class PropertyCallbackInfo;
3892  template <class F, class G, class H>
3893  friend class PersistentValueMapBase;
3894  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3895  V8_INLINE internal::Object* GetDefaultValue();
3896  V8_INLINE explicit ReturnValue(internal::Object** slot);
3897  internal::Object** value_;
3898 };
3899 
3900 
3907 template<typename T>
3908 class FunctionCallbackInfo {
3909  public:
3911  V8_INLINE int Length() const;
3913  V8_INLINE Local<Value> operator[](int i) const;
3915  V8_INLINE Local<Object> This() const;
3926  V8_INLINE Local<Object> Holder() const;
3928  V8_INLINE Local<Value> NewTarget() const;
3930  V8_INLINE bool IsConstructCall() const;
3932  V8_INLINE Local<Value> Data() const;
3934  V8_INLINE Isolate* GetIsolate() const;
3936  V8_INLINE ReturnValue<T> GetReturnValue() const;
3937  // This shouldn't be public, but the arm compiler needs it.
3938  static const int kArgsLength = 6;
3939 
3940  protected:
3941  friend class internal::FunctionCallbackArguments;
3942  friend class internal::CustomArguments<FunctionCallbackInfo>;
3943  friend class debug::ConsoleCallArguments;
3944  static const int kHolderIndex = 0;
3945  static const int kIsolateIndex = 1;
3946  static const int kReturnValueDefaultValueIndex = 2;
3947  static const int kReturnValueIndex = 3;
3948  static const int kDataIndex = 4;
3949  static const int kNewTargetIndex = 5;
3950 
3951  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3952  internal::Object** values, int length);
3953  internal::Object** implicit_args_;
3954  internal::Object** values_;
3955  int length_;
3956 };
3957 
3958 
3963 template<typename T>
3964 class PropertyCallbackInfo {
3965  public:
3969  V8_INLINE Isolate* GetIsolate() const;
3970 
3976  V8_INLINE Local<Value> Data() const;
3977 
4019  V8_INLINE Local<Object> This() const;
4020 
4030  V8_INLINE Local<Object> Holder() const;
4031 
4040  V8_INLINE ReturnValue<T> GetReturnValue() const;
4041 
4049  V8_INLINE bool ShouldThrowOnError() const;
4050 
4051  // This shouldn't be public, but the arm compiler needs it.
4052  static const int kArgsLength = 7;
4053 
4054  protected:
4055  friend class MacroAssembler;
4056  friend class internal::PropertyCallbackArguments;
4057  friend class internal::CustomArguments<PropertyCallbackInfo>;
4058  static const int kShouldThrowOnErrorIndex = 0;
4059  static const int kHolderIndex = 1;
4060  static const int kIsolateIndex = 2;
4061  static const int kReturnValueDefaultValueIndex = 3;
4062  static const int kReturnValueIndex = 4;
4063  static const int kDataIndex = 5;
4064  static const int kThisIndex = 6;
4065 
4066  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
4067  internal::Object** args_;
4068 };
4069 
4070 
4071 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
4072 
4073 enum class ConstructorBehavior { kThrow, kAllow };
4074 
4078 class V8_EXPORT Function : public Object {
4079  public:
4084  static MaybeLocal<Function> New(
4085  Local<Context> context, FunctionCallback callback,
4086  Local<Value> data = Local<Value>(), int length = 0,
4087  ConstructorBehavior behavior = ConstructorBehavior::kAllow,
4088  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4089  static V8_DEPRECATE_SOON(
4090  "Use maybe version",
4091  Local<Function> New(Isolate* isolate, FunctionCallback callback,
4092  Local<Value> data = Local<Value>(), int length = 0));
4093 
4094  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
4095  Local<Context> context, int argc, Local<Value> argv[]) const;
4096 
4097  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
4098  Local<Context> context) const {
4099  return NewInstance(context, 0, nullptr);
4100  }
4101 
4107  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
4108  Local<Context> context, int argc, Local<Value> argv[],
4109  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4110 
4111  V8_DEPRECATE_SOON("Use maybe version",
4112  Local<Value> Call(Local<Value> recv, int argc,
4113  Local<Value> argv[]));
4114  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
4115  Local<Value> recv, int argc,
4116  Local<Value> argv[]);
4117 
4118  void SetName(Local<String> name);
4119  Local<Value> GetName() const;
4120 
4127  Local<Value> GetInferredName() const;
4128 
4133  Local<Value> GetDebugName() const;
4134 
4139  Local<Value> GetDisplayName() const;
4140 
4145  int GetScriptLineNumber() const;
4150  int GetScriptColumnNumber() const;
4151 
4155  int ScriptId() const;
4156 
4161  Local<Value> GetBoundFunction() const;
4162 
4163  ScriptOrigin GetScriptOrigin() const;
4164  V8_INLINE static Function* Cast(Value* obj);
4165  static const int kLineOffsetNotFound;
4166 
4167  private:
4168  Function();
4169  static void CheckCast(Value* obj);
4170 };
4171 
4172 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4173 // The number of required internal fields can be defined by embedder.
4174 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4175 #endif
4176 
4180 class V8_EXPORT Promise : public Object {
4181  public:
4186  enum PromiseState { kPending, kFulfilled, kRejected };
4187 
4188  class V8_EXPORT Resolver : public Object {
4189  public:
4193  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
4194  Local<Context> context);
4195 
4199  Local<Promise> GetPromise();
4200 
4205  V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context,
4206  Local<Value> value);
4207 
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_DEPRECATED macro.
4361 #define COMMA ,
4362  V8_DEPRECATED(
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_DEPRECATED(
4377  "Use BufferReference directly.",
4378  inline BufferReference(CallerOwnedBuffer)); // NOLINT(runtime/explicit)
4379  V8_DEPRECATED("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::shared_ptr<internal::wasm::NativeModule> SharedModule;
4397  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
4398  friend class WasmCompiledModule;
4399  explicit TransferrableModule(SharedModule shared_module)
4400  : shared_module_(std::move(shared_module)) {}
4401  TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
4402  : serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
4403 
4404  SharedModule shared_module_;
4405  OwnedBuffer serialized_ = {nullptr, 0};
4406  OwnedBuffer wire_bytes_ = {nullptr, 0};
4407  };
4408 
4414  TransferrableModule GetTransferrableModule();
4415 
4420  static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
4421  Isolate* isolate, const TransferrableModule&);
4422 
4426  BufferReference GetWasmWireBytesRef();
4427  V8_DEPRECATED("Use GetWasmWireBytesRef version.",
4428  Local<String> GetWasmWireBytes());
4429 
4434  SerializedModule Serialize();
4435 
4440  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
4441  Isolate* isolate, BufferReference serialized_module,
4442  BufferReference wire_bytes);
4443  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
4444 
4445  private:
4446  static MaybeLocal<WasmCompiledModule> Deserialize(
4447  Isolate* isolate, BufferReference serialized_module,
4448  BufferReference wire_bytes);
4449  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
4450  const uint8_t* start,
4451  size_t length);
4452  static BufferReference AsReference(
4453  const TransferrableModule::OwnedBuffer& buff) {
4454  return {buff.first.get(), buff.second};
4455  }
4456 
4457  WasmCompiledModule();
4458  static void CheckCast(Value* obj);
4459 };
4460 
4461 // TODO(clemensh): Remove after M70 branch.
4462 WasmCompiledModule::BufferReference::BufferReference(
4463  WasmCompiledModule::CallerOwnedBuffer buf)
4464  : BufferReference(buf.first, buf.second) {}
4465 WasmCompiledModule::BufferReference::
4466 operator WasmCompiledModule::CallerOwnedBuffer() {
4467  return {start, size};
4468 }
4469 
4476 class V8_EXPORT WasmStreaming final {
4477  public:
4478  class WasmStreamingImpl;
4479 
4480  WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
4481 
4482  ~WasmStreaming();
4483 
4488  void OnBytesReceived(const uint8_t* bytes, size_t size);
4489 
4495  void Finish();
4496 
4502  void Abort(MaybeLocal<Value> exception);
4503 
4509  static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
4510  Local<Value> value);
4511 
4512  private:
4513  std::unique_ptr<WasmStreamingImpl> impl_;
4514 };
4515 
4516 // TODO(mtrofin): when streaming compilation is done, we can rename this
4517 // to simply WasmModuleObjectBuilder
4518 class V8_EXPORT WasmModuleObjectBuilderStreaming final {
4519  public:
4520  explicit WasmModuleObjectBuilderStreaming(Isolate* isolate);
4524  void OnBytesReceived(const uint8_t*, size_t size);
4525  void Finish();
4531  void Abort(MaybeLocal<Value> exception);
4532  Local<Promise> GetPromise();
4533 
4535 
4536  private:
4538  delete;
4540  default;
4542  const WasmModuleObjectBuilderStreaming&) = delete;
4544  WasmModuleObjectBuilderStreaming&&) = default;
4545  Isolate* isolate_ = nullptr;
4546 
4547 #if V8_CC_MSVC
4548 
4556 #else
4557  Persistent<Promise> promise_;
4558 #endif
4559  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4560 };
4561 
4562 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4563 // The number of required internal fields can be defined by embedder.
4564 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4565 #endif
4566 
4567 
4568 enum class ArrayBufferCreationMode { kInternalized, kExternalized };
4569 
4570 
4574 class V8_EXPORT ArrayBuffer : public Object {
4575  public:
4591  class V8_EXPORT Allocator { // NOLINT
4592  public:
4593  virtual ~Allocator() {}
4594 
4599  virtual void* Allocate(size_t length) = 0;
4600 
4605  virtual void* AllocateUninitialized(size_t length) = 0;
4606 
4611  virtual void Free(void* data, size_t length) = 0;
4612 
4618  enum class AllocationMode { kNormal, kReservation };
4619 
4626  static Allocator* NewDefaultAllocator();
4627  };
4628 
4638  class V8_EXPORT Contents { // NOLINT
4639  public:
4640  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
4641 
4642  Contents()
4643  : data_(nullptr),
4644  byte_length_(0),
4645  allocation_base_(nullptr),
4646  allocation_length_(0),
4647  allocation_mode_(Allocator::AllocationMode::kNormal),
4648  deleter_(nullptr),
4649  deleter_data_(nullptr) {}
4650 
4651  void* AllocationBase() const { return allocation_base_; }
4652  size_t AllocationLength() const { return allocation_length_; }
4653  Allocator::AllocationMode AllocationMode() const {
4654  return allocation_mode_;
4655  }
4656 
4657  void* Data() const { return data_; }
4658  size_t ByteLength() const { return byte_length_; }
4659  DeleterCallback Deleter() const { return deleter_; }
4660  void* DeleterData() const { return deleter_data_; }
4661 
4662  private:
4663  Contents(void* data, size_t byte_length, void* allocation_base,
4664  size_t allocation_length,
4665  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
4666  void* deleter_data);
4667 
4668  void* data_;
4669  size_t byte_length_;
4670  void* allocation_base_;
4671  size_t allocation_length_;
4672  Allocator::AllocationMode allocation_mode_;
4673  DeleterCallback deleter_;
4674  void* deleter_data_;
4675 
4676  friend class ArrayBuffer;
4677  };
4678 
4679 
4683  size_t ByteLength() const;
4684 
4691  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4692 
4702  static Local<ArrayBuffer> New(
4703  Isolate* isolate, void* data, size_t byte_length,
4704  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
4705 
4710  bool IsExternal() const;
4711 
4715  bool IsNeuterable() const;
4716 
4723  void Neuter();
4724 
4735  Contents Externalize();
4736 
4745  Contents GetContents();
4746 
4747  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4748 
4749  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4750  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4751 
4752  private:
4753  ArrayBuffer();
4754  static void CheckCast(Value* obj);
4755 };
4756 
4757 
4758 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4759 // The number of required internal fields can be defined by embedder.
4760 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4761 #endif
4762 
4763 
4768 class V8_EXPORT ArrayBufferView : public Object {
4769  public:
4773  Local<ArrayBuffer> Buffer();
4777  size_t ByteOffset();
4781  size_t ByteLength();
4782 
4792  size_t CopyContents(void* dest, size_t byte_length);
4793 
4798  bool HasBuffer() const;
4799 
4800  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4801 
4802  static const int kInternalFieldCount =
4803  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4804  static const int kEmbedderFieldCount =
4805  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4806 
4807  private:
4808  ArrayBufferView();
4809  static void CheckCast(Value* obj);
4810 };
4811 
4812 
4817 class V8_EXPORT TypedArray : public ArrayBufferView {
4818  public:
4819  /*
4820  * The largest typed array size that can be constructed using New.
4821  */
4822  static constexpr size_t kMaxLength = internal::kSmiMaxValue;
4823 
4828  size_t Length();
4829 
4830  V8_INLINE static TypedArray* Cast(Value* obj);
4831 
4832  private:
4833  TypedArray();
4834  static void CheckCast(Value* obj);
4835 };
4836 
4837 
4841 class V8_EXPORT Uint8Array : public TypedArray {
4842  public:
4843  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4844  size_t byte_offset, size_t length);
4845  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4846  size_t byte_offset, size_t length);
4847  V8_INLINE static Uint8Array* Cast(Value* obj);
4848 
4849  private:
4850  Uint8Array();
4851  static void CheckCast(Value* obj);
4852 };
4853 
4854 
4858 class V8_EXPORT Uint8ClampedArray : public TypedArray {
4859  public:
4860  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4861  size_t byte_offset, size_t length);
4862  static Local<Uint8ClampedArray> New(
4863  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4864  size_t length);
4865  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4866 
4867  private:
4869  static void CheckCast(Value* obj);
4870 };
4871 
4875 class V8_EXPORT Int8Array : public TypedArray {
4876  public:
4877  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4878  size_t byte_offset, size_t length);
4879  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4880  size_t byte_offset, size_t length);
4881  V8_INLINE static Int8Array* Cast(Value* obj);
4882 
4883  private:
4884  Int8Array();
4885  static void CheckCast(Value* obj);
4886 };
4887 
4888 
4892 class V8_EXPORT Uint16Array : public TypedArray {
4893  public:
4894  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4895  size_t byte_offset, size_t length);
4896  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4897  size_t byte_offset, size_t length);
4898  V8_INLINE static Uint16Array* Cast(Value* obj);
4899 
4900  private:
4901  Uint16Array();
4902  static void CheckCast(Value* obj);
4903 };
4904 
4905 
4909 class V8_EXPORT Int16Array : public TypedArray {
4910  public:
4911  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4912  size_t byte_offset, size_t length);
4913  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4914  size_t byte_offset, size_t length);
4915  V8_INLINE static Int16Array* Cast(Value* obj);
4916 
4917  private:
4918  Int16Array();
4919  static void CheckCast(Value* obj);
4920 };
4921 
4922 
4926 class V8_EXPORT Uint32Array : public TypedArray {
4927  public:
4928  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4929  size_t byte_offset, size_t length);
4930  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4931  size_t byte_offset, size_t length);
4932  V8_INLINE static Uint32Array* Cast(Value* obj);
4933 
4934  private:
4935  Uint32Array();
4936  static void CheckCast(Value* obj);
4937 };
4938 
4939 
4943 class V8_EXPORT Int32Array : public TypedArray {
4944  public:
4945  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4946  size_t byte_offset, size_t length);
4947  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4948  size_t byte_offset, size_t length);
4949  V8_INLINE static Int32Array* Cast(Value* obj);
4950 
4951  private:
4952  Int32Array();
4953  static void CheckCast(Value* obj);
4954 };
4955 
4956 
4960 class V8_EXPORT Float32Array : public TypedArray {
4961  public:
4962  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4963  size_t byte_offset, size_t length);
4964  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4965  size_t byte_offset, size_t length);
4966  V8_INLINE static Float32Array* Cast(Value* obj);
4967 
4968  private:
4969  Float32Array();
4970  static void CheckCast(Value* obj);
4971 };
4972 
4973 
4977 class V8_EXPORT Float64Array : public TypedArray {
4978  public:
4979  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4980  size_t byte_offset, size_t length);
4981  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4982  size_t byte_offset, size_t length);
4983  V8_INLINE static Float64Array* Cast(Value* obj);
4984 
4985  private:
4986  Float64Array();
4987  static void CheckCast(Value* obj);
4988 };
4989 
4993 class V8_EXPORT BigInt64Array : public TypedArray {
4994  public:
4995  static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
4996  size_t byte_offset, size_t length);
4997  static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4998  size_t byte_offset, size_t length);
4999  V8_INLINE static BigInt64Array* Cast(Value* obj);
5000 
5001  private:
5002  BigInt64Array();
5003  static void CheckCast(Value* obj);
5004 };
5005 
5009 class V8_EXPORT BigUint64Array : public TypedArray {
5010  public:
5011  static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
5012  size_t byte_offset, size_t length);
5013  static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5014  size_t byte_offset, size_t length);
5015  V8_INLINE static BigUint64Array* Cast(Value* obj);
5016 
5017  private:
5018  BigUint64Array();
5019  static void CheckCast(Value* obj);
5020 };
5021 
5025 class V8_EXPORT DataView : public ArrayBufferView {
5026  public:
5027  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
5028  size_t byte_offset, size_t length);
5029  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
5030  size_t byte_offset, size_t length);
5031  V8_INLINE static DataView* Cast(Value* obj);
5032 
5033  private:
5034  DataView();
5035  static void CheckCast(Value* obj);
5036 };
5037 
5038 
5043 class V8_EXPORT SharedArrayBuffer : public Object {
5044  public:
5056  class V8_EXPORT Contents { // NOLINT
5057  public:
5059  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
5060 
5061  Contents()
5062  : data_(nullptr),
5063  byte_length_(0),
5064  allocation_base_(nullptr),
5065  allocation_length_(0),
5066  allocation_mode_(Allocator::AllocationMode::kNormal),
5067  deleter_(nullptr),
5068  deleter_data_(nullptr) {}
5069 
5070  void* AllocationBase() const { return allocation_base_; }
5071  size_t AllocationLength() const { return allocation_length_; }
5072  Allocator::AllocationMode AllocationMode() const {
5073  return allocation_mode_;
5074  }
5075 
5076  void* Data() const { return data_; }
5077  size_t ByteLength() const { return byte_length_; }
5078  DeleterCallback Deleter() const { return deleter_; }
5079  void* DeleterData() const { return deleter_data_; }
5080 
5081  private:
5082  Contents(void* data, size_t byte_length, void* allocation_base,
5083  size_t allocation_length,
5084  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
5085  void* deleter_data);
5086 
5087  void* data_;
5088  size_t byte_length_;
5089  void* allocation_base_;
5090  size_t allocation_length_;
5091  Allocator::AllocationMode allocation_mode_;
5092  DeleterCallback deleter_;
5093  void* deleter_data_;
5094 
5095  friend class SharedArrayBuffer;
5096  };
5097 
5101  size_t ByteLength() const;
5102 
5109  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
5110 
5117  static Local<SharedArrayBuffer> New(
5118  Isolate* isolate, void* data, size_t byte_length,
5119  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5120 
5125  bool IsExternal() const;
5126 
5139  Contents Externalize();
5140 
5153  Contents GetContents();
5154 
5155  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
5156 
5157  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5158 
5159  private:
5161  static void CheckCast(Value* obj);
5162 };
5163 
5164 
5168 class V8_EXPORT Date : public Object {
5169  public:
5170  static V8_DEPRECATE_SOON("Use maybe version.",
5171  Local<Value> New(Isolate* isolate, double time));
5172  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
5173  double time);
5174 
5179  double ValueOf() const;
5180 
5181  V8_INLINE static Date* Cast(Value* obj);
5182 
5195  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
5196 
5197  private:
5198  static void CheckCast(Value* obj);
5199 };
5200 
5201 
5205 class V8_EXPORT NumberObject : public Object {
5206  public:
5207  static Local<Value> New(Isolate* isolate, double value);
5208 
5209  double ValueOf() const;
5210 
5211  V8_INLINE static NumberObject* Cast(Value* obj);
5212 
5213  private:
5214  static void CheckCast(Value* obj);
5215 };
5216 
5220 class V8_EXPORT BigIntObject : public Object {
5221  public:
5222  static Local<Value> New(Isolate* isolate, int64_t value);
5223 
5224  Local<BigInt> ValueOf() const;
5225 
5226  V8_INLINE static BigIntObject* Cast(Value* obj);
5227 
5228  private:
5229  static void CheckCast(Value* obj);
5230 };
5231 
5235 class V8_EXPORT BooleanObject : public Object {
5236  public:
5237  static Local<Value> New(Isolate* isolate, bool value);
5238 
5239  bool ValueOf() const;
5240 
5241  V8_INLINE static BooleanObject* Cast(Value* obj);
5242 
5243  private:
5244  static void CheckCast(Value* obj);
5245 };
5246 
5247 
5251 class V8_EXPORT StringObject : public Object {
5252  public:
5253  static Local<Value> New(Isolate* isolate, Local<String> value);
5254  static V8_DEPRECATED("Use Isolate* version",
5255  Local<Value> New(Local<String> value));
5256 
5257  Local<String> ValueOf() const;
5258 
5259  V8_INLINE static StringObject* Cast(Value* obj);
5260 
5261  private:
5262  static void CheckCast(Value* obj);
5263 };
5264 
5265 
5269 class V8_EXPORT SymbolObject : public Object {
5270  public:
5271  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
5272 
5273  Local<Symbol> ValueOf() const;
5274 
5275  V8_INLINE static SymbolObject* Cast(Value* obj);
5276 
5277  private:
5278  static void CheckCast(Value* obj);
5279 };
5280 
5281 
5285 class V8_EXPORT RegExp : public Object {
5286  public:
5291  enum Flags {
5292  kNone = 0,
5293  kGlobal = 1 << 0,
5294  kIgnoreCase = 1 << 1,
5295  kMultiline = 1 << 2,
5296  kSticky = 1 << 3,
5297  kUnicode = 1 << 4,
5298  kDotAll = 1 << 5,
5299  };
5300 
5311  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
5312  Local<String> pattern,
5313  Flags flags);
5314 
5319  Local<String> GetSource() const;
5320 
5324  Flags GetFlags() const;
5325 
5326  V8_INLINE static RegExp* Cast(Value* obj);
5327 
5328  private:
5329  static void CheckCast(Value* obj);
5330 };
5331 
5332 
5337 class V8_EXPORT External : public Value {
5338  public:
5339  static Local<External> New(Isolate* isolate, void* value);
5340  V8_INLINE static External* Cast(Value* obj);
5341  void* Value() const;
5342  private:
5343  static void CheckCast(v8::Value* obj);
5344 };
5345 
5346 #define V8_INTRINSICS_LIST(F) \
5347  F(ArrayProto_entries, array_entries_iterator) \
5348  F(ArrayProto_forEach, array_for_each_iterator) \
5349  F(ArrayProto_keys, array_keys_iterator) \
5350  F(ArrayProto_values, array_values_iterator) \
5351  F(ErrorPrototype, initial_error_prototype) \
5352  F(IteratorPrototype, initial_iterator_prototype)
5353 
5354 enum Intrinsic {
5355 #define V8_DECL_INTRINSIC(name, iname) k##name,
5356  V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
5357 #undef V8_DECL_INTRINSIC
5358 };
5359 
5360 
5361 // --- Templates ---
5362 
5363 
5367 class V8_EXPORT Template : public Data {
5368  public:
5374  void Set(Local<Name> name, Local<Data> value,
5375  PropertyAttribute attributes = None);
5376  void SetPrivate(Local<Private> name, Local<Data> value,
5377  PropertyAttribute attributes = None);
5378  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5379 
5380  void SetAccessorProperty(
5381  Local<Name> name,
5384  PropertyAttribute attribute = None,
5385  AccessControl settings = DEFAULT);
5386 
5414  void SetNativeDataProperty(
5416  AccessorSetterCallback setter = 0,
5417  // TODO(dcarney): gcc can't handle Local below
5418  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5420  AccessControl settings = DEFAULT,
5421  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5422  void SetNativeDataProperty(
5423  Local<Name> name, AccessorNameGetterCallback getter,
5424  AccessorNameSetterCallback setter = 0,
5425  // TODO(dcarney): gcc can't handle Local below
5426  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5428  AccessControl settings = DEFAULT,
5429  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5430 
5435  void SetLazyDataProperty(
5436  Local<Name> name, AccessorNameGetterCallback getter,
5437  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5438  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
5439 
5444  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5445  PropertyAttribute attribute = None);
5446 
5447  private:
5448  Template();
5449 
5450  friend class ObjectTemplate;
5451  friend class FunctionTemplate;
5452 };
5453 
5454 // TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
5455 // NamedPropertyFooCallback.
5456 
5494  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5495 
5518  Local<Name> property, Local<Value> value,
5519  const PropertyCallbackInfo<Value>& info);
5520 
5543  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5544 
5567  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5568 
5576  const PropertyCallbackInfo<Array>& info);
5577 
5599  Local<Name> property, const PropertyDescriptor& desc,
5600  const PropertyCallbackInfo<Value>& info);
5601 
5622  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5623 
5628  uint32_t index,
5629  const PropertyCallbackInfo<Value>& info);
5630 
5635  uint32_t index,
5636  Local<Value> value,
5637  const PropertyCallbackInfo<Value>& info);
5638 
5643  uint32_t index,
5644  const PropertyCallbackInfo<Integer>& info);
5645 
5650  uint32_t index,
5651  const PropertyCallbackInfo<Boolean>& info);
5652 
5660  const PropertyCallbackInfo<Array>& info);
5661 
5666  uint32_t index, const PropertyDescriptor& desc,
5667  const PropertyCallbackInfo<Value>& info);
5668 
5673  uint32_t index, const PropertyCallbackInfo<Value>& info);
5674 
5679  ACCESS_GET,
5680  ACCESS_SET,
5681  ACCESS_HAS,
5682  ACCESS_DELETE,
5683  ACCESS_KEYS
5684 };
5685 
5686 
5691 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5692  Local<Object> accessed_object,
5693  Local<Value> data);
5694 
5795 class V8_EXPORT FunctionTemplate : public Template {
5796  public:
5798  static Local<FunctionTemplate> New(
5799  Isolate* isolate, FunctionCallback callback = 0,
5800  Local<Value> data = Local<Value>(),
5801  Local<Signature> signature = Local<Signature>(), int length = 0,
5802  ConstructorBehavior behavior = ConstructorBehavior::kAllow,
5803  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5804 
5806  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5807  size_t index);
5808 
5812  static Local<FunctionTemplate> NewWithCache(
5813  Isolate* isolate, FunctionCallback callback,
5814  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5815  Local<Signature> signature = Local<Signature>(), int length = 0,
5816  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5817 
5819  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5820  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
5821  Local<Context> context);
5822 
5830  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5831 
5837  void SetCallHandler(
5838  FunctionCallback callback, Local<Value> data = Local<Value>(),
5839  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5840 
5842  void SetLength(int length);
5843 
5845  Local<ObjectTemplate> InstanceTemplate();
5846 
5852  void Inherit(Local<FunctionTemplate> parent);
5853 
5858  Local<ObjectTemplate> PrototypeTemplate();
5859 
5866  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5867 
5873  void SetClassName(Local<String> name);
5874 
5875 
5880  void SetAcceptAnyReceiver(bool value);
5881 
5894  void SetHiddenPrototype(bool value);
5895 
5900  void ReadOnlyPrototype();
5901 
5906  void RemovePrototype();
5907 
5912  bool HasInstance(Local<Value> object);
5913 
5914  V8_INLINE static FunctionTemplate* Cast(Data* data);
5915 
5916  private:
5917  FunctionTemplate();
5918 
5919  static void CheckCast(Data* that);
5920  friend class Context;
5921  friend class ObjectTemplate;
5922 };
5923 
5932  kNone = 0,
5933 
5937  kAllCanRead = 1,
5938 
5943  kNonMasking = 1 << 1,
5944 
5949  kOnlyInterceptStrings = 1 << 2,
5950 
5954  kHasNoSideEffect = 1 << 3,
5955 };
5956 
5966  Local<Value> data = Local<Value>(),
5968  : getter(getter),
5969  setter(setter),
5970  query(query),
5971  deleter(deleter),
5972  enumerator(enumerator),
5973  definer(definer),
5974  descriptor(descriptor),
5975  data(data),
5976  flags(flags) {}
5977 
5985  Local<Value> data = Local<Value>(),
5987  : getter(getter),
5988  setter(setter),
5989  query(query),
5990  deleter(deleter),
5991  enumerator(enumerator),
5992  definer(0),
5993  descriptor(0),
5994  data(data),
5995  flags(flags) {}
5996 
6004  Local<Value> data = Local<Value>(),
6006  : getter(getter),
6007  setter(setter),
6008  query(0),
6009  deleter(deleter),
6010  enumerator(enumerator),
6011  definer(definer),
6012  descriptor(descriptor),
6013  data(data),
6014  flags(flags) {}
6015 
6023  Local<Value> data;
6024  PropertyHandlerFlags flags;
6025 };
6026 
6027 
6036  Local<Value> data = Local<Value>(),
6038  : getter(getter),
6039  setter(setter),
6040  query(query),
6041  deleter(deleter),
6042  enumerator(enumerator),
6043  definer(definer),
6044  descriptor(descriptor),
6045  data(data),
6046  flags(flags) {}
6047 
6050  IndexedPropertyGetterCallback getter = 0,
6051  IndexedPropertySetterCallback setter = 0,
6052  IndexedPropertyQueryCallback query = 0,
6053  IndexedPropertyDeleterCallback deleter = 0,
6054  IndexedPropertyEnumeratorCallback enumerator = 0,
6055  Local<Value> data = Local<Value>(),
6057  : getter(getter),
6058  setter(setter),
6059  query(query),
6060  deleter(deleter),
6061  enumerator(enumerator),
6062  definer(0),
6063  descriptor(0),
6064  data(data),
6065  flags(flags) {}
6066 
6074  Local<Value> data = Local<Value>(),
6076  : getter(getter),
6077  setter(setter),
6078  query(0),
6079  deleter(deleter),
6080  enumerator(enumerator),
6081  definer(definer),
6082  descriptor(descriptor),
6083  data(data),
6084  flags(flags) {}
6085 
6093  Local<Value> data;
6094  PropertyHandlerFlags flags;
6095 };
6096 
6097 
6104 class V8_EXPORT ObjectTemplate : public Template {
6105  public:
6107  static Local<ObjectTemplate> New(
6108  Isolate* isolate,
6110 
6112  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
6113  size_t index);
6114 
6116  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
6117  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
6118 
6148  void SetAccessor(
6150  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
6151  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
6153  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
6154  void SetAccessor(
6155  Local<Name> name, AccessorNameGetterCallback getter,
6156  AccessorNameSetterCallback setter = 0, Local<Value> data = Local<Value>(),
6157  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
6159  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
6160 
6172  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
6173 
6190  // TODO(dcarney): deprecate
6193  IndexedPropertySetterCallback setter = 0,
6194  IndexedPropertyQueryCallback query = 0,
6195  IndexedPropertyDeleterCallback deleter = 0,
6196  IndexedPropertyEnumeratorCallback enumerator = 0,
6197  Local<Value> data = Local<Value>()) {
6198  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
6199  deleter, enumerator, data));
6200  }
6201 
6212  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
6213 
6220  void SetCallAsFunctionHandler(FunctionCallback callback,
6221  Local<Value> data = Local<Value>());
6222 
6231  void MarkAsUndetectable();
6232 
6241  void SetAccessCheckCallback(AccessCheckCallback callback,
6242  Local<Value> data = Local<Value>());
6243 
6250  void SetAccessCheckCallbackAndHandler(
6251  AccessCheckCallback callback,
6252  const NamedPropertyHandlerConfiguration& named_handler,
6253  const IndexedPropertyHandlerConfiguration& indexed_handler,
6254  Local<Value> data = Local<Value>());
6255 
6260  int InternalFieldCount();
6261 
6266  void SetInternalFieldCount(int value);
6267 
6271  bool IsImmutableProto();
6272 
6277  void SetImmutableProto();
6278 
6279  V8_INLINE static ObjectTemplate* Cast(Data* data);
6280 
6281  private:
6282  ObjectTemplate();
6283  static Local<ObjectTemplate> New(internal::Isolate* isolate,
6284  Local<FunctionTemplate> constructor);
6285  static void CheckCast(Data* that);
6286  friend class FunctionTemplate;
6287 };
6288 
6297 class V8_EXPORT Signature : public Data {
6298  public:
6299  static Local<Signature> New(
6300  Isolate* isolate,
6302 
6303  V8_INLINE static Signature* Cast(Data* data);
6304 
6305  private:
6306  Signature();
6307 
6308  static void CheckCast(Data* that);
6309 };
6310 
6311 
6316 class V8_EXPORT AccessorSignature : public Data {
6317  public:
6318  static Local<AccessorSignature> New(
6319  Isolate* isolate,
6321 
6322  V8_INLINE static AccessorSignature* Cast(Data* data);
6323 
6324  private:
6326 
6327  static void CheckCast(Data* that);
6328 };
6329 
6330 
6331 // --- Extensions ---
6332 V8_DEPRECATE_SOON("Implementation detail", class)
6333 V8_EXPORT ExternalOneByteStringResourceImpl
6334  : public String::ExternalOneByteStringResource {
6335  public:
6336  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
6337  ExternalOneByteStringResourceImpl(const char* data, size_t length)
6338  : data_(data), length_(length) {}
6339  const char* data() const { return data_; }
6340  size_t length() const { return length_; }
6341 
6342  private:
6343  const char* data_;
6344  size_t length_;
6345 };
6346 
6350 class V8_EXPORT Extension { // NOLINT
6351  public:
6352  // Note that the strings passed into this constructor must live as long
6353  // as the Extension itself.
6354  Extension(const char* name,
6355  const char* source = 0,
6356  int dep_count = 0,
6357  const char** deps = 0,
6358  int source_length = -1);
6359  virtual ~Extension() { delete source_; }
6360  virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
6361  Isolate* isolate, Local<String> name) {
6362  return Local<FunctionTemplate>();
6363  }
6364 
6365  const char* name() const { return name_; }
6366  size_t source_length() const { return source_length_; }
6367  const String::ExternalOneByteStringResource* source() const {
6368  return source_;
6369  }
6370  int dependency_count() { return dep_count_; }
6371  const char** dependencies() { return deps_; }
6372  void set_auto_enable(bool value) { auto_enable_ = value; }
6373  bool auto_enable() { return auto_enable_; }
6374 
6375  // Disallow copying and assigning.
6376  Extension(const Extension&) = delete;
6377  void operator=(const Extension&) = delete;
6378 
6379  private:
6380  const char* name_;
6381  size_t source_length_; // expected to initialize before source_
6382  String::ExternalOneByteStringResource* source_;
6383  int dep_count_;
6384  const char** deps_;
6385  bool auto_enable_;
6386 };
6387 
6388 
6389 void V8_EXPORT RegisterExtension(Extension* extension);
6390 
6391 
6392 // --- Statics ---
6393 
6394 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6395 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6396 V8_INLINE Local<Boolean> True(Isolate* isolate);
6397 V8_INLINE Local<Boolean> False(Isolate* isolate);
6398 
6413 class V8_EXPORT ResourceConstraints {
6414  public:
6415  ResourceConstraints();
6416 
6426  void ConfigureDefaults(uint64_t physical_memory,
6427  uint64_t virtual_memory_limit);
6428 
6429  // Returns the max semi-space size in MB.
6430  V8_DEPRECATE_SOON("Use max_semi_space_size_in_kb()",
6431  size_t max_semi_space_size()) {
6432  return max_semi_space_size_in_kb_ / 1024;
6433  }
6434 
6435  // Sets the max semi-space size in MB.
6436  V8_DEPRECATE_SOON("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6437  void set_max_semi_space_size(size_t limit_in_mb)) {
6438  max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6439  }
6440 
6441  // Returns the max semi-space size in KB.
6442  size_t max_semi_space_size_in_kb() const {
6443  return max_semi_space_size_in_kb_;
6444  }
6445 
6446  // Sets the max semi-space size in KB.
6447  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6448  max_semi_space_size_in_kb_ = limit_in_kb;
6449  }
6450 
6451  size_t max_old_space_size() const { return max_old_space_size_; }
6452  void set_max_old_space_size(size_t limit_in_mb) {
6453  max_old_space_size_ = limit_in_mb;
6454  }
6455  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6456  size_t max_executable_size() const) {
6457  return max_executable_size_;
6458  }
6459  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6460  void set_max_executable_size(size_t limit_in_mb)) {
6461  max_executable_size_ = limit_in_mb;
6462  }
6463  uint32_t* stack_limit() const { return stack_limit_; }
6464  // Sets an address beyond which the VM's stack may not grow.
6465  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6466  size_t code_range_size() const { return code_range_size_; }
6467  void set_code_range_size(size_t limit_in_mb) {
6468  code_range_size_ = limit_in_mb;
6469  }
6470  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6471  void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; }
6472 
6473  private:
6474  // max_semi_space_size_ is in KB
6475  size_t max_semi_space_size_in_kb_;
6476 
6477  // The remaining limits are in MB
6478  size_t max_old_space_size_;
6479  size_t max_executable_size_;
6480  uint32_t* stack_limit_;
6481  size_t code_range_size_;
6482  size_t max_zone_pool_size_;
6483 };
6484 
6485 
6486 // --- Exceptions ---
6487 
6488 
6489 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6490 
6491 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6492 
6493 typedef void (*DcheckErrorCallback)(const char* file, int line,
6494  const char* message);
6495 
6496 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6497 
6498 // --- Tracing ---
6499 
6500 typedef void (*LogEventCallback)(const char* name, int event);
6501 
6506 class V8_EXPORT Exception {
6507  public:
6508  static Local<Value> RangeError(Local<String> message);
6509  static Local<Value> ReferenceError(Local<String> message);
6510  static Local<Value> SyntaxError(Local<String> message);
6511  static Local<Value> TypeError(Local<String> message);
6512  static Local<Value> Error(Local<String> message);
6513 
6519  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6520 
6525  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6526 };
6527 
6528 
6529 // --- Counters Callbacks ---
6530 
6531 typedef int* (*CounterLookupCallback)(const char* name);
6532 
6533 typedef void* (*CreateHistogramCallback)(const char* name,
6534  int min,
6535  int max,
6536  size_t buckets);
6537 
6538 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6539 
6540 // --- Enter/Leave Script Callback ---
6541 typedef void (*BeforeCallEnteredCallback)(Isolate*);
6542 typedef void (*CallCompletedCallback)(Isolate*);
6543 
6564 typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)(
6565  Local<Context> context, Local<ScriptOrModule> referrer,
6566  Local<String> specifier);
6567 
6578 typedef void (*HostInitializeImportMetaObjectCallback)(Local<Context> context,
6579  Local<Module> module,
6580  Local<Object> meta);
6581 
6598 enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
6599 
6600 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6601  Local<Value> parent);
6602 
6603 // --- Promise Reject Callback ---
6604 enum PromiseRejectEvent {
6605  kPromiseRejectWithNoHandler = 0,
6606  kPromiseHandlerAddedAfterReject = 1,
6607  kPromiseRejectAfterResolved = 2,
6608  kPromiseResolveAfterResolved = 3,
6609 };
6610 
6611 class PromiseRejectMessage {
6612  public:
6613  PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
6614  Local<Value> value, Local<StackTrace> stack_trace)
6615  : promise_(promise),
6616  event_(event),
6617  value_(value),
6618  stack_trace_(stack_trace) {}
6619 
6620  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6621  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6622  V8_INLINE Local<Value> GetValue() const { return value_; }
6623 
6624  private:
6625  Local<Promise> promise_;
6626  PromiseRejectEvent event_;
6627  Local<Value> value_;
6628  Local<StackTrace> stack_trace_;
6629 };
6630 
6631 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
6632 
6633 // --- Microtasks Callbacks ---
6634 typedef void (*MicrotasksCompletedCallback)(Isolate*);
6635 typedef void (*MicrotaskCallback)(void* data);
6636 
6637 
6645 enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
6646 
6647 
6657 class V8_EXPORT MicrotasksScope {
6658  public:
6659  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6660 
6661  MicrotasksScope(Isolate* isolate, Type type);
6662  ~MicrotasksScope();
6663 
6667  static void PerformCheckpoint(Isolate* isolate);
6668 
6672  static int GetCurrentDepth(Isolate* isolate);
6673 
6677  static bool IsRunningMicrotasks(Isolate* isolate);
6678 
6679  // Prevent copying.
6680  MicrotasksScope(const MicrotasksScope&) = delete;
6681  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6682 
6683  private:
6684  internal::Isolate* const isolate_;
6685  bool run_;
6686 };
6687 
6688 
6689 // --- Failed Access Check Callback ---
6690 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
6691  AccessType type,
6692  Local<Value> data);
6693 
6694 // --- AllowCodeGenerationFromStrings callbacks ---
6695 
6700 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context,
6701  Local<String> source);
6702 
6703 // --- WebAssembly compilation callbacks ---
6704 typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
6705 
6706 typedef bool (*AllowWasmCodeGenerationCallback)(Local<Context> context,
6707  Local<String> source);
6708 
6709 // --- Callback for APIs defined on v8-supported objects, but implemented
6710 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6711 typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&);
6712 
6713 // --- Callback for WebAssembly.compileStreaming ---
6714 typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo<Value>&);
6715 
6716 // --- Callback for checking if WebAssembly threads are enabled ---
6717 typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context);
6718 
6719 // --- Garbage Collection Callbacks ---
6720 
6728 enum GCType {
6729  kGCTypeScavenge = 1 << 0,
6730  kGCTypeMarkSweepCompact = 1 << 1,
6731  kGCTypeIncrementalMarking = 1 << 2,
6732  kGCTypeProcessWeakCallbacks = 1 << 3,
6733  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
6734  kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
6735 };
6736 
6751 enum GCCallbackFlags {
6752  kNoGCCallbackFlags = 0,
6753  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
6754  kGCCallbackFlagForced = 1 << 2,
6755  kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
6756  kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
6757  kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
6758  kGCCallbackScheduleIdleGarbageCollection = 1 << 6,
6759 };
6760 
6761 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6762 
6763 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6764 
6772 typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
6773  size_t initial_heap_limit);
6774 
6781 class V8_EXPORT HeapStatistics {
6782  public:
6783  HeapStatistics();
6784  size_t total_heap_size() { return total_heap_size_; }
6785  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6786  size_t total_physical_size() { return total_physical_size_; }
6787  size_t total_available_size() { return total_available_size_; }
6788  size_t used_heap_size() { return used_heap_size_; }
6789  size_t heap_size_limit() { return heap_size_limit_; }
6790  size_t malloced_memory() { return malloced_memory_; }
6791  size_t external_memory() { return external_memory_; }
6792  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6793  size_t number_of_native_contexts() { return number_of_native_contexts_; }
6794  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
6795 
6800  size_t does_zap_garbage() { return does_zap_garbage_; }
6801 
6802  private:
6803  size_t total_heap_size_;
6804  size_t total_heap_size_executable_;
6805  size_t total_physical_size_;
6806  size_t total_available_size_;
6807  size_t used_heap_size_;
6808  size_t heap_size_limit_;
6809  size_t malloced_memory_;
6810  size_t external_memory_;
6811  size_t peak_malloced_memory_;
6812  bool does_zap_garbage_;
6813  size_t number_of_native_contexts_;
6814  size_t number_of_detached_contexts_;
6815 
6816  friend class V8;
6817  friend class Isolate;
6818 };
6819 
6820 
6821 class V8_EXPORT HeapSpaceStatistics {
6822  public:
6823  HeapSpaceStatistics();
6824  const char* space_name() { return space_name_; }
6825  size_t space_size() { return space_size_; }
6826  size_t space_used_size() { return space_used_size_; }
6827  size_t space_available_size() { return space_available_size_; }
6828  size_t physical_space_size() { return physical_space_size_; }
6829 
6830  private:
6831  const char* space_name_;
6832  size_t space_size_;
6833  size_t space_used_size_;
6834  size_t space_available_size_;
6835  size_t physical_space_size_;
6836 
6837  friend class Isolate;
6838 };
6839 
6840 
6841 class V8_EXPORT HeapObjectStatistics {
6842  public:
6843  HeapObjectStatistics();
6844  const char* object_type() { return object_type_; }
6845  const char* object_sub_type() { return object_sub_type_; }
6846  size_t object_count() { return object_count_; }
6847  size_t object_size() { return object_size_; }
6848 
6849  private:
6850  const char* object_type_;
6851  const char* object_sub_type_;
6852  size_t object_count_;
6853  size_t object_size_;
6854 
6855  friend class Isolate;
6856 };
6857 
6858 class V8_EXPORT HeapCodeStatistics {
6859  public:
6860  HeapCodeStatistics();
6861  size_t code_and_metadata_size() { return code_and_metadata_size_; }
6862  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
6863  size_t external_script_source_size() { return external_script_source_size_; }
6864 
6865  private:
6866  size_t code_and_metadata_size_;
6867  size_t bytecode_and_metadata_size_;
6868  size_t external_script_source_size_;
6869 
6870  friend class Isolate;
6871 };
6872 
6873 class RetainedObjectInfo;
6874 
6875 
6887 typedef void (*FunctionEntryHook)(uintptr_t function,
6888  uintptr_t return_addr_location);
6889 
6895 struct JitCodeEvent {
6896  enum EventType {
6897  CODE_ADDED,
6898  CODE_MOVED,
6899  CODE_REMOVED,
6900  CODE_ADD_LINE_POS_INFO,
6901  CODE_START_LINE_INFO_RECORDING,
6902  CODE_END_LINE_INFO_RECORDING
6903  };
6904  // Definition of the code position type. The "POSITION" type means the place
6905  // in the source code which are of interest when making stack traces to
6906  // pin-point the source location of a stack frame as close as possible.
6907  // The "STATEMENT_POSITION" means the place at the beginning of each
6908  // statement, and is used to indicate possible break locations.
6909  enum PositionType { POSITION, STATEMENT_POSITION };
6910 
6911  // There are two different kinds of JitCodeEvents, one for JIT code generated
6912  // by the optimizing compiler, and one for byte code generated for the
6913  // interpreter. For JIT_CODE events, the |code_start| member of the event
6914  // points to the beginning of jitted assembly code, while for BYTE_CODE
6915  // events, |code_start| points to the first bytecode of the interpreted
6916  // function.
6917  enum CodeType { BYTE_CODE, JIT_CODE };
6918 
6919  // Type of event.
6920  EventType type;
6921  CodeType code_type;
6922  // Start of the instructions.
6923  void* code_start;
6924  // Size of the instructions.
6925  size_t code_len;
6926  // Script info for CODE_ADDED event.
6927  Local<UnboundScript> script;
6928  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
6929  // code line information which is returned from the
6930  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
6931  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
6932  void* user_data;
6933 
6934  struct name_t {
6935  // Name of the object associated with the code, note that the string is not
6936  // zero-terminated.
6937  const char* str;
6938  // Number of chars in str.
6939  size_t len;
6940  };
6941 
6942  struct line_info_t {
6943  // PC offset
6944  size_t offset;
6945  // Code position
6946  size_t pos;
6947  // The position type.
6948  PositionType position_type;
6949  };
6950 
6951  union {
6952  // Only valid for CODE_ADDED.
6953  struct name_t name;
6954 
6955  // Only valid for CODE_ADD_LINE_POS_INFO
6956  struct line_info_t line_info;
6957 
6958  // New location of instructions. Only valid for CODE_MOVED.
6959  void* new_code_start;
6960  };
6961 
6962  Isolate* isolate;
6963 };
6964 
6970 enum RAILMode {
6971  // Response performance mode: In this mode very low virtual machine latency
6972  // is provided. V8 will try to avoid JavaScript execution interruptions.
6973  // Throughput may be throttled.
6974  PERFORMANCE_RESPONSE,
6975  // Animation performance mode: In this mode low virtual machine latency is
6976  // provided. V8 will try to avoid as many JavaScript execution interruptions
6977  // as possible. Throughput may be throttled. This is the default mode.
6978  PERFORMANCE_ANIMATION,
6979  // Idle performance mode: The embedder is idle. V8 can complete deferred work
6980  // in this mode.
6981  PERFORMANCE_IDLE,
6982  // Load performance mode: In this mode high throughput is provided. V8 may
6983  // turn off latency optimizations.
6984  PERFORMANCE_LOAD
6985 };
6986 
6990 enum JitCodeEventOptions {
6991  kJitCodeEventDefault = 0,
6992  // Generate callbacks for already existent code.
6993  kJitCodeEventEnumExisting = 1
6994 };
6995 
6996 
7002 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
7003 
7004 
7008 class V8_EXPORT ExternalResourceVisitor { // NOLINT
7009  public:
7010  virtual ~ExternalResourceVisitor() {}
7011  virtual void VisitExternalString(Local<String> string) {}
7012 };
7013 
7014 
7018 class V8_EXPORT PersistentHandleVisitor { // NOLINT
7019  public:
7020  virtual ~PersistentHandleVisitor() {}
7021  virtual void VisitPersistentHandle(Persistent<Value>* value,
7022  uint16_t class_id) {}
7023 };
7024 
7033 enum class MemoryPressureLevel { kNone, kModerate, kCritical };
7034 
7042 class V8_EXPORT EmbedderHeapTracer {
7043  public:
7044  // Indicator for the stack state of the embedder.
7045  enum EmbedderStackState {
7046  kUnknown,
7047  kNonEmpty,
7048  kEmpty,
7049  };
7050 
7051  enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
7052 
7054  explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
7055  : force_completion(force_completion_) {}
7056 
7057  ForceCompletionAction force_completion;
7058  };
7059 
7060  virtual ~EmbedderHeapTracer() = default;
7061 
7068  virtual void RegisterV8References(
7069  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
7070 
7074  virtual void TracePrologue() = 0;
7075 
7089  V8_DEPRECATE_SOON("Use void AdvanceTracing(deadline_in_ms)",
7090  virtual bool AdvanceTracing(
7091  double deadline_in_ms, AdvanceTracingActions actions)) {
7092  return false;
7093  }
7094 
7108  virtual bool AdvanceTracing(double deadline_in_ms);
7109 
7110  /*
7111  * Returns true if there no more tracing work to be done (see AdvanceTracing)
7112  * and false otherwise.
7113  */
7114  virtual bool IsTracingDone();
7115 
7121  virtual void TraceEpilogue() = 0;
7122 
7130  V8_DEPRECATE_SOON("Use void EnterFinalPause(EmbedderStackState)",
7131  virtual void EnterFinalPause()) {}
7132  virtual void EnterFinalPause(EmbedderStackState stack_state);
7133 
7140  virtual void AbortTracing() = 0;
7141 
7142  /*
7143  * Called by the embedder to request immediate finalization of the currently
7144  * running tracing phase that has been started with TracePrologue and not
7145  * yet finished with TraceEpilogue.
7146  *
7147  * Will be a noop when currently not in tracing.
7148  *
7149  * This is an experimental feature.
7150  */
7151  void FinalizeTracing();
7152 
7153  /*
7154  * Called by the embedder to immediately perform a full garbage collection.
7155  *
7156  * Should only be used in testing code.
7157  */
7158  void GarbageCollectionForTesting(EmbedderStackState stack_state);
7159 
7160  /*
7161  * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
7162  * is not attached to any v8::Isolate.
7163  */
7164  v8::Isolate* isolate() const { return isolate_; }
7165 
7169  V8_DEPRECATE_SOON("Use IsTracingDone",
7170  virtual size_t NumberOfWrappersToTrace()) {
7171  return 0;
7172  }
7173 
7174  protected:
7175  v8::Isolate* isolate_ = nullptr;
7176 
7177  friend class internal::LocalEmbedderHeapTracer;
7178 };
7179 
7184 struct SerializeInternalFieldsCallback {
7185  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
7186  void* data);
7187  SerializeInternalFieldsCallback(CallbackFunction function = nullptr,
7188  void* data_arg = nullptr)
7189  : callback(function), data(data_arg) {}
7190  CallbackFunction callback;
7191  void* data;
7192 };
7193 // Note that these fields are called "internal fields" in the API and called
7194 // "embedder fields" within V8.
7195 typedef SerializeInternalFieldsCallback SerializeEmbedderFieldsCallback;
7196 
7201 struct DeserializeInternalFieldsCallback {
7202  typedef void (*CallbackFunction)(Local<Object> holder, int index,
7203  StartupData payload, void* data);
7204  DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
7205  void* data_arg = nullptr)
7206  : callback(function), data(data_arg) {}
7207  void (*callback)(Local<Object> holder, int index, StartupData payload,
7208  void* data);
7209  void* data;
7210 };
7211 typedef DeserializeInternalFieldsCallback DeserializeEmbedderFieldsCallback;
7212 
7221 class V8_EXPORT Isolate {
7222  public:
7226  struct CreateParams {
7227  CreateParams()
7228  : entry_hook(nullptr),
7229  code_event_handler(nullptr),
7230  snapshot_blob(nullptr),
7231  counter_lookup_callback(nullptr),
7232  create_histogram_callback(nullptr),
7233  add_histogram_sample_callback(nullptr),
7234  array_buffer_allocator(nullptr),
7235  external_references(nullptr),
7236  allow_atomics_wait(true),
7237  only_terminate_in_safe_scope(false) {}
7238 
7247  FunctionEntryHook entry_hook;
7248 
7253  JitCodeEventHandler code_event_handler;
7254 
7258  ResourceConstraints constraints;
7259 
7263  StartupData* snapshot_blob;
7264 
7265 
7270  CounterLookupCallback counter_lookup_callback;
7271 
7278  CreateHistogramCallback create_histogram_callback;
7279  AddHistogramSampleCallback add_histogram_sample_callback;
7280 
7286 
7293  const intptr_t* external_references;
7294 
7300 
7305  };
7306 
7307 
7312  class V8_EXPORT Scope {
7313  public:
7314  explicit Scope(Isolate* isolate) : isolate_(isolate) {
7315  isolate->Enter();
7316  }
7317 
7318  ~Scope() { isolate_->Exit(); }
7319 
7320  // Prevent copying of Scope objects.
7321  Scope(const Scope&) = delete;
7322  Scope& operator=(const Scope&) = delete;
7323 
7324  private:
7325  Isolate* const isolate_;
7326  };
7327 
7328 
7333  public:
7334  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
7335 
7336  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
7338 
7339  // Prevent copying of Scope objects.
7341  delete;
7343  const DisallowJavascriptExecutionScope&) = delete;
7344 
7345  private:
7346  bool on_failure_;
7347  void* internal_;
7348  };
7349 
7350 
7355  public:
7356  explicit AllowJavascriptExecutionScope(Isolate* isolate);
7358 
7359  // Prevent copying of Scope objects.
7361  delete;
7362  AllowJavascriptExecutionScope& operator=(
7363  const AllowJavascriptExecutionScope&) = delete;
7364 
7365  private:
7366  void* internal_throws_;
7367  void* internal_assert_;
7368  };
7369 
7375  public:
7376  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7378 
7379  // Prevent copying of Scope objects.
7381  delete;
7383  const SuppressMicrotaskExecutionScope&) = delete;
7384 
7385  private:
7386  internal::Isolate* const isolate_;
7387  };
7388 
7393  class V8_EXPORT SafeForTerminationScope {
7394  public:
7395  explicit SafeForTerminationScope(v8::Isolate* isolate);
7397 
7398  // Prevent copying of Scope objects.
7400  SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
7401 
7402  private:
7403  internal::Isolate* isolate_;
7404  bool prev_value_;
7405  };
7406 
7411  enum GarbageCollectionType {
7412  kFullGarbageCollection,
7413  kMinorGarbageCollection
7414  };
7415 
7421  enum UseCounterFeature {
7422  kUseAsm = 0,
7423  kBreakIterator = 1,
7424  kLegacyConst = 2,
7425  kMarkDequeOverflow = 3,
7426  kStoreBufferOverflow = 4,
7427  kSlotsBufferOverflow = 5,
7428  kObjectObserve = 6,
7429  kForcedGC = 7,
7430  kSloppyMode = 8,
7431  kStrictMode = 9,
7432  kStrongMode = 10,
7433  kRegExpPrototypeStickyGetter = 11,
7434  kRegExpPrototypeToString = 12,
7435  kRegExpPrototypeUnicodeGetter = 13,
7436  kIntlV8Parse = 14,
7437  kIntlPattern = 15,
7438  kIntlResolved = 16,
7439  kPromiseChain = 17,
7440  kPromiseAccept = 18,
7441  kPromiseDefer = 19,
7442  kHtmlCommentInExternalScript = 20,
7443  kHtmlComment = 21,
7444  kSloppyModeBlockScopedFunctionRedefinition = 22,
7445  kForInInitializer = 23,
7446  kArrayProtectorDirtied = 24,
7447  kArraySpeciesModified = 25,
7448  kArrayPrototypeConstructorModified = 26,
7449  kArrayInstanceProtoModified = 27,
7450  kArrayInstanceConstructorModified = 28,
7451  kLegacyFunctionDeclaration = 29,
7452  kRegExpPrototypeSourceGetter = 30,
7453  kRegExpPrototypeOldFlagGetter = 31,
7454  kDecimalWithLeadingZeroInStrictMode = 32,
7455  kLegacyDateParser = 33,
7456  kDefineGetterOrSetterWouldThrow = 34,
7457  kFunctionConstructorReturnedUndefined = 35,
7458  kAssigmentExpressionLHSIsCallInSloppy = 36,
7459  kAssigmentExpressionLHSIsCallInStrict = 37,
7460  kPromiseConstructorReturnedUndefined = 38,
7461  kConstructorNonUndefinedPrimitiveReturn = 39,
7462  kLabeledExpressionStatement = 40,
7463  kLineOrParagraphSeparatorAsLineTerminator = 41,
7464  kIndexAccessor = 42,
7465  kErrorCaptureStackTrace = 43,
7466  kErrorPrepareStackTrace = 44,
7467  kErrorStackTraceLimit = 45,
7468  kWebAssemblyInstantiation = 46,
7469  kDeoptimizerDisableSpeculation = 47,
7470  kArrayPrototypeSortJSArrayModifiedPrototype = 48,
7471  kFunctionTokenOffsetTooLongForToString = 49,
7472  kWasmSharedMemory = 50,
7473  kWasmThreadOpcodes = 51,
7474 
7475  // If you add new values here, you'll also need to update Chromium's:
7476  // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to
7477  // this list need to be landed first, then changes on the Chromium side.
7478  kUseCounterFeatureCount // This enum value must be last.
7479  };
7480 
7481  enum MessageErrorLevel {
7482  kMessageLog = (1 << 0),
7483  kMessageDebug = (1 << 1),
7484  kMessageInfo = (1 << 2),
7485  kMessageError = (1 << 3),
7486  kMessageWarning = (1 << 4),
7487  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7488  kMessageWarning,
7489  };
7490 
7491  typedef void (*UseCounterCallback)(Isolate* isolate,
7492  UseCounterFeature feature);
7493 
7508  static Isolate* Allocate();
7509 
7513  static void Initialize(Isolate* isolate, const CreateParams& params);
7514 
7524  static Isolate* New(const CreateParams& params);
7525 
7532  static Isolate* GetCurrent();
7533 
7543  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7544  void SetAbortOnUncaughtExceptionCallback(
7545  AbortOnUncaughtExceptionCallback callback);
7546 
7551  void SetHostImportModuleDynamicallyCallback(
7552  HostImportModuleDynamicallyCallback callback);
7553 
7558  void SetHostInitializeImportMetaObjectCallback(
7559  HostInitializeImportMetaObjectCallback callback);
7560 
7567  void MemoryPressureNotification(MemoryPressureLevel level);
7568 
7579  void Enter();
7580 
7588  void Exit();
7589 
7594  void Dispose();
7595 
7600  void DumpAndResetStats();
7601 
7609  void DiscardThreadSpecificMetadata();
7610 
7615  V8_INLINE void SetData(uint32_t slot, void* data);
7616 
7621  V8_INLINE void* GetData(uint32_t slot);
7622 
7627  V8_INLINE static uint32_t GetNumberOfDataSlots();
7628 
7634  template <class T>
7635  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
7636 
7640  void GetHeapStatistics(HeapStatistics* heap_statistics);
7641 
7645  size_t NumberOfHeapSpaces();
7646 
7656  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7657  size_t index);
7658 
7662  size_t NumberOfTrackedHeapObjectTypes();
7663 
7673  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7674  size_t type_index);
7675 
7683  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7684 
7697  void GetStackSample(const RegisterState& state, void** frames,
7698  size_t frames_limit, SampleInfo* sample_info);
7699 
7713  V8_INLINE int64_t
7714  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7715 
7720  size_t NumberOfPhantomHandleResetsSinceLastCall();
7721 
7726  HeapProfiler* GetHeapProfiler();
7727 
7731  void SetIdle(bool is_idle);
7732 
7734  bool InContext();
7735 
7740  Local<Context> GetCurrentContext();
7741 
7743  Local<Context> GetEnteredContext();
7744 
7751  Local<Context> GetEnteredOrMicrotaskContext();
7752 
7757  Local<Context> GetIncumbentContext();
7758 
7765  Local<Value> ThrowException(Local<Value> exception);
7766 
7767  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7768  GCCallbackFlags flags);
7769  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7770  GCCallbackFlags flags, void* data);
7771 
7781  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
7782  GCType gc_type_filter = kGCTypeAll);
7783  void AddGCPrologueCallback(GCCallback callback,
7784  GCType gc_type_filter = kGCTypeAll);
7785 
7790  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
7791  void RemoveGCPrologueCallback(GCCallback callback);
7792 
7796  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7797 
7801  enum class AtomicsWaitEvent {
7803  kStartWait,
7805  kWokenUp,
7807  kTimedOut,
7809  kTerminatedExecution,
7811  kAPIStopped,
7813  kNotEqual
7814  };
7815 
7820  class V8_EXPORT AtomicsWaitWakeHandle {
7821  public:
7836  void Wake();
7837  };
7838 
7862  typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event,
7863  Local<SharedArrayBuffer> array_buffer,
7864  size_t offset_in_bytes, int32_t value,
7865  double timeout_in_ms,
7866  AtomicsWaitWakeHandle* stop_handle,
7867  void* data);
7868 
7875  void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
7876 
7886  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
7887  GCType gc_type_filter = kGCTypeAll);
7888  void AddGCEpilogueCallback(GCCallback callback,
7889  GCType gc_type_filter = kGCTypeAll);
7890 
7895  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
7896  void* data = nullptr);
7897  void RemoveGCEpilogueCallback(GCCallback callback);
7898 
7899  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7900 
7907  void SetGetExternallyAllocatedMemoryInBytesCallback(
7908  GetExternallyAllocatedMemoryInBytesCallback callback);
7909 
7917  void TerminateExecution();
7918 
7927  bool IsExecutionTerminating();
7928 
7943  void CancelTerminateExecution();
7944 
7953  void RequestInterrupt(InterruptCallback callback, void* data);
7954 
7965  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
7966 
7970  void SetEventLogger(LogEventCallback that);
7971 
7978  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7979 
7983  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7984 
7992  void AddCallCompletedCallback(CallCompletedCallback callback);
7993 
7997  void RemoveCallCompletedCallback(CallCompletedCallback callback);
7998 
8003  void SetPromiseHook(PromiseHook hook);
8004 
8009  void SetPromiseRejectCallback(PromiseRejectCallback callback);
8010 
8015  void RunMicrotasks();
8016 
8020  void EnqueueMicrotask(Local<Function> microtask);
8021 
8025  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
8026 
8030  void SetMicrotasksPolicy(MicrotasksPolicy policy);
8031 
8035  MicrotasksPolicy GetMicrotasksPolicy() const;
8036 
8049  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8050 
8054  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8055 
8059  void SetUseCounterCallback(UseCounterCallback callback);
8060 
8065  void SetCounterFunction(CounterLookupCallback);
8066 
8073  void SetCreateHistogramFunction(CreateHistogramCallback);
8074  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
8075 
8090  bool IdleNotificationDeadline(double deadline_in_seconds);
8091 
8096  void LowMemoryNotification();
8097 
8107  int ContextDisposedNotification(bool dependant_context = true);
8108 
8113  void IsolateInForegroundNotification();
8114 
8119  void IsolateInBackgroundNotification();
8120 
8126  void EnableMemorySavingsMode();
8127 
8131  void DisableMemorySavingsMode();
8132 
8140  void SetRAILMode(RAILMode rail_mode);
8141 
8146  void IncreaseHeapLimitForDebugging();
8147 
8151  void RestoreOriginalHeapLimit();
8152 
8157  bool IsHeapLimitIncreasedForDebugging();
8158 
8181  void SetJitCodeEventHandler(JitCodeEventOptions options,
8182  JitCodeEventHandler event_handler);
8183 
8193  void SetStackLimit(uintptr_t stack_limit);
8194 
8208  void GetCodeRange(void** start, size_t* length_in_bytes);
8209 
8211  void SetFatalErrorHandler(FatalErrorCallback that);
8212 
8214  void SetOOMErrorHandler(OOMErrorCallback that);
8215 
8221  void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
8222 
8230  void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
8231  size_t heap_limit);
8232 
8237  void SetAllowCodeGenerationFromStringsCallback(
8238  AllowCodeGenerationFromStringsCallback callback);
8239 
8244  void SetAllowWasmCodeGenerationCallback(
8245  AllowWasmCodeGenerationCallback callback);
8246 
8251  void SetWasmModuleCallback(ExtensionCallback callback);
8252  void SetWasmInstanceCallback(ExtensionCallback callback);
8253 
8254  void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
8255 
8256  void SetWasmStreamingCallback(WasmStreamingCallback callback);
8257 
8258  void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback);
8259 
8264  bool IsDead();
8265 
8275  bool AddMessageListener(MessageCallback that,
8276  Local<Value> data = Local<Value>());
8277 
8289  bool AddMessageListenerWithErrorLevel(MessageCallback that,
8290  int message_levels,
8291  Local<Value> data = Local<Value>());
8292 
8296  void RemoveMessageListeners(MessageCallback that);
8297 
8299  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
8300 
8305  void SetCaptureStackTraceForUncaughtExceptions(
8306  bool capture, int frame_limit = 10,
8307  StackTrace::StackTraceOptions options = StackTrace::kOverview);
8308 
8314  void VisitExternalResources(ExternalResourceVisitor* visitor);
8315 
8320  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
8321 
8329  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
8330 
8336  void VisitWeakHandles(PersistentHandleVisitor* visitor);
8337 
8342  bool IsInUse();
8343 
8349  void SetAllowAtomicsWait(bool allow);
8350 
8351  Isolate() = delete;
8352  ~Isolate() = delete;
8353  Isolate(const Isolate&) = delete;
8354  Isolate& operator=(const Isolate&) = delete;
8355  // Deleting operator new and delete here is allowed as ctor and dtor is also
8356  // deleted.
8357  void* operator new(size_t size) = delete;
8358  void* operator new[](size_t size) = delete;
8359  void operator delete(void*, size_t) = delete;
8360  void operator delete[](void*, size_t) = delete;
8361 
8362  private:
8363  template <class K, class V, class Traits>
8364  friend class PersistentValueMapBase;
8365 
8366  internal::Object** GetDataFromSnapshotOnce(size_t index);
8367  void ReportExternalAllocationLimitReached();
8368  void CheckMemoryPressure();
8369 };
8370 
8371 class V8_EXPORT StartupData {
8372  public:
8373  const char* data;
8374  int raw_size;
8375 };
8376 
8377 
8382 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
8383 
8397 typedef uintptr_t (*ReturnAddressLocationResolver)(
8398  uintptr_t return_addr_location);
8399 
8400 
8404 class V8_EXPORT V8 {
8405  public:
8421  static void SetNativesDataBlob(StartupData* startup_blob);
8422  static void SetSnapshotDataBlob(StartupData* startup_blob);
8423 
8425  static void SetDcheckErrorHandler(DcheckErrorCallback that);
8426 
8427 
8431  static void SetFlagsFromString(const char* str, int length);
8432 
8436  static void SetFlagsFromCommandLine(int* argc,
8437  char** argv,
8438  bool remove_flags);
8439 
8441  static const char* GetVersion();
8442 
8447  static bool Initialize();
8448 
8453  static void SetEntropySource(EntropySource source);
8454 
8459  static void SetReturnAddressLocationResolver(
8460  ReturnAddressLocationResolver return_address_resolver);
8461 
8471  static bool Dispose();
8472 
8480  static bool InitializeICU(const char* icu_data_file = nullptr);
8481 
8494  static bool InitializeICUDefaultLocation(const char* exec_path,
8495  const char* icu_data_file = nullptr);
8496 
8513  static void InitializeExternalStartupData(const char* directory_path);
8514  static void InitializeExternalStartupData(const char* natives_blob,
8515  const char* snapshot_blob);
8520  static void InitializePlatform(Platform* platform);
8521 
8526  static void ShutdownPlatform();
8527 
8528 #if V8_OS_POSIX
8529 
8548  static bool TryHandleSignal(int signal_number, void* info, void* context);
8549 #endif // V8_OS_POSIX
8550 
8555  V8_DEPRECATE_SOON("Use EnableWebAssemblyTrapHandler",
8556  static bool RegisterDefaultSignalHandler());
8557 
8564  static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
8565 
8566  private:
8567  V8();
8568 
8569  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
8570  internal::Object** handle);
8571  static internal::Object** CopyPersistent(internal::Object** handle);
8572  static void DisposeGlobal(internal::Object** global_handle);
8573  static void MakeWeak(internal::Object** location, void* data,
8574  WeakCallbackInfo<void>::Callback weak_callback,
8575  WeakCallbackType type);
8576  static void MakeWeak(internal::Object** location, void* data,
8577  // Must be 0 or -1.
8578  int internal_field_index1,
8579  // Must be 1 or -1.
8580  int internal_field_index2,
8581  WeakCallbackInfo<void>::Callback weak_callback);
8582  static void MakeWeak(internal::Object*** location_addr);
8583  static void* ClearWeak(internal::Object** location);
8584  static void AnnotateStrongRetainer(internal::Object** location,
8585  const char* label);
8586  static Value* Eternalize(Isolate* isolate, Value* handle);
8587 
8588  static void RegisterExternallyReferencedObject(internal::Object** object,
8589  internal::Isolate* isolate);
8590 
8591  template <class K, class V, class T>
8592  friend class PersistentValueMapBase;
8593 
8594  static void FromJustIsNothing();
8595  static void ToLocalEmpty();
8596  static void InternalFieldOutOfBounds(int index);
8597  template <class T> friend class Local;
8598  template <class T>
8599  friend class MaybeLocal;
8600  template <class T>
8601  friend class Maybe;
8602  template <class T>
8603  friend class WeakCallbackInfo;
8604  template <class T> friend class Eternal;
8605  template <class T> friend class PersistentBase;
8606  template <class T, class M> friend class Persistent;
8607  friend class Context;
8608 };
8609 
8613 class V8_EXPORT SnapshotCreator {
8614  public:
8615  enum class FunctionCodeHandling { kClear, kKeep };
8616 
8625  SnapshotCreator(Isolate* isolate,
8626  const intptr_t* external_references = nullptr,
8627  StartupData* existing_blob = nullptr);
8628 
8637  SnapshotCreator(const intptr_t* external_references = nullptr,
8638  StartupData* existing_blob = nullptr);
8639 
8640  ~SnapshotCreator();
8641 
8645  Isolate* GetIsolate();
8646 
8654  void SetDefaultContext(Local<Context> context,
8655  SerializeInternalFieldsCallback callback =
8656  SerializeInternalFieldsCallback());
8657 
8666  size_t AddContext(Local<Context> context,
8667  SerializeInternalFieldsCallback callback =
8668  SerializeInternalFieldsCallback());
8669 
8674  size_t AddTemplate(Local<Template> template_obj);
8675 
8682  template <class T>
8683  V8_INLINE size_t AddData(Local<Context> context, Local<T> object);
8684 
8691  template <class T>
8692  V8_INLINE size_t AddData(Local<T> object);
8693 
8702  StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8703 
8704  // Disallow copying and assigning.
8705  SnapshotCreator(const SnapshotCreator&) = delete;
8706  void operator=(const SnapshotCreator&) = delete;
8707 
8708  private:
8709  size_t AddData(Local<Context> context, internal::Object* object);
8710  size_t AddData(internal::Object* object);
8711 
8712  void* data_;
8713 };
8714 
8725 template <class T>
8726 class Maybe {
8727  public:
8728  V8_INLINE bool IsNothing() const { return !has_value_; }
8729  V8_INLINE bool IsJust() const { return has_value_; }
8730 
8734  V8_INLINE T ToChecked() const { return FromJust(); }
8735 
8740  V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
8741  if (V8_LIKELY(IsJust())) *out = value_;
8742  return IsJust();
8743  }
8744 
8749  V8_INLINE T FromJust() const {
8750  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8751  return value_;
8752  }
8753 
8758  V8_INLINE T FromMaybe(const T& default_value) const {
8759  return has_value_ ? value_ : default_value;
8760  }
8761 
8762  V8_INLINE bool operator==(const Maybe& other) const {
8763  return (IsJust() == other.IsJust()) &&
8764  (!IsJust() || FromJust() == other.FromJust());
8765  }
8766 
8767  V8_INLINE bool operator!=(const Maybe& other) const {
8768  return !operator==(other);
8769  }
8770 
8771  private:
8772  Maybe() : has_value_(false) {}
8773  explicit Maybe(const T& t) : has_value_(true), value_(t) {}
8774 
8775  bool has_value_;
8776  T value_;
8777 
8778  template <class U>
8779  friend Maybe<U> Nothing();
8780  template <class U>
8781  friend Maybe<U> Just(const U& u);
8782 };
8783 
8784 template <class T>
8785 inline Maybe<T> Nothing() {
8786  return Maybe<T>();
8787 }
8788 
8789 template <class T>
8790 inline Maybe<T> Just(const T& t) {
8791  return Maybe<T>(t);
8792 }
8793 
8794 // A template specialization of Maybe<T> for the case of T = void.
8795 template <>
8796 class Maybe<void> {
8797  public:
8798  V8_INLINE bool IsNothing() const { return !is_valid_; }
8799  V8_INLINE bool IsJust() const { return is_valid_; }
8800 
8801  V8_INLINE bool operator==(const Maybe& other) const {
8802  return IsJust() == other.IsJust();
8803  }
8804 
8805  V8_INLINE bool operator!=(const Maybe& other) const {
8806  return !operator==(other);
8807  }
8808 
8809  private:
8810  struct JustTag {};
8811 
8812  Maybe() : is_valid_(false) {}
8813  explicit Maybe(JustTag) : is_valid_(true) {}
8814 
8815  bool is_valid_;
8816 
8817  template <class U>
8818  friend Maybe<U> Nothing();
8819  friend Maybe<void> JustVoid();
8820 };
8821 
8822 inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); }
8823 
8827 class V8_EXPORT TryCatch {
8828  public:
8834  explicit TryCatch(Isolate* isolate);
8835 
8839  ~TryCatch();
8840 
8844  bool HasCaught() const;
8845 
8854  bool CanContinue() const;
8855 
8868  bool HasTerminated() const;
8869 
8877  Local<Value> ReThrow();
8878 
8885  Local<Value> Exception() const;
8886 
8891  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
8892  Local<Context> context) const;
8893 
8901  Local<v8::Message> Message() const;
8902 
8913  void Reset();
8914 
8923  void SetVerbose(bool value);
8924 
8928  bool IsVerbose() const;
8929 
8935  void SetCaptureMessage(bool value);
8936 
8948  static void* JSStackComparableAddress(TryCatch* handler) {
8949  if (handler == NULL) return NULL;
8950  return handler->js_stack_comparable_address_;
8951  }
8952 
8953  TryCatch(const TryCatch&) = delete;
8954  void operator=(const TryCatch&) = delete;
8955 
8956  private:
8957  // Declaring operator new and delete as deleted is not spec compliant.
8958  // Therefore declare them private instead to disable dynamic alloc
8959  void* operator new(size_t size);
8960  void* operator new[](size_t size);
8961  void operator delete(void*, size_t);
8962  void operator delete[](void*, size_t);
8963 
8964  void ResetInternal();
8965 
8966  internal::Isolate* isolate_;
8967  TryCatch* next_;
8968  void* exception_;
8969  void* message_obj_;
8970  void* js_stack_comparable_address_;
8971  bool is_verbose_ : 1;
8972  bool can_continue_ : 1;
8973  bool capture_message_ : 1;
8974  bool rethrow_ : 1;
8975  bool has_terminated_ : 1;
8976 
8977  friend class internal::Isolate;
8978 };
8979 
8980 
8981 // --- Context ---
8982 
8983 
8987 class V8_EXPORT ExtensionConfiguration {
8988  public:
8989  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
8990  ExtensionConfiguration(int name_count, const char* names[])
8991  : name_count_(name_count), names_(names) { }
8992 
8993  const char** begin() const { return &names_[0]; }
8994  const char** end() const { return &names_[name_count_]; }
8995 
8996  private:
8997  const int name_count_;
8998  const char** names_;
8999 };
9000 
9005 class V8_EXPORT Context {
9006  public:
9019  Local<Object> Global();
9020 
9025  void DetachGlobal();
9026 
9045  static Local<Context> New(
9046  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
9047  MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(),
9048  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
9049  DeserializeInternalFieldsCallback internal_fields_deserializer =
9050  DeserializeInternalFieldsCallback());
9051 
9071  static MaybeLocal<Context> FromSnapshot(
9072  Isolate* isolate, size_t context_snapshot_index,
9073  DeserializeInternalFieldsCallback embedder_fields_deserializer =
9074  DeserializeInternalFieldsCallback(),
9075  ExtensionConfiguration* extensions = nullptr,
9076  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9077 
9095  static MaybeLocal<Object> NewRemoteContext(
9096  Isolate* isolate, Local<ObjectTemplate> global_template,
9097  MaybeLocal<Value> global_object = MaybeLocal<Value>());
9098 
9103  void SetSecurityToken(Local<Value> token);
9104 
9106  void UseDefaultSecurityToken();
9107 
9109  Local<Value> GetSecurityToken();
9110 
9117  void Enter();
9118 
9123  void Exit();
9124 
9126  Isolate* GetIsolate();
9127 
9132  enum EmbedderDataFields { kDebugIdIndex = 0 };
9133 
9137  uint32_t GetNumberOfEmbedderDataFields();
9138 
9143  V8_INLINE Local<Value> GetEmbedderData(int index);
9144 
9151  Local<Object> GetExtrasBindingObject();
9152 
9158  void SetEmbedderData(int index, Local<Value> value);
9159 
9166  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
9167 
9173  void SetAlignedPointerInEmbedderData(int index, void* value);
9174 
9188  void AllowCodeGenerationFromStrings(bool allow);
9189 
9194  bool IsCodeGenerationFromStringsAllowed();
9195 
9201  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
9202 
9208  template <class T>
9209  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
9210 
9215  class Scope {
9216  public:
9217  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
9218  context_->Enter();
9219  }
9220  V8_INLINE ~Scope() { context_->Exit(); }
9221 
9222  private:
9223  Local<Context> context_;
9224  };
9225 
9231  class V8_EXPORT BackupIncumbentScope {
9232  public:
9237  explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
9239 
9240  private:
9241  friend class internal::Isolate;
9242 
9243  Local<Context> backup_incumbent_context_;
9244  const BackupIncumbentScope* prev_ = nullptr;
9245  };
9246 
9247  private:
9248  friend class Value;
9249  friend class Script;
9250  friend class Object;
9251  friend class Function;
9252 
9253  internal::Object** GetDataFromSnapshotOnce(size_t index);
9254  Local<Value> SlowGetEmbedderData(int index);
9255  void* SlowGetAlignedPointerFromEmbedderData(int index);
9256 };
9257 
9258 
9335 class V8_EXPORT Unlocker {
9336  public:
9340  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
9341 
9342  ~Unlocker();
9343  private:
9344  void Initialize(Isolate* isolate);
9345 
9346  internal::Isolate* isolate_;
9347 };
9348 
9349 
9350 class V8_EXPORT Locker {
9351  public:
9355  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
9356 
9357  ~Locker();
9358 
9363  static bool IsLocked(Isolate* isolate);
9364 
9368  static bool IsActive();
9369 
9370  // Disallow copying and assigning.
9371  Locker(const Locker&) = delete;
9372  void operator=(const Locker&) = delete;
9373 
9374  private:
9375  void Initialize(Isolate* isolate);
9376 
9377  bool has_lock_;
9378  bool top_level_;
9379  internal::Isolate* isolate_;
9380 };
9381 
9382 
9383 // --- Implementation ---
9384 
9385 
9386 namespace internal {
9387 
9393 class Internals {
9394  public:
9395  // These values match non-compiler-dependent values defined within
9396  // the implementation of v8.
9397  static const int kHeapObjectMapOffset = 0;
9398  static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
9399  static const int kStringResourceOffset = 3 * kApiPointerSize;
9400 
9401  static const int kOddballKindOffset = 4 * kApiPointerSize + kApiDoubleSize;
9402  static const int kForeignAddressOffset = kApiPointerSize;
9403  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
9404  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
9405  static const int kContextHeaderSize = 2 * kApiPointerSize;
9406  static const int kContextEmbedderDataIndex = 5;
9407  static const int kFullStringRepresentationMask = 0x0f;
9408  static const int kStringEncodingMask = 0x8;
9409  static const int kExternalTwoByteRepresentationTag = 0x02;
9410  static const int kExternalOneByteRepresentationTag = 0x0a;
9411 
9412  static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
9413  static const int kExternalMemoryOffset = 4 * kApiPointerSize;
9414  static const int kExternalMemoryLimitOffset =
9415  kExternalMemoryOffset + kApiInt64Size;
9416  static const int kExternalMemoryAtLastMarkCompactOffset =
9417  kExternalMemoryLimitOffset + kApiInt64Size;
9418  static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
9419  kApiInt64Size + kApiInt64Size +
9420  kApiPointerSize + kApiPointerSize;
9421  static const int kUndefinedValueRootIndex = 4;
9422  static const int kTheHoleValueRootIndex = 5;
9423  static const int kNullValueRootIndex = 6;
9424  static const int kTrueValueRootIndex = 7;
9425  static const int kFalseValueRootIndex = 8;
9426  static const int kEmptyStringRootIndex = 9;
9427 
9428  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
9429  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
9430  static const int kNodeStateMask = 0x7;
9431  static const int kNodeStateIsWeakValue = 2;
9432  static const int kNodeStateIsPendingValue = 3;
9433  static const int kNodeStateIsNearDeathValue = 4;
9434  static const int kNodeIsIndependentShift = 3;
9435  static const int kNodeIsActiveShift = 4;
9436 
9437  static const int kFirstNonstringType = 0x80;
9438  static const int kOddballType = 0x83;
9439  static const int kForeignType = 0x87;
9440  static const int kJSSpecialApiObjectType = 0x410;
9441  static const int kJSApiObjectType = 0x420;
9442  static const int kJSObjectType = 0x421;
9443 
9444  static const int kUndefinedOddballKind = 5;
9445  static const int kNullOddballKind = 3;
9446 
9447  static const uint32_t kNumIsolateDataSlots = 4;
9448 
9449  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
9450  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
9451 #ifdef V8_ENABLE_CHECKS
9452  CheckInitializedImpl(isolate);
9453 #endif
9454  }
9455 
9456  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
9457  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
9458  kHeapObjectTag);
9459  }
9460 
9461  V8_INLINE static int SmiValue(const internal::Object* value) {
9462  return PlatformSmiTagging::SmiToInt(value);
9463  }
9464 
9465  V8_INLINE static internal::Object* IntToSmi(int value) {
9466  return PlatformSmiTagging::IntToSmi(value);
9467  }
9468 
9469  V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
9470  return PlatformSmiTagging::IsValidSmi(value);
9471  }
9472 
9473  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
9474  typedef internal::Object O;
9475  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
9476  return ReadField<uint16_t>(map, kMapInstanceTypeOffset);
9477  }
9478 
9479  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
9480  typedef internal::Object O;
9481  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
9482  }
9483 
9484  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
9485  int representation = (instance_type & kFullStringRepresentationMask);
9486  return representation == kExternalTwoByteRepresentationTag;
9487  }
9488 
9489  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
9490  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9491  return *addr & static_cast<uint8_t>(1U << shift);
9492  }
9493 
9494  V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
9495  bool value, int shift) {
9496  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9497  uint8_t mask = static_cast<uint8_t>(1U << shift);
9498  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
9499  }
9500 
9501  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
9502  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9503  return *addr & kNodeStateMask;
9504  }
9505 
9506  V8_INLINE static void UpdateNodeState(internal::Object** obj,
9507  uint8_t value) {
9508  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9509  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
9510  }
9511 
9512  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
9513  uint32_t slot,
9514  void* data) {
9515  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
9516  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
9517  *reinterpret_cast<void**>(addr) = data;
9518  }
9519 
9520  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
9521  uint32_t slot) {
9522  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
9523  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
9524  return *reinterpret_cast<void* const*>(addr);
9525  }
9526 
9527  V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
9528  int index) {
9529  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
9530  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
9531  }
9532 
9533  template <typename T>
9534  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
9535  const uint8_t* addr =
9536  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
9537  return *reinterpret_cast<const T*>(addr);
9538  }
9539 
9540  template <typename T>
9541  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
9542  typedef internal::Object O;
9543  typedef internal::Internals I;
9544  O* ctx = *reinterpret_cast<O* const*>(context);
9545  int embedder_data_offset = I::kContextHeaderSize +
9546  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
9547  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
9548  int value_offset =
9549  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
9550  return I::ReadField<T>(embedder_data, value_offset);
9551  }
9552 };
9553 
9554 // Only perform cast check for types derived from v8::Data since
9555 // other types do not implement the Cast method.
9556 template <bool PerformCheck>
9557 struct CastCheck {
9558  template <class T>
9559  static void Perform(T* data);
9560 };
9561 
9562 template <>
9563 template <class T>
9564 void CastCheck<true>::Perform(T* data) {
9565  T::Cast(data);
9566 }
9567 
9568 template <>
9569 template <class T>
9570 void CastCheck<false>::Perform(T* data) {}
9571 
9572 template <class T>
9573 V8_INLINE void PerformCastCheck(T* data) {
9574  CastCheck<std::is_base_of<Data, T>::value>::Perform(data);
9575 }
9576 
9577 } // namespace internal
9578 
9579 
9580 template <class T>
9581 Local<T> Local<T>::New(Isolate* isolate, Local<T> that) {
9582  return New(isolate, that.val_);
9583 }
9584 
9585 template <class T>
9586 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
9587  return New(isolate, that.val_);
9588 }
9589 
9590 
9591 template <class T>
9592 Local<T> Local<T>::New(Isolate* isolate, T* that) {
9593  if (that == NULL) return Local<T>();
9594  T* that_ptr = that;
9595  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
9596  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
9597  reinterpret_cast<internal::Isolate*>(isolate), *p)));
9598 }
9599 
9600 
9601 template<class T>
9602 template<class S>
9603 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
9604  TYPE_CHECK(T, S);
9605  val_ = reinterpret_cast<T*>(
9606  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
9607 }
9608 
9609 template <class T>
9610 Local<T> Eternal<T>::Get(Isolate* isolate) const {
9611  // The eternal handle will never go away, so as with the roots, we don't even
9612  // need to open a handle.
9613  return Local<T>(val_);
9614 }
9615 
9616 
9617 template <class T>
9619  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
9620  return Local<T>(val_);
9621 }
9622 
9623 
9624 template <class T>
9625 void* WeakCallbackInfo<T>::GetInternalField(int index) const {
9626 #ifdef V8_ENABLE_CHECKS
9627  if (index < 0 || index >= kEmbedderFieldsInWeakCallback) {
9628  V8::InternalFieldOutOfBounds(index);
9629  }
9630 #endif
9631  return embedder_fields_[index];
9632 }
9633 
9634 
9635 template <class T>
9636 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
9637  if (that == NULL) return NULL;
9638  internal::Object** p = reinterpret_cast<internal::Object**>(that);
9639  return reinterpret_cast<T*>(
9640  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
9641  p));
9642 }
9643 
9644 
9645 template <class T, class M>
9646 template <class S, class M2>
9647 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
9648  TYPE_CHECK(T, S);
9649  this->Reset();
9650  if (that.IsEmpty()) return;
9651  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
9652  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
9653  M::Copy(that, this);
9654 }
9655 
9656 template <class T>
9657 bool PersistentBase<T>::IsIndependent() const {
9658  typedef internal::Internals I;
9659  if (this->IsEmpty()) return false;
9660  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
9661  I::kNodeIsIndependentShift);
9662 }
9663 
9664 template <class T>
9666  typedef internal::Internals I;
9667  if (this->IsEmpty()) return false;
9668  uint8_t node_state =
9669  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
9670  return node_state == I::kNodeStateIsNearDeathValue ||
9671  node_state == I::kNodeStateIsPendingValue;
9672 }
9673 
9674 
9675 template <class T>
9677  typedef internal::Internals I;
9678  if (this->IsEmpty()) return false;
9679  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
9680  I::kNodeStateIsWeakValue;
9681 }
9682 
9683 
9684 template <class T>
9686  if (this->IsEmpty()) return;
9687  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
9688  val_ = 0;
9689 }
9690 
9691 
9692 template <class T>
9693 template <class S>
9694 void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
9695  TYPE_CHECK(T, S);
9696  Reset();
9697  if (other.IsEmpty()) return;
9698  this->val_ = New(isolate, other.val_);
9699 }
9700 
9701 
9702 template <class T>
9703 template <class S>
9704 void PersistentBase<T>::Reset(Isolate* isolate,
9705  const PersistentBase<S>& other) {
9706  TYPE_CHECK(T, S);
9707  Reset();
9708  if (other.IsEmpty()) return;
9709  this->val_ = New(isolate, other.val_);
9710 }
9711 
9712 
9713 template <class T>
9714 template <typename P>
9716  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
9717  WeakCallbackType type) {
9718  typedef typename WeakCallbackInfo<void>::Callback Callback;
9719  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
9720  reinterpret_cast<Callback>(callback), type);
9721 }
9722 
9723 template <class T>
9725  V8::MakeWeak(reinterpret_cast<internal::Object***>(&this->val_));
9726 }
9727 
9728 template <class T>
9729 template <typename P>
9731  return reinterpret_cast<P*>(
9732  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
9733 }
9734 
9735 template <class T>
9737  V8::AnnotateStrongRetainer(reinterpret_cast<internal::Object**>(this->val_),
9738  label);
9739 }
9740 
9741 template <class T>
9742 void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
9743  if (IsEmpty()) return;
9744  V8::RegisterExternallyReferencedObject(
9745  reinterpret_cast<internal::Object**>(this->val_),
9746  reinterpret_cast<internal::Isolate*>(isolate));
9747 }
9748 
9749 template <class T>
9751  typedef internal::Internals I;
9752  if (this->IsEmpty()) return;
9753  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
9754  I::kNodeIsIndependentShift);
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::kNodeIsActiveShift);
9763 }
9764 
9765 
9766 template <class T>
9767 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
9768  typedef internal::Internals I;
9769  if (this->IsEmpty()) return;
9770  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
9771  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9772  *reinterpret_cast<uint16_t*>(addr) = class_id;
9773 }
9774 
9775 
9776 template <class T>
9778  typedef internal::Internals I;
9779  if (this->IsEmpty()) return 0;
9780  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
9781  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9782  return *reinterpret_cast<uint16_t*>(addr);
9783 }
9784 
9785 
9786 template<typename T>
9787 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
9788 
9789 template<typename T>
9790 template<typename S>
9791 void ReturnValue<T>::Set(const Persistent<S>& handle) {
9792  TYPE_CHECK(T, S);
9793  if (V8_UNLIKELY(handle.IsEmpty())) {
9794  *value_ = GetDefaultValue();
9795  } else {
9796  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9797  }
9798 }
9799 
9800 template <typename T>
9801 template <typename S>
9802 void ReturnValue<T>::Set(const Global<S>& handle) {
9803  TYPE_CHECK(T, S);
9804  if (V8_UNLIKELY(handle.IsEmpty())) {
9805  *value_ = GetDefaultValue();
9806  } else {
9807  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9808  }
9809 }
9810 
9811 template <typename T>
9812 template <typename S>
9813 void ReturnValue<T>::Set(const Local<S> handle) {
9814  TYPE_CHECK(T, S);
9815  if (V8_UNLIKELY(handle.IsEmpty())) {
9816  *value_ = GetDefaultValue();
9817  } else {
9818  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9819  }
9820 }
9821 
9822 template<typename T>
9823 void ReturnValue<T>::Set(double i) {
9824  TYPE_CHECK(T, Number);
9825  Set(Number::New(GetIsolate(), i));
9826 }
9827 
9828 template<typename T>
9829 void ReturnValue<T>::Set(int32_t i) {
9830  TYPE_CHECK(T, Integer);
9831  typedef internal::Internals I;
9832  if (V8_LIKELY(I::IsValidSmi(i))) {
9833  *value_ = I::IntToSmi(i);
9834  return;
9835  }
9836  Set(Integer::New(GetIsolate(), i));
9837 }
9838 
9839 template<typename T>
9840 void ReturnValue<T>::Set(uint32_t i) {
9841  TYPE_CHECK(T, Integer);
9842  // Can't simply use INT32_MAX here for whatever reason.
9843  bool fits_into_int32_t = (i & (1U << 31)) == 0;
9844  if (V8_LIKELY(fits_into_int32_t)) {
9845  Set(static_cast<int32_t>(i));
9846  return;
9847  }
9848  Set(Integer::NewFromUnsigned(GetIsolate(), i));
9849 }
9850 
9851 template<typename T>
9852 void ReturnValue<T>::Set(bool value) {
9853  TYPE_CHECK(T, Boolean);
9854  typedef internal::Internals I;
9855  int root_index;
9856  if (value) {
9857  root_index = I::kTrueValueRootIndex;
9858  } else {
9859  root_index = I::kFalseValueRootIndex;
9860  }
9861  *value_ = *I::GetRoot(GetIsolate(), root_index);
9862 }
9863 
9864 template<typename T>
9865 void ReturnValue<T>::SetNull() {
9866  TYPE_CHECK(T, Primitive);
9867  typedef internal::Internals I;
9868  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
9869 }
9870 
9871 template<typename T>
9872 void ReturnValue<T>::SetUndefined() {
9873  TYPE_CHECK(T, Primitive);
9874  typedef internal::Internals I;
9875  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
9876 }
9877 
9878 template<typename T>
9879 void ReturnValue<T>::SetEmptyString() {
9880  TYPE_CHECK(T, String);
9881  typedef internal::Internals I;
9882  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
9883 }
9884 
9885 template <typename T>
9886 Isolate* ReturnValue<T>::GetIsolate() const {
9887  // Isolate is always the pointer below the default value on the stack.
9888  return *reinterpret_cast<Isolate**>(&value_[-2]);
9889 }
9890 
9891 template <typename T>
9892 Local<Value> ReturnValue<T>::Get() const {
9893  typedef internal::Internals I;
9894  if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex))
9895  return Local<Value>(*Undefined(GetIsolate()));
9896  return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
9897 }
9898 
9899 template <typename T>
9900 template <typename S>
9901 void ReturnValue<T>::Set(S* whatever) {
9902  // Uncompilable to prevent inadvertent misuse.
9903  TYPE_CHECK(S*, Primitive);
9904 }
9905 
9906 template<typename T>
9907 internal::Object* ReturnValue<T>::GetDefaultValue() {
9908  // Default value is always the pointer below value_ on the stack.
9909  return value_[-1];
9910 }
9911 
9912 template <typename T>
9913 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
9914  internal::Object** values,
9915  int length)
9916  : implicit_args_(implicit_args), values_(values), length_(length) {}
9917 
9918 template<typename T>
9920  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
9921  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
9922 }
9923 
9924 
9925 template<typename T>
9927  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
9928 }
9929 
9930 
9931 template<typename T>
9933  return Local<Object>(reinterpret_cast<Object*>(
9934  &implicit_args_[kHolderIndex]));
9935 }
9936 
9937 template <typename T>
9939  return Local<Value>(
9940  reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex]));
9941 }
9942 
9943 template <typename T>
9945  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
9946 }
9947 
9948 
9949 template<typename T>
9951  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
9952 }
9953 
9954 
9955 template<typename T>
9957  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
9958 }
9959 
9960 
9961 template<typename T>
9963  return !NewTarget()->IsUndefined();
9964 }
9965 
9966 
9967 template<typename T>
9969  return length_;
9970 }
9971 
9972 ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
9973  Local<Integer> resource_line_offset,
9974  Local<Integer> resource_column_offset,
9975  Local<Boolean> resource_is_shared_cross_origin,
9976  Local<Integer> script_id,
9977  Local<Value> source_map_url,
9978  Local<Boolean> resource_is_opaque,
9979  Local<Boolean> is_wasm, Local<Boolean> is_module,
9980  Local<PrimitiveArray> host_defined_options)
9981  : resource_name_(resource_name),
9982  resource_line_offset_(resource_line_offset),
9983  resource_column_offset_(resource_column_offset),
9984  options_(!resource_is_shared_cross_origin.IsEmpty() &&
9985  resource_is_shared_cross_origin->IsTrue(),
9986  !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue(),
9987  !is_wasm.IsEmpty() && is_wasm->IsTrue(),
9988  !is_module.IsEmpty() && is_module->IsTrue()),
9989  script_id_(script_id),
9990  source_map_url_(source_map_url),
9991  host_defined_options_(host_defined_options) {}
9992 
9993 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
9994 
9995 Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions() const {
9996  return host_defined_options_;
9997 }
9998 
9999 Local<Integer> ScriptOrigin::ResourceLineOffset() const {
10000  return resource_line_offset_;
10001 }
10002 
10003 
10004 Local<Integer> ScriptOrigin::ResourceColumnOffset() const {
10005  return resource_column_offset_;
10006 }
10007 
10008 
10009 Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
10010 
10011 
10012 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
10013 
10014 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
10015  CachedData* data)
10016  : source_string(string),
10017  resource_name(origin.ResourceName()),
10018  resource_line_offset(origin.ResourceLineOffset()),
10019  resource_column_offset(origin.ResourceColumnOffset()),
10020  resource_options(origin.Options()),
10021  source_map_url(origin.SourceMapUrl()),
10022  host_defined_options(origin.HostDefinedOptions()),
10023  cached_data(data) {}
10024 
10025 ScriptCompiler::Source::Source(Local<String> string,
10026  CachedData* data)
10027  : source_string(string), cached_data(data) {}
10028 
10029 
10030 ScriptCompiler::Source::~Source() {
10031  delete cached_data;
10032 }
10033 
10034 
10035 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
10036  const {
10037  return cached_data;
10038 }
10039 
10040 const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
10041  return resource_options;
10042 }
10043 
10044 Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
10045  return value ? True(isolate) : False(isolate);
10046 }
10047 
10048 void Template::Set(Isolate* isolate, const char* name, Local<Data> value) {
10050  .ToLocalChecked(),
10051  value);
10052 }
10053 
10054 FunctionTemplate* FunctionTemplate::Cast(Data* data) {
10055 #ifdef V8_ENABLE_CHECKS
10056  CheckCast(data);
10057 #endif
10058  return reinterpret_cast<FunctionTemplate*>(data);
10059 }
10060 
10061 ObjectTemplate* ObjectTemplate::Cast(Data* data) {
10062 #ifdef V8_ENABLE_CHECKS
10063  CheckCast(data);
10064 #endif
10065  return reinterpret_cast<ObjectTemplate*>(data);
10066 }
10067 
10068 Signature* Signature::Cast(Data* data) {
10069 #ifdef V8_ENABLE_CHECKS
10070  CheckCast(data);
10071 #endif
10072  return reinterpret_cast<Signature*>(data);
10073 }
10074 
10075 AccessorSignature* AccessorSignature::Cast(Data* data) {
10076 #ifdef V8_ENABLE_CHECKS
10077  CheckCast(data);
10078 #endif
10079  return reinterpret_cast<AccessorSignature*>(data);
10080 }
10081 
10083 #ifndef V8_ENABLE_CHECKS
10084  typedef internal::Object O;
10085  typedef internal::Internals I;
10086  O* obj = *reinterpret_cast<O**>(this);
10087  // Fast path: If the object is a plain JSObject, which is the common case, we
10088  // know where to find the internal fields and can return the value directly.
10089  auto instance_type = I::GetInstanceType(obj);
10090  if (instance_type == I::kJSObjectType ||
10091  instance_type == I::kJSApiObjectType ||
10092  instance_type == I::kJSSpecialApiObjectType) {
10093  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
10094  O* value = I::ReadField<O*>(obj, offset);
10095  O** result = HandleScope::CreateHandle(
10096  reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value);
10097  return Local<Value>(reinterpret_cast<Value*>(result));
10098  }
10099 #endif
10100  return SlowGetInternalField(index);
10101 }
10102 
10103 
10105 #ifndef V8_ENABLE_CHECKS
10106  typedef internal::Object O;
10107  typedef internal::Internals I;
10108  O* obj = *reinterpret_cast<O**>(this);
10109  // Fast path: If the object is a plain JSObject, which is the common case, we
10110  // know where to find the internal fields and can return the value directly.
10111  auto instance_type = I::GetInstanceType(obj);
10112  if (V8_LIKELY(instance_type == I::kJSObjectType ||
10113  instance_type == I::kJSApiObjectType ||
10114  instance_type == I::kJSSpecialApiObjectType)) {
10115  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
10116  return I::ReadField<void*>(obj, offset);
10117  }
10118 #endif
10119  return SlowGetAlignedPointerFromInternalField(index);
10120 }
10121 
10122 String* String::Cast(v8::Value* value) {
10123 #ifdef V8_ENABLE_CHECKS
10124  CheckCast(value);
10125 #endif
10126  return static_cast<String*>(value);
10127 }
10128 
10129 
10130 Local<String> String::Empty(Isolate* isolate) {
10131  typedef internal::Object* S;
10132  typedef internal::Internals I;
10133  I::CheckInitialized(isolate);
10134  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
10135  return Local<String>(reinterpret_cast<String*>(slot));
10136 }
10137 
10138 
10140  typedef internal::Object O;
10141  typedef internal::Internals I;
10142  O* obj = *reinterpret_cast<O* const*>(this);
10143 
10144  ExternalStringResource* result;
10145  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
10146  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
10147  result = reinterpret_cast<String::ExternalStringResource*>(value);
10148  } else {
10149  result = GetExternalStringResourceSlow();
10150  }
10151 #ifdef V8_ENABLE_CHECKS
10152  VerifyExternalStringResource(result);
10153 #endif
10154  return result;
10155 }
10156 
10157 
10159  String::Encoding* encoding_out) const {
10160  typedef internal::Object O;
10161  typedef internal::Internals I;
10162  O* obj = *reinterpret_cast<O* const*>(this);
10163  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
10164  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
10165  ExternalStringResourceBase* resource;
10166  if (type == I::kExternalOneByteRepresentationTag ||
10167  type == I::kExternalTwoByteRepresentationTag) {
10168  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
10169  resource = static_cast<ExternalStringResourceBase*>(value);
10170  } else {
10171  resource = GetExternalStringResourceBaseSlow(encoding_out);
10172  }
10173 #ifdef V8_ENABLE_CHECKS
10174  VerifyExternalStringResourceBase(resource, *encoding_out);
10175 #endif
10176  return resource;
10177 }
10178 
10179 
10180 bool Value::IsUndefined() const {
10181 #ifdef V8_ENABLE_CHECKS
10182  return FullIsUndefined();
10183 #else
10184  return QuickIsUndefined();
10185 #endif
10186 }
10187 
10188 bool Value::QuickIsUndefined() const {
10189  typedef internal::Object O;
10190  typedef internal::Internals I;
10191  O* obj = *reinterpret_cast<O* const*>(this);
10192  if (!I::HasHeapObjectTag(obj)) return false;
10193  if (I::GetInstanceType(obj) != I::kOddballType) return false;
10194  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
10195 }
10196 
10197 
10198 bool Value::IsNull() const {
10199 #ifdef V8_ENABLE_CHECKS
10200  return FullIsNull();
10201 #else
10202  return QuickIsNull();
10203 #endif
10204 }
10205 
10206 bool Value::QuickIsNull() const {
10207  typedef internal::Object O;
10208  typedef internal::Internals I;
10209  O* obj = *reinterpret_cast<O* const*>(this);
10210  if (!I::HasHeapObjectTag(obj)) return false;
10211  if (I::GetInstanceType(obj) != I::kOddballType) return false;
10212  return (I::GetOddballKind(obj) == I::kNullOddballKind);
10213 }
10214 
10216 #ifdef V8_ENABLE_CHECKS
10217  return FullIsNull() || FullIsUndefined();
10218 #else
10219  return QuickIsNullOrUndefined();
10220 #endif
10221 }
10222 
10223 bool Value::QuickIsNullOrUndefined() const {
10224  typedef internal::Object O;
10225  typedef internal::Internals I;
10226  O* obj = *reinterpret_cast<O* const*>(this);
10227  if (!I::HasHeapObjectTag(obj)) return false;
10228  if (I::GetInstanceType(obj) != I::kOddballType) return false;
10229  int kind = I::GetOddballKind(obj);
10230  return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
10231 }
10232 
10233 bool Value::IsString() const {
10234 #ifdef V8_ENABLE_CHECKS
10235  return FullIsString();
10236 #else
10237  return QuickIsString();
10238 #endif
10239 }
10240 
10241 bool Value::QuickIsString() const {
10242  typedef internal::Object O;
10243  typedef internal::Internals I;
10244  O* obj = *reinterpret_cast<O* const*>(this);
10245  if (!I::HasHeapObjectTag(obj)) return false;
10246  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
10247 }
10248 
10249 
10250 template <class T> Value* Value::Cast(T* value) {
10251  return static_cast<Value*>(value);
10252 }
10253 
10254 Local<Boolean> Value::ToBoolean() const {
10255  return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
10256  .FromMaybe(Local<Boolean>());
10257 }
10258 
10259 Local<String> Value::ToString() const {
10260  return ToString(Isolate::GetCurrent()->GetCurrentContext())
10261  .FromMaybe(Local<String>());
10262 }
10263 
10264 Local<Object> Value::ToObject() const {
10265  return ToObject(Isolate::GetCurrent()->GetCurrentContext())
10266  .FromMaybe(Local<Object>());
10267 }
10268 
10269 Local<Integer> Value::ToInteger() const {
10270  return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
10271  .FromMaybe(Local<Integer>());
10272 }
10273 
10274 Boolean* Boolean::Cast(v8::Value* value) {
10275 #ifdef V8_ENABLE_CHECKS
10276  CheckCast(value);
10277 #endif
10278  return static_cast<Boolean*>(value);
10279 }
10280 
10281 
10282 Name* Name::Cast(v8::Value* value) {
10283 #ifdef V8_ENABLE_CHECKS
10284  CheckCast(value);
10285 #endif
10286  return static_cast<Name*>(value);
10287 }
10288 
10289 
10290 Symbol* Symbol::Cast(v8::Value* value) {
10291 #ifdef V8_ENABLE_CHECKS
10292  CheckCast(value);
10293 #endif
10294  return static_cast<Symbol*>(value);
10295 }
10296 
10297 
10298 Private* Private::Cast(Data* data) {
10299 #ifdef V8_ENABLE_CHECKS
10300  CheckCast(data);
10301 #endif
10302  return reinterpret_cast<Private*>(data);
10303 }
10304 
10305 
10306 Number* Number::Cast(v8::Value* value) {
10307 #ifdef V8_ENABLE_CHECKS
10308  CheckCast(value);
10309 #endif
10310  return static_cast<Number*>(value);
10311 }
10312 
10313 
10314 Integer* Integer::Cast(v8::Value* value) {
10315 #ifdef V8_ENABLE_CHECKS
10316  CheckCast(value);
10317 #endif
10318  return static_cast<Integer*>(value);
10319 }
10320 
10321 
10322 Int32* Int32::Cast(v8::Value* value) {
10323 #ifdef V8_ENABLE_CHECKS
10324  CheckCast(value);
10325 #endif
10326  return static_cast<Int32*>(value);
10327 }
10328 
10329 
10330 Uint32* Uint32::Cast(v8::Value* value) {
10331 #ifdef V8_ENABLE_CHECKS
10332  CheckCast(value);
10333 #endif
10334  return static_cast<Uint32*>(value);
10335 }
10336 
10337 BigInt* BigInt::Cast(v8::Value* value) {
10338 #ifdef V8_ENABLE_CHECKS
10339  CheckCast(value);
10340 #endif
10341  return static_cast<BigInt*>(value);
10342 }
10343 
10344 Date* Date::Cast(v8::Value* value) {
10345 #ifdef V8_ENABLE_CHECKS
10346  CheckCast(value);
10347 #endif
10348  return static_cast<Date*>(value);
10349 }
10350 
10351 
10352 StringObject* StringObject::Cast(v8::Value* value) {
10353 #ifdef V8_ENABLE_CHECKS
10354  CheckCast(value);
10355 #endif
10356  return static_cast<StringObject*>(value);
10357 }
10358 
10359 
10360 SymbolObject* SymbolObject::Cast(v8::Value* value) {
10361 #ifdef V8_ENABLE_CHECKS
10362  CheckCast(value);
10363 #endif
10364  return static_cast<SymbolObject*>(value);
10365 }
10366 
10367 
10368 NumberObject* NumberObject::Cast(v8::Value* value) {
10369 #ifdef V8_ENABLE_CHECKS
10370  CheckCast(value);
10371 #endif
10372  return static_cast<NumberObject*>(value);
10373 }
10374 
10375 BigIntObject* BigIntObject::Cast(v8::Value* value) {
10376 #ifdef V8_ENABLE_CHECKS
10377  CheckCast(value);
10378 #endif
10379  return static_cast<BigIntObject*>(value);
10380 }
10381 
10382 BooleanObject* BooleanObject::Cast(v8::Value* value) {
10383 #ifdef V8_ENABLE_CHECKS
10384  CheckCast(value);
10385 #endif
10386  return static_cast<BooleanObject*>(value);
10387 }
10388 
10389 
10390 RegExp* RegExp::Cast(v8::Value* value) {
10391 #ifdef V8_ENABLE_CHECKS
10392  CheckCast(value);
10393 #endif
10394  return static_cast<RegExp*>(value);
10395 }
10396 
10397 
10398 Object* Object::Cast(v8::Value* value) {
10399 #ifdef V8_ENABLE_CHECKS
10400  CheckCast(value);
10401 #endif
10402  return static_cast<Object*>(value);
10403 }
10404 
10405 
10406 Array* Array::Cast(v8::Value* value) {
10407 #ifdef V8_ENABLE_CHECKS
10408  CheckCast(value);
10409 #endif
10410  return static_cast<Array*>(value);
10411 }
10412 
10413 
10414 Map* Map::Cast(v8::Value* value) {
10415 #ifdef V8_ENABLE_CHECKS
10416  CheckCast(value);
10417 #endif
10418  return static_cast<Map*>(value);
10419 }
10420 
10421 
10422 Set* Set::Cast(v8::Value* value) {
10423 #ifdef V8_ENABLE_CHECKS
10424  CheckCast(value);
10425 #endif
10426  return static_cast<Set*>(value);
10427 }
10428 
10429 
10430 Promise* Promise::Cast(v8::Value* value) {
10431 #ifdef V8_ENABLE_CHECKS
10432  CheckCast(value);
10433 #endif
10434  return static_cast<Promise*>(value);
10435 }
10436 
10437 
10438 Proxy* Proxy::Cast(v8::Value* value) {
10439 #ifdef V8_ENABLE_CHECKS
10440  CheckCast(value);
10441 #endif
10442  return static_cast<Proxy*>(value);
10443 }
10444 
10445 WasmCompiledModule* WasmCompiledModule::Cast(v8::Value* value) {
10446 #ifdef V8_ENABLE_CHECKS
10447  CheckCast(value);
10448 #endif
10449  return static_cast<WasmCompiledModule*>(value);
10450 }
10451 
10452 Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
10453 #ifdef V8_ENABLE_CHECKS
10454  CheckCast(value);
10455 #endif
10456  return static_cast<Promise::Resolver*>(value);
10457 }
10458 
10459 
10460 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
10461 #ifdef V8_ENABLE_CHECKS
10462  CheckCast(value);
10463 #endif
10464  return static_cast<ArrayBuffer*>(value);
10465 }
10466 
10467 
10468 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
10469 #ifdef V8_ENABLE_CHECKS
10470  CheckCast(value);
10471 #endif
10472  return static_cast<ArrayBufferView*>(value);
10473 }
10474 
10475 
10476 TypedArray* TypedArray::Cast(v8::Value* value) {
10477 #ifdef V8_ENABLE_CHECKS
10478  CheckCast(value);
10479 #endif
10480  return static_cast<TypedArray*>(value);
10481 }
10482 
10483 
10484 Uint8Array* Uint8Array::Cast(v8::Value* value) {
10485 #ifdef V8_ENABLE_CHECKS
10486  CheckCast(value);
10487 #endif
10488  return static_cast<Uint8Array*>(value);
10489 }
10490 
10491 
10492 Int8Array* Int8Array::Cast(v8::Value* value) {
10493 #ifdef V8_ENABLE_CHECKS
10494  CheckCast(value);
10495 #endif
10496  return static_cast<Int8Array*>(value);
10497 }
10498 
10499 
10500 Uint16Array* Uint16Array::Cast(v8::Value* value) {
10501 #ifdef V8_ENABLE_CHECKS
10502  CheckCast(value);
10503 #endif
10504  return static_cast<Uint16Array*>(value);
10505 }
10506 
10507 
10508 Int16Array* Int16Array::Cast(v8::Value* value) {
10509 #ifdef V8_ENABLE_CHECKS
10510  CheckCast(value);
10511 #endif
10512  return static_cast<Int16Array*>(value);
10513 }
10514 
10515 
10516 Uint32Array* Uint32Array::Cast(v8::Value* value) {
10517 #ifdef V8_ENABLE_CHECKS
10518  CheckCast(value);
10519 #endif
10520  return static_cast<Uint32Array*>(value);
10521 }
10522 
10523 
10524 Int32Array* Int32Array::Cast(v8::Value* value) {
10525 #ifdef V8_ENABLE_CHECKS
10526  CheckCast(value);
10527 #endif
10528  return static_cast<Int32Array*>(value);
10529 }
10530 
10531 
10532 Float32Array* Float32Array::Cast(v8::Value* value) {
10533 #ifdef V8_ENABLE_CHECKS
10534  CheckCast(value);
10535 #endif
10536  return static_cast<Float32Array*>(value);
10537 }
10538 
10539 
10540 Float64Array* Float64Array::Cast(v8::Value* value) {
10541 #ifdef V8_ENABLE_CHECKS
10542  CheckCast(value);
10543 #endif
10544  return static_cast<Float64Array*>(value);
10545 }
10546 
10547 BigInt64Array* BigInt64Array::Cast(v8::Value* value) {
10548 #ifdef V8_ENABLE_CHECKS
10549  CheckCast(value);
10550 #endif
10551  return static_cast<BigInt64Array*>(value);
10552 }
10553 
10554 BigUint64Array* BigUint64Array::Cast(v8::Value* value) {
10555 #ifdef V8_ENABLE_CHECKS
10556  CheckCast(value);
10557 #endif
10558  return static_cast<BigUint64Array*>(value);
10559 }
10560 
10561 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
10562 #ifdef V8_ENABLE_CHECKS
10563  CheckCast(value);
10564 #endif
10565  return static_cast<Uint8ClampedArray*>(value);
10566 }
10567 
10568 
10569 DataView* DataView::Cast(v8::Value* value) {
10570 #ifdef V8_ENABLE_CHECKS
10571  CheckCast(value);
10572 #endif
10573  return static_cast<DataView*>(value);
10574 }
10575 
10576 
10577 SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
10578 #ifdef V8_ENABLE_CHECKS
10579  CheckCast(value);
10580 #endif
10581  return static_cast<SharedArrayBuffer*>(value);
10582 }
10583 
10584 
10585 Function* Function::Cast(v8::Value* value) {
10586 #ifdef V8_ENABLE_CHECKS
10587  CheckCast(value);
10588 #endif
10589  return static_cast<Function*>(value);
10590 }
10591 
10592 
10593 External* External::Cast(v8::Value* value) {
10594 #ifdef V8_ENABLE_CHECKS
10595  CheckCast(value);
10596 #endif
10597  return static_cast<External*>(value);
10598 }
10599 
10600 
10601 template<typename T>
10603  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
10604 }
10605 
10606 
10607 template<typename T>
10609  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
10610 }
10611 
10612 
10613 template<typename T>
10615  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
10616 }
10617 
10618 
10619 template<typename T>
10621  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
10622 }
10623 
10624 
10625 template<typename T>
10627  return ReturnValue<T>(&args_[kReturnValueIndex]);
10628 }
10629 
10630 template <typename T>
10632  typedef internal::Internals I;
10633  return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(0);
10634 }
10635 
10636 
10637 Local<Primitive> Undefined(Isolate* isolate) {
10638  typedef internal::Object* S;
10639  typedef internal::Internals I;
10640  I::CheckInitialized(isolate);
10641  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
10642  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10643 }
10644 
10645 
10646 Local<Primitive> Null(Isolate* isolate) {
10647  typedef internal::Object* S;
10648  typedef internal::Internals I;
10649  I::CheckInitialized(isolate);
10650  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
10651  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10652 }
10653 
10654 
10655 Local<Boolean> True(Isolate* isolate) {
10656  typedef internal::Object* S;
10657  typedef internal::Internals I;
10658  I::CheckInitialized(isolate);
10659  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
10660  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
10661 }
10662 
10663 
10664 Local<Boolean> False(Isolate* isolate) {
10665  typedef internal::Object* S;
10666  typedef internal::Internals I;
10667  I::CheckInitialized(isolate);
10668  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
10669  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
10670 }
10671 
10672 
10673 void Isolate::SetData(uint32_t slot, void* data) {
10674  typedef internal::Internals I;
10675  I::SetEmbedderData(this, slot, data);
10676 }
10677 
10678 
10679 void* Isolate::GetData(uint32_t slot) {
10680  typedef internal::Internals I;
10681  return I::GetEmbedderData(this, slot);
10682 }
10683 
10684 
10685 uint32_t Isolate::GetNumberOfDataSlots() {
10686  typedef internal::Internals I;
10687  return I::kNumIsolateDataSlots;
10688 }
10689 
10690 template <class T>
10691 MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
10692  T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
10693  if (data) internal::PerformCastCheck(data);
10694  return Local<T>(data);
10695 }
10696 
10697 int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
10698  int64_t change_in_bytes) {
10699  typedef internal::Internals I;
10700  const int64_t kMemoryReducerActivationLimit = 32 * 1024 * 1024;
10701  int64_t* external_memory = reinterpret_cast<int64_t*>(
10702  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
10703  int64_t* external_memory_limit = reinterpret_cast<int64_t*>(
10704  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
10705  int64_t* external_memory_at_last_mc =
10706  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
10707  I::kExternalMemoryAtLastMarkCompactOffset);
10708  const int64_t amount = *external_memory + change_in_bytes;
10709 
10710  *external_memory = amount;
10711 
10712  int64_t allocation_diff_since_last_mc =
10713  *external_memory_at_last_mc - *external_memory;
10714  allocation_diff_since_last_mc = allocation_diff_since_last_mc < 0
10715  ? -allocation_diff_since_last_mc
10716  : allocation_diff_since_last_mc;
10717  if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) {
10718  CheckMemoryPressure();
10719  }
10720 
10721  if (change_in_bytes < 0) {
10722  *external_memory_limit += change_in_bytes;
10723  }
10724 
10725  if (change_in_bytes > 0 && amount > *external_memory_limit) {
10726  ReportExternalAllocationLimitReached();
10727  }
10728  return *external_memory;
10729 }
10730 
10731 Local<Value> Context::GetEmbedderData(int index) {
10732 #ifndef V8_ENABLE_CHECKS
10733  typedef internal::Object O;
10734  typedef internal::Internals I;
10735  auto* context = *reinterpret_cast<internal::NeverReadOnlySpaceObject**>(this);
10736  O** result =
10737  HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
10738  return Local<Value>(reinterpret_cast<Value*>(result));
10739 #else
10740  return SlowGetEmbedderData(index);
10741 #endif
10742 }
10743 
10744 
10745 void* Context::GetAlignedPointerFromEmbedderData(int index) {
10746 #ifndef V8_ENABLE_CHECKS
10747  typedef internal::Internals I;
10748  return I::ReadEmbedderData<void*>(this, index);
10749 #else
10750  return SlowGetAlignedPointerFromEmbedderData(index);
10751 #endif
10752 }
10753 
10754 template <class T>
10755 MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
10756  T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
10757  if (data) internal::PerformCastCheck(data);
10758  return Local<T>(data);
10759 }
10760 
10761 template <class T>
10762 size_t SnapshotCreator::AddData(Local<Context> context, Local<T> object) {
10763  T* object_ptr = *object;
10764  internal::Object** p = reinterpret_cast<internal::Object**>(object_ptr);
10765  return AddData(context, *p);
10766 }
10767 
10768 template <class T>
10769 size_t SnapshotCreator::AddData(Local<T> object) {
10770  T* object_ptr = *object;
10771  internal::Object** p = reinterpret_cast<internal::Object**>(object_ptr);
10772  return AddData(*p);
10773 }
10774 
10787 } // namespace v8
10788 
10789 
10790 #undef TYPE_CHECK
10791 
10792 
10793 #endif // INCLUDE_V8_H_
V8_INLINE bool IsNearDeath() const
Definition: v8.h:9665
V8_INLINE uint16_t WrapperClassId() const
Definition: v8.h:9777
Definition: v8.h:3133
Definition: v8.h:4858
Definition: v8.h:1354
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:6048
IntegrityLevel
Definition: v8.h:3339
Definition: v8.h:3189
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:5649
KeyConversionMode
Definition: v8.h:3334
Definition: v8.h:4960
static V8_INLINE Local< Context > CreationContext(const PersistentBase< Object > &object)
Definition: v8.h:3702
bool only_terminate_in_safe_scope
Definition: v8.h:7304
Definition: v8.h:1206
V8_INLINE bool IsNullOrUndefined() const
Definition: v8.h:10215
WriteOptions
Definition: v8.h:2724
NewStringType
Definition: v8.h:2643
Isolate * GetIsolate()
Definition: v8.h:1994
void(* GenericNamedPropertyDefinerCallback)(Local< Name > property, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5598
Definition: v8.h:3252
Definition: v8.h:123
Definition: v8.h:4909
int InternalFieldCount()
V8_INLINE void Clear()
Definition: v8.h:325
V8_INLINE bool IsString() const
Definition: v8.h:10233
Definition: v8.h:1122
virtual ~ExternalStringResource()
Definition: v8.h:2810
V8_INLINE Local< T > Escape(Local< T > value)
Definition: v8.h:1029
IndexFilter
Definition: v8.h:3328
Definition: v8.h:1171
PropertyAttribute
Definition: v8.h:3244
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
Definition: v8.h:3574
V8_INLINE int Length() const
Definition: v8.h:9968
static V8_INLINE Local< T > Cast(Local< S > that)
Definition: v8.h:376
KeyCollectionMode
Definition: v8.h:3322
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
Definition: v8.h:900
V8_INLINE bool IsWeak() const
Definition: v8.h:9676
Definition: v8.h:4180
Definition: v8.h:5025
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Definition: v8.h:3593
void(* GenericNamedPropertyDeleterCallback)(Local< Name > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:5566
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:9393
Definition: v8.h:3248
virtual ~ExternalOneByteStringResource()
Definition: v8.h:2843
Definition: v8.h:1992
Definition: v8.h:3097
Definition: v8.h:85
void(* IndexedPropertyDescriptorCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5672
Definition: v8.h:5043
Definition: v8.h:5009
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:3260
Definition: v8.h:2620
Definition: v8.h:182
V8_INLINE bool IsEmpty() const
Definition: v8.h:320
Definition: v8.h:2234
Definition: v8.h:2606
Definition: v8.h:4993
Definition: v8-util.h:162
Definition: v8.h:1811
Definition: v8.h:4638
Definition: v8.h:1380
V8_INLINE Local< Object > Holder() const
Definition: v8.h:9932
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
Definition: v8.h:796
V8_INLINE Local< Value > NewTarget() const
Definition: v8.h:9938
V8_INLINE Isolate * GetIsolate() const
Definition: v8.h:10602
Definition: v8.h:140
V8_INLINE T FromJust() const
Definition: v8.h:8749
V8_INLINE bool ShouldThrowOnError() const
Definition: v8.h:10631
V8_INLINE void SetWeak()
Definition: v8.h:9724
PropertyHandlerFlags
Definition: v8.h:5928
Definition: v8.h:6297
Definition: v8.h:6942
V8_INLINE Local< S > As() const
Definition: v8.h:391
Definition: v8.h:2660
Definition: v8-platform.h:247
Definition: v8.h:1423
Definition: v8.h:1939
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, v8::NewStringType type, int length=-1)
Definition: v8.h:4875
Definition: v8.h:114
Definition: v8.h:2129
void(* IndexedPropertyDefinerCallback)(uint32_t index, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5665
V8_INLINE Global()
Definition: v8.h:883
Definition: v8.h:4476
V8_INLINE Persistent(const Persistent &that)
Definition: v8.h:816
Definition: v8.h:2599
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
Definition: v8.h:472
Definition: v8.h:7226
bool(* AccessCheckCallback)(Local< Context > accessing_context, Local< Object > accessed_object, Local< Value > data)
Definition: v8.h:5691
Definition: v8.h:2131
CreateHistogramCallback create_histogram_callback
Definition: v8.h:7278
void(* GenericNamedPropertyQueryCallback)(Local< Name > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:5542
Definition: v8.h:3767
V8_DEPRECATE_SOON("Objects are always considered independent. " "Use MarkActive to avoid collecting otherwise dead weak handles.", V8_INLINE void MarkIndependent())
void(* GenericNamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:5575
Definition: v8.h:1860
StartupData * snapshot_blob
Definition: v8.h:7263
Definition: v8.h:7312
Definition: v8.h:4284
Definition: v8-platform.h:16
Definition: v8.h:963
Definition: v8.h:5795
Definition: v8.h:117
V8_INLINE Local< Value > operator[](int i) const
Definition: v8.h:9919
Definition: v8.h:4574
V8_INLINE Global & operator=(Global< S > &&rhs)
Definition: v8.h:915
V8_INLINE bool operator!=(const Local< S > &that) const
Definition: v8.h:362
Definition: v8.h:6934
CounterLookupCallback counter_lookup_callback
Definition: v8.h:7270
AccessType
Definition: v8.h:5678
Definition: v8-util.h:426
void(* GenericNamedPropertyDescriptorCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5621
V8_INLINE bool operator==(const Local< S > &that) const
Definition: v8.h:338
Definition: v8.h:3010
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5627
V8_INLINE Local< T > ToLocalChecked()
Definition: v8.h:9618
V8_INLINE Local< Value > Data() const
Definition: v8.h:9944
Definition: v8.h:4078
V8_INLINE ReturnValue< T > GetReturnValue() const
Definition: v8.h:10626
V8_WARN_UNUSED_RESULT V8_INLINE bool To(T *out) const
Definition: v8.h:8740
Definition: v8.h:521
V8_INLINE ExternalStringResourceBase * GetExternalStringResourceBase(Encoding *encoding_out) const
Definition: v8.h:10158
FunctionEntryHook entry_hook
Definition: v8.h:7247
V8_INLINE Persistent()
Definition: v8.h:789
Definition: v8.h:121
V8_INLINE void MarkActive()
Definition: v8.h:9758
V8_INLINE Local< Value > Data() const
Definition: v8.h:10608
Definition: v8.h:4892
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5634
Definition: v8.h:1723
Definition: v8.h:4188
Definition: v8.h:3246
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:5205
Definition: v8.h:6316
Definition: v8.h:4926
Definition: v8.h:3823
Flags
Definition: v8.h:5291
V8_INLINE Local(Local< S > that)
Definition: v8.h:307
bool IsExternal() const
Definition: v8.h:1244
Definition: v8.h:2987
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:5659
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:5642
Definition: v8.h:3250
bool allow_atomics_wait
Definition: v8.h:7299
Definition: v8.h:4333
Definition: v8.h:5056
Definition: v8.h:5367
const intptr_t * external_references
Definition: v8.h:7293
void Set(Local< Name > name, Local< Data > value, PropertyAttribute attributes=None)
Definition: v8-util.h:569
Definition: v8.h:4768
Definition: v8.h:1137
Definition: v8.h:116
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Definition: v8.h:806
V8_INLINE Global(Isolate *isolate, Local< S > that)
Definition: v8.h:890
Definition: v8.h:4356
V8_INLINE Local< Object > Holder() const
Definition: v8.h:10620
V8_INLINE ReturnValue< T > GetReturnValue() const
Definition: v8.h:9956
Definition: v8.h:1947
SideEffectType
Definition: v8.h:3313
V8_INLINE void SetWrapperClassId(uint16_t class_id)
Definition: v8.h:9767
V8_INLINE void * GetAlignedPointerFromInternalField(int index)
Definition: v8.h:10104
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8.h:9581
V8_INLINE T FromMaybe(const T &default_value) const
Definition: v8.h:8758
void(* GenericNamedPropertyGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5493
Definition: v8.h:5337
Definition: v8.h:1060
V8_INLINE ExternalStringResource * GetExternalStringResource() const
Definition: v8.h:10139
StackTraceOptions
Definition: v8.h:1819
JitCodeEventHandler code_event_handler
Definition: v8.h:7253
Definition: v8.h:4817
Definition: v8.h:1019
Definition: v8.h:5168
Definition: v8.h:5285
Definition: v8.h:3344
Definition: v8.h:765
Definition: v8.h:9215
static V8_INLINE Local< String > Empty(Isolate *isolate)
Definition: v8.h:10130
V8_INLINE Global(Global &&other)
Definition: v8.h:907
Definition: v8.h:133
ArrayBuffer::Allocator * array_buffer_allocator
Definition: v8.h:7285
Definition: v8.h:1237
Definition: v8.h:1099
V8_INLINE bool IsNull() const
Definition: v8.h:10198
Definition: v8.h:3044
V8_INLINE void RegisterExternalReference(Isolate *isolate) const
Definition: v8.h:9742
Definition: v8.h:4591
Definition: v8.h:6104
Definition: v8.h:134
Definition: v8.h:1389
Definition: v8.h:1957
Definition: v8.h:5269
V8_INLINE Local< Object > This() const
Definition: v8.h:10614
Definition: v8.h:130
V8_INLINE void AnnotateStrongRetainer(const char *label)
Definition: v8.h:9736
Definition: v8.h:1088
NoCacheReason
Definition: v8.h:1563
Definition: v8.h:4841
V8_INLINE bool IsUndefined() const
Definition: v8.h:10180
V8_INLINE bool IsConstructCall() const
Definition: v8.h:9962
V8_INLINE T ToChecked() const
Definition: v8.h:8734
V8_INLINE Local< S > FromMaybe(Local< S > default_value) const
Definition: v8.h:488
virtual void Dispose()
Definition: v8.h:2786
void(* GenericNamedPropertySetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5517
V8_INLINE Local< Object > This() const
Definition: v8.h:9926
Definition: v8.h:4943
AllocationMode
Definition: v8.h:4618
Definition: v8.h:5220
Definition: v8.h:5235
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:1269
Definition: v8.h:3162
PromiseState
Definition: v8.h:4186
V8_INLINE void Reset()
Definition: v8.h:9685
Definition: v8.h:5251
Definition: v8.h:3176
Definition: v8.h:1260
AccessControl
Definition: v8.h:3287
Definition: v8-util.h:354
Global Pass()
Definition: v8.h:927
Definition: v8.h:4977
V8_INLINE Isolate * GetIsolate() const
Definition: v8.h:9950
PropertyFilter
Definition: v8.h:3297
ResourceConstraints constraints
Definition: v8.h:7258
Definition: v8.h:3787
Definition: v8.h:3147
Definition: v8.h:9557
V8_INLINE Local< Value > GetInternalField(int index)
Definition: v8.h:10082
void SetIndexedPropertyHandler(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter=0, IndexedPropertyQueryCallback query=0, IndexedPropertyDeleterCallback deleter=0, IndexedPropertyEnumeratorCallback enumerator=0, Local< Value > data=Local< Value >())
Definition: v8.h:6191
Definition: v8.h:152
Definition: v8.h:194
Definition: v8.h:119
V8_INLINE ~Persistent()
Definition: v8.h:837
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:5978