v8  7.4.288(node12.0.0)
V8 is Google's open source JavaScript engine
v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "v8-internal.h" // NOLINT(build/include)
26 #include "v8-version.h" // NOLINT(build/include)
27 #include "v8config.h" // NOLINT(build/include)
28 
29 // We reserve the V8_* prefix for macros defined in V8 public API and
30 // assume there are no name conflicts with the embedder's code.
31 
35 namespace v8 {
36 
37 class AccessorSignature;
38 class Array;
39 class ArrayBuffer;
40 class BigInt;
41 class BigIntObject;
42 class Boolean;
43 class BooleanObject;
44 class Context;
45 class Data;
46 class Date;
47 class External;
48 class Function;
49 class FunctionTemplate;
50 class HeapProfiler;
51 class ImplementationUtilities;
52 class Int32;
53 class Integer;
54 class Isolate;
55 template <class T>
56 class Maybe;
57 class MicrotaskQueue;
58 class Name;
59 class Number;
60 class NumberObject;
61 class Object;
62 class ObjectOperationDescriptor;
63 class ObjectTemplate;
64 class Platform;
65 class Primitive;
66 class Promise;
67 class PropertyDescriptor;
68 class Proxy;
69 class RawOperationDescriptor;
70 class Script;
71 class SharedArrayBuffer;
72 class Signature;
73 class StartupData;
74 class StackFrame;
75 class StackTrace;
76 class String;
77 class StringObject;
78 class Symbol;
79 class SymbolObject;
80 class PrimitiveArray;
81 class Private;
82 class Uint32;
83 class Utils;
84 class Value;
85 class WasmModuleObject;
86 template <class T> class Local;
87 template <class T>
88 class MaybeLocal;
89 template <class T> class Eternal;
90 template<class T> class NonCopyablePersistentTraits;
91 template<class T> class PersistentBase;
92 template <class T, class M = NonCopyablePersistentTraits<T> >
93 class Persistent;
94 template <class T>
95 class Global;
96 template <class T>
98 template<class K, class V, class T> class PersistentValueMap;
99 template <class K, class V, class T>
101 template <class K, class V, class T>
102 class GlobalValueMap;
103 template<class V, class T> class PersistentValueVector;
104 template<class T, class P> class WeakCallbackObject;
105 class FunctionTemplate;
106 class ObjectTemplate;
107 template<typename T> class FunctionCallbackInfo;
108 template<typename T> class PropertyCallbackInfo;
109 class StackTrace;
110 class StackFrame;
111 class Isolate;
112 class CallHandlerHelper;
114 template<typename T> class ReturnValue;
115 
116 namespace internal {
117 class Arguments;
118 class DeferredHandles;
119 class Heap;
120 class HeapObject;
121 class Isolate;
122 class LocalEmbedderHeapTracer;
123 class MicrotaskQueue;
124 class NeverReadOnlySpaceObject;
125 struct ScriptStreamingData;
126 template<typename T> class CustomArguments;
127 class PropertyCallbackArguments;
128 class FunctionCallbackArguments;
129 class GlobalHandles;
130 class ScopedExternalStringLock;
131 
132 namespace wasm {
133 class NativeModule;
134 class StreamingDecoder;
135 } // namespace wasm
136 
137 } // namespace internal
138 
139 namespace debug {
140 class ConsoleCallArguments;
141 } // namespace debug
142 
143 // --- Handles ---
144 
145 #define TYPE_CHECK(T, S) \
146  while (false) { \
147  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
148  }
149 
181 template <class T>
182 class Local {
183  public:
184  V8_INLINE Local() : val_(nullptr) {}
185  template <class S>
187  : val_(reinterpret_cast<T*>(*that)) {
193  TYPE_CHECK(T, S);
194  }
195 
199  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
200 
204  V8_INLINE void Clear() { val_ = nullptr; }
205 
206  V8_INLINE T* operator->() const { return val_; }
207 
208  V8_INLINE T* operator*() const { return val_; }
209 
216  template <class S>
217  V8_INLINE bool operator==(const Local<S>& that) const {
218  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
219  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
220  if (a == nullptr) return b == nullptr;
221  if (b == nullptr) return false;
222  return *a == *b;
223  }
224 
225  template <class S> V8_INLINE bool operator==(
226  const PersistentBase<S>& that) const {
227  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
228  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
229  if (a == nullptr) return b == nullptr;
230  if (b == nullptr) return false;
231  return *a == *b;
232  }
233 
240  template <class S>
241  V8_INLINE bool operator!=(const Local<S>& that) const {
242  return !operator==(that);
243  }
244 
245  template <class S> V8_INLINE bool operator!=(
246  const Persistent<S>& that) const {
247  return !operator==(that);
248  }
249 
255  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
256 #ifdef V8_ENABLE_CHECKS
257  // If we're going to perform the type check then we have to check
258  // that the handle isn't empty before doing the checked cast.
259  if (that.IsEmpty()) return Local<T>();
260 #endif
261  return Local<T>(T::Cast(*that));
262  }
263 
269  template <class S>
271  return Local<S>::Cast(*this);
272  }
273 
279  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
280  V8_INLINE static Local<T> New(Isolate* isolate,
281  const PersistentBase<T>& that);
282  V8_INLINE static Local<T> New(Isolate* isolate, const TracedGlobal<T>& that);
283 
284  private:
285  friend class Utils;
286  template<class F> friend class Eternal;
287  template<class F> friend class PersistentBase;
288  template<class F, class M> friend class Persistent;
289  template<class F> friend class Local;
290  template <class F>
291  friend class MaybeLocal;
292  template<class F> friend class FunctionCallbackInfo;
293  template<class F> friend class PropertyCallbackInfo;
294  friend class String;
295  friend class Object;
296  friend class Context;
297  friend class Isolate;
298  friend class Private;
299  template<class F> friend class internal::CustomArguments;
300  friend Local<Primitive> Undefined(Isolate* isolate);
301  friend Local<Primitive> Null(Isolate* isolate);
302  friend Local<Boolean> True(Isolate* isolate);
303  friend Local<Boolean> False(Isolate* isolate);
304  friend class HandleScope;
305  friend class EscapableHandleScope;
306  template <class F1, class F2, class F3>
308  template<class F1, class F2> friend class PersistentValueVector;
309  template <class F>
310  friend class ReturnValue;
311  template <class F>
312  friend class TracedGlobal;
313 
314  explicit V8_INLINE Local(T* that) : val_(that) {}
315  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
316  T* val_;
317 };
318 
319 
320 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
321 // Handle is an alias for Local for historical reasons.
322 template <class T>
323 using Handle = Local<T>;
324 #endif
325 
326 
337 template <class T>
338 class MaybeLocal {
339  public:
340  V8_INLINE MaybeLocal() : val_(nullptr) {}
341  template <class S>
343  : val_(reinterpret_cast<T*>(*that)) {
344  TYPE_CHECK(T, S);
345  }
346 
347  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
348 
353  template <class S>
355  out->val_ = IsEmpty() ? nullptr : this->val_;
356  return !IsEmpty();
357  }
358 
364 
369  template <class S>
370  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
371  return IsEmpty() ? default_value : Local<S>(val_);
372  }
373 
374  private:
375  T* val_;
376 };
377 
382 template <class T> class Eternal {
383  public:
384  V8_INLINE Eternal() : val_(nullptr) {}
385  template <class S>
386  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
387  Set(isolate, handle);
388  }
389  // Can only be safely called if already set.
390  V8_INLINE Local<T> Get(Isolate* isolate) const;
391  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
392  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
393 
394  private:
395  T* val_;
396 };
397 
398 
399 static const int kInternalFieldsInWeakCallback = 2;
400 static const int kEmbedderFieldsInWeakCallback = 2;
401 
402 template <typename T>
404  public:
405  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
406 
407  WeakCallbackInfo(Isolate* isolate, T* parameter,
408  void* embedder_fields[kEmbedderFieldsInWeakCallback],
409  Callback* callback)
410  : isolate_(isolate), parameter_(parameter), callback_(callback) {
411  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
412  embedder_fields_[i] = embedder_fields[i];
413  }
414  }
415 
416  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
417  V8_INLINE T* GetParameter() const { return parameter_; }
418  V8_INLINE void* GetInternalField(int index) const;
419 
420  // When first called, the embedder MUST Reset() the Global which triggered the
421  // callback. The Global itself is unusable for anything else. No v8 other api
422  // calls may be called in the first callback. Should additional work be
423  // required, the embedder must set a second pass callback, which will be
424  // called after all the initial callbacks are processed.
425  // Calling SetSecondPassCallback on the second pass will immediately crash.
426  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
427 
428  private:
429  Isolate* isolate_;
430  T* parameter_;
431  Callback* callback_;
432  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
433 };
434 
435 
436 // kParameter will pass a void* parameter back to the callback, kInternalFields
437 // will pass the first two internal fields back to the callback, kFinalizer
438 // will pass a void* parameter back, but is invoked before the object is
439 // actually collected, so it can be resurrected. In the last case, it is not
440 // possible to request a second pass callback.
442 
456 template <class T> class PersistentBase {
457  public:
462  V8_INLINE void Reset();
467  template <class S>
468  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
469 
474  template <class S>
475  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
476 
477  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
478  V8_INLINE void Empty() { val_ = 0; }
479 
480  V8_INLINE Local<T> Get(Isolate* isolate) const {
481  return Local<T>::New(isolate, *this);
482  }
483 
484  template <class S>
485  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
486  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
487  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
488  if (a == nullptr) return b == nullptr;
489  if (b == nullptr) return false;
490  return *a == *b;
491  }
492 
493  template <class S>
494  V8_INLINE bool operator==(const Local<S>& that) const {
495  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
496  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
497  if (a == nullptr) return b == nullptr;
498  if (b == nullptr) return false;
499  return *a == *b;
500  }
501 
502  template <class S>
503  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
504  return !operator==(that);
505  }
506 
507  template <class S>
508  V8_INLINE bool operator!=(const Local<S>& that) const {
509  return !operator==(that);
510  }
511 
519  template <typename P>
520  V8_INLINE void SetWeak(P* parameter,
521  typename WeakCallbackInfo<P>::Callback callback,
522  WeakCallbackType type);
523 
531  V8_INLINE void SetWeak();
532 
533  template<typename P>
534  V8_INLINE P* ClearWeak();
535 
536  // TODO(dcarney): remove this.
537  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
538 
545  V8_INLINE void AnnotateStrongRetainer(const char* label);
546 
553  "Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference",
554  V8_INLINE void RegisterExternalReference(Isolate* isolate) const);
555 
563  "Weak objects are always considered independent. "
564  "Use TracedGlobal when trying to use EmbedderHeapTracer. "
565  "Use a strong handle when trying to keep an object alive.",
566  V8_INLINE void MarkIndependent());
567 
575  V8_DEPRECATE_SOON("Use TracedGlobal.", V8_INLINE void MarkActive());
576 
577  V8_DEPRECATED("See MarkIndependent.", V8_INLINE bool IsIndependent() const);
578 
580  V8_DEPRECATED("Garbage collection internal state should not be relied on.",
581  V8_INLINE bool IsNearDeath() const);
582 
584  V8_INLINE bool IsWeak() const;
585 
589  V8_INLINE void SetWrapperClassId(uint16_t class_id);
590 
595  V8_INLINE uint16_t WrapperClassId() const;
596 
597  PersistentBase(const PersistentBase& other) = delete; // NOLINT
598  void operator=(const PersistentBase&) = delete;
599 
600  private:
601  friend class Isolate;
602  friend class Utils;
603  template<class F> friend class Local;
604  template<class F1, class F2> friend class Persistent;
605  template <class F>
606  friend class Global;
607  template<class F> friend class PersistentBase;
608  template<class F> friend class ReturnValue;
609  template <class F1, class F2, class F3>
611  template<class F1, class F2> friend class PersistentValueVector;
612  friend class Object;
613 
614  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
615  V8_INLINE static T* New(Isolate* isolate, T* that);
616 
617  T* val_;
618 };
619 
620 
627 template<class T>
628 class NonCopyablePersistentTraits {
629  public:
631  static const bool kResetInDestructor = false;
632  template<class S, class M>
633  V8_INLINE static void Copy(const Persistent<S, M>& source,
634  NonCopyablePersistent* dest) {
635  Uncompilable<Object>();
636  }
637  // TODO(dcarney): come up with a good compile error here.
638  template<class O> V8_INLINE static void Uncompilable() {
639  TYPE_CHECK(O, Primitive);
640  }
641 };
642 
643 
648 template<class T>
651  static const bool kResetInDestructor = true;
652  template<class S, class M>
653  static V8_INLINE void Copy(const Persistent<S, M>& source,
654  CopyablePersistent* dest) {
655  // do nothing, just allow copy
656  }
657 };
658 
659 
668 template <class T, class M> class Persistent : public PersistentBase<T> {
669  public:
679  template <class S>
681  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
682  TYPE_CHECK(T, S);
683  }
689  template <class S, class M2>
691  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
692  TYPE_CHECK(T, S);
693  }
700  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(nullptr) {
701  Copy(that);
702  }
703  template <class S, class M2>
705  Copy(that);
706  }
708  Copy(that);
709  return *this;
710  }
711  template <class S, class M2>
713  Copy(that);
714  return *this;
715  }
722  if (M::kResetInDestructor) this->Reset();
723  }
724 
725  // TODO(dcarney): this is pretty useless, fix or remove
726  template <class S>
727  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
728 #ifdef V8_ENABLE_CHECKS
729  // If we're going to perform the type check then we have to check
730  // that the handle isn't empty before doing the checked cast.
731  if (!that.IsEmpty()) T::Cast(*that);
732 #endif
733  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
734  }
735 
736  // TODO(dcarney): this is pretty useless, fix or remove
737  template <class S>
738  V8_INLINE Persistent<S>& As() const { // NOLINT
739  return Persistent<S>::Cast(*this);
740  }
741 
742  private:
743  friend class Isolate;
744  friend class Utils;
745  template<class F> friend class Local;
746  template<class F1, class F2> friend class Persistent;
747  template<class F> friend class ReturnValue;
748 
749  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
750  V8_INLINE T* operator*() const { return this->val_; }
751  template<class S, class M2>
752  V8_INLINE void Copy(const Persistent<S, M2>& that);
753 };
754 
755 
761 template <class T>
762 class Global : public PersistentBase<T> {
763  public:
767  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
768 
774  template <class S>
776  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
777  TYPE_CHECK(T, S);
778  }
779 
785  template <class S>
786  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
787  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
788  TYPE_CHECK(T, S);
789  }
790 
794  V8_INLINE Global(Global&& other);
795 
796  V8_INLINE ~Global() { this->Reset(); }
797 
801  template <class S>
803 
807  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
808 
809  /*
810  * For compatibility with Chromium's base::Bind (base::Passed).
811  */
812  typedef void MoveOnlyTypeForCPP03;
813 
814  Global(const Global&) = delete;
815  void operator=(const Global&) = delete;
816 
817  private:
818  template <class F>
819  friend class ReturnValue;
820  V8_INLINE T* operator*() const { return this->val_; }
821 };
822 
823 
824 // UniquePersistent is an alias for Global for historical reason.
825 template <class T>
827 
839 template <typename T>
840 class V8_EXPORT TracedGlobal {
841  public:
845  TracedGlobal() = default;
846  ~TracedGlobal() { Reset(); }
847 
854  template <class S>
855  TracedGlobal(Isolate* isolate, Local<S> that)
856  : val_(New(isolate, *that, &val_)) {
857  TYPE_CHECK(T, S);
858  }
859 
864 
868  template <class S>
869  V8_INLINE TracedGlobal& operator=(TracedGlobal<S>&& rhs);
870 
874  TracedGlobal(const TracedGlobal&) = delete;
875  void operator=(const TracedGlobal&) = delete;
876 
881  bool IsEmpty() const { return val_ == nullptr; }
882 
887  V8_INLINE void Reset();
888 
893  template <class S>
894  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
895 
899  Local<T> Get(Isolate* isolate) const { return Local<T>::New(isolate, *this); }
900 
901  template <class S>
903  return reinterpret_cast<TracedGlobal<S>&>(
904  const_cast<TracedGlobal<T>&>(*this));
905  }
906 
907  template <class S>
908  V8_INLINE bool operator==(const TracedGlobal<S>& that) const {
909  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
910  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
911  if (a == nullptr) return b == nullptr;
912  if (b == nullptr) return false;
913  return *a == *b;
914  }
915 
916  template <class S>
917  V8_INLINE bool operator==(const Local<S>& that) const {
918  internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
919  internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
920  if (a == nullptr) return b == nullptr;
921  if (b == nullptr) return false;
922  return *a == *b;
923  }
924 
925  template <class S>
926  V8_INLINE bool operator!=(const TracedGlobal<S>& that) const {
927  return !operator==(that);
928  }
929 
930  template <class S>
931  V8_INLINE bool operator!=(const Local<S>& that) const {
932  return !operator==(that);
933  }
934 
938  V8_INLINE void SetWrapperClassId(uint16_t class_id);
939 
944  V8_INLINE uint16_t WrapperClassId() const;
945 
956  V8_INLINE void SetFinalizationCallback(
957  void* parameter, WeakCallbackInfo<void>::Callback callback);
958 
959  private:
960  V8_INLINE static T* New(Isolate* isolate, T* that, T** slot);
961 
962  T* operator*() const { return this->val_; }
963 
964  T* val_ = nullptr;
965 
966  friend class EmbedderHeapTracer;
967  template <typename F>
968  friend class Local;
969  friend class Object;
970  template <typename F>
971  friend class ReturnValue;
972 };
973 
989  public:
990  explicit HandleScope(Isolate* isolate);
991 
992  ~HandleScope();
993 
997  static int NumberOfHandles(Isolate* isolate);
998 
1000  return reinterpret_cast<Isolate*>(isolate_);
1001  }
1002 
1003  HandleScope(const HandleScope&) = delete;
1004  void operator=(const HandleScope&) = delete;
1005 
1006  protected:
1007  V8_INLINE HandleScope() = default;
1008 
1009  void Initialize(Isolate* isolate);
1010 
1011  static internal::Address* CreateHandle(internal::Isolate* isolate,
1012  internal::Address value);
1013 
1014  private:
1015  // Declaring operator new and delete as deleted is not spec compliant.
1016  // Therefore declare them private instead to disable dynamic alloc
1017  void* operator new(size_t size);
1018  void* operator new[](size_t size);
1019  void operator delete(void*, size_t);
1020  void operator delete[](void*, size_t);
1021 
1022  internal::Isolate* isolate_;
1023  internal::Address* prev_next_;
1024  internal::Address* prev_limit_;
1025 
1026  // Local::New uses CreateHandle with an Isolate* parameter.
1027  template<class F> friend class Local;
1028 
1029  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
1030  // a HeapObject in their shortcuts.
1031  friend class Object;
1032  friend class Context;
1033 };
1034 
1035 
1041  public:
1042  explicit EscapableHandleScope(Isolate* isolate);
1043  V8_INLINE ~EscapableHandleScope() = default;
1044 
1049  template <class T>
1051  internal::Address* slot =
1052  Escape(reinterpret_cast<internal::Address*>(*value));
1053  return Local<T>(reinterpret_cast<T*>(slot));
1054  }
1055 
1056  template <class T>
1058  return Escape(value.FromMaybe(Local<T>()));
1059  }
1060 
1061  EscapableHandleScope(const EscapableHandleScope&) = delete;
1062  void operator=(const EscapableHandleScope&) = delete;
1063 
1064  private:
1065  // Declaring operator new and delete as deleted is not spec compliant.
1066  // Therefore declare them private instead to disable dynamic alloc
1067  void* operator new(size_t size);
1068  void* operator new[](size_t size);
1069  void operator delete(void*, size_t);
1070  void operator delete[](void*, size_t);
1071 
1072  internal::Address* Escape(internal::Address* escape_value);
1073  internal::Address* escape_slot_;
1074 };
1075 
1082  public:
1083  explicit SealHandleScope(Isolate* isolate);
1084  ~SealHandleScope();
1085 
1086  SealHandleScope(const SealHandleScope&) = delete;
1087  void operator=(const SealHandleScope&) = delete;
1088 
1089  private:
1090  // Declaring operator new and delete as deleted is not spec compliant.
1091  // Therefore declare them private instead to disable dynamic alloc
1092  void* operator new(size_t size);
1093  void* operator new[](size_t size);
1094  void operator delete(void*, size_t);
1095  void operator delete[](void*, size_t);
1096 
1097  internal::Isolate* const isolate_;
1098  internal::Address* prev_limit_;
1099  int prev_sealed_level_;
1100 };
1101 
1102 
1103 // --- Special objects ---
1104 
1105 
1110  private:
1111  Data();
1112 };
1113 
1121  public:
1126  Local<Value> GetResourceName();
1127 
1132  Local<PrimitiveArray> GetHostDefinedOptions();
1133 };
1134 
1144  public:
1145  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1146  int Length() const;
1147  void Set(Isolate* isolate, int index, Local<Primitive> item);
1148  Local<Primitive> Get(Isolate* isolate, int index);
1149 };
1150 
1155  public:
1156  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1157  bool is_opaque = false, bool is_wasm = false,
1158  bool is_module = false)
1159  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1160  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1161  (is_module ? kIsModule : 0)) {}
1163  : flags_(flags &
1164  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1165 
1166  bool IsSharedCrossOrigin() const {
1167  return (flags_ & kIsSharedCrossOrigin) != 0;
1168  }
1169  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1170  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1171  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1172 
1173  int Flags() const { return flags_; }
1174 
1175  private:
1176  enum {
1177  kIsSharedCrossOrigin = 1,
1178  kIsOpaque = 1 << 1,
1179  kIsWasm = 1 << 2,
1180  kIsModule = 1 << 3
1181  };
1182  const int flags_;
1183 };
1184 
1189  public:
1191  Local<Value> resource_name,
1192  Local<Integer> resource_line_offset = Local<Integer>(),
1193  Local<Integer> resource_column_offset = Local<Integer>(),
1194  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1195  Local<Integer> script_id = Local<Integer>(),
1196  Local<Value> source_map_url = Local<Value>(),
1197  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1198  Local<Boolean> is_wasm = Local<Boolean>(),
1199  Local<Boolean> is_module = Local<Boolean>(),
1200  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
1201 
1208  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1209 
1210  private:
1211  Local<Value> resource_name_;
1212  Local<Integer> resource_line_offset_;
1213  Local<Integer> resource_column_offset_;
1214  ScriptOriginOptions options_;
1215  Local<Integer> script_id_;
1216  Local<Value> source_map_url_;
1217  Local<PrimitiveArray> host_defined_options_;
1218 };
1219 
1224  public:
1228  Local<Script> BindToCurrentContext();
1229 
1230  int GetId();
1231  Local<Value> GetScriptName();
1232 
1236  Local<Value> GetSourceURL();
1240  Local<Value> GetSourceMappingURL();
1241 
1246  int GetLineNumber(int code_pos);
1247 
1248  static const int kNoScriptId = 0;
1249 };
1250 
1255  // Only used as a container for code caching.
1256 };
1257 
1262  public:
1263  int GetLineNumber() { return line_number_; }
1264  int GetColumnNumber() { return column_number_; }
1265 
1266  Location(int line_number, int column_number)
1267  : line_number_(line_number), column_number_(column_number) {}
1268 
1269  private:
1270  int line_number_;
1271  int column_number_;
1272 };
1273 
1278  public:
1286  enum Status {
1292  kErrored
1293  };
1294 
1298  Status GetStatus() const;
1299 
1303  Local<Value> GetException() const;
1304 
1308  int GetModuleRequestsLength() const;
1309 
1314  Local<String> GetModuleRequest(int i) const;
1315 
1320  Location GetModuleRequestLocation(int i) const;
1321 
1325  int GetIdentityHash() const;
1326 
1327  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1328  Local<String> specifier,
1329  Local<Module> referrer);
1330 
1338  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1339  ResolveCallback callback);
1340 
1350 
1356  Local<Value> GetModuleNamespace();
1357 
1364  Local<UnboundModuleScript> GetUnboundModuleScript();
1365 };
1366 
1372  public:
1377  Local<Context> context, Local<String> source,
1378  ScriptOrigin* origin = nullptr);
1379 
1386 
1390  Local<UnboundScript> GetUnboundScript();
1391 };
1392 
1393 
1398  public:
1409  BufferOwned
1410  };
1411 
1413  : data(nullptr),
1414  length(0),
1415  rejected(false),
1416  buffer_policy(BufferNotOwned) {}
1417 
1418  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1419  // data and guarantees that it stays alive until the CachedData object is
1420  // destroyed. If the policy is BufferOwned, the given data will be deleted
1421  // (with delete[]) when the CachedData object is destroyed.
1422  CachedData(const uint8_t* data, int length,
1423  BufferPolicy buffer_policy = BufferNotOwned);
1424  ~CachedData();
1425  // TODO(marja): Async compilation; add constructors which take a callback
1426  // which will be called when V8 no longer needs the data.
1427  const uint8_t* data;
1428  int length;
1429  bool rejected;
1431 
1432  // Prevent copying.
1433  CachedData(const CachedData&) = delete;
1434  CachedData& operator=(const CachedData&) = delete;
1435  };
1436 
1440  class Source {
1441  public:
1442  // Source takes ownership of CachedData.
1443  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1444  CachedData* cached_data = nullptr);
1445  V8_INLINE Source(Local<String> source_string,
1446  CachedData* cached_data = nullptr);
1447  V8_INLINE ~Source();
1448 
1449  // Ownership of the CachedData or its buffers is *not* transferred to the
1450  // caller. The CachedData object is alive as long as the Source object is
1451  // alive.
1452  V8_INLINE const CachedData* GetCachedData() const;
1453 
1454  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1455 
1456  // Prevent copying.
1457  Source(const Source&) = delete;
1458  Source& operator=(const Source&) = delete;
1459 
1460  private:
1461  friend class ScriptCompiler;
1462 
1463  Local<String> source_string;
1464 
1465  // Origin information
1466  Local<Value> resource_name;
1467  Local<Integer> resource_line_offset;
1468  Local<Integer> resource_column_offset;
1469  ScriptOriginOptions resource_options;
1470  Local<Value> source_map_url;
1471  Local<PrimitiveArray> host_defined_options;
1472 
1473  // Cached data from previous compilation (if a kConsume*Cache flag is
1474  // set), or hold newly generated cache data (kProduce*Cache flags) are
1475  // set when calling a compile method.
1476  CachedData* cached_data;
1477  };
1478 
1484  public:
1485  virtual ~ExternalSourceStream() = default;
1486 
1508  virtual size_t GetMoreData(const uint8_t** src) = 0;
1509 
1520  virtual bool SetBookmark();
1521 
1525  virtual void ResetToBookmark();
1526  };
1527 
1535  public:
1536  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1537 
1538  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1539  ~StreamedSource();
1540 
1541  internal::ScriptStreamingData* impl() const { return impl_.get(); }
1542 
1543  // Prevent copying.
1544  StreamedSource(const StreamedSource&) = delete;
1545  StreamedSource& operator=(const StreamedSource&) = delete;
1546 
1547  private:
1548  std::unique_ptr<internal::ScriptStreamingData> impl_;
1549  };
1550 
1556  public:
1557  void Run();
1558 
1559  private:
1560  friend class ScriptCompiler;
1561 
1562  explicit ScriptStreamingTask(internal::ScriptStreamingData* data)
1563  : data_(data) {}
1564 
1565  internal::ScriptStreamingData* data_;
1566  };
1567 
1569  kNoCompileOptions = 0,
1571  kEagerCompile
1572  };
1573 
1578  kNoCacheNoReason = 0,
1592  kNoCacheBecauseDeferredProduceCodeCache
1593  };
1594 
1608  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1609  Isolate* isolate, Source* source,
1610  CompileOptions options = kNoCompileOptions,
1611  NoCacheReason no_cache_reason = kNoCacheNoReason);
1612 
1625  Local<Context> context, Source* source,
1626  CompileOptions options = kNoCompileOptions,
1627  NoCacheReason no_cache_reason = kNoCacheNoReason);
1628 
1640  static ScriptStreamingTask* StartStreamingScript(
1641  Isolate* isolate, StreamedSource* source,
1642  CompileOptions options = kNoCompileOptions);
1643 
1652  Local<Context> context, StreamedSource* source,
1653  Local<String> full_source_string, const ScriptOrigin& origin);
1654 
1673  static uint32_t CachedDataVersionTag();
1674 
1682  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1683  Isolate* isolate, Source* source,
1684  CompileOptions options = kNoCompileOptions,
1685  NoCacheReason no_cache_reason = kNoCacheNoReason);
1686 
1697  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1698  Local<Context> context, Source* source, size_t arguments_count,
1699  Local<String> arguments[], size_t context_extension_count,
1700  Local<Object> context_extensions[],
1701  CompileOptions options = kNoCompileOptions,
1702  NoCacheReason no_cache_reason = kNoCacheNoReason);
1703 
1709  static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
1710 
1716  static CachedData* CreateCodeCache(
1717  Local<UnboundModuleScript> unbound_module_script);
1718 
1725  static CachedData* CreateCodeCacheForFunction(Local<Function> function);
1726 
1727  private:
1728  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1729  Isolate* isolate, Source* source, CompileOptions options,
1730  NoCacheReason no_cache_reason);
1731 };
1732 
1733 
1738  public:
1739  Local<String> Get() const;
1740 
1744  Isolate* GetIsolate() const;
1745 
1747  Local<Context> context) const;
1748 
1753  ScriptOrigin GetScriptOrigin() const;
1754 
1759  Local<Value> GetScriptResourceName() const;
1760 
1766  Local<StackTrace> GetStackTrace() const;
1767 
1771  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1772 
1777  int GetStartPosition() const;
1778 
1783  int GetEndPosition() const;
1784 
1788  int ErrorLevel() const;
1789 
1794  int GetStartColumn() const;
1795  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1796 
1801  int GetEndColumn() const;
1802  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1803 
1808  bool IsSharedCrossOrigin() const;
1809  bool IsOpaque() const;
1810 
1811  // TODO(1245381): Print to a string instead of on a FILE.
1812  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1813 
1814  static const int kNoLineNumberInfo = 0;
1815  static const int kNoColumnInfo = 0;
1816  static const int kNoScriptIdInfo = 0;
1817 };
1818 
1819 
1826  public:
1834  kLineNumber = 1,
1835  kColumnOffset = 1 << 1 | kLineNumber,
1836  kScriptName = 1 << 2,
1837  kFunctionName = 1 << 3,
1838  kIsEval = 1 << 4,
1839  kIsConstructor = 1 << 5,
1840  kScriptNameOrSourceURL = 1 << 6,
1841  kScriptId = 1 << 7,
1842  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1843  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1844  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1845  };
1846 
1850  Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
1851 
1855  int GetFrameCount() const;
1856 
1864  static Local<StackTrace> CurrentStackTrace(
1865  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1866 };
1867 
1868 
1873  public:
1880  int GetLineNumber() const;
1881 
1889  int GetColumn() const;
1890 
1897  int GetScriptId() const;
1898 
1903  Local<String> GetScriptName() const;
1904 
1911  Local<String> GetScriptNameOrSourceURL() const;
1912 
1916  Local<String> GetFunctionName() const;
1917 
1922  bool IsEval() const;
1923 
1928  bool IsConstructor() const;
1929 
1933  bool IsWasm() const;
1934 };
1935 
1936 
1937 // A StateTag represents a possible state of the VM.
1938 enum StateTag {
1947 };
1948 
1949 // A RegisterState represents the current state of registers used
1950 // by the sampling profiler API.
1952  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1953  void* pc; // Instruction pointer.
1954  void* sp; // Stack pointer.
1955  void* fp; // Frame pointer.
1956 };
1957 
1958 // The output structure filled up by GetStackSample API function.
1959 struct SampleInfo {
1960  size_t frames_count; // Number of frames collected.
1961  StateTag vm_state; // Current VM state.
1962  void* external_callback_entry; // External callback address if VM is
1963  // executing an external callback.
1964 };
1965 
1966 struct MemoryRange {
1967  const void* start = nullptr;
1968  size_t length_in_bytes = 0;
1969 };
1970 
1971 struct JSEntryStub {
1973 };
1974 
1975 struct UnwindState {
1979 };
1980 
1985  public:
1995  Local<Context> context, Local<String> json_string);
1996 
2004  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
2005  Local<Context> context, Local<Value> json_object,
2006  Local<String> gap = Local<String>());
2007 };
2008 
2014  public:
2016  public:
2017  virtual ~Delegate() = default;
2018 
2024  virtual void ThrowDataCloneError(Local<String> message) = 0;
2025 
2031  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
2032 
2043  virtual Maybe<uint32_t> GetSharedArrayBufferId(
2044  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
2045 
2046  virtual Maybe<uint32_t> GetWasmModuleTransferId(
2047  Isolate* isolate, Local<WasmModuleObject> module);
2059  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
2060  size_t* actual_size);
2061 
2067  virtual void FreeBufferMemory(void* buffer);
2068  };
2069 
2070  explicit ValueSerializer(Isolate* isolate);
2071  ValueSerializer(Isolate* isolate, Delegate* delegate);
2072  ~ValueSerializer();
2073 
2077  void WriteHeader();
2078 
2083  Local<Value> value);
2084 
2091  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
2092 
2098  void TransferArrayBuffer(uint32_t transfer_id,
2099  Local<ArrayBuffer> array_buffer);
2100 
2101 
2109  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
2110 
2116  void WriteUint32(uint32_t value);
2117  void WriteUint64(uint64_t value);
2118  void WriteDouble(double value);
2119  void WriteRawBytes(const void* source, size_t length);
2120 
2121  private:
2122  ValueSerializer(const ValueSerializer&) = delete;
2123  void operator=(const ValueSerializer&) = delete;
2124 
2125  struct PrivateData;
2126  PrivateData* private_;
2127 };
2128 
2134  public:
2136  public:
2137  virtual ~Delegate() = default;
2138 
2144  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
2145 
2150  virtual MaybeLocal<WasmModuleObject> GetWasmModuleFromId(
2151  Isolate* isolate, uint32_t transfer_id);
2152 
2157  virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
2158  Isolate* isolate, uint32_t clone_id);
2159  };
2160 
2161  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2162  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2163  Delegate* delegate);
2164  ~ValueDeserializer();
2165 
2170  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2171 
2176 
2181  void TransferArrayBuffer(uint32_t transfer_id,
2182  Local<ArrayBuffer> array_buffer);
2183 
2189  void TransferSharedArrayBuffer(uint32_t id,
2190  Local<SharedArrayBuffer> shared_array_buffer);
2191 
2199  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2200 
2204  void SetExpectInlineWasm(bool allow_inline_wasm);
2205 
2211  uint32_t GetWireFormatVersion() const;
2212 
2218  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2219  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2220  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2221  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2222 
2223  private:
2224  ValueDeserializer(const ValueDeserializer&) = delete;
2225  void operator=(const ValueDeserializer&) = delete;
2226 
2227  struct PrivateData;
2228  PrivateData* private_;
2229 };
2230 
2231 
2232 // --- Value ---
2233 
2234 
2238 class V8_EXPORT Value : public Data {
2239  public:
2244  V8_INLINE bool IsUndefined() const;
2245 
2250  V8_INLINE bool IsNull() const;
2251 
2257  V8_INLINE bool IsNullOrUndefined() const;
2258 
2262  bool IsTrue() const;
2263 
2267  bool IsFalse() const;
2268 
2272  bool IsName() const;
2273 
2278  V8_INLINE bool IsString() const;
2279 
2283  bool IsSymbol() const;
2284 
2288  bool IsFunction() const;
2289 
2294  bool IsArray() const;
2295 
2299  bool IsObject() const;
2300 
2304  bool IsBigInt() const;
2305 
2309  bool IsBoolean() const;
2310 
2314  bool IsNumber() const;
2315 
2319  bool IsExternal() const;
2320 
2324  bool IsInt32() const;
2325 
2329  bool IsUint32() const;
2330 
2334  bool IsDate() const;
2335 
2339  bool IsArgumentsObject() const;
2340 
2344  bool IsBigIntObject() const;
2345 
2349  bool IsBooleanObject() const;
2350 
2354  bool IsNumberObject() const;
2355 
2359  bool IsStringObject() const;
2360 
2364  bool IsSymbolObject() const;
2365 
2369  bool IsNativeError() const;
2370 
2374  bool IsRegExp() const;
2375 
2379  bool IsAsyncFunction() const;
2380 
2384  bool IsGeneratorFunction() const;
2385 
2389  bool IsGeneratorObject() const;
2390 
2394  bool IsPromise() const;
2395 
2399  bool IsMap() const;
2400 
2404  bool IsSet() const;
2405 
2409  bool IsMapIterator() const;
2410 
2414  bool IsSetIterator() const;
2415 
2419  bool IsWeakMap() const;
2420 
2424  bool IsWeakSet() const;
2425 
2429  bool IsArrayBuffer() const;
2430 
2434  bool IsArrayBufferView() const;
2435 
2439  bool IsTypedArray() const;
2440 
2444  bool IsUint8Array() const;
2445 
2449  bool IsUint8ClampedArray() const;
2450 
2454  bool IsInt8Array() const;
2455 
2459  bool IsUint16Array() const;
2460 
2464  bool IsInt16Array() const;
2465 
2469  bool IsUint32Array() const;
2470 
2474  bool IsInt32Array() const;
2475 
2479  bool IsFloat32Array() const;
2480 
2484  bool IsFloat64Array() const;
2485 
2489  bool IsBigInt64Array() const;
2490 
2494  bool IsBigUint64Array() const;
2495 
2499  bool IsDataView() const;
2500 
2505  bool IsSharedArrayBuffer() const;
2506 
2510  bool IsProxy() const;
2511 
2512  bool IsWebAssemblyCompiledModule() const;
2513 
2517  bool IsModuleNamespaceObject() const;
2518 
2520  Local<Context> context) const;
2521  V8_DEPRECATE_SOON("ToBoolean can never throw. Use Local version.",
2523  Local<Context> context) const);
2525  Local<Context> context) const;
2527  Local<Context> context) const;
2529  Local<Context> context) const;
2531  Local<Context> context) const;
2533  Local<Context> context) const;
2535  Local<Context> context) const;
2537 
2538  Local<Boolean> ToBoolean(Isolate* isolate) const;
2539  V8_DEPRECATE_SOON("Use maybe version",
2540  Local<Number> ToNumber(Isolate* isolate) const);
2541  V8_DEPRECATE_SOON("Use maybe version",
2542  Local<String> ToString(Isolate* isolate) const);
2543  V8_DEPRECATE_SOON("Use maybe version",
2544  Local<Object> ToObject(Isolate* isolate) const);
2545  V8_DEPRECATE_SOON("Use maybe version",
2546  Local<Integer> ToInteger(Isolate* isolate) const);
2547  V8_DEPRECATE_SOON("Use maybe version",
2548  Local<Int32> ToInt32(Isolate* isolate) const);
2549 
2555  Local<Context> context) const;
2556 
2557  bool BooleanValue(Isolate* isolate) const;
2558 
2559  V8_DEPRECATED("BooleanValue can never throw. Use Isolate version.",
2560  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(
2561  Local<Context> context) const);
2562  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2564  Local<Context> context) const;
2566  Local<Context> context) const;
2567  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2568 
2571  Local<Value> that) const;
2572  bool StrictEquals(Local<Value> that) const;
2573  bool SameValue(Local<Value> that) const;
2574 
2575  template <class T> V8_INLINE static Value* Cast(T* value);
2576 
2577  Local<String> TypeOf(Isolate*);
2578 
2579  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2580 
2581  private:
2582  V8_INLINE bool QuickIsUndefined() const;
2583  V8_INLINE bool QuickIsNull() const;
2584  V8_INLINE bool QuickIsNullOrUndefined() const;
2585  V8_INLINE bool QuickIsString() const;
2586  bool FullIsUndefined() const;
2587  bool FullIsNull() const;
2588  bool FullIsString() const;
2589 };
2590 
2591 
2595 class V8_EXPORT Primitive : public Value { };
2596 
2597 
2602 class V8_EXPORT Boolean : public Primitive {
2603  public:
2604  bool Value() const;
2605  V8_INLINE static Boolean* Cast(v8::Value* obj);
2606  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2607 
2608  private:
2609  static void CheckCast(v8::Value* obj);
2610 };
2611 
2612 
2616 class V8_EXPORT Name : public Primitive {
2617  public:
2625  int GetIdentityHash();
2626 
2627  V8_INLINE static Name* Cast(Value* obj);
2628 
2629  private:
2630  static void CheckCast(Value* obj);
2631 };
2632 
2639 enum class NewStringType {
2643  kNormal,
2644 
2651 };
2652 
2656 class V8_EXPORT String : public Name {
2657  public:
2658  static constexpr int kMaxLength = internal::kApiTaggedSize == 4
2659  ? (1 << 28) - 16
2660  : internal::kSmiMaxValue / 2 - 24;
2661 
2662  enum Encoding {
2663  UNKNOWN_ENCODING = 0x1,
2664  TWO_BYTE_ENCODING = 0x0,
2665  ONE_BYTE_ENCODING = 0x8
2666  };
2670  int Length() const;
2671 
2676  int Utf8Length(Isolate* isolate) const;
2677 
2684  bool IsOneByte() const;
2685 
2691  bool ContainsOnlyOneByte() const;
2692 
2719  NO_OPTIONS = 0,
2720  HINT_MANY_WRITES_EXPECTED = 1,
2721  NO_NULL_TERMINATION = 2,
2722  PRESERVE_ONE_BYTE_NULL = 4,
2723  // Used by WriteUtf8 to replace orphan surrogate code units with the
2724  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2725  // output.
2726  REPLACE_INVALID_UTF8 = 8
2727  };
2728 
2729  // 16-bit character codes.
2730  int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
2731  int options = NO_OPTIONS) const;
2732  // One byte characters.
2733  int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
2734  int length = -1, int options = NO_OPTIONS) const;
2735  // UTF-8 encoded characters.
2736  int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
2737  int* nchars_ref = nullptr, int options = NO_OPTIONS) const;
2738 
2742  V8_INLINE static Local<String> Empty(Isolate* isolate);
2743 
2747  bool IsExternal() const;
2748 
2752  bool IsExternalOneByte() const;
2753 
2755  public:
2756  virtual ~ExternalStringResourceBase() = default;
2757 
2763  virtual bool IsCacheable() const { return true; }
2764 
2765  protected:
2766  ExternalStringResourceBase() = default;
2767 
2774  virtual void Dispose() { delete this; }
2775 
2787  virtual void Lock() const {}
2788 
2792  virtual void Unlock() const {}
2793 
2794  // Disallow copying and assigning.
2796  void operator=(const ExternalStringResourceBase&) = delete;
2797 
2798  private:
2799  friend class internal::Heap;
2800  friend class v8::String;
2801  friend class internal::ScopedExternalStringLock;
2802  };
2803 
2811  : public ExternalStringResourceBase {
2812  public:
2817  ~ExternalStringResource() override = default;
2818 
2822  virtual const uint16_t* data() const = 0;
2823 
2827  virtual size_t length() const = 0;
2828 
2829  protected:
2830  ExternalStringResource() = default;
2831  };
2832 
2844  : public ExternalStringResourceBase {
2845  public:
2850  ~ExternalOneByteStringResource() override = default;
2852  virtual const char* data() const = 0;
2854  virtual size_t length() const = 0;
2855  protected:
2856  ExternalOneByteStringResource() = default;
2857  };
2858 
2864  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2865  Encoding* encoding_out) const;
2866 
2871  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2872 
2877  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2878 
2879  V8_INLINE static String* Cast(v8::Value* obj);
2880 
2881  // TODO(dcarney): remove with deprecation of New functions.
2883  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2884  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2885  };
2886 
2888  static V8_DEPRECATED(
2889  "Use maybe version",
2890  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2891  NewStringType type = kNormalString,
2892  int length = -1));
2893 
2896  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2897  Isolate* isolate, const char* data, v8::NewStringType type,
2898  int length = -1);
2899 
2902  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2903  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2904  int length = -1);
2905 
2907  static V8_DEPRECATE_SOON(
2908  "Use maybe version",
2909  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2910  NewStringType type = kNormalString,
2911  int length = -1));
2912 
2915  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2916  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2917  int length = -1);
2918 
2923  static Local<String> Concat(Isolate* isolate, Local<String> left,
2924  Local<String> right);
2925 
2934  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2935  Isolate* isolate, ExternalStringResource* resource);
2936 
2946  bool MakeExternal(ExternalStringResource* resource);
2947 
2956  static V8_DEPRECATE_SOON(
2957  "Use maybe version",
2958  Local<String> NewExternal(Isolate* isolate,
2959  ExternalOneByteStringResource* resource));
2960  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2961  Isolate* isolate, ExternalOneByteStringResource* resource);
2962 
2972  bool MakeExternal(ExternalOneByteStringResource* resource);
2973 
2977  bool CanMakeExternal();
2978 
2982  bool StringEquals(Local<String> str);
2983 
2992  public:
2993  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2994  ~Utf8Value();
2995  char* operator*() { return str_; }
2996  const char* operator*() const { return str_; }
2997  int length() const { return length_; }
2998 
2999  // Disallow copying and assigning.
3000  Utf8Value(const Utf8Value&) = delete;
3001  void operator=(const Utf8Value&) = delete;
3002 
3003  private:
3004  char* str_;
3005  int length_;
3006  };
3007 
3015  public:
3016  Value(Isolate* isolate, Local<v8::Value> obj);
3017  ~Value();
3018  uint16_t* operator*() { return str_; }
3019  const uint16_t* operator*() const { return str_; }
3020  int length() const { return length_; }
3021 
3022  // Disallow copying and assigning.
3023  Value(const Value&) = delete;
3024  void operator=(const Value&) = delete;
3025 
3026  private:
3027  uint16_t* str_;
3028  int length_;
3029  };
3030 
3031  private:
3032  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
3033  Encoding encoding) const;
3034  void VerifyExternalStringResource(ExternalStringResource* val) const;
3035  ExternalStringResource* GetExternalStringResourceSlow() const;
3036  ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
3037  String::Encoding* encoding_out) const;
3038 
3039  static void CheckCast(v8::Value* obj);
3040 };
3041 
3042 
3046 class V8_EXPORT Symbol : public Name {
3047  public:
3051  Local<Value> Name() const;
3052 
3056  static Local<Symbol> New(Isolate* isolate,
3057  Local<String> name = Local<String>());
3058 
3066  static Local<Symbol> For(Isolate *isolate, Local<String> name);
3067 
3072  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
3073 
3074  // Well-known symbols
3075  static Local<Symbol> GetAsyncIterator(Isolate* isolate);
3076  static Local<Symbol> GetHasInstance(Isolate* isolate);
3077  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
3078  static Local<Symbol> GetIterator(Isolate* isolate);
3079  static Local<Symbol> GetMatch(Isolate* isolate);
3080  static Local<Symbol> GetReplace(Isolate* isolate);
3081  static Local<Symbol> GetSearch(Isolate* isolate);
3082  static Local<Symbol> GetSplit(Isolate* isolate);
3083  static Local<Symbol> GetToPrimitive(Isolate* isolate);
3084  static Local<Symbol> GetToStringTag(Isolate* isolate);
3085  static Local<Symbol> GetUnscopables(Isolate* isolate);
3086 
3087  V8_INLINE static Symbol* Cast(Value* obj);
3088 
3089  private:
3090  Symbol();
3091  static void CheckCast(Value* obj);
3092 };
3093 
3094 
3100 class V8_EXPORT Private : public Data {
3101  public:
3105  Local<Value> Name() const;
3106 
3110  static Local<Private> New(Isolate* isolate,
3111  Local<String> name = Local<String>());
3112 
3122  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
3123 
3124  V8_INLINE static Private* Cast(Data* data);
3125 
3126  private:
3127  Private();
3128 
3129  static void CheckCast(Data* that);
3130 };
3131 
3132 
3136 class V8_EXPORT Number : public Primitive {
3137  public:
3138  double Value() const;
3139  static Local<Number> New(Isolate* isolate, double value);
3140  V8_INLINE static Number* Cast(v8::Value* obj);
3141  private:
3142  Number();
3143  static void CheckCast(v8::Value* obj);
3144 };
3145 
3146 
3150 class V8_EXPORT Integer : public Number {
3151  public:
3152  static Local<Integer> New(Isolate* isolate, int32_t value);
3153  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
3154  int64_t Value() const;
3155  V8_INLINE static Integer* Cast(v8::Value* obj);
3156  private:
3157  Integer();
3158  static void CheckCast(v8::Value* obj);
3159 };
3160 
3161 
3165 class V8_EXPORT Int32 : public Integer {
3166  public:
3167  int32_t Value() const;
3168  V8_INLINE static Int32* Cast(v8::Value* obj);
3169 
3170  private:
3171  Int32();
3172  static void CheckCast(v8::Value* obj);
3173 };
3174 
3175 
3179 class V8_EXPORT Uint32 : public Integer {
3180  public:
3181  uint32_t Value() const;
3182  V8_INLINE static Uint32* Cast(v8::Value* obj);
3183 
3184  private:
3185  Uint32();
3186  static void CheckCast(v8::Value* obj);
3187 };
3188 
3192 class V8_EXPORT BigInt : public Primitive {
3193  public:
3194  static Local<BigInt> New(Isolate* isolate, int64_t value);
3195  static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
3203  static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
3204  int word_count, const uint64_t* words);
3205 
3212  uint64_t Uint64Value(bool* lossless = nullptr) const;
3213 
3219  int64_t Int64Value(bool* lossless = nullptr) const;
3220 
3225  int WordCount() const;
3226 
3235  void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
3236 
3237  V8_INLINE static BigInt* Cast(v8::Value* obj);
3238 
3239  private:
3240  BigInt();
3241  static void CheckCast(v8::Value* obj);
3242 };
3243 
3249  None = 0,
3251  ReadOnly = 1 << 0,
3253  DontEnum = 1 << 1,
3255  DontDelete = 1 << 2
3256 };
3257 
3263 typedef void (*AccessorGetterCallback)(
3264  Local<String> property,
3265  const PropertyCallbackInfo<Value>& info);
3267  Local<Name> property,
3268  const PropertyCallbackInfo<Value>& info);
3269 
3270 
3271 typedef void (*AccessorSetterCallback)(
3272  Local<String> property,
3273  Local<Value> value,
3274  const PropertyCallbackInfo<void>& info);
3276  Local<Name> property,
3277  Local<Value> value,
3278  const PropertyCallbackInfo<void>& info);
3279 
3280 
3291  DEFAULT = 0,
3293  ALL_CAN_WRITE = 1 << 1,
3295 };
3296 
3307 };
3308 
3319 enum class SideEffectType {
3323 };
3324 
3333 
3339 
3345 
3350 
3354 class V8_EXPORT Object : public Value {
3355  public:
3356  V8_DEPRECATE_SOON("Use maybe version",
3357  bool Set(Local<Value> key, Local<Value> value));
3363  Local<Value> key, Local<Value> value);
3364 
3365  V8_DEPRECATE_SOON("Use maybe version",
3366  bool Set(uint32_t index, Local<Value> value));
3367  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3368  Local<Value> value);
3369 
3370  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3371  //
3372  // Defines a configurable, writable, enumerable property with the given value
3373  // on the object unless the property already exists and is not configurable
3374  // or the object is not extensible.
3375  //
3376  // Returns true on success.
3377  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3378  Local<Name> key,
3379  Local<Value> value);
3380  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3381  uint32_t index,
3382  Local<Value> value);
3383 
3384  // Implements DefineOwnProperty.
3385  //
3386  // In general, CreateDataProperty will be faster, however, does not allow
3387  // for specifying attributes.
3388  //
3389  // Returns true on success.
3390  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3391  Local<Context> context, Local<Name> key, Local<Value> value,
3392  PropertyAttribute attributes = None);
3393 
3394  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3395  //
3396  // The defineProperty function is used to add an own property or
3397  // update the attributes of an existing own property of an object.
3398  //
3399  // Both data and accessor descriptors can be used.
3400  //
3401  // In general, CreateDataProperty is faster, however, does not allow
3402  // for specifying attributes or an accessor descriptor.
3403  //
3404  // The PropertyDescriptor can change when redefining a property.
3405  //
3406  // Returns true on success.
3407  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3408  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3409 
3410  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3412  Local<Value> key);
3413 
3414  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3416  uint32_t index);
3417 
3423  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3424  Local<Context> context, Local<Value> key);
3425 
3429  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3430  Local<Context> context, Local<Name> key);
3431 
3448  Local<Value> key);
3449 
3451  Local<Value> key);
3452 
3453  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3454 
3456  uint32_t index);
3457 
3461  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
3462  Local<Context> context, Local<Name> name,
3464  AccessorNameSetterCallback setter = nullptr,
3466  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
3467  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3468  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3469 
3470  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3471  Local<Function> setter = Local<Function>(),
3472  PropertyAttribute attribute = None,
3473  AccessControl settings = DEFAULT);
3474 
3479  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3480  Local<Context> context, Local<Name> name,
3482  AccessorNameSetterCallback setter = nullptr,
3483  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
3484  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3485  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3486 
3495  V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
3496  Local<Context> context, Local<Name> name,
3498  PropertyAttribute attributes = None,
3499  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
3500  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
3501 
3508  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3509  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3510  Local<Value> value);
3511  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3512  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3513 
3520  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3521  Local<Context> context);
3522  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3523  Local<Context> context, KeyCollectionMode mode,
3524  PropertyFilter property_filter, IndexFilter index_filter,
3526 
3532  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3533  Local<Context> context);
3534 
3541  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3542  Local<Context> context, PropertyFilter filter,
3544 
3550  Local<Value> GetPrototype();
3551 
3557  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3558  Local<Value> prototype);
3559 
3564  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3565 
3571  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3572  Local<Context> context);
3573 
3577  Local<String> GetConstructorName();
3578 
3582  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3583 
3585  int InternalFieldCount();
3586 
3589  const PersistentBase<Object>& object) {
3590  return object.val_->InternalFieldCount();
3591  }
3592 
3595  return object.val_->InternalFieldCount();
3596  }
3597 
3599  V8_INLINE Local<Value> GetInternalField(int index);
3600 
3602  void SetInternalField(int index, Local<Value> value);
3603 
3609  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3610 
3613  const PersistentBase<Object>& object, int index) {
3614  return object.val_->GetAlignedPointerFromInternalField(index);
3615  }
3616 
3619  const TracedGlobal<Object>& object, int index) {
3620  return object.val_->GetAlignedPointerFromInternalField(index);
3621  }
3622 
3628  void SetAlignedPointerInInternalField(int index, void* value);
3629  void SetAlignedPointerInInternalFields(int argc, int indices[],
3630  void* values[]);
3631 
3637  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3638  Local<Name> key);
3639  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3640  uint32_t index);
3654  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3655  Local<Name> key);
3656  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3657  Local<Context> context, uint32_t index);
3658  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3659  Local<Context> context, Local<Name> key);
3660 
3665  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3666  Local<Context> context, Local<Name> key);
3667 
3674  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3675  Local<Name> key);
3676 
3682  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3683  Local<Context> context, Local<Name> key);
3684 
3690  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3691  Local<Context> context, Local<Name> key);
3692 
3694  bool HasNamedLookupInterceptor();
3695 
3697  bool HasIndexedLookupInterceptor();
3698 
3706  int GetIdentityHash();
3707 
3712  // TODO(dcarney): take an isolate and optionally bail out?
3713  Local<Object> Clone();
3714 
3718  Local<Context> CreationContext();
3719 
3722  const PersistentBase<Object>& object) {
3723  return object.val_->CreationContext();
3724  }
3725 
3731  bool IsCallable();
3732 
3736  bool IsConstructor();
3737 
3743  Local<Value> recv,
3744  int argc,
3745  Local<Value> argv[]);
3746 
3752  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3753  Local<Context> context, int argc, Local<Value> argv[]);
3754 
3758  Isolate* GetIsolate();
3759 
3769  MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3770 
3771  static Local<Object> New(Isolate* isolate);
3772 
3781  static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null,
3782  Local<Name>* names, Local<Value>* values,
3783  size_t length);
3784 
3785  V8_INLINE static Object* Cast(Value* obj);
3786 
3787  private:
3788  Object();
3789  static void CheckCast(Value* obj);
3790  Local<Value> SlowGetInternalField(int index);
3791  void* SlowGetAlignedPointerFromInternalField(int index);
3792 };
3793 
3794 
3798 class V8_EXPORT Array : public Object {
3799  public:
3800  uint32_t Length() const;
3801 
3806  static Local<Array> New(Isolate* isolate, int length = 0);
3807 
3812  static Local<Array> New(Isolate* isolate, Local<Value>* elements,
3813  size_t length);
3814  V8_INLINE static Array* Cast(Value* obj);
3815  private:
3816  Array();
3817  static void CheckCast(Value* obj);
3818 };
3819 
3820 
3824 class V8_EXPORT Map : public Object {
3825  public:
3826  size_t Size() const;
3827  void Clear();
3829  Local<Value> key);
3831  Local<Value> key,
3832  Local<Value> value);
3834  Local<Value> key);
3836  Local<Value> key);
3837 
3842  Local<Array> AsArray() const;
3843 
3847  static Local<Map> New(Isolate* isolate);
3848 
3849  V8_INLINE static Map* Cast(Value* obj);
3850 
3851  private:
3852  Map();
3853  static void CheckCast(Value* obj);
3854 };
3855 
3856 
3860 class V8_EXPORT Set : public Object {
3861  public:
3862  size_t Size() const;
3863  void Clear();
3865  Local<Value> key);
3867  Local<Value> key);
3869  Local<Value> key);
3870 
3874  Local<Array> AsArray() const;
3875 
3879  static Local<Set> New(Isolate* isolate);
3880 
3881  V8_INLINE static Set* Cast(Value* obj);
3882 
3883  private:
3884  Set();
3885  static void CheckCast(Value* obj);
3886 };
3887 
3888 
3889 template<typename T>
3890 class ReturnValue {
3891  public:
3892  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3893  : value_(that.value_) {
3894  TYPE_CHECK(T, S);
3895  }
3896  // Local setters
3897  template <typename S>
3898  V8_INLINE V8_DEPRECATED("Use Global<> instead",
3899  void Set(const Persistent<S>& handle));
3900  template <typename S>
3901  V8_INLINE void Set(const Global<S>& handle);
3902  template <typename S>
3903  V8_INLINE void Set(const TracedGlobal<S>& handle);
3904  template <typename S>
3905  V8_INLINE void Set(const Local<S> handle);
3906  // Fast primitive setters
3907  V8_INLINE void Set(bool value);
3908  V8_INLINE void Set(double i);
3909  V8_INLINE void Set(int32_t i);
3910  V8_INLINE void Set(uint32_t i);
3911  // Fast JS primitive setters
3912  V8_INLINE void SetNull();
3913  V8_INLINE void SetUndefined();
3914  V8_INLINE void SetEmptyString();
3915  // Convenience getter for Isolate
3916  V8_INLINE Isolate* GetIsolate() const;
3917 
3918  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3919  template <typename S>
3920  V8_INLINE void Set(S* whatever);
3921 
3922  // Getter. Creates a new Local<> so it comes with a certain performance
3923  // hit. If the ReturnValue was not yet set, this will return the undefined
3924  // value.
3925  V8_INLINE Local<Value> Get() const;
3926 
3927  private:
3928  template<class F> friend class ReturnValue;
3929  template<class F> friend class FunctionCallbackInfo;
3930  template<class F> friend class PropertyCallbackInfo;
3931  template <class F, class G, class H>
3933  V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
3934  V8_INLINE internal::Address GetDefaultValue();
3935  V8_INLINE explicit ReturnValue(internal::Address* slot);
3936  internal::Address* value_;
3937 };
3938 
3939 
3946 template<typename T>
3947 class FunctionCallbackInfo {
3948  public:
3950  V8_INLINE int Length() const;
3952  V8_INLINE Local<Value> operator[](int i) const;
3954  V8_INLINE Local<Object> This() const;
3965  V8_INLINE Local<Object> Holder() const;
3967  V8_INLINE Local<Value> NewTarget() const;
3969  V8_INLINE bool IsConstructCall() const;
3971  V8_INLINE Local<Value> Data() const;
3973  V8_INLINE Isolate* GetIsolate() const;
3975  V8_INLINE ReturnValue<T> GetReturnValue() const;
3976  // This shouldn't be public, but the arm compiler needs it.
3977  static const int kArgsLength = 6;
3978 
3979  protected:
3983  static const int kHolderIndex = 0;
3984  static const int kIsolateIndex = 1;
3985  static const int kReturnValueDefaultValueIndex = 2;
3986  static const int kReturnValueIndex = 3;
3987  static const int kDataIndex = 4;
3988  static const int kNewTargetIndex = 5;
3989 
3991  internal::Address* values, int length);
3994  int length_;
3995 };
3996 
3997 
4002 template<typename T>
4003 class PropertyCallbackInfo {
4004  public:
4008  V8_INLINE Isolate* GetIsolate() const;
4009 
4015  V8_INLINE Local<Value> Data() const;
4016 
4058  V8_INLINE Local<Object> This() const;
4059 
4069  V8_INLINE Local<Object> Holder() const;
4070 
4080 
4088  V8_INLINE bool ShouldThrowOnError() const;
4089 
4090  // This shouldn't be public, but the arm compiler needs it.
4091  static const int kArgsLength = 7;
4092 
4093  protected:
4094  friend class MacroAssembler;
4095  friend class internal::PropertyCallbackArguments;
4097  static const int kShouldThrowOnErrorIndex = 0;
4098  static const int kHolderIndex = 1;
4099  static const int kIsolateIndex = 2;
4100  static const int kReturnValueDefaultValueIndex = 3;
4101  static const int kReturnValueIndex = 4;
4102  static const int kDataIndex = 5;
4103  static const int kThisIndex = 6;
4104 
4107 };
4108 
4109 
4110 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
4111 
4113 
4117 class V8_EXPORT Function : public Object {
4118  public:
4123  static MaybeLocal<Function> New(
4124  Local<Context> context, FunctionCallback callback,
4125  Local<Value> data = Local<Value>(), int length = 0,
4127  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
4128 
4130  Local<Context> context, int argc, Local<Value> argv[]) const;
4131 
4133  Local<Context> context) const {
4134  return NewInstance(context, 0, nullptr);
4135  }
4136 
4142  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
4143  Local<Context> context, int argc, Local<Value> argv[],
4144  SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
4145 
4147  Local<Value> recv, int argc,
4148  Local<Value> argv[]);
4149 
4150  void SetName(Local<String> name);
4151  Local<Value> GetName() const;
4152 
4159  Local<Value> GetInferredName() const;
4160 
4165  Local<Value> GetDebugName() const;
4166 
4171  Local<Value> GetDisplayName() const;
4172 
4177  int GetScriptLineNumber() const;
4182  int GetScriptColumnNumber() const;
4183 
4187  int ScriptId() const;
4188 
4193  Local<Value> GetBoundFunction() const;
4194 
4195  ScriptOrigin GetScriptOrigin() const;
4196  V8_INLINE static Function* Cast(Value* obj);
4197  static const int kLineOffsetNotFound;
4198 
4199  private:
4200  Function();
4201  static void CheckCast(Value* obj);
4202 };
4203 
4204 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
4205 // The number of required internal fields can be defined by embedder.
4206 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
4207 #endif
4208 
4212 class V8_EXPORT Promise : public Object {
4213  public:
4218  enum PromiseState { kPending, kFulfilled, kRejected };
4219 
4220  class V8_EXPORT Resolver : public Object {
4221  public:
4226  Local<Context> context);
4227 
4231  Local<Promise> GetPromise();
4232 
4238  Local<Value> value);
4239 
4241  Local<Value> value);
4242 
4243  V8_INLINE static Resolver* Cast(Value* obj);
4244 
4245  private:
4246  Resolver();
4247  static void CheckCast(Value* obj);
4248  };
4249 
4257  Local<Function> handler);
4258 
4260  Local<Function> handler);
4261 
4263  Local<Function> on_fulfilled,
4264  Local<Function> on_rejected);
4265 
4270  bool HasHandler();
4271 
4276  Local<Value> Result();
4277 
4281  PromiseState State();
4282 
4286  void MarkAsHandled();
4287 
4288  V8_INLINE static Promise* Cast(Value* obj);
4289 
4290  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4291 
4292  private:
4293  Promise();
4294  static void CheckCast(Value* obj);
4295 };
4296 
4326  public:
4327  // GenericDescriptor
4329 
4330  // DataDescriptor
4331  explicit PropertyDescriptor(Local<Value> value);
4332 
4333  // DataDescriptor with writable property
4334  PropertyDescriptor(Local<Value> value, bool writable);
4335 
4336  // AccessorDescriptor
4338 
4339  ~PropertyDescriptor();
4340 
4341  Local<Value> value() const;
4342  bool has_value() const;
4343 
4344  Local<Value> get() const;
4345  bool has_get() const;
4346  Local<Value> set() const;
4347  bool has_set() const;
4348 
4349  void set_enumerable(bool enumerable);
4350  bool enumerable() const;
4351  bool has_enumerable() const;
4352 
4353  void set_configurable(bool configurable);
4354  bool configurable() const;
4355  bool has_configurable() const;
4356 
4357  bool writable() const;
4358  bool has_writable() const;
4359 
4360  struct PrivateData;
4361  PrivateData* get_private() const { return private_; }
4362 
4363  PropertyDescriptor(const PropertyDescriptor&) = delete;
4364  void operator=(const PropertyDescriptor&) = delete;
4365 
4366  private:
4367  PrivateData* private_;
4368 };
4369 
4374 class V8_EXPORT Proxy : public Object {
4375  public:
4376  Local<Value> GetTarget();
4377  Local<Value> GetHandler();
4378  bool IsRevoked();
4379  void Revoke();
4380 
4384  static MaybeLocal<Proxy> New(Local<Context> context,
4385  Local<Object> local_target,
4386  Local<Object> local_handler);
4387 
4388  V8_INLINE static Proxy* Cast(Value* obj);
4389 
4390  private:
4391  Proxy();
4392  static void CheckCast(Value* obj);
4393 };
4394 
4405 template <typename T>
4407  public:
4409  constexpr MemorySpan() = default;
4410 
4411  constexpr MemorySpan(T* data, size_t size) : data_(data), size_(size) {}
4412 
4414  constexpr T* data() const { return data_; }
4416  constexpr size_t size() const { return size_; }
4417 
4418  private:
4419  T* data_ = nullptr;
4420  size_t size_ = 0;
4421 };
4422 
4426 struct OwnedBuffer {
4427  std::unique_ptr<const uint8_t[]> buffer;
4428  size_t size = 0;
4429  OwnedBuffer(std::unique_ptr<const uint8_t[]> buffer, size_t size)
4430  : buffer(std::move(buffer)), size(size) {}
4431  OwnedBuffer() = default;
4432 };
4433 
4434 // Wrapper around a compiled WebAssembly module, which is potentially shared by
4435 // different WasmModuleObjects.
4437  public:
4442  OwnedBuffer Serialize();
4443 
4447  MemorySpan<const uint8_t> GetWireBytesRef();
4448 
4449  private:
4450  explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>);
4451  friend class Utils;
4452 
4453  const std::shared_ptr<internal::wasm::NativeModule> native_module_;
4454 };
4455 
4456 // An instance of WebAssembly.Module.
4458  public:
4465  class TransferrableModule final {
4466  public:
4467  TransferrableModule(TransferrableModule&& src) = default;
4468  TransferrableModule(const TransferrableModule& src) = delete;
4469 
4470  TransferrableModule& operator=(TransferrableModule&& src) = default;
4471  TransferrableModule& operator=(const TransferrableModule& src) = delete;
4472 
4473  private:
4474  typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
4475  friend class WasmModuleObject;
4476  explicit TransferrableModule(SharedModule shared_module)
4477  : shared_module_(std::move(shared_module)) {}
4478  TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
4479  : serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
4480 
4481  SharedModule shared_module_;
4482  OwnedBuffer serialized_ = {nullptr, 0};
4483  OwnedBuffer wire_bytes_ = {nullptr, 0};
4484  };
4485 
4491  TransferrableModule GetTransferrableModule();
4492 
4497  static MaybeLocal<WasmModuleObject> FromTransferrableModule(
4498  Isolate* isolate, const TransferrableModule&);
4499 
4504  CompiledWasmModule GetCompiledModule();
4505 
4510  static MaybeLocal<WasmModuleObject> DeserializeOrCompile(
4511  Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
4512  MemorySpan<const uint8_t> wire_bytes);
4513  V8_INLINE static WasmModuleObject* Cast(Value* obj);
4514 
4515  private:
4516  static MaybeLocal<WasmModuleObject> Deserialize(
4517  Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
4518  MemorySpan<const uint8_t> wire_bytes);
4519  static MaybeLocal<WasmModuleObject> Compile(Isolate* isolate,
4520  const uint8_t* start,
4521  size_t length);
4522  static MemorySpan<const uint8_t> AsReference(const OwnedBuffer& buff) {
4523  return {buff.buffer.get(), buff.size};
4524  }
4525 
4526  WasmModuleObject();
4527  static void CheckCast(Value* obj);
4528 };
4529 
4530 V8_DEPRECATED("Use WasmModuleObject",
4531  typedef WasmModuleObject WasmCompiledModule);
4532 
4540  public:
4541  class WasmStreamingImpl;
4542 
4546  class Client {
4547  public:
4548  virtual ~Client() = default;
4553  virtual void OnModuleCompiled(CompiledWasmModule compiled_module) = 0;
4554  };
4555 
4556  explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
4557 
4558  ~WasmStreaming();
4559 
4564  void OnBytesReceived(const uint8_t* bytes, size_t size);
4565 
4571  void Finish();
4572 
4578  void Abort(MaybeLocal<Value> exception);
4579 
4587  bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size);
4588 
4593  void SetClient(std::shared_ptr<Client> client);
4594 
4600  static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
4601  Local<Value> value);
4602 
4603  private:
4604  std::unique_ptr<WasmStreamingImpl> impl_;
4605 };
4606 
4607 // TODO(mtrofin): when streaming compilation is done, we can rename this
4608 // to simply WasmModuleObjectBuilder
4610  public:
4611  explicit WasmModuleObjectBuilderStreaming(Isolate* isolate);
4615  void OnBytesReceived(const uint8_t*, size_t size);
4616  void Finish();
4622  void Abort(MaybeLocal<Value> exception);
4623  Local<Promise> GetPromise();
4624 
4625  ~WasmModuleObjectBuilderStreaming() = default;
4626 
4627  private:
4629  delete;
4631  default;
4633  const WasmModuleObjectBuilderStreaming&) = delete;
4635  WasmModuleObjectBuilderStreaming&&) = default;
4636  Isolate* isolate_ = nullptr;
4637 
4638 #if V8_CC_MSVC
4639 
4647 #else
4648  Persistent<Promise> promise_;
4649 #endif
4650  std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
4651 };
4652 
4653 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4654 // The number of required internal fields can be defined by embedder.
4655 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4656 #endif
4657 
4658 
4660 
4661 
4665 class V8_EXPORT ArrayBuffer : public Object {
4666  public:
4682  class V8_EXPORT Allocator { // NOLINT
4683  public:
4684  virtual ~Allocator() = default;
4685 
4690  virtual void* Allocate(size_t length) = 0;
4691 
4696  virtual void* AllocateUninitialized(size_t length) = 0;
4697 
4702  virtual void Free(void* data, size_t length) = 0;
4703 
4709  enum class AllocationMode { kNormal, kReservation };
4710 
4717  static Allocator* NewDefaultAllocator();
4718  };
4719 
4729  class V8_EXPORT Contents { // NOLINT
4730  public:
4731  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
4732 
4734  : data_(nullptr),
4735  byte_length_(0),
4736  allocation_base_(nullptr),
4737  allocation_length_(0),
4738  allocation_mode_(Allocator::AllocationMode::kNormal),
4739  deleter_(nullptr),
4740  deleter_data_(nullptr) {}
4741 
4742  void* AllocationBase() const { return allocation_base_; }
4743  size_t AllocationLength() const { return allocation_length_; }
4745  return allocation_mode_;
4746  }
4747 
4748  void* Data() const { return data_; }
4749  size_t ByteLength() const { return byte_length_; }
4750  DeleterCallback Deleter() const { return deleter_; }
4751  void* DeleterData() const { return deleter_data_; }
4752 
4753  private:
4754  Contents(void* data, size_t byte_length, void* allocation_base,
4755  size_t allocation_length,
4756  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
4757  void* deleter_data);
4758 
4759  void* data_;
4760  size_t byte_length_;
4761  void* allocation_base_;
4762  size_t allocation_length_;
4763  Allocator::AllocationMode allocation_mode_;
4764  DeleterCallback deleter_;
4765  void* deleter_data_;
4766 
4767  friend class ArrayBuffer;
4768  };
4769 
4770 
4774  size_t ByteLength() const;
4775 
4782  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4783 
4793  static Local<ArrayBuffer> New(
4794  Isolate* isolate, void* data, size_t byte_length,
4796 
4801  bool IsExternal() const;
4802 
4806  bool IsDetachable() const;
4807 
4808  // TODO(913887): fix the use of 'neuter' in the API.
4809  V8_DEPRECATE_SOON("Use IsDetachable() instead.",
4810  inline bool IsNeuterable() const) {
4811  return IsDetachable();
4812  }
4813 
4820  void Detach();
4821 
4822  // TODO(913887): fix the use of 'neuter' in the API.
4823  V8_DEPRECATE_SOON("Use Detach() instead.", inline void Neuter()) { Detach(); }
4824 
4835  Contents Externalize();
4836 
4845  Contents GetContents();
4846 
4847  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4848 
4849  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4850  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4851 
4852  private:
4853  ArrayBuffer();
4854  static void CheckCast(Value* obj);
4855 };
4856 
4857 
4858 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4859 // The number of required internal fields can be defined by embedder.
4860 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4861 #endif
4862 
4863 
4869  public:
4873  Local<ArrayBuffer> Buffer();
4877  size_t ByteOffset();
4881  size_t ByteLength();
4882 
4892  size_t CopyContents(void* dest, size_t byte_length);
4893 
4898  bool HasBuffer() const;
4899 
4900  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4901 
4902  static const int kInternalFieldCount =
4904  static const int kEmbedderFieldCount =
4906 
4907  private:
4908  ArrayBufferView();
4909  static void CheckCast(Value* obj);
4910 };
4911 
4912 
4918  public:
4919  /*
4920  * The largest typed array size that can be constructed using New.
4921  */
4922  static constexpr size_t kMaxLength = internal::kSmiMaxValue;
4923 
4928  size_t Length();
4929 
4930  V8_INLINE static TypedArray* Cast(Value* obj);
4931 
4932  private:
4933  TypedArray();
4934  static void CheckCast(Value* obj);
4935 };
4936 
4937 
4942  public:
4943  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4944  size_t byte_offset, size_t length);
4945  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4946  size_t byte_offset, size_t length);
4947  V8_INLINE static Uint8Array* Cast(Value* obj);
4948 
4949  private:
4950  Uint8Array();
4951  static void CheckCast(Value* obj);
4952 };
4953 
4954 
4959  public:
4960  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4961  size_t byte_offset, size_t length);
4962  static Local<Uint8ClampedArray> New(
4963  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4964  size_t length);
4965  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4966 
4967  private:
4969  static void CheckCast(Value* obj);
4970 };
4971 
4976  public:
4977  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4978  size_t byte_offset, size_t length);
4979  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4980  size_t byte_offset, size_t length);
4981  V8_INLINE static Int8Array* Cast(Value* obj);
4982 
4983  private:
4984  Int8Array();
4985  static void CheckCast(Value* obj);
4986 };
4987 
4988 
4993  public:
4994  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4995  size_t byte_offset, size_t length);
4996  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4997  size_t byte_offset, size_t length);
4998  V8_INLINE static Uint16Array* Cast(Value* obj);
4999 
5000  private:
5001  Uint16Array();
5002  static void CheckCast(Value* obj);
5003 };
5004 
5005 
5010  public:
5011  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
5012  size_t byte_offset, size_t length);
5013  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5014  size_t byte_offset, size_t length);
5015  V8_INLINE static Int16Array* Cast(Value* obj);
5016 
5017  private:
5018  Int16Array();
5019  static void CheckCast(Value* obj);
5020 };
5021 
5022 
5027  public:
5028  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
5029  size_t byte_offset, size_t length);
5030  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5031  size_t byte_offset, size_t length);
5032  V8_INLINE static Uint32Array* Cast(Value* obj);
5033 
5034  private:
5035  Uint32Array();
5036  static void CheckCast(Value* obj);
5037 };
5038 
5039 
5044  public:
5045  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
5046  size_t byte_offset, size_t length);
5047  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5048  size_t byte_offset, size_t length);
5049  V8_INLINE static Int32Array* Cast(Value* obj);
5050 
5051  private:
5052  Int32Array();
5053  static void CheckCast(Value* obj);
5054 };
5055 
5056 
5061  public:
5062  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
5063  size_t byte_offset, size_t length);
5064  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5065  size_t byte_offset, size_t length);
5066  V8_INLINE static Float32Array* Cast(Value* obj);
5067 
5068  private:
5069  Float32Array();
5070  static void CheckCast(Value* obj);
5071 };
5072 
5073 
5078  public:
5079  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
5080  size_t byte_offset, size_t length);
5081  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5082  size_t byte_offset, size_t length);
5083  V8_INLINE static Float64Array* Cast(Value* obj);
5084 
5085  private:
5086  Float64Array();
5087  static void CheckCast(Value* obj);
5088 };
5089 
5094  public:
5095  static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
5096  size_t byte_offset, size_t length);
5097  static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5098  size_t byte_offset, size_t length);
5099  V8_INLINE static BigInt64Array* Cast(Value* obj);
5100 
5101  private:
5102  BigInt64Array();
5103  static void CheckCast(Value* obj);
5104 };
5105 
5110  public:
5111  static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
5112  size_t byte_offset, size_t length);
5113  static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
5114  size_t byte_offset, size_t length);
5115  V8_INLINE static BigUint64Array* Cast(Value* obj);
5116 
5117  private:
5118  BigUint64Array();
5119  static void CheckCast(Value* obj);
5120 };
5121 
5126  public:
5127  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
5128  size_t byte_offset, size_t length);
5129  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
5130  size_t byte_offset, size_t length);
5131  V8_INLINE static DataView* Cast(Value* obj);
5132 
5133  private:
5134  DataView();
5135  static void CheckCast(Value* obj);
5136 };
5137 
5138 
5144  public:
5156  class V8_EXPORT Contents { // NOLINT
5157  public:
5159  using DeleterCallback = void (*)(void* buffer, size_t length, void* info);
5160 
5162  : data_(nullptr),
5163  byte_length_(0),
5164  allocation_base_(nullptr),
5165  allocation_length_(0),
5166  allocation_mode_(Allocator::AllocationMode::kNormal),
5167  deleter_(nullptr),
5168  deleter_data_(nullptr),
5169  is_growable_(false) {}
5170 
5171  void* AllocationBase() const { return allocation_base_; }
5172  size_t AllocationLength() const { return allocation_length_; }
5174  return allocation_mode_;
5175  }
5176 
5177  void* Data() const { return data_; }
5178  size_t ByteLength() const { return byte_length_; }
5179  DeleterCallback Deleter() const { return deleter_; }
5180  void* DeleterData() const { return deleter_data_; }
5181  bool IsGrowable() const { return is_growable_; }
5182 
5183  private:
5184  Contents(void* data, size_t byte_length, void* allocation_base,
5185  size_t allocation_length,
5186  Allocator::AllocationMode allocation_mode, DeleterCallback deleter,
5187  void* deleter_data, bool is_growable);
5188 
5189  void* data_;
5190  size_t byte_length_;
5191  void* allocation_base_;
5192  size_t allocation_length_;
5193  Allocator::AllocationMode allocation_mode_;
5194  DeleterCallback deleter_;
5195  void* deleter_data_;
5196  bool is_growable_;
5197 
5198  friend class SharedArrayBuffer;
5199  };
5200 
5204  size_t ByteLength() const;
5205 
5212  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
5213 
5220  static Local<SharedArrayBuffer> New(
5221  Isolate* isolate, void* data, size_t byte_length,
5223 
5228  static Local<SharedArrayBuffer> New(
5229  Isolate* isolate, const SharedArrayBuffer::Contents&,
5231 
5236  bool IsExternal() const;
5237 
5250  Contents Externalize();
5251 
5264  Contents GetContents();
5265 
5266  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
5267 
5268  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
5269 
5270  private:
5272  static void CheckCast(Value* obj);
5273 };
5274 
5275 
5279 class V8_EXPORT Date : public Object {
5280  public:
5282  double time);
5283 
5288  double ValueOf() const;
5289 
5290  V8_INLINE static Date* Cast(Value* obj);
5291 
5305  enum class TimeZoneDetection { kSkip, kRedetect };
5306 
5320  "Use Isolate::DateTimeConfigurationChangeNotification",
5321  static void DateTimeConfigurationChangeNotification(
5322  Isolate* isolate,
5323  TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip));
5324 
5325  private:
5326  static void CheckCast(Value* obj);
5327 };
5328 
5329 
5334  public:
5335  static Local<Value> New(Isolate* isolate, double value);
5336 
5337  double ValueOf() const;
5338 
5339  V8_INLINE static NumberObject* Cast(Value* obj);
5340 
5341  private:
5342  static void CheckCast(Value* obj);
5343 };
5344 
5349  public:
5350  static Local<Value> New(Isolate* isolate, int64_t value);
5351 
5352  Local<BigInt> ValueOf() const;
5353 
5354  V8_INLINE static BigIntObject* Cast(Value* obj);
5355 
5356  private:
5357  static void CheckCast(Value* obj);
5358 };
5359 
5364  public:
5365  static Local<Value> New(Isolate* isolate, bool value);
5366 
5367  bool ValueOf() const;
5368 
5369  V8_INLINE static BooleanObject* Cast(Value* obj);
5370 
5371  private:
5372  static void CheckCast(Value* obj);
5373 };
5374 
5375 
5380  public:
5381  static Local<Value> New(Isolate* isolate, Local<String> value);
5382 
5383  Local<String> ValueOf() const;
5384 
5385  V8_INLINE static StringObject* Cast(Value* obj);
5386 
5387  private:
5388  static void CheckCast(Value* obj);
5389 };
5390 
5391 
5396  public:
5397  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
5398 
5399  Local<Symbol> ValueOf() const;
5400 
5401  V8_INLINE static SymbolObject* Cast(Value* obj);
5402 
5403  private:
5404  static void CheckCast(Value* obj);
5405 };
5406 
5407 
5411 class V8_EXPORT RegExp : public Object {
5412  public:
5417  enum Flags {
5418  kNone = 0,
5419  kGlobal = 1 << 0,
5420  kIgnoreCase = 1 << 1,
5421  kMultiline = 1 << 2,
5422  kSticky = 1 << 3,
5423  kUnicode = 1 << 4,
5424  kDotAll = 1 << 5,
5425  };
5426 
5438  Local<String> pattern,
5439  Flags flags);
5440 
5445  Local<String> GetSource() const;
5446 
5450  Flags GetFlags() const;
5451 
5452  V8_INLINE static RegExp* Cast(Value* obj);
5453 
5454  private:
5455  static void CheckCast(Value* obj);
5456 };
5457 
5458 
5463 class V8_EXPORT External : public Value {
5464  public:
5465  static Local<External> New(Isolate* isolate, void* value);
5466  V8_INLINE static External* Cast(Value* obj);
5467  void* Value() const;
5468  private:
5469  static void CheckCast(v8::Value* obj);
5470 };
5471 
5472 #define V8_INTRINSICS_LIST(F) \
5473  F(ArrayProto_entries, array_entries_iterator) \
5474  F(ArrayProto_forEach, array_for_each_iterator) \
5475  F(ArrayProto_keys, array_keys_iterator) \
5476  F(ArrayProto_values, array_values_iterator) \
5477  F(ErrorPrototype, initial_error_prototype) \
5478  F(IteratorPrototype, initial_iterator_prototype)
5479 
5481 #define V8_DECL_INTRINSIC(name, iname) k##name,
5483 #undef V8_DECL_INTRINSIC
5484 };
5485 
5486 
5487 // --- Templates ---
5488 
5489 
5493 class V8_EXPORT Template : public Data {
5494  public:
5500  void Set(Local<Name> name, Local<Data> value,
5501  PropertyAttribute attributes = None);
5502  void SetPrivate(Local<Private> name, Local<Data> value,
5503  PropertyAttribute attributes = None);
5504  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5505 
5506  void SetAccessorProperty(
5507  Local<Name> name,
5510  PropertyAttribute attribute = None,
5511  AccessControl settings = DEFAULT);
5512 
5540  void SetNativeDataProperty(
5542  AccessorSetterCallback setter = nullptr,
5543  // TODO(dcarney): gcc can't handle Local below
5544  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5546  AccessControl settings = DEFAULT,
5547  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5548  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5549  void SetNativeDataProperty(
5551  AccessorNameSetterCallback setter = nullptr,
5552  // TODO(dcarney): gcc can't handle Local below
5553  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5555  AccessControl settings = DEFAULT,
5556  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5557  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5558 
5563  void SetLazyDataProperty(
5565  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5566  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
5567  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
5568 
5573  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5574  PropertyAttribute attribute = None);
5575 
5576  private:
5577  Template();
5578 
5579  friend class ObjectTemplate;
5580  friend class FunctionTemplate;
5581 };
5582 
5583 // TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
5584 // NamedPropertyFooCallback.
5585 
5623  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5624 
5647  Local<Name> property, Local<Value> value,
5648  const PropertyCallbackInfo<Value>& info);
5649 
5672  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5673 
5696  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5697 
5705  const PropertyCallbackInfo<Array>& info);
5706 
5728  Local<Name> property, const PropertyDescriptor& desc,
5729  const PropertyCallbackInfo<Value>& info);
5730 
5751  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5752 
5757  uint32_t index,
5758  const PropertyCallbackInfo<Value>& info);
5759 
5764  uint32_t index,
5765  Local<Value> value,
5766  const PropertyCallbackInfo<Value>& info);
5767 
5772  uint32_t index,
5773  const PropertyCallbackInfo<Integer>& info);
5774 
5779  uint32_t index,
5780  const PropertyCallbackInfo<Boolean>& info);
5781 
5789  const PropertyCallbackInfo<Array>& info);
5790 
5795  uint32_t index, const PropertyDescriptor& desc,
5796  const PropertyCallbackInfo<Value>& info);
5797 
5802  uint32_t index, const PropertyCallbackInfo<Value>& info);
5803 
5813 };
5814 
5815 
5820 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5821  Local<Object> accessed_object,
5822  Local<Value> data);
5823 
5925  public:
5927  static Local<FunctionTemplate> New(
5928  Isolate* isolate, FunctionCallback callback = nullptr,
5929  Local<Value> data = Local<Value>(),
5930  Local<Signature> signature = Local<Signature>(), int length = 0,
5932  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5933 
5935  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5936  size_t index);
5937 
5941  static Local<FunctionTemplate> NewWithCache(
5942  Isolate* isolate, FunctionCallback callback,
5943  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5944  Local<Signature> signature = Local<Signature>(), int length = 0,
5945  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5946 
5949  Local<Context> context);
5950 
5958  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5959 
5965  void SetCallHandler(
5966  FunctionCallback callback, Local<Value> data = Local<Value>(),
5967  SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5968 
5970  void SetLength(int length);
5971 
5973  Local<ObjectTemplate> InstanceTemplate();
5974 
5980  void Inherit(Local<FunctionTemplate> parent);
5981 
5986  Local<ObjectTemplate> PrototypeTemplate();
5987 
5994  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5995 
6001  void SetClassName(Local<String> name);
6002 
6003 
6008  void SetAcceptAnyReceiver(bool value);
6009 
6022  V8_DEPRECATED("This feature is incompatible with ES6+.",
6023  void SetHiddenPrototype(bool value));
6024 
6029  void ReadOnlyPrototype();
6030 
6035  void RemovePrototype();
6036 
6041  bool HasInstance(Local<Value> object);
6042 
6043  V8_INLINE static FunctionTemplate* Cast(Data* data);
6044 
6045  private:
6046  FunctionTemplate();
6047 
6048  static void CheckCast(Data* that);
6049  friend class Context;
6050  friend class ObjectTemplate;
6051 };
6052 
6061  kNone = 0,
6062 
6066  kAllCanRead = 1,
6067 
6072  kNonMasking = 1 << 1,
6073 
6078  kOnlyInterceptStrings = 1 << 2,
6079 
6083  kHasNoSideEffect = 1 << 3,
6084 };
6085 
6097  : getter(getter),
6098  setter(setter),
6099  query(query),
6100  deleter(deleter),
6102  definer(definer),
6104  data(data),
6105  flags(flags) {}
6106 
6116  : getter(getter),
6117  setter(setter),
6118  query(query),
6119  deleter(deleter),
6121  definer(nullptr),
6122  descriptor(nullptr),
6123  data(data),
6124  flags(flags) {}
6125 
6135  : getter(getter),
6136  setter(setter),
6137  query(nullptr),
6138  deleter(deleter),
6140  definer(definer),
6142  data(data),
6143  flags(flags) {}
6144 
6154 };
6155 
6156 
6167  : getter(getter),
6168  setter(setter),
6169  query(query),
6170  deleter(deleter),
6172  definer(definer),
6174  data(data),
6175  flags(flags) {}
6176 
6186  : getter(getter),
6187  setter(setter),
6188  query(query),
6189  deleter(deleter),
6191  definer(nullptr),
6192  descriptor(nullptr),
6193  data(data),
6194  flags(flags) {}
6195 
6205  : getter(getter),
6206  setter(setter),
6207  query(nullptr),
6208  deleter(deleter),
6210  definer(definer),
6212  data(data),
6213  flags(flags) {}
6214 
6224 };
6225 
6226 
6234  public:
6236  static Local<ObjectTemplate> New(
6237  Isolate* isolate,
6239 
6241  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
6242  size_t index);
6243 
6246 
6276  void SetAccessor(
6278  AccessorSetterCallback setter = nullptr,
6279  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
6280  PropertyAttribute attribute = None,
6282  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6283  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6284  void SetAccessor(
6286  AccessorNameSetterCallback setter = nullptr,
6287  Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
6288  PropertyAttribute attribute = None,
6290  SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
6291  SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
6292 
6304  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
6305 
6322  // TODO(dcarney): deprecate
6325  IndexedPropertySetterCallback setter = nullptr,
6326  IndexedPropertyQueryCallback query = nullptr,
6327  IndexedPropertyDeleterCallback deleter = nullptr,
6328  IndexedPropertyEnumeratorCallback enumerator = nullptr,
6329  Local<Value> data = Local<Value>()) {
6330  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
6331  deleter, enumerator, data));
6332  }
6333 
6344  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
6345 
6352  void SetCallAsFunctionHandler(FunctionCallback callback,
6353  Local<Value> data = Local<Value>());
6354 
6363  void MarkAsUndetectable();
6364 
6373  void SetAccessCheckCallback(AccessCheckCallback callback,
6374  Local<Value> data = Local<Value>());
6375 
6382  void SetAccessCheckCallbackAndHandler(
6383  AccessCheckCallback callback,
6384  const NamedPropertyHandlerConfiguration& named_handler,
6385  const IndexedPropertyHandlerConfiguration& indexed_handler,
6386  Local<Value> data = Local<Value>());
6387 
6392  int InternalFieldCount();
6393 
6398  void SetInternalFieldCount(int value);
6399 
6403  bool IsImmutableProto();
6404 
6409  void SetImmutableProto();
6410 
6411  V8_INLINE static ObjectTemplate* Cast(Data* data);
6412 
6413  private:
6414  ObjectTemplate();
6415  static Local<ObjectTemplate> New(internal::Isolate* isolate,
6416  Local<FunctionTemplate> constructor);
6417  static void CheckCast(Data* that);
6418  friend class FunctionTemplate;
6419 };
6420 
6429 class V8_EXPORT Signature : public Data {
6430  public:
6431  static Local<Signature> New(
6432  Isolate* isolate,
6434 
6435  V8_INLINE static Signature* Cast(Data* data);
6436 
6437  private:
6438  Signature();
6439 
6440  static void CheckCast(Data* that);
6441 };
6442 
6443 
6449  public:
6450  static Local<AccessorSignature> New(
6451  Isolate* isolate,
6453 
6454  V8_INLINE static AccessorSignature* Cast(Data* data);
6455 
6456  private:
6458 
6459  static void CheckCast(Data* that);
6460 };
6461 
6462 
6463 // --- Extensions ---
6464 
6468 class V8_EXPORT Extension { // NOLINT
6469  public:
6470  // Note that the strings passed into this constructor must live as long
6471  // as the Extension itself.
6472  Extension(const char* name, const char* source = nullptr, int dep_count = 0,
6473  const char** deps = nullptr, int source_length = -1);
6474  virtual ~Extension() { delete source_; }
6476  Isolate* isolate, Local<String> name) {
6477  return Local<FunctionTemplate>();
6478  }
6479 
6480  const char* name() const { return name_; }
6481  size_t source_length() const { return source_length_; }
6483  return source_;
6484  }
6485  int dependency_count() const { return dep_count_; }
6486  const char** dependencies() const { return deps_; }
6487  void set_auto_enable(bool value) { auto_enable_ = value; }
6488  bool auto_enable() { return auto_enable_; }
6489 
6490  // Disallow copying and assigning.
6491  Extension(const Extension&) = delete;
6492  void operator=(const Extension&) = delete;
6493 
6494  private:
6495  const char* name_;
6496  size_t source_length_; // expected to initialize before source_
6498  int dep_count_;
6499  const char** deps_;
6500  bool auto_enable_;
6501 };
6502 
6504  "Use unique_ptr version or stop using extension (http://crbug.com/334679).",
6505  void V8_EXPORT RegisterExtension(Extension* extension));
6506 
6507 void V8_EXPORT RegisterExtension(std::unique_ptr<Extension>);
6508 
6509 // --- Statics ---
6510 
6511 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6512 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6513 V8_INLINE Local<Boolean> True(Isolate* isolate);
6514 V8_INLINE Local<Boolean> False(Isolate* isolate);
6515 
6531  public:
6533 
6543  void ConfigureDefaults(uint64_t physical_memory,
6544  uint64_t virtual_memory_limit);
6545 
6546  // Returns the max semi-space size in KB.
6547  size_t max_semi_space_size_in_kb() const {
6548  return max_semi_space_size_in_kb_;
6549  }
6550 
6551  // Sets the max semi-space size in KB.
6552  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6553  max_semi_space_size_in_kb_ = limit_in_kb;
6554  }
6555 
6556  size_t max_old_space_size() const { return max_old_space_size_; }
6557  void set_max_old_space_size(size_t limit_in_mb) {
6558  max_old_space_size_ = limit_in_mb;
6559  }
6560  uint32_t* stack_limit() const { return stack_limit_; }
6561  // Sets an address beyond which the VM's stack may not grow.
6562  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6563  size_t code_range_size() const { return code_range_size_; }
6564  void set_code_range_size(size_t limit_in_mb) {
6565  code_range_size_ = limit_in_mb;
6566  }
6567  V8_DEPRECATE_SOON("Zone does not pool memory any more.",
6568  size_t max_zone_pool_size() const) {
6569  return max_zone_pool_size_;
6570  }
6571  V8_DEPRECATE_SOON("Zone does not pool memory any more.",
6572  void set_max_zone_pool_size(size_t bytes)) {
6573  max_zone_pool_size_ = bytes;
6574  }
6575 
6576  private:
6577  // max_semi_space_size_ is in KB
6578  size_t max_semi_space_size_in_kb_;
6579 
6580  // The remaining limits are in MB
6581  size_t max_old_space_size_;
6582  uint32_t* stack_limit_;
6583  size_t code_range_size_;
6584  size_t max_zone_pool_size_;
6585 };
6586 
6587 
6588 // --- Exceptions ---
6589 
6590 
6591 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6592 
6593 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6594 
6595 typedef void (*DcheckErrorCallback)(const char* file, int line,
6596  const char* message);
6597 
6598 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6599 
6600 // --- Tracing ---
6601 
6602 typedef void (*LogEventCallback)(const char* name, int event);
6603 
6609  public:
6610  static Local<Value> RangeError(Local<String> message);
6611  static Local<Value> ReferenceError(Local<String> message);
6612  static Local<Value> SyntaxError(Local<String> message);
6613  static Local<Value> TypeError(Local<String> message);
6614  static Local<Value> Error(Local<String> message);
6615 
6621  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6622 
6627  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6628 };
6629 
6630 
6631 // --- Counters Callbacks ---
6632 
6633 typedef int* (*CounterLookupCallback)(const char* name);
6634 
6635 typedef void* (*CreateHistogramCallback)(const char* name,
6636  int min,
6637  int max,
6638  size_t buckets);
6639 
6640 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6641 
6642 // --- Enter/Leave Script Callback ---
6644 typedef void (*CallCompletedCallback)(Isolate*);
6645 
6667  Local<Context> context, Local<ScriptOrModule> referrer,
6668  Local<String> specifier);
6669 
6681  Local<Module> module,
6682  Local<Object> meta);
6683 
6692  Local<Value> error,
6693  Local<Array> sites);
6694 
6712 
6713 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6714  Local<Value> parent);
6715 
6716 // --- Promise Reject Callback ---
6722 };
6723 
6725  public:
6727  Local<Value> value, Local<StackTrace> stack_trace)
6728  : promise_(promise),
6729  event_(event),
6730  value_(value),
6731  stack_trace_(stack_trace) {}
6732 
6733  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6734  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6735  V8_INLINE Local<Value> GetValue() const { return value_; }
6736 
6737  private:
6738  Local<Promise> promise_;
6739  PromiseRejectEvent event_;
6740  Local<Value> value_;
6741  Local<StackTrace> stack_trace_;
6742 };
6743 
6745 
6746 // --- Microtasks Callbacks ---
6749 typedef void (*MicrotaskCallback)(void* data);
6750 
6751 
6760 
6777  public:
6781  static std::unique_ptr<MicrotaskQueue> New();
6782 
6783  virtual ~MicrotaskQueue() = default;
6784 
6788  virtual void EnqueueMicrotask(Isolate* isolate,
6789  Local<Function> microtask) = 0;
6790 
6794  virtual void EnqueueMicrotask(v8::Isolate* isolate,
6795  MicrotaskCallback callback,
6796  void* data = nullptr) = 0;
6797 
6810  virtual void AddMicrotasksCompletedCallback(
6811  MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
6812 
6816  virtual void RemoveMicrotasksCompletedCallback(
6817  MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
6818 
6822  virtual void PerformCheckpoint(Isolate* isolate) = 0;
6823 
6827  virtual bool IsRunningMicrotasks() const = 0;
6828 
6829  private:
6830  friend class internal::MicrotaskQueue;
6831  MicrotaskQueue() = default;
6832  MicrotaskQueue(const MicrotaskQueue&) = delete;
6833  MicrotaskQueue& operator=(const MicrotaskQueue&) = delete;
6834 };
6835 
6846  public:
6847  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6848 
6849  MicrotasksScope(Isolate* isolate, Type type);
6850  MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
6851  ~MicrotasksScope();
6852 
6856  static void PerformCheckpoint(Isolate* isolate);
6857 
6861  static int GetCurrentDepth(Isolate* isolate);
6862 
6866  static bool IsRunningMicrotasks(Isolate* isolate);
6867 
6868  // Prevent copying.
6869  MicrotasksScope(const MicrotasksScope&) = delete;
6870  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6871 
6872  private:
6873  internal::Isolate* const isolate_;
6874  internal::MicrotaskQueue* const microtask_queue_;
6875  bool run_;
6876 };
6877 
6878 
6879 // --- Failed Access Check Callback ---
6881  AccessType type,
6882  Local<Value> data);
6883 
6884 // --- AllowCodeGenerationFromStrings callbacks ---
6885 
6891  Local<String> source);
6892 
6893 // --- WebAssembly compilation callbacks ---
6895 
6897  Local<String> source);
6898 
6899 // --- Callback for APIs defined on v8-supported objects, but implemented
6900 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6902 
6903 // --- Callback for WebAssembly.compileStreaming ---
6905 
6906 // --- Callback for checking if WebAssembly threads are enabled ---
6908 
6909 // --- Garbage Collection Callbacks ---
6910 
6918 enum GCType {
6925 };
6926 
6949 };
6950 
6951 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6952 
6953 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6954 
6962 typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
6963  size_t initial_heap_limit);
6964 
6972  public:
6973  HeapStatistics();
6974  size_t total_heap_size() { return total_heap_size_; }
6975  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6976  size_t total_physical_size() { return total_physical_size_; }
6977  size_t total_available_size() { return total_available_size_; }
6978  size_t used_heap_size() { return used_heap_size_; }
6979  size_t heap_size_limit() { return heap_size_limit_; }
6980  size_t malloced_memory() { return malloced_memory_; }
6981  size_t external_memory() { return external_memory_; }
6982  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6983  size_t number_of_native_contexts() { return number_of_native_contexts_; }
6984  size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
6985 
6990  size_t does_zap_garbage() { return does_zap_garbage_; }
6991 
6992  private:
6993  size_t total_heap_size_;
6994  size_t total_heap_size_executable_;
6995  size_t total_physical_size_;
6996  size_t total_available_size_;
6997  size_t used_heap_size_;
6998  size_t heap_size_limit_;
6999  size_t malloced_memory_;
7000  size_t external_memory_;
7001  size_t peak_malloced_memory_;
7002  bool does_zap_garbage_;
7003  size_t number_of_native_contexts_;
7004  size_t number_of_detached_contexts_;
7005 
7006  friend class V8;
7007  friend class Isolate;
7008 };
7009 
7010 
7012  public:
7014  const char* space_name() { return space_name_; }
7015  size_t space_size() { return space_size_; }
7016  size_t space_used_size() { return space_used_size_; }
7017  size_t space_available_size() { return space_available_size_; }
7018  size_t physical_space_size() { return physical_space_size_; }
7019 
7020  private:
7021  const char* space_name_;
7022  size_t space_size_;
7023  size_t space_used_size_;
7024  size_t space_available_size_;
7025  size_t physical_space_size_;
7026 
7027  friend class Isolate;
7028 };
7029 
7030 
7032  public:
7034  const char* object_type() { return object_type_; }
7035  const char* object_sub_type() { return object_sub_type_; }
7036  size_t object_count() { return object_count_; }
7037  size_t object_size() { return object_size_; }
7038 
7039  private:
7040  const char* object_type_;
7041  const char* object_sub_type_;
7042  size_t object_count_;
7043  size_t object_size_;
7044 
7045  friend class Isolate;
7046 };
7047 
7049  public:
7051  size_t code_and_metadata_size() { return code_and_metadata_size_; }
7052  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
7053  size_t external_script_source_size() { return external_script_source_size_; }
7054 
7055  private:
7056  size_t code_and_metadata_size_;
7057  size_t bytecode_and_metadata_size_;
7058  size_t external_script_source_size_;
7059 
7060  friend class Isolate;
7061 };
7062 
7069  enum EventType {
7076  };
7077  // Definition of the code position type. The "POSITION" type means the place
7078  // in the source code which are of interest when making stack traces to
7079  // pin-point the source location of a stack frame as close as possible.
7080  // The "STATEMENT_POSITION" means the place at the beginning of each
7081  // statement, and is used to indicate possible break locations.
7083 
7084  // There are two different kinds of JitCodeEvents, one for JIT code generated
7085  // by the optimizing compiler, and one for byte code generated for the
7086  // interpreter. For JIT_CODE events, the |code_start| member of the event
7087  // points to the beginning of jitted assembly code, while for BYTE_CODE
7088  // events, |code_start| points to the first bytecode of the interpreted
7089  // function.
7091 
7092  // Type of event.
7095  // Start of the instructions.
7096  void* code_start;
7097  // Size of the instructions.
7098  size_t code_len;
7099  // Script info for CODE_ADDED event.
7101  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
7102  // code line information which is returned from the
7103  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
7104  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
7105  void* user_data;
7106 
7107  struct name_t {
7108  // Name of the object associated with the code, note that the string is not
7109  // zero-terminated.
7110  const char* str;
7111  // Number of chars in str.
7112  size_t len;
7113  };
7114 
7115  struct line_info_t {
7116  // PC offset
7117  size_t offset;
7118  // Code position
7119  size_t pos;
7120  // The position type.
7122  };
7123 
7124  union {
7125  // Only valid for CODE_ADDED.
7126  struct name_t name;
7127 
7128  // Only valid for CODE_ADD_LINE_POS_INFO
7130 
7131  // New location of instructions. Only valid for CODE_MOVED.
7133  };
7134 
7136 };
7137 
7143 enum RAILMode : unsigned {
7144  // Response performance mode: In this mode very low virtual machine latency
7145  // is provided. V8 will try to avoid JavaScript execution interruptions.
7146  // Throughput may be throttled.
7148  // Animation performance mode: In this mode low virtual machine latency is
7149  // provided. V8 will try to avoid as many JavaScript execution interruptions
7150  // as possible. Throughput may be throttled. This is the default mode.
7152  // Idle performance mode: The embedder is idle. V8 can complete deferred work
7153  // in this mode.
7155  // Load performance mode: In this mode high throughput is provided. V8 may
7156  // turn off latency optimizations.
7158 };
7159 
7165  // Generate callbacks for already existent code.
7167 };
7168 
7169 
7175 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
7176 
7177 
7182  public:
7183  virtual ~ExternalResourceVisitor() = default;
7184  virtual void VisitExternalString(Local<String> string) {}
7185 };
7186 
7187 
7192  public:
7193  virtual ~PersistentHandleVisitor() = default;
7195  uint16_t class_id) {}
7196 };
7197 
7207 
7216  public:
7217  // Indicator for the stack state of the embedder.
7222  };
7223 
7228  public:
7229  virtual ~TracedGlobalHandleVisitor() = default;
7230  virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& value) = 0;
7231  };
7232 
7233  virtual ~EmbedderHeapTracer() = default;
7234 
7239  void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor);
7240 
7247  virtual void RegisterV8References(
7248  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
7249 
7250  void RegisterEmbedderReference(const TracedGlobal<v8::Value>& ref);
7251 
7255  virtual void TracePrologue() = 0;
7256 
7267  virtual bool AdvanceTracing(double deadline_in_ms) = 0;
7268 
7269  /*
7270  * Returns true if there no more tracing work to be done (see AdvanceTracing)
7271  * and false otherwise.
7272  */
7273  virtual bool IsTracingDone() = 0;
7274 
7280  virtual void TraceEpilogue() = 0;
7281 
7286  virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
7287 
7288  /*
7289  * Called by the embedder to request immediate finalization of the currently
7290  * running tracing phase that has been started with TracePrologue and not
7291  * yet finished with TraceEpilogue.
7292  *
7293  * Will be a noop when currently not in tracing.
7294  *
7295  * This is an experimental feature.
7296  */
7297  void FinalizeTracing();
7298 
7306  const v8::TracedGlobal<v8::Value>& handle) {
7307  return true;
7308  }
7309 
7310  /*
7311  * Called by the embedder to immediately perform a full garbage collection.
7312  *
7313  * Should only be used in testing code.
7314  */
7315  void GarbageCollectionForTesting(EmbedderStackState stack_state);
7316 
7317  /*
7318  * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
7319  * is not attached to any v8::Isolate.
7320  */
7321  v8::Isolate* isolate() const { return isolate_; }
7322 
7323  protected:
7324  v8::Isolate* isolate_ = nullptr;
7325 
7326  friend class internal::LocalEmbedderHeapTracer;
7327 };
7328 
7338  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
7339  void* data);
7341  void* data_arg = nullptr)
7342  : callback(function), data(data_arg) {}
7344  void* data;
7345 };
7346 // Note that these fields are called "internal fields" in the API and called
7347 // "embedder fields" within V8.
7349 
7355  typedef void (*CallbackFunction)(Local<Object> holder, int index,
7356  StartupData payload, void* data);
7358  void* data_arg = nullptr)
7359  : callback(function), data(data_arg) {}
7360  void (*callback)(Local<Object> holder, int index, StartupData payload,
7361  void* data);
7362  void* data;
7363 };
7365 
7375  public:
7379  struct CreateParams {
7381  : code_event_handler(nullptr),
7382  snapshot_blob(nullptr),
7383  counter_lookup_callback(nullptr),
7384  create_histogram_callback(nullptr),
7385  add_histogram_sample_callback(nullptr),
7386  array_buffer_allocator(nullptr),
7387  external_references(nullptr),
7388  allow_atomics_wait(true),
7389  only_terminate_in_safe_scope(false) {}
7390 
7396 
7401 
7406 
7407 
7413 
7422 
7428 
7435  const intptr_t* external_references;
7436 
7442 
7447  };
7448 
7449 
7455  public:
7456  explicit Scope(Isolate* isolate) : isolate_(isolate) {
7457  isolate->Enter();
7458  }
7459 
7460  ~Scope() { isolate_->Exit(); }
7461 
7462  // Prevent copying of Scope objects.
7463  Scope(const Scope&) = delete;
7464  Scope& operator=(const Scope&) = delete;
7465 
7466  private:
7467  Isolate* const isolate_;
7468  };
7469 
7470 
7475  public:
7476  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
7477 
7478  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
7480 
7481  // Prevent copying of Scope objects.
7483  delete;
7485  const DisallowJavascriptExecutionScope&) = delete;
7486 
7487  private:
7488  OnFailure on_failure_;
7489  void* internal_;
7490  };
7491 
7492 
7497  public:
7498  explicit AllowJavascriptExecutionScope(Isolate* isolate);
7500 
7501  // Prevent copying of Scope objects.
7503  delete;
7504  AllowJavascriptExecutionScope& operator=(
7505  const AllowJavascriptExecutionScope&) = delete;
7506 
7507  private:
7508  void* internal_throws_;
7509  void* internal_assert_;
7510  void* internal_dump_;
7511  };
7512 
7518  public:
7519  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7520  explicit SuppressMicrotaskExecutionScope(MicrotaskQueue* microtask_queue);
7522 
7523  // Prevent copying of Scope objects.
7525  delete;
7527  const SuppressMicrotaskExecutionScope&) = delete;
7528 
7529  private:
7530  internal::Isolate* const isolate_;
7531  internal::MicrotaskQueue* const microtask_queue_;
7532  };
7533 
7539  public:
7540  explicit SafeForTerminationScope(v8::Isolate* isolate);
7542 
7543  // Prevent copying of Scope objects.
7545  SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
7546 
7547  private:
7548  internal::Isolate* isolate_;
7549  bool prev_value_;
7550  };
7551 
7558  kMinorGarbageCollection
7559  };
7560 
7567  kUseAsm = 0,
7568  kBreakIterator = 1,
7569  kLegacyConst = 2,
7570  kMarkDequeOverflow = 3,
7571  kStoreBufferOverflow = 4,
7572  kSlotsBufferOverflow = 5,
7573  kObjectObserve = 6,
7574  kForcedGC = 7,
7575  kSloppyMode = 8,
7576  kStrictMode = 9,
7577  kStrongMode = 10,
7578  kRegExpPrototypeStickyGetter = 11,
7579  kRegExpPrototypeToString = 12,
7580  kRegExpPrototypeUnicodeGetter = 13,
7581  kIntlV8Parse = 14,
7582  kIntlPattern = 15,
7583  kIntlResolved = 16,
7584  kPromiseChain = 17,
7585  kPromiseAccept = 18,
7586  kPromiseDefer = 19,
7587  kHtmlCommentInExternalScript = 20,
7588  kHtmlComment = 21,
7589  kSloppyModeBlockScopedFunctionRedefinition = 22,
7590  kForInInitializer = 23,
7591  kArrayProtectorDirtied = 24,
7592  kArraySpeciesModified = 25,
7593  kArrayPrototypeConstructorModified = 26,
7594  kArrayInstanceProtoModified = 27,
7595  kArrayInstanceConstructorModified = 28,
7596  kLegacyFunctionDeclaration = 29,
7597  kRegExpPrototypeSourceGetter = 30,
7598  kRegExpPrototypeOldFlagGetter = 31,
7599  kDecimalWithLeadingZeroInStrictMode = 32,
7600  kLegacyDateParser = 33,
7601  kDefineGetterOrSetterWouldThrow = 34,
7602  kFunctionConstructorReturnedUndefined = 35,
7603  kAssigmentExpressionLHSIsCallInSloppy = 36,
7604  kAssigmentExpressionLHSIsCallInStrict = 37,
7605  kPromiseConstructorReturnedUndefined = 38,
7606  kConstructorNonUndefinedPrimitiveReturn = 39,
7607  kLabeledExpressionStatement = 40,
7608  kLineOrParagraphSeparatorAsLineTerminator = 41,
7609  kIndexAccessor = 42,
7610  kErrorCaptureStackTrace = 43,
7611  kErrorPrepareStackTrace = 44,
7612  kErrorStackTraceLimit = 45,
7613  kWebAssemblyInstantiation = 46,
7614  kDeoptimizerDisableSpeculation = 47,
7615  kArrayPrototypeSortJSArrayModifiedPrototype = 48,
7616  kFunctionTokenOffsetTooLongForToString = 49,
7617  kWasmSharedMemory = 50,
7618  kWasmThreadOpcodes = 51,
7619  kAtomicsNotify = 52,
7620  kAtomicsWake = 53,
7621  kCollator = 54,
7622  kNumberFormat = 55,
7623  kDateTimeFormat = 56,
7624  kPluralRules = 57,
7625  kRelativeTimeFormat = 58,
7626  kLocale = 59,
7627  kListFormat = 60,
7628  kSegmenter = 61,
7629  kStringLocaleCompare = 62,
7630  kStringToLocaleUpperCase = 63,
7631  kStringToLocaleLowerCase = 64,
7632  kNumberToLocaleString = 65,
7633  kDateToLocaleString = 66,
7634  kDateToLocaleDateString = 67,
7635  kDateToLocaleTimeString = 68,
7636  kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
7637  kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
7638  kOptimizedFunctionWithOneShotBytecode = 71,
7639  kRegExpMatchIsTrueishOnNonJSRegExp = 72,
7640  kRegExpMatchIsFalseishOnJSRegExp = 73,
7641  kDateGetTimezoneOffset = 74,
7642  kStringNormalize = 75,
7643 
7644  // If you add new values here, you'll also need to update Chromium's:
7645  // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to
7646  // this list need to be landed first, then changes on the Chromium side.
7647  kUseCounterFeatureCount // This enum value must be last.
7648  };
7649 
7651  kMessageLog = (1 << 0),
7652  kMessageDebug = (1 << 1),
7653  kMessageInfo = (1 << 2),
7654  kMessageError = (1 << 3),
7655  kMessageWarning = (1 << 4),
7656  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7657  kMessageWarning,
7658  };
7659 
7660  typedef void (*UseCounterCallback)(Isolate* isolate,
7661  UseCounterFeature feature);
7662 
7677  static Isolate* Allocate();
7678 
7682  static void Initialize(Isolate* isolate, const CreateParams& params);
7683 
7693  static Isolate* New(const CreateParams& params);
7694 
7701  static Isolate* GetCurrent();
7702 
7712  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7713  void SetAbortOnUncaughtExceptionCallback(
7714  AbortOnUncaughtExceptionCallback callback);
7715 
7720  void SetHostImportModuleDynamicallyCallback(
7722 
7727  void SetHostInitializeImportMetaObjectCallback(
7729 
7734  void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
7735 
7742  void MemoryPressureNotification(MemoryPressureLevel level);
7743 
7754  void Enter();
7755 
7763  void Exit();
7764 
7769  void Dispose();
7770 
7775  void DumpAndResetStats();
7776 
7784  void DiscardThreadSpecificMetadata();
7785 
7790  V8_INLINE void SetData(uint32_t slot, void* data);
7791 
7796  V8_INLINE void* GetData(uint32_t slot);
7797 
7802  V8_INLINE static uint32_t GetNumberOfDataSlots();
7803 
7809  template <class T>
7810  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
7811 
7815  void GetHeapStatistics(HeapStatistics* heap_statistics);
7816 
7820  size_t NumberOfHeapSpaces();
7821 
7831  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7832  size_t index);
7833 
7837  size_t NumberOfTrackedHeapObjectTypes();
7838 
7848  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7849  size_t type_index);
7850 
7858  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7859 
7872  void GetStackSample(const RegisterState& state, void** frames,
7873  size_t frames_limit, SampleInfo* sample_info);
7874 
7888  V8_INLINE int64_t
7889  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7890 
7895  size_t NumberOfPhantomHandleResetsSinceLastCall();
7896 
7901  HeapProfiler* GetHeapProfiler();
7902 
7906  void SetIdle(bool is_idle);
7907 
7909  ArrayBuffer::Allocator* GetArrayBufferAllocator();
7910 
7912  bool InContext();
7913 
7918  Local<Context> GetCurrentContext();
7919 
7921  V8_DEPRECATED("Use GetEnteredOrMicrotaskContext().",
7922  Local<Context> GetEnteredContext());
7923 
7930  Local<Context> GetEnteredOrMicrotaskContext();
7931 
7936  Local<Context> GetIncumbentContext();
7937 
7944  Local<Value> ThrowException(Local<Value> exception);
7945 
7946  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7947  GCCallbackFlags flags);
7948  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7949  GCCallbackFlags flags, void* data);
7950 
7960  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
7961  GCType gc_type_filter = kGCTypeAll);
7962  void AddGCPrologueCallback(GCCallback callback,
7963  GCType gc_type_filter = kGCTypeAll);
7964 
7969  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
7970  void RemoveGCPrologueCallback(GCCallback callback);
7971 
7975  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7976 
7977  /*
7978  * Gets the currently active heap tracer for the isolate.
7979  */
7980  EmbedderHeapTracer* GetEmbedderHeapTracer();
7981 
7985  enum class AtomicsWaitEvent {
7987  kStartWait,
7989  kWokenUp,
7991  kTimedOut,
7993  kTerminatedExecution,
7995  kAPIStopped,
7997  kNotEqual
7998  };
7999 
8005  public:
8020  void Wake();
8021  };
8022 
8046  typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event,
8047  Local<SharedArrayBuffer> array_buffer,
8048  size_t offset_in_bytes, int64_t value,
8049  double timeout_in_ms,
8050  AtomicsWaitWakeHandle* stop_handle,
8051  void* data);
8052 
8059  void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
8060 
8070  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
8071  GCType gc_type_filter = kGCTypeAll);
8072  void AddGCEpilogueCallback(GCCallback callback,
8073  GCType gc_type_filter = kGCTypeAll);
8074 
8079  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
8080  void* data = nullptr);
8081  void RemoveGCEpilogueCallback(GCCallback callback);
8082 
8083  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
8084 
8091  void SetGetExternallyAllocatedMemoryInBytesCallback(
8092  GetExternallyAllocatedMemoryInBytesCallback callback);
8093 
8101  void TerminateExecution();
8102 
8111  bool IsExecutionTerminating();
8112 
8127  void CancelTerminateExecution();
8128 
8137  void RequestInterrupt(InterruptCallback callback, void* data);
8138 
8149  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
8150 
8154  void SetEventLogger(LogEventCallback that);
8155 
8162  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
8163 
8167  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
8168 
8176  void AddCallCompletedCallback(CallCompletedCallback callback);
8177 
8181  void RemoveCallCompletedCallback(CallCompletedCallback callback);
8182 
8187  void SetPromiseHook(PromiseHook hook);
8188 
8193  void SetPromiseRejectCallback(PromiseRejectCallback callback);
8194 
8199  void RunMicrotasks();
8200 
8204  void EnqueueMicrotask(Local<Function> microtask);
8205 
8209  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
8210 
8214  void SetMicrotasksPolicy(MicrotasksPolicy policy);
8215 
8219  MicrotasksPolicy GetMicrotasksPolicy() const;
8220 
8234  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8235 
8239  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8240 
8244  void SetUseCounterCallback(UseCounterCallback callback);
8245 
8250  void SetCounterFunction(CounterLookupCallback);
8251 
8258  void SetCreateHistogramFunction(CreateHistogramCallback);
8259  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
8260 
8275  bool IdleNotificationDeadline(double deadline_in_seconds);
8276 
8281  void LowMemoryNotification();
8282 
8292  int ContextDisposedNotification(bool dependant_context = true);
8293 
8298  void IsolateInForegroundNotification();
8299 
8304  void IsolateInBackgroundNotification();
8305 
8311  void EnableMemorySavingsMode();
8312 
8316  void DisableMemorySavingsMode();
8317 
8325  void SetRAILMode(RAILMode rail_mode);
8326 
8331  void IncreaseHeapLimitForDebugging();
8332 
8336  void RestoreOriginalHeapLimit();
8337 
8342  bool IsHeapLimitIncreasedForDebugging();
8343 
8366  void SetJitCodeEventHandler(JitCodeEventOptions options,
8367  JitCodeEventHandler event_handler);
8368 
8378  void SetStackLimit(uintptr_t stack_limit);
8379 
8395  void GetCodeRange(void** start, size_t* length_in_bytes);
8396 
8400  UnwindState GetUnwindState();
8401 
8403  void SetFatalErrorHandler(FatalErrorCallback that);
8404 
8406  void SetOOMErrorHandler(OOMErrorCallback that);
8407 
8413  void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
8414 
8422  void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
8423  size_t heap_limit);
8424 
8431  void AutomaticallyRestoreInitialHeapLimit(double threshold_percent = 0.5);
8432 
8437  void SetAllowCodeGenerationFromStringsCallback(
8439 
8444  void SetAllowWasmCodeGenerationCallback(
8446 
8451  void SetWasmModuleCallback(ExtensionCallback callback);
8452  void SetWasmInstanceCallback(ExtensionCallback callback);
8453 
8454  void SetWasmStreamingCallback(WasmStreamingCallback callback);
8455 
8456  void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback);
8457 
8462  bool IsDead();
8463 
8473  bool AddMessageListener(MessageCallback that,
8474  Local<Value> data = Local<Value>());
8475 
8487  bool AddMessageListenerWithErrorLevel(MessageCallback that,
8488  int message_levels,
8489  Local<Value> data = Local<Value>());
8490 
8494  void RemoveMessageListeners(MessageCallback that);
8495 
8497  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
8498 
8503  void SetCaptureStackTraceForUncaughtExceptions(
8504  bool capture, int frame_limit = 10,
8506 
8512  void VisitExternalResources(ExternalResourceVisitor* visitor);
8513 
8518  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
8519 
8527  V8_DEPRECATED(
8528  "Use VisitHandlesWithClassIds",
8529  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor));
8530 
8536  void VisitWeakHandles(PersistentHandleVisitor* visitor);
8537 
8542  bool IsInUse();
8543 
8549  void SetAllowAtomicsWait(bool allow);
8550 
8564  enum class TimeZoneDetection { kSkip, kRedetect };
8565 
8576  void DateTimeConfigurationChangeNotification(
8577  TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip);
8578 
8588  void LocaleConfigurationChangeNotification();
8589 
8590  Isolate() = delete;
8591  ~Isolate() = delete;
8592  Isolate(const Isolate&) = delete;
8593  Isolate& operator=(const Isolate&) = delete;
8594  // Deleting operator new and delete here is allowed as ctor and dtor is also
8595  // deleted.
8596  void* operator new(size_t size) = delete;
8597  void* operator new[](size_t size) = delete;
8598  void operator delete(void*, size_t) = delete;
8599  void operator delete[](void*, size_t) = delete;
8600 
8601  private:
8602  template <class K, class V, class Traits>
8604 
8605  internal::Address* GetDataFromSnapshotOnce(size_t index);
8606  void ReportExternalAllocationLimitReached();
8607  void CheckMemoryPressure();
8608 };
8609 
8611  public:
8612  const char* data;
8614 };
8615 
8616 
8621 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
8622 
8636 typedef uintptr_t (*ReturnAddressLocationResolver)(
8637  uintptr_t return_addr_location);
8638 
8639 
8643 class V8_EXPORT V8 {
8644  public:
8660  static void SetNativesDataBlob(StartupData* startup_blob);
8661  static void SetSnapshotDataBlob(StartupData* startup_blob);
8662 
8664  static void SetDcheckErrorHandler(DcheckErrorCallback that);
8665 
8666 
8670  static void SetFlagsFromString(const char* str, int length);
8671 
8675  static void SetFlagsFromCommandLine(int* argc,
8676  char** argv,
8677  bool remove_flags);
8678 
8680  static const char* GetVersion();
8681 
8686  static bool Initialize();
8687 
8692  static void SetEntropySource(EntropySource source);
8693 
8698  static void SetReturnAddressLocationResolver(
8699  ReturnAddressLocationResolver return_address_resolver);
8700 
8710  static bool Dispose();
8711 
8719  static bool InitializeICU(const char* icu_data_file = nullptr);
8720 
8733  static bool InitializeICUDefaultLocation(const char* exec_path,
8734  const char* icu_data_file = nullptr);
8735 
8752  static void InitializeExternalStartupData(const char* directory_path);
8753  static void InitializeExternalStartupData(const char* natives_blob,
8754  const char* snapshot_blob);
8759  static void InitializePlatform(Platform* platform);
8760 
8765  static void ShutdownPlatform();
8766