V8 API Reference Guide for node.js v9.8.0
v8.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "v8-version.h" // NOLINT(build/include)
26 #include "v8config.h" // NOLINT(build/include)
27 
28 // We reserve the V8_* prefix for macros defined in V8 public API and
29 // assume there are no name conflicts with the embedder's code.
30 
31 #ifdef V8_OS_WIN
32 
33 // Setup for Windows DLL export/import. When building the V8 DLL the
34 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
35 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
36 // static library or building a program which uses the V8 static library neither
37 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
38 #ifdef BUILDING_V8_SHARED
39 # define V8_EXPORT __declspec(dllexport)
40 #elif USING_V8_SHARED
41 # define V8_EXPORT __declspec(dllimport)
42 #else
43 # define V8_EXPORT
44 #endif // BUILDING_V8_SHARED
45 
46 #else // V8_OS_WIN
47 
48 // Setup for Linux shared library export.
49 #if V8_HAS_ATTRIBUTE_VISIBILITY
50 # ifdef BUILDING_V8_SHARED
51 # define V8_EXPORT __attribute__ ((visibility("default")))
52 # else
53 # define V8_EXPORT
54 # endif
55 #else
56 # define V8_EXPORT
57 #endif
58 
59 #endif // V8_OS_WIN
60 
64 namespace v8 {
65 
66 class AccessorSignature;
67 class Array;
68 class ArrayBuffer;
69 class Boolean;
70 class BooleanObject;
71 class Context;
72 class CpuProfiler;
73 class Data;
74 class Date;
75 class External;
76 class Function;
77 class FunctionTemplate;
78 class HeapProfiler;
79 class ImplementationUtilities;
80 class Int32;
81 class Integer;
82 class Isolate;
83 template <class T>
84 class Maybe;
85 class Name;
86 class Number;
87 class NumberObject;
88 class Object;
89 class ObjectOperationDescriptor;
90 class ObjectTemplate;
91 class Platform;
92 class Primitive;
93 class Promise;
94 class PropertyDescriptor;
95 class Proxy;
96 class RawOperationDescriptor;
97 class Script;
98 class SharedArrayBuffer;
99 class Signature;
100 class StartupData;
101 class StackFrame;
102 class StackTrace;
103 class String;
104 class StringObject;
105 class Symbol;
106 class SymbolObject;
107 class PrimitiveArray;
108 class Private;
109 class Uint32;
110 class Utils;
111 class Value;
112 class WasmCompiledModule;
113 template <class T> class Local;
114 template <class T>
116 template <class T> class Eternal;
117 template<class T> class NonCopyablePersistentTraits;
118 template<class T> class PersistentBase;
119 template <class T, class M = NonCopyablePersistentTraits<T> >
121 template <class T>
122 class Global;
123 template<class K, class V, class T> class PersistentValueMap;
124 template <class K, class V, class T>
126 template <class K, class V, class T>
127 class GlobalValueMap;
128 template<class V, class T> class PersistentValueVector;
129 template<class T, class P> class WeakCallbackObject;
130 class FunctionTemplate;
131 class ObjectTemplate;
132 template<typename T> class FunctionCallbackInfo;
133 template<typename T> class PropertyCallbackInfo;
134 class StackTrace;
135 class StackFrame;
136 class Isolate;
137 class CallHandlerHelper;
139 template<typename T> class ReturnValue;
140 
141 namespace internal {
142 class Arguments;
143 class DeferredHandles;
144 class Heap;
145 class HeapObject;
146 class Isolate;
147 class Object;
148 struct StreamedSource;
149 template<typename T> class CustomArguments;
150 class PropertyCallbackArguments;
151 class FunctionCallbackArguments;
152 class GlobalHandles;
153 } // namespace internal
154 
155 namespace debug {
156 class ConsoleCallArguments;
157 } // namespace debug
158 
159 // --- Handles ---
160 
161 #define TYPE_CHECK(T, S) \
162  while (false) { \
163  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
164  }
165 
197 template <class T>
198 class Local {
199  public:
200  V8_INLINE Local() : val_(0) {}
201  template <class S>
202  V8_INLINE Local(Local<S> that)
203  : val_(reinterpret_cast<T*>(*that)) {
209  TYPE_CHECK(T, S);
210  }
211 
215  V8_INLINE bool IsEmpty() const { return val_ == 0; }
216 
220  V8_INLINE void Clear() { val_ = 0; }
221 
222  V8_INLINE T* operator->() const { return val_; }
223 
224  V8_INLINE T* operator*() const { return val_; }
225 
232  template <class S>
233  V8_INLINE bool operator==(const Local<S>& that) const {
234  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
235  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
236  if (a == 0) return b == 0;
237  if (b == 0) return false;
238  return *a == *b;
239  }
240 
241  template <class S> V8_INLINE bool operator==(
242  const PersistentBase<S>& that) const {
243  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
244  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
245  if (a == 0) return b == 0;
246  if (b == 0) return false;
247  return *a == *b;
248  }
249 
256  template <class S>
257  V8_INLINE bool operator!=(const Local<S>& that) const {
258  return !operator==(that);
259  }
260 
261  template <class S> V8_INLINE bool operator!=(
262  const Persistent<S>& that) const {
263  return !operator==(that);
264  }
265 
271  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
272 #ifdef V8_ENABLE_CHECKS
273  // If we're going to perform the type check then we have to check
274  // that the handle isn't empty before doing the checked cast.
275  if (that.IsEmpty()) return Local<T>();
276 #endif
277  return Local<T>(T::Cast(*that));
278  }
279 
285  template <class S>
286  V8_INLINE Local<S> As() const {
287  return Local<S>::Cast(*this);
288  }
289 
295  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
296  V8_INLINE static Local<T> New(Isolate* isolate,
297  const PersistentBase<T>& that);
298 
299  private:
300  friend class Utils;
301  template<class F> friend class Eternal;
302  template<class F> friend class PersistentBase;
303  template<class F, class M> friend class Persistent;
304  template<class F> friend class Local;
305  template <class F>
306  friend class MaybeLocal;
307  template<class F> friend class FunctionCallbackInfo;
308  template<class F> friend class PropertyCallbackInfo;
309  friend class String;
310  friend class Object;
311  friend class Context;
312  friend class Private;
313  template<class F> friend class internal::CustomArguments;
314  friend Local<Primitive> Undefined(Isolate* isolate);
315  friend Local<Primitive> Null(Isolate* isolate);
316  friend Local<Boolean> True(Isolate* isolate);
317  friend Local<Boolean> False(Isolate* isolate);
318  friend class HandleScope;
319  friend class EscapableHandleScope;
320  template <class F1, class F2, class F3>
321  friend class PersistentValueMapBase;
322  template<class F1, class F2> friend class PersistentValueVector;
323  template <class F>
324  friend class ReturnValue;
325 
326  explicit V8_INLINE Local(T* that) : val_(that) {}
327  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
328  T* val_;
329 };
330 
331 
332 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
333 // Handle is an alias for Local for historical reasons.
334 template <class T>
335 using Handle = Local<T>;
336 #endif
337 
338 
349 template <class T>
350 class MaybeLocal {
351  public:
352  V8_INLINE MaybeLocal() : val_(nullptr) {}
353  template <class S>
354  V8_INLINE MaybeLocal(Local<S> that)
355  : val_(reinterpret_cast<T*>(*that)) {
356  TYPE_CHECK(T, S);
357  }
358 
359  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
360 
365  template <class S>
366  V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
367  out->val_ = IsEmpty() ? nullptr : this->val_;
368  return !IsEmpty();
369  }
370 
375  V8_INLINE Local<T> ToLocalChecked();
376 
381  template <class S>
382  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
383  return IsEmpty() ? default_value : Local<S>(val_);
384  }
385 
386  private:
387  T* val_;
388 };
389 
394 template <class T> class Eternal {
395  public:
396  V8_INLINE Eternal() : val_(nullptr) {}
397  template <class S>
398  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
399  Set(isolate, handle);
400  }
401  // Can only be safely called if already set.
402  V8_INLINE Local<T> Get(Isolate* isolate) const;
403  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
404  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
405 
406  private:
407  T* val_;
408 };
409 
410 
411 static const int kInternalFieldsInWeakCallback = 2;
412 static const int kEmbedderFieldsInWeakCallback = 2;
413 
414 template <typename T>
416  public:
417  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
418 
419  WeakCallbackInfo(Isolate* isolate, T* parameter,
420  void* embedder_fields[kEmbedderFieldsInWeakCallback],
421  Callback* callback)
422  : isolate_(isolate), parameter_(parameter), callback_(callback) {
423  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
424  embedder_fields_[i] = embedder_fields[i];
425  }
426  }
427 
428  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
429  V8_INLINE T* GetParameter() const { return parameter_; }
430  V8_INLINE void* GetInternalField(int index) const;
431 
432  V8_INLINE V8_DEPRECATED("use indexed version",
433  void* GetInternalField1() const) {
434  return embedder_fields_[0];
435  }
436  V8_INLINE V8_DEPRECATED("use indexed version",
437  void* GetInternalField2() const) {
438  return embedder_fields_[1];
439  }
440 
441  V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.",
442  bool IsFirstPass() const) {
443  return callback_ != nullptr;
444  }
445 
446  // When first called, the embedder MUST Reset() the Global which triggered the
447  // callback. The Global itself is unusable for anything else. No v8 other api
448  // calls may be called in the first callback. Should additional work be
449  // required, the embedder must set a second pass callback, which will be
450  // called after all the initial callbacks are processed.
451  // Calling SetSecondPassCallback on the second pass will immediately crash.
452  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
453 
454  private:
455  Isolate* isolate_;
456  T* parameter_;
457  Callback* callback_;
458  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
459 };
460 
461 
462 // kParameter will pass a void* parameter back to the callback, kInternalFields
463 // will pass the first two internal fields back to the callback, kFinalizer
464 // will pass a void* parameter back, but is invoked before the object is
465 // actually collected, so it can be resurrected. In the last case, it is not
466 // possible to request a second pass callback.
467 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };
468 
482 template <class T> class PersistentBase {
483  public:
488  V8_INLINE void Reset();
493  template <class S>
494  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
495 
500  template <class S>
501  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
502 
503  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
504  V8_INLINE void Empty() { val_ = 0; }
505 
506  V8_INLINE Local<T> Get(Isolate* isolate) const {
507  return Local<T>::New(isolate, *this);
508  }
509 
510  template <class S>
511  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
512  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
513  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
514  if (a == NULL) return b == NULL;
515  if (b == NULL) return false;
516  return *a == *b;
517  }
518 
519  template <class S>
520  V8_INLINE bool operator==(const Local<S>& that) const {
521  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
522  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
523  if (a == NULL) return b == NULL;
524  if (b == NULL) return false;
525  return *a == *b;
526  }
527 
528  template <class S>
529  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
530  return !operator==(that);
531  }
532 
533  template <class S>
534  V8_INLINE bool operator!=(const Local<S>& that) const {
535  return !operator==(that);
536  }
537 
545  template <typename P>
546  V8_INLINE void SetWeak(P* parameter,
547  typename WeakCallbackInfo<P>::Callback callback,
548  WeakCallbackType type);
549 
557  V8_INLINE void SetWeak();
558 
559  template<typename P>
560  V8_INLINE P* ClearWeak();
561 
562  // TODO(dcarney): remove this.
563  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
564 
570  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
571 
578  V8_INLINE void MarkIndependent();
579 
585  V8_INLINE void MarkActive();
586 
587  V8_INLINE bool IsIndependent() const;
588 
590  V8_INLINE bool IsNearDeath() const;
591 
593  V8_INLINE bool IsWeak() const;
594 
599  V8_INLINE void SetWrapperClassId(uint16_t class_id);
600 
605  V8_INLINE uint16_t WrapperClassId() const;
606 
607  PersistentBase(const PersistentBase& other) = delete; // NOLINT
608  void operator=(const PersistentBase&) = delete;
609 
610  private:
611  friend class Isolate;
612  friend class Utils;
613  template<class F> friend class Local;
614  template<class F1, class F2> friend class Persistent;
615  template <class F>
616  friend class Global;
617  template<class F> friend class PersistentBase;
618  template<class F> friend class ReturnValue;
619  template <class F1, class F2, class F3>
620  friend class PersistentValueMapBase;
621  template<class F1, class F2> friend class PersistentValueVector;
622  friend class Object;
623 
624  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
625  V8_INLINE static T* New(Isolate* isolate, T* that);
626 
627  T* val_;
628 };
629 
630 
637 template<class T>
639  public:
640  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
641  static const bool kResetInDestructor = false;
642  template<class S, class M>
643  V8_INLINE static void Copy(const Persistent<S, M>& source,
644  NonCopyablePersistent* dest) {
645  Uncompilable<Object>();
646  }
647  // TODO(dcarney): come up with a good compile error here.
648  template<class O> V8_INLINE static void Uncompilable() {
649  TYPE_CHECK(O, Primitive);
650  }
651 };
652 
653 
658 template<class T>
661  static const bool kResetInDestructor = true;
662  template<class S, class M>
663  static V8_INLINE void Copy(const Persistent<S, M>& source,
664  CopyablePersistent* dest) {
665  // do nothing, just allow copy
666  }
667 };
668 
669 
678 template <class T, class M> class Persistent : public PersistentBase<T> {
679  public:
683  V8_INLINE Persistent() : PersistentBase<T>(0) { }
689  template <class S>
690  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
691  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
692  TYPE_CHECK(T, S);
693  }
699  template <class S, class M2>
700  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
701  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
702  TYPE_CHECK(T, S);
703  }
710  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
711  Copy(that);
712  }
713  template <class S, class M2>
714  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
715  Copy(that);
716  }
717  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
718  Copy(that);
719  return *this;
720  }
721  template <class S, class M2>
722  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
723  Copy(that);
724  return *this;
725  }
731  V8_INLINE ~Persistent() {
732  if (M::kResetInDestructor) this->Reset();
733  }
734 
735  // TODO(dcarney): this is pretty useless, fix or remove
736  template <class S>
737  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
738 #ifdef V8_ENABLE_CHECKS
739  // If we're going to perform the type check then we have to check
740  // that the handle isn't empty before doing the checked cast.
741  if (!that.IsEmpty()) T::Cast(*that);
742 #endif
743  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
744  }
745 
746  // TODO(dcarney): this is pretty useless, fix or remove
747  template <class S>
748  V8_INLINE Persistent<S>& As() const { // NOLINT
749  return Persistent<S>::Cast(*this);
750  }
751 
752  private:
753  friend class Isolate;
754  friend class Utils;
755  template<class F> friend class Local;
756  template<class F1, class F2> friend class Persistent;
757  template<class F> friend class ReturnValue;
758 
759  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
760  V8_INLINE T* operator*() const { return this->val_; }
761  template<class S, class M2>
762  V8_INLINE void Copy(const Persistent<S, M2>& that);
763 };
764 
765 
771 template <class T>
772 class Global : public PersistentBase<T> {
773  public:
777  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
783  template <class S>
784  V8_INLINE Global(Isolate* isolate, Local<S> that)
785  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
786  TYPE_CHECK(T, S);
787  }
793  template <class S>
794  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
795  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
796  TYPE_CHECK(T, S);
797  }
801  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
802  other.val_ = nullptr;
803  }
804  V8_INLINE ~Global() { this->Reset(); }
808  template <class S>
809  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
810  TYPE_CHECK(T, S);
811  if (this != &rhs) {
812  this->Reset();
813  this->val_ = rhs.val_;
814  rhs.val_ = nullptr;
815  }
816  return *this;
817  }
821  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
822 
823  /*
824  * For compatibility with Chromium's base::Bind (base::Passed).
825  */
826  typedef void MoveOnlyTypeForCPP03;
827 
828  Global(const Global&) = delete;
829  void operator=(const Global&) = delete;
830 
831  private:
832  template <class F>
833  friend class ReturnValue;
834  V8_INLINE T* operator*() const { return this->val_; }
835 };
836 
837 
838 // UniquePersistent is an alias for Global for historical reason.
839 template <class T>
841 
842 
857 class V8_EXPORT HandleScope {
858  public:
859  explicit HandleScope(Isolate* isolate);
860 
861  ~HandleScope();
862 
866  static int NumberOfHandles(Isolate* isolate);
867 
868  V8_INLINE Isolate* GetIsolate() const {
869  return reinterpret_cast<Isolate*>(isolate_);
870  }
871 
872  HandleScope(const HandleScope&) = delete;
873  void operator=(const HandleScope&) = delete;
874 
875  protected:
876  V8_INLINE HandleScope() {}
877 
878  void Initialize(Isolate* isolate);
879 
880  static internal::Object** CreateHandle(internal::Isolate* isolate,
881  internal::Object* value);
882 
883  private:
884  // Declaring operator new and delete as deleted is not spec compliant.
885  // Therefore declare them private instead to disable dynamic alloc
886  void* operator new(size_t size);
887  void* operator new[](size_t size);
888  void operator delete(void*, size_t);
889  void operator delete[](void*, size_t);
890 
891  // Uses heap_object to obtain the current Isolate.
892  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
893  internal::Object* value);
894 
895  internal::Isolate* isolate_;
896  internal::Object** prev_next_;
897  internal::Object** prev_limit_;
898 
899  // Local::New uses CreateHandle with an Isolate* parameter.
900  template<class F> friend class Local;
901 
902  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
903  // a HeapObject* in their shortcuts.
904  friend class Object;
905  friend class Context;
906 };
907 
908 
913 class V8_EXPORT EscapableHandleScope : public HandleScope {
914  public:
915  explicit EscapableHandleScope(Isolate* isolate);
916  V8_INLINE ~EscapableHandleScope() {}
917 
922  template <class T>
923  V8_INLINE Local<T> Escape(Local<T> value) {
924  internal::Object** slot =
925  Escape(reinterpret_cast<internal::Object**>(*value));
926  return Local<T>(reinterpret_cast<T*>(slot));
927  }
928 
930  void operator=(const EscapableHandleScope&) = delete;
931 
932  private:
933  // Declaring operator new and delete as deleted is not spec compliant.
934  // Therefore declare them private instead to disable dynamic alloc
935  void* operator new(size_t size);
936  void* operator new[](size_t size);
937  void operator delete(void*, size_t);
938  void operator delete[](void*, size_t);
939 
940  internal::Object** Escape(internal::Object** escape_value);
941  internal::Object** escape_slot_;
942 };
943 
949 class V8_EXPORT SealHandleScope {
950  public:
951  SealHandleScope(Isolate* isolate);
952  ~SealHandleScope();
953 
954  SealHandleScope(const SealHandleScope&) = delete;
955  void operator=(const SealHandleScope&) = delete;
956 
957  private:
958  // Declaring operator new and delete as deleted is not spec compliant.
959  // Therefore declare them private instead to disable dynamic alloc
960  void* operator new(size_t size);
961  void* operator new[](size_t size);
962  void operator delete(void*, size_t);
963  void operator delete[](void*, size_t);
964 
965  internal::Isolate* const isolate_;
966  internal::Object** prev_limit_;
967  int prev_sealed_level_;
968 };
969 
970 
971 // --- Special objects ---
972 
973 
977 class V8_EXPORT Data {
978  private:
979  Data();
980 };
981 
991 class V8_EXPORT ScriptOrModule {
992  public:
997  Local<Value> GetResourceName();
998 
1003  Local<PrimitiveArray> GetHostDefinedOptions();
1004 };
1005 
1017 class V8_EXPORT PrimitiveArray {
1018  public:
1019  static Local<PrimitiveArray> New(Isolate* isolate, int length);
1020  int Length() const;
1021  void Set(int index, Local<Primitive> item);
1022  Local<Primitive> Get(int index);
1023 };
1024 
1029  public:
1030  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
1031  bool is_opaque = false, bool is_wasm = false,
1032  bool is_module = false)
1033  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1034  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
1035  (is_module ? kIsModule : 0)) {}
1036  V8_INLINE ScriptOriginOptions(int flags)
1037  : flags_(flags &
1038  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
1039 
1040  bool IsSharedCrossOrigin() const {
1041  return (flags_ & kIsSharedCrossOrigin) != 0;
1042  }
1043  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1044  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1045  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1046 
1047  int Flags() const { return flags_; }
1048 
1049  private:
1050  enum {
1051  kIsSharedCrossOrigin = 1,
1052  kIsOpaque = 1 << 1,
1053  kIsWasm = 1 << 2,
1054  kIsModule = 1 << 3
1055  };
1056  const int flags_;
1057 };
1058 
1063  public:
1064  V8_INLINE ScriptOrigin(
1065  Local<Value> resource_name,
1066  Local<Integer> resource_line_offset = Local<Integer>(),
1067  Local<Integer> resource_column_offset = Local<Integer>(),
1068  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1069  Local<Integer> script_id = Local<Integer>(),
1070  Local<Value> source_map_url = Local<Value>(),
1071  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1072  Local<Boolean> is_wasm = Local<Boolean>(),
1073  Local<Boolean> is_module = Local<Boolean>() /*,
1074  // Backed out for ABI compatibility with V8 6.2
1075  Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>() */);
1076 
1077  V8_INLINE Local<Value> ResourceName() const;
1078  V8_INLINE Local<Integer> ResourceLineOffset() const;
1079  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1080  V8_INLINE Local<Integer> ScriptID() const;
1081  V8_INLINE Local<Value> SourceMapUrl() const;
1082  // Backed out for ABI compatibility with V8 6.2
1083  // V8_INLINE Local<PrimitiveArray> HostDefinedOptions() const;
1084  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1085 
1086  private:
1087  Local<Value> resource_name_;
1088  Local<Integer> resource_line_offset_;
1089  Local<Integer> resource_column_offset_;
1090  ScriptOriginOptions options_;
1091  Local<Integer> script_id_;
1092  Local<Value> source_map_url_;
1093  // Backed out for ABI compatibility with V8 6.2
1094  // Local<PrimitiveArray> host_defined_options_;
1095 };
1096 
1100 class V8_EXPORT UnboundScript {
1101  public:
1105  Local<Script> BindToCurrentContext();
1106 
1107  int GetId();
1108  Local<Value> GetScriptName();
1109 
1113  Local<Value> GetSourceURL();
1117  Local<Value> GetSourceMappingURL();
1118 
1123  int GetLineNumber(int code_pos);
1124 
1125  static const int kNoScriptId = 0;
1126 };
1127 
1131 class V8_EXPORT Location {
1132  public:
1133  int GetLineNumber() { return line_number_; }
1134  int GetColumnNumber() { return column_number_; }
1135 
1136  Location(int line_number, int column_number)
1137  : line_number_(line_number), column_number_(column_number) {}
1138 
1139  private:
1140  int line_number_;
1141  int column_number_;
1142 };
1143 
1150 class V8_EXPORT Module {
1151  public:
1155  enum Status {
1156  kUninstantiated,
1157  kInstantiating,
1158  kInstantiated,
1159  kEvaluating,
1160  kEvaluated,
1161  kErrored
1162  };
1163 
1167  Status GetStatus() const;
1168 
1172  Local<Value> GetException() const;
1173 
1177  int GetModuleRequestsLength() const;
1178 
1183  Local<String> GetModuleRequest(int i) const;
1184 
1189  Location GetModuleRequestLocation(int i) const;
1190 
1194  int GetIdentityHash() const;
1195 
1196  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1197  Local<String> specifier,
1198  Local<Module> referrer);
1199 
1207  V8_DEPRECATED("Use Maybe<bool> version",
1208  bool Instantiate(Local<Context> context,
1209  ResolveCallback callback));
1210  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1211  ResolveCallback callback);
1212 
1219  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
1220 
1225  Local<Value> GetModuleNamespace();
1226 };
1227 
1232 class V8_EXPORT Script {
1233  public:
1237  static V8_DEPRECATE_SOON(
1238  "Use maybe version",
1239  Local<Script> Compile(Local<String> source,
1240  ScriptOrigin* origin = nullptr));
1241  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1242  Local<Context> context, Local<String> source,
1243  ScriptOrigin* origin = nullptr);
1244 
1245  static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
1246  Compile(Local<String> source,
1247  Local<String> file_name));
1248 
1254  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
1255  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1256 
1260  Local<UnboundScript> GetUnboundScript();
1261 };
1262 
1263 
1267 class V8_EXPORT ScriptCompiler {
1268  public:
1276  struct V8_EXPORT CachedData {
1277  enum BufferPolicy {
1278  BufferNotOwned,
1279  BufferOwned
1280  };
1281 
1282  CachedData()
1283  : data(NULL),
1284  length(0),
1285  rejected(false),
1286  buffer_policy(BufferNotOwned) {}
1287 
1288  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1289  // data and guarantees that it stays alive until the CachedData object is
1290  // destroyed. If the policy is BufferOwned, the given data will be deleted
1291  // (with delete[]) when the CachedData object is destroyed.
1292  CachedData(const uint8_t* data, int length,
1293  BufferPolicy buffer_policy = BufferNotOwned);
1294  ~CachedData();
1295  // TODO(marja): Async compilation; add constructors which take a callback
1296  // which will be called when V8 no longer needs the data.
1297  const uint8_t* data;
1298  int length;
1299  bool rejected;
1300  BufferPolicy buffer_policy;
1301 
1302  // Prevent copying.
1303  CachedData(const CachedData&) = delete;
1304  CachedData& operator=(const CachedData&) = delete;
1305  };
1306 
1310  class Source {
1311  public:
1312  // Source takes ownership of CachedData.
1313  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1314  CachedData* cached_data = NULL);
1315  V8_INLINE Source(Local<String> source_string,
1316  CachedData* cached_data = NULL);
1317  V8_INLINE ~Source();
1318 
1319  // Ownership of the CachedData or its buffers is *not* transferred to the
1320  // caller. The CachedData object is alive as long as the Source object is
1321  // alive.
1322  V8_INLINE const CachedData* GetCachedData() const;
1323 
1324  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1325 
1326  // Prevent copying.
1327  Source(const Source&) = delete;
1328  Source& operator=(const Source&) = delete;
1329 
1330  private:
1331  friend class ScriptCompiler;
1332 
1333  Local<String> source_string;
1334 
1335  // Origin information
1336  Local<Value> resource_name;
1337  Local<Integer> resource_line_offset;
1338  Local<Integer> resource_column_offset;
1339  ScriptOriginOptions resource_options;
1340  Local<Value> source_map_url;
1341  // Local<PrimitiveArray> host_defined_options;
1342 
1343  // Cached data from previous compilation (if a kConsume*Cache flag is
1344  // set), or hold newly generated cache data (kProduce*Cache flags) are
1345  // set when calling a compile method.
1346  CachedData* cached_data;
1347  };
1348 
1353  class V8_EXPORT ExternalSourceStream {
1354  public:
1355  virtual ~ExternalSourceStream() {}
1356 
1374  virtual size_t GetMoreData(const uint8_t** src) = 0;
1375 
1386  virtual bool SetBookmark();
1387 
1391  virtual void ResetToBookmark();
1392  };
1393 
1394 
1401  class V8_EXPORT StreamedSource {
1402  public:
1403  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1404 
1405  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1406  ~StreamedSource();
1407 
1408  // Ownership of the CachedData or its buffers is *not* transferred to the
1409  // caller. The CachedData object is alive as long as the StreamedSource
1410  // object is alive.
1411  const CachedData* GetCachedData() const;
1412 
1413  internal::StreamedSource* impl() const { return impl_; }
1414 
1415  // Prevent copying.
1416  StreamedSource(const StreamedSource&) = delete;
1417  StreamedSource& operator=(const StreamedSource&) = delete;
1418 
1419  private:
1420  internal::StreamedSource* impl_;
1421  };
1422 
1428  public:
1429  virtual ~ScriptStreamingTask() {}
1430  virtual void Run() = 0;
1431  };
1432 
1433  enum CompileOptions {
1434  kNoCompileOptions = 0,
1435  kProduceParserCache,
1436  kConsumeParserCache,
1437  kProduceCodeCache,
1438  kConsumeCodeCache
1439  };
1440 
1454  static V8_DEPRECATED("Use maybe version",
1455  Local<UnboundScript> CompileUnbound(
1456  Isolate* isolate, Source* source,
1457  CompileOptions options = kNoCompileOptions));
1458  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1459  Isolate* isolate, Source* source,
1460  CompileOptions options = kNoCompileOptions);
1461 
1473  static V8_DEPRECATED(
1474  "Use maybe version",
1475  Local<Script> Compile(Isolate* isolate, Source* source,
1476  CompileOptions options = kNoCompileOptions));
1477  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1478  Local<Context> context, Source* source,
1479  CompileOptions options = kNoCompileOptions);
1480 
1492  static ScriptStreamingTask* StartStreamingScript(
1493  Isolate* isolate, StreamedSource* source,
1494  CompileOptions options = kNoCompileOptions);
1495 
1503  static V8_DEPRECATED("Use maybe version",
1504  Local<Script> Compile(Isolate* isolate,
1505  StreamedSource* source,
1506  Local<String> full_source_string,
1507  const ScriptOrigin& origin));
1508  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1509  Local<Context> context, StreamedSource* source,
1510  Local<String> full_source_string, const ScriptOrigin& origin);
1511 
1530  static uint32_t CachedDataVersionTag();
1531 
1542  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1543  Isolate* isolate, Source* source);
1544 
1555  static V8_DEPRECATE_SOON("Use maybe version",
1556  Local<Function> CompileFunctionInContext(
1557  Isolate* isolate, Source* source,
1558  Local<Context> context, size_t arguments_count,
1559  Local<String> arguments[],
1560  size_t context_extension_count,
1561  Local<Object> context_extensions[]));
1562  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1563  Local<Context> context, Source* source, size_t arguments_count,
1564  Local<String> arguments[], size_t context_extension_count,
1565  Local<Object> context_extensions[]);
1566 
1567  private:
1568  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1569  Isolate* isolate, Source* source, CompileOptions options);
1570 };
1571 
1572 
1576 class V8_EXPORT Message {
1577  public:
1578  Local<String> Get() const;
1579 
1580  V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
1581  V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
1582  Local<Context> context) const;
1583 
1588  ScriptOrigin GetScriptOrigin() const;
1589 
1594  Local<Value> GetScriptResourceName() const;
1595 
1601  Local<StackTrace> GetStackTrace() const;
1602 
1606  V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
1607  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1608 
1613  int GetStartPosition() const;
1614 
1619  int GetEndPosition() const;
1620 
1624  int ErrorLevel() const;
1625 
1630  V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
1631  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1632 
1637  V8_DEPRECATED("Use maybe version", int GetEndColumn() const);
1638  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1639 
1644  bool IsSharedCrossOrigin() const;
1645  bool IsOpaque() const;
1646 
1647  // TODO(1245381): Print to a string instead of on a FILE.
1648  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1649 
1650  static const int kNoLineNumberInfo = 0;
1651  static const int kNoColumnInfo = 0;
1652  static const int kNoScriptIdInfo = 0;
1653 };
1654 
1655 
1661 class V8_EXPORT StackTrace {
1662  public:
1670  kLineNumber = 1,
1671  kColumnOffset = 1 << 1 | kLineNumber,
1672  kScriptName = 1 << 2,
1673  kFunctionName = 1 << 3,
1674  kIsEval = 1 << 4,
1675  kIsConstructor = 1 << 5,
1676  kScriptNameOrSourceURL = 1 << 6,
1677  kScriptId = 1 << 7,
1678  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1679  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1680  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1681  };
1682 
1686  Local<StackFrame> GetFrame(uint32_t index) const;
1687 
1691  int GetFrameCount() const;
1692 
1696  V8_DEPRECATED("Use native API instead", Local<Array> AsArray());
1697 
1705  static Local<StackTrace> CurrentStackTrace(
1706  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1707 };
1708 
1709 
1713 class V8_EXPORT StackFrame {
1714  public:
1721  int GetLineNumber() const;
1722 
1730  int GetColumn() const;
1731 
1738  int GetScriptId() const;
1739 
1744  Local<String> GetScriptName() const;
1745 
1752  Local<String> GetScriptNameOrSourceURL() const;
1753 
1757  Local<String> GetFunctionName() const;
1758 
1763  bool IsEval() const;
1764 
1769  bool IsConstructor() const;
1770 
1774  bool IsWasm() const;
1775 };
1776 
1777 
1778 // A StateTag represents a possible state of the VM.
1779 enum StateTag {
1780  JS,
1781  GC,
1782  PARSER,
1783  BYTECODE_COMPILER,
1784  COMPILER,
1785  OTHER,
1786  EXTERNAL,
1787  IDLE
1788 };
1789 
1790 // A RegisterState represents the current state of registers used
1791 // by the sampling profiler API.
1793  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1794  void* pc; // Instruction pointer.
1795  void* sp; // Stack pointer.
1796  void* fp; // Frame pointer.
1797 };
1798 
1799 // The output structure filled up by GetStackSample API function.
1800 struct SampleInfo {
1801  size_t frames_count; // Number of frames collected.
1802  StateTag vm_state; // Current VM state.
1803  void* external_callback_entry; // External callback address if VM is
1804  // executing an external callback.
1805 };
1806 
1810 class V8_EXPORT JSON {
1811  public:
1819  static V8_DEPRECATED("Use the maybe version taking context",
1820  Local<Value> Parse(Local<String> json_string));
1821  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1822  MaybeLocal<Value> Parse(Isolate* isolate,
1823  Local<String> json_string));
1824  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1825  Local<Context> context, Local<String> json_string);
1826 
1834  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1835  Local<Context> context, Local<Object> json_object,
1836  Local<String> gap = Local<String>());
1837 };
1838 
1847 class V8_EXPORT ValueSerializer {
1848  public:
1849  class V8_EXPORT Delegate {
1850  public:
1851  virtual ~Delegate() {}
1852 
1858  virtual void ThrowDataCloneError(Local<String> message) = 0;
1859 
1865  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
1866 
1877  virtual Maybe<uint32_t> GetSharedArrayBufferId(
1878  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
1879 
1880  virtual Maybe<uint32_t> GetWasmModuleTransferId(
1881  Isolate* isolate, Local<WasmCompiledModule> module);
1891  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
1892  size_t* actual_size);
1893 
1897  virtual void FreeBufferMemory(void* buffer);
1898  };
1899 
1900  explicit ValueSerializer(Isolate* isolate);
1901  ValueSerializer(Isolate* isolate, Delegate* delegate);
1902  ~ValueSerializer();
1903 
1907  void WriteHeader();
1908 
1912  V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
1913  Local<Value> value);
1914 
1919  V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
1920 
1927  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
1928 
1934  void TransferArrayBuffer(uint32_t transfer_id,
1935  Local<ArrayBuffer> array_buffer);
1936 
1940  V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
1941  void TransferSharedArrayBuffer(
1942  uint32_t transfer_id,
1943  Local<SharedArrayBuffer> shared_array_buffer));
1944 
1952  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
1953 
1959  void WriteUint32(uint32_t value);
1960  void WriteUint64(uint64_t value);
1961  void WriteDouble(double value);
1962  void WriteRawBytes(const void* source, size_t length);
1963 
1964  private:
1965  ValueSerializer(const ValueSerializer&) = delete;
1966  void operator=(const ValueSerializer&) = delete;
1967 
1968  struct PrivateData;
1969  PrivateData* private_;
1970 };
1971 
1980 class V8_EXPORT ValueDeserializer {
1981  public:
1982  class V8_EXPORT Delegate {
1983  public:
1984  virtual ~Delegate() {}
1985 
1991  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
1992 
1997  virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
1998  Isolate* isolate, uint32_t transfer_id);
1999  };
2000 
2001  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
2002  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
2003  Delegate* delegate);
2004  ~ValueDeserializer();
2005 
2010  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
2011 
2015  V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
2016 
2021  void TransferArrayBuffer(uint32_t transfer_id,
2022  Local<ArrayBuffer> array_buffer);
2023 
2029  void TransferSharedArrayBuffer(uint32_t id,
2030  Local<SharedArrayBuffer> shared_array_buffer);
2031 
2039  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2040 
2044  void SetExpectInlineWasm(bool allow_inline_wasm);
2045 
2051  uint32_t GetWireFormatVersion() const;
2052 
2058  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2059  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2060  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2061  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2062 
2063  private:
2064  ValueDeserializer(const ValueDeserializer&) = delete;
2065  void operator=(const ValueDeserializer&) = delete;
2066 
2067  struct PrivateData;
2068  PrivateData* private_;
2069 };
2070 
2076 class V8_EXPORT NativeWeakMap : public Data {
2077  public:
2078  static Local<NativeWeakMap> New(Isolate* isolate);
2079  void Set(Local<Value> key, Local<Value> value);
2080  Local<Value> Get(Local<Value> key) const;
2081  bool Has(Local<Value> key);
2082  bool Delete(Local<Value> key);
2083 };
2084 
2085 
2086 // --- Value ---
2087 
2088 
2092 class V8_EXPORT Value : public Data {
2093  public:
2098  V8_INLINE bool IsUndefined() const;
2099 
2104  V8_INLINE bool IsNull() const;
2105 
2111  V8_INLINE bool IsNullOrUndefined() const;
2112 
2116  bool IsTrue() const;
2117 
2121  bool IsFalse() const;
2122 
2126  bool IsName() const;
2127 
2132  V8_INLINE bool IsString() const;
2133 
2137  bool IsSymbol() const;
2138 
2142  bool IsFunction() const;
2143 
2148  bool IsArray() const;
2149 
2153  bool IsObject() const;
2154 
2158  bool IsBoolean() const;
2159 
2163  bool IsNumber() const;
2164 
2168  bool IsExternal() const;
2169 
2173  bool IsInt32() const;
2174 
2178  bool IsUint32() const;
2179 
2183  bool IsDate() const;
2184 
2188  bool IsArgumentsObject() const;
2189 
2193  bool IsBooleanObject() const;
2194 
2198  bool IsNumberObject() const;
2199 
2203  bool IsStringObject() const;
2204 
2208  bool IsSymbolObject() const;
2209 
2213  bool IsNativeError() const;
2214 
2218  bool IsRegExp() const;
2219 
2223  bool IsAsyncFunction() const;
2224 
2228  bool IsGeneratorFunction() const;
2229 
2233  bool IsGeneratorObject() const;
2234 
2238  bool IsPromise() const;
2239 
2243  bool IsMap() const;
2244 
2248  bool IsSet() const;
2249 
2253  bool IsMapIterator() const;
2254 
2258  bool IsSetIterator() const;
2259 
2263  bool IsWeakMap() const;
2264 
2268  bool IsWeakSet() const;
2269 
2273  bool IsArrayBuffer() const;
2274 
2278  bool IsArrayBufferView() const;
2279 
2283  bool IsTypedArray() const;
2284 
2288  bool IsUint8Array() const;
2289 
2293  bool IsUint8ClampedArray() const;
2294 
2298  bool IsInt8Array() const;
2299 
2303  bool IsUint16Array() const;
2304 
2308  bool IsInt16Array() const;
2309 
2313  bool IsUint32Array() const;
2314 
2318  bool IsInt32Array() const;
2319 
2323  bool IsFloat32Array() const;
2324 
2328  bool IsFloat64Array() const;
2329 
2333  bool IsDataView() const;
2334 
2339  bool IsSharedArrayBuffer() const;
2340 
2344  bool IsProxy() const;
2345 
2346  bool IsWebAssemblyCompiledModule() const;
2347 
2348  V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
2349  Local<Context> context) const;
2350  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
2351  Local<Context> context) const;
2352  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
2353  Local<Context> context) const;
2354  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
2355  Local<Context> context) const;
2356  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
2357  Local<Context> context) const;
2358  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
2359  Local<Context> context) const;
2360  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
2361  Local<Context> context) const;
2362  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
2363 
2364  V8_DEPRECATE_SOON("Use maybe version",
2365  Local<Boolean> ToBoolean(Isolate* isolate) const);
2366  V8_DEPRECATE_SOON("Use maybe version",
2367  Local<Number> ToNumber(Isolate* isolate) const);
2368  V8_DEPRECATE_SOON("Use maybe version",
2369  Local<String> ToString(Isolate* isolate) const);
2370  V8_DEPRECATED("Use maybe version",
2371  Local<String> ToDetailString(Isolate* isolate) const);
2372  V8_DEPRECATE_SOON("Use maybe version",
2373  Local<Object> ToObject(Isolate* isolate) const);
2374  V8_DEPRECATE_SOON("Use maybe version",
2375  Local<Integer> ToInteger(Isolate* isolate) const);
2376  V8_DEPRECATED("Use maybe version",
2377  Local<Uint32> ToUint32(Isolate* isolate) const);
2378  V8_DEPRECATE_SOON("Use maybe version",
2379  Local<Int32> ToInt32(Isolate* isolate) const);
2380 
2381  inline V8_DEPRECATE_SOON("Use maybe version",
2382  Local<Boolean> ToBoolean() const);
2383  inline V8_DEPRECATED("Use maybe version", Local<Number> ToNumber() const);
2384  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
2385  inline V8_DEPRECATED("Use maybe version",
2386  Local<String> ToDetailString() const);
2387  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
2388  inline V8_DEPRECATE_SOON("Use maybe version",
2389  Local<Integer> ToInteger() const);
2390  inline V8_DEPRECATED("Use maybe version", Local<Uint32> ToUint32() const);
2391  inline V8_DEPRECATED("Use maybe version", Local<Int32> ToInt32() const);
2392 
2397  V8_DEPRECATED("Use maybe version", Local<Uint32> ToArrayIndex() const);
2398  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
2399  Local<Context> context) const;
2400 
2401  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2402  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2403  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2404  Local<Context> context) const;
2405  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2406  Local<Context> context) const;
2407  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2408 
2409  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2410  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2411  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2412  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2413  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2414 
2416  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2417  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2418  Local<Value> that) const;
2419  bool StrictEquals(Local<Value> that) const;
2420  bool SameValue(Local<Value> that) const;
2421 
2422  template <class T> V8_INLINE static Value* Cast(T* value);
2423 
2424  Local<String> TypeOf(Isolate*);
2425 
2426  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2427 
2428  private:
2429  V8_INLINE bool QuickIsUndefined() const;
2430  V8_INLINE bool QuickIsNull() const;
2431  V8_INLINE bool QuickIsNullOrUndefined() const;
2432  V8_INLINE bool QuickIsString() const;
2433  bool FullIsUndefined() const;
2434  bool FullIsNull() const;
2435  bool FullIsString() const;
2436 };
2437 
2438 
2442 class V8_EXPORT Primitive : public Value { };
2443 
2444 
2449 class V8_EXPORT Boolean : public Primitive {
2450  public:
2451  bool Value() const;
2452  V8_INLINE static Boolean* Cast(v8::Value* obj);
2453  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2454 
2455  private:
2456  static void CheckCast(v8::Value* obj);
2457 };
2458 
2459 
2463 class V8_EXPORT Name : public Primitive {
2464  public:
2472  int GetIdentityHash();
2473 
2474  V8_INLINE static Name* Cast(Value* obj);
2475 
2476  private:
2477  static void CheckCast(Value* obj);
2478 };
2479 
2486 enum class NewStringType {
2490  kNormal,
2491 
2498 };
2499 
2503 class V8_EXPORT String : public Name {
2504  public:
2505  static constexpr int kMaxLength =
2506  sizeof(void*) == 4 ? (1 << 28) - 16 : (1 << 30) - 1 - 24;
2507 
2508  enum Encoding {
2509  UNKNOWN_ENCODING = 0x1,
2510  TWO_BYTE_ENCODING = 0x0,
2511  ONE_BYTE_ENCODING = 0x8
2512  };
2516  int Length() const;
2517 
2522  int Utf8Length() const;
2523 
2530  bool IsOneByte() const;
2531 
2537  bool ContainsOnlyOneByte() const;
2538 
2565  NO_OPTIONS = 0,
2566  HINT_MANY_WRITES_EXPECTED = 1,
2567  NO_NULL_TERMINATION = 2,
2568  PRESERVE_ONE_BYTE_NULL = 4,
2569  // Used by WriteUtf8 to replace orphan surrogate code units with the
2570  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2571  // output.
2572  REPLACE_INVALID_UTF8 = 8
2573  };
2574 
2575  // 16-bit character codes.
2576  int Write(uint16_t* buffer,
2577  int start = 0,
2578  int length = -1,
2579  int options = NO_OPTIONS) const;
2580  // One byte characters.
2581  int WriteOneByte(uint8_t* buffer,
2582  int start = 0,
2583  int length = -1,
2584  int options = NO_OPTIONS) const;
2585  // UTF-8 encoded characters.
2586  int WriteUtf8(char* buffer,
2587  int length = -1,
2588  int* nchars_ref = NULL,
2589  int options = NO_OPTIONS) const;
2590 
2594  V8_INLINE static Local<String> Empty(Isolate* isolate);
2595 
2599  bool IsExternal() const;
2600 
2604  bool IsExternalOneByte() const;
2605 
2606  class V8_EXPORT ExternalStringResourceBase { // NOLINT
2607  public:
2608  virtual ~ExternalStringResourceBase() {}
2609 
2610  virtual bool IsCompressible() const { return false; }
2611 
2612  protected:
2614 
2621  virtual void Dispose() { delete this; }
2622 
2623  // Disallow copying and assigning.
2625  void operator=(const ExternalStringResourceBase&) = delete;
2626 
2627  private:
2628  friend class internal::Heap;
2629  friend class v8::String;
2630  };
2631 
2638  class V8_EXPORT ExternalStringResource
2639  : public ExternalStringResourceBase {
2640  public:
2646 
2650  virtual const uint16_t* data() const = 0;
2651 
2655  virtual size_t length() const = 0;
2656 
2657  protected:
2659  };
2660 
2672  : public ExternalStringResourceBase {
2673  public:
2680  virtual const char* data() const = 0;
2682  virtual size_t length() const = 0;
2683  protected:
2685  };
2686 
2692  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2693  Encoding* encoding_out) const;
2694 
2699  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2700 
2705  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2706 
2707  V8_INLINE static String* Cast(v8::Value* obj);
2708 
2709  // TODO(dcarney): remove with deprecation of New functions.
2710  enum NewStringType {
2711  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2712  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2713  };
2714 
2716  static V8_DEPRECATE_SOON(
2717  "Use maybe version",
2718  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2719  NewStringType type = kNormalString,
2720  int length = -1));
2721 
2724  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2725  Isolate* isolate, const char* data, v8::NewStringType type,
2726  int length = -1);
2727 
2729  static V8_DEPRECATED(
2730  "Use maybe version",
2731  Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2732  NewStringType type = kNormalString,
2733  int length = -1));
2734 
2737  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2738  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2739  int length = -1);
2740 
2742  static V8_DEPRECATE_SOON(
2743  "Use maybe version",
2744  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2745  NewStringType type = kNormalString,
2746  int length = -1));
2747 
2750  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2751  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2752  int length = -1);
2753 
2758  static Local<String> Concat(Local<String> left, Local<String> right);
2759 
2768  static V8_DEPRECATED("Use maybe version",
2769  Local<String> NewExternal(
2770  Isolate* isolate, ExternalStringResource* resource));
2771  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2772  Isolate* isolate, ExternalStringResource* resource);
2773 
2783  bool MakeExternal(ExternalStringResource* resource);
2784 
2793  static V8_DEPRECATE_SOON(
2794  "Use maybe version",
2795  Local<String> NewExternal(Isolate* isolate,
2796  ExternalOneByteStringResource* resource));
2797  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2798  Isolate* isolate, ExternalOneByteStringResource* resource);
2799 
2809  bool MakeExternal(ExternalOneByteStringResource* resource);
2810 
2814  bool CanMakeExternal();
2815 
2823  class V8_EXPORT Utf8Value {
2824  public:
2825  V8_DEPRECATE_SOON("Use Isolate version",
2826  explicit Utf8Value(Local<v8::Value> obj));
2827  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2828  ~Utf8Value();
2829  char* operator*() { return str_; }
2830  const char* operator*() const { return str_; }
2831  int length() const { return length_; }
2832 
2833  // Disallow copying and assigning.
2834  Utf8Value(const Utf8Value&) = delete;
2835  void operator=(const Utf8Value&) = delete;
2836 
2837  private:
2838  char* str_;
2839  int length_;
2840  };
2841 
2848  class V8_EXPORT Value {
2849  public:
2850  V8_DEPRECATE_SOON("Use Isolate version",
2851  explicit Value(Local<v8::Value> obj));
2852  Value(Isolate* isolate, Local<v8::Value> obj);
2853  ~Value();
2854  uint16_t* operator*() { return str_; }
2855  const uint16_t* operator*() const { return str_; }
2856  int length() const { return length_; }
2857 
2858  // Disallow copying and assigning.
2859  Value(const Value&) = delete;
2860  void operator=(const Value&) = delete;
2861 
2862  private:
2863  uint16_t* str_;
2864  int length_;
2865  };
2866 
2867  private:
2868  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2869  Encoding encoding) const;
2870  void VerifyExternalStringResource(ExternalStringResource* val) const;
2871  static void CheckCast(v8::Value* obj);
2872 };
2873 
2874 
2878 class V8_EXPORT Symbol : public Name {
2879  public:
2883  Local<Value> Name() const;
2884 
2888  static Local<Symbol> New(Isolate* isolate,
2889  Local<String> name = Local<String>());
2890 
2898  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2899 
2904  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2905 
2906  // Well-known symbols
2907  static Local<Symbol> GetHasInstance(Isolate* isolate);
2908  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
2909  static Local<Symbol> GetIterator(Isolate* isolate);
2910  static Local<Symbol> GetMatch(Isolate* isolate);
2911  static Local<Symbol> GetReplace(Isolate* isolate);
2912  static Local<Symbol> GetSearch(Isolate* isolate);
2913  static Local<Symbol> GetSplit(Isolate* isolate);
2914  static Local<Symbol> GetToPrimitive(Isolate* isolate);
2915  static Local<Symbol> GetToStringTag(Isolate* isolate);
2916  static Local<Symbol> GetUnscopables(Isolate* isolate);
2917 
2918  V8_INLINE static Symbol* Cast(Value* obj);
2919 
2920  private:
2921  Symbol();
2922  static void CheckCast(Value* obj);
2923 };
2924 
2925 
2931 class V8_EXPORT Private : public Data {
2932  public:
2936  Local<Value> Name() const;
2937 
2941  static Local<Private> New(Isolate* isolate,
2942  Local<String> name = Local<String>());
2943 
2953  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
2954 
2955  private:
2956  Private();
2957 };
2958 
2959 
2963 class V8_EXPORT Number : public Primitive {
2964  public:
2965  double Value() const;
2966  static Local<Number> New(Isolate* isolate, double value);
2967  V8_INLINE static Number* Cast(v8::Value* obj);
2968  private:
2969  Number();
2970  static void CheckCast(v8::Value* obj);
2971 };
2972 
2973 
2977 class V8_EXPORT Integer : public Number {
2978  public:
2979  static Local<Integer> New(Isolate* isolate, int32_t value);
2980  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2981  int64_t Value() const;
2982  V8_INLINE static Integer* Cast(v8::Value* obj);
2983  private:
2984  Integer();
2985  static void CheckCast(v8::Value* obj);
2986 };
2987 
2988 
2992 class V8_EXPORT Int32 : public Integer {
2993  public:
2994  int32_t Value() const;
2995  V8_INLINE static Int32* Cast(v8::Value* obj);
2996 
2997  private:
2998  Int32();
2999  static void CheckCast(v8::Value* obj);
3000 };
3001 
3002 
3006 class V8_EXPORT Uint32 : public Integer {
3007  public:
3008  uint32_t Value() const;
3009  V8_INLINE static Uint32* Cast(v8::Value* obj);
3010 
3011  private:
3012  Uint32();
3013  static void CheckCast(v8::Value* obj);
3014 };
3015 
3021  None = 0,
3023  ReadOnly = 1 << 0,
3025  DontEnum = 1 << 1,
3027  DontDelete = 1 << 2
3028 };
3029 
3035 typedef void (*AccessorGetterCallback)(
3036  Local<String> property,
3037  const PropertyCallbackInfo<Value>& info);
3038 typedef void (*AccessorNameGetterCallback)(
3039  Local<Name> property,
3040  const PropertyCallbackInfo<Value>& info);
3041 
3042 
3043 typedef void (*AccessorSetterCallback)(
3044  Local<String> property,
3045  Local<Value> value,
3046  const PropertyCallbackInfo<void>& info);
3047 typedef void (*AccessorNameSetterCallback)(
3048  Local<Name> property,
3049  Local<Value> value,
3050  const PropertyCallbackInfo<void>& info);
3051 
3052 
3063  DEFAULT = 0,
3064  ALL_CAN_READ = 1,
3065  ALL_CAN_WRITE = 1 << 1,
3066  PROHIBITS_OVERWRITING = 1 << 2
3067 };
3068 
3073  ALL_PROPERTIES = 0,
3074  ONLY_WRITABLE = 1,
3075  ONLY_ENUMERABLE = 2,
3076  ONLY_CONFIGURABLE = 4,
3077  SKIP_STRINGS = 8,
3078  SKIP_SYMBOLS = 16
3079 };
3080 
3088 enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes };
3089 
3094 enum class IndexFilter { kIncludeIndices, kSkipIndices };
3095 
3099 enum class IntegrityLevel { kFrozen, kSealed };
3100 
3104 class V8_EXPORT Object : public Value {
3105  public:
3106  V8_DEPRECATE_SOON("Use maybe version",
3107  bool Set(Local<Value> key, Local<Value> value));
3108  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
3109  Local<Value> key, Local<Value> value);
3110 
3111  V8_DEPRECATE_SOON("Use maybe version",
3112  bool Set(uint32_t index, Local<Value> value));
3113  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3114  Local<Value> value);
3115 
3116  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3117  //
3118  // Defines a configurable, writable, enumerable property with the given value
3119  // on the object unless the property already exists and is not configurable
3120  // or the object is not extensible.
3121  //
3122  // Returns true on success.
3123  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3124  Local<Name> key,
3125  Local<Value> value);
3126  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3127  uint32_t index,
3128  Local<Value> value);
3129 
3130  // Implements DefineOwnProperty.
3131  //
3132  // In general, CreateDataProperty will be faster, however, does not allow
3133  // for specifying attributes.
3134  //
3135  // Returns true on success.
3136  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3137  Local<Context> context, Local<Name> key, Local<Value> value,
3138  PropertyAttribute attributes = None);
3139 
3140  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3141  //
3142  // The defineProperty function is used to add an own property or
3143  // update the attributes of an existing own property of an object.
3144  //
3145  // Both data and accessor descriptors can be used.
3146  //
3147  // In general, CreateDataProperty is faster, however, does not allow
3148  // for specifying attributes or an accessor descriptor.
3149  //
3150  // The PropertyDescriptor can change when redefining a property.
3151  //
3152  // Returns true on success.
3153  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3154  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3155 
3156  // Sets an own property on this object bypassing interceptors and
3157  // overriding accessors or read-only properties.
3158  //
3159  // Note that if the object has an interceptor the property will be set
3160  // locally, but since the interceptor takes precedence the local property
3161  // will only be returned if the interceptor doesn't return a value.
3162  //
3163  // Note also that this only works for named properties.
3164  V8_DEPRECATED("Use CreateDataProperty / DefineOwnProperty",
3165  Maybe<bool> ForceSet(Local<Context> context, Local<Value> key,
3166  Local<Value> value,
3167  PropertyAttribute attribs = None));
3168 
3169  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3170  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3171  Local<Value> key);
3172 
3173  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3174  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3175  uint32_t index);
3176 
3182  V8_DEPRECATED("Use maybe version",
3183  PropertyAttribute GetPropertyAttributes(Local<Value> key));
3184  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3185  Local<Context> context, Local<Value> key);
3186 
3190  V8_DEPRECATED("Use maybe version",
3191  Local<Value> GetOwnPropertyDescriptor(Local<Name> key));
3192  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3193  Local<Context> context, Local<Name> key);
3194 
3195  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
3211  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3212  Local<Value> key);
3213 
3214  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3215  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3216  Local<Value> key);
3217 
3218  V8_DEPRECATED("Use maybe version", bool Has(uint32_t index));
3219  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3220  uint32_t index);
3221 
3222  V8_DEPRECATED("Use maybe version", bool Delete(uint32_t index));
3223  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3224  uint32_t index);
3225 
3226  V8_DEPRECATED("Use maybe version",
3227  bool SetAccessor(Local<String> name,
3228  AccessorGetterCallback getter,
3229  AccessorSetterCallback setter = 0,
3230  Local<Value> data = Local<Value>(),
3231  AccessControl settings = DEFAULT,
3232  PropertyAttribute attribute = None));
3233  V8_DEPRECATED("Use maybe version",
3234  bool SetAccessor(Local<Name> name,
3235  AccessorNameGetterCallback getter,
3236  AccessorNameSetterCallback setter = 0,
3237  Local<Value> data = Local<Value>(),
3238  AccessControl settings = DEFAULT,
3239  PropertyAttribute attribute = None));
3240  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(Local<Context> context,
3241  Local<Name> name,
3242  AccessorNameGetterCallback getter,
3243  AccessorNameSetterCallback setter = 0,
3245  AccessControl settings = DEFAULT,
3246  PropertyAttribute attribute = None);
3247 
3248  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3249  Local<Function> setter = Local<Function>(),
3250  PropertyAttribute attribute = None,
3251  AccessControl settings = DEFAULT);
3252 
3257  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3258  Local<Context> context, Local<Name> name,
3259  AccessorNameGetterCallback getter,
3260  AccessorNameSetterCallback setter = nullptr,
3261  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None);
3262 
3269  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3270  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3271  Local<Value> value);
3272  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3273  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3274 
3281  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3282  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3283  Local<Context> context);
3284  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3285  Local<Context> context, KeyCollectionMode mode,
3286  PropertyFilter property_filter, IndexFilter index_filter);
3287 
3293  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3294  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3295  Local<Context> context);
3296 
3303  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3304  Local<Context> context, PropertyFilter filter);
3305 
3311  Local<Value> GetPrototype();
3312 
3318  V8_DEPRECATED("Use maybe version", bool SetPrototype(Local<Value> prototype));
3319  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3320  Local<Value> prototype);
3321 
3326  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3327 
3333  V8_DEPRECATED("Use maybe version", Local<String> ObjectProtoToString());
3334  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3335  Local<Context> context);
3336 
3340  Local<String> GetConstructorName();
3341 
3345  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3346 
3348  int InternalFieldCount();
3349 
3351  V8_INLINE static int InternalFieldCount(
3352  const PersistentBase<Object>& object) {
3353  return object.val_->InternalFieldCount();
3354  }
3355 
3357  V8_INLINE Local<Value> GetInternalField(int index);
3358 
3360  void SetInternalField(int index, Local<Value> value);
3361 
3367  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3368 
3370  V8_INLINE static void* GetAlignedPointerFromInternalField(
3371  const PersistentBase<Object>& object, int index) {
3372  return object.val_->GetAlignedPointerFromInternalField(index);
3373  }
3374 
3380  void SetAlignedPointerInInternalField(int index, void* value);
3381  void SetAlignedPointerInInternalFields(int argc, int indices[],
3382  void* values[]);
3383 
3384  // Testers for local properties.
3385  V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
3386 
3392  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3393  Local<Name> key);
3394  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3395  uint32_t index);
3396  V8_DEPRECATE_SOON("Use maybe version",
3397  bool HasRealNamedProperty(Local<String> key));
3411  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3412  Local<Name> key);
3413  V8_DEPRECATE_SOON("Use maybe version",
3414  bool HasRealIndexedProperty(uint32_t index));
3415  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3416  Local<Context> context, uint32_t index);
3417  V8_DEPRECATE_SOON("Use maybe version",
3418  bool HasRealNamedCallbackProperty(Local<String> key));
3419  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3420  Local<Context> context, Local<Name> key);
3421 
3426  V8_DEPRECATED(
3427  "Use maybe version",
3428  Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
3429  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3430  Local<Context> context, Local<Name> key);
3431 
3437  V8_DEPRECATED(
3438  "Use maybe version",
3439  Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
3440  Local<String> key));
3441  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
3442  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3443  Local<Name> key);
3444 
3450  V8_DEPRECATED("Use maybe version",
3451  Local<Value> GetRealNamedProperty(Local<String> key));
3452  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3453  Local<Context> context, Local<Name> key);
3454 
3460  V8_DEPRECATED("Use maybe version",
3461  Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3462  Local<String> key));
3463  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3464  Local<Context> context, Local<Name> key);
3465 
3467  bool HasNamedLookupInterceptor();
3468 
3470  bool HasIndexedLookupInterceptor();
3471 
3479  int GetIdentityHash();
3480 
3485  // TODO(dcarney): take an isolate and optionally bail out?
3486  Local<Object> Clone();
3487 
3491  Local<Context> CreationContext();
3492 
3495  const PersistentBase<Object>& object) {
3496  return object.val_->CreationContext();
3497  }
3498 
3504  bool IsCallable();
3505 
3509  bool IsConstructor();
3510 
3515  V8_DEPRECATED("Use maybe version",
3516  Local<Value> CallAsFunction(Local<Value> recv, int argc,
3517  Local<Value> argv[]));
3518  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
3519  Local<Value> recv,
3520  int argc,
3521  Local<Value> argv[]);
3522 
3528  V8_DEPRECATED("Use maybe version",
3529  Local<Value> CallAsConstructor(int argc, Local<Value> argv[]));
3530  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3531  Local<Context> context, int argc, Local<Value> argv[]);
3532 
3536  V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
3537 
3538  static Local<Object> New(Isolate* isolate);
3539 
3540  V8_INLINE static Object* Cast(Value* obj);
3541 
3542  private:
3543  Object();
3544  static void CheckCast(Value* obj);
3545  Local<Value> SlowGetInternalField(int index);
3546  void* SlowGetAlignedPointerFromInternalField(int index);
3547 };
3548 
3549 
3553 class V8_EXPORT Array : public Object {
3554  public:
3555  uint32_t Length() const;
3556 
3561  V8_DEPRECATED("Cloning is not supported.",
3562  Local<Object> CloneElementAt(uint32_t index));
3563  V8_DEPRECATED("Cloning is not supported.",
3564  MaybeLocal<Object> CloneElementAt(Local<Context> context,
3565  uint32_t index));
3566 
3571  static Local<Array> New(Isolate* isolate, int length = 0);
3572 
3573  V8_INLINE static Array* Cast(Value* obj);
3574  private:
3575  Array();
3576  static void CheckCast(Value* obj);
3577 };
3578 
3579 
3583 class V8_EXPORT Map : public Object {
3584  public:
3585  size_t Size() const;
3586  void Clear();
3587  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3588  Local<Value> key);
3589  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
3590  Local<Value> key,
3591  Local<Value> value);
3592  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3593  Local<Value> key);
3594  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3595  Local<Value> key);
3596 
3601  Local<Array> AsArray() const;
3602 
3606  static Local<Map> New(Isolate* isolate);
3607 
3608  V8_INLINE static Map* Cast(Value* obj);
3609 
3610  private:
3611  Map();
3612  static void CheckCast(Value* obj);
3613 };
3614 
3615 
3619 class V8_EXPORT Set : public Object {
3620  public:
3621  size_t Size() const;
3622  void Clear();
3623  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3624  Local<Value> key);
3625  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3626  Local<Value> key);
3627  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3628  Local<Value> key);
3629 
3633  Local<Array> AsArray() const;
3634 
3638  static Local<Set> New(Isolate* isolate);
3639 
3640  V8_INLINE static Set* Cast(Value* obj);
3641 
3642  private:
3643  Set();
3644  static void CheckCast(Value* obj);
3645 };
3646 
3647 
3648 template<typename T>
3649 class ReturnValue {
3650  public:
3651  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3652  : value_(that.value_) {
3653  TYPE_CHECK(T, S);
3654  }
3655  // Local setters
3656  template <typename S>
3657  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3658  void Set(const Persistent<S>& handle));
3659  template <typename S>
3660  V8_INLINE void Set(const Global<S>& handle);
3661  template <typename S>
3662  V8_INLINE void Set(const Local<S> handle);
3663  // Fast primitive setters
3664  V8_INLINE void Set(bool value);
3665  V8_INLINE void Set(double i);
3666  V8_INLINE void Set(int32_t i);
3667  V8_INLINE void Set(uint32_t i);
3668  // Fast JS primitive setters
3669  V8_INLINE void SetNull();
3670  V8_INLINE void SetUndefined();
3671  V8_INLINE void SetEmptyString();
3672  // Convenience getter for Isolate
3673  V8_INLINE Isolate* GetIsolate() const;
3674 
3675  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3676  template <typename S>
3677  V8_INLINE void Set(S* whatever);
3678 
3679  // Getter. Creates a new Local<> so it comes with a certain performance
3680  // hit. If the ReturnValue was not yet set, this will return the undefined
3681  // value.
3682  V8_INLINE Local<Value> Get() const;
3683 
3684  private:
3685  template<class F> friend class ReturnValue;
3686  template<class F> friend class FunctionCallbackInfo;
3687  template<class F> friend class PropertyCallbackInfo;
3688  template <class F, class G, class H>
3689  friend class PersistentValueMapBase;
3690  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3691  V8_INLINE internal::Object* GetDefaultValue();
3692  V8_INLINE explicit ReturnValue(internal::Object** slot);
3693  internal::Object** value_;
3694 };
3695 
3696 
3703 template<typename T>
3704 class FunctionCallbackInfo {
3705  public:
3707  V8_INLINE int Length() const;
3709  V8_INLINE Local<Value> operator[](int i) const;
3710  V8_INLINE V8_DEPRECATED("Use Data() to explicitly pass Callee instead",
3711  Local<Function> Callee() const);
3713  V8_INLINE Local<Object> This() const;
3724  V8_INLINE Local<Object> Holder() const;
3726  V8_INLINE Local<Value> NewTarget() const;
3728  V8_INLINE bool IsConstructCall() const;
3730  V8_INLINE Local<Value> Data() const;
3732  V8_INLINE Isolate* GetIsolate() const;
3734  V8_INLINE ReturnValue<T> GetReturnValue() const;
3735  // This shouldn't be public, but the arm compiler needs it.
3736  static const int kArgsLength = 8;
3737 
3738  protected:
3739  friend class internal::FunctionCallbackArguments;
3740  friend class internal::CustomArguments<FunctionCallbackInfo>;
3741  friend class debug::ConsoleCallArguments;
3742  static const int kHolderIndex = 0;
3743  static const int kIsolateIndex = 1;
3744  static const int kReturnValueDefaultValueIndex = 2;
3745  static const int kReturnValueIndex = 3;
3746  static const int kDataIndex = 4;
3747  static const int kCalleeIndex = 5;
3748  static const int kContextSaveIndex = 6;
3749  static const int kNewTargetIndex = 7;
3750 
3751  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3752  internal::Object** values, int length);
3753  internal::Object** implicit_args_;
3754  internal::Object** values_;
3755  int length_;
3756 };
3757 
3758 
3763 template<typename T>
3764 class PropertyCallbackInfo {
3765  public:
3769  V8_INLINE Isolate* GetIsolate() const;
3770 
3776  V8_INLINE Local<Value> Data() const;
3777 
3819  V8_INLINE Local<Object> This() const;
3820 
3830  V8_INLINE Local<Object> Holder() const;
3831 
3840  V8_INLINE ReturnValue<T> GetReturnValue() const;
3841 
3849  V8_INLINE bool ShouldThrowOnError() const;
3850 
3851  // This shouldn't be public, but the arm compiler needs it.
3852  static const int kArgsLength = 7;
3853 
3854  protected:
3855  friend class MacroAssembler;
3856  friend class internal::PropertyCallbackArguments;
3857  friend class internal::CustomArguments<PropertyCallbackInfo>;
3858  static const int kShouldThrowOnErrorIndex = 0;
3859  static const int kHolderIndex = 1;
3860  static const int kIsolateIndex = 2;
3861  static const int kReturnValueDefaultValueIndex = 3;
3862  static const int kReturnValueIndex = 4;
3863  static const int kDataIndex = 5;
3864  static const int kThisIndex = 6;
3865 
3866  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
3867  internal::Object** args_;
3868 };
3869 
3870 
3871 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3872 
3873 enum class ConstructorBehavior { kThrow, kAllow };
3874 
3878 class V8_EXPORT Function : public Object {
3879  public:
3884  static MaybeLocal<Function> New(
3885  Local<Context> context, FunctionCallback callback,
3886  Local<Value> data = Local<Value>(), int length = 0,
3887  ConstructorBehavior behavior = ConstructorBehavior::kAllow);
3888  static V8_DEPRECATE_SOON(
3889  "Use maybe version",
3890  Local<Function> New(Isolate* isolate, FunctionCallback callback,
3891  Local<Value> data = Local<Value>(), int length = 0));
3892 
3893  V8_DEPRECATED("Use maybe version",
3894  Local<Object> NewInstance(int argc, Local<Value> argv[]) const);
3895  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
3896  Local<Context> context, int argc, Local<Value> argv[]) const;
3897 
3898  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
3899  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
3900  Local<Context> context) const {
3901  return NewInstance(context, 0, nullptr);
3902  }
3903 
3904  V8_DEPRECATE_SOON("Use maybe version",
3905  Local<Value> Call(Local<Value> recv, int argc,
3906  Local<Value> argv[]));
3907  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
3908  Local<Value> recv, int argc,
3909  Local<Value> argv[]);
3910 
3911  void SetName(Local<String> name);
3912  Local<Value> GetName() const;
3913 
3920  Local<Value> GetInferredName() const;
3921 
3926  Local<Value> GetDebugName() const;
3927 
3932  Local<Value> GetDisplayName() const;
3933 
3938  int GetScriptLineNumber() const;
3943  int GetScriptColumnNumber() const;
3944 
3948  V8_DEPRECATED("this should no longer be used.", bool IsBuiltin() const);
3949 
3953  int ScriptId() const;
3954 
3959  Local<Value> GetBoundFunction() const;
3960 
3961  ScriptOrigin GetScriptOrigin() const;
3962  V8_INLINE static Function* Cast(Value* obj);
3963  static const int kLineOffsetNotFound;
3964 
3965  private:
3966  Function();
3967  static void CheckCast(Value* obj);
3968 };
3969 
3970 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
3971 // The number of required internal fields can be defined by embedder.
3972 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
3973 #endif
3974 
3978 class V8_EXPORT Promise : public Object {
3979  public:
3984  enum PromiseState { kPending, kFulfilled, kRejected };
3985 
3986  class V8_EXPORT Resolver : public Object {
3987  public:
3991  static V8_DEPRECATE_SOON("Use maybe version",
3992  Local<Resolver> New(Isolate* isolate));
3993  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
3994  Local<Context> context);
3995 
3999  Local<Promise> GetPromise();
4000 
4005  V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
4006  V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context,
4007  Local<Value> value);
4008 
4009  V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
4010  V8_WARN_UNUSED_RESULT Maybe<bool> Reject(Local<Context> context,
4011  Local<Value> value);
4012 
4013  V8_INLINE static Resolver* Cast(Value* obj);
4014 
4015  private:
4016  Resolver();
4017  static void CheckCast(Value* obj);
4018  };
4019 
4026  V8_DEPRECATED("Use maybe version",
4027  Local<Promise> Catch(Local<Function> handler));
4028  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
4029  Local<Function> handler);
4030 
4031  V8_DEPRECATED("Use maybe version",
4032  Local<Promise> Then(Local<Function> handler));
4033  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
4034  Local<Function> handler);
4035 
4040  bool HasHandler();
4041 
4046  Local<Value> Result();
4047 
4051  PromiseState State();
4052 
4053  V8_INLINE static Promise* Cast(Value* obj);
4054 
4055  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4056 
4057  private:
4058  Promise();
4059  static void CheckCast(Value* obj);
4060 };
4061 
4090 class V8_EXPORT PropertyDescriptor {
4091  public:
4092  // GenericDescriptor
4094 
4095  // DataDescriptor
4097 
4098  // DataDescriptor with writable property
4099  PropertyDescriptor(Local<Value> value, bool writable);
4100 
4101  // AccessorDescriptor
4103 
4104  ~PropertyDescriptor();
4105 
4106  Local<Value> value() const;
4107  bool has_value() const;
4108 
4109  Local<Value> get() const;
4110  bool has_get() const;
4111  Local<Value> set() const;
4112  bool has_set() const;
4113 
4114  void set_enumerable(bool enumerable);
4115  bool enumerable() const;
4116  bool has_enumerable() const;
4117 
4118  void set_configurable(bool configurable);
4119  bool configurable() const;
4120  bool has_configurable() const;
4121 
4122  bool writable() const;
4123  bool has_writable() const;
4124 
4125  struct PrivateData;
4126  PrivateData* get_private() const { return private_; }
4127 
4128  PropertyDescriptor(const PropertyDescriptor&) = delete;
4129  void operator=(const PropertyDescriptor&) = delete;
4130 
4131  private:
4132  PrivateData* private_;
4133 };
4134 
4139 class V8_EXPORT Proxy : public Object {
4140  public:
4141  Local<Object> GetTarget();
4142  Local<Value> GetHandler();
4143  bool IsRevoked();
4144  void Revoke();
4145 
4149  static MaybeLocal<Proxy> New(Local<Context> context,
4150  Local<Object> local_target,
4151  Local<Object> local_handler);
4152 
4153  V8_INLINE static Proxy* Cast(Value* obj);
4154 
4155  private:
4156  Proxy();
4157  static void CheckCast(Value* obj);
4158 };
4159 
4160 // TODO(mtrofin): rename WasmCompiledModule to WasmModuleObject, for
4161 // consistency with internal APIs.
4162 class V8_EXPORT WasmCompiledModule : public Object {
4163  public:
4164  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
4165  // A buffer that is owned by the caller.
4166  typedef std::pair<const uint8_t*, size_t> CallerOwnedBuffer;
4167 
4168  // An opaque, native heap object for transferring wasm modules. It
4169  // supports move semantics, and does not support copy semantics.
4170  class TransferrableModule final {
4171  public:
4172  TransferrableModule(TransferrableModule&& src) = default;
4173  TransferrableModule(const TransferrableModule& src) = delete;
4174 
4175  TransferrableModule& operator=(TransferrableModule&& src) = default;
4176  TransferrableModule& operator=(const TransferrableModule& src) = delete;
4177 
4178  private:
4179  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
4180  friend class WasmCompiledModule;
4181  TransferrableModule(OwnedBuffer&& code, OwnedBuffer&& bytes)
4182  : compiled_code(std::move(code)), wire_bytes(std::move(bytes)) {}
4183 
4184  OwnedBuffer compiled_code = {nullptr, 0};
4185  OwnedBuffer wire_bytes = {nullptr, 0};
4186  };
4187 
4188  // Get an in-memory, non-persistable, and context-independent (meaning,
4189  // suitable for transfer to another Isolate and Context) representation
4190  // of this wasm compiled module.
4191  TransferrableModule GetTransferrableModule();
4192 
4193  // Efficiently re-create a WasmCompiledModule, without recompiling, from
4194  // a TransferrableModule.
4195  static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
4196  Isolate* isolate, const TransferrableModule&);
4197 
4198  // Get the wasm-encoded bytes that were used to compile this module.
4199  Local<String> GetWasmWireBytes();
4200 
4201  // Serialize the compiled module. The serialized data does not include the
4202  // uncompiled bytes.
4203  SerializedModule Serialize();
4204 
4205  // If possible, deserialize the module, otherwise compile it from the provided
4206  // uncompiled bytes.
4207  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
4208  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
4209  const CallerOwnedBuffer& wire_bytes);
4210  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
4211 
4212  private:
4213  // TODO(ahaas): please remove the friend once streamed compilation is
4214  // implemented
4215  friend class WasmModuleObjectBuilder;
4216 
4217  static MaybeLocal<WasmCompiledModule> Deserialize(
4218  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
4219  const CallerOwnedBuffer& wire_bytes);
4220  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
4221  const uint8_t* start,
4222  size_t length);
4223  static CallerOwnedBuffer AsCallerOwned(
4224  const TransferrableModule::OwnedBuffer& buff) {
4225  return {buff.first.get(), buff.second};
4226  }
4227 
4229  static void CheckCast(Value* obj);
4230 };
4231 
4232 // TODO(mtrofin): when streaming compilation is done, we can rename this
4233 // to simply WasmModuleObjectBuilder
4234 class V8_EXPORT WasmModuleObjectBuilderStreaming final {
4235  public:
4237  // The buffer passed into OnBytesReceived is owned by the caller.
4238  void OnBytesReceived(const uint8_t*, size_t size);
4239  void Finish();
4240  void Abort(Local<Value> exception);
4241  Local<Promise> GetPromise();
4242 
4244 
4245  private:
4246  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer;
4247 
4249  delete;
4251  default;
4253  const WasmModuleObjectBuilderStreaming&) = delete;
4255  WasmModuleObjectBuilderStreaming&&) = default;
4256  Isolate* isolate_ = nullptr;
4257 
4258 #if V8_CC_MSVC
4259  // We don't need the static Copy API, so the default
4260  // NonCopyablePersistentTraits would be sufficient, however,
4261  // MSVC eagerly instantiates the Copy.
4262  // We ensure we don't use Copy, however, by compiling with the
4263  // defaults everywhere else.
4265 #else
4266  Persistent<Promise> promise_;
4267 #endif
4268  std::vector<Buffer> received_buffers_;
4269  size_t total_size_ = 0;
4270 };
4271 
4272 class V8_EXPORT WasmModuleObjectBuilder final {
4273  public:
4274  WasmModuleObjectBuilder(Isolate* isolate) : isolate_(isolate) {}
4275  // The buffer passed into OnBytesReceived is owned by the caller.
4276  void OnBytesReceived(const uint8_t*, size_t size);
4278 
4279  private:
4280  Isolate* isolate_ = nullptr;
4281  // TODO(ahaas): We probably need none of this below here once streamed
4282  // compilation is implemented.
4283  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer;
4284 
4285  // Disable copy semantics *in this implementation*. We can choose to
4286  // relax this, albeit it's not clear why.
4289  WasmModuleObjectBuilder& operator=(const WasmModuleObjectBuilder&) = delete;
4290  WasmModuleObjectBuilder& operator=(WasmModuleObjectBuilder&&) = default;
4291 
4292  std::vector<Buffer> received_buffers_;
4293  size_t total_size_ = 0;
4294 };
4295 
4296 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4297 // The number of required internal fields can be defined by embedder.
4298 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4299 #endif
4300 
4301 
4302 enum class ArrayBufferCreationMode { kInternalized, kExternalized };
4303 
4304 
4308 class V8_EXPORT ArrayBuffer : public Object {
4309  public:
4325  class V8_EXPORT Allocator { // NOLINT
4326  public:
4327  virtual ~Allocator() {}
4328 
4333  virtual void* Allocate(size_t length) = 0;
4334 
4339  virtual void* AllocateUninitialized(size_t length) = 0;
4340 
4345  // TODO(eholk): make this pure virtual once blink implements this.
4346  virtual void* Reserve(size_t length);
4347 
4352  virtual void Free(void* data, size_t length) = 0;
4353 
4354  enum class AllocationMode { kNormal, kReservation };
4355 
4361  // TODO(eholk): make this pure virtual once blink implements this.
4362  virtual void Free(void* data, size_t length, AllocationMode mode);
4363 
4364  enum class Protection { kNoAccess, kReadWrite };
4365 
4373  // TODO(eholk): make this pure virtual once blink implements this.
4374  virtual void SetProtection(void* data, size_t length,
4375  Protection protection);
4376 
4383  static Allocator* NewDefaultAllocator();
4384  };
4385 
4394  class V8_EXPORT Contents { // NOLINT
4395  public:
4396  Contents()
4397  : data_(nullptr),
4398  byte_length_(0),
4399  allocation_base_(nullptr),
4400  allocation_length_(0),
4401  allocation_mode_(Allocator::AllocationMode::kNormal) {}
4402 
4403  void* AllocationBase() const { return allocation_base_; }
4404  size_t AllocationLength() const { return allocation_length_; }
4405  Allocator::AllocationMode AllocationMode() const {
4406  return allocation_mode_;
4407  }
4408 
4409  void* Data() const { return data_; }
4410  size_t ByteLength() const { return byte_length_; }
4411 
4412  private:
4413  void* data_;
4414  size_t byte_length_;
4415  void* allocation_base_;
4416  size_t allocation_length_;
4417  Allocator::AllocationMode allocation_mode_;
4418 
4419  friend class ArrayBuffer;
4420  };
4421 
4422 
4426  size_t ByteLength() const;
4427 
4434  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4435 
4445  static Local<ArrayBuffer> New(
4446  Isolate* isolate, void* data, size_t byte_length,
4447  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
4448 
4453  bool IsExternal() const;
4454 
4458  bool IsNeuterable() const;
4459 
4466  void Neuter();
4467 
4477  Contents Externalize();
4478 
4489  Contents GetContents();
4490 
4491  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4492 
4493  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4494  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4495 
4496  private:
4497  ArrayBuffer();
4498  static void CheckCast(Value* obj);
4499 };
4500 
4501 
4502 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4503 // The number of required internal fields can be defined by embedder.
4504 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4505 #endif
4506 
4507 
4512 class V8_EXPORT ArrayBufferView : public Object {
4513  public:
4517  Local<ArrayBuffer> Buffer();
4521  size_t ByteOffset();
4525  size_t ByteLength();
4526 
4536  size_t CopyContents(void* dest, size_t byte_length);
4537 
4542  bool HasBuffer() const;
4543 
4544  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4545 
4546  static const int kInternalFieldCount =
4547  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4548  static const int kEmbedderFieldCount =
4549  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
4550 
4551  private:
4552  ArrayBufferView();
4553  static void CheckCast(Value* obj);
4554 };
4555 
4556 
4561 class V8_EXPORT TypedArray : public ArrayBufferView {
4562  public:
4563  /*
4564  * The largest typed array size that can be constructed using New.
4565  */
4566  static constexpr size_t kMaxLength =
4567  sizeof(void*) == 4 ? (1u << 30) - 1 : (1u << 31) - 1;
4568 
4573  size_t Length();
4574 
4575  V8_INLINE static TypedArray* Cast(Value* obj);
4576 
4577  private:
4578  TypedArray();
4579  static void CheckCast(Value* obj);
4580 };
4581 
4582 
4586 class V8_EXPORT Uint8Array : public TypedArray {
4587  public:
4588  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4589  size_t byte_offset, size_t length);
4590  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4591  size_t byte_offset, size_t length);
4592  V8_INLINE static Uint8Array* Cast(Value* obj);
4593 
4594  private:
4595  Uint8Array();
4596  static void CheckCast(Value* obj);
4597 };
4598 
4599 
4603 class V8_EXPORT Uint8ClampedArray : public TypedArray {
4604  public:
4605  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4606  size_t byte_offset, size_t length);
4607  static Local<Uint8ClampedArray> New(
4608  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4609  size_t length);
4610  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4611 
4612  private:
4614  static void CheckCast(Value* obj);
4615 };
4616 
4620 class V8_EXPORT Int8Array : public TypedArray {
4621  public:
4622  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4623  size_t byte_offset, size_t length);
4624  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4625  size_t byte_offset, size_t length);
4626  V8_INLINE static Int8Array* Cast(Value* obj);
4627 
4628  private:
4629  Int8Array();
4630  static void CheckCast(Value* obj);
4631 };
4632 
4633 
4637 class V8_EXPORT Uint16Array : public TypedArray {
4638  public:
4639  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4640  size_t byte_offset, size_t length);
4641  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4642  size_t byte_offset, size_t length);
4643  V8_INLINE static Uint16Array* Cast(Value* obj);
4644 
4645  private:
4646  Uint16Array();
4647  static void CheckCast(Value* obj);
4648 };
4649 
4650 
4654 class V8_EXPORT Int16Array : public TypedArray {
4655  public:
4656  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4657  size_t byte_offset, size_t length);
4658  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4659  size_t byte_offset, size_t length);
4660  V8_INLINE static Int16Array* Cast(Value* obj);
4661 
4662  private:
4663  Int16Array();
4664  static void CheckCast(Value* obj);
4665 };
4666 
4667 
4671 class V8_EXPORT Uint32Array : public TypedArray {
4672  public:
4673  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4674  size_t byte_offset, size_t length);
4675  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4676  size_t byte_offset, size_t length);
4677  V8_INLINE static Uint32Array* Cast(Value* obj);
4678 
4679  private:
4680  Uint32Array();
4681  static void CheckCast(Value* obj);
4682 };
4683 
4684 
4688 class V8_EXPORT Int32Array : public TypedArray {
4689  public:
4690  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4691  size_t byte_offset, size_t length);
4692  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4693  size_t byte_offset, size_t length);
4694  V8_INLINE static Int32Array* Cast(Value* obj);
4695 
4696  private:
4697  Int32Array();
4698  static void CheckCast(Value* obj);
4699 };
4700 
4701 
4705 class V8_EXPORT Float32Array : public TypedArray {
4706  public:
4707  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4708  size_t byte_offset, size_t length);
4709  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4710  size_t byte_offset, size_t length);
4711  V8_INLINE static Float32Array* Cast(Value* obj);
4712 
4713  private:
4714  Float32Array();
4715  static void CheckCast(Value* obj);
4716 };
4717 
4718 
4722 class V8_EXPORT Float64Array : public TypedArray {
4723  public:
4724  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4725  size_t byte_offset, size_t length);
4726  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4727  size_t byte_offset, size_t length);
4728  V8_INLINE static Float64Array* Cast(Value* obj);
4729 
4730  private:
4731  Float64Array();
4732  static void CheckCast(Value* obj);
4733 };
4734 
4735 
4739 class V8_EXPORT DataView : public ArrayBufferView {
4740  public:
4741  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
4742  size_t byte_offset, size_t length);
4743  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
4744  size_t byte_offset, size_t length);
4745  V8_INLINE static DataView* Cast(Value* obj);
4746 
4747  private:
4748  DataView();
4749  static void CheckCast(Value* obj);
4750 };
4751 
4752 
4757 class V8_EXPORT SharedArrayBuffer : public Object {
4758  public:
4770  class V8_EXPORT Contents { // NOLINT
4771  public:
4772  Contents()
4773  : data_(nullptr),
4774  byte_length_(0),
4775  allocation_base_(nullptr),
4776  allocation_length_(0),
4777  allocation_mode_(ArrayBuffer::Allocator::AllocationMode::kNormal) {}
4778 
4779  void* AllocationBase() const { return allocation_base_; }
4780  size_t AllocationLength() const { return allocation_length_; }
4781  ArrayBuffer::Allocator::AllocationMode AllocationMode() const {
4782  return allocation_mode_;
4783  }
4784 
4785  void* Data() const { return data_; }
4786  size_t ByteLength() const { return byte_length_; }
4787 
4788  private:
4789  void* data_;
4790  size_t byte_length_;
4791  void* allocation_base_;
4792  size_t allocation_length_;
4793  ArrayBuffer::Allocator::AllocationMode allocation_mode_;
4794 
4795  friend class SharedArrayBuffer;
4796  };
4797 
4798 
4802  size_t ByteLength() const;
4803 
4810  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
4811 
4818  static Local<SharedArrayBuffer> New(
4819  Isolate* isolate, void* data, size_t byte_length,
4820  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
4821 
4826  bool IsExternal() const;
4827 
4840  Contents Externalize();
4841 
4854  Contents GetContents();
4855 
4856  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
4857 
4858  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4859 
4860  private:
4862  static void CheckCast(Value* obj);
4863 };
4864 
4865 
4869 class V8_EXPORT Date : public Object {
4870  public:
4871  static V8_DEPRECATE_SOON("Use maybe version.",
4872  Local<Value> New(Isolate* isolate, double time));
4873  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
4874  double time);
4875 
4880  double ValueOf() const;
4881 
4882  V8_INLINE static Date* Cast(Value* obj);
4883 
4896  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
4897 
4898  private:
4899  static void CheckCast(Value* obj);
4900 };
4901 
4902 
4906 class V8_EXPORT NumberObject : public Object {
4907  public:
4908  static Local<Value> New(Isolate* isolate, double value);
4909 
4910  double ValueOf() const;
4911 
4912  V8_INLINE static NumberObject* Cast(Value* obj);
4913 
4914  private:
4915  static void CheckCast(Value* obj);
4916 };
4917 
4918 
4922 class V8_EXPORT BooleanObject : public Object {
4923  public:
4924  static Local<Value> New(Isolate* isolate, bool value);
4925  V8_DEPRECATED("Pass an isolate", static Local<Value> New(bool value));
4926 
4927  bool ValueOf() const;
4928 
4929  V8_INLINE static BooleanObject* Cast(Value* obj);
4930 
4931  private:
4932  static void CheckCast(Value* obj);
4933 };
4934 
4935 
4939 class V8_EXPORT StringObject : public Object {
4940  public:
4941  static Local<Value> New(Local<String> value);
4942 
4943  Local<String> ValueOf() const;
4944 
4945  V8_INLINE static StringObject* Cast(Value* obj);
4946 
4947  private:
4948  static void CheckCast(Value* obj);
4949 };
4950 
4951 
4955 class V8_EXPORT SymbolObject : public Object {
4956  public:
4957  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
4958 
4959  Local<Symbol> ValueOf() const;
4960 
4961  V8_INLINE static SymbolObject* Cast(Value* obj);
4962 
4963  private:
4964  static void CheckCast(Value* obj);
4965 };
4966 
4967 
4971 class V8_EXPORT RegExp : public Object {
4972  public:
4977  enum Flags {
4978  kNone = 0,
4979  kGlobal = 1 << 0,
4980  kIgnoreCase = 1 << 1,
4981  kMultiline = 1 << 2,
4982  kSticky = 1 << 3,
4983  kUnicode = 1 << 4,
4984  kDotAll = 1 << 5,
4985  };
4986 
4997  static V8_DEPRECATE_SOON("Use maybe version",
4998  Local<RegExp> New(Local<String> pattern,
4999  Flags flags));
5000  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
5001  Local<String> pattern,
5002  Flags flags);
5003 
5008  Local<String> GetSource() const;
5009 
5013  Flags GetFlags() const;
5014 
5015  V8_INLINE static RegExp* Cast(Value* obj);
5016 
5017  private:
5018  static void CheckCast(Value* obj);
5019 };
5020 
5021 
5026 class V8_EXPORT External : public Value {
5027  public:
5028  static Local<External> New(Isolate* isolate, void* value);
5029  V8_INLINE static External* Cast(Value* obj);
5030  void* Value() const;
5031  private:
5032  static void CheckCast(v8::Value* obj);
5033 };
5034 
5035 #define V8_INTRINSICS_LIST(F) \
5036  F(ArrayProto_entries, array_entries_iterator) \
5037  F(ArrayProto_forEach, array_for_each_iterator) \
5038  F(ArrayProto_keys, array_keys_iterator) \
5039  F(ArrayProto_values, array_values_iterator) \
5040  F(ErrorPrototype, initial_error_prototype) \
5041  F(IteratorPrototype, initial_iterator_prototype)
5042 
5043 enum Intrinsic {
5044 #define V8_DECL_INTRINSIC(name, iname) k##name,
5045  V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
5046 #undef V8_DECL_INTRINSIC
5047 };
5048 
5049 
5050 // --- Templates ---
5051 
5052 
5056 class V8_EXPORT Template : public Data {
5057  public:
5063  void Set(Local<Name> name, Local<Data> value,
5064  PropertyAttribute attributes = None);
5065  void SetPrivate(Local<Private> name, Local<Data> value,
5066  PropertyAttribute attributes = None);
5067  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5068 
5069  void SetAccessorProperty(
5070  Local<Name> name,
5073  PropertyAttribute attribute = None,
5074  AccessControl settings = DEFAULT);
5075 
5103  void SetNativeDataProperty(
5105  AccessorSetterCallback setter = 0,
5106  // TODO(dcarney): gcc can't handle Local below
5107  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5109  AccessControl settings = DEFAULT);
5110  void SetNativeDataProperty(
5111  Local<Name> name, AccessorNameGetterCallback getter,
5112  AccessorNameSetterCallback setter = 0,
5113  // TODO(dcarney): gcc can't handle Local below
5114  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5116  AccessControl settings = DEFAULT);
5117 
5122  void SetLazyDataProperty(Local<Name> name, AccessorNameGetterCallback getter,
5123  Local<Value> data = Local<Value>(),
5124  PropertyAttribute attribute = None);
5125 
5130  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5131  PropertyAttribute attribute = None);
5132 
5133  private:
5134  Template();
5135 
5136  friend class ObjectTemplate;
5137  friend class FunctionTemplate;
5138 };
5139 
5140 
5146  Local<String> property,
5147  const PropertyCallbackInfo<Value>& info);
5148 
5149 
5155  Local<String> property,
5156  Local<Value> value,
5157  const PropertyCallbackInfo<Value>& info);
5158 
5159 
5166  Local<String> property,
5167  const PropertyCallbackInfo<Integer>& info);
5168 
5169 
5176  Local<String> property,
5177  const PropertyCallbackInfo<Boolean>& info);
5178 
5184  const PropertyCallbackInfo<Array>& info);
5185 
5186 
5187 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
5188 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
5189 
5227  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5228 
5251  Local<Name> property, Local<Value> value,
5252  const PropertyCallbackInfo<Value>& info);
5253 
5276  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5277 
5300  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5301 
5307  const PropertyCallbackInfo<Array>& info);
5308 
5330  Local<Name> property, const PropertyDescriptor& desc,
5331  const PropertyCallbackInfo<Value>& info);
5332 
5353  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5354 
5359  uint32_t index,
5360  const PropertyCallbackInfo<Value>& info);
5361 
5366  uint32_t index,
5367  Local<Value> value,
5368  const PropertyCallbackInfo<Value>& info);
5369 
5374  uint32_t index,
5375  const PropertyCallbackInfo<Integer>& info);
5376 
5381  uint32_t index,
5382  const PropertyCallbackInfo<Boolean>& info);
5383 
5388  const PropertyCallbackInfo<Array>& info);
5389 
5394  uint32_t index, const PropertyDescriptor& desc,
5395  const PropertyCallbackInfo<Value>& info);
5396 
5401  uint32_t index, const PropertyCallbackInfo<Value>& info);
5402 
5407  ACCESS_GET,
5408  ACCESS_SET,
5409  ACCESS_HAS,
5410  ACCESS_DELETE,
5411  ACCESS_KEYS
5412 };
5413 
5414 
5419 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5420  Local<Object> accessed_object,
5421  Local<Value> data);
5422 
5522 class V8_EXPORT FunctionTemplate : public Template {
5523  public:
5525  static Local<FunctionTemplate> New(
5526  Isolate* isolate, FunctionCallback callback = 0,
5527  Local<Value> data = Local<Value>(),
5528  Local<Signature> signature = Local<Signature>(), int length = 0,
5529  ConstructorBehavior behavior = ConstructorBehavior::kAllow);
5530 
5532  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5533  size_t index);
5534 
5538  static Local<FunctionTemplate> NewWithCache(
5539  Isolate* isolate, FunctionCallback callback,
5540  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5541  Local<Signature> signature = Local<Signature>(), int length = 0);
5542 
5544  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5545  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
5546  Local<Context> context);
5547 
5555  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5556 
5562  void SetCallHandler(FunctionCallback callback,
5563  Local<Value> data = Local<Value>());
5564 
5566  void SetLength(int length);
5567 
5569  Local<ObjectTemplate> InstanceTemplate();
5570 
5576  void Inherit(Local<FunctionTemplate> parent);
5577 
5582  Local<ObjectTemplate> PrototypeTemplate();
5583 
5590  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5591 
5597  void SetClassName(Local<String> name);
5598 
5599 
5604  void SetAcceptAnyReceiver(bool value);
5605 
5618  void SetHiddenPrototype(bool value);
5619 
5624  void ReadOnlyPrototype();
5625 
5630  void RemovePrototype();
5631 
5636  bool HasInstance(Local<Value> object);
5637 
5638  private:
5639  FunctionTemplate();
5640  friend class Context;
5641  friend class ObjectTemplate;
5642 };
5643 
5652  kNone = 0,
5653 
5657  kAllCanRead = 1,
5658 
5663  kNonMasking = 1 << 1,
5664 
5669  kOnlyInterceptStrings = 1 << 2,
5670 };
5671 
5680  Local<Value> data = Local<Value>(),
5682  : getter(getter),
5683  setter(setter),
5684  query(query),
5685  deleter(deleter),
5686  enumerator(enumerator),
5687  definer(0),
5688  descriptor(0),
5689  data(data),
5690  flags(flags) {}
5691 
5699  Local<Value> data = Local<Value>(),
5701  : getter(getter),
5702  setter(setter),
5703  query(0),
5704  deleter(deleter),
5705  enumerator(enumerator),
5706  definer(definer),
5707  descriptor(descriptor),
5708  data(data),
5709  flags(flags) {}
5710 
5718  Local<Value> data;
5719  PropertyHandlerFlags flags;
5720 };
5721 
5722 
5726  IndexedPropertyGetterCallback getter = 0,
5727  IndexedPropertySetterCallback setter = 0,
5728  IndexedPropertyQueryCallback query = 0,
5729  IndexedPropertyDeleterCallback deleter = 0,
5730  IndexedPropertyEnumeratorCallback enumerator = 0,
5731  Local<Value> data = Local<Value>(),
5733  : getter(getter),
5734  setter(setter),
5735  query(query),
5736  deleter(deleter),
5737  enumerator(enumerator),
5738  definer(0),
5739  descriptor(0),
5740  data(data),
5741  flags(flags) {}
5742 
5750  Local<Value> data = Local<Value>(),
5752  : getter(getter),
5753  setter(setter),
5754  query(0),
5755  deleter(deleter),
5756  enumerator(enumerator),
5757  definer(definer),
5758  descriptor(descriptor),
5759  data(data),
5760  flags(flags) {}
5761 
5769  Local<Value> data;
5770  PropertyHandlerFlags flags;
5771 };
5772 
5773 
5780 class V8_EXPORT ObjectTemplate : public Template {
5781  public:
5783  static Local<ObjectTemplate> New(
5784  Isolate* isolate,
5786  static V8_DEPRECATED("Use isolate version", Local<ObjectTemplate> New());
5787 
5789  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
5790  size_t index);
5791 
5793  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
5794  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
5795 
5825  void SetAccessor(
5827  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
5828  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
5830  void SetAccessor(
5831  Local<Name> name, AccessorNameGetterCallback getter,
5832  AccessorNameSetterCallback setter = 0, Local<Value> data = Local<Value>(),
5833  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
5835 
5858  // TODO(dcarney): deprecate
5859  void SetNamedPropertyHandler(NamedPropertyGetterCallback getter,
5860  NamedPropertySetterCallback setter = 0,
5861  NamedPropertyQueryCallback query = 0,
5862  NamedPropertyDeleterCallback deleter = 0,
5863  NamedPropertyEnumeratorCallback enumerator = 0,
5864  Local<Value> data = Local<Value>());
5865 
5877  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
5878 
5895  // TODO(dcarney): deprecate
5898  IndexedPropertySetterCallback setter = 0,
5899  IndexedPropertyQueryCallback query = 0,
5900  IndexedPropertyDeleterCallback deleter = 0,
5901  IndexedPropertyEnumeratorCallback enumerator = 0,
5902  Local<Value> data = Local<Value>()) {
5903  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
5904  deleter, enumerator, data));
5905  }
5906 
5917  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
5918 
5925  void SetCallAsFunctionHandler(FunctionCallback callback,
5926  Local<Value> data = Local<Value>());
5927 
5936  void MarkAsUndetectable();
5937 
5946  void SetAccessCheckCallback(AccessCheckCallback callback,
5947  Local<Value> data = Local<Value>());
5948 
5955  void SetAccessCheckCallbackAndHandler(
5956  AccessCheckCallback callback,
5957  const NamedPropertyHandlerConfiguration& named_handler,
5958  const IndexedPropertyHandlerConfiguration& indexed_handler,
5959  Local<Value> data = Local<Value>());
5960 
5965  int InternalFieldCount();
5966 
5971  void SetInternalFieldCount(int value);
5972 
5976  bool IsImmutableProto();
5977 
5982  void SetImmutableProto();
5983 
5984  private:
5985  ObjectTemplate();
5986  static Local<ObjectTemplate> New(internal::Isolate* isolate,
5987  Local<FunctionTemplate> constructor);
5988  friend class FunctionTemplate;
5989 };
5990 
5999 class V8_EXPORT Signature : public Data {
6000  public:
6001  static Local<Signature> New(
6002  Isolate* isolate,
6004 
6005  private:
6006  Signature();
6007 };
6008 
6009 
6014 class V8_EXPORT AccessorSignature : public Data {
6015  public:
6016  static Local<AccessorSignature> New(
6017  Isolate* isolate,
6019 
6020  private:
6022 };
6023 
6024 
6025 // --- Extensions ---
6026 
6029  public:
6030  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
6031  ExternalOneByteStringResourceImpl(const char* data, size_t length)
6032  : data_(data), length_(length) {}
6033  const char* data() const { return data_; }
6034  size_t length() const { return length_; }
6035 
6036  private:
6037  const char* data_;
6038  size_t length_;
6039 };
6040 
6044 class V8_EXPORT Extension { // NOLINT
6045  public:
6046  // Note that the strings passed into this constructor must live as long
6047  // as the Extension itself.
6048  Extension(const char* name,
6049  const char* source = 0,
6050  int dep_count = 0,
6051  const char** deps = 0,
6052  int source_length = -1);
6053  virtual ~Extension() { }
6054  virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
6055  Isolate* isolate, Local<String> name) {
6056  return Local<FunctionTemplate>();
6057  }
6058 
6059  const char* name() const { return name_; }
6060  size_t source_length() const { return source_length_; }
6061  const String::ExternalOneByteStringResource* source() const {
6062  return &source_; }
6063  int dependency_count() { return dep_count_; }
6064  const char** dependencies() { return deps_; }
6065  void set_auto_enable(bool value) { auto_enable_ = value; }
6066  bool auto_enable() { return auto_enable_; }
6067 
6068  // Disallow copying and assigning.
6069  Extension(const Extension&) = delete;
6070  void operator=(const Extension&) = delete;
6071 
6072  private:
6073  const char* name_;
6074  size_t source_length_; // expected to initialize before source_
6076  int dep_count_;
6077  const char** deps_;
6078  bool auto_enable_;
6079 };
6080 
6081 
6082 void V8_EXPORT RegisterExtension(Extension* extension);
6083 
6084 
6085 // --- Statics ---
6086 
6087 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6088 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6089 V8_INLINE Local<Boolean> True(Isolate* isolate);
6090 V8_INLINE Local<Boolean> False(Isolate* isolate);
6091 
6106 class V8_EXPORT ResourceConstraints {
6107  public:
6109 
6119  void ConfigureDefaults(uint64_t physical_memory,
6120  uint64_t virtual_memory_limit);
6121 
6122  // Returns the max semi-space size in MB.
6123  V8_DEPRECATE_SOON("Use max_semi_space_size_in_kb()",
6124  int max_semi_space_size()) {
6125  return static_cast<int>(max_semi_space_size_in_kb_ / 1024);
6126  }
6127 
6128  // Sets the max semi-space size in MB.
6129  V8_DEPRECATE_SOON("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6130  void set_max_semi_space_size(int limit_in_mb)) {
6131  max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6132  }
6133 
6134  // Returns the max semi-space size in KB.
6135  size_t max_semi_space_size_in_kb() const {
6136  return max_semi_space_size_in_kb_;
6137  }
6138 
6139  // Sets the max semi-space size in KB.
6140  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6141  max_semi_space_size_in_kb_ = limit_in_kb;
6142  }
6143 
6144  int max_old_space_size() const { return max_old_space_size_; }
6145  void set_max_old_space_size(int limit_in_mb) {
6146  max_old_space_size_ = limit_in_mb;
6147  }
6148  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6149  int max_executable_size() const) {
6150  return max_executable_size_;
6151  }
6152  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6153  void set_max_executable_size(int limit_in_mb)) {
6154  max_executable_size_ = limit_in_mb;
6155  }
6156  uint32_t* stack_limit() const { return stack_limit_; }
6157  // Sets an address beyond which the VM's stack may not grow.
6158  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6159  size_t code_range_size() const { return code_range_size_; }
6160  void set_code_range_size(size_t limit_in_mb) {
6161  code_range_size_ = limit_in_mb;
6162  }
6163  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6164  void set_max_zone_pool_size(const size_t bytes) {
6165  max_zone_pool_size_ = bytes;
6166  }
6167 
6168  private:
6169  // max_semi_space_size_ is in KB
6170  size_t max_semi_space_size_in_kb_;
6171 
6172  // The remaining limits are in MB
6173  int max_old_space_size_;
6174  int max_executable_size_;
6175  uint32_t* stack_limit_;
6176  size_t code_range_size_;
6177  size_t max_zone_pool_size_;
6178 };
6179 
6180 
6181 // --- Exceptions ---
6182 
6183 
6184 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6185 
6186 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6187 
6188 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6189 
6190 // --- Tracing ---
6191 
6192 typedef void (*LogEventCallback)(const char* name, int event);
6193 
6198 class V8_EXPORT Exception {
6199  public:
6200  static Local<Value> RangeError(Local<String> message);
6201  static Local<Value> ReferenceError(Local<String> message);
6202  static Local<Value> SyntaxError(Local<String> message);
6203  static Local<Value> TypeError(Local<String> message);
6204  static Local<Value> Error(Local<String> message);
6205 
6211  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6212  V8_DEPRECATED("Use version with an Isolate*",
6213  static Local<Message> CreateMessage(Local<Value> exception));
6214 
6219  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6220 };
6221 
6222 
6223 // --- Counters Callbacks ---
6224 
6225 typedef int* (*CounterLookupCallback)(const char* name);
6226 
6227 typedef void* (*CreateHistogramCallback)(const char* name,
6228  int min,
6229  int max,
6230  size_t buckets);
6231 
6232 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6233 
6234 // --- Memory Allocation Callback ---
6235 enum ObjectSpace {
6236  kObjectSpaceNewSpace = 1 << 0,
6237  kObjectSpaceOldSpace = 1 << 1,
6238  kObjectSpaceCodeSpace = 1 << 2,
6239  kObjectSpaceMapSpace = 1 << 3,
6240  kObjectSpaceLoSpace = 1 << 4,
6241  kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldSpace |
6242  kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
6243  kObjectSpaceLoSpace
6244 };
6245 
6246  enum AllocationAction {
6247  kAllocationActionAllocate = 1 << 0,
6248  kAllocationActionFree = 1 << 1,
6249  kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
6250  };
6251 
6252 // --- Enter/Leave Script Callback ---
6253 typedef void (*BeforeCallEnteredCallback)(Isolate*);
6254 typedef void (*CallCompletedCallback)(Isolate*);
6255 typedef void (*DeprecatedCallCompletedCallback)();
6256 
6277 typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)(
6278  Local<Context> context, Local<ScriptOrModule> referrer,
6279  Local<String> specifier);
6280 
6297 enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
6298 
6299 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6300  Local<Value> parent);
6301 
6302 // --- Promise Reject Callback ---
6303 enum PromiseRejectEvent {
6304  kPromiseRejectWithNoHandler = 0,
6305  kPromiseHandlerAddedAfterReject = 1
6306 };
6307 
6309  public:
6310  PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
6311  Local<Value> value, Local<StackTrace> stack_trace)
6312  : promise_(promise),
6313  event_(event),
6314  value_(value),
6315  stack_trace_(stack_trace) {}
6316 
6317  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6318  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6319  V8_INLINE Local<Value> GetValue() const { return value_; }
6320 
6321  V8_DEPRECATED("Use v8::Exception::CreateMessage(GetValue())->GetStackTrace()",
6322  V8_INLINE Local<StackTrace> GetStackTrace() const) {
6323  return stack_trace_;
6324  }
6325 
6326  private:
6327  Local<Promise> promise_;
6328  PromiseRejectEvent event_;
6329  Local<Value> value_;
6330  Local<StackTrace> stack_trace_;
6331 };
6332 
6333 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
6334 
6335 // --- Microtasks Callbacks ---
6336 typedef void (*MicrotasksCompletedCallback)(Isolate*);
6337 typedef void (*MicrotaskCallback)(void* data);
6338 
6339 
6347 enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
6348 
6349 
6359 class V8_EXPORT MicrotasksScope {
6360  public:
6361  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6362 
6363  MicrotasksScope(Isolate* isolate, Type type);
6364  ~MicrotasksScope();
6365 
6369  static void PerformCheckpoint(Isolate* isolate);
6370 
6374  static int GetCurrentDepth(Isolate* isolate);
6375 
6379  static bool IsRunningMicrotasks(Isolate* isolate);
6380 
6381  // Prevent copying.
6382  MicrotasksScope(const MicrotasksScope&) = delete;
6383  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6384 
6385  private:
6386  internal::Isolate* const isolate_;
6387  bool run_;
6388 };
6389 
6390 
6391 // --- Failed Access Check Callback ---
6392 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
6393  AccessType type,
6394  Local<Value> data);
6395 
6396 // --- AllowCodeGenerationFromStrings callbacks ---
6397 
6403  Local<String> source);
6404 
6405 // --- WebAssembly compilation callbacks ---
6406 typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
6407 
6408 // --- Callback for APIs defined on v8-supported objects, but implemented
6409 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6410 typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&);
6411 
6412 // --- Garbage Collection Callbacks ---
6413 
6421 enum GCType {
6422  kGCTypeScavenge = 1 << 0,
6423  kGCTypeMarkSweepCompact = 1 << 1,
6424  kGCTypeIncrementalMarking = 1 << 2,
6425  kGCTypeProcessWeakCallbacks = 1 << 3,
6426  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
6427  kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
6428 };
6429 
6445  kNoGCCallbackFlags = 0,
6446  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
6447  kGCCallbackFlagForced = 1 << 2,
6448  kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
6449  kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
6450  kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
6451  kGCCallbackScheduleIdleGarbageCollection = 1 << 6,
6452 };
6453 
6454 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6455 
6456 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6457 
6458 
6465 class V8_EXPORT HeapStatistics {
6466  public:
6467  HeapStatistics();
6468  size_t total_heap_size() { return total_heap_size_; }
6469  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6470  size_t total_physical_size() { return total_physical_size_; }
6471  size_t total_available_size() { return total_available_size_; }
6472  size_t used_heap_size() { return used_heap_size_; }
6473  size_t heap_size_limit() { return heap_size_limit_; }
6474  size_t malloced_memory() { return malloced_memory_; }
6475  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6476 
6481  size_t does_zap_garbage() { return does_zap_garbage_; }
6482 
6483  private:
6484  size_t total_heap_size_;
6485  size_t total_heap_size_executable_;
6486  size_t total_physical_size_;
6487  size_t total_available_size_;
6488  size_t used_heap_size_;
6489  size_t heap_size_limit_;
6490  size_t malloced_memory_;
6491  size_t peak_malloced_memory_;
6492  bool does_zap_garbage_;
6493 
6494  friend class V8;
6495  friend class Isolate;
6496 };
6497 
6498 
6499 class V8_EXPORT HeapSpaceStatistics {
6500  public:
6502  const char* space_name() { return space_name_; }
6503  size_t space_size() { return space_size_; }
6504  size_t space_used_size() { return space_used_size_; }
6505  size_t space_available_size() { return space_available_size_; }
6506  size_t physical_space_size() { return physical_space_size_; }
6507 
6508  private:
6509  const char* space_name_;
6510  size_t space_size_;
6511  size_t space_used_size_;
6512  size_t space_available_size_;
6513  size_t physical_space_size_;
6514 
6515  friend class Isolate;
6516 };
6517 
6518 
6519 class V8_EXPORT HeapObjectStatistics {
6520  public:
6522  const char* object_type() { return object_type_; }
6523  const char* object_sub_type() { return object_sub_type_; }
6524  size_t object_count() { return object_count_; }
6525  size_t object_size() { return object_size_; }
6526 
6527  private:
6528  const char* object_type_;
6529  const char* object_sub_type_;
6530  size_t object_count_;
6531  size_t object_size_;
6532 
6533  friend class Isolate;
6534 };
6535 
6536 class V8_EXPORT HeapCodeStatistics {
6537  public:
6539  size_t code_and_metadata_size() { return code_and_metadata_size_; }
6540  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
6541 
6542  private:
6543  size_t code_and_metadata_size_;
6544  size_t bytecode_and_metadata_size_;
6545 
6546  friend class Isolate;
6547 };
6548 
6549 class RetainedObjectInfo;
6550 
6551 
6563 typedef void (*FunctionEntryHook)(uintptr_t function,
6564  uintptr_t return_addr_location);
6565 
6572  enum EventType {
6573  CODE_ADDED,
6574  CODE_MOVED,
6575  CODE_REMOVED,
6576  CODE_ADD_LINE_POS_INFO,
6577  CODE_START_LINE_INFO_RECORDING,
6578  CODE_END_LINE_INFO_RECORDING
6579  };
6580  // Definition of the code position type. The "POSITION" type means the place
6581  // in the source code which are of interest when making stack traces to
6582  // pin-point the source location of a stack frame as close as possible.
6583  // The "STATEMENT_POSITION" means the place at the beginning of each
6584  // statement, and is used to indicate possible break locations.
6585  enum PositionType { POSITION, STATEMENT_POSITION };
6586 
6587  // Type of event.
6588  EventType type;
6589  // Start of the instructions.
6590  void* code_start;
6591  // Size of the instructions.
6592  size_t code_len;
6593  // Script info for CODE_ADDED event.
6594  Local<UnboundScript> script;
6595  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
6596  // code line information which is returned from the
6597  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
6598  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
6599  void* user_data;
6600 
6601  struct name_t {
6602  // Name of the object associated with the code, note that the string is not
6603  // zero-terminated.
6604  const char* str;
6605  // Number of chars in str.
6606  size_t len;
6607  };
6608 
6609  struct line_info_t {
6610  // PC offset
6611  size_t offset;
6612  // Code position
6613  size_t pos;
6614  // The position type.
6615  PositionType position_type;
6616  };
6617 
6618  union {
6619  // Only valid for CODE_ADDED.
6620  struct name_t name;
6621 
6622  // Only valid for CODE_ADD_LINE_POS_INFO
6623  struct line_info_t line_info;
6624 
6625  // New location of instructions. Only valid for CODE_MOVED.
6626  void* new_code_start;
6627  };
6628 };
6629 
6635 enum RAILMode {
6636  // Response performance mode: In this mode very low virtual machine latency
6637  // is provided. V8 will try to avoid JavaScript execution interruptions.
6638  // Throughput may be throttled.
6639  PERFORMANCE_RESPONSE,
6640  // Animation performance mode: In this mode low virtual machine latency is
6641  // provided. V8 will try to avoid as many JavaScript execution interruptions
6642  // as possible. Throughput may be throttled. This is the default mode.
6643  PERFORMANCE_ANIMATION,
6644  // Idle performance mode: The embedder is idle. V8 can complete deferred work
6645  // in this mode.
6646  PERFORMANCE_IDLE,
6647  // Load performance mode: In this mode high throughput is provided. V8 may
6648  // turn off latency optimizations.
6649  PERFORMANCE_LOAD
6650 };
6651 
6656  kJitCodeEventDefault = 0,
6657  // Generate callbacks for already existent code.
6658  kJitCodeEventEnumExisting = 1
6659 };
6660 
6661 
6667 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
6668 
6669 
6673 class V8_EXPORT ExternalResourceVisitor { // NOLINT
6674  public:
6675  virtual ~ExternalResourceVisitor() {}
6676  virtual void VisitExternalString(Local<String> string) {}
6677 };
6678 
6679 
6683 class V8_EXPORT PersistentHandleVisitor { // NOLINT
6684  public:
6685  virtual ~PersistentHandleVisitor() {}
6686  virtual void VisitPersistentHandle(Persistent<Value>* value,
6687  uint16_t class_id) {}
6688 };
6689 
6698 enum class MemoryPressureLevel { kNone, kModerate, kCritical };
6699 
6711 class V8_EXPORT EmbedderHeapTracer {
6712  public:
6713  enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
6714 
6716  explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
6717  : force_completion(force_completion_) {}
6718 
6719  ForceCompletionAction force_completion;
6720  };
6721 
6728  virtual void RegisterV8References(
6729  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
6730 
6734  virtual void TracePrologue() = 0;
6735 
6746  virtual bool AdvanceTracing(double deadline_in_ms,
6747  AdvanceTracingActions actions) = 0;
6748 
6754  virtual void TraceEpilogue() = 0;
6755 
6760  virtual void EnterFinalPause() = 0;
6761 
6768  virtual void AbortTracing() = 0;
6769 
6773  virtual size_t NumberOfWrappersToTrace() { return 0; }
6774 
6775  protected:
6776  virtual ~EmbedderHeapTracer() = default;
6777 };
6778 
6784  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
6785  void* data);
6786  SerializeInternalFieldsCallback(CallbackFunction function = nullptr,
6787  void* data_arg = nullptr)
6788  : callback(function), data(data_arg) {}
6789  CallbackFunction callback;
6790  void* data;
6791 };
6792 // Note that these fields are called "internal fields" in the API and called
6793 // "embedder fields" within V8.
6795 
6801  typedef void (*CallbackFunction)(Local<Object> holder, int index,
6802  StartupData payload, void* data);
6803  DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
6804  void* data_arg = nullptr)
6805  : callback(function), data(data_arg) {}
6806  void (*callback)(Local<Object> holder, int index, StartupData payload,
6807  void* data);
6808  void* data;
6809 };
6811 
6820 class V8_EXPORT Isolate {
6821  public:
6825  struct CreateParams {
6826  CreateParams()
6827  : entry_hook(nullptr),
6828  code_event_handler(nullptr),
6829  snapshot_blob(nullptr),
6830  counter_lookup_callback(nullptr),
6831  create_histogram_callback(nullptr),
6832  add_histogram_sample_callback(nullptr),
6833  array_buffer_allocator(nullptr),
6834  external_references(nullptr),
6835  allow_atomics_wait(true) {}
6836 
6846 
6852 
6857 
6862 
6863 
6868  CounterLookupCallback counter_lookup_callback;
6869 
6876  CreateHistogramCallback create_histogram_callback;
6877  AddHistogramSampleCallback add_histogram_sample_callback;
6878 
6884 
6891  const intptr_t* external_references;
6892 
6898  };
6899 
6900 
6905  class V8_EXPORT Scope {
6906  public:
6907  explicit Scope(Isolate* isolate) : isolate_(isolate) {
6908  isolate->Enter();
6909  }
6910 
6911  ~Scope() { isolate_->Exit(); }
6912 
6913  // Prevent copying of Scope objects.
6914  Scope(const Scope&) = delete;
6915  Scope& operator=(const Scope&) = delete;
6916 
6917  private:
6918  Isolate* const isolate_;
6919  };
6920 
6921 
6926  public:
6927  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
6928 
6929  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
6931 
6932  // Prevent copying of Scope objects.
6934  delete;
6936  const DisallowJavascriptExecutionScope&) = delete;
6937 
6938  private:
6939  bool on_failure_;
6940  void* internal_;
6941  };
6942 
6943 
6948  public:
6949  explicit AllowJavascriptExecutionScope(Isolate* isolate);
6951 
6952  // Prevent copying of Scope objects.
6954  delete;
6955  AllowJavascriptExecutionScope& operator=(
6956  const AllowJavascriptExecutionScope&) = delete;
6957 
6958  private:
6959  void* internal_throws_;
6960  void* internal_assert_;
6961  };
6962 
6968  public:
6969  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
6971 
6972  // Prevent copying of Scope objects.
6974  delete;
6976  const SuppressMicrotaskExecutionScope&) = delete;
6977 
6978  private:
6979  internal::Isolate* const isolate_;
6980  };
6981 
6987  kFullGarbageCollection,
6988  kMinorGarbageCollection
6989  };
6990 
6997  kUseAsm = 0,
6998  kBreakIterator = 1,
6999  kLegacyConst = 2,
7000  kMarkDequeOverflow = 3,
7001  kStoreBufferOverflow = 4,
7002  kSlotsBufferOverflow = 5,
7003  kObjectObserve = 6,
7004  kForcedGC = 7,
7005  kSloppyMode = 8,
7006  kStrictMode = 9,
7007  kStrongMode = 10,
7008  kRegExpPrototypeStickyGetter = 11,
7009  kRegExpPrototypeToString = 12,
7010  kRegExpPrototypeUnicodeGetter = 13,
7011  kIntlV8Parse = 14,
7012  kIntlPattern = 15,
7013  kIntlResolved = 16,
7014  kPromiseChain = 17,
7015  kPromiseAccept = 18,
7016  kPromiseDefer = 19,
7017  kHtmlCommentInExternalScript = 20,
7018  kHtmlComment = 21,
7019  kSloppyModeBlockScopedFunctionRedefinition = 22,
7020  kForInInitializer = 23,
7021  kArrayProtectorDirtied = 24,
7022  kArraySpeciesModified = 25,
7023  kArrayPrototypeConstructorModified = 26,
7024  kArrayInstanceProtoModified = 27,
7025  kArrayInstanceConstructorModified = 28,
7026  kLegacyFunctionDeclaration = 29,
7027  kRegExpPrototypeSourceGetter = 30,
7028  kRegExpPrototypeOldFlagGetter = 31,
7029  kDecimalWithLeadingZeroInStrictMode = 32,
7030  kLegacyDateParser = 33,
7031  kDefineGetterOrSetterWouldThrow = 34,
7032  kFunctionConstructorReturnedUndefined = 35,
7033  kAssigmentExpressionLHSIsCallInSloppy = 36,
7034  kAssigmentExpressionLHSIsCallInStrict = 37,
7035  kPromiseConstructorReturnedUndefined = 38,
7036  kConstructorNonUndefinedPrimitiveReturn = 39,
7037  kLabeledExpressionStatement = 40,
7038 
7039  // If you add new values here, you'll also need to update Chromium's:
7040  // UseCounter.h, V8PerIsolateData.cpp, histograms.xml
7041  kUseCounterFeatureCount // This enum value must be last.
7042  };
7043 
7044  enum MessageErrorLevel {
7045  kMessageLog = (1 << 0),
7046  kMessageDebug = (1 << 1),
7047  kMessageInfo = (1 << 2),
7048  kMessageError = (1 << 3),
7049  kMessageWarning = (1 << 4),
7050  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
7051  kMessageWarning,
7052  };
7053 
7054  typedef void (*UseCounterCallback)(Isolate* isolate,
7055  UseCounterFeature feature);
7056 
7057 
7067  static Isolate* New(const CreateParams& params);
7068 
7075  static Isolate* GetCurrent();
7076 
7086  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7087  void SetAbortOnUncaughtExceptionCallback(
7088  AbortOnUncaughtExceptionCallback callback);
7089 
7097  void SetHostImportModuleDynamicallyCallback(
7099 
7106  void MemoryPressureNotification(MemoryPressureLevel level);
7107 
7118  void Enter();
7119 
7127  void Exit();
7128 
7133  void Dispose();
7134 
7139  void DumpAndResetStats();
7140 
7148  void DiscardThreadSpecificMetadata();
7149 
7154  V8_INLINE void SetData(uint32_t slot, void* data);
7155 
7160  V8_INLINE void* GetData(uint32_t slot);
7161 
7166  V8_INLINE static uint32_t GetNumberOfDataSlots();
7167 
7171  void GetHeapStatistics(HeapStatistics* heap_statistics);
7172 
7176  size_t NumberOfHeapSpaces();
7177 
7187  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7188  size_t index);
7189 
7193  size_t NumberOfTrackedHeapObjectTypes();
7194 
7204  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7205  size_t type_index);
7206 
7214  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7215 
7228  void GetStackSample(const RegisterState& state, void** frames,
7229  size_t frames_limit, SampleInfo* sample_info);
7230 
7244  V8_INLINE int64_t
7245  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7246 
7251  size_t NumberOfPhantomHandleResetsSinceLastCall();
7252 
7257  HeapProfiler* GetHeapProfiler();
7258 
7264  V8_DEPRECATE_SOON("CpuProfiler should be created with CpuProfiler::New call.",
7265  CpuProfiler* GetCpuProfiler());
7266 
7268  bool InContext();
7269 
7274  Local<Context> GetCurrentContext();
7275 
7281  V8_DEPRECATE_SOON(
7282  "Calling context concept is not compatible with tail calls, and will be "
7283  "removed.",
7284  Local<Context> GetCallingContext());
7285 
7287  Local<Context> GetEnteredContext();
7288 
7295  Local<Context> GetEnteredOrMicrotaskContext();
7296 
7301  Local<Context> GetIncumbentContext();
7302 
7309  Local<Value> ThrowException(Local<Value> exception);
7310 
7311  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7312  GCCallbackFlags flags);
7313  typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type,
7314  GCCallbackFlags flags, void* data);
7315 
7325  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
7326  GCType gc_type_filter = kGCTypeAll);
7327  void AddGCPrologueCallback(GCCallback callback,
7328  GCType gc_type_filter = kGCTypeAll);
7329 
7334  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
7335  void RemoveGCPrologueCallback(GCCallback callback);
7336 
7340  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7341 
7351  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
7352  GCType gc_type_filter = kGCTypeAll);
7353  void AddGCEpilogueCallback(GCCallback callback,
7354  GCType gc_type_filter = kGCTypeAll);
7355 
7360  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
7361  void* data = nullptr);
7362  void RemoveGCEpilogueCallback(GCCallback callback);
7363 
7364  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7365 
7372  void SetGetExternallyAllocatedMemoryInBytesCallback(
7373  GetExternallyAllocatedMemoryInBytesCallback callback);
7374 
7382  void TerminateExecution();
7383 
7392  bool IsExecutionTerminating();
7393 
7408  void CancelTerminateExecution();
7409 
7418  void RequestInterrupt(InterruptCallback callback, void* data);
7419 
7430  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
7431 
7435  void SetEventLogger(LogEventCallback that);
7436 
7443  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7444 
7448  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7449 
7457  void AddCallCompletedCallback(CallCompletedCallback callback);
7458  V8_DEPRECATE_SOON(
7459  "Use callback with parameter",
7460  void AddCallCompletedCallback(DeprecatedCallCompletedCallback callback));
7461 
7465  void RemoveCallCompletedCallback(CallCompletedCallback callback);
7466  V8_DEPRECATE_SOON(
7467  "Use callback with parameter",
7468  void RemoveCallCompletedCallback(
7469  DeprecatedCallCompletedCallback callback));
7470 
7475  void SetPromiseHook(PromiseHook hook);
7476 
7481  void SetPromiseRejectCallback(PromiseRejectCallback callback);
7482 
7487  void RunMicrotasks();
7488 
7492  void EnqueueMicrotask(Local<Function> microtask);
7493 
7497  void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
7498 
7503  void SetMicrotasksPolicy(MicrotasksPolicy policy);
7504  V8_DEPRECATE_SOON("Use SetMicrotasksPolicy",
7505  void SetAutorunMicrotasks(bool autorun));
7506 
7510  MicrotasksPolicy GetMicrotasksPolicy() const;
7511  V8_DEPRECATE_SOON("Use GetMicrotasksPolicy",
7512  bool WillAutorunMicrotasks() const);
7513 
7526  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7527 
7531  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7532 
7536  void SetUseCounterCallback(UseCounterCallback callback);
7537 
7542  void SetCounterFunction(CounterLookupCallback);
7543 
7550  void SetCreateHistogramFunction(CreateHistogramCallback);
7551  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
7552 
7567  bool IdleNotificationDeadline(double deadline_in_seconds);
7568 
7569  V8_DEPRECATED("use IdleNotificationDeadline()",
7570  bool IdleNotification(int idle_time_in_ms));
7571 
7576  void LowMemoryNotification();
7577 
7587  int ContextDisposedNotification(bool dependant_context = true);
7588 
7593  void IsolateInForegroundNotification();
7594 
7599  void IsolateInBackgroundNotification();
7600 
7608  void SetRAILMode(RAILMode rail_mode);
7609 
7614  void IncreaseHeapLimitForDebugging();
7615 
7619  void RestoreOriginalHeapLimit();
7620 
7625  bool IsHeapLimitIncreasedForDebugging();
7626 
7649  void SetJitCodeEventHandler(JitCodeEventOptions options,
7650  JitCodeEventHandler event_handler);
7651 
7661  void SetStackLimit(uintptr_t stack_limit);
7662 
7676  void GetCodeRange(void** start, size_t* length_in_bytes);
7677 
7679  void SetFatalErrorHandler(FatalErrorCallback that);
7680 
7682  void SetOOMErrorHandler(OOMErrorCallback that);
7683 
7688  void SetAllowCodeGenerationFromStringsCallback(
7690 
7695  void SetWasmModuleCallback(ExtensionCallback callback);
7696  void SetWasmInstanceCallback(ExtensionCallback callback);
7697 
7698  void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
7699 
7704  bool IsDead();
7705 
7715  bool AddMessageListener(MessageCallback that,
7716  Local<Value> data = Local<Value>());
7717 
7729  bool AddMessageListenerWithErrorLevel(MessageCallback that,
7730  int message_levels,
7731  Local<Value> data = Local<Value>());
7732 
7736  void RemoveMessageListeners(MessageCallback that);
7737 
7739  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
7740 
7745  void SetCaptureStackTraceForUncaughtExceptions(
7746  bool capture, int frame_limit = 10,
7747  StackTrace::StackTraceOptions options = StackTrace::kOverview);
7748 
7754  void VisitExternalResources(ExternalResourceVisitor* visitor);
7755 
7760  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
7761 
7769  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
7770 
7776  void VisitWeakHandles(PersistentHandleVisitor* visitor);
7777 
7782  bool IsInUse();
7783 
7789  void SetAllowAtomicsWait(bool allow);
7790 
7791  Isolate() = delete;
7792  ~Isolate() = delete;
7793  Isolate(const Isolate&) = delete;
7794  Isolate& operator=(const Isolate&) = delete;
7795  // Deleting operator new and delete here is allowed as ctor and dtor is also
7796  // deleted.
7797  void* operator new(size_t size) = delete;
7798  void* operator new[](size_t size) = delete;
7799  void operator delete(void*, size_t) = delete;
7800  void operator delete[](void*, size_t) = delete;
7801 
7802  private:
7803  template <class K, class V, class Traits>
7804  friend class PersistentValueMapBase;
7805 
7806  void ReportExternalAllocationLimitReached();
7807  void CheckMemoryPressure();
7808 };
7809 
7810 class V8_EXPORT StartupData {
7811  public:
7812  const char* data;
7813  int raw_size;
7814 };
7815 
7816 
7821 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
7822 
7836 typedef uintptr_t (*ReturnAddressLocationResolver)(
7837  uintptr_t return_addr_location);
7838 
7839 
7843 class V8_EXPORT V8 {
7844  public:
7846  V8_INLINE static V8_DEPRECATED(
7847  "Use isolate version",
7848  void SetFatalErrorHandler(FatalErrorCallback that));
7849 
7854  V8_INLINE static V8_DEPRECATED("Use isolate version", bool IsDead());
7855 
7871  static void SetNativesDataBlob(StartupData* startup_blob);
7872  static void SetSnapshotDataBlob(StartupData* startup_blob);
7873 
7880  static StartupData CreateSnapshotDataBlob(const char* embedded_source = NULL);
7881 
7890  static StartupData WarmUpSnapshotDataBlob(StartupData cold_startup_blob,
7891  const char* warmup_source);
7892 
7902  V8_INLINE static V8_DEPRECATED(
7903  "Use isolate version",
7904  bool AddMessageListener(MessageCallback that,
7905  Local<Value> data = Local<Value>()));
7906 
7910  V8_INLINE static V8_DEPRECATED(
7911  "Use isolate version", void RemoveMessageListeners(MessageCallback that));
7912 
7917  V8_INLINE static V8_DEPRECATED(
7918  "Use isolate version",
7919  void SetCaptureStackTraceForUncaughtExceptions(
7920  bool capture, int frame_limit = 10,
7921  StackTrace::StackTraceOptions options = StackTrace::kOverview));
7922 
7926  static void SetFlagsFromString(const char* str, int length);
7927 
7931  static void SetFlagsFromCommandLine(int* argc,
7932  char** argv,
7933  bool remove_flags);
7934 
7936  static const char* GetVersion();
7937 
7939  V8_INLINE static V8_DEPRECATED(
7940  "Use isolate version",
7941  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback));
7942 
7953  static V8_DEPRECATED(
7954  "Use isolate version",
7955  void AddGCPrologueCallback(GCCallback callback,
7956  GCType gc_type_filter = kGCTypeAll));
7957 
7962  V8_INLINE static V8_DEPRECATED(
7963  "Use isolate version",
7964  void RemoveGCPrologueCallback(GCCallback callback));
7965 
7976  static V8_DEPRECATED(
7977  "Use isolate version",
7978  void AddGCEpilogueCallback(GCCallback callback,
7979  GCType gc_type_filter = kGCTypeAll));
7980 
7985  V8_INLINE static V8_DEPRECATED(
7986  "Use isolate version",
7987  void RemoveGCEpilogueCallback(GCCallback callback));
7988 
7993  static bool Initialize();
7994 
7999  static void SetEntropySource(EntropySource source);
8000 
8005  static void SetReturnAddressLocationResolver(
8006  ReturnAddressLocationResolver return_address_resolver);
8007 
8017  V8_INLINE static V8_DEPRECATED("Use isolate version",
8018  void TerminateExecution(Isolate* isolate));
8019 
8030  V8_INLINE static V8_DEPRECATED(
8031  "Use isolate version",
8032  bool IsExecutionTerminating(Isolate* isolate = NULL));
8033 
8050  V8_INLINE static V8_DEPRECATED(
8051  "Use isolate version", void CancelTerminateExecution(Isolate* isolate));
8052 
8062  static bool Dispose();
8063 
8069  V8_INLINE static V8_DEPRECATED(
8070  "Use isolate version",
8071  void VisitExternalResources(ExternalResourceVisitor* visitor));
8072 
8077  V8_INLINE static V8_DEPRECATED(
8078  "Use isolate version",
8079  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor));
8080 
8085  V8_INLINE static V8_DEPRECATED(
8086  "Use isolate version",
8087  void VisitHandlesWithClassIds(Isolate* isolate,
8088  PersistentHandleVisitor* visitor));
8089 
8097  V8_INLINE static V8_DEPRECATED(
8098  "Use isolate version",
8099  void VisitHandlesForPartialDependence(Isolate* isolate,
8100  PersistentHandleVisitor* visitor));
8101 
8109  V8_DEPRECATE_SOON(
8110  "Use version with default location.",
8111  static bool InitializeICU(const char* icu_data_file = nullptr));
8112 
8125  static bool InitializeICUDefaultLocation(const char* exec_path,
8126  const char* icu_data_file = nullptr);
8127 
8144  static void InitializeExternalStartupData(const char* directory_path);
8145  static void InitializeExternalStartupData(const char* natives_blob,
8146  const char* snapshot_blob);
8151  static void InitializePlatform(Platform* platform);
8152 
8157  static void ShutdownPlatform();
8158 
8159 #if V8_OS_POSIX
8160 
8179  static bool TryHandleSignal(int signal_number, void* info, void* context);
8180 #endif // V8_OS_POSIX
8181 
8186  static bool RegisterDefaultSignalHandler();
8187 
8188  private:
8189  V8();
8190 
8191  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
8192  internal::Object** handle);
8193  static internal::Object** CopyPersistent(internal::Object** handle);
8194  static void DisposeGlobal(internal::Object** global_handle);
8195  static void MakeWeak(internal::Object** location, void* data,
8196  WeakCallbackInfo<void>::Callback weak_callback,
8197  WeakCallbackType type);
8198  static void MakeWeak(internal::Object** location, void* data,
8199  // Must be 0 or -1.
8200  int internal_field_index1,
8201  // Must be 1 or -1.
8202  int internal_field_index2,
8203  WeakCallbackInfo<void>::Callback weak_callback);
8204  static void MakeWeak(internal::Object*** location_addr);
8205  static void* ClearWeak(internal::Object** location);
8206  static Value* Eternalize(Isolate* isolate, Value* handle);
8207 
8208  static void RegisterExternallyReferencedObject(internal::Object** object,
8209  internal::Isolate* isolate);
8210 
8211  template <class K, class V, class T>
8212  friend class PersistentValueMapBase;
8213 
8214  static void FromJustIsNothing();
8215  static void ToLocalEmpty();
8216  static void InternalFieldOutOfBounds(int index);
8217  template <class T> friend class Local;
8218  template <class T>
8219  friend class MaybeLocal;
8220  template <class T>
8221  friend class Maybe;
8222  template <class T>
8223  friend class WeakCallbackInfo;
8224  template <class T> friend class Eternal;
8225  template <class T> friend class PersistentBase;
8226  template <class T, class M> friend class Persistent;
8227  friend class Context;
8228 };
8229 
8233 class V8_EXPORT SnapshotCreator {
8234  public:
8235  enum class FunctionCodeHandling { kClear, kKeep };
8236 
8245  SnapshotCreator(const intptr_t* external_references = nullptr,
8246  StartupData* existing_blob = nullptr);
8247 
8248  ~SnapshotCreator();
8249 
8253  Isolate* GetIsolate();
8254 
8262  void SetDefaultContext(Local<Context> context,
8265 
8274  size_t AddContext(Local<Context> context,
8277 
8282  size_t AddTemplate(Local<Template> template_obj);
8283 
8292  StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8293 
8294  // Disallow copying and assigning.
8295  SnapshotCreator(const SnapshotCreator&) = delete;
8296  void operator=(const SnapshotCreator&) = delete;
8297 
8298  private:
8299  void* data_;
8300 };
8301 
8312 template <class T>
8313 class Maybe {
8314  public:
8315  V8_INLINE bool IsNothing() const { return !has_value_; }
8316  V8_INLINE bool IsJust() const { return has_value_; }
8317 
8321  V8_INLINE T ToChecked() const { return FromJust(); }
8322 
8327  V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
8328  if (V8_LIKELY(IsJust())) *out = value_;
8329  return IsJust();
8330  }
8331 
8336  V8_INLINE T FromJust() const {
8337  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8338  return value_;
8339  }
8340 
8345  V8_INLINE T FromMaybe(const T& default_value) const {
8346  return has_value_ ? value_ : default_value;
8347  }
8348 
8349  V8_INLINE bool operator==(const Maybe& other) const {
8350  return (IsJust() == other.IsJust()) &&
8351  (!IsJust() || FromJust() == other.FromJust());
8352  }
8353 
8354  V8_INLINE bool operator!=(const Maybe& other) const {
8355  return !operator==(other);
8356  }
8357 
8358  private:
8359  Maybe() : has_value_(false) {}
8360  explicit Maybe(const T& t) : has_value_(true), value_(t) {}
8361 
8362  bool has_value_;
8363  T value_;
8364 
8365  template <class U>
8366  friend Maybe<U> Nothing();
8367  template <class U>
8368  friend Maybe<U> Just(const U& u);
8369 };
8370 
8371 
8372 template <class T>
8373 inline Maybe<T> Nothing() {
8374  return Maybe<T>();
8375 }
8376 
8377 
8378 template <class T>
8379 inline Maybe<T> Just(const T& t) {
8380  return Maybe<T>(t);
8381 }
8382 
8383 
8387 class V8_EXPORT TryCatch {
8388  public:
8394  V8_DEPRECATED("Use isolate version", TryCatch());
8395 
8401  TryCatch(Isolate* isolate);
8402 
8406  ~TryCatch();
8407 
8411  bool HasCaught() const;
8412 
8421  bool CanContinue() const;
8422 
8435  bool HasTerminated() const;
8436 
8444  Local<Value> ReThrow();
8445 
8452  Local<Value> Exception() const;
8453 
8458  V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace() const);
8459  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
8460  Local<Context> context) const;
8461 
8469  Local<v8::Message> Message() const;
8470 
8481  void Reset();
8482 
8491  void SetVerbose(bool value);
8492 
8496  bool IsVerbose() const;
8497 
8503  void SetCaptureMessage(bool value);
8504 
8516  static void* JSStackComparableAddress(TryCatch* handler) {
8517  if (handler == NULL) return NULL;
8518  return handler->js_stack_comparable_address_;
8519  }
8520 
8521  TryCatch(const TryCatch&) = delete;
8522  void operator=(const TryCatch&) = delete;
8523 
8524  private:
8525  // Declaring operator new and delete as deleted is not spec compliant.
8526  // Therefore declare them private instead to disable dynamic alloc
8527  void* operator new(size_t size);
8528  void* operator new[](size_t size);
8529  void operator delete(void*, size_t);
8530  void operator delete[](void*, size_t);
8531 
8532  void ResetInternal();
8533 
8534  internal::Isolate* isolate_;
8535  TryCatch* next_;
8536  void* exception_;
8537  void* message_obj_;
8538  void* js_stack_comparable_address_;
8539  bool is_verbose_ : 1;
8540  bool can_continue_ : 1;
8541  bool capture_message_ : 1;
8542  bool rethrow_ : 1;
8543  bool has_terminated_ : 1;
8544 
8545  friend class internal::Isolate;
8546 };
8547 
8548 
8549 // --- Context ---
8550 
8551 
8555 class V8_EXPORT ExtensionConfiguration {
8556  public:
8557  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
8558  ExtensionConfiguration(int name_count, const char* names[])
8559  : name_count_(name_count), names_(names) { }
8560 
8561  const char** begin() const { return &names_[0]; }
8562  const char** end() const { return &names_[name_count_]; }
8563 
8564  private:
8565  const int name_count_;
8566  const char** names_;
8567 };
8568 
8573 class V8_EXPORT Context {
8574  public:
8588 
8593  void DetachGlobal();
8594 
8613  static Local<Context> New(
8614  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
8616  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
8617  DeserializeInternalFieldsCallback internal_fields_deserializer =
8619 
8639  static MaybeLocal<Context> FromSnapshot(
8640  Isolate* isolate, size_t context_snapshot_index,
8641  DeserializeInternalFieldsCallback embedder_fields_deserializer =
8643  ExtensionConfiguration* extensions = nullptr,
8644  MaybeLocal<Value> global_object = MaybeLocal<Value>());
8645 
8663  static MaybeLocal<Object> NewRemoteContext(
8664  Isolate* isolate, Local<ObjectTemplate> global_template,
8665  MaybeLocal<Value> global_object = MaybeLocal<Value>());
8666 
8671  void SetSecurityToken(Local<Value> token);
8672 
8674  void UseDefaultSecurityToken();
8675 
8677  Local<Value> GetSecurityToken();
8678 
8685  void Enter();
8686 
8691  void Exit();
8692 
8694  Isolate* GetIsolate();
8695 
8700  enum EmbedderDataFields { kDebugIdIndex = 0 };
8701 
8706  V8_INLINE Local<Value> GetEmbedderData(int index);
8707 
8714  Local<Object> GetExtrasBindingObject();
8715 
8721  void SetEmbedderData(int index, Local<Value> value);
8722 
8729  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
8730 
8736  void SetAlignedPointerInEmbedderData(int index, void* value);
8737 
8751  void AllowCodeGenerationFromStrings(bool allow);
8752 
8757  bool IsCodeGenerationFromStringsAllowed();
8758 
8764  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
8765 
8769  V8_DEPRECATED("no longer supported", size_t EstimatedSize());
8770 
8775  class Scope {
8776  public:
8777  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
8778  context_->Enter();
8779  }
8780  V8_INLINE ~Scope() { context_->Exit(); }
8781 
8782  private:
8783  Local<Context> context_;
8784  };
8785 
8792  public:
8797  explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
8799 
8800  private:
8801  friend class internal::Isolate;
8802 
8803  Local<Context> backup_incumbent_context_;
8804  const BackupIncumbentScope* prev_ = nullptr;
8805  };
8806 
8807  private:
8808  friend class Value;
8809  friend class Script;
8810  friend class Object;
8811  friend class Function;
8812 
8813  Local<Value> SlowGetEmbedderData(int index);
8814  void* SlowGetAlignedPointerFromEmbedderData(int index);
8815 };
8816 
8817 
8894 class V8_EXPORT Unlocker {
8895  public:
8899  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
8900 
8901  ~Unlocker();
8902  private:
8903  void Initialize(Isolate* isolate);
8904 
8905  internal::Isolate* isolate_;
8906 };
8907 
8908 
8909 class V8_EXPORT Locker {
8910  public:
8914  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
8915 
8916  ~Locker();
8917 
8922  static bool IsLocked(Isolate* isolate);
8923 
8927  static bool IsActive();
8928 
8929  // Disallow copying and assigning.
8930  Locker(const Locker&) = delete;
8931  void operator=(const Locker&) = delete;
8932 
8933  private:
8934  void Initialize(Isolate* isolate);
8935 
8936  bool has_lock_;
8937  bool top_level_;
8938  internal::Isolate* isolate_;
8939 };
8940 
8941 
8942 // --- Implementation ---
8943 
8944 
8945 namespace internal {
8946 
8947 const int kApiPointerSize = sizeof(void*); // NOLINT
8948 const int kApiIntSize = sizeof(int); // NOLINT
8949 const int kApiInt64Size = sizeof(int64_t); // NOLINT
8950 
8951 // Tag information for HeapObject.
8952 const int kHeapObjectTag = 1;
8953 const int kHeapObjectTagSize = 2;
8954 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
8955 
8956 // Tag information for Smi.
8957 const int kSmiTag = 0;
8958 const int kSmiTagSize = 1;
8959 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
8960 
8961 template <size_t ptr_size> struct SmiTagging;
8962 
8963 template<int kSmiShiftSize>
8964 V8_INLINE internal::Object* IntToSmi(int value) {
8965  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
8966  uintptr_t tagged_value =
8967  (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
8968  return reinterpret_cast<internal::Object*>(tagged_value);
8969 }
8970 
8971 // Smi constants for 32-bit systems.
8972 template <> struct SmiTagging<4> {
8973  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
8974  static int SmiShiftSize() { return kSmiShiftSize; }
8975  static int SmiValueSize() { return kSmiValueSize; }
8976  V8_INLINE static int SmiToInt(const internal::Object* value) {
8977  int shift_bits = kSmiTagSize + kSmiShiftSize;
8978  // Throw away top 32 bits and shift down (requires >> to be sign extending).
8979  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
8980  }
8981  V8_INLINE static internal::Object* IntToSmi(int value) {
8982  return internal::IntToSmi<kSmiShiftSize>(value);
8983  }
8984  V8_INLINE static bool IsValidSmi(intptr_t value) {
8985  // To be representable as an tagged small integer, the two
8986  // most-significant bits of 'value' must be either 00 or 11 due to
8987  // sign-extension. To check this we add 01 to the two
8988  // most-significant bits, and check if the most-significant bit is 0
8989  //
8990  // CAUTION: The original code below:
8991  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
8992  // may lead to incorrect results according to the C language spec, and
8993  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
8994  // compiler may produce undefined results in case of signed integer
8995  // overflow. The computation must be done w/ unsigned ints.
8996  return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
8997  }
8998 };
8999 
9000 // Smi constants for 64-bit systems.
9001 template <> struct SmiTagging<8> {
9002  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
9003  static int SmiShiftSize() { return kSmiShiftSize; }
9004  static int SmiValueSize() { return kSmiValueSize; }
9005  V8_INLINE static int SmiToInt(const internal::Object* value) {
9006  int shift_bits = kSmiTagSize + kSmiShiftSize;
9007  // Shift down and throw away top 32 bits.
9008  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
9009  }
9010  V8_INLINE static internal::Object* IntToSmi(int value) {
9011  return internal::IntToSmi<kSmiShiftSize>(value);
9012  }
9013  V8_INLINE static bool IsValidSmi(intptr_t value) {
9014  // To be representable as a long smi, the value must be a 32-bit integer.
9015  return (value == static_cast<int32_t>(value));
9016  }
9017 };
9018 
9020 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
9021 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
9022 V8_INLINE static bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
9023 V8_INLINE static bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
9024 
9030 class Internals {
9031  public:
9032  // These values match non-compiler-dependent values defined within
9033  // the implementation of v8.
9034  static const int kHeapObjectMapOffset = 0;
9035  static const int kMapInstanceTypeAndBitFieldOffset =
9036  1 * kApiPointerSize + kApiIntSize;
9037  static const int kStringResourceOffset = 3 * kApiPointerSize;
9038 
9039  static const int kOddballKindOffset = 4 * kApiPointerSize + sizeof(double);
9040  static const int kForeignAddressOffset = kApiPointerSize;
9041  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
9042  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
9043  static const int kContextHeaderSize = 2 * kApiPointerSize;
9044  static const int kContextEmbedderDataIndex = 5;
9045  static const int kFullStringRepresentationMask = 0x0f;
9046  static const int kStringEncodingMask = 0x8;
9047  static const int kExternalTwoByteRepresentationTag = 0x02;
9048  static const int kExternalOneByteRepresentationTag = 0x0a;
9049 
9050  static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
9051  static const int kExternalMemoryOffset = 4 * kApiPointerSize;
9052  static const int kExternalMemoryLimitOffset =
9053  kExternalMemoryOffset + kApiInt64Size;
9054  static const int kExternalMemoryAtLastMarkCompactOffset =
9055  kExternalMemoryLimitOffset + kApiInt64Size;
9056  static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
9057  kApiInt64Size + kApiInt64Size +
9058  kApiPointerSize + kApiPointerSize;
9059  static const int kUndefinedValueRootIndex = 4;
9060  static const int kTheHoleValueRootIndex = 5;
9061  static const int kNullValueRootIndex = 6;
9062  static const int kTrueValueRootIndex = 7;
9063  static const int kFalseValueRootIndex = 8;
9064  static const int kEmptyStringRootIndex = 9;
9065 
9066  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
9067  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
9068  static const int kNodeStateMask = 0x7;
9069  static const int kNodeStateIsWeakValue = 2;
9070  static const int kNodeStateIsPendingValue = 3;
9071  static const int kNodeStateIsNearDeathValue = 4;
9072  static const int kNodeIsIndependentShift = 3;
9073  static const int kNodeIsActiveShift = 4;
9074 
9075  static const int kJSApiObjectType = 0xbd;
9076  static const int kJSObjectType = 0xbe;
9077  static const int kFirstNonstringType = 0x80;
9078  static const int kOddballType = 0x82;
9079  static const int kForeignType = 0x86;
9080 
9081  static const int kUndefinedOddballKind = 5;
9082  static const int kNullOddballKind = 3;
9083 
9084  static const uint32_t kNumIsolateDataSlots = 4;
9085 
9086  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
9087  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
9088 #ifdef V8_ENABLE_CHECKS
9089  CheckInitializedImpl(isolate);
9090 #endif
9091  }
9092 
9093  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
9094  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
9095  kHeapObjectTag);
9096  }
9097 
9098  V8_INLINE static int SmiValue(const internal::Object* value) {
9099  return PlatformSmiTagging::SmiToInt(value);
9100  }
9101 
9102  V8_INLINE static internal::Object* IntToSmi(int value) {
9103  return PlatformSmiTagging::IntToSmi(value);
9104  }
9105 
9106  V8_INLINE static bool IsValidSmi(intptr_t value) {
9107  return PlatformSmiTagging::IsValidSmi(value);
9108  }
9109 
9110  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
9111  typedef internal::Object O;
9112  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
9113  // Map::InstanceType is defined so that it will always be loaded into
9114  // the LS 8 bits of one 16-bit word, regardless of endianess.
9115  return ReadField<uint16_t>(map, kMapInstanceTypeAndBitFieldOffset) & 0xff;
9116  }
9117 
9118  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
9119  typedef internal::Object O;
9120  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
9121  }
9122 
9123  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
9124  int representation = (instance_type & kFullStringRepresentationMask);
9125  return representation == kExternalTwoByteRepresentationTag;
9126  }
9127 
9128  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
9129  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9130  return *addr & static_cast<uint8_t>(1U << shift);
9131  }
9132 
9133  V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
9134  bool value, int shift) {
9135  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9136  uint8_t mask = static_cast<uint8_t>(1U << shift);
9137  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
9138  }
9139 
9140  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
9141  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9142  return *addr & kNodeStateMask;
9143  }
9144 
9145  V8_INLINE static void UpdateNodeState(internal::Object** obj,
9146  uint8_t value) {
9147  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
9148  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
9149  }
9150 
9151  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
9152  uint32_t slot,
9153  void* data) {
9154  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
9155  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
9156  *reinterpret_cast<void**>(addr) = data;
9157  }
9158 
9159  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
9160  uint32_t slot) {
9161  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
9162  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
9163  return *reinterpret_cast<void* const*>(addr);
9164  }
9165 
9166  V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
9167  int index) {
9168  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
9169  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
9170  }
9171 
9172  template <typename T>
9173  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
9174  const uint8_t* addr =
9175  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
9176  return *reinterpret_cast<const T*>(addr);
9177  }
9178 
9179  template <typename T>
9180  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
9181  typedef internal::Object O;
9182  typedef internal::Internals I;
9183  O* ctx = *reinterpret_cast<O* const*>(context);
9184  int embedder_data_offset = I::kContextHeaderSize +
9185  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
9186  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
9187  int value_offset =
9188  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
9189  return I::ReadField<T>(embedder_data, value_offset);
9190  }
9191 };
9192 
9193 } // namespace internal
9194 
9195 
9196 template <class T>
9198  return New(isolate, that.val_);
9199 }
9200 
9201 template <class T>
9202 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
9203  return New(isolate, that.val_);
9204 }
9205 
9206 
9207 template <class T>
9208 Local<T> Local<T>::New(Isolate* isolate, T* that) {
9209  if (that == NULL) return Local<T>();
9210  T* that_ptr = that;
9211  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
9212  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
9213  reinterpret_cast<internal::Isolate*>(isolate), *p)));
9214 }
9215 
9216 
9217 template<class T>
9218 template<class S>
9219 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
9220  TYPE_CHECK(T, S);
9221  val_ = reinterpret_cast<T*>(
9222  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
9223 }
9224 
9225 template <class T>
9226 Local<T> Eternal<T>::Get(Isolate* isolate) const {
9227  // The eternal handle will never go away, so as with the roots, we don't even
9228  // need to open a handle.
9229  return Local<T>(val_);
9230 }
9231 
9232 
9233 template <class T>
9235  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
9236  return Local<T>(val_);
9237 }
9238 
9239 
9240 template <class T>
9241 void* WeakCallbackInfo<T>::GetInternalField(int index) const {
9242 #ifdef V8_ENABLE_CHECKS
9243  if (index < 0 || index >= kEmbedderFieldsInWeakCallback) {
9244  V8::InternalFieldOutOfBounds(index);
9245  }
9246 #endif
9247  return embedder_fields_[index];
9248 }
9249 
9250 
9251 template <class T>
9252 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
9253  if (that == NULL) return NULL;
9254  internal::Object** p = reinterpret_cast<internal::Object**>(that);
9255  return reinterpret_cast<T*>(
9256  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
9257  p));
9258 }
9259 
9260 
9261 template <class T, class M>
9262 template <class S, class M2>
9263 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
9264  TYPE_CHECK(T, S);
9265  this->Reset();
9266  if (that.IsEmpty()) return;
9267  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
9268  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
9269  M::Copy(that, this);
9270 }
9271 
9272 
9273 template <class T>
9274 bool PersistentBase<T>::IsIndependent() const {
9275  typedef internal::Internals I;
9276  if (this->IsEmpty()) return false;
9277  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
9278  I::kNodeIsIndependentShift);
9279 }
9280 
9281 
9282 template <class T>
9284  typedef internal::Internals I;
9285  if (this->IsEmpty()) return false;
9286  uint8_t node_state =
9287  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
9288  return node_state == I::kNodeStateIsNearDeathValue ||
9289  node_state == I::kNodeStateIsPendingValue;
9290 }
9291 
9292 
9293 template <class T>
9295  typedef internal::Internals I;
9296  if (this->IsEmpty()) return false;
9297  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
9298  I::kNodeStateIsWeakValue;
9299 }
9300 
9301 
9302 template <class T>
9304  if (this->IsEmpty()) return;
9305  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
9306  val_ = 0;
9307 }
9308 
9309 
9310 template <class T>
9311 template <class S>
9312 void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
9313  TYPE_CHECK(T, S);
9314  Reset();
9315  if (other.IsEmpty()) return;
9316  this->val_ = New(isolate, other.val_);
9317 }
9318 
9319 
9320 template <class T>
9321 template <class S>
9322 void PersistentBase<T>::Reset(Isolate* isolate,
9323  const PersistentBase<S>& other) {
9324  TYPE_CHECK(T, S);
9325  Reset();
9326  if (other.IsEmpty()) return;
9327  this->val_ = New(isolate, other.val_);
9328 }
9329 
9330 
9331 template <class T>
9332 template <typename P>
9334  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
9335  WeakCallbackType type) {
9336  typedef typename WeakCallbackInfo<void>::Callback Callback;
9337  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
9338  reinterpret_cast<Callback>(callback), type);
9339 }
9340 
9341 template <class T>
9343  V8::MakeWeak(reinterpret_cast<internal::Object***>(&this->val_));
9344 }
9345 
9346 template <class T>
9347 template <typename P>
9349  return reinterpret_cast<P*>(
9350  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
9351 }
9352 
9353 template <class T>
9355  if (IsEmpty()) return;
9356  V8::RegisterExternallyReferencedObject(
9357  reinterpret_cast<internal::Object**>(this->val_),
9358  reinterpret_cast<internal::Isolate*>(isolate));
9359 }
9360 
9361 template <class T>
9363  typedef internal::Internals I;
9364  if (this->IsEmpty()) return;
9365  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
9366  true,
9367  I::kNodeIsIndependentShift);
9368 }
9369 
9370 template <class T>
9372  typedef internal::Internals I;
9373  if (this->IsEmpty()) return;
9374  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
9375  I::kNodeIsActiveShift);
9376 }
9377 
9378 
9379 template <class T>
9380 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
9381  typedef internal::Internals I;
9382  if (this->IsEmpty()) return;
9383  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
9384  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9385  *reinterpret_cast<uint16_t*>(addr) = class_id;
9386 }
9387 
9388 
9389 template <class T>
9391  typedef internal::Internals I;
9392  if (this->IsEmpty()) return 0;
9393  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
9394  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
9395  return *reinterpret_cast<uint16_t*>(addr);
9396 }
9397 
9398 
9399 template<typename T>
9400 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
9401 
9402 template<typename T>
9403 template<typename S>
9404 void ReturnValue<T>::Set(const Persistent<S>& handle) {
9405  TYPE_CHECK(T, S);
9406  if (V8_UNLIKELY(handle.IsEmpty())) {
9407  *value_ = GetDefaultValue();
9408  } else {
9409  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9410  }
9411 }
9412 
9413 template <typename T>
9414 template <typename S>
9415 void ReturnValue<T>::Set(const Global<S>& handle) {
9416  TYPE_CHECK(T, S);
9417  if (V8_UNLIKELY(handle.IsEmpty())) {
9418  *value_ = GetDefaultValue();
9419  } else {
9420  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9421  }
9422 }
9423 
9424 template <typename T>
9425 template <typename S>
9426 void ReturnValue<T>::Set(const Local<S> handle) {
9427  TYPE_CHECK(T, S);
9428  if (V8_UNLIKELY(handle.IsEmpty())) {
9429  *value_ = GetDefaultValue();
9430  } else {
9431  *value_ = *reinterpret_cast<internal::Object**>(*handle);
9432  }
9433 }
9434 
9435 template<typename T>
9436 void ReturnValue<T>::Set(double i) {
9437  TYPE_CHECK(T, Number);
9438  Set(Number::New(GetIsolate(), i));
9439 }
9440 
9441 template<typename T>
9442 void ReturnValue<T>::Set(int32_t i) {
9443  TYPE_CHECK(T, Integer);
9444  typedef internal::Internals I;
9445  if (V8_LIKELY(I::IsValidSmi(i))) {
9446  *value_ = I::IntToSmi(i);
9447  return;
9448  }
9449  Set(Integer::New(GetIsolate(), i));
9450 }
9451 
9452 template<typename T>
9453 void ReturnValue<T>::Set(uint32_t i) {
9454  TYPE_CHECK(T, Integer);
9455  // Can't simply use INT32_MAX here for whatever reason.
9456  bool fits_into_int32_t = (i & (1U << 31)) == 0;
9457  if (V8_LIKELY(fits_into_int32_t)) {
9458  Set(static_cast<int32_t>(i));
9459  return;
9460  }
9461  Set(Integer::NewFromUnsigned(GetIsolate(), i));
9462 }
9463 
9464 template<typename T>
9465 void ReturnValue<T>::Set(bool value) {
9466  TYPE_CHECK(T, Boolean);
9467  typedef internal::Internals I;
9468  int root_index;
9469  if (value) {
9470  root_index = I::kTrueValueRootIndex;
9471  } else {
9472  root_index = I::kFalseValueRootIndex;
9473  }
9474  *value_ = *I::GetRoot(GetIsolate(), root_index);
9475 }
9476 
9477 template<typename T>
9478 void ReturnValue<T>::SetNull() {
9479  TYPE_CHECK(T, Primitive);
9480  typedef internal::Internals I;
9481  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
9482 }
9483 
9484 template<typename T>
9486  TYPE_CHECK(T, Primitive);
9487  typedef internal::Internals I;
9488  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
9489 }
9490 
9491 template<typename T>
9493  TYPE_CHECK(T, String);
9494  typedef internal::Internals I;
9495  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
9496 }
9497 
9498 template <typename T>
9500  // Isolate is always the pointer below the default value on the stack.
9501  return *reinterpret_cast<Isolate**>(&value_[-2]);
9502 }
9503 
9504 template <typename T>
9506  typedef internal::Internals I;
9507  if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex))
9508  return Local<Value>(*Undefined(GetIsolate()));
9509  return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
9510 }
9511 
9512 template <typename T>
9513 template <typename S>
9514 void ReturnValue<T>::Set(S* whatever) {
9515  // Uncompilable to prevent inadvertent misuse.
9516  TYPE_CHECK(S*, Primitive);
9517 }
9518 
9519 template<typename T>
9520 internal::Object* ReturnValue<T>::GetDefaultValue() {
9521  // Default value is always the pointer below value_ on the stack.
9522  return value_[-1];
9523 }
9524 
9525 template <typename T>
9526 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
9527  internal::Object** values,
9528  int length)
9529  : implicit_args_(implicit_args), values_(values), length_(length) {}
9530 
9531 template<typename T>
9533  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
9534  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
9535 }
9536 
9537 
9538 template<typename T>
9540  return Local<Function>(reinterpret_cast<Function*>(
9541  &implicit_args_[kCalleeIndex]));
9542 }
9543 
9544 
9545 template<typename T>
9547  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
9548 }
9549 
9550 
9551 template<typename T>
9553  return Local<Object>(reinterpret_cast<Object*>(
9554  &implicit_args_[kHolderIndex]));
9555 }
9556 
9557 template <typename T>
9559  return Local<Value>(
9560  reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex]));
9561 }
9562 
9563 template <typename T>
9565  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
9566 }
9567 
9568 
9569 template<typename T>
9571  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
9572 }
9573 
9574 
9575 template<typename T>
9577  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
9578 }
9579 
9580 
9581 template<typename T>
9583  return !NewTarget()->IsUndefined();
9584 }
9585 
9586 
9587 template<typename T>
9589  return length_;
9590 }
9591 
9592 ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
9593  Local<Integer> resource_line_offset,
9594  Local<Integer> resource_column_offset,
9595  Local<Boolean> resource_is_shared_cross_origin,
9596  Local<Integer> script_id,
9597  Local<Value> source_map_url,
9598  Local<Boolean> resource_is_opaque,
9599  Local<Boolean> is_wasm, Local<Boolean> is_module /*,
9600  // Backed out for ABI compatibility with V8 6.2
9601  Local<PrimitiveArray> host_defined_options */)
9602  : resource_name_(resource_name),
9603  resource_line_offset_(resource_line_offset),
9604  resource_column_offset_(resource_column_offset),
9605  options_(!resource_is_shared_cross_origin.IsEmpty() &&
9606  resource_is_shared_cross_origin->IsTrue(),
9607  !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue(),
9608  !is_wasm.IsEmpty() && is_wasm->IsTrue(),
9609  !is_module.IsEmpty() && is_module->IsTrue()),
9610  script_id_(script_id),
9611  source_map_url_(source_map_url) /*,
9612  // Backed out for ABI compatibility with V8 6.2
9613  host_defined_options_(host_defined_options) */ {}
9614 
9615 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
9616 
9617 // Backed out for ABI compatibility with V8 6.2
9618 // Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions() const {
9619 // return host_defined_options_;
9620 // }
9621 
9622 Local<Integer> ScriptOrigin::ResourceLineOffset() const {
9623  return resource_line_offset_;
9624 }
9625 
9626 
9627 Local<Integer> ScriptOrigin::ResourceColumnOffset() const {
9628  return resource_column_offset_;
9629 }
9630 
9631 
9632 Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
9633 
9634 
9635 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
9636 
9637 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
9638  CachedData* data)
9639  : source_string(string),
9640  resource_name(origin.ResourceName()),
9641  resource_line_offset(origin.ResourceLineOffset()),
9642  resource_column_offset(origin.ResourceColumnOffset()),
9643  resource_options(origin.Options()),
9644  source_map_url(origin.SourceMapUrl()),
9645  // Backed out for ABI compatibility with V8 6.2
9646  // host_defined_options(origin.HostDefinedOptions()),
9647  cached_data(data) {}
9648 
9649 ScriptCompiler::Source::Source(Local<String> string,
9650  CachedData* data)
9651  : source_string(string), cached_data(data) {}
9652 
9653 
9654 ScriptCompiler::Source::~Source() {
9655  delete cached_data;
9656 }
9657 
9658 
9659 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
9660  const {
9661  return cached_data;
9662 }
9663 
9664 const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
9665  return resource_options;
9666 }
9667 
9668 Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
9669  return value ? True(isolate) : False(isolate);
9670 }
9671 
9672 void Template::Set(Isolate* isolate, const char* name, Local<Data> value) {
9674  .ToLocalChecked(),
9675  value);
9676 }
9677 
9678 
9680 #ifndef V8_ENABLE_CHECKS
9681  typedef internal::Object O;
9682  typedef internal::HeapObject HO;
9683  typedef internal::Internals I;
9684  O* obj = *reinterpret_cast<O**>(this);
9685  // Fast path: If the object is a plain JSObject, which is the common case, we
9686  // know where to find the internal fields and can return the value directly.
9687  auto instance_type = I::GetInstanceType(obj);
9688  if (instance_type == I::kJSObjectType ||
9689  instance_type == I::kJSApiObjectType) {
9690  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
9691  O* value = I::ReadField<O*>(obj, offset);
9692  O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
9693  return Local<Value>(reinterpret_cast<Value*>(result));
9694  }
9695 #endif
9696  return SlowGetInternalField(index);
9697 }
9698 
9699 
9701 #ifndef V8_ENABLE_CHECKS
9702  typedef internal::Object O;
9703  typedef internal::Internals I;
9704  O* obj = *reinterpret_cast<O**>(this);
9705  // Fast path: If the object is a plain JSObject, which is the common case, we
9706  // know where to find the internal fields and can return the value directly.
9707  auto instance_type = I::GetInstanceType(obj);
9708  if (V8_LIKELY(instance_type == I::kJSObjectType ||
9709  instance_type == I::kJSApiObjectType)) {
9710  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
9711  return I::ReadField<void*>(obj, offset);
9712  }
9713 #endif
9714  return SlowGetAlignedPointerFromInternalField(index);
9715 }
9716 
9717 String* String::Cast(v8::Value* value) {
9718 #ifdef V8_ENABLE_CHECKS
9719  CheckCast(value);
9720 #endif
9721  return static_cast<String*>(value);
9722 }
9723 
9724 
9726  typedef internal::Object* S;
9727  typedef internal::Internals I;
9728  I::CheckInitialized(isolate);
9729  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
9730  return Local<String>(reinterpret_cast<String*>(slot));
9731 }
9732 
9733 
9735  typedef internal::Object O;
9736  typedef internal::Internals I;
9737  O* obj = *reinterpret_cast<O* const*>(this);
9739  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
9740  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
9741  result = reinterpret_cast<String::ExternalStringResource*>(value);
9742  } else {
9743  result = NULL;
9744  }
9745 #ifdef V8_ENABLE_CHECKS
9746  VerifyExternalStringResource(result);
9747 #endif
9748  return result;
9749 }
9750 
9751 
9753  String::Encoding* encoding_out) const {
9754  typedef internal::Object O;
9755  typedef internal::Internals I;
9756  O* obj = *reinterpret_cast<O* const*>(this);
9757  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
9758  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
9759  ExternalStringResourceBase* resource = NULL;
9760  if (type == I::kExternalOneByteRepresentationTag ||
9761  type == I::kExternalTwoByteRepresentationTag) {
9762  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
9763  resource = static_cast<ExternalStringResourceBase*>(value);
9764  }
9765 #ifdef V8_ENABLE_CHECKS
9766  VerifyExternalStringResourceBase(resource, *encoding_out);
9767 #endif
9768  return resource;
9769 }
9770 
9771 
9772 bool Value::IsUndefined() const {
9773 #ifdef V8_ENABLE_CHECKS
9774  return FullIsUndefined();
9775 #else
9776  return QuickIsUndefined();
9777 #endif
9778 }
9779 
9780 bool Value::QuickIsUndefined() const {
9781  typedef internal::Object O;
9782  typedef internal::Internals I;
9783  O* obj = *reinterpret_cast<O* const*>(this);
9784  if (!I::HasHeapObjectTag(obj)) return false;
9785  if (I::GetInstanceType(obj) != I::kOddballType) return false;
9786  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
9787 }
9788 
9789 
9790 bool Value::IsNull() const {
9791 #ifdef V8_ENABLE_CHECKS
9792  return FullIsNull();
9793 #else
9794  return QuickIsNull();
9795 #endif
9796 }
9797 
9798 bool Value::QuickIsNull() const {
9799  typedef internal::Object O;
9800  typedef internal::Internals I;
9801  O* obj = *reinterpret_cast<O* const*>(this);
9802  if (!I::HasHeapObjectTag(obj)) return false;
9803  if (I::GetInstanceType(obj) != I::kOddballType) return false;
9804  return (I::GetOddballKind(obj) == I::kNullOddballKind);
9805 }
9806 
9808 #ifdef V8_ENABLE_CHECKS
9809  return FullIsNull() || FullIsUndefined();
9810 #else
9811  return QuickIsNullOrUndefined();
9812 #endif
9813 }
9814 
9815 bool Value::QuickIsNullOrUndefined() const {
9816  typedef internal::Object O;
9817  typedef internal::Internals I;
9818  O* obj = *reinterpret_cast<O* const*>(this);
9819  if (!I::HasHeapObjectTag(obj)) return false;
9820  if (I::GetInstanceType(obj) != I::kOddballType) return false;
9821  int kind = I::GetOddballKind(obj);
9822  return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
9823 }
9824 
9825 bool Value::IsString() const {
9826 #ifdef V8_ENABLE_CHECKS
9827  return FullIsString();
9828 #else
9829  return QuickIsString();
9830 #endif
9831 }
9832 
9833 bool Value::QuickIsString() const {
9834  typedef internal::Object O;
9835  typedef internal::Internals I;
9836  O* obj = *reinterpret_cast<O* const*>(this);
9837  if (!I::HasHeapObjectTag(obj)) return false;
9838  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
9839 }
9840 
9841 
9842 template <class T> Value* Value::Cast(T* value) {
9843  return static_cast<Value*>(value);
9844 }
9845 
9846 
9847 Local<Boolean> Value::ToBoolean() const {
9848  return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
9849  .FromMaybe(Local<Boolean>());
9850 }
9851 
9852 
9853 Local<Number> Value::ToNumber() const {
9854  return ToNumber(Isolate::GetCurrent()->GetCurrentContext())
9855  .FromMaybe(Local<Number>());
9856 }
9857 
9858 
9859 Local<String> Value::ToString() const {
9860  return ToString(Isolate::GetCurrent()->GetCurrentContext())
9861  .FromMaybe(Local<String>());
9862 }
9863 
9864 
9865 Local<String> Value::ToDetailString() const {
9866  return ToDetailString(Isolate::GetCurrent()->GetCurrentContext())
9867  .FromMaybe(Local<String>());
9868 }
9869 
9870 
9871 Local<Object> Value::ToObject() const {
9872  return ToObject(Isolate::GetCurrent()->GetCurrentContext())
9873  .FromMaybe(Local<Object>());
9874 }
9875 
9876 
9877 Local<Integer> Value::ToInteger() const {
9878  return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
9879  .FromMaybe(Local<Integer>());
9880 }
9881 
9882 
9883 Local<Uint32> Value::ToUint32() const {
9884  return ToUint32(Isolate::GetCurrent()->GetCurrentContext())
9885  .FromMaybe(Local<Uint32>());
9886 }
9887 
9888 
9889 Local<Int32> Value::ToInt32() const {
9890  return ToInt32(Isolate::GetCurrent()->GetCurrentContext())
9891  .FromMaybe(Local<Int32>());
9892 }
9893 
9894 
9895 Boolean* Boolean::Cast(v8::Value* value) {
9896 #ifdef V8_ENABLE_CHECKS
9897  CheckCast(value);
9898 #endif
9899  return static_cast<Boolean*>(value);
9900 }
9901 
9902 
9903 Name* Name::Cast(v8::Value* value) {
9904 #ifdef V8_ENABLE_CHECKS
9905  CheckCast(value);
9906 #endif
9907  return static_cast<Name*>(value);
9908 }
9909 
9910 
9911 Symbol* Symbol::Cast(v8::Value* value) {
9912 #ifdef V8_ENABLE_CHECKS
9913  CheckCast(value);
9914 #endif
9915  return static_cast<Symbol*>(value);
9916 }
9917 
9918 
9919 Number* Number::Cast(v8::Value* value) {
9920 #ifdef V8_ENABLE_CHECKS
9921  CheckCast(value);
9922 #endif
9923  return static_cast<Number*>(value);
9924 }
9925 
9926 
9927 Integer* Integer::Cast(v8::Value* value) {
9928 #ifdef V8_ENABLE_CHECKS
9929  CheckCast(value);
9930 #endif
9931  return static_cast<Integer*>(value);
9932 }
9933 
9934 
9935 Int32* Int32::Cast(v8::Value* value) {
9936 #ifdef V8_ENABLE_CHECKS
9937  CheckCast(value);
9938 #endif
9939  return static_cast<Int32*>(value);
9940 }
9941 
9942 
9943 Uint32* Uint32::Cast(v8::Value* value) {
9944 #ifdef V8_ENABLE_CHECKS
9945  CheckCast(value);
9946 #endif
9947  return static_cast<Uint32*>(value);
9948 }
9949 
9950 
9951 Date* Date::Cast(v8::Value* value) {
9952 #ifdef V8_ENABLE_CHECKS
9953  CheckCast(value);
9954 #endif
9955  return static_cast<Date*>(value);
9956 }
9957 
9958 
9959 StringObject* StringObject::Cast(v8::Value* value) {
9960 #ifdef V8_ENABLE_CHECKS
9961  CheckCast(value);
9962 #endif
9963  return static_cast<StringObject*>(value);
9964 }
9965 
9966 
9967 SymbolObject* SymbolObject::Cast(v8::Value* value) {
9968 #ifdef V8_ENABLE_CHECKS
9969  CheckCast(value);
9970 #endif
9971  return static_cast<SymbolObject*>(value);
9972 }
9973 
9974 
9975 NumberObject* NumberObject::Cast(v8::Value* value) {
9976 #ifdef V8_ENABLE_CHECKS
9977  CheckCast(value);
9978 #endif
9979  return static_cast<NumberObject*>(value);
9980 }
9981 
9982 
9983 BooleanObject* BooleanObject::Cast(v8::Value* value) {
9984 #ifdef V8_ENABLE_CHECKS
9985  CheckCast(value);
9986 #endif
9987  return static_cast<BooleanObject*>(value);
9988 }
9989 
9990 
9991 RegExp* RegExp::Cast(v8::Value* value) {
9992 #ifdef V8_ENABLE_CHECKS
9993  CheckCast(value);
9994 #endif
9995  return static_cast<RegExp*>(value);
9996 }
9997 
9998 
9999 Object* Object::Cast(v8::Value* value) {
10000 #ifdef V8_ENABLE_CHECKS
10001  CheckCast(value);
10002 #endif
10003  return static_cast<Object*>(value);
10004 }
10005 
10006 
10007 Array* Array::Cast(v8::Value* value) {
10008 #ifdef V8_ENABLE_CHECKS
10009  CheckCast(value);
10010 #endif
10011  return static_cast<Array*>(value);
10012 }
10013 
10014 
10015 Map* Map::Cast(v8::Value* value) {
10016 #ifdef V8_ENABLE_CHECKS
10017  CheckCast(value);
10018 #endif
10019  return static_cast<Map*>(value);
10020 }
10021 
10022 
10023 Set* Set::Cast(v8::Value* value) {
10024 #ifdef V8_ENABLE_CHECKS
10025  CheckCast(value);
10026 #endif
10027  return static_cast<Set*>(value);
10028 }
10029 
10030 
10031 Promise* Promise::Cast(v8::Value* value) {
10032 #ifdef V8_ENABLE_CHECKS
10033  CheckCast(value);
10034 #endif
10035  return static_cast<Promise*>(value);
10036 }
10037 
10038 
10039 Proxy* Proxy::Cast(v8::Value* value) {
10040 #ifdef V8_ENABLE_CHECKS
10041  CheckCast(value);
10042 #endif
10043  return static_cast<Proxy*>(value);
10044 }
10045 
10046 WasmCompiledModule* WasmCompiledModule::Cast(v8::Value* value) {
10047 #ifdef V8_ENABLE_CHECKS
10048  CheckCast(value);
10049 #endif
10050  return static_cast<WasmCompiledModule*>(value);
10051 }
10052 
10053 Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
10054 #ifdef V8_ENABLE_CHECKS
10055  CheckCast(value);
10056 #endif
10057  return static_cast<Promise::Resolver*>(value);
10058 }
10059 
10060 
10061 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
10062 #ifdef V8_ENABLE_CHECKS
10063  CheckCast(value);
10064 #endif
10065  return static_cast<ArrayBuffer*>(value);
10066 }
10067 
10068 
10069 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
10070 #ifdef V8_ENABLE_CHECKS
10071  CheckCast(value);
10072 #endif
10073  return static_cast<ArrayBufferView*>(value);
10074 }
10075 
10076 
10077 TypedArray* TypedArray::Cast(v8::Value* value) {
10078 #ifdef V8_ENABLE_CHECKS
10079  CheckCast(value);
10080 #endif
10081  return static_cast<TypedArray*>(value);
10082 }
10083 
10084 
10085 Uint8Array* Uint8Array::Cast(v8::Value* value) {
10086 #ifdef V8_ENABLE_CHECKS
10087  CheckCast(value);
10088 #endif
10089  return static_cast<Uint8Array*>(value);
10090 }
10091 
10092 
10093 Int8Array* Int8Array::Cast(v8::Value* value) {
10094 #ifdef V8_ENABLE_CHECKS
10095  CheckCast(value);
10096 #endif
10097  return static_cast<Int8Array*>(value);
10098 }
10099 
10100 
10101 Uint16Array* Uint16Array::Cast(v8::Value* value) {
10102 #ifdef V8_ENABLE_CHECKS
10103  CheckCast(value);
10104 #endif
10105  return static_cast<Uint16Array*>(value);
10106 }
10107 
10108 
10109 Int16Array* Int16Array::Cast(v8::Value* value) {
10110 #ifdef V8_ENABLE_CHECKS
10111  CheckCast(value);
10112 #endif
10113  return static_cast<Int16Array*>(value);
10114 }
10115 
10116 
10117 Uint32Array* Uint32Array::Cast(v8::Value* value) {
10118 #ifdef V8_ENABLE_CHECKS
10119  CheckCast(value);
10120 #endif
10121  return static_cast<Uint32Array*>(value);
10122 }
10123 
10124 
10125 Int32Array* Int32Array::Cast(v8::Value* value) {
10126 #ifdef V8_ENABLE_CHECKS
10127  CheckCast(value);
10128 #endif
10129  return static_cast<Int32Array*>(value);
10130 }
10131 
10132 
10133 Float32Array* Float32Array::Cast(v8::Value* value) {
10134 #ifdef V8_ENABLE_CHECKS
10135  CheckCast(value);
10136 #endif
10137  return static_cast<Float32Array*>(value);
10138 }
10139 
10140 
10141 Float64Array* Float64Array::Cast(v8::Value* value) {
10142 #ifdef V8_ENABLE_CHECKS
10143  CheckCast(value);
10144 #endif
10145  return static_cast<Float64Array*>(value);
10146 }
10147 
10148 
10149 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
10150 #ifdef V8_ENABLE_CHECKS
10151  CheckCast(value);
10152 #endif
10153  return static_cast<Uint8ClampedArray*>(value);
10154 }
10155 
10156 
10157 DataView* DataView::Cast(v8::Value* value) {
10158 #ifdef V8_ENABLE_CHECKS
10159  CheckCast(value);
10160 #endif
10161  return static_cast<DataView*>(value);
10162 }
10163 
10164 
10165 SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
10166 #ifdef V8_ENABLE_CHECKS
10167  CheckCast(value);
10168 #endif
10169  return static_cast<SharedArrayBuffer*>(value);
10170 }
10171 
10172 
10173 Function* Function::Cast(v8::Value* value) {
10174 #ifdef V8_ENABLE_CHECKS
10175  CheckCast(value);
10176 #endif
10177  return static_cast<Function*>(value);
10178 }
10179 
10180 
10181 External* External::Cast(v8::Value* value) {
10182 #ifdef V8_ENABLE_CHECKS
10183  CheckCast(value);
10184 #endif
10185  return static_cast<External*>(value);
10186 }
10187 
10188 
10189 template<typename T>
10191  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
10192 }
10193 
10194 
10195 template<typename T>
10197  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
10198 }
10199 
10200 
10201 template<typename T>
10203  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
10204 }
10205 
10206 
10207 template<typename T>
10209  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
10210 }
10211 
10212 
10213 template<typename T>
10215  return ReturnValue<T>(&args_[kReturnValueIndex]);
10216 }
10217 
10218 template <typename T>
10220  typedef internal::Internals I;
10221  return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(0);
10222 }
10223 
10224 
10225 Local<Primitive> Undefined(Isolate* isolate) {
10226  typedef internal::Object* S;
10227  typedef internal::Internals I;
10228  I::CheckInitialized(isolate);
10229  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
10230  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10231 }
10232 
10233 
10234 Local<Primitive> Null(Isolate* isolate) {
10235  typedef internal::Object* S;
10236  typedef internal::Internals I;
10237  I::CheckInitialized(isolate);
10238  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
10239  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
10240 }
10241 
10242 
10243 Local<Boolean> True(Isolate* isolate) {
10244  typedef internal::Object* S;
10245  typedef internal::Internals I;
10246  I::CheckInitialized(isolate);
10247<