v8  6.2.414(node8.16.0)
V8 is Google's open source JavaScript engine
v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "v8-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 Private;
108 class Uint32;
109 class Utils;
110 class Value;
111 class WasmCompiledModule;
112 template <class T> class Local;
113 template <class T>
115 template <class T> class Eternal;
116 template<class T> class NonCopyablePersistentTraits;
117 template<class T> class PersistentBase;
118 template <class T, class M = NonCopyablePersistentTraits<T> >
120 template <class T>
121 class Global;
122 template<class K, class V, class T> class PersistentValueMap;
123 template <class K, class V, class T>
125 template <class K, class V, class T>
126 class GlobalValueMap;
127 template<class V, class T> class PersistentValueVector;
128 template<class T, class P> class WeakCallbackObject;
129 class FunctionTemplate;
130 class ObjectTemplate;
131 template<typename T> class FunctionCallbackInfo;
132 template<typename T> class PropertyCallbackInfo;
133 class StackTrace;
134 class StackFrame;
135 class Isolate;
136 class CallHandlerHelper;
138 template<typename T> class ReturnValue;
139 
140 namespace internal {
141 class Arguments;
142 class DeferredHandles;
143 class Heap;
144 class HeapObject;
145 class Isolate;
146 class Object;
147 struct StreamedSource;
148 template<typename T> class CustomArguments;
149 class PropertyCallbackArguments;
150 class FunctionCallbackArguments;
151 class GlobalHandles;
152 } // namespace internal
153 
154 namespace debug {
155 class ConsoleCallArguments;
156 } // namespace debug
157 
158 // --- Handles ---
159 
160 #define TYPE_CHECK(T, S) \
161  while (false) { \
162  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
163  }
164 
196 template <class T>
197 class Local {
198  public:
199  V8_INLINE Local() : val_(0) {}
200  template <class S>
202  : val_(reinterpret_cast<T*>(*that)) {
208  TYPE_CHECK(T, S);
209  }
210 
214  V8_INLINE bool IsEmpty() const { return val_ == 0; }
215 
219  V8_INLINE void Clear() { val_ = 0; }
220 
221  V8_INLINE T* operator->() const { return val_; }
222 
223  V8_INLINE T* operator*() const { return val_; }
224 
231  template <class S>
232  V8_INLINE bool operator==(const Local<S>& that) const {
233  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
234  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
235  if (a == 0) return b == 0;
236  if (b == 0) return false;
237  return *a == *b;
238  }
239 
240  template <class S> V8_INLINE bool operator==(
241  const PersistentBase<S>& that) const {
242  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
243  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
244  if (a == 0) return b == 0;
245  if (b == 0) return false;
246  return *a == *b;
247  }
248 
255  template <class S>
256  V8_INLINE bool operator!=(const Local<S>& that) const {
257  return !operator==(that);
258  }
259 
260  template <class S> V8_INLINE bool operator!=(
261  const Persistent<S>& that) const {
262  return !operator==(that);
263  }
264 
270  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
271 #ifdef V8_ENABLE_CHECKS
272  // If we're going to perform the type check then we have to check
273  // that the handle isn't empty before doing the checked cast.
274  if (that.IsEmpty()) return Local<T>();
275 #endif
276  return Local<T>(T::Cast(*that));
277  }
278 
284  template <class S>
286  return Local<S>::Cast(*this);
287  }
288 
294  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
295  V8_INLINE static Local<T> New(Isolate* isolate,
296  const PersistentBase<T>& that);
297 
298  private:
299  friend class Utils;
300  template<class F> friend class Eternal;
301  template<class F> friend class PersistentBase;
302  template<class F, class M> friend class Persistent;
303  template<class F> friend class Local;
304  template <class F>
305  friend class MaybeLocal;
306  template<class F> friend class FunctionCallbackInfo;
307  template<class F> friend class PropertyCallbackInfo;
308  friend class String;
309  friend class Object;
310  friend class Context;
311  friend class Private;
312  template<class F> friend class internal::CustomArguments;
313  friend Local<Primitive> Undefined(Isolate* isolate);
314  friend Local<Primitive> Null(Isolate* isolate);
315  friend Local<Boolean> True(Isolate* isolate);
316  friend Local<Boolean> False(Isolate* isolate);
317  friend class HandleScope;
318  friend class EscapableHandleScope;
319  template <class F1, class F2, class F3>
321  template<class F1, class F2> friend class PersistentValueVector;
322  template <class F>
323  friend class ReturnValue;
324 
325  explicit V8_INLINE Local(T* that) : val_(that) {}
326  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
327  T* val_;
328 };
329 
330 
331 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
332 // Handle is an alias for Local for historical reasons.
333 template <class T>
334 using Handle = Local<T>;
335 #endif
336 
337 
348 template <class T>
349 class MaybeLocal {
350  public:
351  V8_INLINE MaybeLocal() : val_(nullptr) {}
352  template <class S>
354  : val_(reinterpret_cast<T*>(*that)) {
355  TYPE_CHECK(T, S);
356  }
357 
358  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
359 
364  template <class S>
366  out->val_ = IsEmpty() ? nullptr : this->val_;
367  return !IsEmpty();
368  }
369 
375 
380  template <class S>
381  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
382  return IsEmpty() ? default_value : Local<S>(val_);
383  }
384 
385  private:
386  T* val_;
387 };
388 
393 template <class T> class Eternal {
394  public:
395  V8_INLINE Eternal() : val_(nullptr) {}
396  template <class S>
397  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
398  Set(isolate, handle);
399  }
400  // Can only be safely called if already set.
401  V8_INLINE Local<T> Get(Isolate* isolate) const;
402  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
403  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
404 
405  private:
406  T* val_;
407 };
408 
409 
410 static const int kInternalFieldsInWeakCallback = 2;
411 static const int kEmbedderFieldsInWeakCallback = 2;
412 
413 template <typename T>
415  public:
416  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
417 
418  WeakCallbackInfo(Isolate* isolate, T* parameter,
419  void* embedder_fields[kEmbedderFieldsInWeakCallback],
420  Callback* callback)
421  : isolate_(isolate), parameter_(parameter), callback_(callback) {
422  for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
423  embedder_fields_[i] = embedder_fields[i];
424  }
425  }
426 
427  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
428  V8_INLINE T* GetParameter() const { return parameter_; }
429  V8_INLINE void* GetInternalField(int index) const;
430 
431  V8_INLINE V8_DEPRECATED("use indexed version",
432  void* GetInternalField1() const) {
433  return embedder_fields_[0];
434  }
435  V8_INLINE V8_DEPRECATED("use indexed version",
436  void* GetInternalField2() const) {
437  return embedder_fields_[1];
438  }
439 
440  V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.",
441  bool IsFirstPass() const) {
442  return callback_ != nullptr;
443  }
444 
445  // When first called, the embedder MUST Reset() the Global which triggered the
446  // callback. The Global itself is unusable for anything else. No v8 other api
447  // calls may be called in the first callback. Should additional work be
448  // required, the embedder must set a second pass callback, which will be
449  // called after all the initial callbacks are processed.
450  // Calling SetSecondPassCallback on the second pass will immediately crash.
451  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
452 
453  private:
454  Isolate* isolate_;
455  T* parameter_;
456  Callback* callback_;
457  void* embedder_fields_[kEmbedderFieldsInWeakCallback];
458 };
459 
460 
461 // kParameter will pass a void* parameter back to the callback, kInternalFields
462 // will pass the first two internal fields back to the callback, kFinalizer
463 // will pass a void* parameter back, but is invoked before the object is
464 // actually collected, so it can be resurrected. In the last case, it is not
465 // possible to request a second pass callback.
467 
481 template <class T> class PersistentBase {
482  public:
487  V8_INLINE void Reset();
492  template <class S>
493  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
494 
499  template <class S>
500  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
501 
502  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
503  V8_INLINE void Empty() { val_ = 0; }
504 
505  V8_INLINE Local<T> Get(Isolate* isolate) const {
506  return Local<T>::New(isolate, *this);
507  }
508 
509  template <class S>
510  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
511  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
512  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
513  if (a == NULL) return b == NULL;
514  if (b == NULL) return false;
515  return *a == *b;
516  }
517 
518  template <class S>
519  V8_INLINE bool operator==(const Local<S>& that) const {
520  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
521  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
522  if (a == NULL) return b == NULL;
523  if (b == NULL) return false;
524  return *a == *b;
525  }
526 
527  template <class S>
528  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
529  return !operator==(that);
530  }
531 
532  template <class S>
533  V8_INLINE bool operator!=(const Local<S>& that) const {
534  return !operator==(that);
535  }
536 
544  template <typename P>
545  V8_INLINE void SetWeak(P* parameter,
546  typename WeakCallbackInfo<P>::Callback callback,
547  WeakCallbackType type);
548 
556  V8_INLINE void SetWeak();
557 
558  template<typename P>
559  V8_INLINE P* ClearWeak();
560 
561  // TODO(dcarney): remove this.
562  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
563 
569  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
570 
577  V8_INLINE void MarkIndependent();
578 
584  V8_INLINE void MarkActive();
585 
586  V8_INLINE bool IsIndependent() const;
587 
589  V8_INLINE bool IsNearDeath() const;
590 
592  V8_INLINE bool IsWeak() const;
593 
598  V8_INLINE void SetWrapperClassId(uint16_t class_id);
599 
604  V8_INLINE uint16_t WrapperClassId() const;
605 
606  PersistentBase(const PersistentBase& other) = delete; // NOLINT
607  void operator=(const PersistentBase&) = delete;
608 
609  private:
610  friend class Isolate;
611  friend class Utils;
612  template<class F> friend class Local;
613  template<class F1, class F2> friend class Persistent;
614  template <class F>
615  friend class Global;
616  template<class F> friend class PersistentBase;
617  template<class F> friend class ReturnValue;
618  template <class F1, class F2, class F3>
620  template<class F1, class F2> friend class PersistentValueVector;
621  friend class Object;
622 
623  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
624  V8_INLINE static T* New(Isolate* isolate, T* that);
625 
626  T* val_;
627 };
628 
629 
636 template<class T>
637 class NonCopyablePersistentTraits {
638  public:
640  static const bool kResetInDestructor = false;
641  template<class S, class M>
642  V8_INLINE static void Copy(const Persistent<S, M>& source,
643  NonCopyablePersistent* dest) {
644  Uncompilable<Object>();
645  }
646  // TODO(dcarney): come up with a good compile error here.
647  template<class O> V8_INLINE static void Uncompilable() {
648  TYPE_CHECK(O, Primitive);
649  }
650 };
651 
652 
657 template<class T>
660  static const bool kResetInDestructor = true;
661  template<class S, class M>
662  static V8_INLINE void Copy(const Persistent<S, M>& source,
663  CopyablePersistent* dest) {
664  // do nothing, just allow copy
665  }
666 };
667 
668 
677 template <class T, class M> class Persistent : public PersistentBase<T> {
678  public:
688  template <class S>
690  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
691  TYPE_CHECK(T, S);
692  }
698  template <class S, class M2>
700  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
701  TYPE_CHECK(T, S);
702  }
710  Copy(that);
711  }
712  template <class S, class M2>
714  Copy(that);
715  }
716  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
717  Copy(that);
718  return *this;
719  }
720  template <class S, class M2>
722  Copy(that);
723  return *this;
724  }
731  if (M::kResetInDestructor) this->Reset();
732  }
733 
734  // TODO(dcarney): this is pretty useless, fix or remove
735  template <class S>
736  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
737 #ifdef V8_ENABLE_CHECKS
738  // If we're going to perform the type check then we have to check
739  // that the handle isn't empty before doing the checked cast.
740  if (!that.IsEmpty()) T::Cast(*that);
741 #endif
742  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
743  }
744 
745  // TODO(dcarney): this is pretty useless, fix or remove
746  template <class S>
747  V8_INLINE Persistent<S>& As() const { // NOLINT
748  return Persistent<S>::Cast(*this);
749  }
750 
751  private:
752  friend class Isolate;
753  friend class Utils;
754  template<class F> friend class Local;
755  template<class F1, class F2> friend class Persistent;
756  template<class F> friend class ReturnValue;
757 
758  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
759  V8_INLINE T* operator*() const { return this->val_; }
760  template<class S, class M2>
761  V8_INLINE void Copy(const Persistent<S, M2>& that);
762 };
763 
764 
770 template <class T>
771 class Global : public PersistentBase<T> {
772  public:
776  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
782  template <class S>
784  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
785  TYPE_CHECK(T, S);
786  }
792  template <class S>
793  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
794  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
795  TYPE_CHECK(T, S);
796  }
800  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
801  other.val_ = nullptr;
802  }
803  V8_INLINE ~Global() { this->Reset(); }
807  template <class S>
808  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
809  TYPE_CHECK(T, S);
810  if (this != &rhs) {
811  this->Reset();
812  this->val_ = rhs.val_;
813  rhs.val_ = nullptr;
814  }
815  return *this;
816  }
820  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
821 
822  /*
823  * For compatibility with Chromium's base::Bind (base::Passed).
824  */
825  typedef void MoveOnlyTypeForCPP03;
826 
827  Global(const Global&) = delete;
828  void operator=(const Global&) = delete;
829 
830  private:
831  template <class F>
832  friend class ReturnValue;
833  V8_INLINE T* operator*() const { return this->val_; }
834 };
835 
836 
837 // UniquePersistent is an alias for Global for historical reason.
838 template <class T>
840 
841 
857  public:
858  explicit HandleScope(Isolate* isolate);
859 
860  ~HandleScope();
861 
865  static int NumberOfHandles(Isolate* isolate);
866 
868  return reinterpret_cast<Isolate*>(isolate_);
869  }
870 
871  HandleScope(const HandleScope&) = delete;
872  void operator=(const HandleScope&) = delete;
873 
874  protected:
876 
877  void Initialize(Isolate* isolate);
878 
879  static internal::Object** CreateHandle(internal::Isolate* isolate,
880  internal::Object* value);
881 
882  private:
883  // Declaring operator new and delete as deleted is not spec compliant.
884  // Therefore declare them private instead to disable dynamic alloc
885  void* operator new(size_t size);
886  void* operator new[](size_t size);
887  void operator delete(void*, size_t);
888  void operator delete[](void*, size_t);
889 
890  // Uses heap_object to obtain the current Isolate.
891  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
892  internal::Object* value);
893 
894  internal::Isolate* isolate_;
895  internal::Object** prev_next_;
896  internal::Object** prev_limit_;
897 
898  // Local::New uses CreateHandle with an Isolate* parameter.
899  template<class F> friend class Local;
900 
901  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
902  // a HeapObject* in their shortcuts.
903  friend class Object;
904  friend class Context;
905 };
906 
907 
913  public:
914  explicit EscapableHandleScope(Isolate* isolate);
916 
921  template <class T>
923  internal::Object** slot =
924  Escape(reinterpret_cast<internal::Object**>(*value));
925  return Local<T>(reinterpret_cast<T*>(slot));
926  }
927 
929  void operator=(const EscapableHandleScope&) = delete;
930 
931  private:
932  // Declaring operator new and delete as deleted is not spec compliant.
933  // Therefore declare them private instead to disable dynamic alloc
934  void* operator new(size_t size);
935  void* operator new[](size_t size);
936  void operator delete(void*, size_t);
937  void operator delete[](void*, size_t);
938 
939  internal::Object** Escape(internal::Object** escape_value);
940  internal::Object** escape_slot_;
941 };
942 
949  public:
950  SealHandleScope(Isolate* isolate);
951  ~SealHandleScope();
952 
953  SealHandleScope(const SealHandleScope&) = delete;
954  void operator=(const SealHandleScope&) = delete;
955 
956  private:
957  // Declaring operator new and delete as deleted is not spec compliant.
958  // Therefore declare them private instead to disable dynamic alloc
959  void* operator new(size_t size);
960  void* operator new[](size_t size);
961  void operator delete(void*, size_t);
962  void operator delete[](void*, size_t);
963 
964  internal::Isolate* const isolate_;
965  internal::Object** prev_limit_;
966  int prev_sealed_level_;
967 };
968 
969 
970 // --- Special objects ---
971 
972 
977  private:
978  Data();
979 };
980 
981 
986  public:
987  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
988  bool is_opaque = false, bool is_wasm = false,
989  bool is_module = false)
990  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
991  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
992  (is_module ? kIsModule : 0)) {}
994  : flags_(flags &
995  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
996 
997  bool IsSharedCrossOrigin() const {
998  return (flags_ & kIsSharedCrossOrigin) != 0;
999  }
1000  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1001  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
1002  bool IsModule() const { return (flags_ & kIsModule) != 0; }
1003 
1004  int Flags() const { return flags_; }
1005 
1006  private:
1007  enum {
1008  kIsSharedCrossOrigin = 1,
1009  kIsOpaque = 1 << 1,
1010  kIsWasm = 1 << 2,
1011  kIsModule = 1 << 3
1012  };
1013  const int flags_;
1014 };
1015 
1020  public:
1022  Local<Value> resource_name,
1023  Local<Integer> resource_line_offset = Local<Integer>(),
1024  Local<Integer> resource_column_offset = Local<Integer>(),
1025  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1026  Local<Integer> script_id = Local<Integer>(),
1027  Local<Value> source_map_url = Local<Value>(),
1028  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1029  Local<Boolean> is_wasm = Local<Boolean>(),
1030  Local<Boolean> is_module = Local<Boolean>());
1031 
1037  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1038 
1039  private:
1040  Local<Value> resource_name_;
1041  Local<Integer> resource_line_offset_;
1042  Local<Integer> resource_column_offset_;
1043  ScriptOriginOptions options_;
1044  Local<Integer> script_id_;
1045  Local<Value> source_map_url_;
1046 };
1047 
1052  public:
1056  Local<Script> BindToCurrentContext();
1057 
1058  int GetId();
1059  Local<Value> GetScriptName();
1060 
1064  Local<Value> GetSourceURL();
1068  Local<Value> GetSourceMappingURL();
1069 
1074  int GetLineNumber(int code_pos);
1075 
1076  static const int kNoScriptId = 0;
1077 };
1078 
1083  public:
1084  int GetLineNumber() { return line_number_; }
1085  int GetColumnNumber() { return column_number_; }
1086 
1087  Location(int line_number, int column_number)
1088  : line_number_(line_number), column_number_(column_number) {}
1089 
1090  private:
1091  int line_number_;
1092  int column_number_;
1093 };
1094 
1102  public:
1106  enum Status {
1112  kErrored
1113  };
1114 
1118  Status GetStatus() const;
1119 
1123  Local<Value> GetException() const;
1124 
1128  int GetModuleRequestsLength() const;
1129 
1134  Local<String> GetModuleRequest(int i) const;
1135 
1140  Location GetModuleRequestLocation(int i) const;
1141 
1145  int GetIdentityHash() const;
1146 
1147  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1148  Local<String> specifier,
1149  Local<Module> referrer);
1150 
1158  V8_DEPRECATED("Use Maybe<bool> version",
1159  bool Instantiate(Local<Context> context,
1160  ResolveCallback callback));
1161  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context,
1162  ResolveCallback callback);
1163 
1171 
1176  Local<Value> GetModuleNamespace();
1177 };
1178 
1184  public:
1188  static V8_DEPRECATE_SOON(
1189  "Use maybe version",
1190  Local<Script> Compile(Local<String> source,
1191  ScriptOrigin* origin = nullptr));
1193  Local<Context> context, Local<String> source,
1194  ScriptOrigin* origin = nullptr);
1195 
1196  static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
1197  Compile(Local<String> source,
1198  Local<String> file_name));
1199 
1205  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
1207 
1211  Local<UnboundScript> GetUnboundScript();
1212 };
1213 
1214 
1219  public:
1230  BufferOwned
1231  };
1232 
1234  : data(NULL),
1235  length(0),
1236  rejected(false),
1237  buffer_policy(BufferNotOwned) {}
1238 
1239  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1240  // data and guarantees that it stays alive until the CachedData object is
1241  // destroyed. If the policy is BufferOwned, the given data will be deleted
1242  // (with delete[]) when the CachedData object is destroyed.
1243  CachedData(const uint8_t* data, int length,
1244  BufferPolicy buffer_policy = BufferNotOwned);
1245  ~CachedData();
1246  // TODO(marja): Async compilation; add constructors which take a callback
1247  // which will be called when V8 no longer needs the data.
1248  const uint8_t* data;
1249  int length;
1250  bool rejected;
1252 
1253  // Prevent copying.
1254  CachedData(const CachedData&) = delete;
1255  CachedData& operator=(const CachedData&) = delete;
1256  };
1257 
1261  class Source {
1262  public:
1263  // Source takes ownership of CachedData.
1264  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1265  CachedData* cached_data = NULL);
1266  V8_INLINE Source(Local<String> source_string,
1267  CachedData* cached_data = NULL);
1268  V8_INLINE ~Source();
1269 
1270  // Ownership of the CachedData or its buffers is *not* transferred to the
1271  // caller. The CachedData object is alive as long as the Source object is
1272  // alive.
1273  V8_INLINE const CachedData* GetCachedData() const;
1274 
1275  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
1276 
1277  // Prevent copying.
1278  Source(const Source&) = delete;
1279  Source& operator=(const Source&) = delete;
1280 
1281  private:
1282  friend class ScriptCompiler;
1283 
1284  Local<String> source_string;
1285 
1286  // Origin information
1287  Local<Value> resource_name;
1288  Local<Integer> resource_line_offset;
1289  Local<Integer> resource_column_offset;
1290  ScriptOriginOptions resource_options;
1291  Local<Value> source_map_url;
1292 
1293  // Cached data from previous compilation (if a kConsume*Cache flag is
1294  // set), or hold newly generated cache data (kProduce*Cache flags) are
1295  // set when calling a compile method.
1296  CachedData* cached_data;
1297  };
1298 
1304  public:
1306 
1319  virtual size_t GetMoreData(const uint8_t** src) = 0;
1320 
1331  virtual bool SetBookmark();
1332 
1336  virtual void ResetToBookmark();
1337  };
1338 
1339 
1347  public:
1348  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1349 
1350  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1351  ~StreamedSource();
1352 
1353  // Ownership of the CachedData or its buffers is *not* transferred to the
1354  // caller. The CachedData object is alive as long as the StreamedSource
1355  // object is alive.
1356  const CachedData* GetCachedData() const;
1357 
1358  internal::StreamedSource* impl() const { return impl_; }
1359 
1360  // Prevent copying.
1361  StreamedSource(const StreamedSource&) = delete;
1362  StreamedSource& operator=(const StreamedSource&) = delete;
1363 
1364  private:
1365  internal::StreamedSource* impl_;
1366  };
1367 
1373  public:
1375  virtual void Run() = 0;
1376  };
1377 
1379  kNoCompileOptions = 0,
1383  kConsumeCodeCache
1384  };
1385 
1399  static V8_DEPRECATED("Use maybe version",
1400  Local<UnboundScript> CompileUnbound(
1401  Isolate* isolate, Source* source,
1402  CompileOptions options = kNoCompileOptions));
1403  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1404  Isolate* isolate, Source* source,
1405  CompileOptions options = kNoCompileOptions);
1406 
1418  static V8_DEPRECATED(
1419  "Use maybe version",
1420  Local<Script> Compile(Isolate* isolate, Source* source,
1421  CompileOptions options = kNoCompileOptions));
1423  Local<Context> context, Source* source,
1424  CompileOptions options = kNoCompileOptions);
1425 
1437  static ScriptStreamingTask* StartStreamingScript(
1438  Isolate* isolate, StreamedSource* source,
1439  CompileOptions options = kNoCompileOptions);
1440 
1448  static V8_DEPRECATED("Use maybe version",
1449  Local<Script> Compile(Isolate* isolate,
1450  StreamedSource* source,
1451  Local<String> full_source_string,
1452  const ScriptOrigin& origin));
1454  Local<Context> context, StreamedSource* source,
1455  Local<String> full_source_string, const ScriptOrigin& origin);
1456 
1475  static uint32_t CachedDataVersionTag();
1476 
1487  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1488  Isolate* isolate, Source* source);
1489 
1500  static V8_DEPRECATE_SOON("Use maybe version",
1501  Local<Function> CompileFunctionInContext(
1502  Isolate* isolate, Source* source,
1503  Local<Context> context, size_t arguments_count,
1504  Local<String> arguments[],
1505  size_t context_extension_count,
1506  Local<Object> context_extensions[]));
1507  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1508  Local<Context> context, Source* source, size_t arguments_count,
1509  Local<String> arguments[], size_t context_extension_count,
1510  Local<Object> context_extensions[]);
1511 
1512  private:
1513  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1514  Isolate* isolate, Source* source, CompileOptions options);
1515 };
1516 
1517 
1522  public:
1523  Local<String> Get() const;
1524 
1525  V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
1527  Local<Context> context) const;
1528 
1533  ScriptOrigin GetScriptOrigin() const;
1534 
1539  Local<Value> GetScriptResourceName() const;
1540 
1546  Local<StackTrace> GetStackTrace() const;
1547 
1551  V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
1552  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1553 
1558  int GetStartPosition() const;
1559 
1564  int GetEndPosition() const;
1565 
1569  int ErrorLevel() const;
1570 
1575  V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
1576  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1577 
1582  V8_DEPRECATED("Use maybe version", int GetEndColumn() const);
1583  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1584 
1589  bool IsSharedCrossOrigin() const;
1590  bool IsOpaque() const;
1591 
1592  // TODO(1245381): Print to a string instead of on a FILE.
1593  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1594 
1595  static const int kNoLineNumberInfo = 0;
1596  static const int kNoColumnInfo = 0;
1597  static const int kNoScriptIdInfo = 0;
1598 };
1599 
1600 
1607  public:
1615  kLineNumber = 1,
1616  kColumnOffset = 1 << 1 | kLineNumber,
1617  kScriptName = 1 << 2,
1618  kFunctionName = 1 << 3,
1619  kIsEval = 1 << 4,
1620  kIsConstructor = 1 << 5,
1621  kScriptNameOrSourceURL = 1 << 6,
1622  kScriptId = 1 << 7,
1623  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1624  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1625  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1626  };
1627 
1631  Local<StackFrame> GetFrame(uint32_t index) const;
1632 
1636  int GetFrameCount() const;
1637 
1641  V8_DEPRECATED("Use native API instead", Local<Array> AsArray());
1642 
1650  static Local<StackTrace> CurrentStackTrace(
1651  Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
1652 };
1653 
1654 
1659  public:
1666  int GetLineNumber() const;
1667 
1675  int GetColumn() const;
1676 
1683  int GetScriptId() const;
1684 
1689  Local<String> GetScriptName() const;
1690 
1697  Local<String> GetScriptNameOrSourceURL() const;
1698 
1702  Local<String> GetFunctionName() const;
1703 
1708  bool IsEval() const;
1709 
1714  bool IsConstructor() const;
1715 
1719  bool IsWasm() const;
1720 };
1721 
1722 
1723 // A StateTag represents a possible state of the VM.
1724 enum StateTag {
1733 };
1734 
1735 // A RegisterState represents the current state of registers used
1736 // by the sampling profiler API.
1738  RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
1739  void* pc; // Instruction pointer.
1740  void* sp; // Stack pointer.
1741  void* fp; // Frame pointer.
1742 };
1743 
1744 // The output structure filled up by GetStackSample API function.
1745 struct SampleInfo {
1746  size_t frames_count; // Number of frames collected.
1747  StateTag vm_state; // Current VM state.
1748  void* external_callback_entry; // External callback address if VM is
1749  // executing an external callback.
1750 };
1751 
1756  public:
1764  static V8_DEPRECATED("Use the maybe version taking context",
1765  Local<Value> Parse(Local<String> json_string));
1766  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1767  MaybeLocal<Value> Parse(Isolate* isolate,
1768  Local<String> json_string));
1770  Local<Context> context, Local<String> json_string);
1771 
1779  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1780  Local<Context> context, Local<Object> json_object,
1781  Local<String> gap = Local<String>());
1782 };
1783 
1793  public:
1795  public:
1796  virtual ~Delegate() {}
1797 
1803  virtual void ThrowDataCloneError(Local<String> message) = 0;
1804 
1810  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
1811 
1822  virtual Maybe<uint32_t> GetSharedArrayBufferId(
1823  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
1824 
1825  virtual Maybe<uint32_t> GetWasmModuleTransferId(
1826  Isolate* isolate, Local<WasmCompiledModule> module);
1836  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
1837  size_t* actual_size);
1838 
1842  virtual void FreeBufferMemory(void* buffer);
1843  };
1844 
1845  explicit ValueSerializer(Isolate* isolate);
1846  ValueSerializer(Isolate* isolate, Delegate* delegate);
1847  ~ValueSerializer();
1848 
1852  void WriteHeader();
1853 
1858  Local<Value> value);
1859 
1864  V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
1865 
1872  V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
1873 
1879  void TransferArrayBuffer(uint32_t transfer_id,
1880  Local<ArrayBuffer> array_buffer);
1881 
1885  V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
1886  void TransferSharedArrayBuffer(
1887  uint32_t transfer_id,
1888  Local<SharedArrayBuffer> shared_array_buffer));
1889 
1897  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
1898 
1904  void WriteUint32(uint32_t value);
1905  void WriteUint64(uint64_t value);
1906  void WriteDouble(double value);
1907  void WriteRawBytes(const void* source, size_t length);
1908 
1909  private:
1910  ValueSerializer(const ValueSerializer&) = delete;
1911  void operator=(const ValueSerializer&) = delete;
1912 
1913  struct PrivateData;
1914  PrivateData* private_;
1915 };
1916 
1926  public:
1928  public:
1929  virtual ~Delegate() {}
1930 
1936  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
1937 
1942  virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
1943  Isolate* isolate, uint32_t transfer_id);
1944  };
1945 
1946  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
1947  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
1948  Delegate* delegate);
1949  ~ValueDeserializer();
1950 
1955  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
1956 
1961 
1966  void TransferArrayBuffer(uint32_t transfer_id,
1967  Local<ArrayBuffer> array_buffer);
1968 
1974  void TransferSharedArrayBuffer(uint32_t id,
1975  Local<SharedArrayBuffer> shared_array_buffer);
1976 
1984  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
1985 
1989  void SetExpectInlineWasm(bool allow_inline_wasm);
1990 
1996  uint32_t GetWireFormatVersion() const;
1997 
2003  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
2004  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
2005  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
2006  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
2007 
2008  private:
2009  ValueDeserializer(const ValueDeserializer&) = delete;
2010  void operator=(const ValueDeserializer&) = delete;
2011 
2012  struct PrivateData;
2013  PrivateData* private_;
2014 };
2015 
2021 class V8_EXPORT NativeWeakMap : public Data {
2022  public:
2023  static Local<NativeWeakMap> New(Isolate* isolate);
2024  void Set(Local<Value> key, Local<Value> value);
2025  Local<Value> Get(Local<Value> key) const;
2026  bool Has(Local<Value> key);
2027  bool Delete(Local<Value> key);
2028 };
2029 
2030 
2031 // --- Value ---
2032 
2033 
2037 class V8_EXPORT Value : public Data {
2038  public:
2043  V8_INLINE bool IsUndefined() const;
2044 
2049  V8_INLINE bool IsNull() const;
2050 
2056  V8_INLINE bool IsNullOrUndefined() const;
2057 
2061  bool IsTrue() const;
2062 
2066  bool IsFalse() const;
2067 
2071  bool IsName() const;
2072 
2077  V8_INLINE bool IsString() const;
2078 
2082  bool IsSymbol() const;
2083 
2087  bool IsFunction() const;
2088 
2093  bool IsArray() const;
2094 
2098  bool IsObject() const;
2099 
2103  bool IsBoolean() const;
2104 
2108  bool IsNumber() const;
2109 
2113  bool IsExternal() const;
2114 
2118  bool IsInt32() const;
2119 
2123  bool IsUint32() const;
2124 
2128  bool IsDate() const;
2129 
2133  bool IsArgumentsObject() const;
2134 
2138  bool IsBooleanObject() const;
2139 
2143  bool IsNumberObject() const;
2144 
2148  bool IsStringObject() const;
2149 
2153  bool IsSymbolObject() const;
2154 
2158  bool IsNativeError() const;
2159 
2163  bool IsRegExp() const;
2164 
2168  bool IsAsyncFunction() const;
2169 
2173  bool IsGeneratorFunction() const;
2174 
2178  bool IsGeneratorObject() const;
2179 
2183  bool IsPromise() const;
2184 
2188  bool IsMap() const;
2189 
2193  bool IsSet() const;
2194 
2198  bool IsMapIterator() const;
2199 
2203  bool IsSetIterator() const;
2204 
2208  bool IsWeakMap() const;
2209 
2213  bool IsWeakSet() const;
2214 
2218  bool IsArrayBuffer() const;
2219 
2223  bool IsArrayBufferView() const;
2224 
2228  bool IsTypedArray() const;
2229 
2233  bool IsUint8Array() const;
2234 
2238  bool IsUint8ClampedArray() const;
2239 
2243  bool IsInt8Array() const;
2244 
2248  bool IsUint16Array() const;
2249 
2253  bool IsInt16Array() const;
2254 
2258  bool IsUint32Array() const;
2259 
2263  bool IsInt32Array() const;
2264 
2268  bool IsFloat32Array() const;
2269 
2273  bool IsFloat64Array() const;
2274 
2278  bool IsDataView() const;
2279 
2284  bool IsSharedArrayBuffer() const;
2285 
2289  bool IsProxy() const;
2290 
2291  bool IsWebAssemblyCompiledModule() const;
2292 
2294  Local<Context> context) const;
2296  Local<Context> context) const;
2298  Local<Context> context) const;
2300  Local<Context> context) const;
2302  Local<Context> context) const;
2304  Local<Context> context) const;
2306  Local<Context> context) const;
2308 
2309  V8_DEPRECATE_SOON("Use maybe version",
2310  Local<Boolean> ToBoolean(Isolate* isolate) const);
2311  V8_DEPRECATE_SOON("Use maybe version",
2312  Local<Number> ToNumber(Isolate* isolate) const);
2313  V8_DEPRECATE_SOON("Use maybe version",
2314  Local<String> ToString(Isolate* isolate) const);
2315  V8_DEPRECATED("Use maybe version",
2316  Local<String> ToDetailString(Isolate* isolate) const);
2317  V8_DEPRECATE_SOON("Use maybe version",
2318  Local<Object> ToObject(Isolate* isolate) const);
2319  V8_DEPRECATE_SOON("Use maybe version",
2320  Local<Integer> ToInteger(Isolate* isolate) const);
2321  V8_DEPRECATED("Use maybe version",
2322  Local<Uint32> ToUint32(Isolate* isolate) const);
2323  V8_DEPRECATE_SOON("Use maybe version",
2324  Local<Int32> ToInt32(Isolate* isolate) const);
2325 
2326  inline V8_DEPRECATE_SOON("Use maybe version",
2327  Local<Boolean> ToBoolean() const);
2328  inline V8_DEPRECATED("Use maybe version", Local<Number> ToNumber() const);
2329  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
2330  inline V8_DEPRECATED("Use maybe version",
2331  Local<String> ToDetailString() const);
2332  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
2333  inline V8_DEPRECATE_SOON("Use maybe version",
2334  Local<Integer> ToInteger() const);
2335  inline V8_DEPRECATED("Use maybe version", Local<Uint32> ToUint32() const);
2336  inline V8_DEPRECATED("Use maybe version", Local<Int32> ToInt32() const);
2337 
2342  V8_DEPRECATED("Use maybe version", Local<Uint32> ToArrayIndex() const);
2344  Local<Context> context) const;
2345 
2346  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2347  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2349  Local<Context> context) const;
2351  Local<Context> context) const;
2352  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2353 
2354  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2355  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2356  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2357  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2358  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2359 
2361  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2363  Local<Value> that) const;
2364  bool StrictEquals(Local<Value> that) const;
2365  bool SameValue(Local<Value> that) const;
2366 
2367  template <class T> V8_INLINE static Value* Cast(T* value);
2368 
2369  Local<String> TypeOf(Isolate*);
2370 
2371  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
2372 
2373  private:
2374  V8_INLINE bool QuickIsUndefined() const;
2375  V8_INLINE bool QuickIsNull() const;
2376  V8_INLINE bool QuickIsNullOrUndefined() const;
2377  V8_INLINE bool QuickIsString() const;
2378  bool FullIsUndefined() const;
2379  bool FullIsNull() const;
2380  bool FullIsString() const;
2381 };
2382 
2383 
2387 class V8_EXPORT Primitive : public Value { };
2388 
2389 
2394 class V8_EXPORT Boolean : public Primitive {
2395  public:
2396  bool Value() const;
2397  V8_INLINE static Boolean* Cast(v8::Value* obj);
2398  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2399 
2400  private:
2401  static void CheckCast(v8::Value* obj);
2402 };
2403 
2404 
2408 class V8_EXPORT Name : public Primitive {
2409  public:
2417  int GetIdentityHash();
2418 
2419  V8_INLINE static Name* Cast(Value* obj);
2420 
2421  private:
2422  static void CheckCast(Value* obj);
2423 };
2424 
2431 enum class NewStringType {
2435  kNormal,
2436 
2443 };
2444 
2448 class V8_EXPORT String : public Name {
2449  public:
2450  static constexpr int kMaxLength =
2451  sizeof(void*) == 4 ? (1 << 28) - 16 : (1 << 30) - 1 - 24;
2452 
2453  enum Encoding {
2454  UNKNOWN_ENCODING = 0x1,
2455  TWO_BYTE_ENCODING = 0x0,
2456  ONE_BYTE_ENCODING = 0x8
2457  };
2461  int Length() const;
2462 
2467  int Utf8Length() const;
2468 
2475  bool IsOneByte() const;
2476 
2482  bool ContainsOnlyOneByte() const;
2483 
2510  NO_OPTIONS = 0,
2511  HINT_MANY_WRITES_EXPECTED = 1,
2512  NO_NULL_TERMINATION = 2,
2513  PRESERVE_ONE_BYTE_NULL = 4,
2514  // Used by WriteUtf8 to replace orphan surrogate code units with the
2515  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2516  // output.
2517  REPLACE_INVALID_UTF8 = 8
2518  };
2519 
2520  // 16-bit character codes.
2521  int Write(uint16_t* buffer,
2522  int start = 0,
2523  int length = -1,
2524  int options = NO_OPTIONS) const;
2525  // One byte characters.
2526  int WriteOneByte(uint8_t* buffer,
2527  int start = 0,
2528  int length = -1,
2529  int options = NO_OPTIONS) const;
2530  // UTF-8 encoded characters.
2531  int WriteUtf8(char* buffer,
2532  int length = -1,
2533  int* nchars_ref = NULL,
2534  int options = NO_OPTIONS) const;
2535 
2539  V8_INLINE static Local<String> Empty(Isolate* isolate);
2540 
2544  bool IsExternal() const;
2545 
2549  bool IsExternalOneByte() const;
2550 
2552  public:
2554 
2555  virtual bool IsCompressible() const { return false; }
2556 
2557  protected:
2559 
2566  virtual void Dispose() { delete this; }
2567 
2568  // Disallow copying and assigning.
2570  void operator=(const ExternalStringResourceBase&) = delete;
2571 
2572  private:
2573  friend class internal::Heap;
2574  friend class v8::String;
2575  };
2576 
2584  : public ExternalStringResourceBase {
2585  public:
2591 
2595  virtual const uint16_t* data() const = 0;
2596 
2600  virtual size_t length() const = 0;
2601 
2602  protected:
2604  };
2605 
2617  : public ExternalStringResourceBase {
2618  public:
2625  virtual const char* data() const = 0;
2627  virtual size_t length() const = 0;
2628  protected:
2630  };
2631 
2637  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2638  Encoding* encoding_out) const;
2639 
2644  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2645 
2650  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2651 
2652  V8_INLINE static String* Cast(v8::Value* obj);
2653 
2654  // TODO(dcarney): remove with deprecation of New functions.
2656  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2657  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2658  };
2659 
2661  static V8_DEPRECATE_SOON(
2662  "Use maybe version",
2663  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2664  NewStringType type = kNormalString,
2665  int length = -1));
2666 
2669  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2670  Isolate* isolate, const char* data, v8::NewStringType type,
2671  int length = -1);
2672 
2674  static V8_DEPRECATED(
2675  "Use maybe version",
2676  Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2677  NewStringType type = kNormalString,
2678  int length = -1));
2679 
2682  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2683  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2684  int length = -1);
2685 
2687  static V8_DEPRECATE_SOON(
2688  "Use maybe version",
2689  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2690  NewStringType type = kNormalString,
2691  int length = -1));
2692 
2695  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2696  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2697  int length = -1);
2698 
2703  static Local<String> Concat(Local<String> left, Local<String> right);
2704 
2713  static V8_DEPRECATED("Use maybe version",
2714  Local<String> NewExternal(
2715  Isolate* isolate, ExternalStringResource* resource));
2716  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2717  Isolate* isolate, ExternalStringResource* resource);
2718 
2728  bool MakeExternal(ExternalStringResource* resource);
2729 
2738  static V8_DEPRECATE_SOON(
2739  "Use maybe version",
2740  Local<String> NewExternal(Isolate* isolate,
2741  ExternalOneByteStringResource* resource));
2742  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2743  Isolate* isolate, ExternalOneByteStringResource* resource);
2744 
2754  bool MakeExternal(ExternalOneByteStringResource* resource);
2755 
2759  bool CanMakeExternal();
2760 
2769  public:
2770  V8_DEPRECATE_SOON("Use Isolate version",
2771  explicit Utf8Value(Local<v8::Value> obj));
2772  Utf8Value(Isolate* isolate, Local<v8::Value> obj);
2773  ~Utf8Value();
2774  char* operator*() { return str_; }
2775  const char* operator*() const { return str_; }
2776  int length() const { return length_; }
2777 
2778  // Disallow copying and assigning.
2779  Utf8Value(const Utf8Value&) = delete;
2780  void operator=(const Utf8Value&) = delete;
2781 
2782  private:
2783  char* str_;
2784  int length_;
2785  };
2786 
2794  public:
2795  V8_DEPRECATE_SOON("Use Isolate version",
2796  explicit Value(Local<v8::Value> obj));
2797  Value(Isolate* isolate, Local<v8::Value> obj);
2798  ~Value();
2799  uint16_t* operator*() { return str_; }
2800  const uint16_t* operator*() const { return str_; }
2801  int length() const { return length_; }
2802 
2803  // Disallow copying and assigning.
2804  Value(const Value&) = delete;
2805  void operator=(const Value&) = delete;
2806 
2807  private:
2808  uint16_t* str_;
2809  int length_;
2810  };
2811 
2812  private:
2813  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2814  Encoding encoding) const;
2815  void VerifyExternalStringResource(ExternalStringResource* val) const;
2816  static void CheckCast(v8::Value* obj);
2817 };
2818 
2819 
2823 class V8_EXPORT Symbol : public Name {
2824  public:
2828  Local<Value> Name() const;
2829 
2833  static Local<Symbol> New(Isolate* isolate,
2834  Local<String> name = Local<String>());
2835 
2843  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2844 
2849  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2850 
2851  // Well-known symbols
2852  static Local<Symbol> GetHasInstance(Isolate* isolate);
2853  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
2854  static Local<Symbol> GetIterator(Isolate* isolate);
2855  static Local<Symbol> GetMatch(Isolate* isolate);
2856  static Local<Symbol> GetReplace(Isolate* isolate);
2857  static Local<Symbol> GetSearch(Isolate* isolate);
2858  static Local<Symbol> GetSplit(Isolate* isolate);
2859  static Local<Symbol> GetToPrimitive(Isolate* isolate);
2860  static Local<Symbol> GetToStringTag(Isolate* isolate);
2861  static Local<Symbol> GetUnscopables(Isolate* isolate);
2862 
2863  V8_INLINE static Symbol* Cast(Value* obj);
2864 
2865  private:
2866  Symbol();
2867  static void CheckCast(Value* obj);
2868 };
2869 
2870 
2876 class V8_EXPORT Private : public Data {
2877  public:
2881  Local<Value> Name() const;
2882 
2886  static Local<Private> New(Isolate* isolate,
2887  Local<String> name = Local<String>());
2888 
2898  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
2899 
2900  private:
2901  Private();
2902 };
2903 
2904 
2908 class V8_EXPORT Number : public Primitive {
2909  public:
2910  double Value() const;
2911  static Local<Number> New(Isolate* isolate, double value);
2912  V8_INLINE static Number* Cast(v8::Value* obj);
2913  private:
2914  Number();
2915  static void CheckCast(v8::Value* obj);
2916 };
2917 
2918 
2922 class V8_EXPORT Integer : public Number {
2923  public:
2924  static Local<Integer> New(Isolate* isolate, int32_t value);
2925  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2926  int64_t Value() const;
2927  V8_INLINE static Integer* Cast(v8::Value* obj);
2928  private:
2929  Integer();
2930  static void CheckCast(v8::Value* obj);
2931 };
2932 
2933 
2937 class V8_EXPORT Int32 : public Integer {
2938  public:
2939  int32_t Value() const;
2940  V8_INLINE static Int32* Cast(v8::Value* obj);
2941 
2942  private:
2943  Int32();
2944  static void CheckCast(v8::Value* obj);
2945 };
2946 
2947 
2951 class V8_EXPORT Uint32 : public Integer {
2952  public:
2953  uint32_t Value() const;
2954  V8_INLINE static Uint32* Cast(v8::Value* obj);
2955 
2956  private:
2957  Uint32();
2958  static void CheckCast(v8::Value* obj);
2959 };
2960 
2966  None = 0,
2968  ReadOnly = 1 << 0,
2970  DontEnum = 1 << 1,
2972  DontDelete = 1 << 2
2973 };
2974 
2980 typedef void (*AccessorGetterCallback)(
2981  Local<String> property,
2982  const PropertyCallbackInfo<Value>& info);
2984  Local<Name> property,
2985  const PropertyCallbackInfo<Value>& info);
2986 
2987 
2988 typedef void (*AccessorSetterCallback)(
2989  Local<String> property,
2990  Local<Value> value,
2991  const PropertyCallbackInfo<void>& info);
2993  Local<Name> property,
2994  Local<Value> value,
2995  const PropertyCallbackInfo<void>& info);
2996 
2997 
3008  DEFAULT = 0,
3010  ALL_CAN_WRITE = 1 << 1,
3012 };
3013 
3024 };
3025 
3034 
3040 
3045 
3049 class V8_EXPORT Object : public Value {
3050  public:
3051  V8_DEPRECATE_SOON("Use maybe version",
3052  bool Set(Local<Value> key, Local<Value> value));
3054  Local<Value> key, Local<Value> value);
3055 
3056  V8_DEPRECATE_SOON("Use maybe version",
3057  bool Set(uint32_t index, Local<Value> value));
3058  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
3059  Local<Value> value);
3060 
3061  // Implements CreateDataProperty (ECMA-262, 7.3.4).
3062  //
3063  // Defines a configurable, writable, enumerable property with the given value
3064  // on the object unless the property already exists and is not configurable
3065  // or the object is not extensible.
3066  //
3067  // Returns true on success.
3068  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3069  Local<Name> key,
3070  Local<Value> value);
3071  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
3072  uint32_t index,
3073  Local<Value> value);
3074 
3075  // Implements DefineOwnProperty.
3076  //
3077  // In general, CreateDataProperty will be faster, however, does not allow
3078  // for specifying attributes.
3079  //
3080  // Returns true on success.
3081  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
3082  Local<Context> context, Local<Name> key, Local<Value> value,
3083  PropertyAttribute attributes = None);
3084 
3085  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
3086  //
3087  // The defineProperty function is used to add an own property or
3088  // update the attributes of an existing own property of an object.
3089  //
3090  // Both data and accessor descriptors can be used.
3091  //
3092  // In general, CreateDataProperty is faster, however, does not allow
3093  // for specifying attributes or an accessor descriptor.
3094  //
3095  // The PropertyDescriptor can change when redefining a property.
3096  //
3097  // Returns true on success.
3098  V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
3099  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
3100 
3101  // Sets an own property on this object bypassing interceptors and
3102  // overriding accessors or read-only properties.
3103  //
3104  // Note that if the object has an interceptor the property will be set
3105  // locally, but since the interceptor takes precedence the local property
3106  // will only be returned if the interceptor doesn't return a value.
3107  //
3108  // Note also that this only works for named properties.
3109  V8_DEPRECATED("Use CreateDataProperty / DefineOwnProperty",
3110  Maybe<bool> ForceSet(Local<Context> context, Local<Value> key,
3111  Local<Value> value,
3112  PropertyAttribute attribs = None));
3113 
3114  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
3116  Local<Value> key);
3117 
3118  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
3120  uint32_t index);
3121 
3127  V8_DEPRECATED("Use maybe version",
3128  PropertyAttribute GetPropertyAttributes(Local<Value> key));
3129  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
3130  Local<Context> context, Local<Value> key);
3131 
3135  V8_DEPRECATED("Use maybe version",
3136  Local<Value> GetOwnPropertyDescriptor(Local<Name> key));
3137  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
3138  Local<Context> context, Local<Name> key);
3139 
3140  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
3157  Local<Value> key);
3158 
3159  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3161  Local<Value> key);
3162 
3163  V8_DEPRECATED("Use maybe version", bool Has(uint32_t index));
3165  uint32_t index);
3166 
3167  V8_DEPRECATED("Use maybe version", bool Delete(uint32_t index));
3169  uint32_t index);
3170 
3171  V8_DEPRECATED("Use maybe version",
3172  bool SetAccessor(Local<String> name,
3173  AccessorGetterCallback getter,
3174  AccessorSetterCallback setter = 0,
3175  Local<Value> data = Local<Value>(),
3176  AccessControl settings = DEFAULT,
3177  PropertyAttribute attribute = None));
3178  V8_DEPRECATED("Use maybe version",
3179  bool SetAccessor(Local<Name> name,
3181  AccessorNameSetterCallback setter = 0,
3182  Local<Value> data = Local<Value>(),
3183  AccessControl settings = DEFAULT,
3184  PropertyAttribute attribute = None));
3185  V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(Local<Context> context,
3186  Local<Name> name,
3188  AccessorNameSetterCallback setter = 0,
3190  AccessControl settings = DEFAULT,
3191  PropertyAttribute attribute = None);
3192 
3193  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3194  Local<Function> setter = Local<Function>(),
3195  PropertyAttribute attribute = None,
3196  AccessControl settings = DEFAULT);
3197 
3202  V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
3203  Local<Context> context, Local<Name> name,
3205  AccessorNameSetterCallback setter = nullptr,
3206  Local<Value> data = Local<Value>(), PropertyAttribute attributes = None);
3207 
3214  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3215  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3216  Local<Value> value);
3217  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3218  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3219 
3226  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3227  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3228  Local<Context> context);
3229  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
3230  Local<Context> context, KeyCollectionMode mode,
3231  PropertyFilter property_filter, IndexFilter index_filter);
3232 
3238  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3239  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3240  Local<Context> context);
3241 
3248  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
3249  Local<Context> context, PropertyFilter filter);
3250 
3256  Local<Value> GetPrototype();
3257 
3263  V8_DEPRECATED("Use maybe version", bool SetPrototype(Local<Value> prototype));
3264  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3265  Local<Value> prototype);
3266 
3271  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
3272 
3278  V8_DEPRECATED("Use maybe version", Local<String> ObjectProtoToString());
3279  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
3280  Local<Context> context);
3281 
3285  Local<String> GetConstructorName();
3286 
3290  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3291 
3293  int InternalFieldCount();
3294 
3297  const PersistentBase<Object>& object) {
3298  return object.val_->InternalFieldCount();
3299  }
3300 
3302  V8_INLINE Local<Value> GetInternalField(int index);
3303 
3305  void SetInternalField(int index, Local<Value> value);
3306 
3312  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
3313 
3316  const PersistentBase<Object>& object, int index) {
3317  return object.val_->GetAlignedPointerFromInternalField(index);
3318  }
3319 
3325  void SetAlignedPointerInInternalField(int index, void* value);
3326  void SetAlignedPointerInInternalFields(int argc, int indices[],
3327  void* values[]);
3328 
3329  // Testers for local properties.
3330  V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
3331 
3337  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3338  Local<Name> key);
3339  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3340  uint32_t index);
3341  V8_DEPRECATE_SOON("Use maybe version",
3342  bool HasRealNamedProperty(Local<String> key));
3356  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3357  Local<Name> key);
3358  V8_DEPRECATE_SOON("Use maybe version",
3359  bool HasRealIndexedProperty(uint32_t index));
3360  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
3361  Local<Context> context, uint32_t index);
3362  V8_DEPRECATE_SOON("Use maybe version",
3363  bool HasRealNamedCallbackProperty(Local<String> key));
3364  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
3365  Local<Context> context, Local<Name> key);
3366 
3371  V8_DEPRECATED(
3372  "Use maybe version",
3373  Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
3374  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
3375  Local<Context> context, Local<Name> key);
3376 
3382  V8_DEPRECATED(
3383  "Use maybe version",
3384  Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
3385  Local<String> key));
3387  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
3388  Local<Name> key);
3389 
3395  V8_DEPRECATED("Use maybe version",
3396  Local<Value> GetRealNamedProperty(Local<String> key));
3397  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
3398  Local<Context> context, Local<Name> key);
3399 
3405  V8_DEPRECATED("Use maybe version",
3406  Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3407  Local<String> key));
3408  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3409  Local<Context> context, Local<Name> key);
3410 
3412  bool HasNamedLookupInterceptor();
3413 
3415  bool HasIndexedLookupInterceptor();
3416 
3424  int GetIdentityHash();
3425 
3430  // TODO(dcarney): take an isolate and optionally bail out?
3431  Local<Object> Clone();
3432 
3436  Local<Context> CreationContext();
3437 
3440  const PersistentBase<Object>& object) {
3441  return object.val_->CreationContext();
3442  }
3443 
3449  bool IsCallable();
3450 
3454  bool IsConstructor();
3455 
3460  V8_DEPRECATED("Use maybe version",
3461  Local<Value> CallAsFunction(Local<Value> recv, int argc,
3462  Local<Value> argv[]));
3464  Local<Value> recv,
3465  int argc,
3466  Local<Value> argv[]);
3467 
3473  V8_DEPRECATED("Use maybe version",
3474  Local<Value> CallAsConstructor(int argc, Local<Value> argv[]));
3475  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
3476  Local<Context> context, int argc, Local<Value> argv[]);
3477 
3481  V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
3482 
3483  static Local<Object> New(Isolate* isolate);
3484 
3485  V8_INLINE static Object* Cast(Value* obj);
3486 
3487  private:
3488  Object();
3489  static void CheckCast(Value* obj);
3490  Local<Value> SlowGetInternalField(int index);
3491  void* SlowGetAlignedPointerFromInternalField(int index);
3492 };
3493 
3494 
3498 class V8_EXPORT Array : public Object {
3499  public:
3500  uint32_t Length() const;
3501 
3506  V8_DEPRECATED("Cloning is not supported.",
3507  Local<Object> CloneElementAt(uint32_t index));
3508  V8_DEPRECATED("Cloning is not supported.",
3509  MaybeLocal<Object> CloneElementAt(Local<Context> context,
3510  uint32_t index));
3511 
3516  static Local<Array> New(Isolate* isolate, int length = 0);
3517 
3518  V8_INLINE static Array* Cast(Value* obj);
3519  private:
3520  Array();
3521  static void CheckCast(Value* obj);
3522 };
3523 
3524 
3528 class V8_EXPORT Map : public Object {
3529  public:
3530  size_t Size() const;
3531  void Clear();
3533  Local<Value> key);
3535  Local<Value> key,
3536  Local<Value> value);
3538  Local<Value> key);
3540  Local<Value> key);
3541 
3546  Local<Array> AsArray() const;
3547 
3551  static Local<Map> New(Isolate* isolate);
3552 
3553  V8_INLINE static Map* Cast(Value* obj);
3554 
3555  private:
3556  Map();
3557  static void CheckCast(Value* obj);
3558 };
3559 
3560 
3564 class V8_EXPORT Set : public Object {
3565  public:
3566  size_t Size() const;
3567  void Clear();
3569  Local<Value> key);
3571  Local<Value> key);
3573  Local<Value> key);
3574 
3578  Local<Array> AsArray() const;
3579 
3583  static Local<Set> New(Isolate* isolate);
3584 
3585  V8_INLINE static Set* Cast(Value* obj);
3586 
3587  private:
3588  Set();
3589  static void CheckCast(Value* obj);
3590 };
3591 
3592 
3593 template<typename T>
3594 class ReturnValue {
3595  public:
3596  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3597  : value_(that.value_) {
3598  TYPE_CHECK(T, S);
3599  }
3600  // Local setters
3601  template <typename S>
3602  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3603  void Set(const Persistent<S>& handle));
3604  template <typename S>
3605  V8_INLINE void Set(const Global<S>& handle);
3606  template <typename S>
3607  V8_INLINE void Set(const Local<S> handle);
3608  // Fast primitive setters
3609  V8_INLINE void Set(bool value);
3610  V8_INLINE void Set(double i);
3611  V8_INLINE void Set(int32_t i);
3612  V8_INLINE void Set(uint32_t i);
3613  // Fast JS primitive setters
3614  V8_INLINE void SetNull();
3615  V8_INLINE void SetUndefined();
3616  V8_INLINE void SetEmptyString();
3617  // Convenience getter for Isolate
3618  V8_INLINE Isolate* GetIsolate() const;
3619 
3620  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3621  template <typename S>
3622  V8_INLINE void Set(S* whatever);
3623 
3624  // Getter. Creates a new Local<> so it comes with a certain performance
3625  // hit. If the ReturnValue was not yet set, this will return the undefined
3626  // value.
3627  V8_INLINE Local<Value> Get() const;
3628 
3629  private:
3630  template<class F> friend class ReturnValue;
3631  template<class F> friend class FunctionCallbackInfo;
3632  template<class F> friend class PropertyCallbackInfo;
3633  template <class F, class G, class H>
3635  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3636  V8_INLINE internal::Object* GetDefaultValue();
3637  V8_INLINE explicit ReturnValue(internal::Object** slot);
3638  internal::Object** value_;
3639 };
3640 
3641 
3648 template<typename T>
3649 class FunctionCallbackInfo {
3650  public:
3652  V8_INLINE int Length() const;
3654  V8_INLINE Local<Value> operator[](int i) const;
3655  V8_INLINE V8_DEPRECATED("Use Data() to explicitly pass Callee instead",
3656  Local<Function> Callee() const);
3658  V8_INLINE Local<Object> This() const;
3669  V8_INLINE Local<Object> Holder() const;
3671  V8_INLINE Local<Value> NewTarget() const;
3673  V8_INLINE bool IsConstructCall() const;
3675  V8_INLINE Local<Value> Data() const;
3677  V8_INLINE Isolate* GetIsolate() const;
3679  V8_INLINE ReturnValue<T> GetReturnValue() const;
3680  // This shouldn't be public, but the arm compiler needs it.
3681  static const int kArgsLength = 8;
3682 
3683  protected:
3687  static const int kHolderIndex = 0;
3688  static const int kIsolateIndex = 1;
3689  static const int kReturnValueDefaultValueIndex = 2;
3690  static const int kReturnValueIndex = 3;
3691  static const int kDataIndex = 4;
3692  static const int kCalleeIndex = 5;
3693  static const int kContextSaveIndex = 6;
3694  static const int kNewTargetIndex = 7;
3695 
3696  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3697  internal::Object** values, int length);
3698  internal::Object** implicit_args_;
3699  internal::Object** values_;
3700  int length_;
3701 };
3702 
3703 
3708 template<typename T>
3709 class PropertyCallbackInfo {
3710  public:
3714  V8_INLINE Isolate* GetIsolate() const;
3715 
3721  V8_INLINE Local<Value> Data() const;
3722 
3764  V8_INLINE Local<Object> This() const;
3765 
3775  V8_INLINE Local<Object> Holder() const;
3776 
3786 
3794  V8_INLINE bool ShouldThrowOnError() const;
3795 
3796  // This shouldn't be public, but the arm compiler needs it.
3797  static const int kArgsLength = 7;
3798 
3799  protected:
3800  friend class MacroAssembler;
3801  friend class internal::PropertyCallbackArguments;
3803  static const int kShouldThrowOnErrorIndex = 0;
3804  static const int kHolderIndex = 1;
3805  static const int kIsolateIndex = 2;
3806  static const int kReturnValueDefaultValueIndex = 3;
3807  static const int kReturnValueIndex = 4;
3808  static const int kDataIndex = 5;
3809  static const int kThisIndex = 6;
3810 
3811  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
3812  internal::Object** args_;
3813 };
3814 
3815 
3816 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3817 
3819 
3823 class V8_EXPORT Function : public Object {
3824  public:
3829  static MaybeLocal<Function> New(
3830  Local<Context> context, FunctionCallback callback,
3831  Local<Value> data = Local<Value>(), int length = 0,
3833  static V8_DEPRECATE_SOON(
3834  "Use maybe version",
3835  Local<Function> New(Isolate* isolate, FunctionCallback callback,
3836  Local<Value> data = Local<Value>(), int length = 0));
3837 
3838  V8_DEPRECATED("Use maybe version",
3839  Local<Object> NewInstance(int argc, Local<Value> argv[]) const);
3841  Local<Context> context, int argc, Local<Value> argv[]) const;
3842 
3843  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
3845  Local<Context> context) const {
3846  return NewInstance(context, 0, nullptr);
3847  }
3848 
3849  V8_DEPRECATE_SOON("Use maybe version",
3850  Local<Value> Call(Local<Value> recv, int argc,
3851  Local<Value> argv[]));
3853  Local<Value> recv, int argc,
3854  Local<Value> argv[]);
3855 
3856  void SetName(Local<String> name);
3857  Local<Value> GetName() const;
3858 
3865  Local<Value> GetInferredName() const;
3866 
3871  Local<Value> GetDebugName() const;
3872 
3877  Local<Value> GetDisplayName() const;
3878 
3883  int GetScriptLineNumber() const;
3888  int GetScriptColumnNumber() const;
3889 
3893  V8_DEPRECATED("this should no longer be used.", bool IsBuiltin() const);
3894 
3898  int ScriptId() const;
3899 
3904  Local<Value> GetBoundFunction() const;
3905 
3906  ScriptOrigin GetScriptOrigin() const;
3907  V8_INLINE static Function* Cast(Value* obj);
3908  static const int kLineOffsetNotFound;
3909 
3910  private:
3911  Function();
3912  static void CheckCast(Value* obj);
3913 };
3914 
3915 #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
3916 // The number of required internal fields can be defined by embedder.
3917 #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
3918 #endif
3919 
3923 class V8_EXPORT Promise : public Object {
3924  public:
3929  enum PromiseState { kPending, kFulfilled, kRejected };
3930 
3931  class V8_EXPORT Resolver : public Object {
3932  public:
3936  static V8_DEPRECATE_SOON("Use maybe version",
3937  Local<Resolver> New(Isolate* isolate));
3939  Local<Context> context);
3940 
3944  Local<Promise> GetPromise();
3945 
3950  V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
3952  Local<Value> value);
3953 
3954  V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
3956  Local<Value> value);
3957 
3958  V8_INLINE static Resolver* Cast(Value* obj);
3959 
3960  private:
3961  Resolver();
3962  static void CheckCast(Value* obj);
3963  };
3964 
3971  V8_DEPRECATED("Use maybe version",
3972  Local<Promise> Catch(Local<Function> handler));
3974  Local<Function> handler);
3975 
3976  V8_DEPRECATED("Use maybe version",
3977  Local<Promise> Then(Local<Function> handler));
3979  Local<Function> handler);
3980 
3985  bool HasHandler();
3986 
3991  Local<Value> Result();
3992 
3996  PromiseState State();
3997 
3998  V8_INLINE static Promise* Cast(Value* obj);
3999 
4000  static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
4001 
4002  private:
4003  Promise();
4004  static void CheckCast(Value* obj);
4005 };
4006 
4036  public:
4037  // GenericDescriptor
4039 
4040  // DataDescriptor
4042 
4043  // DataDescriptor with writable property
4044  PropertyDescriptor(Local<Value> value, bool writable);
4045 
4046  // AccessorDescriptor
4048 
4049  ~PropertyDescriptor();
4050 
4051  Local<Value> value() const;
4052  bool has_value() const;
4053 
4054  Local<Value> get() const;
4055  bool has_get() const;
4056  Local<Value> set() const;
4057  bool has_set() const;
4058 
4059  void set_enumerable(bool enumerable);
4060  bool enumerable() const;
4061  bool has_enumerable() const;
4062 
4063  void set_configurable(bool configurable);
4064  bool configurable() const;
4065  bool has_configurable() const;
4066 
4067  bool writable() const;
4068  bool has_writable() const;
4069 
4070  struct PrivateData;
4071  PrivateData* get_private() const { return private_; }
4072 
4073  PropertyDescriptor(const PropertyDescriptor&) = delete;
4074  void operator=(const PropertyDescriptor&) = delete;
4075 
4076  private:
4077  PrivateData* private_;
4078 };
4079 
4084 class V8_EXPORT Proxy : public Object {
4085  public:
4086  Local<Object> GetTarget();
4087  Local<Value> GetHandler();
4088  bool IsRevoked();
4089  void Revoke();
4090 
4094  static MaybeLocal<Proxy> New(Local<Context> context,
4095  Local<Object> local_target,
4096  Local<Object> local_handler);
4097 
4098  V8_INLINE static Proxy* Cast(Value* obj);
4099 
4100  private:
4101  Proxy();
4102  static void CheckCast(Value* obj);
4103 };
4104 
4105 // TODO(mtrofin): rename WasmCompiledModule to WasmModuleObject, for
4106 // consistency with internal APIs.
4108  public:
4109  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
4110  // A buffer that is owned by the caller.
4111  typedef std::pair<const uint8_t*, size_t> CallerOwnedBuffer;
4112 
4113  // An opaque, native heap object for transferring wasm modules. It
4114  // supports move semantics, and does not support copy semantics.
4115  class TransferrableModule final {
4116  public:
4117  TransferrableModule(TransferrableModule&& src) = default;
4118  TransferrableModule(const TransferrableModule& src) = delete;
4119 
4120  TransferrableModule& operator=(TransferrableModule&& src) = default;
4121  TransferrableModule& operator=(const TransferrableModule& src) = delete;
4122 
4123  private:
4124  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
4125  friend class WasmCompiledModule;
4126  TransferrableModule(OwnedBuffer&& code, OwnedBuffer&& bytes)
4127  : compiled_code(std::move(code)), wire_bytes(std::move(bytes)) {}
4128 
4129  OwnedBuffer compiled_code = {nullptr, 0};
4130  OwnedBuffer wire_bytes = {nullptr, 0};
4131  };
4132 
4133  // Get an in-memory, non-persistable, and context-independent (meaning,
4134  // suitable for transfer to another Isolate and Context) representation
4135  // of this wasm compiled module.
4136  TransferrableModule GetTransferrableModule();
4137 
4138  // Efficiently re-create a WasmCompiledModule, without recompiling, from
4139  // a TransferrableModule.
4140  static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
4141  Isolate* isolate, const TransferrableModule&);
4142 
4143  // Get the wasm-encoded bytes that were used to compile this module.
4144  Local<String> GetWasmWireBytes();
4145 
4146  // Serialize the compiled module. The serialized data does not include the
4147  // uncompiled bytes.
4148  SerializedModule Serialize();
4149 
4150  // If possible, deserialize the module, otherwise compile it from the provided
4151  // uncompiled bytes.
4152  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
4153  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
4154  const CallerOwnedBuffer& wire_bytes);
4155  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
4156 
4157  private:
4158  // TODO(ahaas): please remove the friend once streamed compilation is
4159  // implemented
4161 
4162  static MaybeLocal<WasmCompiledModule> Deserialize(
4163  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
4164  const CallerOwnedBuffer& wire_bytes);
4165  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
4166  const uint8_t* start,
4167  size_t length);
4168  static CallerOwnedBuffer AsCallerOwned(
4169  const TransferrableModule::OwnedBuffer& buff) {
4170  return {buff.first.get(), buff.second};
4171  }
4172 
4173  WasmCompiledModule();
4174  static void CheckCast(Value* obj);
4175 };
4176 
4177 // TODO(mtrofin): when streaming compilation is done, we can rename this
4178 // to simply WasmModuleObjectBuilder
4180  public:
4182  // The buffer passed into OnBytesReceived is owned by the caller.
4183  void OnBytesReceived(const uint8_t*, size_t size);
4184  void Finish();
4185  void Abort(Local<Value> exception);
4186  Local<Promise> GetPromise();
4187 
4189 
4190  private:
4191  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer;
4192 
4194  delete;
4196  default;
4198  const WasmModuleObjectBuilderStreaming&) = delete;
4200  WasmModuleObjectBuilderStreaming&&) = default;
4201  Isolate* isolate_ = nullptr;
4202 
4203 #if V8_CC_MSVC
4204  // We don't need the static Copy API, so the default
4205  // NonCopyablePersistentTraits would be sufficient, however,
4206  // MSVC eagerly instantiates the Copy.
4207  // We ensure we don't use Copy, however, by compiling with the
4208  // defaults everywhere else.
4210 #else
4211  Persistent<Promise> promise_;
4212 #endif
4213  std::vector<Buffer> received_buffers_;
4214  size_t total_size_ = 0;
4215 };
4216 
4218  public:
4219  WasmModuleObjectBuilder(Isolate* isolate) : isolate_(isolate) {}
4220  // The buffer passed into OnBytesReceived is owned by the caller.
4221  void OnBytesReceived(const uint8_t*, size_t size);
4223 
4224  private:
4225  Isolate* isolate_ = nullptr;
4226  // TODO(ahaas): We probably need none of this below here once streamed
4227  // compilation is implemented.
4228  typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer;
4229 
4230  // Disable copy semantics *in this implementation*. We can choose to
4231  // relax this, albeit it's not clear why.
4234  WasmModuleObjectBuilder& operator=(const WasmModuleObjectBuilder&) = delete;
4235  WasmModuleObjectBuilder& operator=(WasmModuleObjectBuilder&&) = default;
4236 
4237  std::vector<Buffer> received_buffers_;
4238  size_t total_size_ = 0;
4239 };
4240 
4241 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
4242 // The number of required internal fields can be defined by embedder.
4243 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
4244 #endif
4245 
4246 
4248 
4249 
4253 class V8_EXPORT ArrayBuffer : public Object {
4254  public:
4270  class V8_EXPORT Allocator { // NOLINT
4271  public:
4272  virtual ~Allocator() {}
4273 
4278  virtual void* Allocate(size_t length) = 0;
4279 
4284  virtual void* AllocateUninitialized(size_t length) = 0;
4285 
4290  // TODO(eholk): make this pure virtual once blink implements this.
4291  virtual void* Reserve(size_t length);
4292 
4297  virtual void Free(void* data, size_t length) = 0;
4298 
4299  enum class AllocationMode { kNormal, kReservation };
4300 
4306  // TODO(eholk): make this pure virtual once blink implements this.
4307  virtual void Free(void* data, size_t length, AllocationMode mode);
4308 
4309  enum class Protection { kNoAccess, kReadWrite };
4310 
4318  // TODO(eholk): make this pure virtual once blink implements this.
4319  virtual void SetProtection(void* data, size_t length,
4320  Protection protection);
4321 
4328  static Allocator* NewDefaultAllocator();
4329  };
4330 
4339  class V8_EXPORT Contents { // NOLINT
4340  public:
4342  : data_(nullptr),
4343  byte_length_(0),
4344  allocation_base_(nullptr),
4345  allocation_length_(0),
4346  allocation_mode_(Allocator::AllocationMode::kNormal) {}
4347 
4348  void* AllocationBase() const { return allocation_base_; }
4349  size_t AllocationLength() const { return allocation_length_; }
4351  return allocation_mode_;
4352  }
4353 
4354  void* Data() const { return data_; }
4355  size_t ByteLength() const { return byte_length_; }
4356 
4357  private:
4358  void* data_;
4359  size_t byte_length_;
4360  void* allocation_base_;
4361  size_t allocation_length_;
4362  Allocator::AllocationMode allocation_mode_;
4363 
4364  friend class ArrayBuffer;
4365  };
4366 
4367 
4371  size_t ByteLength() const;
4372 
4379  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4380 
4390  static Local<ArrayBuffer> New(
4391  Isolate* isolate, void* data, size_t byte_length,
4393 
4398  bool IsExternal() const;
4399 
4403  bool IsNeuterable() const;
4404 
4411  void Neuter();
4412 
4422  Contents Externalize();
4423 
4434  Contents GetContents();
4435 
4436  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4437 
4438  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4439  static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4440 
4441  private:
4442  ArrayBuffer();
4443  static void CheckCast(Value* obj);
4444 };
4445 
4446 
4447 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4448 // The number of required internal fields can be defined by embedder.
4449 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4450 #endif
4451 
4452 
4458  public:
4462  Local<ArrayBuffer> Buffer();
4466  size_t ByteOffset();
4470  size_t ByteLength();
4471 
4481  size_t CopyContents(void* dest, size_t byte_length);
4482 
4487  bool HasBuffer() const;
4488 
4489  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4490 
4491  static const int kInternalFieldCount =
4493  static const int kEmbedderFieldCount =
4495 
4496  private:
4497  ArrayBufferView();
4498  static void CheckCast(Value* obj);
4499 };
4500 
4501 
4507  public:
4508  /*
4509  * The largest typed array size that can be constructed using New.
4510  */
4511  static constexpr size_t kMaxLength =
4512  sizeof(void*) == 4 ? (1u << 30) - 1 : (1u << 31) - 1;
4513 
4518  size_t Length();
4519 
4520  V8_INLINE static TypedArray* Cast(Value* obj);
4521 
4522  private:
4523  TypedArray();
4524  static void CheckCast(Value* obj);
4525 };
4526 
4527 
4532  public:
4533  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4534  size_t byte_offset, size_t length);
4535  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4536  size_t byte_offset, size_t length);
4537  V8_INLINE static Uint8Array* Cast(Value* obj);
4538 
4539  private:
4540  Uint8Array();
4541  static void CheckCast(Value* obj);
4542 };
4543 
4544 
4549  public:
4550  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4551  size_t byte_offset, size_t length);
4552  static Local<Uint8ClampedArray> New(
4553  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4554  size_t length);
4555  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4556 
4557  private:
4559  static void CheckCast(Value* obj);
4560 };
4561 
4566  public:
4567  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4568  size_t byte_offset, size_t length);
4569  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4570  size_t byte_offset, size_t length);
4571  V8_INLINE static Int8Array* Cast(Value* obj);
4572 
4573  private:
4574  Int8Array();
4575  static void CheckCast(Value* obj);
4576 };
4577 
4578 
4583  public:
4584  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4585  size_t byte_offset, size_t length);
4586  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4587  size_t byte_offset, size_t length);
4588  V8_INLINE static Uint16Array* Cast(Value* obj);
4589 
4590  private:
4591  Uint16Array();
4592  static void CheckCast(Value* obj);
4593 };
4594 
4595 
4600  public:
4601  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4602  size_t byte_offset, size_t length);
4603  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4604  size_t byte_offset, size_t length);
4605  V8_INLINE static Int16Array* Cast(Value* obj);
4606 
4607  private:
4608  Int16Array();
4609  static void CheckCast(Value* obj);
4610 };
4611 
4612 
4617  public:
4618  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4619  size_t byte_offset, size_t length);
4620  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4621  size_t byte_offset, size_t length);
4622  V8_INLINE static Uint32Array* Cast(Value* obj);
4623 
4624  private:
4625  Uint32Array();
4626  static void CheckCast(Value* obj);
4627 };
4628 
4629 
4634  public:
4635  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4636  size_t byte_offset, size_t length);
4637  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4638  size_t byte_offset, size_t length);
4639  V8_INLINE static Int32Array* Cast(Value* obj);
4640 
4641  private:
4642  Int32Array();
4643  static void CheckCast(Value* obj);
4644 };
4645 
4646 
4651  public:
4652  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4653  size_t byte_offset, size_t length);
4654  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4655  size_t byte_offset, size_t length);
4656  V8_INLINE static Float32Array* Cast(Value* obj);
4657 
4658  private:
4659  Float32Array();
4660  static void CheckCast(Value* obj);
4661 };
4662 
4663 
4668  public:
4669  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4670  size_t byte_offset, size_t length);
4671  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4672  size_t byte_offset, size_t length);
4673  V8_INLINE static Float64Array* Cast(Value* obj);
4674 
4675  private:
4676  Float64Array();
4677  static void CheckCast(Value* obj);
4678 };
4679 
4680 
4685  public:
4686  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
4687  size_t byte_offset, size_t length);
4688  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
4689  size_t byte_offset, size_t length);
4690  V8_INLINE static DataView* Cast(Value* obj);
4691 
4692  private:
4693  DataView();
4694  static void CheckCast(Value* obj);
4695 };
4696 
4697 
4703  public:
4715  class V8_EXPORT Contents { // NOLINT
4716  public:
4718  : data_(nullptr),
4719  byte_length_(0),
4720  allocation_base_(nullptr),
4721  allocation_length_(0),
4722  allocation_mode_(ArrayBuffer::Allocator::AllocationMode::kNormal) {}
4723 
4724  void* AllocationBase() const { return allocation_base_; }
4725  size_t AllocationLength() const { return allocation_length_; }
4727  return allocation_mode_;
4728  }
4729 
4730  void* Data() const { return data_; }
4731  size_t ByteLength() const { return byte_length_; }
4732 
4733  private:
4734  void* data_;
4735  size_t byte_length_;
4736  void* allocation_base_;
4737  size_t allocation_length_;
4738  ArrayBuffer::Allocator::AllocationMode allocation_mode_;
4739 
4740  friend class SharedArrayBuffer;
4741  };
4742 
4743 
4747  size_t ByteLength() const;
4748 
4755  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
4756 
4763  static Local<SharedArrayBuffer> New(
4764  Isolate* isolate, void* data, size_t byte_length,
4766 
4771  bool IsExternal() const;
4772 
4785  Contents Externalize();
4786 
4799  Contents GetContents();
4800 
4801  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
4802 
4803  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
4804 
4805  private:
4807  static void CheckCast(Value* obj);
4808 };
4809 
4810 
4814 class V8_EXPORT Date : public Object {
4815  public:
4816  static V8_DEPRECATE_SOON("Use maybe version.",
4817  Local<Value> New(Isolate* isolate, double time));
4819  double time);
4820 
4825  double ValueOf() const;
4826 
4827  V8_INLINE static Date* Cast(Value* obj);
4828 
4841  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
4842 
4843  private:
4844  static void CheckCast(Value* obj);
4845 };
4846 
4847 
4852  public:
4853  static Local<Value> New(Isolate* isolate, double value);
4854 
4855  double ValueOf() const;
4856 
4857  V8_INLINE static NumberObject* Cast(Value* obj);
4858 
4859  private:
4860  static void CheckCast(Value* obj);
4861 };
4862 
4863 
4868  public:
4869  static Local<Value> New(Isolate* isolate, bool value);
4870  V8_DEPRECATED("Pass an isolate", static Local<Value> New(bool value));
4871 
4872  bool ValueOf() const;
4873 
4874  V8_INLINE static BooleanObject* Cast(Value* obj);
4875 
4876  private:
4877  static void CheckCast(Value* obj);
4878 };
4879 
4880 
4885  public:
4886  static Local<Value> New(Local<String> value);
4887 
4888  Local<String> ValueOf() const;
4889 
4890  V8_INLINE static StringObject* Cast(Value* obj);
4891 
4892  private:
4893  static void CheckCast(Value* obj);
4894 };
4895 
4896 
4901  public:
4902  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
4903 
4904  Local<Symbol> ValueOf() const;
4905 
4906  V8_INLINE static SymbolObject* Cast(Value* obj);
4907 
4908  private:
4909  static void CheckCast(Value* obj);
4910 };
4911 
4912 
4916 class V8_EXPORT RegExp : public Object {
4917  public:
4922  enum Flags {
4923  kNone = 0,
4924  kGlobal = 1 << 0,
4925  kIgnoreCase = 1 << 1,
4926  kMultiline = 1 << 2,
4927  kSticky = 1 << 3,
4928  kUnicode = 1 << 4,
4929  kDotAll = 1 << 5,
4930  };
4931 
4942  static V8_DEPRECATE_SOON("Use maybe version",
4943  Local<RegExp> New(Local<String> pattern,
4944  Flags flags));
4946  Local<String> pattern,
4947  Flags flags);
4948 
4953  Local<String> GetSource() const;
4954 
4958  Flags GetFlags() const;
4959 
4960  V8_INLINE static RegExp* Cast(Value* obj);
4961 
4962  private:
4963  static void CheckCast(Value* obj);
4964 };
4965 
4966 
4971 class V8_EXPORT External : public Value {
4972  public:
4973  static Local<External> New(Isolate* isolate, void* value);
4974  V8_INLINE static External* Cast(Value* obj);
4975  void* Value() const;
4976  private:
4977  static void CheckCast(v8::Value* obj);
4978 };
4979 
4980 #define V8_INTRINSICS_LIST(F) \
4981  F(ArrayProto_entries, array_entries_iterator) \
4982  F(ArrayProto_forEach, array_for_each_iterator) \
4983  F(ArrayProto_keys, array_keys_iterator) \
4984  F(ArrayProto_values, array_values_iterator) \
4985  F(ErrorPrototype, initial_error_prototype) \
4986  F(IteratorPrototype, initial_iterator_prototype)
4987 
4989 #define V8_DECL_INTRINSIC(name, iname) k##name,
4991 #undef V8_DECL_INTRINSIC
4992 };
4993 
4994 
4995 // --- Templates ---
4996 
4997 
5001 class V8_EXPORT Template : public Data {
5002  public:
5008  void Set(Local<Name> name, Local<Data> value,
5009  PropertyAttribute attributes = None);
5010  void SetPrivate(Local<Private> name, Local<Data> value,
5011  PropertyAttribute attributes = None);
5012  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
5013 
5014  void SetAccessorProperty(
5015  Local<Name> name,
5018  PropertyAttribute attribute = None,
5019  AccessControl settings = DEFAULT);
5020 
5048  void SetNativeDataProperty(
5050  AccessorSetterCallback setter = 0,
5051  // TODO(dcarney): gcc can't handle Local below
5052  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5054  AccessControl settings = DEFAULT);
5055  void SetNativeDataProperty(
5057  AccessorNameSetterCallback setter = 0,
5058  // TODO(dcarney): gcc can't handle Local below
5059  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
5061  AccessControl settings = DEFAULT);
5062 
5067  void SetLazyDataProperty(Local<Name> name, AccessorNameGetterCallback getter,
5068  Local<Value> data = Local<Value>(),
5069  PropertyAttribute attribute = None);
5070 
5075  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
5076  PropertyAttribute attribute = None);
5077 
5078  private:
5079  Template();
5080 
5081  friend class ObjectTemplate;
5082  friend class FunctionTemplate;
5083 };
5084 
5085 
5091  Local<String> property,
5092  const PropertyCallbackInfo<Value>& info);
5093 
5094 
5100  Local<String> property,
5101  Local<Value> value,
5102  const PropertyCallbackInfo<Value>& info);
5103 
5104 
5111  Local<String> property,
5112  const PropertyCallbackInfo<Integer>& info);
5113 
5114 
5121  Local<String> property,
5122  const PropertyCallbackInfo<Boolean>& info);
5123 
5129  const PropertyCallbackInfo<Array>& info);
5130 
5131 
5132 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
5133 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
5134 
5172  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5173 
5196  Local<Name> property, Local<Value> value,
5197  const PropertyCallbackInfo<Value>& info);
5198 
5221  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
5222 
5245  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
5246 
5252  const PropertyCallbackInfo<Array>& info);
5253 
5275  Local<Name> property, const PropertyDescriptor& desc,
5276  const PropertyCallbackInfo<Value>& info);
5277 
5298  Local<Name> property, const PropertyCallbackInfo<Value>& info);
5299 
5304  uint32_t index,
5305  const PropertyCallbackInfo<Value>& info);
5306 
5311  uint32_t index,
5312  Local<Value> value,
5313  const PropertyCallbackInfo<Value>& info);
5314 
5319  uint32_t index,
5320  const PropertyCallbackInfo<Integer>& info);
5321 
5326  uint32_t index,
5327  const PropertyCallbackInfo<Boolean>& info);
5328 
5333  const PropertyCallbackInfo<Array>& info);
5334 
5339  uint32_t index, const PropertyDescriptor& desc,
5340  const PropertyCallbackInfo<Value>& info);
5341 
5346  uint32_t index, const PropertyCallbackInfo<Value>& info);
5347 
5357 };
5358 
5359 
5364 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5365  Local<Object> accessed_object,
5366  Local<Value> data);
5367 
5468  public:
5470  static Local<FunctionTemplate> New(
5471  Isolate* isolate, FunctionCallback callback = 0,
5472  Local<Value> data = Local<Value>(),
5473  Local<Signature> signature = Local<Signature>(), int length = 0,
5475 
5477  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5478  size_t index);
5479 
5483  static Local<FunctionTemplate> NewWithCache(
5484  Isolate* isolate, FunctionCallback callback,
5485  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5486  Local<Signature> signature = Local<Signature>(), int length = 0);
5487 
5489  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5491  Local<Context> context);
5492 
5500  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5501 
5507  void SetCallHandler(FunctionCallback callback,
5508  Local<Value> data = Local<Value>());
5509 
5511  void SetLength(int length);
5512 
5514  Local<ObjectTemplate> InstanceTemplate();
5515 
5521  void Inherit(Local<FunctionTemplate> parent);
5522 
5527  Local<ObjectTemplate> PrototypeTemplate();
5528 
5535  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5536 
5542  void SetClassName(Local<String> name);
5543 
5544 
5549  void SetAcceptAnyReceiver(bool value);
5550 
5563  void SetHiddenPrototype(bool value);
5564 
5569  void ReadOnlyPrototype();
5570 
5575  void RemovePrototype();
5576 
5581  bool HasInstance(Local<Value> object);
5582 
5583  private:
5584  FunctionTemplate();
5585  friend class Context;
5586  friend class ObjectTemplate;
5587 };
5588 
5597  kNone = 0,
5598 
5602  kAllCanRead = 1,
5603 
5608  kNonMasking = 1 << 1,
5609 
5614  kOnlyInterceptStrings = 1 << 2,
5615 };
5616 
5627  : getter(getter),
5628  setter(setter),
5629  query(query),
5630  deleter(deleter),
5632  definer(0),
5633  descriptor(0),
5634  data(data),
5635  flags(flags) {}
5636 
5646  : getter(getter),
5647  setter(setter),
5648  query(0),
5649  deleter(deleter),
5651  definer(definer),
5653  data(data),
5654  flags(flags) {}
5655 
5665 };
5666 
5667 
5678  : getter(getter),
5679  setter(setter),
5680  query(query),
5681  deleter(deleter),
5683  definer(0),
5684  descriptor(0),
5685  data(data),
5686  flags(flags) {}
5687 
5697  : getter(getter),
5698  setter(setter),
5699  query(0),
5700  deleter(deleter),
5702  definer(definer),
5704  data(data),
5705  flags(flags) {}
5706 
5716 };
5717 
5718 
5726  public:
5728  static Local<ObjectTemplate> New(
5729  Isolate* isolate,
5731  static V8_DEPRECATED("Use isolate version", Local<ObjectTemplate> New());
5732 
5734  static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
5735  size_t index);
5736 
5738  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
5740 
5770  void SetAccessor(
5772  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
5773  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
5775  void SetAccessor(
5778  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
5780 
5803  // TODO(dcarney): deprecate
5804  void SetNamedPropertyHandler(NamedPropertyGetterCallback getter,
5805  NamedPropertySetterCallback setter = 0,
5806  NamedPropertyQueryCallback query = 0,
5807  NamedPropertyDeleterCallback deleter = 0,
5808  NamedPropertyEnumeratorCallback enumerator = 0,
5809  Local<Value> data = Local<Value>());
5810 
5822  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
5823 
5840  // TODO(dcarney): deprecate
5843  IndexedPropertySetterCallback setter = 0,
5844  IndexedPropertyQueryCallback query = 0,
5845  IndexedPropertyDeleterCallback deleter = 0,
5846  IndexedPropertyEnumeratorCallback enumerator = 0,
5847  Local<Value> data = Local<Value>()) {
5848  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
5849  deleter, enumerator, data));
5850  }
5851 
5862  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
5863 
5870  void SetCallAsFunctionHandler(FunctionCallback callback,
5871  Local<Value> data = Local<Value>());
5872 
5881  void MarkAsUndetectable();
5882 
5891  void SetAccessCheckCallback(AccessCheckCallback callback,
5892  Local<Value> data = Local<Value>());
5893 
5900  void SetAccessCheckCallbackAndHandler(
5901  AccessCheckCallback callback,
5902  const NamedPropertyHandlerConfiguration& named_handler,
5903  const IndexedPropertyHandlerConfiguration& indexed_handler,
5904  Local<Value> data = Local<Value>());
5905 
5910  int InternalFieldCount();
5911 
5916  void SetInternalFieldCount(int value);
5917 
5921  bool IsImmutableProto();
5922 
5927  void SetImmutableProto();
5928 
5929  private:
5930  ObjectTemplate();
5931  static Local<ObjectTemplate> New(internal::Isolate* isolate,
5932  Local<FunctionTemplate> constructor);
5933  friend class FunctionTemplate;
5934 };
5935 
5944 class V8_EXPORT Signature : public Data {
5945  public:
5946  static Local<Signature> New(
5947  Isolate* isolate,
5949 
5950  private:
5951  Signature();
5952 };
5953 
5954 
5960  public:
5961  static Local<AccessorSignature> New(
5962  Isolate* isolate,
5964 
5965  private:
5967 };
5968 
5969 
5970 // --- Extensions ---
5971 
5974  public:
5975  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
5976  ExternalOneByteStringResourceImpl(const char* data, size_t length)
5977  : data_(data), length_(length) {}
5978  const char* data() const { return data_; }
5979  size_t length() const { return length_; }
5980 
5981  private:
5982  const char* data_;
5983  size_t length_;
5984 };
5985 
5989 class V8_EXPORT Extension { // NOLINT
5990  public:
5991  // Note that the strings passed into this constructor must live as long
5992  // as the Extension itself.
5993  Extension(const char* name,
5994  const char* source = 0,
5995  int dep_count = 0,
5996  const char** deps = 0,
5997  int source_length = -1);
5998  virtual ~Extension() { }
6000  Isolate* isolate, Local<String> name) {
6001  return Local<FunctionTemplate>();
6002  }
6003 
6004  const char* name() const { return name_; }
6005  size_t source_length() const { return source_length_; }
6007  return &source_; }
6008  int dependency_count() { return dep_count_; }
6009  const char** dependencies() { return deps_; }
6010  void set_auto_enable(bool value) { auto_enable_ = value; }
6011  bool auto_enable() { return auto_enable_; }
6012 
6013  // Disallow copying and assigning.
6014  Extension(const Extension&) = delete;
6015  void operator=(const Extension&) = delete;
6016 
6017  private:
6018  const char* name_;
6019  size_t source_length_; // expected to initialize before source_
6021  int dep_count_;
6022  const char** deps_;
6023  bool auto_enable_;
6024 };
6025 
6026 
6027 void V8_EXPORT RegisterExtension(Extension* extension);
6028 
6029 
6030 // --- Statics ---
6031 
6032 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
6033 V8_INLINE Local<Primitive> Null(Isolate* isolate);
6034 V8_INLINE Local<Boolean> True(Isolate* isolate);
6035 V8_INLINE Local<Boolean> False(Isolate* isolate);
6036 
6052  public:
6054 
6064  void ConfigureDefaults(uint64_t physical_memory,
6065  uint64_t virtual_memory_limit);
6066 
6067  // Returns the max semi-space size in MB.
6068  V8_DEPRECATE_SOON("Use max_semi_space_size_in_kb()",
6069  int max_semi_space_size()) {
6070  return static_cast<int>(max_semi_space_size_in_kb_ / 1024);
6071  }
6072 
6073  // Sets the max semi-space size in MB.
6074  V8_DEPRECATE_SOON("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
6075  void set_max_semi_space_size(int limit_in_mb)) {
6076  max_semi_space_size_in_kb_ = limit_in_mb * 1024;
6077  }
6078 
6079  // Returns the max semi-space size in KB.
6080  size_t max_semi_space_size_in_kb() const {
6081  return max_semi_space_size_in_kb_;
6082  }
6083 
6084  // Sets the max semi-space size in KB.
6085  void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
6086  max_semi_space_size_in_kb_ = limit_in_kb;
6087  }
6088 
6089  int max_old_space_size() const { return max_old_space_size_; }
6090  void set_max_old_space_size(int limit_in_mb) {
6091  max_old_space_size_ = limit_in_mb;
6092  }
6093  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6094  int max_executable_size() const) {
6095  return max_executable_size_;
6096  }
6097  V8_DEPRECATE_SOON("max_executable_size_ is subsumed by max_old_space_size_",
6098  void set_max_executable_size(int limit_in_mb)) {
6099  max_executable_size_ = limit_in_mb;
6100  }
6101  uint32_t* stack_limit() const { return stack_limit_; }
6102  // Sets an address beyond which the VM's stack may not grow.
6103  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
6104  size_t code_range_size() const { return code_range_size_; }
6105  void set_code_range_size(size_t limit_in_mb) {
6106  code_range_size_ = limit_in_mb;
6107  }
6108  size_t max_zone_pool_size() const { return max_zone_pool_size_; }
6109  void set_max_zone_pool_size(const size_t bytes) {
6110  max_zone_pool_size_ = bytes;
6111  }
6112 
6113  private:
6114  // max_semi_space_size_ is in KB
6115  size_t max_semi_space_size_in_kb_;
6116 
6117  // The remaining limits are in MB
6118  int max_old_space_size_;
6119  int max_executable_size_;
6120  uint32_t* stack_limit_;
6121  size_t code_range_size_;
6122  size_t max_zone_pool_size_;
6123 };
6124 
6125 
6126 // --- Exceptions ---
6127 
6128 
6129 typedef void (*FatalErrorCallback)(const char* location, const char* message);
6130 
6131 typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
6132 
6133 typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
6134 
6135 // --- Tracing ---
6136 
6137 typedef void (*LogEventCallback)(const char* name, int event);
6138 
6144  public:
6145  static Local<Value> RangeError(Local<String> message);
6146  static Local<Value> ReferenceError(Local<String> message);
6147  static Local<Value> SyntaxError(Local<String> message);
6148  static Local<Value> TypeError(Local<String> message);
6149  static Local<Value> Error(Local<String> message);
6150 
6156  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
6157  V8_DEPRECATED("Use version with an Isolate*",
6158  static Local<Message> CreateMessage(Local<Value> exception));
6159 
6164  static Local<StackTrace> GetStackTrace(Local<Value> exception);
6165 };
6166 
6167 
6168 // --- Counters Callbacks ---
6169 
6170 typedef int* (*CounterLookupCallback)(const char* name);
6171 
6172 typedef void* (*CreateHistogramCallback)(const char* name,
6173  int min,
6174  int max,
6175  size_t buckets);
6176 
6177 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
6178 
6179 // --- Memory Allocation Callback ---
6189 };
6190 
6195  };
6196 
6197 // --- Enter/Leave Script Callback ---
6199 typedef void (*CallCompletedCallback)(Isolate*);
6201 
6223  Local<Context> context, Local<String> referrer, Local<String> specifier);
6224 
6242 
6243 typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
6244  Local<Value> parent);
6245 
6246 // --- Promise Reject Callback ---
6250 };
6251 
6253  public:
6255  Local<Value> value, Local<StackTrace> stack_trace)
6256  : promise_(promise),
6257  event_(event),
6258  value_(value),
6259  stack_trace_(stack_trace) {}
6260 
6261  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
6262  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
6263  V8_INLINE Local<Value> GetValue() const { return value_; }
6264 
6265  V8_DEPRECATED("Use v8::Exception::CreateMessage(GetValue())->GetStackTrace()",
6266  V8_INLINE Local<StackTrace> GetStackTrace() const) {
6267  return stack_trace_;
6268  }
6269 
6270  private:
6271  Local<Promise> promise_;
6272  PromiseRejectEvent event_;
6273  Local<Value> value_;
6274  Local<StackTrace> stack_trace_;
6275 };
6276 
6278 
6279 // --- Microtasks Callbacks ---
6281 typedef void (*MicrotaskCallback)(void* data);
6282 
6283 
6292 
6293 
6304  public:
6305  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
6306 
6307  MicrotasksScope(Isolate* isolate, Type type);
6308  ~MicrotasksScope();
6309 
6313  static void PerformCheckpoint(Isolate* isolate);
6314 
6318  static int GetCurrentDepth(Isolate* isolate);
6319 
6323  static bool IsRunningMicrotasks(Isolate* isolate);
6324 
6325  // Prevent copying.
6326  MicrotasksScope(const MicrotasksScope&) = delete;
6327  MicrotasksScope& operator=(const MicrotasksScope&) = delete;
6328 
6329  private:
6330  internal::Isolate* const isolate_;
6331  bool run_;
6332 };
6333 
6334 
6335 // --- Failed Access Check Callback ---
6337  AccessType type,
6338  Local<Value> data);
6339 
6340 // --- AllowCodeGenerationFromStrings callbacks ---
6341 
6347  Local<String> source);
6348 
6349 // --- WebAssembly compilation callbacks ---
6351 
6352 // --- Callback for APIs defined on v8-supported objects, but implemented
6353 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
6355 
6356 // --- Garbage Collection Callbacks ---
6357 
6365 enum GCType {
6372 };
6373 
6396 };
6397 
6398 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
6399 
6400 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
6401 
6402 
6410  public:
6411  HeapStatistics();
6412  size_t total_heap_size() { return total_heap_size_; }
6413  size_t total_heap_size_executable() { return total_heap_size_executable_; }
6414  size_t total_physical_size() { return total_physical_size_; }
6415  size_t total_available_size() { return total_available_size_; }
6416  size_t used_heap_size() { return used_heap_size_; }
6417  size_t heap_size_limit() { return heap_size_limit_; }
6418  size_t malloced_memory() { return malloced_memory_; }
6419  size_t peak_malloced_memory() { return peak_malloced_memory_; }
6420 
6425  size_t does_zap_garbage() { return does_zap_garbage_; }
6426 
6427  private:
6428  size_t total_heap_size_;
6429  size_t total_heap_size_executable_;
6430  size_t total_physical_size_;
6431  size_t total_available_size_;
6432  size_t used_heap_size_;
6433  size_t heap_size_limit_;
6434  size_t malloced_memory_;
6435  size_t peak_malloced_memory_;
6436  bool does_zap_garbage_;
6437 
6438  friend class V8;
6439  friend class Isolate;
6440 };
6441 
6442 
6444  public:
6446  const char* space_name() { return space_name_; }
6447  size_t space_size() { return space_size_; }
6448  size_t space_used_size() { return space_used_size_; }
6449  size_t space_available_size() { return space_available_size_; }
6450  size_t physical_space_size() { return physical_space_size_; }
6451 
6452  private:
6453  const char* space_name_;
6454  size_t space_size_;
6455  size_t space_used_size_;
6456  size_t space_available_size_;
6457  size_t physical_space_size_;
6458 
6459  friend class Isolate;
6460 };
6461 
6462 
6464  public:
6466  const char* object_type() { return object_type_; }
6467  const char* object_sub_type() { return object_sub_type_; }
6468  size_t object_count() { return object_count_; }
6469  size_t object_size() { return object_size_; }
6470 
6471  private:
6472  const char* object_type_;
6473  const char* object_sub_type_;
6474  size_t object_count_;
6475  size_t object_size_;
6476 
6477  friend class Isolate;
6478 };
6479 
6481  public:
6483  size_t code_and_metadata_size() { return code_and_metadata_size_; }
6484  size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
6485 
6486  private:
6487  size_t code_and_metadata_size_;
6488  size_t bytecode_and_metadata_size_;
6489 
6490  friend class Isolate;
6491 };
6492 
6493 class RetainedObjectInfo;
6494 
6495 
6507 typedef void (*FunctionEntryHook)(uintptr_t function,
6508  uintptr_t return_addr_location);
6509 
6516  enum EventType {
6523  };
6524  // Definition of the code position type. The "POSITION" type means the place
6525  // in the source code which are of interest when making stack traces to
6526  // pin-point the source location of a stack frame as close as possible.
6527  // The "STATEMENT_POSITION" means the place at the beginning of each
6528  // statement, and is used to indicate possible break locations.
6530 
6531  // Type of event.
6533  // Start of the instructions.
6534  void* code_start;
6535  // Size of the instructions.
6536  size_t code_len;
6537  // Script info for CODE_ADDED event.
6539  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
6540  // code line information which is returned from the
6541  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
6542  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
6543  void* user_data;
6544 
6545  struct name_t {
6546  // Name of the object associated with the code, note that the string is not
6547  // zero-terminated.
6548  const char* str;
6549  // Number of chars in str.
6550  size_t len;
6551  };
6552 
6553  struct line_info_t {
6554  // PC offset
6555  size_t offset;
6556  // Code position
6557  size_t pos;
6558  // The position type.
6560  };
6561 
6562  union {
6563  // Only valid for CODE_ADDED.
6564  struct name_t name;
6565 
6566  // Only valid for CODE_ADD_LINE_POS_INFO
6568 
6569  // New location of instructions. Only valid for CODE_MOVED.
6571  };
6572 };
6573 
6579 enum RAILMode {
6580  // Response performance mode: In this mode very low virtual machine latency
6581  // is provided. V8 will try to avoid JavaScript execution interruptions.
6582  // Throughput may be throttled.
6584  // Animation performance mode: In this mode low virtual machine latency is
6585  // provided. V8 will try to avoid as many JavaScript execution interruptions
6586  // as possible. Throughput may be throttled. This is the default mode.
6588  // Idle performance mode: The embedder is idle. V8 can complete deferred work
6589  // in this mode.
6591  // Load performance mode: In this mode high throughput is provided. V8 may
6592  // turn off latency optimizations.
6594 };
6595 
6601  // Generate callbacks for already existent code.
6603 };
6604 
6605 
6611 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
6612 
6613 
6618  public:
6620  virtual void VisitExternalString(Local<String> string) {}
6621 };
6622 
6623 
6628  public:
6631  uint16_t class_id) {}
6632 };
6633 
6643 
6656  public:
6657  enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
6658 
6660  explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
6661  : force_completion(force_completion_) {}
6662 
6664  };
6665 
6672  virtual void RegisterV8References(
6673  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
6674 
6678  virtual void TracePrologue() = 0;
6679 
6690  virtual bool AdvanceTracing(double deadline_in_ms,
6691  AdvanceTracingActions actions) = 0;
6692 
6698  virtual void TraceEpilogue() = 0;
6699 
6704  virtual void EnterFinalPause() = 0;
6705 
6712  virtual void AbortTracing() = 0;
6713 
6717  virtual size_t NumberOfWrappersToTrace() { return 0; }
6718 
6719  protected:
6720  virtual ~EmbedderHeapTracer() = default;
6721 };
6722 
6728  typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
6729  void* data);
6731  void* data_arg = nullptr)
6732  : callback(function), data(data_arg) {}
6734  void* data;
6735 };
6736 // Note that these fields are called "internal fields" in the API and called
6737 // "embedder fields" within V8.
6739 
6745  typedef void (*CallbackFunction)(Local<Object> holder, int index,
6746  StartupData payload, void* data);
6748  void* data_arg = nullptr)
6749  : callback(function), data(data_arg) {}
6750  void (*callback)(Local<Object> holder, int index, StartupData payload,
6751  void* data);
6752  void* data;
6753 };
6755 
6765  public:
6769  struct CreateParams {
6771  : entry_hook(nullptr),
6772  code_event_handler(nullptr),
6773  snapshot_blob(nullptr),
6774  counter_lookup_callback(nullptr),
6775  create_histogram_callback(nullptr),
6776  add_histogram_sample_callback(nullptr),
6777  array_buffer_allocator(nullptr),
6778  external_references(nullptr),
6779  allow_atomics_wait(true) {}
6780 
6790 
6796 
6801 
6806 
6807 
6813 
6822 
6828 
6835  const intptr_t* external_references;
6836 
6842  };
6843 
6844 
6850  public:
6851  explicit Scope(Isolate* isolate) : isolate_(isolate) {
6852  isolate->Enter();
6853  }
6854 
6855  ~Scope() { isolate_->Exit(); }
6856 
6857  // Prevent copying of Scope objects.
6858  Scope(const Scope&) = delete;
6859  Scope& operator=(const Scope&) = delete;
6860 
6861  private:
6862  Isolate* const isolate_;
6863  };
6864 
6865 
6870  public:
6871  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
6872 
6873  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
6875 
6876  // Prevent copying of Scope objects.
6878  delete;
6880  const DisallowJavascriptExecutionScope&) = delete;
6881 
6882  private:
6883  bool on_failure_;
6884  void* internal_;
6885  };
6886 
6887 
6892  public:
6893  explicit AllowJavascriptExecutionScope(Isolate* isolate);
6895 
6896  // Prevent copying of Scope objects.
6898  delete;
6899  AllowJavascriptExecutionScope& operator=(
6900  const AllowJavascriptExecutionScope&) = delete;
6901 
6902  private:
6903  void* internal_throws_;
6904  void* internal_assert_;
6905  };
6906 
6912  public:
6913  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
6915 
6916  // Prevent copying of Scope objects.
6918  delete;
6920  const SuppressMicrotaskExecutionScope&) = delete;
6921 
6922  private:
6923  internal::Isolate* const isolate_;
6924  };
6925 
6932  kMinorGarbageCollection
6933  };
6934 
6941  kUseAsm = 0,
6942  kBreakIterator = 1,
6943  kLegacyConst = 2,
6944  kMarkDequeOverflow = 3,
6945  kStoreBufferOverflow = 4,
6946  kSlotsBufferOverflow = 5,
6947  kObjectObserve = 6,
6948  kForcedGC = 7,
6949  kSloppyMode = 8,
6950  kStrictMode = 9,
6951  kStrongMode = 10,
6952  kRegExpPrototypeStickyGetter = 11,
6953  kRegExpPrototypeToString = 12,
6954  kRegExpPrototypeUnicodeGetter = 13,
6955  kIntlV8Parse = 14,
6956  kIntlPattern = 15,
6957  kIntlResolved = 16,
6958  kPromiseChain = 17,
6959  kPromiseAccept = 18,
6960  kPromiseDefer = 19,
6961  kHtmlCommentInExternalScript = 20,
6962  kHtmlComment = 21,
6963  kSloppyModeBlockScopedFunctionRedefinition = 22,
6964  kForInInitializer = 23,
6965  kArrayProtectorDirtied = 24,
6966  kArraySpeciesModified = 25,
6967  kArrayPrototypeConstructorModified = 26,
6968  kArrayInstanceProtoModified = 27,
6969  kArrayInstanceConstructorModified = 28,
6970  kLegacyFunctionDeclaration = 29,
6971  kRegExpPrototypeSourceGetter = 30,
6972  kRegExpPrototypeOldFlagGetter = 31,
6973  kDecimalWithLeadingZeroInStrictMode = 32,
6974  kLegacyDateParser = 33,
6975  kDefineGetterOrSetterWouldThrow = 34,
6976  kFunctionConstructorReturnedUndefined = 35,
6977  kAssigmentExpressionLHSIsCallInSloppy = 36,
6978  kAssigmentExpressionLHSIsCallInStrict = 37,
6979  kPromiseConstructorReturnedUndefined = 38,
6980  kConstructorNonUndefinedPrimitiveReturn = 39,
6981  kLabeledExpressionStatement = 40,
6982 
6983  // If you add new values here, you'll also need to update Chromium's:
6984  // UseCounter.h, V8PerIsolateData.cpp, histograms.xml
6985  kUseCounterFeatureCount // This enum value must be last.
6986  };
6987 
6989  kMessageLog = (1 << 0),
6990  kMessageDebug = (1 << 1),
6991  kMessageInfo = (1 << 2),
6992  kMessageError = (1 << 3),
6993  kMessageWarning = (1 << 4),
6994  kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
6995  kMessageWarning,
6996  };
6997 
6998  typedef void (*UseCounterCallback)(Isolate* isolate,
6999  UseCounterFeature feature);
7000 
7001 
7011  static Isolate* New(const CreateParams& params);
7012 
7019  static Isolate* GetCurrent();
7020 
7030  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
7031  void SetAbortOnUncaughtExceptionCallback(
7032  AbortOnUncaughtExceptionCallback callback);
7033 
7041  void SetHostImportModuleDynamicallyCallback(
7043 
7050  void MemoryPressureNotification(MemoryPressureLevel level);
7051 
7062  void Enter();
7063 
7071  void Exit();
7072 
7077  void Dispose();
7078 
7083  void DumpAndResetStats();
7084 
7092  void DiscardThreadSpecificMetadata();
7093 
7098  V8_INLINE void SetData(uint32_t slot, void* data);
7099 
7104  V8_INLINE void* GetData(uint32_t slot);
7105 
7110  V8_INLINE static uint32_t GetNumberOfDataSlots();
7111 
7115  void GetHeapStatistics(HeapStatistics* heap_statistics);
7116 
7120  size_t NumberOfHeapSpaces();
7121 
7131  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7132  size_t index);
7133 
7137  size_t NumberOfTrackedHeapObjectTypes();
7138 
7148  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7149  size_t type_index);
7150 
7158  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7159 
7172  void GetStackSample(const RegisterState& state, void** frames,
7173  size_t frames_limit, SampleInfo* sample_info);
7174 
7188  V8_INLINE int64_t
7189  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
7190 
7195  size_t NumberOfPhantomHandleResetsSinceLastCall();
7196 
7201  HeapProfiler* GetHeapProfiler();
7202 
7208  V8_DEPRECATE_SOON("CpuProfiler should be created with CpuProfiler::New call.",
7209  CpuProfiler* GetCpuProfiler());
7210 
7212  bool InContext();
7213 
7218  Local<Context> GetCurrentContext();
7219 
7226  "Calling context concept is not compatible with tail calls, and will be "
7227  "removed.",
7228  Local<Context> GetCallingContext());
7229 
7231  Local<Context> GetEnteredContext();
7232 
7239  Local<Context> GetEnteredOrMicrotaskContext();
7240 
7245  Local<Context> GetIncumbentContext();
7246 
7253  Local<Value> ThrowException(Local<Value> exception);
7254 
7255  typedef void (*GCCallback)(Isolate* isolate, GCType type,
7256  GCCallbackFlags flags);
7257 
7267  void AddGCPrologueCallback(GCCallback callback,
7268  GCType gc_type_filter = kGCTypeAll);
7269 
7274  void RemoveGCPrologueCallback(GCCallback callback);
7275 
7279  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
7280 
7290  void AddGCEpilogueCallback(GCCallback callback,
7291  GCType gc_type_filter = kGCTypeAll);
7292 
7297  void RemoveGCEpilogueCallback(GCCallback callback);
7298 
7299  typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
7300 
7307  void SetGetExternallyAllocatedMemoryInBytesCallback(
7308  GetExternallyAllocatedMemoryInBytesCallback callback);
7309 
7317  void TerminateExecution();
7318 
7327  bool IsExecutionTerminating();
7328 
7343  void CancelTerminateExecution();
7344 
7353  void RequestInterrupt(InterruptCallback callback, void* data);
7354 
7365  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
7366 
7370  void SetEventLogger(LogEventCallback that);
7371 
7378  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7379 
7383  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
7384 
7392  void AddCallCompletedCallback(CallCompletedCallback callback);
7394  "Use callback with parameter",
7395  void AddCallCompletedCallback(DeprecatedCallCompletedCallback callback));
7396 
7400  void RemoveCallCompletedCallback(CallCompletedCallback callback);
7402  "Use callback with parameter",
7403  void RemoveCallCompletedCallback(
7405 
7410  void SetPromiseHook(PromiseHook hook);
7411 
7416  void SetPromiseRejectCallback(PromiseRejectCallback callback);
7417 
7422  void RunMicrotasks();
7423 
7427  void EnqueueMicrotask(Local<Function> microtask);
7428 
7432  void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
7433 
7438  void SetMicrotasksPolicy(MicrotasksPolicy policy);
7439  V8_DEPRECATE_SOON("Use SetMicrotasksPolicy",
7440  void SetAutorunMicrotasks(bool autorun));
7441 
7445  MicrotasksPolicy GetMicrotasksPolicy() const;
7446  V8_DEPRECATE_SOON("Use GetMicrotasksPolicy",
7447  bool WillAutorunMicrotasks() const);
7448 
7461  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7462 
7466  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
7467 
7471  void SetUseCounterCallback(UseCounterCallback callback);
7472 
7477  void SetCounterFunction(CounterLookupCallback);
7478 
7485  void SetCreateHistogramFunction(CreateHistogramCallback);
7486  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
7487 
7502  bool IdleNotificationDeadline(double deadline_in_seconds);
7503 
7504  V8_DEPRECATED("use IdleNotificationDeadline()",
7505  bool IdleNotification(int idle_time_in_ms));
7506 
7511  void LowMemoryNotification();
7512 
7522  int ContextDisposedNotification(bool dependant_context = true);
7523 
7528  void IsolateInForegroundNotification();
7529 
7534  void IsolateInBackgroundNotification();
7535 
7543  void SetRAILMode(RAILMode rail_mode);
7544 
7549  void IncreaseHeapLimitForDebugging();
7550 
7554  void RestoreOriginalHeapLimit();
7555 
7560  bool IsHeapLimitIncreasedForDebugging();
7561 
7584  void SetJitCodeEventHandler(JitCodeEventOptions options,
7585  JitCodeEventHandler event_handler);
7586 
7596  void SetStackLimit(uintptr_t stack_limit);
7597 
7611  void GetCodeRange(void** start, size_t* length_in_bytes);
7612 
7614  void SetFatalErrorHandler(FatalErrorCallback that);
7615 
7617  void SetOOMErrorHandler(OOMErrorCallback that);
7618 
7623  void SetAllowCodeGenerationFromStringsCallback(
7625 
7630  void SetWasmModuleCallback(ExtensionCallback callback);
7631  void SetWasmInstanceCallback(ExtensionCallback callback);
7632 
7633  void SetWasmCompileStreamingCallback(ApiImplementationCallback callback);
7634 
7639  bool IsDead();
7640 
7650  bool AddMessageListener(MessageCallback that,
7651  Local<Value> data = Local<Value>());
7652 
7664  bool AddMessageListenerWithErrorLevel(MessageCallback that,
7665  int message_levels,
7666  Local<Value> data = Local<Value>());
7667 
7671  void RemoveMessageListeners(MessageCallback that);
7672 
7674  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
7675 
7680  void SetCaptureStackTraceForUncaughtExceptions(
7681  bool capture, int frame_limit = 10,
7683 
7689  void VisitExternalResources(ExternalResourceVisitor* visitor);
7690 
7695  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
7696 
7704  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
7705 
7711  void VisitWeakHandles(PersistentHandleVisitor* visitor);
7712 
7717  bool IsInUse();
7718 
7724  void SetAllowAtomicsWait(bool allow);
7725 
7726  Isolate() = delete;
7727  ~Isolate() = delete;
7728  Isolate(const Isolate&) = delete;
7729  Isolate& operator=(const Isolate&) = delete;
7730  // Deleting operator new and delete here is allowed as ctor and dtor is also
7731  // deleted.
7732  void* operator new(size_t size) = delete;
7733  void* operator new[](size_t size) = delete;
7734  void operator delete(void*, size_t) = delete;
7735  void operator delete[](void*, size_t) = delete;
7736 
7737  private:
7738  template <class K, class V, class Traits>
7740 
7741  void ReportExternalAllocationLimitReached();
7742  void CheckMemoryPressure();
7743 };
7744 
7746  public:
7747  const char* data;
7749 };
7750 
7751 
7756 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
7757 
7771 typedef uintptr_t (*ReturnAddressLocationResolver)(
7772  uintptr_t return_addr_location);
7773 
7774 
7778 class V8_EXPORT V8 {
7779  public:
7781  V8_INLINE static V8_DEPRECATED(
7782  "Use isolate version",
7783  void SetFatalErrorHandler(FatalErrorCallback that));
7784 
7789  V8_INLINE static V8_DEPRECATED("Use isolate version", bool IsDead());
7790 
7806  static void SetNativesDataBlob(StartupData* startup_blob);
7807  static void SetSnapshotDataBlob(StartupData* startup_blob);
7808 
7815  static StartupData CreateSnapshotDataBlob(const char* embedded_source = NULL);
7816 
7825  static StartupData WarmUpSnapshotDataBlob(StartupData cold_startup_blob,
7826  const char* warmup_source);
7827 
7837  V8_INLINE static V8_DEPRECATED(
7838  "Use isolate version",
7839  bool AddMessageListener(MessageCallback that,
7840  Local<Value> data = Local<Value>()));
7841 
7845  V8_INLINE static V8_DEPRECATED(
7846  "Use isolate version", void RemoveMessageListeners(MessageCallback that));
7847 
7852  V8_INLINE static V8_DEPRECATED(
7853  "Use isolate version",
7854  void SetCaptureStackTraceForUncaughtExceptions(
7855  bool capture, int frame_limit = 10,
7857 
7861  static void SetFlagsFromString(const char* str, int length);
7862 
7866  static void SetFlagsFromCommandLine(int* argc,
7867  char** argv,
7868  bool remove_flags);
7869 
7871  static const char* GetVersion();
7872 
7874  V8_INLINE static V8_DEPRECATED(
7875  "Use isolate version",
7876  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback));
7877 
7888  static V8_DEPRECATED(
7889  "Use isolate version",
7890  void AddGCPrologueCallback(GCCallback callback,
7891  GCType gc_type_filter = kGCTypeAll));
7892 
7897  V8_INLINE static V8_DEPRECATED(
7898  "Use isolate version",
7899  void RemoveGCPrologueCallback(GCCallback callback));
7900 
7911  static V8_DEPRECATED(
7912  "Use isolate version",
7913  void AddGCEpilogueCallback(GCCallback callback,
7914  GCType gc_type_filter = kGCTypeAll));
7915 
7920  V8_INLINE static V8_DEPRECATED(
7921  "Use isolate version",
7922  void RemoveGCEpilogueCallback(GCCallback callback));
7923 
7928  static bool Initialize();
7929 
7934  static void SetEntropySource(EntropySource source);
7935 
7940  static void SetReturnAddressLocationResolver(
7941  ReturnAddressLocationResolver return_address_resolver);
7942 
7952  V8_INLINE static V8_DEPRECATED("Use isolate version",
7953  void TerminateExecution(Isolate* isolate));
7954 
7965  V8_INLINE static V8_DEPRECATED(
7966  "Use isolate version",
7967  bool IsExecutionTerminating(Isolate* isolate = NULL));
7968 
7985  V8_INLINE static V8_DEPRECATED(
7986  "Use isolate version", void CancelTerminateExecution(Isolate* isolate));
7987 
7997  static bool Dispose();
7998 
8004  V8_INLINE static V8_DEPRECATED(
8005  "Use isolate version",
8006  void VisitExternalResources(ExternalResourceVisitor* visitor));
8007 
8012  V8_INLINE static V8_DEPRECATED(
8013  "Use isolate version",
8014  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor));
8015 
8020  V8_INLINE static V8_DEPRECATED(
8021  "Use isolate version",
8022  void VisitHandlesWithClassIds(Isolate* isolate,
8023  PersistentHandleVisitor* visitor));
8024 
8032  V8_INLINE static V8_DEPRECATED(
8033  "Use isolate version",
8034  void VisitHandlesForPartialDependence(Isolate* isolate,
8035  PersistentHandleVisitor* visitor));
8036 
8045  "Use version with default location.",
8046  static bool InitializeICU(const char* icu_data_file = nullptr));
8047 
8060  static bool InitializeICUDefaultLocation(const char* exec_path,
8061  const char* icu_data_file = nullptr);
8062 
8079  static void InitializeExternalStartupData(const char* directory_path);
8080  static void InitializeExternalStartupData(const char* natives_blob,
8081  const char* snapshot_blob);
8086  static void InitializePlatform(Platform* platform);
8087 
8092  static void ShutdownPlatform();
8093 
8094 #if V8_OS_POSIX
8095 
8114  static bool TryHandleSignal(int signal_number, void* info, void* context);
8115 #endif // V8_OS_POSIX
8116 
8121  static bool RegisterDefaultSignalHandler();
8122 
8123  private:
8124  V8();
8125 
8126  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
8127  internal::Object** handle);
8128  static internal::Object** CopyPersistent(internal::Object** handle);
8129  static void DisposeGlobal(internal::Object** global_handle);
8130  static void MakeWeak(internal::Object** location, void* data,
8131  WeakCallbackInfo<void>::Callback weak_callback,
8132  WeakCallbackType type);
8133  static void MakeWeak(internal::Object** location, void* data,
8134  // Must be 0 or -1.
8135  int internal_field_index1,
8136  // Must be 1 or -1.
8137  int internal_field_index2,
8138  WeakCallbackInfo<void>::Callback weak_callback);
8139  static void MakeWeak(internal::Object*** location_addr);
8140  static void* ClearWeak(internal::Object** location);
8141  static Value* Eternalize(Isolate* isolate, Value* handle);
8142 
8143  static void RegisterExternallyReferencedObject(internal::Object** object,
8144  internal::Isolate* isolate);
8145 
8146  template <class K, class V, class T>
8148 
8149  static void FromJustIsNothing();
8150  static void ToLocalEmpty();
8151  static void InternalFieldOutOfBounds(int index);
8152  template <class T> friend class Local;
8153  template <class T>
8154  friend class MaybeLocal;
8155  template <class T>
8156  friend class Maybe;
8157  template <class T>
8158  friend class WeakCallbackInfo;
8159  template <class T> friend class Eternal;
8160  template <class T> friend class PersistentBase;
8161  template <class T, class M> friend class Persistent;
8162  friend class Context;
8163 };
8164 
8169  public:
8170  enum class FunctionCodeHandling { kClear, kKeep };
8171 
8180  SnapshotCreator(const intptr_t* external_references = nullptr,
8181  StartupData* existing_blob = nullptr);
8182 
8183  ~SnapshotCreator();
8184 
8188  Isolate* GetIsolate();
8189 
8197  void SetDefaultContext(Local<Context> context,
8200 
8209  size_t AddContext(Local<Context> context,
8212 
8217  size_t AddTemplate(Local<Template> template_obj);
8218 
8227  StartupData CreateBlob(FunctionCodeHandling function_code_handling);
8228 
8229  // Disallow copying and assigning.
8230  SnapshotCreator(const SnapshotCreator&) = delete;
8231  void operator=(const SnapshotCreator&) = delete;
8232 
8233  private:
8234  void* data_;
8235 };
8236 
8247 template <class T>
8248 class Maybe {
8249  public:
8250  V8_INLINE bool IsNothing() const { return !has_value_; }
8251  V8_INLINE bool IsJust() const { return has_value_; }
8252 
8256  V8_INLINE T ToChecked() const { return FromJust(); }
8257 
8262  V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
8263  if (V8_LIKELY(IsJust())) *out = value_;
8264  return IsJust();
8265  }
8266 
8271  V8_INLINE T FromJust() const {
8272  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
8273  return value_;
8274  }
8275 
8280  V8_INLINE T FromMaybe(const T& default_value) const {
8281  return has_value_ ? value_ : default_value;
8282  }
8283 
8284  V8_INLINE bool operator==(const Maybe& other) const {
8285  return (IsJust() == other.IsJust()) &&
8286  (!IsJust() || FromJust() == other.FromJust());
8287  }
8288 
8289  V8_INLINE bool operator!=(const Maybe& other) const {
8290  return !operator==(other);
8291  }
8292 
8293  private:
8294  Maybe() : has_value_(false) {}
8295  explicit Maybe(const T& t) : has_value_(true), value_(t) {}
8296 
8297  bool has_value_;
8298  T value_;
8299 
8300  template <class U>
8301  friend Maybe<U> Nothing();
8302  template <class U>
8303  friend Maybe<U> Just(const U& u);
8304 };
8305 
8306 
8307 template <class T>
8308 inline Maybe<T> Nothing() {
8309  return Maybe<T>();
8310 }
8311 
8312 
8313 template <class T>
8314 inline Maybe<T> Just(const T& t) {
8315  return Maybe<T>(t);
8316 }
8317 
8318 
8323  public:
8329  V8_DEPRECATED("Use isolate version", TryCatch());
8330 
8336  TryCatch(Isolate* isolate);
8337 
8341  ~TryCatch();
8342 
8346  bool HasCaught() const;
8347 
8356  bool CanContinue() const;
8357 
8370  bool HasTerminated() const;
8371 
8379  Local<Value> ReThrow();
8380 
8387  Local<Value> Exception() const;
8388 
8393  V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace() const);
8395  Local<Context> context) const;
8396 
8404  Local<v8::Message> Message() const;
8405 
8416  void Reset();
8417 
8426  void SetVerbose(bool value);
8427 
8431  bool IsVerbose() const;
8432 
8438  void SetCaptureMessage(bool value);
8439 
8451  static void* JSStackComparableAddress(TryCatch* handler) {
8452  if (handler == NULL) return NULL;
8453  return handler->js_stack_comparable_address_;
8454  }
8455 
8456  TryCatch(const TryCatch&) = delete;
8457  void operator=(const TryCatch&) = delete;
8458 
8459  private:
8460  // Declaring operator new and delete as deleted is not spec compliant.
8461  // Therefore declare them private instead to disable dynamic alloc
8462  void* operator new(size_t size);
8463  void* operator new[](size_t size);
8464  void operator delete(void*, size_t);
8465  void operator delete[](void*, size_t);
8466 
8467  void ResetInternal();
8468 
8469  internal::Isolate* isolate_;
8470  TryCatch* next_;
8471  void* exception_;
8472  void* message_obj_;
8473  void* js_stack_comparable_address_;
8474  bool is_verbose_ : 1;
8475  bool can_continue_ : 1;
8476  bool capture_message_ : 1;
8477  bool rethrow_ : 1;
8478  bool has_terminated_ : 1;
8479 
8480  friend class internal::Isolate;
8481 };
8482 
8483 
8484 // --- Context ---
8485 
8486 
8491  public:
8492  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
8493  ExtensionConfiguration(int name_count, const char* names[])
8494  : name_count_(name_count), names_(names) { }
8495 
8496  const char** begin() const { return &names_[0]; }
8497  const char** end() const { return &names_[name_count_]; }
8498 
8499  private:
8500  const int name_count_;
8501  const char** names_;
8502 };
8503 
8509  public:
8523 
8528  void DetachGlobal();
8529 
8548  static Local<Context> New(
8549  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
8551  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
8552  DeserializeInternalFieldsCallback internal_fields_deserializer =
8554 
8574  static MaybeLocal<Context> FromSnapshot(
8575  Isolate* isolate, size_t context_snapshot_index,
8576  DeserializeInternalFieldsCallback embedder_fields_deserializer =
8578  ExtensionConfiguration* extensions = nullptr,
8579  MaybeLocal<Value> global_object = MaybeLocal<Value>());
8580 
8598  static MaybeLocal<Object> NewRemoteContext(
8599  Isolate* isolate, Local<ObjectTemplate> global_template,
8600  MaybeLocal<Value> global_object = MaybeLocal<Value>());
8601 
8606  void SetSecurityToken(Local<Value> token);
8607 
8609  void UseDefaultSecurityToken();
8610 
8612  Local<Value> GetSecurityToken();
8613 
8620  void Enter();
8621 
8626  void Exit();
8627 
8629  Isolate* GetIsolate();
8630 
8635  enum EmbedderDataFields { kDebugIdIndex = 0 };
8636 
8641  V8_INLINE Local<Value> GetEmbedderData(int index);
8642 
8649  Local<Object> GetExtrasBindingObject();
8650 
8656  void SetEmbedderData(int index, Local<Value> value);
8657 
8664  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
8665 
8671  void SetAlignedPointerInEmbedderData(int index, void* value);
8672 
8686  void AllowCodeGenerationFromStrings(bool allow);
8687 
8692  bool IsCodeGenerationFromStringsAllowed();
8693 
8699  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
8700 
8704  V8_DEPRECATED("no longer supported", size_t EstimatedSize());
8705 
8710  class Scope {
8711  public:
8712  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
8713  context_->Enter();
8714  }
8715  V8_INLINE ~Scope() { context_->Exit(); }
8716 
8717  private:
8718  Local<Context> context_;
8719  };
8720 
8727  public:
8732  explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
8734 
8735  private:
8736  friend class internal::Isolate;
8737 
8738  Local<Context> backup_incumbent_context_;
8739  const BackupIncumbentScope* prev_ = nullptr;
8740  };
8741 
8742  private:
8743  friend class Value;
8744  friend class Script;
8745  friend class Object;
8746  friend class Function;
8747 
8748  Local<Value> SlowGetEmbedderData(int index);
8749  void* SlowGetAlignedPointerFromEmbedderData(int index);
8750 };
8751 
8752 
8830  public:
8834  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
8835 
8836  ~Unlocker();
8837  private:
8838  void Initialize(Isolate* isolate);
8839 
8840  internal::Isolate* isolate_;
8841 };
8842 
8843