V8 API Reference Guide for node.js v5.11.0 - v5.11.1
v8.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef V8_H_
16 #define V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 
22 #include "v8-version.h"
23 #include "v8config.h"
24 
25 // We reserve the V8_* prefix for macros defined in V8 public API and
26 // assume there are no name conflicts with the embedder's code.
27 
28 #ifdef V8_OS_WIN
29 
30 // Setup for Windows DLL export/import. When building the V8 DLL the
31 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
32 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
33 // static library or building a program which uses the V8 static library neither
34 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
35 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
36 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
37  build configuration to ensure that at most one of these is set
38 #endif
39 
40 #ifdef BUILDING_V8_SHARED
41 # define V8_EXPORT __declspec(dllexport)
42 #elif USING_V8_SHARED
43 # define V8_EXPORT __declspec(dllimport)
44 #else
45 # define V8_EXPORT
46 #endif // BUILDING_V8_SHARED
47 
48 #else // V8_OS_WIN
49 
50 // Setup for Linux shared library export.
51 #if V8_HAS_ATTRIBUTE_VISIBILITY && defined(V8_SHARED)
52 # ifdef BUILDING_V8_SHARED
53 # define V8_EXPORT __attribute__ ((visibility("default")))
54 # else
55 # define V8_EXPORT
56 # endif
57 #else
58 # define V8_EXPORT
59 #endif
60 
61 #endif // V8_OS_WIN
62 
66 namespace v8 {
67 
68 class AccessorSignature;
69 class Array;
70 class Boolean;
71 class BooleanObject;
72 class Context;
73 class CpuProfiler;
74 class Data;
75 class Date;
76 class External;
77 class Function;
78 class FunctionTemplate;
79 class HeapProfiler;
80 class ImplementationUtilities;
81 class Int32;
82 class Integer;
83 class Isolate;
84 template <class T>
85 class Maybe;
86 class Name;
87 class Number;
88 class NumberObject;
89 class Object;
90 class ObjectOperationDescriptor;
91 class ObjectTemplate;
92 class Platform;
93 class Primitive;
94 class Promise;
95 class RawOperationDescriptor;
96 class Script;
97 class SharedArrayBuffer;
98 class Signature;
99 class StartupData;
100 class StackFrame;
101 class StackTrace;
102 class String;
103 class StringObject;
104 class Symbol;
105 class SymbolObject;
106 class Uint32;
107 class Utils;
108 class Value;
109 template <class T> class Local;
110 template <class T>
112 template <class T> class Eternal;
113 template<class T> class NonCopyablePersistentTraits;
114 template<class T> class PersistentBase;
115 template<class T,
117 template <class T>
118 class Global;
119 template<class K, class V, class T> class PersistentValueMap;
120 template <class K, class V, class T>
122 template <class K, class V, class T>
123 class GlobalValueMap;
124 template<class V, class T> class PersistentValueVector;
125 template<class T, class P> class WeakCallbackObject;
126 class FunctionTemplate;
127 class ObjectTemplate;
128 class Data;
129 template<typename T> class FunctionCallbackInfo;
130 template<typename T> class PropertyCallbackInfo;
131 class StackTrace;
132 class StackFrame;
133 class Isolate;
134 class CallHandlerHelper;
136 template<typename T> class ReturnValue;
137 
138 namespace internal {
139 class Arguments;
140 class Heap;
141 class HeapObject;
142 class Isolate;
143 class Object;
144 struct StreamedSource;
145 template<typename T> class CustomArguments;
146 class PropertyCallbackArguments;
147 class FunctionCallbackArguments;
148 class GlobalHandles;
149 }
150 
151 
155 class UniqueId {
156  public:
157  explicit UniqueId(intptr_t data)
158  : data_(data) {}
159 
160  bool operator==(const UniqueId& other) const {
161  return data_ == other.data_;
162  }
163 
164  bool operator!=(const UniqueId& other) const {
165  return data_ != other.data_;
166  }
167 
168  bool operator<(const UniqueId& other) const {
169  return data_ < other.data_;
170  }
171 
172  private:
173  intptr_t data_;
174 };
175 
176 // --- Handles ---
177 
178 #define TYPE_CHECK(T, S) \
179  while (false) { \
180  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
181  }
182 
183 
209 template <class T>
210 class Local {
211  public:
212  V8_INLINE Local() : val_(0) {}
213  template <class S>
214  V8_INLINE Local(Local<S> that)
215  : val_(reinterpret_cast<T*>(*that)) {
221  TYPE_CHECK(T, S);
222  }
223 
227  V8_INLINE bool IsEmpty() const { return val_ == 0; }
228 
232  V8_INLINE void Clear() { val_ = 0; }
233 
234  V8_INLINE T* operator->() const { return val_; }
235 
236  V8_INLINE T* operator*() const { return val_; }
237 
244  template <class S>
245  V8_INLINE bool operator==(const Local<S>& that) const {
246  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
247  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
248  if (a == 0) return b == 0;
249  if (b == 0) return false;
250  return *a == *b;
251  }
252 
253  template <class S> V8_INLINE bool operator==(
254  const PersistentBase<S>& that) const {
255  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
256  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
257  if (a == 0) return b == 0;
258  if (b == 0) return false;
259  return *a == *b;
260  }
261 
268  template <class S>
269  V8_INLINE bool operator!=(const Local<S>& that) const {
270  return !operator==(that);
271  }
272 
273  template <class S> V8_INLINE bool operator!=(
274  const Persistent<S>& that) const {
275  return !operator==(that);
276  }
277 
278  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
279 #ifdef V8_ENABLE_CHECKS
280  // If we're going to perform the type check then we have to check
281  // that the handle isn't empty before doing the checked cast.
282  if (that.IsEmpty()) return Local<T>();
283 #endif
284  return Local<T>(T::Cast(*that));
285  }
286 
287 
288  template <class S> V8_INLINE Local<S> As() {
289  return Local<S>::Cast(*this);
290  }
291 
297  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
298  V8_INLINE static Local<T> New(Isolate* isolate,
299  const PersistentBase<T>& that);
300 
301  private:
302  friend class Utils;
303  template<class F> friend class Eternal;
304  template<class F> friend class PersistentBase;
305  template<class F, class M> friend class Persistent;
306  template<class F> friend class Local;
307  template <class F>
308  friend class MaybeLocal;
309  template<class F> friend class FunctionCallbackInfo;
310  template<class F> friend class PropertyCallbackInfo;
311  friend class String;
312  friend class Object;
313  friend class Context;
314  template<class F> friend class internal::CustomArguments;
315  friend Local<Primitive> Undefined(Isolate* isolate);
316  friend Local<Primitive> Null(Isolate* isolate);
317  friend Local<Boolean> True(Isolate* isolate);
318  friend Local<Boolean> False(Isolate* isolate);
319  friend class HandleScope;
320  friend class EscapableHandleScope;
321  template <class F1, class F2, class F3>
322  friend class PersistentValueMapBase;
323  template<class F1, class F2> friend class PersistentValueVector;
324 
325  template <class S>
326  V8_INLINE Local(S* that)
327  : val_(that) {}
328  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
329  T* val_;
330 };
331 
332 
333 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
334 // Local is an alias for Local for historical reasons.
335 template <class T>
336 using Handle = Local<T>;
337 #endif
338 
339 
350 template <class T>
351 class MaybeLocal {
352  public:
353  V8_INLINE MaybeLocal() : val_(nullptr) {}
354  template <class S>
355  V8_INLINE MaybeLocal(Local<S> that)
356  : val_(reinterpret_cast<T*>(*that)) {
357  TYPE_CHECK(T, S);
358  }
359 
360  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
361 
362  template <class S>
363  V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
364  out->val_ = IsEmpty() ? nullptr : this->val_;
365  return !IsEmpty();
366  }
367 
368  // Will crash if the MaybeLocal<> is empty.
369  V8_INLINE Local<T> ToLocalChecked();
370 
371  template <class S>
372  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
373  return IsEmpty() ? default_value : Local<S>(val_);
374  }
375 
376  private:
377  T* val_;
378 };
379 
380 
381 // Eternal handles are set-once handles that live for the life of the isolate.
382 template <class T> class Eternal {
383  public:
384  V8_INLINE Eternal() : index_(kInitialValue) { }
385  template<class S>
386  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
387  Set(isolate, handle);
388  }
389  // Can only be safely called if already set.
390  V8_INLINE Local<T> Get(Isolate* isolate);
391  V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
392  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
393 
394  private:
395  static const int kInitialValue = -1;
396  int index_;
397 };
398 
399 
400 static const int kInternalFieldsInWeakCallback = 2;
401 
402 
403 template <typename T>
405  public:
406  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
407 
408  WeakCallbackInfo(Isolate* isolate, T* parameter,
409  void* internal_fields[kInternalFieldsInWeakCallback],
410  Callback* callback)
411  : isolate_(isolate), parameter_(parameter), callback_(callback) {
412  for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) {
413  internal_fields_[i] = internal_fields[i];
414  }
415  }
416 
417  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
418  V8_INLINE T* GetParameter() const { return parameter_; }
419  V8_INLINE void* GetInternalField(int index) const;
420 
421  V8_INLINE V8_DEPRECATE_SOON("use indexed version",
422  void* GetInternalField1() const) {
423  return internal_fields_[0];
424  }
425  V8_INLINE V8_DEPRECATE_SOON("use indexed version",
426  void* GetInternalField2() const) {
427  return internal_fields_[1];
428  }
429 
430  bool IsFirstPass() const { return callback_ != nullptr; }
431 
432  // When first called, the embedder MUST Reset() the Global which triggered the
433  // callback. The Global itself is unusable for anything else. No v8 other api
434  // calls may be called in the first callback. Should additional work be
435  // required, the embedder must set a second pass callback, which will be
436  // called after all the initial callbacks are processed.
437  // Calling SetSecondPassCallback on the second pass will immediately crash.
438  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
439 
440  private:
441  Isolate* isolate_;
442  T* parameter_;
443  Callback* callback_;
444  void* internal_fields_[kInternalFieldsInWeakCallback];
445 };
446 
447 
448 template <class T, class P>
450  public:
451  typedef void (*Callback)(const WeakCallbackData<T, P>& data);
452 
453  WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle)
454  : isolate_(isolate), parameter_(parameter), handle_(handle) {}
455 
456  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
457  V8_INLINE P* GetParameter() const { return parameter_; }
458  V8_INLINE Local<T> GetValue() const { return handle_; }
459 
460  private:
461  Isolate* isolate_;
462  P* parameter_;
463  Local<T> handle_;
464 };
465 
466 
467 // TODO(dcarney): delete this with WeakCallbackData
468 template <class T>
470 
471 
472 enum class WeakCallbackType { kParameter, kInternalFields };
473 
474 
488 template <class T> class PersistentBase {
489  public:
494  V8_INLINE void Reset();
499  template <class S>
500  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
501 
506  template <class S>
507  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
508 
509  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
510  V8_INLINE void Empty() { val_ = 0; }
511 
512  V8_INLINE Local<T> Get(Isolate* isolate) const {
513  return Local<T>::New(isolate, *this);
514  }
515 
516  template <class S>
517  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
518  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
519  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
520  if (a == NULL) return b == NULL;
521  if (b == NULL) return false;
522  return *a == *b;
523  }
524 
525  template <class S>
526  V8_INLINE bool operator==(const Local<S>& that) const {
527  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
528  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
529  if (a == NULL) return b == NULL;
530  if (b == NULL) return false;
531  return *a == *b;
532  }
533 
534  template <class S>
535  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
536  return !operator==(that);
537  }
538 
539  template <class S>
540  V8_INLINE bool operator!=(const Local<S>& that) const {
541  return !operator==(that);
542  }
543 
551  template <typename P>
552  V8_INLINE V8_DEPRECATE_SOON(
553  "use WeakCallbackInfo version",
554  void SetWeak(P* parameter,
555  typename WeakCallbackData<T, P>::Callback callback));
556 
557  template <typename S, typename P>
558  V8_INLINE V8_DEPRECATE_SOON(
559  "use WeakCallbackInfo version",
560  void SetWeak(P* parameter,
561  typename WeakCallbackData<S, P>::Callback callback));
562 
563  // Phantom persistents work like weak persistents, except that the pointer to
564  // the object being collected is not available in the finalization callback.
565  // This enables the garbage collector to collect the object and any objects
566  // it references transitively in one GC cycle. At the moment you can either
567  // specify a parameter for the callback or the location of two internal
568  // fields in the dying object.
569  template <typename P>
570  V8_INLINE V8_DEPRECATE_SOON(
571  "use SetWeak",
572  void SetPhantom(P* parameter,
573  typename WeakCallbackInfo<P>::Callback callback,
574  int internal_field_index1 = -1,
575  int internal_field_index2 = -1));
576 
577  template <typename P>
578  V8_INLINE void SetWeak(P* parameter,
579  typename WeakCallbackInfo<P>::Callback callback,
580  WeakCallbackType type);
581 
582  template<typename P>
583  V8_INLINE P* ClearWeak();
584 
585  // TODO(dcarney): remove this.
586  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
587 
594  V8_INLINE void MarkIndependent();
595 
604  V8_INLINE void MarkPartiallyDependent();
605 
606  V8_INLINE bool IsIndependent() const;
607 
609  V8_INLINE bool IsNearDeath() const;
610 
612  V8_INLINE bool IsWeak() const;
613 
618  V8_INLINE void SetWrapperClassId(uint16_t class_id);
619 
624  V8_INLINE uint16_t WrapperClassId() const;
625 
626  private:
627  friend class Isolate;
628  friend class Utils;
629  template<class F> friend class Local;
630  template<class F1, class F2> friend class Persistent;
631  template <class F>
632  friend class Global;
633  template<class F> friend class PersistentBase;
634  template<class F> friend class ReturnValue;
635  template <class F1, class F2, class F3>
636  friend class PersistentValueMapBase;
637  template<class F1, class F2> friend class PersistentValueVector;
638  friend class Object;
639 
640  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
641  PersistentBase(const PersistentBase& other) = delete; // NOLINT
642  void operator=(const PersistentBase&) = delete;
643  V8_INLINE static T* New(Isolate* isolate, T* that);
644 
645  T* val_;
646 };
647 
648 
655 template<class T>
656 class NonCopyablePersistentTraits {
657  public:
658  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
659  static const bool kResetInDestructor = false;
660  template<class S, class M>
661  V8_INLINE static void Copy(const Persistent<S, M>& source,
662  NonCopyablePersistent* dest) {
663  Uncompilable<Object>();
664  }
665  // TODO(dcarney): come up with a good compile error here.
666  template<class O> V8_INLINE static void Uncompilable() {
667  TYPE_CHECK(O, Primitive);
668  }
669 };
670 
671 
676 template<class T>
679  static const bool kResetInDestructor = true;
680  template<class S, class M>
681  static V8_INLINE void Copy(const Persistent<S, M>& source,
682  CopyablePersistent* dest) {
683  // do nothing, just allow copy
684  }
685 };
686 
687 
696 template <class T, class M> class Persistent : public PersistentBase<T> {
697  public:
701  V8_INLINE Persistent() : PersistentBase<T>(0) { }
707  template <class S>
708  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
709  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
710  TYPE_CHECK(T, S);
711  }
717  template <class S, class M2>
718  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
719  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
720  TYPE_CHECK(T, S);
721  }
728  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
729  Copy(that);
730  }
731  template <class S, class M2>
732  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
733  Copy(that);
734  }
735  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
736  Copy(that);
737  return *this;
738  }
739  template <class S, class M2>
740  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
741  Copy(that);
742  return *this;
743  }
749  V8_INLINE ~Persistent() {
750  if (M::kResetInDestructor) this->Reset();
751  }
752 
753  // TODO(dcarney): this is pretty useless, fix or remove
754  template <class S>
755  V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT
756 #ifdef V8_ENABLE_CHECKS
757  // If we're going to perform the type check then we have to check
758  // that the handle isn't empty before doing the checked cast.
759  if (!that.IsEmpty()) T::Cast(*that);
760 #endif
761  return reinterpret_cast<Persistent<T>&>(that);
762  }
763 
764  // TODO(dcarney): this is pretty useless, fix or remove
765  template <class S> V8_INLINE Persistent<S>& As() { // NOLINT
766  return Persistent<S>::Cast(*this);
767  }
768 
769  private:
770  friend class Isolate;
771  friend class Utils;
772  template<class F> friend class Local;
773  template<class F1, class F2> friend class Persistent;
774  template<class F> friend class ReturnValue;
775 
776  template <class S> V8_INLINE Persistent(S* that) : PersistentBase<T>(that) { }
777  V8_INLINE T* operator*() const { return this->val_; }
778  template<class S, class M2>
779  V8_INLINE void Copy(const Persistent<S, M2>& that);
780 };
781 
782 
788 template <class T>
789 class Global : public PersistentBase<T> {
790  public:
794  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
800  template <class S>
801  V8_INLINE Global(Isolate* isolate, Local<S> that)
802  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
803  TYPE_CHECK(T, S);
804  }
810  template <class S>
811  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
812  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
813  TYPE_CHECK(T, S);
814  }
818  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) {
819  other.val_ = nullptr;
820  }
821  V8_INLINE ~Global() { this->Reset(); }
825  template <class S>
826  V8_INLINE Global& operator=(Global<S>&& rhs) {
827  TYPE_CHECK(T, S);
828  if (this != &rhs) {
829  this->Reset();
830  this->val_ = rhs.val_;
831  rhs.val_ = nullptr;
832  }
833  return *this;
834  }
838  Global Pass() { return static_cast<Global&&>(*this); }
839 
840  /*
841  * For compatibility with Chromium's base::Bind (base::Passed).
842  */
843  typedef void MoveOnlyTypeForCPP03;
844 
845  private:
846  template <class F>
847  friend class ReturnValue;
848  Global(const Global&) = delete;
849  void operator=(const Global&) = delete;
850  V8_INLINE T* operator*() const { return this->val_; }
851 };
852 
853 
854 // UniquePersistent is an alias for Global for historical reason.
855 template <class T>
856 using UniquePersistent = Global<T>;
857 
858 
873 class V8_EXPORT HandleScope {
874  public:
875  HandleScope(Isolate* isolate);
876 
877  ~HandleScope();
878 
882  static int NumberOfHandles(Isolate* isolate);
883 
884  V8_INLINE Isolate* GetIsolate() const {
885  return reinterpret_cast<Isolate*>(isolate_);
886  }
887 
888  protected:
889  V8_INLINE HandleScope() {}
890 
891  void Initialize(Isolate* isolate);
892 
893  static internal::Object** CreateHandle(internal::Isolate* isolate,
894  internal::Object* value);
895 
896  private:
897  // Uses heap_object to obtain the current Isolate.
898  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
899  internal::Object* value);
900 
901  // Make it hard to create heap-allocated or illegal handle scopes by
902  // disallowing certain operations.
903  HandleScope(const HandleScope&);
904  void operator=(const HandleScope&);
905  void* operator new(size_t size);
906  void operator delete(void*, size_t);
907 
908  internal::Isolate* isolate_;
909  internal::Object** prev_next_;
910  internal::Object** prev_limit_;
911 
912  // Local::New uses CreateHandle with an Isolate* parameter.
913  template<class F> friend class Local;
914 
915  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
916  // a HeapObject* in their shortcuts.
917  friend class Object;
918  friend class Context;
919 };
920 
921 
926 class V8_EXPORT EscapableHandleScope : public HandleScope {
927  public:
928  EscapableHandleScope(Isolate* isolate);
929  V8_INLINE ~EscapableHandleScope() {}
930 
935  template <class T>
936  V8_INLINE Local<T> Escape(Local<T> value) {
937  internal::Object** slot =
938  Escape(reinterpret_cast<internal::Object**>(*value));
939  return Local<T>(reinterpret_cast<T*>(slot));
940  }
941 
942  private:
943  internal::Object** Escape(internal::Object** escape_value);
944 
945  // Make it hard to create heap-allocated or illegal handle scopes by
946  // disallowing certain operations.
948  void operator=(const EscapableHandleScope&);
949  void* operator new(size_t size);
950  void operator delete(void*, size_t);
951 
952  internal::Object** escape_slot_;
953 };
954 
955 class V8_EXPORT SealHandleScope {
956  public:
957  SealHandleScope(Isolate* isolate);
958  ~SealHandleScope();
959 
960  private:
961  // Make it hard to create heap-allocated or illegal handle scopes by
962  // disallowing certain operations.
964  void operator=(const SealHandleScope&);
965  void* operator new(size_t size);
966  void operator delete(void*, size_t);
967 
968  internal::Isolate* isolate_;
969  int prev_level_;
970  internal::Object** prev_limit_;
971 };
972 
973 
974 // --- Special objects ---
975 
976 
980 class V8_EXPORT Data {
981  private:
982  Data();
983 };
984 
985 
990  public:
991  V8_INLINE ScriptOriginOptions(bool is_embedder_debug_script = false,
992  bool is_shared_cross_origin = false,
993  bool is_opaque = false)
994  : flags_((is_embedder_debug_script ? kIsEmbedderDebugScript : 0) |
995  (is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
996  (is_opaque ? kIsOpaque : 0)) {}
997  V8_INLINE ScriptOriginOptions(int flags)
998  : flags_(flags &
999  (kIsEmbedderDebugScript | kIsSharedCrossOrigin | kIsOpaque)) {}
1000  bool IsEmbedderDebugScript() const {
1001  return (flags_ & kIsEmbedderDebugScript) != 0;
1002  }
1003  bool IsSharedCrossOrigin() const {
1004  return (flags_ & kIsSharedCrossOrigin) != 0;
1005  }
1006  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1007  int Flags() const { return flags_; }
1008 
1009  private:
1010  enum {
1011  kIsEmbedderDebugScript = 1,
1012  kIsSharedCrossOrigin = 1 << 1,
1013  kIsOpaque = 1 << 2
1014  };
1015  const int flags_;
1016 };
1017 
1022  public:
1023  V8_INLINE ScriptOrigin(
1024  Local<Value> resource_name,
1025  Local<Integer> resource_line_offset = Local<Integer>(),
1026  Local<Integer> resource_column_offset = Local<Integer>(),
1027  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1028  Local<Integer> script_id = Local<Integer>(),
1029  Local<Boolean> resource_is_embedder_debug_script = Local<Boolean>(),
1030  Local<Value> source_map_url = Local<Value>(),
1031  Local<Boolean> resource_is_opaque = Local<Boolean>());
1032  V8_INLINE Local<Value> ResourceName() const;
1033  V8_INLINE Local<Integer> ResourceLineOffset() const;
1034  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1038  V8_INLINE Local<Integer> ScriptID() const;
1039  V8_INLINE Local<Value> SourceMapUrl() const;
1040  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1041 
1042  private:
1043  Local<Value> resource_name_;
1044  Local<Integer> resource_line_offset_;
1045  Local<Integer> resource_column_offset_;
1046  ScriptOriginOptions options_;
1047  Local<Integer> script_id_;
1048  Local<Value> source_map_url_;
1049 };
1050 
1051 
1055 class V8_EXPORT UnboundScript {
1056  public:
1060  Local<Script> BindToCurrentContext();
1061 
1062  int GetId();
1063  Local<Value> GetScriptName();
1064 
1068  Local<Value> GetSourceURL();
1072  Local<Value> GetSourceMappingURL();
1073 
1078  int GetLineNumber(int code_pos);
1079 
1080  static const int kNoScriptId = 0;
1081 };
1082 
1083 
1088 class V8_EXPORT Script {
1089  public:
1093  static V8_DEPRECATE_SOON(
1094  "Use maybe version",
1095  Local<Script> Compile(Local<String> source,
1096  ScriptOrigin* origin = nullptr));
1097  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1098  Local<Context> context, Local<String> source,
1099  ScriptOrigin* origin = nullptr);
1100 
1101  static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
1102  Compile(Local<String> source,
1103  Local<String> file_name));
1104 
1110  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
1111  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1112 
1116  Local<UnboundScript> GetUnboundScript();
1117 };
1118 
1119 
1123 class V8_EXPORT ScriptCompiler {
1124  public:
1132  struct V8_EXPORT CachedData {
1133  enum BufferPolicy {
1134  BufferNotOwned,
1135  BufferOwned
1136  };
1137 
1138  CachedData()
1139  : data(NULL),
1140  length(0),
1141  rejected(false),
1142  buffer_policy(BufferNotOwned) {}
1143 
1144  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1145  // data and guarantees that it stays alive until the CachedData object is
1146  // destroyed. If the policy is BufferOwned, the given data will be deleted
1147  // (with delete[]) when the CachedData object is destroyed.
1148  CachedData(const uint8_t* data, int length,
1149  BufferPolicy buffer_policy = BufferNotOwned);
1150  ~CachedData();
1151  // TODO(marja): Async compilation; add constructors which take a callback
1152  // which will be called when V8 no longer needs the data.
1153  const uint8_t* data;
1154  int length;
1155  bool rejected;
1156  BufferPolicy buffer_policy;
1157 
1158  private:
1159  // Prevent copying. Not implemented.
1160  CachedData(const CachedData&);
1161  CachedData& operator=(const CachedData&);
1162  };
1163 
1167  class Source {
1168  public:
1169  // Source takes ownership of CachedData.
1170  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1171  CachedData* cached_data = NULL);
1172  V8_INLINE Source(Local<String> source_string,
1173  CachedData* cached_data = NULL);
1174  V8_INLINE ~Source();
1175 
1176  // Ownership of the CachedData or its buffers is *not* transferred to the
1177  // caller. The CachedData object is alive as long as the Source object is
1178  // alive.
1179  V8_INLINE const CachedData* GetCachedData() const;
1180 
1181  private:
1182  friend class ScriptCompiler;
1183  // Prevent copying. Not implemented.
1184  Source(const Source&);
1185  Source& operator=(const Source&);
1186 
1187  Local<String> source_string;
1188 
1189  // Origin information
1190  Local<Value> resource_name;
1191  Local<Integer> resource_line_offset;
1192  Local<Integer> resource_column_offset;
1193  ScriptOriginOptions resource_options;
1194  Local<Value> source_map_url;
1195 
1196  // Cached data from previous compilation (if a kConsume*Cache flag is
1197  // set), or hold newly generated cache data (kProduce*Cache flags) are
1198  // set when calling a compile method.
1199  CachedData* cached_data;
1200  };
1201 
1206  class V8_EXPORT ExternalSourceStream {
1207  public:
1208  virtual ~ExternalSourceStream() {}
1209 
1227  virtual size_t GetMoreData(const uint8_t** src) = 0;
1228 
1239  virtual bool SetBookmark();
1240 
1244  virtual void ResetToBookmark();
1245  };
1246 
1247 
1254  class V8_EXPORT StreamedSource {
1255  public:
1256  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1257 
1258  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1259  ~StreamedSource();
1260 
1261  // Ownership of the CachedData or its buffers is *not* transferred to the
1262  // caller. The CachedData object is alive as long as the StreamedSource
1263  // object is alive.
1264  const CachedData* GetCachedData() const;
1265 
1266  internal::StreamedSource* impl() const { return impl_; }
1267 
1268  private:
1269  // Prevent copying. Not implemented.
1271  StreamedSource& operator=(const StreamedSource&);
1272 
1273  internal::StreamedSource* impl_;
1274  };
1275 
1281  public:
1282  virtual ~ScriptStreamingTask() {}
1283  virtual void Run() = 0;
1284  };
1285 
1286  enum CompileOptions {
1287  kNoCompileOptions = 0,
1288  kProduceParserCache,
1289  kConsumeParserCache,
1290  kProduceCodeCache,
1291  kConsumeCodeCache
1292  };
1293 
1307  static V8_DEPRECATE_SOON("Use maybe version",
1308  Local<UnboundScript> CompileUnbound(
1309  Isolate* isolate, Source* source,
1310  CompileOptions options = kNoCompileOptions));
1311  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1312  Isolate* isolate, Source* source,
1313  CompileOptions options = kNoCompileOptions);
1314 
1326  static V8_DEPRECATE_SOON(
1327  "Use maybe version",
1328  Local<Script> Compile(Isolate* isolate, Source* source,
1329  CompileOptions options = kNoCompileOptions));
1330  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1331  Local<Context> context, Source* source,
1332  CompileOptions options = kNoCompileOptions);
1333 
1345  static ScriptStreamingTask* StartStreamingScript(
1346  Isolate* isolate, StreamedSource* source,
1347  CompileOptions options = kNoCompileOptions);
1348 
1356  static V8_DEPRECATE_SOON(
1357  "Use maybe version",
1358  Local<Script> Compile(Isolate* isolate, StreamedSource* source,
1359  Local<String> full_source_string,
1360  const ScriptOrigin& origin));
1361  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1362  Local<Context> context, StreamedSource* source,
1363  Local<String> full_source_string, const ScriptOrigin& origin);
1364 
1383  static uint32_t CachedDataVersionTag();
1384 
1395  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> CompileModule(
1396  Local<Context> context, Source* source,
1397  CompileOptions options = kNoCompileOptions);
1398 
1409  static V8_DEPRECATE_SOON("Use maybe version",
1410  Local<Function> CompileFunctionInContext(
1411  Isolate* isolate, Source* source,
1412  Local<Context> context, size_t arguments_count,
1413  Local<String> arguments[],
1414  size_t context_extension_count,
1415  Local<Object> context_extensions[]));
1416  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1417  Local<Context> context, Source* source, size_t arguments_count,
1418  Local<String> arguments[], size_t context_extension_count,
1419  Local<Object> context_extensions[]);
1420 
1421  private:
1422  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1423  Isolate* isolate, Source* source, CompileOptions options, bool is_module);
1424 };
1425 
1426 
1430 class V8_EXPORT Message {
1431  public:
1432  Local<String> Get() const;
1433 
1434  V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
1435  V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
1436  Local<Context> context) const;
1437 
1442  ScriptOrigin GetScriptOrigin() const;
1443 
1448  Local<Value> GetScriptResourceName() const;
1449 
1455  Local<StackTrace> GetStackTrace() const;
1456 
1460  V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
1461  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1462 
1467  int GetStartPosition() const;
1468 
1473  int GetEndPosition() const;
1474 
1479  V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
1480  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1481 
1486  V8_DEPRECATE_SOON("Use maybe version", int GetEndColumn() const);
1487  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1488 
1493  bool IsSharedCrossOrigin() const;
1494  bool IsOpaque() const;
1495 
1496  // TODO(1245381): Print to a string instead of on a FILE.
1497  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1498 
1499  static const int kNoLineNumberInfo = 0;
1500  static const int kNoColumnInfo = 0;
1501  static const int kNoScriptIdInfo = 0;
1502 };
1503 
1504 
1510 class V8_EXPORT StackTrace {
1511  public:
1517  kLineNumber = 1,
1518  kColumnOffset = 1 << 1 | kLineNumber,
1519  kScriptName = 1 << 2,
1520  kFunctionName = 1 << 3,
1521  kIsEval = 1 << 4,
1522  kIsConstructor = 1 << 5,
1523  kScriptNameOrSourceURL = 1 << 6,
1524  kScriptId = 1 << 7,
1525  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1526  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1527  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1528  };
1529 
1533  Local<StackFrame> GetFrame(uint32_t index) const;
1534 
1538  int GetFrameCount() const;
1539 
1543  Local<Array> AsArray();
1544 
1552  static Local<StackTrace> CurrentStackTrace(
1553  Isolate* isolate,
1554  int frame_limit,
1555  StackTraceOptions options = kOverview);
1556 };
1557 
1558 
1562 class V8_EXPORT StackFrame {
1563  public:
1570  int GetLineNumber() const;
1571 
1579  int GetColumn() const;
1580 
1587  int GetScriptId() const;
1588 
1593  Local<String> GetScriptName() const;
1594 
1601  Local<String> GetScriptNameOrSourceURL() const;
1602 
1606  Local<String> GetFunctionName() const;
1607 
1612  bool IsEval() const;
1613 
1618  bool IsConstructor() const;
1619 };
1620 
1621 
1622 // A StateTag represents a possible state of the VM.
1623 enum StateTag { JS, GC, COMPILER, OTHER, EXTERNAL, IDLE };
1624 
1625 
1626 // A RegisterState represents the current state of registers used
1627 // by the sampling profiler API.
1629  RegisterState() : pc(NULL), sp(NULL), fp(NULL) {}
1630  void* pc; // Instruction pointer.
1631  void* sp; // Stack pointer.
1632  void* fp; // Frame pointer.
1633 };
1634 
1635 
1636 // The output structure filled up by GetStackSample API function.
1637 struct SampleInfo {
1638  size_t frames_count;
1639  StateTag vm_state;
1640 };
1641 
1642 
1646 class V8_EXPORT JSON {
1647  public:
1655  static V8_DEPRECATE_SOON("Use maybe version",
1656  Local<Value> Parse(Local<String> json_string));
1657  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1658  Isolate* isolate, Local<String> json_string);
1659 };
1660 
1661 
1667 class V8_EXPORT NativeWeakMap : public Data {
1668  public:
1669  static Local<NativeWeakMap> New(Isolate* isolate);
1670  void Set(Local<Value> key, Local<Value> value);
1671  Local<Value> Get(Local<Value> key);
1672  bool Has(Local<Value> key);
1673  bool Delete(Local<Value> key);
1674 };
1675 
1676 
1677 // --- Value ---
1678 
1679 
1683 class V8_EXPORT Value : public Data {
1684  public:
1689  V8_INLINE bool IsUndefined() const;
1690 
1695  V8_INLINE bool IsNull() const;
1696 
1700  bool IsTrue() const;
1701 
1705  bool IsFalse() const;
1706 
1711  bool IsName() const;
1712 
1717  V8_INLINE bool IsString() const;
1718 
1723  bool IsSymbol() const;
1724 
1728  bool IsFunction() const;
1729 
1733  bool IsArray() const;
1734 
1738  bool IsObject() const;
1739 
1743  bool IsBoolean() const;
1744 
1748  bool IsNumber() const;
1749 
1753  bool IsExternal() const;
1754 
1758  bool IsInt32() const;
1759 
1763  bool IsUint32() const;
1764 
1768  bool IsDate() const;
1769 
1773  bool IsArgumentsObject() const;
1774 
1778  bool IsBooleanObject() const;
1779 
1783  bool IsNumberObject() const;
1784 
1788  bool IsStringObject() const;
1789 
1794  bool IsSymbolObject() const;
1795 
1799  bool IsNativeError() const;
1800 
1804  bool IsRegExp() const;
1805 
1810  bool IsGeneratorFunction() const;
1811 
1816  bool IsGeneratorObject() const;
1817 
1822  bool IsPromise() const;
1823 
1827  bool IsMap() const;
1828 
1832  bool IsSet() const;
1833 
1837  bool IsMapIterator() const;
1838 
1842  bool IsSetIterator() const;
1843 
1847  bool IsWeakMap() const;
1848 
1852  bool IsWeakSet() const;
1853 
1858  bool IsArrayBuffer() const;
1859 
1864  bool IsArrayBufferView() const;
1865 
1870  bool IsTypedArray() const;
1871 
1876  bool IsUint8Array() const;
1877 
1882  bool IsUint8ClampedArray() const;
1883 
1888  bool IsInt8Array() const;
1889 
1894  bool IsUint16Array() const;
1895 
1900  bool IsInt16Array() const;
1901 
1906  bool IsUint32Array() const;
1907 
1912  bool IsInt32Array() const;
1913 
1918  bool IsFloat32Array() const;
1919 
1924  bool IsFloat64Array() const;
1925 
1930  bool IsFloat32x4() const;
1931 
1936  bool IsDataView() const;
1937 
1942  bool IsSharedArrayBuffer() const;
1943 
1944 
1945  V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
1946  Local<Context> context) const;
1947  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
1948  Local<Context> context) const;
1949  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
1950  Local<Context> context) const;
1951  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
1952  Local<Context> context) const;
1953  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
1954  Local<Context> context) const;
1955  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
1956  Local<Context> context) const;
1957  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
1958  Local<Context> context) const;
1959  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
1960 
1961  V8_DEPRECATE_SOON("Use maybe version",
1962  Local<Boolean> ToBoolean(Isolate* isolate) const);
1963  V8_DEPRECATE_SOON("Use maybe version",
1964  Local<Number> ToNumber(Isolate* isolate) const);
1965  V8_DEPRECATE_SOON("Use maybe version",
1966  Local<String> ToString(Isolate* isolate) const);
1967  V8_DEPRECATE_SOON("Use maybe version",
1968  Local<String> ToDetailString(Isolate* isolate) const);
1969  V8_DEPRECATE_SOON("Use maybe version",
1970  Local<Object> ToObject(Isolate* isolate) const);
1971  V8_DEPRECATE_SOON("Use maybe version",
1972  Local<Integer> ToInteger(Isolate* isolate) const);
1973  V8_DEPRECATE_SOON("Use maybe version",
1974  Local<Uint32> ToUint32(Isolate* isolate) const);
1975  V8_DEPRECATE_SOON("Use maybe version",
1976  Local<Int32> ToInt32(Isolate* isolate) const);
1977 
1978  inline V8_DEPRECATE_SOON("Use maybe version",
1979  Local<Boolean> ToBoolean() const);
1980  inline V8_DEPRECATE_SOON("Use maybe version", Local<Number> ToNumber() const);
1981  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
1982  inline V8_DEPRECATE_SOON("Use maybe version",
1983  Local<String> ToDetailString() const);
1984  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
1985  inline V8_DEPRECATE_SOON("Use maybe version",
1986  Local<Integer> ToInteger() const);
1987  inline V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToUint32() const);
1988  inline V8_DEPRECATE_SOON("Use maybe version", Local<Int32> ToInt32() const);
1989 
1994  V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToArrayIndex() const);
1995  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
1996  Local<Context> context) const;
1997 
1998  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
1999  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2000  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2001  Local<Context> context) const;
2002  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2003  Local<Context> context) const;
2004  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2005 
2006  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2007  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2008  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2009  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2010  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2011 
2013  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2014  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2015  Local<Value> that) const;
2016  bool StrictEquals(Local<Value> that) const;
2017  bool SameValue(Local<Value> that) const;
2018 
2019  template <class T> V8_INLINE static Value* Cast(T* value);
2020 
2021  private:
2022  V8_INLINE bool QuickIsUndefined() const;
2023  V8_INLINE bool QuickIsNull() const;
2024  V8_INLINE bool QuickIsString() const;
2025  bool FullIsUndefined() const;
2026  bool FullIsNull() const;
2027  bool FullIsString() const;
2028 };
2029 
2030 
2034 class V8_EXPORT Primitive : public Value { };
2035 
2036 
2041 class V8_EXPORT Boolean : public Primitive {
2042  public:
2043  bool Value() const;
2044  V8_INLINE static Boolean* Cast(v8::Value* obj);
2045  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2046 
2047  private:
2048  static void CheckCast(v8::Value* obj);
2049 };
2050 
2051 
2055 class V8_EXPORT Name : public Primitive {
2056  public:
2064  int GetIdentityHash();
2065 
2066  V8_INLINE static Name* Cast(v8::Value* obj);
2067  private:
2068  static void CheckCast(v8::Value* obj);
2069 };
2070 
2071 
2072 enum class NewStringType { kNormal, kInternalized };
2073 
2074 
2078 class V8_EXPORT String : public Name {
2079  public:
2080  static const int kMaxLength = (1 << 28) - 16;
2081 
2082  enum Encoding {
2083  UNKNOWN_ENCODING = 0x1,
2084  TWO_BYTE_ENCODING = 0x0,
2085  ONE_BYTE_ENCODING = 0x4
2086  };
2090  int Length() const;
2091 
2096  int Utf8Length() const;
2097 
2103  bool IsOneByte() const;
2104 
2109  bool ContainsOnlyOneByte() const;
2110 
2137  NO_OPTIONS = 0,
2138  HINT_MANY_WRITES_EXPECTED = 1,
2139  NO_NULL_TERMINATION = 2,
2140  PRESERVE_ONE_BYTE_NULL = 4,
2141  // Used by WriteUtf8 to replace orphan surrogate code units with the
2142  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2143  // output.
2144  REPLACE_INVALID_UTF8 = 8
2145  };
2146 
2147  // 16-bit character codes.
2148  int Write(uint16_t* buffer,
2149  int start = 0,
2150  int length = -1,
2151  int options = NO_OPTIONS) const;
2152  // One byte characters.
2153  int WriteOneByte(uint8_t* buffer,
2154  int start = 0,
2155  int length = -1,
2156  int options = NO_OPTIONS) const;
2157  // UTF-8 encoded characters.
2158  int WriteUtf8(char* buffer,
2159  int length = -1,
2160  int* nchars_ref = NULL,
2161  int options = NO_OPTIONS) const;
2162 
2166  V8_INLINE static v8::Local<v8::String> Empty(Isolate* isolate);
2167 
2171  bool IsExternal() const;
2172 
2176  bool IsExternalOneByte() const;
2177 
2178  class V8_EXPORT ExternalStringResourceBase { // NOLINT
2179  public:
2180  virtual ~ExternalStringResourceBase() {}
2181 
2182  protected:
2184 
2191  virtual void Dispose() { delete this; }
2192 
2193  private:
2194  // Disallow copying and assigning.
2196  void operator=(const ExternalStringResourceBase&);
2197 
2198  friend class v8::internal::Heap;
2199  };
2200 
2207  class V8_EXPORT ExternalStringResource
2208  : public ExternalStringResourceBase {
2209  public:
2215 
2219  virtual const uint16_t* data() const = 0;
2220 
2224  virtual size_t length() const = 0;
2225 
2226  protected:
2228  };
2229 
2241  : public ExternalStringResourceBase {
2242  public:
2249  virtual const char* data() const = 0;
2251  virtual size_t length() const = 0;
2252  protected:
2254  };
2255 
2261  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2262  Encoding* encoding_out) const;
2263 
2268  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2269 
2274  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2275 
2276  V8_INLINE static String* Cast(v8::Value* obj);
2277 
2278  // TODO(dcarney): remove with deprecation of New functions.
2279  enum NewStringType {
2280  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2281  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2282  };
2283 
2285  static V8_DEPRECATE_SOON(
2286  "Use maybe version",
2287  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2288  NewStringType type = kNormalString,
2289  int length = -1));
2290 
2293  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2294  Isolate* isolate, const char* data, v8::NewStringType type,
2295  int length = -1);
2296 
2298  static V8_DEPRECATE_SOON(
2299  "Use maybe version",
2300  Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2301  NewStringType type = kNormalString,
2302  int length = -1));
2303 
2306  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2307  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2308  int length = -1);
2309 
2311  static V8_DEPRECATE_SOON(
2312  "Use maybe version",
2313  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2314  NewStringType type = kNormalString,
2315  int length = -1));
2316 
2319  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2320  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2321  int length = -1);
2322 
2327  static Local<String> Concat(Local<String> left, Local<String> right);
2328 
2337  static V8_DEPRECATE_SOON(
2338  "Use maybe version",
2339  Local<String> NewExternal(Isolate* isolate,
2340  ExternalStringResource* resource));
2341  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2342  Isolate* isolate, ExternalStringResource* resource);
2343 
2353  bool MakeExternal(ExternalStringResource* resource);
2354 
2363  static V8_DEPRECATE_SOON(
2364  "Use maybe version",
2365  Local<String> NewExternal(Isolate* isolate,
2366  ExternalOneByteStringResource* resource));
2367  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2368  Isolate* isolate, ExternalOneByteStringResource* resource);
2369 
2379  bool MakeExternal(ExternalOneByteStringResource* resource);
2380 
2384  bool CanMakeExternal();
2385 
2393  class V8_EXPORT Utf8Value {
2394  public:
2395  explicit Utf8Value(Local<v8::Value> obj);
2396  ~Utf8Value();
2397  char* operator*() { return str_; }
2398  const char* operator*() const { return str_; }
2399  int length() const { return length_; }
2400  private:
2401  char* str_;
2402  int length_;
2403 
2404  // Disallow copying and assigning.
2405  Utf8Value(const Utf8Value&);
2406  void operator=(const Utf8Value&);
2407  };
2408 
2415  class V8_EXPORT Value {
2416  public:
2417  explicit Value(Local<v8::Value> obj);
2418  ~Value();
2419  uint16_t* operator*() { return str_; }
2420  const uint16_t* operator*() const { return str_; }
2421  int length() const { return length_; }
2422  private:
2423  uint16_t* str_;
2424  int length_;
2425 
2426  // Disallow copying and assigning.
2427  Value(const Value&);
2428  void operator=(const Value&);
2429  };
2430 
2431  private:
2432  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2433  Encoding encoding) const;
2434  void VerifyExternalStringResource(ExternalStringResource* val) const;
2435  static void CheckCast(v8::Value* obj);
2436 };
2437 
2438 
2444 class V8_EXPORT Symbol : public Name {
2445  public:
2446  // Returns the print name string of the symbol, or undefined if none.
2447  Local<Value> Name() const;
2448 
2449  // Create a symbol. If name is not empty, it will be used as the description.
2450  static Local<Symbol> New(
2451  Isolate *isolate, Local<String> name = Local<String>());
2452 
2453  // Access global symbol registry.
2454  // Note that symbols created this way are never collected, so
2455  // they should only be used for statically fixed properties.
2456  // Also, there is only one global name space for the names used as keys.
2457  // To minimize the potential for clashes, use qualified names as keys.
2458  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2459 
2460  // Retrieve a global symbol. Similar to |For|, but using a separate
2461  // registry that is not accessible by (and cannot clash with) JavaScript code.
2462  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2463 
2464  // Well-known symbols
2465  static Local<Symbol> GetIterator(Isolate* isolate);
2466  static Local<Symbol> GetUnscopables(Isolate* isolate);
2467  static Local<Symbol> GetToStringTag(Isolate* isolate);
2468 
2469  V8_INLINE static Symbol* Cast(v8::Value* obj);
2470 
2471  private:
2472  Symbol();
2473  static void CheckCast(v8::Value* obj);
2474 };
2475 
2476 
2480 class V8_EXPORT Number : public Primitive {
2481  public:
2482  double Value() const;
2483  static Local<Number> New(Isolate* isolate, double value);
2484  V8_INLINE static Number* Cast(v8::Value* obj);
2485  private:
2486  Number();
2487  static void CheckCast(v8::Value* obj);
2488 };
2489 
2490 
2494 class V8_EXPORT Integer : public Number {
2495  public:
2496  static Local<Integer> New(Isolate* isolate, int32_t value);
2497  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2498  int64_t Value() const;
2499  V8_INLINE static Integer* Cast(v8::Value* obj);
2500  private:
2501  Integer();
2502  static void CheckCast(v8::Value* obj);
2503 };
2504 
2505 
2509 class V8_EXPORT Int32 : public Integer {
2510  public:
2511  int32_t Value() const;
2512  V8_INLINE static Int32* Cast(v8::Value* obj);
2513 
2514  private:
2515  Int32();
2516  static void CheckCast(v8::Value* obj);
2517 };
2518 
2519 
2523 class V8_EXPORT Uint32 : public Integer {
2524  public:
2525  uint32_t Value() const;
2526  V8_INLINE static Uint32* Cast(v8::Value* obj);
2527 
2528  private:
2529  Uint32();
2530  static void CheckCast(v8::Value* obj);
2531 };
2532 
2533 
2534 enum PropertyAttribute {
2535  None = 0,
2536  ReadOnly = 1 << 0,
2537  DontEnum = 1 << 1,
2538  DontDelete = 1 << 2
2539 };
2540 
2546 typedef void (*AccessorGetterCallback)(
2547  Local<String> property,
2548  const PropertyCallbackInfo<Value>& info);
2549 typedef void (*AccessorNameGetterCallback)(
2550  Local<Name> property,
2551  const PropertyCallbackInfo<Value>& info);
2552 
2553 
2554 typedef void (*AccessorSetterCallback)(
2555  Local<String> property,
2556  Local<Value> value,
2557  const PropertyCallbackInfo<void>& info);
2558 typedef void (*AccessorNameSetterCallback)(
2559  Local<Name> property,
2560  Local<Value> value,
2561  const PropertyCallbackInfo<void>& info);
2562 
2563 
2574  DEFAULT = 0,
2575  ALL_CAN_READ = 1,
2576  ALL_CAN_WRITE = 1 << 1,
2577  PROHIBITS_OVERWRITING = 1 << 2
2578 };
2579 
2580 
2584 class V8_EXPORT Object : public Value {
2585  public:
2586  V8_DEPRECATE_SOON("Use maybe version",
2587  bool Set(Local<Value> key, Local<Value> value));
2588  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
2589  Local<Value> key, Local<Value> value);
2590 
2591  V8_DEPRECATE_SOON("Use maybe version",
2592  bool Set(uint32_t index, Local<Value> value));
2593  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
2594  Local<Value> value);
2595 
2596  // Implements CreateDataProperty (ECMA-262, 7.3.4).
2597  //
2598  // Defines a configurable, writable, enumerable property with the given value
2599  // on the object unless the property already exists and is not configurable
2600  // or the object is not extensible.
2601  //
2602  // Returns true on success.
2603  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2604  Local<Name> key,
2605  Local<Value> value);
2606  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2607  uint32_t index,
2608  Local<Value> value);
2609 
2610  // Implements DefineOwnProperty.
2611  //
2612  // In general, CreateDataProperty will be faster, however, does not allow
2613  // for specifying attributes.
2614  //
2615  // Returns true on success.
2616  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
2617  Local<Context> context, Local<Name> key, Local<Value> value,
2618  PropertyAttribute attributes = None);
2619 
2620  // Sets an own property on this object bypassing interceptors and
2621  // overriding accessors or read-only properties.
2622  //
2623  // Note that if the object has an interceptor the property will be set
2624  // locally, but since the interceptor takes precedence the local property
2625  // will only be returned if the interceptor doesn't return a value.
2626  //
2627  // Note also that this only works for named properties.
2628  V8_DEPRECATE_SOON("Use CreateDataProperty",
2629  bool ForceSet(Local<Value> key, Local<Value> value,
2630  PropertyAttribute attribs = None));
2631  V8_DEPRECATE_SOON("Use CreateDataProperty",
2632  Maybe<bool> ForceSet(Local<Context> context,
2633  Local<Value> key, Local<Value> value,
2634  PropertyAttribute attribs = None));
2635 
2636  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
2637  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2638  Local<Value> key);
2639 
2640  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
2641  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2642  uint32_t index);
2643 
2649  V8_DEPRECATE_SOON("Use maybe version",
2650  PropertyAttribute GetPropertyAttributes(Local<Value> key));
2651  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
2652  Local<Context> context, Local<Value> key);
2653 
2657  V8_DEPRECATE_SOON("Use maybe version",
2658  Local<Value> GetOwnPropertyDescriptor(Local<String> key));
2659  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
2660  Local<Context> context, Local<String> key);
2661 
2662  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
2663  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
2664  Local<Value> key);
2665 
2666  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
2667  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2668  Maybe<bool> Delete(Local<Context> context, Local<Value> key);
2669 
2670  V8_DEPRECATE_SOON("Use maybe version", bool Has(uint32_t index));
2671  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
2672 
2673  V8_DEPRECATE_SOON("Use maybe version", bool Delete(uint32_t index));
2674  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2675  Maybe<bool> Delete(Local<Context> context, uint32_t index);
2676 
2677  V8_DEPRECATE_SOON("Use maybe version",
2678  bool SetAccessor(Local<String> name,
2679  AccessorGetterCallback getter,
2680  AccessorSetterCallback setter = 0,
2681  Local<Value> data = Local<Value>(),
2682  AccessControl settings = DEFAULT,
2683  PropertyAttribute attribute = None));
2684  V8_DEPRECATE_SOON("Use maybe version",
2685  bool SetAccessor(Local<Name> name,
2686  AccessorNameGetterCallback getter,
2687  AccessorNameSetterCallback setter = 0,
2688  Local<Value> data = Local<Value>(),
2689  AccessControl settings = DEFAULT,
2690  PropertyAttribute attribute = None));
2691  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2692  Maybe<bool> SetAccessor(Local<Context> context, Local<Name> name,
2693  AccessorNameGetterCallback getter,
2694  AccessorNameSetterCallback setter = 0,
2696  AccessControl settings = DEFAULT,
2697  PropertyAttribute attribute = None);
2698 
2699  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
2700  Local<Function> setter = Local<Function>(),
2701  PropertyAttribute attribute = None,
2702  AccessControl settings = DEFAULT);
2703 
2710  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
2711  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
2712  Local<Context> context);
2713 
2719  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
2720  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
2721  Local<Context> context);
2722 
2728  Local<Value> GetPrototype();
2729 
2735  V8_DEPRECATE_SOON("Use maybe version",
2736  bool SetPrototype(Local<Value> prototype));
2737  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
2738  Local<Value> prototype);
2739 
2744  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
2745 
2751  V8_DEPRECATE_SOON("Use maybe version", Local<String> ObjectProtoToString());
2752  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
2753  Local<Context> context);
2754 
2758  Local<String> GetConstructorName();
2759 
2761  int InternalFieldCount();
2762 
2764  V8_INLINE static int InternalFieldCount(
2765  const PersistentBase<Object>& object) {
2766  return object.val_->InternalFieldCount();
2767  }
2768 
2770  V8_INLINE Local<Value> GetInternalField(int index);
2771 
2773  void SetInternalField(int index, Local<Value> value);
2774 
2780  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
2781 
2783  V8_INLINE static void* GetAlignedPointerFromInternalField(
2784  const PersistentBase<Object>& object, int index) {
2785  return object.val_->GetAlignedPointerFromInternalField(index);
2786  }
2787 
2793  void SetAlignedPointerInInternalField(int index, void* value);
2794 
2795  // Testers for local properties.
2796  V8_DEPRECATE_SOON("Use maybe version",
2797  bool HasOwnProperty(Local<String> key));
2798  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
2799  Local<Name> key);
2800  V8_DEPRECATE_SOON("Use maybe version",
2801  bool HasRealNamedProperty(Local<String> key));
2802  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
2803  Local<Name> key);
2804  V8_DEPRECATE_SOON("Use maybe version",
2805  bool HasRealIndexedProperty(uint32_t index));
2806  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
2807  Local<Context> context, uint32_t index);
2808  V8_DEPRECATE_SOON("Use maybe version",
2809  bool HasRealNamedCallbackProperty(Local<String> key));
2810  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
2811  Local<Context> context, Local<Name> key);
2812 
2817  V8_DEPRECATE_SOON(
2818  "Use maybe version",
2819  Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
2820  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
2821  Local<Context> context, Local<Name> key);
2822 
2828  V8_DEPRECATE_SOON(
2829  "Use maybe version",
2830  Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
2831  Local<String> key));
2832  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
2833  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
2834  Local<Name> key);
2835 
2841  V8_DEPRECATE_SOON("Use maybe version",
2842  Local<Value> GetRealNamedProperty(Local<String> key));
2843  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
2844  Local<Context> context, Local<Name> key);
2845 
2851  V8_DEPRECATE_SOON("Use maybe version",
2852  Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
2853  Local<String> key));
2854  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
2855  Local<Context> context, Local<Name> key);
2856 
2858  bool HasNamedLookupInterceptor();
2859 
2861  bool HasIndexedLookupInterceptor();
2862 
2870  int GetIdentityHash();
2871 
2878  // TODO(dcarney): convert these to take a isolate and optionally bailout?
2879  bool SetHiddenValue(Local<String> key, Local<Value> value);
2880  Local<Value> GetHiddenValue(Local<String> key);
2881  bool DeleteHiddenValue(Local<String> key);
2882 
2887  // TODO(dcarney): take an isolate and optionally bail out?
2888  Local<Object> Clone();
2889 
2893  Local<Context> CreationContext();
2894 
2900  bool IsCallable();
2901 
2906  V8_DEPRECATE_SOON("Use maybe version",
2907  Local<Value> CallAsFunction(Local<Value> recv, int argc,
2908  Local<Value> argv[]));
2909  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
2910  Local<Value> recv,
2911  int argc,
2912  Local<Value> argv[]);
2913 
2919  V8_DEPRECATE_SOON("Use maybe version",
2920  Local<Value> CallAsConstructor(int argc,
2921  Local<Value> argv[]));
2922  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
2923  Local<Context> context, int argc, Local<Value> argv[]);
2924 
2928  V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
2929 
2930  static Local<Object> New(Isolate* isolate);
2931 
2932  V8_INLINE static Object* Cast(Value* obj);
2933 
2934  private:
2935  Object();
2936  static void CheckCast(Value* obj);
2937  Local<Value> SlowGetInternalField(int index);
2938  void* SlowGetAlignedPointerFromInternalField(int index);
2939 };
2940 
2941 
2945 class V8_EXPORT Array : public Object {
2946  public:
2947  uint32_t Length() const;
2948 
2953  V8_DEPRECATE_SOON("Use maybe version",
2954  Local<Object> CloneElementAt(uint32_t index));
2955  V8_WARN_UNUSED_RESULT MaybeLocal<Object> CloneElementAt(
2956  Local<Context> context, uint32_t index);
2957 
2962  static Local<Array> New(Isolate* isolate, int length = 0);
2963 
2964  V8_INLINE static Array* Cast(Value* obj);
2965  private:
2966  Array();
2967  static void CheckCast(Value* obj);
2968 };
2969 
2970 
2974 class V8_EXPORT Map : public Object {
2975  public:
2976  size_t Size() const;
2977  void Clear();
2978  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2979  Local<Value> key);
2980  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
2981  Local<Value> key,
2982  Local<Value> value);
2983  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
2984  Local<Value> key);
2985  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
2986  Local<Value> key);
2987 
2992  Local<Array> AsArray() const;
2993 
2997  static Local<Map> New(Isolate* isolate);
2998 
3004  static V8_WARN_UNUSED_RESULT V8_DEPRECATED(
3005  "Use mutation methods instead",
3006  MaybeLocal<Map> FromArray(Local<Context> context, Local<Array> array));
3007 
3008  V8_INLINE static Map* Cast(Value* obj);
3009 
3010  private:
3011  Map();
3012  static void CheckCast(Value* obj);
3013 };
3014 
3015 
3019 class V8_EXPORT Set : public Object {
3020  public:
3021  size_t Size() const;
3022  void Clear();
3023  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3024  Local<Value> key);
3025  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3026  Local<Value> key);
3027  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3028  Local<Value> key);
3029 
3033  Local<Array> AsArray() const;
3034 
3038  static Local<Set> New(Isolate* isolate);
3039 
3044  static V8_WARN_UNUSED_RESULT V8_DEPRECATED(
3045  "Use mutation methods instead",
3046  MaybeLocal<Set> FromArray(Local<Context> context, Local<Array> array));
3047 
3048  V8_INLINE static Set* Cast(Value* obj);
3049 
3050  private:
3051  Set();
3052  static void CheckCast(Value* obj);
3053 };
3054 
3055 
3056 template<typename T>
3057 class ReturnValue {
3058  public:
3059  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3060  : value_(that.value_) {
3061  TYPE_CHECK(T, S);
3062  }
3063  // Local setters
3064  template <typename S>
3065  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3066  void Set(const Persistent<S>& handle));
3067  template <typename S>
3068  V8_INLINE void Set(const Global<S>& handle);
3069  template <typename S>
3070  V8_INLINE void Set(const Local<S> handle);
3071  // Fast primitive setters
3072  V8_INLINE void Set(bool value);
3073  V8_INLINE void Set(double i);
3074  V8_INLINE void Set(int32_t i);
3075  V8_INLINE void Set(uint32_t i);
3076  // Fast JS primitive setters
3077  V8_INLINE void SetNull();
3078  V8_INLINE void SetUndefined();
3079  V8_INLINE void SetEmptyString();
3080  // Convenience getter for Isolate
3081  V8_INLINE Isolate* GetIsolate();
3082 
3083  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3084  template <typename S>
3085  V8_INLINE void Set(S* whatever);
3086 
3087  private:
3088  template<class F> friend class ReturnValue;
3089  template<class F> friend class FunctionCallbackInfo;
3090  template<class F> friend class PropertyCallbackInfo;
3091  template <class F, class G, class H>
3092  friend class PersistentValueMapBase;
3093  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3094  V8_INLINE internal::Object* GetDefaultValue();
3095  V8_INLINE explicit ReturnValue(internal::Object** slot);
3096  internal::Object** value_;
3097 };
3098 
3099 
3106 template<typename T>
3107 class FunctionCallbackInfo {
3108  public:
3109  V8_INLINE int Length() const;
3110  V8_INLINE Local<Value> operator[](int i) const;
3111  V8_INLINE Local<Function> Callee() const;
3112  V8_INLINE Local<Object> This() const;
3113  V8_INLINE Local<Object> Holder() const;
3114  V8_INLINE bool IsConstructCall() const;
3115  V8_INLINE Local<Value> Data() const;
3116  V8_INLINE Isolate* GetIsolate() const;
3117  V8_INLINE ReturnValue<T> GetReturnValue() const;
3118  // This shouldn't be public, but the arm compiler needs it.
3119  static const int kArgsLength = 7;
3120 
3121  protected:
3122  friend class internal::FunctionCallbackArguments;
3123  friend class internal::CustomArguments<FunctionCallbackInfo>;
3124  static const int kHolderIndex = 0;
3125  static const int kIsolateIndex = 1;
3126  static const int kReturnValueDefaultValueIndex = 2;
3127  static const int kReturnValueIndex = 3;
3128  static const int kDataIndex = 4;
3129  static const int kCalleeIndex = 5;
3130  static const int kContextSaveIndex = 6;
3131 
3132  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3133  internal::Object** values,
3134  int length,
3135  bool is_construct_call);
3136  internal::Object** implicit_args_;
3137  internal::Object** values_;
3138  int length_;
3139  int is_construct_call_;
3140 };
3141 
3142 
3147 template<typename T>
3148 class PropertyCallbackInfo {
3149  public:
3150  V8_INLINE Isolate* GetIsolate() const;
3151  V8_INLINE Local<Value> Data() const;
3152  V8_INLINE Local<Object> This() const;
3153  V8_INLINE Local<Object> Holder() const;
3154  V8_INLINE ReturnValue<T> GetReturnValue() const;
3155  // This shouldn't be public, but the arm compiler needs it.
3156  static const int kArgsLength = 6;
3157 
3158  protected:
3159  friend class MacroAssembler;
3160  friend class internal::PropertyCallbackArguments;
3161  friend class internal::CustomArguments<PropertyCallbackInfo>;
3162  static const int kHolderIndex = 0;
3163  static const int kIsolateIndex = 1;
3164  static const int kReturnValueDefaultValueIndex = 2;
3165  static const int kReturnValueIndex = 3;
3166  static const int kDataIndex = 4;
3167  static const int kThisIndex = 5;
3168 
3169  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
3170  internal::Object** args_;
3171 };
3172 
3173 
3174 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3175 
3176 
3180 class V8_EXPORT Function : public Object {
3181  public:
3186  static MaybeLocal<Function> New(Local<Context> context,
3187  FunctionCallback callback,
3188  Local<Value> data = Local<Value>(),
3189  int length = 0);
3190  static V8_DEPRECATE_SOON(
3191  "Use maybe version",
3192  Local<Function> New(Isolate* isolate, FunctionCallback callback,
3193  Local<Value> data = Local<Value>(), int length = 0));
3194 
3195  V8_DEPRECATE_SOON("Use maybe version",
3196  Local<Object> NewInstance(int argc, Local<Value> argv[])
3197  const);
3198  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
3199  Local<Context> context, int argc, Local<Value> argv[]) const;
3200 
3201  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance() const);
3202  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
3203  Local<Context> context) const {
3204  return NewInstance(context, 0, nullptr);
3205  }
3206 
3207  V8_DEPRECATE_SOON("Use maybe version",
3208  Local<Value> Call(Local<Value> recv, int argc,
3209  Local<Value> argv[]));
3210  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
3211  Local<Value> recv, int argc,
3212  Local<Value> argv[]);
3213 
3214  void SetName(Local<String> name);
3215  Local<Value> GetName() const;
3216 
3223  Local<Value> GetInferredName() const;
3224 
3229  Local<Value> GetDisplayName() const;
3230 
3235  int GetScriptLineNumber() const;
3240  int GetScriptColumnNumber() const;
3241 
3245  bool IsBuiltin() const;
3246 
3250  int ScriptId() const;
3251 
3256  Local<Value> GetBoundFunction() const;
3257 
3258  ScriptOrigin GetScriptOrigin() const;
3259  V8_INLINE static Function* Cast(Value* obj);
3260  static const int kLineOffsetNotFound;
3261 
3262  private:
3263  Function();
3264  static void CheckCast(Value* obj);
3265 };
3266 
3267 
3272 class V8_EXPORT Promise : public Object {
3273  public:
3274  class V8_EXPORT Resolver : public Object {
3275  public:
3279  static V8_DEPRECATE_SOON("Use maybe version",
3280  Local<Resolver> New(Isolate* isolate));
3281  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
3282  Local<Context> context);
3283 
3287  Local<Promise> GetPromise();
3288 
3293  V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
3294  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3295  Maybe<bool> Resolve(Local<Context> context, Local<Value> value);
3296 
3297  V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
3298  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3299  Maybe<bool> Reject(Local<Context> context, Local<Value> value);
3300 
3301  V8_INLINE static Resolver* Cast(Value* obj);
3302 
3303  private:
3304  Resolver();
3305  static void CheckCast(Value* obj);
3306  };
3307 
3314  V8_DEPRECATE_SOON("Use maybe version",
3315  Local<Promise> Chain(Local<Function> handler));
3316  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Chain(Local<Context> context,
3317  Local<Function> handler);
3318 
3319  V8_DEPRECATE_SOON("Use maybe version",
3320  Local<Promise> Catch(Local<Function> handler));
3321  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
3322  Local<Function> handler);
3323 
3324  V8_DEPRECATE_SOON("Use maybe version",
3325  Local<Promise> Then(Local<Function> handler));
3326  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
3327  Local<Function> handler);
3328 
3333  bool HasHandler();
3334 
3335  V8_INLINE static Promise* Cast(Value* obj);
3336 
3337  private:
3338  Promise();
3339  static void CheckCast(Value* obj);
3340 };
3341 
3342 
3343 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
3344 // The number of required internal fields can be defined by embedder.
3345 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
3346 #endif
3347 
3348 
3349 enum class ArrayBufferCreationMode { kInternalized, kExternalized };
3350 
3351 
3356 class V8_EXPORT ArrayBuffer : public Object {
3357  public:
3365  class V8_EXPORT Allocator { // NOLINT
3366  public:
3367  virtual ~Allocator() {}
3368 
3373  virtual void* Allocate(size_t length) = 0;
3374 
3379  virtual void* AllocateUninitialized(size_t length) = 0;
3384  virtual void Free(void* data, size_t length) = 0;
3385  };
3386 
3397  class V8_EXPORT Contents { // NOLINT
3398  public:
3399  Contents() : data_(NULL), byte_length_(0) {}
3400 
3401  void* Data() const { return data_; }
3402  size_t ByteLength() const { return byte_length_; }
3403 
3404  private:
3405  void* data_;
3406  size_t byte_length_;
3407 
3408  friend class ArrayBuffer;
3409  };
3410 
3411 
3415  size_t ByteLength() const;
3416 
3423  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
3424 
3431  static Local<ArrayBuffer> New(
3432  Isolate* isolate, void* data, size_t byte_length,
3433  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
3434 
3439  bool IsExternal() const;
3440 
3444  bool IsNeuterable() const;
3445 
3452  void Neuter();
3453 
3463  Contents Externalize();
3464 
3475  Contents GetContents();
3476 
3477  V8_INLINE static ArrayBuffer* Cast(Value* obj);
3478 
3479  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
3480 
3481  private:
3482  ArrayBuffer();
3483  static void CheckCast(Value* obj);
3484 };
3485 
3486 
3487 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
3488 // The number of required internal fields can be defined by embedder.
3489 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
3490 #endif
3491 
3492 
3499 class V8_EXPORT ArrayBufferView : public Object {
3500  public:
3504  Local<ArrayBuffer> Buffer();
3508  size_t ByteOffset();
3512  size_t ByteLength();
3513 
3523  size_t CopyContents(void* dest, size_t byte_length);
3524 
3529  bool HasBuffer() const;
3530 
3531  V8_INLINE static ArrayBufferView* Cast(Value* obj);
3532 
3533  static const int kInternalFieldCount =
3534  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
3535 
3536  private:
3537  ArrayBufferView();
3538  static void CheckCast(Value* obj);
3539 };
3540 
3541 
3547 class V8_EXPORT TypedArray : public ArrayBufferView {
3548  public:
3553  size_t Length();
3554 
3555  V8_INLINE static TypedArray* Cast(Value* obj);
3556 
3557  private:
3558  TypedArray();
3559  static void CheckCast(Value* obj);
3560 };
3561 
3562 
3567 class V8_EXPORT Uint8Array : public TypedArray {
3568  public:
3569  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
3570  size_t byte_offset, size_t length);
3571  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3572  size_t byte_offset, size_t length);
3573  V8_INLINE static Uint8Array* Cast(Value* obj);
3574 
3575  private:
3576  Uint8Array();
3577  static void CheckCast(Value* obj);
3578 };
3579 
3580 
3585 class V8_EXPORT Uint8ClampedArray : public TypedArray {
3586  public:
3587  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
3588  size_t byte_offset, size_t length);
3589  static Local<Uint8ClampedArray> New(
3590  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
3591  size_t length);
3592  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
3593 
3594  private:
3596  static void CheckCast(Value* obj);
3597 };
3598 
3603 class V8_EXPORT Int8Array : public TypedArray {
3604  public:
3605  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
3606  size_t byte_offset, size_t length);
3607  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3608  size_t byte_offset, size_t length);
3609  V8_INLINE static Int8Array* Cast(Value* obj);
3610 
3611  private:
3612  Int8Array();
3613  static void CheckCast(Value* obj);
3614 };
3615 
3616 
3621 class V8_EXPORT Uint16Array : public TypedArray {
3622  public:
3623  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
3624  size_t byte_offset, size_t length);
3625  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3626  size_t byte_offset, size_t length);
3627  V8_INLINE static Uint16Array* Cast(Value* obj);
3628 
3629  private:
3630  Uint16Array();
3631  static void CheckCast(Value* obj);
3632 };
3633 
3634 
3639 class V8_EXPORT Int16Array : public TypedArray {
3640  public:
3641  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
3642  size_t byte_offset, size_t length);
3643  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3644  size_t byte_offset, size_t length);
3645  V8_INLINE static Int16Array* Cast(Value* obj);
3646 
3647  private:
3648  Int16Array();
3649  static void CheckCast(Value* obj);
3650 };
3651 
3652 
3657 class V8_EXPORT Uint32Array : public TypedArray {
3658  public:
3659  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
3660  size_t byte_offset, size_t length);
3661  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3662  size_t byte_offset, size_t length);
3663  V8_INLINE static Uint32Array* Cast(Value* obj);
3664 
3665  private:
3666  Uint32Array();
3667  static void CheckCast(Value* obj);
3668 };
3669 
3670 
3675 class V8_EXPORT Int32Array : public TypedArray {
3676  public:
3677  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
3678  size_t byte_offset, size_t length);
3679  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3680  size_t byte_offset, size_t length);
3681  V8_INLINE static Int32Array* Cast(Value* obj);
3682 
3683  private:
3684  Int32Array();
3685  static void CheckCast(Value* obj);
3686 };
3687 
3688 
3693 class V8_EXPORT Float32Array : public TypedArray {
3694  public:
3695  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
3696  size_t byte_offset, size_t length);
3697  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3698  size_t byte_offset, size_t length);
3699  V8_INLINE static Float32Array* Cast(Value* obj);
3700 
3701  private:
3702  Float32Array();
3703  static void CheckCast(Value* obj);
3704 };
3705 
3706 
3711 class V8_EXPORT Float64Array : public TypedArray {
3712  public:
3713  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
3714  size_t byte_offset, size_t length);
3715  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3716  size_t byte_offset, size_t length);
3717  V8_INLINE static Float64Array* Cast(Value* obj);
3718 
3719  private:
3720  Float64Array();
3721  static void CheckCast(Value* obj);
3722 };
3723 
3724 
3729 class V8_EXPORT DataView : public ArrayBufferView {
3730  public:
3731  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
3732  size_t byte_offset, size_t length);
3733  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
3734  size_t byte_offset, size_t length);
3735  V8_INLINE static DataView* Cast(Value* obj);
3736 
3737  private:
3738  DataView();
3739  static void CheckCast(Value* obj);
3740 };
3741 
3742 
3747 class V8_EXPORT SharedArrayBuffer : public Object {
3748  public:
3760  class V8_EXPORT Contents { // NOLINT
3761  public:
3762  Contents() : data_(NULL), byte_length_(0) {}
3763 
3764  void* Data() const { return data_; }
3765  size_t ByteLength() const { return byte_length_; }
3766 
3767  private:
3768  void* data_;
3769  size_t byte_length_;
3770 
3771  friend class SharedArrayBuffer;
3772  };
3773 
3774 
3778  size_t ByteLength() const;
3779 
3786  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
3787 
3794  static Local<SharedArrayBuffer> New(
3795  Isolate* isolate, void* data, size_t byte_length,
3796  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
3797 
3802  bool IsExternal() const;
3803 
3816  Contents Externalize();
3817 
3830  Contents GetContents();
3831 
3832  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
3833 
3834  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
3835 
3836  private:
3838  static void CheckCast(Value* obj);
3839 };
3840 
3841 
3845 class V8_EXPORT Date : public Object {
3846  public:
3847  static V8_DEPRECATE_SOON("Use maybe version.",
3848  Local<Value> New(Isolate* isolate, double time));
3849  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
3850  double time);
3851 
3856  double ValueOf() const;
3857 
3858  V8_INLINE static Date* Cast(v8::Value* obj);
3859 
3872  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
3873 
3874  private:
3875  static void CheckCast(v8::Value* obj);
3876 };
3877 
3878 
3882 class V8_EXPORT NumberObject : public Object {
3883  public:
3884  static Local<Value> New(Isolate* isolate, double value);
3885 
3886  double ValueOf() const;
3887 
3888  V8_INLINE static NumberObject* Cast(v8::Value* obj);
3889 
3890  private:
3891  static void CheckCast(v8::Value* obj);
3892 };
3893 
3894 
3898 class V8_EXPORT BooleanObject : public Object {
3899  public:
3900  static Local<Value> New(bool value);
3901 
3902  bool ValueOf() const;
3903 
3904  V8_INLINE static BooleanObject* Cast(v8::Value* obj);
3905 
3906  private:
3907  static void CheckCast(v8::Value* obj);
3908 };
3909 
3910 
3914 class V8_EXPORT StringObject : public Object {
3915  public:
3916  static Local<Value> New(Local<String> value);
3917 
3918  Local<String> ValueOf() const;
3919 
3920  V8_INLINE static StringObject* Cast(v8::Value* obj);
3921 
3922  private:
3923  static void CheckCast(v8::Value* obj);
3924 };
3925 
3926 
3932 class V8_EXPORT SymbolObject : public Object {
3933  public:
3934  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
3935 
3936  Local<Symbol> ValueOf() const;
3937 
3938  V8_INLINE static SymbolObject* Cast(v8::Value* obj);
3939 
3940  private:
3941  static void CheckCast(v8::Value* obj);
3942 };
3943 
3944 
3948 class V8_EXPORT RegExp : public Object {
3949  public:
3954  enum Flags {
3955  kNone = 0,
3956  kGlobal = 1,
3957  kIgnoreCase = 2,
3958  kMultiline = 4
3959  };
3960 
3971  static V8_DEPRECATE_SOON("Use maybe version",
3972  Local<RegExp> New(Local<String> pattern,
3973  Flags flags));
3974  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
3975  Local<String> pattern,
3976  Flags flags);
3977 
3982  Local<String> GetSource() const;
3983 
3987  Flags GetFlags() const;
3988 
3989  V8_INLINE static RegExp* Cast(v8::Value* obj);
3990 
3991  private:
3992  static void CheckCast(v8::Value* obj);
3993 };
3994 
3995 
4000 class V8_EXPORT External : public Value {
4001  public:
4002  static Local<External> New(Isolate* isolate, void* value);
4003  V8_INLINE static External* Cast(Value* obj);
4004  void* Value() const;
4005  private:
4006  static void CheckCast(v8::Value* obj);
4007 };
4008 
4009 
4010 // --- Templates ---
4011 
4012 
4016 class V8_EXPORT Template : public Data {
4017  public:
4019  void Set(Local<Name> name, Local<Data> value,
4020  PropertyAttribute attributes = None);
4021  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
4022 
4023  void SetAccessorProperty(
4024  Local<Name> name,
4027  PropertyAttribute attribute = None,
4028  AccessControl settings = DEFAULT);
4029 
4057  void SetNativeDataProperty(
4059  AccessorSetterCallback setter = 0,
4060  // TODO(dcarney): gcc can't handle Local below
4061  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4063  AccessControl settings = DEFAULT);
4064  void SetNativeDataProperty(
4065  Local<Name> name, AccessorNameGetterCallback getter,
4066  AccessorNameSetterCallback setter = 0,
4067  // TODO(dcarney): gcc can't handle Local below
4068  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4070  AccessControl settings = DEFAULT);
4071 
4072  private:
4073  Template();
4074 
4075  friend class ObjectTemplate;
4076  friend class FunctionTemplate;
4077 };
4078 
4079 
4085  Local<String> property,
4086  const PropertyCallbackInfo<Value>& info);
4087 
4088 
4094  Local<String> property,
4095  Local<Value> value,
4096  const PropertyCallbackInfo<Value>& info);
4097 
4098 
4105  Local<String> property,
4106  const PropertyCallbackInfo<Integer>& info);
4107 
4108 
4115  Local<String> property,
4116  const PropertyCallbackInfo<Boolean>& info);
4117 
4118 
4124  const PropertyCallbackInfo<Array>& info);
4125 
4126 
4127 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
4128 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
4134  Local<Name> property, const PropertyCallbackInfo<Value>& info);
4135 
4136 
4142  Local<Name> property, Local<Value> value,
4143  const PropertyCallbackInfo<Value>& info);
4144 
4145 
4152  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
4153 
4154 
4161  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
4162 
4163 
4169  const PropertyCallbackInfo<Array>& info);
4170 
4171 
4177  uint32_t index,
4178  const PropertyCallbackInfo<Value>& info);
4179 
4180 
4186  uint32_t index,
4187  Local<Value> value,
4188  const PropertyCallbackInfo<Value>& info);
4189 
4190 
4196  uint32_t index,
4197  const PropertyCallbackInfo<Integer>& info);
4198 
4199 
4206  uint32_t index,
4207  const PropertyCallbackInfo<Boolean>& info);
4208 
4209 
4215  const PropertyCallbackInfo<Array>& info);
4216 
4217 
4222  ACCESS_GET,
4223  ACCESS_SET,
4224  ACCESS_HAS,
4225  ACCESS_DELETE,
4226  ACCESS_KEYS
4227 };
4228 
4229 
4235  Local<Value> key,
4236  AccessType type,
4237  Local<Value> data);
4238 
4239 
4245  uint32_t index,
4246  AccessType type,
4247  Local<Value> data);
4248 
4249 
4345 class V8_EXPORT FunctionTemplate : public Template {
4346  public:
4348  static Local<FunctionTemplate> New(
4349  Isolate* isolate, FunctionCallback callback = 0,
4350  Local<Value> data = Local<Value>(),
4351  Local<Signature> signature = Local<Signature>(), int length = 0);
4352 
4354  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
4355  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
4356  Local<Context> context);
4357 
4363  void SetCallHandler(FunctionCallback callback,
4364  Local<Value> data = Local<Value>());
4365 
4367  void SetLength(int length);
4368 
4370  Local<ObjectTemplate> InstanceTemplate();
4371 
4373  void Inherit(Local<FunctionTemplate> parent);
4374 
4379  Local<ObjectTemplate> PrototypeTemplate();
4380 
4386  void SetClassName(Local<String> name);
4387 
4388 
4393  void SetAcceptAnyReceiver(bool value);
4394 
4407  void SetHiddenPrototype(bool value);
4408 
4413  void ReadOnlyPrototype();
4414 
4419  void RemovePrototype();
4420 
4425  bool HasInstance(Local<Value> object);
4426 
4427  private:
4428  FunctionTemplate();
4429  friend class Context;
4430  friend class ObjectTemplate;
4431 };
4432 
4433 
4434 enum class PropertyHandlerFlags {
4435  kNone = 0,
4436  // See ALL_CAN_READ above.
4437  kAllCanRead = 1,
4438  // Will not call into interceptor for properties on the receiver or prototype
4439  // chain. Currently only valid for named interceptors.
4440  kNonMasking = 1 << 1,
4441  // Will not call into interceptor for symbol lookup. Only meaningful for
4442  // named interceptors.
4443  kOnlyInterceptStrings = 1 << 2,
4444 };
4445 
4446 
4455  Local<Value> data = Local<Value>(),
4456  PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
4457  : getter(getter),
4458  setter(setter),
4459  query(query),
4460  deleter(deleter),
4461  enumerator(enumerator),
4462  data(data),
4463  flags(flags) {}
4464 
4470  Local<Value> data;
4471  PropertyHandlerFlags flags;
4472 };
4473 
4474 
4478  IndexedPropertyGetterCallback getter = 0,
4479  IndexedPropertySetterCallback setter = 0,
4480  IndexedPropertyQueryCallback query = 0,
4481  IndexedPropertyDeleterCallback deleter = 0,
4482  IndexedPropertyEnumeratorCallback enumerator = 0,
4483  Local<Value> data = Local<Value>(),
4484  PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
4485  : getter(getter),
4486  setter(setter),
4487  query(query),
4488  deleter(deleter),
4489  enumerator(enumerator),
4490  data(data),
4491  flags(flags) {}
4492 
4498  Local<Value> data;
4499  PropertyHandlerFlags flags;
4500 };
4501 
4502 
4509 class V8_EXPORT ObjectTemplate : public Template {
4510  public:
4512  static Local<ObjectTemplate> New(
4513  Isolate* isolate,
4515  static V8_DEPRECATE_SOON("Use isolate version", Local<ObjectTemplate> New());
4516 
4518  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
4519  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
4520 
4550  void SetAccessor(
4552  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
4553  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
4555  void SetAccessor(
4556  Local<Name> name, AccessorNameGetterCallback getter,
4557  AccessorNameSetterCallback setter = 0, Local<Value> data = Local<Value>(),
4558  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
4560 
4581  // TODO(dcarney): deprecate
4582  void SetNamedPropertyHandler(NamedPropertyGetterCallback getter,
4583  NamedPropertySetterCallback setter = 0,
4584  NamedPropertyQueryCallback query = 0,
4585  NamedPropertyDeleterCallback deleter = 0,
4586  NamedPropertyEnumeratorCallback enumerator = 0,
4587  Local<Value> data = Local<Value>());
4588  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
4589 
4606  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
4607  // TODO(dcarney): deprecate
4608  void SetIndexedPropertyHandler(
4610  IndexedPropertySetterCallback setter = 0,
4611  IndexedPropertyQueryCallback query = 0,
4612  IndexedPropertyDeleterCallback deleter = 0,
4613  IndexedPropertyEnumeratorCallback enumerator = 0,
4614  Local<Value> data = Local<Value>()) {
4615  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
4616  deleter, enumerator, data));
4617  }
4624  void SetCallAsFunctionHandler(FunctionCallback callback,
4625  Local<Value> data = Local<Value>());
4626 
4635  void MarkAsUndetectable();
4636 
4645  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
4646  IndexedSecurityCallback indexed_handler,
4647  Local<Value> data = Local<Value>());
4648 
4653  int InternalFieldCount();
4654 
4659  void SetInternalFieldCount(int value);
4660 
4661  private:
4662  ObjectTemplate();
4663  static Local<ObjectTemplate> New(internal::Isolate* isolate,
4664  Local<FunctionTemplate> constructor);
4665  friend class FunctionTemplate;
4666 };
4667 
4668 
4672 class V8_EXPORT Signature : public Data {
4673  public:
4674  static Local<Signature> New(
4675  Isolate* isolate,
4677 
4678  private:
4679  Signature();
4680 };
4681 
4682 
4687 class V8_EXPORT AccessorSignature : public Data {
4688  public:
4689  static Local<AccessorSignature> New(
4690  Isolate* isolate,
4692 
4693  private:
4695 };
4696 
4697 
4702 class V8_EXPORT TypeSwitch : public Data {
4703  public:
4704  static Local<TypeSwitch> New(Local<FunctionTemplate> type);
4705  static Local<TypeSwitch> New(int argc, Local<FunctionTemplate> types[]);
4706  int match(Local<Value> value);
4707 
4708  private:
4709  TypeSwitch();
4710 };
4711 
4712 
4713 // --- Extensions ---
4714 
4717  public:
4718  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
4719  ExternalOneByteStringResourceImpl(const char* data, size_t length)
4720  : data_(data), length_(length) {}
4721  const char* data() const { return data_; }
4722  size_t length() const { return length_; }
4723 
4724  private:
4725  const char* data_;
4726  size_t length_;
4727 };
4728 
4732 class V8_EXPORT Extension { // NOLINT
4733  public:
4734  // Note that the strings passed into this constructor must live as long
4735  // as the Extension itself.
4736  Extension(const char* name,
4737  const char* source = 0,
4738  int dep_count = 0,
4739  const char** deps = 0,
4740  int source_length = -1);
4741  virtual ~Extension() { }
4742  virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
4743  v8::Isolate* isolate, v8::Local<v8::String> name) {
4745  }
4746 
4747  const char* name() const { return name_; }
4748  size_t source_length() const { return source_length_; }
4749  const String::ExternalOneByteStringResource* source() const {
4750  return &source_; }
4751  int dependency_count() { return dep_count_; }
4752  const char** dependencies() { return deps_; }
4753  void set_auto_enable(bool value) { auto_enable_ = value; }
4754  bool auto_enable() { return auto_enable_; }
4755 
4756  private:
4757  const char* name_;
4758  size_t source_length_; // expected to initialize before source_
4760  int dep_count_;
4761  const char** deps_;
4762  bool auto_enable_;
4763 
4764  // Disallow copying and assigning.
4765  Extension(const Extension&);
4766  void operator=(const Extension&);
4767 };
4768 
4769 
4770 void V8_EXPORT RegisterExtension(Extension* extension);
4771 
4772 
4773 // --- Statics ---
4774 
4775 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
4776 V8_INLINE Local<Primitive> Null(Isolate* isolate);
4777 V8_INLINE Local<Boolean> True(Isolate* isolate);
4778 V8_INLINE Local<Boolean> False(Isolate* isolate);
4779 
4780 
4790 class V8_EXPORT ResourceConstraints {
4791  public:
4793 
4803  void ConfigureDefaults(uint64_t physical_memory,
4804  uint64_t virtual_memory_limit);
4805 
4806  int max_semi_space_size() const { return max_semi_space_size_; }
4807  void set_max_semi_space_size(int value) { max_semi_space_size_ = value; }
4808  int max_old_space_size() const { return max_old_space_size_; }
4809  void set_max_old_space_size(int value) { max_old_space_size_ = value; }
4810  int max_executable_size() const { return max_executable_size_; }
4811  void set_max_executable_size(int value) { max_executable_size_ = value; }
4812  uint32_t* stack_limit() const { return stack_limit_; }
4813  // Sets an address beyond which the VM's stack may not grow.
4814  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
4815  size_t code_range_size() const { return code_range_size_; }
4816  void set_code_range_size(size_t value) {
4817  code_range_size_ = value;
4818  }
4819 
4820  private:
4821  int max_semi_space_size_;
4822  int max_old_space_size_;
4823  int max_executable_size_;
4824  uint32_t* stack_limit_;
4825  size_t code_range_size_;
4826 };
4827 
4828 
4829 // --- Exceptions ---
4830 
4831 
4832 typedef void (*FatalErrorCallback)(const char* location, const char* message);
4833 
4834 
4835 typedef void (*MessageCallback)(Local<Message> message, Local<Value> error);
4836 
4837 // --- Tracing ---
4838 
4839 typedef void (*LogEventCallback)(const char* name, int event);
4840 
4845 class V8_EXPORT Exception {
4846  public:
4847  static Local<Value> RangeError(Local<String> message);
4848  static Local<Value> ReferenceError(Local<String> message);
4849  static Local<Value> SyntaxError(Local<String> message);
4850  static Local<Value> TypeError(Local<String> message);
4851  static Local<Value> Error(Local<String> message);
4852 
4858  static Local<Message> CreateMessage(Local<Value> exception);
4859 
4864  static Local<StackTrace> GetStackTrace(Local<Value> exception);
4865 };
4866 
4867 
4868 // --- Counters Callbacks ---
4869 
4870 typedef int* (*CounterLookupCallback)(const char* name);
4871 
4872 typedef void* (*CreateHistogramCallback)(const char* name,
4873  int min,
4874  int max,
4875  size_t buckets);
4876 
4877 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
4878 
4879 // --- Memory Allocation Callback ---
4880 enum ObjectSpace {
4881  kObjectSpaceNewSpace = 1 << 0,
4882  kObjectSpaceOldSpace = 1 << 1,
4883  kObjectSpaceCodeSpace = 1 << 2,
4884  kObjectSpaceMapSpace = 1 << 3,
4885  kObjectSpaceLoSpace = 1 << 4,
4886  kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldSpace |
4887  kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
4888  kObjectSpaceLoSpace
4889 };
4890 
4891  enum AllocationAction {
4892  kAllocationActionAllocate = 1 << 0,
4893  kAllocationActionFree = 1 << 1,
4894  kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
4895  };
4896 
4897 typedef void (*MemoryAllocationCallback)(ObjectSpace space,
4898  AllocationAction action,
4899  int size);
4900 
4901 // --- Leave Script Callback ---
4902 typedef void (*CallCompletedCallback)();
4903 
4904 // --- Promise Reject Callback ---
4905 enum PromiseRejectEvent {
4906  kPromiseRejectWithNoHandler = 0,
4907  kPromiseHandlerAddedAfterReject = 1
4908 };
4909 
4911  public:
4912  PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
4913  Local<Value> value, Local<StackTrace> stack_trace)
4914  : promise_(promise),
4915  event_(event),
4916  value_(value),
4917  stack_trace_(stack_trace) {}
4918 
4919  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
4920  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
4921  V8_INLINE Local<Value> GetValue() const { return value_; }
4922 
4923  // DEPRECATED. Use v8::Exception::CreateMessage(GetValue())->GetStackTrace()
4924  V8_INLINE Local<StackTrace> GetStackTrace() const { return stack_trace_; }
4925 
4926  private:
4927  Local<Promise> promise_;
4928  PromiseRejectEvent event_;
4929  Local<Value> value_;
4930  Local<StackTrace> stack_trace_;
4931 };
4932 
4933 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
4934 
4935 // --- Microtask Callback ---
4936 typedef void (*MicrotaskCallback)(void* data);
4937 
4938 // --- Failed Access Check Callback ---
4939 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
4940  AccessType type,
4941  Local<Value> data);
4942 
4943 // --- AllowCodeGenerationFromStrings callbacks ---
4944 
4950 
4951 // --- Garbage Collection Callbacks ---
4952 
4960 enum GCType {
4961  kGCTypeScavenge = 1 << 0,
4962  kGCTypeMarkSweepCompact = 1 << 1,
4963  kGCTypeIncrementalMarking = 1 << 2,
4964  kGCTypeProcessWeakCallbacks = 1 << 3,
4965  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
4966  kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
4967 };
4968 
4969 enum GCCallbackFlags {
4970  kNoGCCallbackFlags = 0,
4971  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
4972  kGCCallbackFlagForced = 1 << 2,
4973  kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3
4974 };
4975 
4976 V8_DEPRECATE_SOON("Use GCCallBack instead",
4977  typedef void (*GCPrologueCallback)(GCType type,
4978  GCCallbackFlags flags));
4979 V8_DEPRECATE_SOON("Use GCCallBack instead",
4980  typedef void (*GCEpilogueCallback)(GCType type,
4981  GCCallbackFlags flags));
4982 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
4983 
4984 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
4985 
4986 
4993 class V8_EXPORT HeapStatistics {
4994  public:
4995  HeapStatistics();
4996  size_t total_heap_size() { return total_heap_size_; }
4997  size_t total_heap_size_executable() { return total_heap_size_executable_; }
4998  size_t total_physical_size() { return total_physical_size_; }
4999  size_t total_available_size() { return total_available_size_; }
5000  size_t used_heap_size() { return used_heap_size_; }
5001  size_t heap_size_limit() { return heap_size_limit_; }
5002 
5003  private:
5004  size_t total_heap_size_;
5005  size_t total_heap_size_executable_;
5006  size_t total_physical_size_;
5007  size_t total_available_size_;
5008  size_t used_heap_size_;
5009  size_t heap_size_limit_;
5010 
5011  friend class V8;
5012  friend class Isolate;
5013 };
5014 
5015 
5016 class V8_EXPORT HeapSpaceStatistics {
5017  public:
5019  const char* space_name() { return space_name_; }
5020  size_t space_size() { return space_size_; }
5021  size_t space_used_size() { return space_used_size_; }
5022  size_t space_available_size() { return space_available_size_; }
5023  size_t physical_space_size() { return physical_space_size_; }
5024 
5025  private:
5026  const char* space_name_;
5027  size_t space_size_;
5028  size_t space_used_size_;
5029  size_t space_available_size_;
5030  size_t physical_space_size_;
5031 
5032  friend class Isolate;
5033 };
5034 
5035 
5036 class V8_EXPORT HeapObjectStatistics {
5037  public:
5039  const char* object_type() { return object_type_; }
5040  const char* object_sub_type() { return object_sub_type_; }
5041  size_t object_count() { return object_count_; }
5042  size_t object_size() { return object_size_; }
5043 
5044  private:
5045  const char* object_type_;
5046  const char* object_sub_type_;
5047  size_t object_count_;
5048  size_t object_size_;
5049 
5050  friend class Isolate;
5051 };
5052 
5053 
5054 class RetainedObjectInfo;
5055 
5056 
5068 typedef void (*FunctionEntryHook)(uintptr_t function,
5069  uintptr_t return_addr_location);
5070 
5077  enum EventType {
5078  CODE_ADDED,
5079  CODE_MOVED,
5080  CODE_REMOVED,
5081  CODE_ADD_LINE_POS_INFO,
5082  CODE_START_LINE_INFO_RECORDING,
5083  CODE_END_LINE_INFO_RECORDING
5084  };
5085  // Definition of the code position type. The "POSITION" type means the place
5086  // in the source code which are of interest when making stack traces to
5087  // pin-point the source location of a stack frame as close as possible.
5088  // The "STATEMENT_POSITION" means the place at the beginning of each
5089  // statement, and is used to indicate possible break locations.
5090  enum PositionType { POSITION, STATEMENT_POSITION };
5091 
5092  // Type of event.
5093  EventType type;
5094  // Start of the instructions.
5095  void* code_start;
5096  // Size of the instructions.
5097  size_t code_len;
5098  // Script info for CODE_ADDED event.
5099  Local<UnboundScript> script;
5100  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
5101  // code line information which is returned from the
5102  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
5103  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
5104  void* user_data;
5105 
5106  struct name_t {
5107  // Name of the object associated with the code, note that the string is not
5108  // zero-terminated.
5109  const char* str;
5110  // Number of chars in str.
5111  size_t len;
5112  };
5113 
5114  struct line_info_t {
5115  // PC offset
5116  size_t offset;
5117  // Code postion
5118  size_t pos;
5119  // The position type.
5120  PositionType position_type;
5121  };
5122 
5123  union {
5124  // Only valid for CODE_ADDED.
5125  struct name_t name;
5126 
5127  // Only valid for CODE_ADD_LINE_POS_INFO
5128  struct line_info_t line_info;
5129 
5130  // New location of instructions. Only valid for CODE_MOVED.
5131  void* new_code_start;
5132  };
5133 };
5134 
5139  kJitCodeEventDefault = 0,
5140  // Generate callbacks for already existent code.
5141  kJitCodeEventEnumExisting = 1
5142 };
5143 
5144 
5150 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
5151 
5152 
5156 class V8_EXPORT ExternalResourceVisitor { // NOLINT
5157  public:
5158  virtual ~ExternalResourceVisitor() {}
5159  virtual void VisitExternalString(Local<String> string) {}
5160 };
5161 
5162 
5166 class V8_EXPORT PersistentHandleVisitor { // NOLINT
5167  public:
5168  virtual ~PersistentHandleVisitor() {}
5169  virtual void VisitPersistentHandle(Persistent<Value>* value,
5170  uint16_t class_id) {}
5171 };
5172 
5173 
5182 class V8_EXPORT Isolate {
5183  public:
5187  struct CreateParams {
5188  CreateParams()
5189  : entry_hook(NULL),
5190  code_event_handler(NULL),
5191  snapshot_blob(NULL),
5192  counter_lookup_callback(NULL),
5193  create_histogram_callback(NULL),
5194  add_histogram_sample_callback(NULL),
5195  array_buffer_allocator(NULL) {}
5196 
5205 
5211 
5216 
5221 
5222 
5227  CounterLookupCallback counter_lookup_callback;
5228 
5235  CreateHistogramCallback create_histogram_callback;
5236  AddHistogramSampleCallback add_histogram_sample_callback;
5237 
5243  };
5244 
5245 
5250  class V8_EXPORT Scope {
5251  public:
5252  explicit Scope(Isolate* isolate) : isolate_(isolate) {
5253  isolate->Enter();
5254  }
5255 
5256  ~Scope() { isolate_->Exit(); }
5257 
5258  private:
5259  Isolate* const isolate_;
5260 
5261  // Prevent copying of Scope objects.
5262  Scope(const Scope&);
5263  Scope& operator=(const Scope&);
5264  };
5265 
5266 
5271  public:
5272  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
5273 
5274  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
5276 
5277  private:
5278  bool on_failure_;
5279  void* internal_;
5280 
5281  // Prevent copying of Scope objects.
5285  };
5286 
5287 
5292  public:
5293  explicit AllowJavascriptExecutionScope(Isolate* isolate);
5295 
5296  private:
5297  void* internal_throws_;
5298  void* internal_assert_;
5299 
5300  // Prevent copying of Scope objects.
5302  AllowJavascriptExecutionScope& operator=(
5304  };
5305 
5311  public:
5312  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
5314 
5315  private:
5316  internal::Isolate* isolate_;
5317 
5318  // Prevent copying of Scope objects.
5322  };
5323 
5329  kFullGarbageCollection,
5330  kMinorGarbageCollection
5331  };
5332 
5339  kUseAsm = 0,
5340  kBreakIterator = 1,
5341  kLegacyConst = 2,
5342  kMarkDequeOverflow = 3,
5343  kStoreBufferOverflow = 4,
5344  kSlotsBufferOverflow = 5,
5345  kObjectObserve = 6,
5346  kForcedGC = 7,
5347  kUseCounterFeatureCount // This enum value must be last.
5348  };
5349 
5350  typedef void (*UseCounterCallback)(Isolate* isolate,
5351  UseCounterFeature feature);
5352 
5353 
5363  static Isolate* New(const CreateParams& params);
5364 
5371  static Isolate* GetCurrent();
5372 
5382  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
5383  void SetAbortOnUncaughtExceptionCallback(
5384  AbortOnUncaughtExceptionCallback callback);
5385 
5396  void Enter();
5397 
5405  void Exit();
5406 
5411  void Dispose();
5412 
5417  V8_INLINE void SetData(uint32_t slot, void* data);
5418 
5423  V8_INLINE void* GetData(uint32_t slot);
5424 
5429  V8_INLINE static uint32_t GetNumberOfDataSlots();
5430 
5434  void GetHeapStatistics(HeapStatistics* heap_statistics);
5435 
5439  size_t NumberOfHeapSpaces();
5440 
5450  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
5451  size_t index);
5452 
5456  size_t NumberOfTrackedHeapObjectTypes();
5457 
5467  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
5468  size_t type_index);
5469 
5482  void GetStackSample(const RegisterState& state, void** frames,
5483  size_t frames_limit, SampleInfo* sample_info);
5484 
5498  V8_INLINE int64_t
5499  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
5500 
5505  HeapProfiler* GetHeapProfiler();
5506 
5512  CpuProfiler* GetCpuProfiler();
5513 
5515  bool InContext();
5516 
5518  Local<Context> GetCurrentContext();
5519 
5525  Local<Context> GetCallingContext();
5526 
5528  Local<Context> GetEnteredContext();
5529 
5536  Local<Value> ThrowException(Local<Value> exception);
5537 
5549  template<typename T> void SetObjectGroupId(const Persistent<T>& object,
5550  UniqueId id);
5551 
5559  template<typename T> void SetReferenceFromGroup(UniqueId id,
5560  const Persistent<T>& child);
5561 
5568  template<typename T, typename S>
5569  void SetReference(const Persistent<T>& parent, const Persistent<S>& child);
5570 
5571  V8_DEPRECATE_SOON("Use GCCallBack instead",
5572  typedef void (*GCPrologueCallback)(Isolate* isolate,
5573  GCType type,
5574  GCCallbackFlags flags));
5575  V8_DEPRECATE_SOON("Use GCCallBack instead",
5576  typedef void (*GCEpilogueCallback)(Isolate* isolate,
5577  GCType type,
5578  GCCallbackFlags flags));
5579  typedef void (*GCCallback)(Isolate* isolate, GCType type,
5580  GCCallbackFlags flags);
5581 
5591  void AddGCPrologueCallback(GCCallback callback,
5592  GCType gc_type_filter = kGCTypeAll);
5593 
5598  void RemoveGCPrologueCallback(GCCallback callback);
5599 
5609  void AddGCEpilogueCallback(GCCallback callback,
5610  GCType gc_type_filter = kGCTypeAll);
5611 
5616  void RemoveGCEpilogueCallback(GCCallback callback);
5617 
5625  void TerminateExecution();
5626 
5635  bool IsExecutionTerminating();
5636 
5651  void CancelTerminateExecution();
5652 
5661  void RequestInterrupt(InterruptCallback callback, void* data);
5662 
5673  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
5674 
5678  void SetEventLogger(LogEventCallback that);
5679 
5687  void AddCallCompletedCallback(CallCompletedCallback callback);
5688 
5692  void RemoveCallCompletedCallback(CallCompletedCallback callback);
5693 
5694 
5699  void SetPromiseRejectCallback(PromiseRejectCallback callback);
5700 
5705  void RunMicrotasks();
5706 
5710  void EnqueueMicrotask(Local<Function> microtask);
5711 
5715  void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
5716 
5721  void SetAutorunMicrotasks(bool autorun);
5722 
5727  bool WillAutorunMicrotasks() const;
5728 
5732  void SetUseCounterCallback(UseCounterCallback callback);
5733 
5738  void SetCounterFunction(CounterLookupCallback);
5739 
5746  void SetCreateHistogramFunction(CreateHistogramCallback);
5747  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
5748 
5763  bool IdleNotificationDeadline(double deadline_in_seconds);
5764 
5765  V8_DEPRECATE_SOON("use IdleNotificationDeadline()",
5766  bool IdleNotification(int idle_time_in_ms));
5767 
5772  void LowMemoryNotification();
5773 
5783  int ContextDisposedNotification(bool dependant_context = true);
5784 
5807  void SetJitCodeEventHandler(JitCodeEventOptions options,
5808  JitCodeEventHandler event_handler);
5809 
5819  void SetStackLimit(uintptr_t stack_limit);
5820 
5834  void GetCodeRange(void** start, size_t* length_in_bytes);
5835 
5837  void SetFatalErrorHandler(FatalErrorCallback that);
5838 
5843  void SetAllowCodeGenerationFromStringsCallback(
5845 
5850  bool IsDead();
5851 
5861  bool AddMessageListener(MessageCallback that,
5862  Local<Value> data = Local<Value>());
5863 
5867  void RemoveMessageListeners(MessageCallback that);
5868 
5870  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
5871 
5876  void SetCaptureStackTraceForUncaughtExceptions(
5877  bool capture, int frame_limit = 10,
5878  StackTrace::StackTraceOptions options = StackTrace::kOverview);
5879 
5884  void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
5885  ObjectSpace space, AllocationAction action);
5886 
5890  void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
5891 
5897  void VisitExternalResources(ExternalResourceVisitor* visitor);
5898 
5903  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
5904 
5912  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
5913 
5914  private:
5915  template <class K, class V, class Traits>
5916  friend class PersistentValueMapBase;
5917 
5918  Isolate();
5919  Isolate(const Isolate&);
5920  ~Isolate();
5921  Isolate& operator=(const Isolate&);
5922  void* operator new(size_t size);
5923  void operator delete(void*, size_t);
5924 
5925  void SetObjectGroupId(internal::Object** object, UniqueId id);
5926  void SetReferenceFromGroup(UniqueId id, internal::Object** object);
5927  void SetReference(internal::Object** parent, internal::Object** child);
5928  void CollectAllGarbage(const char* gc_reason);
5929 };
5930 
5931 class V8_EXPORT StartupData {
5932  public:
5933  const char* data;
5934  int raw_size;
5935 };
5936 
5937 
5942 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
5943 
5944 
5958 typedef uintptr_t (*ReturnAddressLocationResolver)(
5959  uintptr_t return_addr_location);
5960 
5961 
5965 class V8_EXPORT V8 {
5966  public:
5968  V8_INLINE static V8_DEPRECATE_SOON(
5969  "Use isolate version",
5970  void SetFatalErrorHandler(FatalErrorCallback that));
5971 
5976  V8_INLINE static V8_DEPRECATE_SOON(
5977  "Use isolate version", void SetAllowCodeGenerationFromStringsCallback(
5979 
5984  V8_INLINE static V8_DEPRECATE_SOON("no alternative", bool IsDead());
5985 
6001  static void SetNativesDataBlob(StartupData* startup_blob);
6002  static void SetSnapshotDataBlob(StartupData* startup_blob);
6003 
6009  static StartupData CreateSnapshotDataBlob(const char* custom_source = NULL);
6010 
6020  V8_INLINE static V8_DEPRECATE_SOON(
6021  "Use isolate version",
6022  bool AddMessageListener(MessageCallback that,
6023  Local<Value> data = Local<Value>()));
6024 
6028  V8_INLINE static V8_DEPRECATE_SOON(
6029  "Use isolate version", void RemoveMessageListeners(MessageCallback that));
6030 
6035  V8_INLINE static V8_DEPRECATE_SOON(
6036  "Use isolate version",
6037  void SetCaptureStackTraceForUncaughtExceptions(
6038  bool capture, int frame_limit = 10,
6039  StackTrace::StackTraceOptions options = StackTrace::kOverview));
6040 
6044  static void SetFlagsFromString(const char* str, int length);
6045 
6049  static void SetFlagsFromCommandLine(int* argc,
6050  char** argv,
6051  bool remove_flags);
6052 
6054  static const char* GetVersion();
6055 
6057  V8_INLINE static V8_DEPRECATE_SOON(
6058  "Use isolate version",
6059  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback));
6060 
6071  static V8_DEPRECATE_SOON(
6072  "Use isolate version",
6073  void AddGCPrologueCallback(GCCallback callback,
6074  GCType gc_type_filter = kGCTypeAll));
6075 
6080  V8_INLINE static V8_DEPRECATE_SOON(
6081  "Use isolate version",
6082  void RemoveGCPrologueCallback(GCCallback callback));
6083 
6094  static V8_DEPRECATE_SOON(
6095  "Use isolate version",
6096  void AddGCEpilogueCallback(GCCallback callback,
6097  GCType gc_type_filter = kGCTypeAll));
6098 
6103  V8_INLINE static V8_DEPRECATE_SOON(
6104  "Use isolate version",
6105  void RemoveGCEpilogueCallback(GCCallback callback));
6106 
6111  V8_INLINE static V8_DEPRECATE_SOON(
6112  "Use isolate version",
6113  void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
6114  ObjectSpace space,
6115  AllocationAction action));
6116 
6120  V8_INLINE static V8_DEPRECATE_SOON(
6121  "Use isolate version",
6122  void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback));
6123 
6128  static bool Initialize();
6129 
6134  static void SetEntropySource(EntropySource source);
6135 
6140  static void SetReturnAddressLocationResolver(
6141  ReturnAddressLocationResolver return_address_resolver);
6142 
6152  V8_INLINE static V8_DEPRECATE_SOON("Use isolate version",
6153  void TerminateExecution(Isolate* isolate));
6154 
6165  V8_INLINE static V8_DEPRECATE_SOON(
6166  "Use isolate version",
6167  bool IsExecutionTerminating(Isolate* isolate = NULL));
6168 
6185  V8_INLINE static V8_DEPRECATE_SOON(
6186  "Use isolate version", void CancelTerminateExecution(Isolate* isolate));
6187 
6197  static bool Dispose();
6198 
6204  V8_INLINE static V8_DEPRECATE_SOON(
6205  "Use isoalte version",
6206  void VisitExternalResources(ExternalResourceVisitor* visitor));
6207 
6212  V8_INLINE static V8_DEPRECATE_SOON(
6213  "Use isolate version",
6214  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor));
6215 
6220  V8_INLINE static V8_DEPRECATE_SOON(
6221  "Use isolate version",
6222  void VisitHandlesWithClassIds(Isolate* isolate,
6223  PersistentHandleVisitor* visitor));
6224 
6232  V8_INLINE static V8_DEPRECATE_SOON(
6233  "Use isolate version",
6234  void VisitHandlesForPartialDependence(Isolate* isolate,
6235  PersistentHandleVisitor* visitor));
6236 
6244  static bool InitializeICU(const char* icu_data_file = NULL);
6245 
6262  static void InitializeExternalStartupData(const char* directory_path);
6263  static void InitializeExternalStartupData(const char* natives_blob,
6264  const char* snapshot_blob);
6269  static void InitializePlatform(Platform* platform);
6270 
6275  static void ShutdownPlatform();
6276 
6277  private:
6278  V8();
6279 
6280  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
6281  internal::Object** handle);
6282  static internal::Object** CopyPersistent(internal::Object** handle);
6283  static void DisposeGlobal(internal::Object** global_handle);
6284  typedef WeakCallbackData<Value, void>::Callback WeakCallback;
6285  static void MakeWeak(internal::Object** global_handle, void* data,
6286  WeakCallback weak_callback);
6287  static void MakeWeak(internal::Object** global_handle, void* data,
6288  WeakCallbackInfo<void>::Callback weak_callback,
6289  WeakCallbackType type);
6290  static void MakeWeak(internal::Object** global_handle, void* data,
6291  // Must be 0 or -1.
6292  int internal_field_index1,
6293  // Must be 1 or -1.
6294  int internal_field_index2,
6295  WeakCallbackInfo<void>::Callback weak_callback);
6296  static void* ClearWeak(internal::Object** global_handle);
6297  static void Eternalize(Isolate* isolate,
6298  Value* handle,
6299  int* index);
6300  static Local<Value> GetEternal(Isolate* isolate, int index);
6301 
6302  static void FromJustIsNothing();
6303  static void ToLocalEmpty();
6304  static void InternalFieldOutOfBounds(int index);
6305  template <class T> friend class Local;
6306  template <class T>
6307  friend class MaybeLocal;
6308  template <class T>
6309  friend class Maybe;
6310  template <class T>
6311  friend class WeakCallbackInfo;
6312  template <class T> friend class Eternal;
6313  template <class T> friend class PersistentBase;
6314  template <class T, class M> friend class Persistent;
6315  friend class Context;
6316 };
6317 
6318 
6329 template <class T>
6330 class Maybe {
6331  public:
6332  V8_INLINE bool IsNothing() const { return !has_value; }
6333  V8_INLINE bool IsJust() const { return has_value; }
6334 
6335  // Will crash if the Maybe<> is nothing.
6336  V8_INLINE T FromJust() const {
6337  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
6338  return value;
6339  }
6340 
6341  V8_INLINE T FromMaybe(const T& default_value) const {
6342  return has_value ? value : default_value;
6343  }
6344 
6345  V8_INLINE bool operator==(const Maybe& other) const {
6346  return (IsJust() == other.IsJust()) &&
6347  (!IsJust() || FromJust() == other.FromJust());
6348  }
6349 
6350  V8_INLINE bool operator!=(const Maybe& other) const {
6351  return !operator==(other);
6352  }
6353 
6354  private:
6355  Maybe() : has_value(false) {}
6356  explicit Maybe(const T& t) : has_value(true), value(t) {}
6357 
6358  bool has_value;
6359  T value;
6360 
6361  template <class U>
6362  friend Maybe<U> Nothing();
6363  template <class U>
6364  friend Maybe<U> Just(const U& u);
6365 };
6366 
6367 
6368 template <class T>
6369 inline Maybe<T> Nothing() {
6370  return Maybe<T>();
6371 }
6372 
6373 
6374 template <class T>
6375 inline Maybe<T> Just(const T& t) {
6376  return Maybe<T>(t);
6377 }
6378 
6379 
6383 class V8_EXPORT TryCatch {
6384  public:
6390  V8_DEPRECATE_SOON("Use isolate version", TryCatch());
6391 
6397  TryCatch(Isolate* isolate);
6398 
6402  ~TryCatch();
6403 
6407  bool HasCaught() const;
6408 
6417  bool CanContinue() const;
6418 
6431  bool HasTerminated() const;
6432 
6440  Local<Value> ReThrow();
6441 
6448  Local<Value> Exception() const;
6449 
6454  V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace() const);
6455  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
6456  Local<Context> context) const;
6457 
6465  Local<v8::Message> Message() const;
6466 
6477  void Reset();
6478 
6487  void SetVerbose(bool value);
6488 
6494  void SetCaptureMessage(bool value);
6495 
6507  static void* JSStackComparableAddress(v8::TryCatch* handler) {
6508  if (handler == NULL) return NULL;
6509  return handler->js_stack_comparable_address_;
6510  }
6511 
6512  private:
6513  void ResetInternal();
6514 
6515  // Make it hard to create heap-allocated TryCatch blocks.
6516  TryCatch(const TryCatch&);
6517  void operator=(const TryCatch&);
6518  void* operator new(size_t size);
6519  void operator delete(void*, size_t);
6520 
6521  v8::internal::Isolate* isolate_;
6522  v8::TryCatch* next_;
6523  void* exception_;
6524  void* message_obj_;
6525  void* js_stack_comparable_address_;
6526  bool is_verbose_ : 1;
6527  bool can_continue_ : 1;
6528  bool capture_message_ : 1;
6529  bool rethrow_ : 1;
6530  bool has_terminated_ : 1;
6531 
6532  friend class v8::internal::Isolate;
6533 };
6534 
6535 
6536 // --- Context ---
6537 
6538 
6542 class V8_EXPORT ExtensionConfiguration {
6543  public:
6544  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
6545  ExtensionConfiguration(int name_count, const char* names[])
6546  : name_count_(name_count), names_(names) { }
6547 
6548  const char** begin() const { return &names_[0]; }
6549  const char** end() const { return &names_[name_count_]; }
6550 
6551  private:
6552  const int name_count_;
6553  const char** names_;
6554 };
6555 
6556 
6561 class V8_EXPORT Context {
6562  public:
6576 
6581  void DetachGlobal();
6582 
6601  static Local<Context> New(
6602  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
6603  Local<ObjectTemplate> global_template = Local<ObjectTemplate>(),
6604  Local<Value> global_object = Local<Value>());
6605 
6610  void SetSecurityToken(Local<Value> token);
6611 
6613  void UseDefaultSecurityToken();
6614 
6616  Local<Value> GetSecurityToken();
6617 
6624  void Enter();
6625 
6630  void Exit();
6631 
6633  v8::Isolate* GetIsolate();
6634 
6640  enum EmbedderDataFields { kDebugIdIndex = 0 };
6641 
6647  V8_INLINE Local<Value> GetEmbedderData(int index);
6648 
6655  Local<Object> GetExtrasBindingObject();
6656 
6662  void SetEmbedderData(int index, Local<Value> value);
6663 
6670  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
6671 
6677  void SetAlignedPointerInEmbedderData(int index, void* value);
6678 
6692  void AllowCodeGenerationFromStrings(bool allow);
6693 
6698  bool IsCodeGenerationFromStringsAllowed();
6699 
6705  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
6706 
6710  size_t EstimatedSize();
6711 
6716  class Scope {
6717  public:
6718  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
6719  context_->Enter();
6720  }
6721  V8_INLINE ~Scope() { context_->Exit(); }
6722 
6723  private:
6724  Local<Context> context_;
6725  };
6726 
6727  private:
6728  friend class Value;
6729  friend class Script;
6730  friend class Object;
6731  friend class Function;
6732 
6733  Local<Value> SlowGetEmbedderData(int index);
6734  void* SlowGetAlignedPointerFromEmbedderData(int index);
6735 };
6736 
6737 
6814 class V8_EXPORT Unlocker {
6815  public:
6819  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
6820 
6821  ~Unlocker();
6822  private:
6823  void Initialize(Isolate* isolate);
6824 
6825  internal::Isolate* isolate_;
6826 };
6827 
6828 
6829 class V8_EXPORT Locker {
6830  public:
6834  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
6835 
6836  ~Locker();
6837 
6842  static bool IsLocked(Isolate* isolate);
6843 
6847  static bool IsActive();
6848 
6849  private:
6850  void Initialize(Isolate* isolate);
6851 
6852  bool has_lock_;
6853  bool top_level_;
6854  internal::Isolate* isolate_;
6855 
6856  // Disallow copying and assigning.
6857  Locker(const Locker&);
6858  void operator=(const Locker&);
6859 };
6860 
6861 
6862 // --- Implementation ---
6863 
6864 
6865 namespace internal {
6866 
6867 const int kApiPointerSize = sizeof(void*); // NOLINT
6868 const int kApiIntSize = sizeof(int); // NOLINT
6869 const int kApiInt64Size = sizeof(int64_t); // NOLINT
6870 
6871 // Tag information for HeapObject.
6872 const int kHeapObjectTag = 1;
6873 const int kHeapObjectTagSize = 2;
6874 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
6875 
6876 // Tag information for Smi.
6877 const int kSmiTag = 0;
6878 const int kSmiTagSize = 1;
6879 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
6880 
6881 template <size_t ptr_size> struct SmiTagging;
6882 
6883 template<int kSmiShiftSize>
6884 V8_INLINE internal::Object* IntToSmi(int value) {
6885  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
6886  uintptr_t tagged_value =
6887  (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
6888  return reinterpret_cast<internal::Object*>(tagged_value);
6889 }
6890 
6891 // Smi constants for 32-bit systems.
6892 template <> struct SmiTagging<4> {
6893  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
6894  static int SmiShiftSize() { return kSmiShiftSize; }
6895  static int SmiValueSize() { return kSmiValueSize; }
6896  V8_INLINE static int SmiToInt(const internal::Object* value) {
6897  int shift_bits = kSmiTagSize + kSmiShiftSize;
6898  // Throw away top 32 bits and shift down (requires >> to be sign extending).
6899  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
6900  }
6901  V8_INLINE static internal::Object* IntToSmi(int value) {
6902  return internal::IntToSmi<kSmiShiftSize>(value);
6903  }
6904  V8_INLINE static bool IsValidSmi(intptr_t value) {
6905  // To be representable as an tagged small integer, the two
6906  // most-significant bits of 'value' must be either 00 or 11 due to
6907  // sign-extension. To check this we add 01 to the two
6908  // most-significant bits, and check if the most-significant bit is 0
6909  //
6910  // CAUTION: The original code below:
6911  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
6912  // may lead to incorrect results according to the C language spec, and
6913  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
6914  // compiler may produce undefined results in case of signed integer
6915  // overflow. The computation must be done w/ unsigned ints.
6916  return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
6917  }
6918 };
6919 
6920 // Smi constants for 64-bit systems.
6921 template <> struct SmiTagging<8> {
6922  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
6923  static int SmiShiftSize() { return kSmiShiftSize; }
6924  static int SmiValueSize() { return kSmiValueSize; }
6925  V8_INLINE static int SmiToInt(const internal::Object* value) {
6926  int shift_bits = kSmiTagSize + kSmiShiftSize;
6927  // Shift down and throw away top 32 bits.
6928  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
6929  }
6930  V8_INLINE static internal::Object* IntToSmi(int value) {
6931  return internal::IntToSmi<kSmiShiftSize>(value);
6932  }
6933  V8_INLINE static bool IsValidSmi(intptr_t value) {
6934  // To be representable as a long smi, the value must be a 32-bit integer.
6935  return (value == static_cast<int32_t>(value));
6936  }
6937 };
6938 
6940 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
6941 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
6942 V8_INLINE static bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
6943 V8_INLINE static bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
6944 
6950 class Internals {
6951  public:
6952  // These values match non-compiler-dependent values defined within
6953  // the implementation of v8.
6954  static const int kHeapObjectMapOffset = 0;
6955  static const int kMapInstanceTypeAndBitFieldOffset =
6956  1 * kApiPointerSize + kApiIntSize;
6957  static const int kStringResourceOffset = 3 * kApiPointerSize;
6958 
6959  static const int kOddballKindOffset = 4 * kApiPointerSize;
6960  static const int kForeignAddressOffset = kApiPointerSize;
6961  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
6962  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
6963  static const int kContextHeaderSize = 2 * kApiPointerSize;
6964  static const int kContextEmbedderDataIndex = 27;
6965  static const int kFullStringRepresentationMask = 0x07;
6966  static const int kStringEncodingMask = 0x4;
6967  static const int kExternalTwoByteRepresentationTag = 0x02;
6968  static const int kExternalOneByteRepresentationTag = 0x06;
6969 
6970  static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
6971  static const int kAmountOfExternalAllocatedMemoryOffset =
6972  4 * kApiPointerSize;
6973  static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
6974  kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size;
6975  static const int kIsolateRootsOffset =
6976  kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size +
6977  kApiPointerSize;
6978  static const int kUndefinedValueRootIndex = 5;
6979  static const int kNullValueRootIndex = 7;
6980  static const int kTrueValueRootIndex = 8;
6981  static const int kFalseValueRootIndex = 9;
6982  static const int kEmptyStringRootIndex = 10;
6983 
6984  // The external allocation limit should be below 256 MB on all architectures
6985  // to avoid that resource-constrained embedders run low on memory.
6986  static const int kExternalAllocationLimit = 192 * 1024 * 1024;
6987 
6988  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
6989  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
6990  static const int kNodeStateMask = 0x7;
6991  static const int kNodeStateIsWeakValue = 2;
6992  static const int kNodeStateIsPendingValue = 3;
6993  static const int kNodeStateIsNearDeathValue = 4;
6994  static const int kNodeIsIndependentShift = 3;
6995  static const int kNodeIsPartiallyDependentShift = 4;
6996 
6997  static const int kJSObjectType = 0xb6;
6998  static const int kFirstNonstringType = 0x80;
6999  static const int kOddballType = 0x83;
7000  static const int kForeignType = 0x87;
7001 
7002  static const int kUndefinedOddballKind = 5;
7003  static const int kNullOddballKind = 3;
7004 
7005  static const uint32_t kNumIsolateDataSlots = 4;
7006 
7007  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
7008  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
7009 #ifdef V8_ENABLE_CHECKS
7010  CheckInitializedImpl(isolate);
7011 #endif
7012  }
7013 
7014  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
7015  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
7016  kHeapObjectTag);
7017  }
7018 
7019  V8_INLINE static int SmiValue(const internal::Object* value) {
7020  return PlatformSmiTagging::SmiToInt(value);
7021  }
7022 
7023  V8_INLINE static internal::Object* IntToSmi(int value) {
7024  return PlatformSmiTagging::IntToSmi(value);
7025  }
7026 
7027  V8_INLINE static bool IsValidSmi(intptr_t value) {
7028  return PlatformSmiTagging::IsValidSmi(value);
7029  }
7030 
7031  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
7032  typedef internal::Object O;
7033  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
7034  // Map::InstanceType is defined so that it will always be loaded into
7035  // the LS 8 bits of one 16-bit word, regardless of endianess.
7036  return ReadField<uint16_t>(map, kMapInstanceTypeAndBitFieldOffset) & 0xff;
7037  }
7038 
7039  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
7040  typedef internal::Object O;
7041  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
7042  }
7043 
7044  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
7045  int representation = (instance_type & kFullStringRepresentationMask);
7046  return representation == kExternalTwoByteRepresentationTag;
7047  }
7048 
7049  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
7050  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7051  return *addr & static_cast<uint8_t>(1U << shift);
7052  }
7053 
7054  V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
7055  bool value, int shift) {
7056  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7057  uint8_t mask = static_cast<uint8_t>(1U << shift);
7058  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
7059  }
7060 
7061  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
7062  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7063  return *addr & kNodeStateMask;
7064  }
7065 
7066  V8_INLINE static void UpdateNodeState(internal::Object** obj,
7067  uint8_t value) {
7068  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7069  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
7070  }
7071 
7072  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
7073  uint32_t slot,
7074  void* data) {
7075  uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) +
7076  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
7077  *reinterpret_cast<void**>(addr) = data;
7078  }
7079 
7080  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
7081  uint32_t slot) {
7082  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
7083  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
7084  return *reinterpret_cast<void* const*>(addr);
7085  }
7086 
7087  V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
7088  int index) {
7089  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
7090  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
7091  }
7092 
7093  template <typename T>
7094  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
7095  const uint8_t* addr =
7096  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
7097  return *reinterpret_cast<const T*>(addr);
7098  }
7099 
7100  template <typename T>
7101  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
7102  typedef internal::Object O;
7103  typedef internal::Internals I;
7104  O* ctx = *reinterpret_cast<O* const*>(context);
7105  int embedder_data_offset = I::kContextHeaderSize +
7106  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
7107  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
7108  int value_offset =
7109  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
7110  return I::ReadField<T>(embedder_data, value_offset);
7111  }
7112 };
7113 
7114 } // namespace internal
7115 
7116 
7117 template <class T>
7119  return New(isolate, that.val_);
7120 }
7121 
7122 template <class T>
7123 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
7124  return New(isolate, that.val_);
7125 }
7126 
7127 
7128 template <class T>
7129 Local<T> Local<T>::New(Isolate* isolate, T* that) {
7130  if (that == NULL) return Local<T>();
7131  T* that_ptr = that;
7132  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
7133  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
7134  reinterpret_cast<internal::Isolate*>(isolate), *p)));
7135 }
7136 
7137 
7138 template<class T>
7139 template<class S>
7140 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
7141  TYPE_CHECK(T, S);
7142  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_);
7143 }
7144 
7145 
7146 template<class T>
7147 Local<T> Eternal<T>::Get(Isolate* isolate) {
7148  return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_)));
7149 }
7150 
7151 
7152 template <class T>
7153 Local<T> MaybeLocal<T>::ToLocalChecked() {
7154  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
7155  return Local<T>(val_);
7156 }
7157 
7158 
7159 template <class T>
7160 void* WeakCallbackInfo<T>::GetInternalField(int index) const {
7161 #ifdef V8_ENABLE_CHECKS
7162  if (index < 0 || index >= kInternalFieldsInWeakCallback) {
7163  V8::InternalFieldOutOfBounds(index);
7164  }
7165 #endif
7166  return internal_fields_[index];
7167 }
7168 
7169 
7170 template <class T>
7171 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
7172  if (that == NULL) return NULL;
7173  internal::Object** p = reinterpret_cast<internal::Object**>(that);
7174  return reinterpret_cast<T*>(
7175  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
7176  p));
7177 }
7178 
7179 
7180 template <class T, class M>
7181 template <class S, class M2>
7182 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
7183  TYPE_CHECK(T, S);
7184  this->Reset();
7185  if (that.IsEmpty()) return;
7186  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
7187  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
7188  M::Copy(that, this);
7189 }
7190 
7191 
7192 template <class T>
7193 bool PersistentBase<T>::IsIndependent() const {
7194  typedef internal::Internals I;
7195  if (this->IsEmpty()) return false;
7196  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7197  I::kNodeIsIndependentShift);
7198 }
7199 
7200 
7201 template <class T>
7203  typedef internal::Internals I;
7204  if (this->IsEmpty()) return false;
7205  uint8_t node_state =
7206  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
7207  return node_state == I::kNodeStateIsNearDeathValue ||
7208  node_state == I::kNodeStateIsPendingValue;
7209 }
7210 
7211 
7212 template <class T>
7214  typedef internal::Internals I;
7215  if (this->IsEmpty()) return false;
7216  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
7217  I::kNodeStateIsWeakValue;
7218 }
7219 
7220 
7221 template <class T>
7223  if (this->IsEmpty()) return;
7224  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
7225  val_ = 0;
7226 }
7227 
7228 
7229 template <class T>
7230 template <class S>
7231 void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
7232  TYPE_CHECK(T, S);
7233  Reset();
7234  if (other.IsEmpty()) return;
7235  this->val_ = New(isolate, other.val_);
7236 }
7237 
7238 
7239 template <class T>
7240 template <class S>
7241 void PersistentBase<T>::Reset(Isolate* isolate,
7242  const PersistentBase<S>& other) {
7243  TYPE_CHECK(T, S);
7244  Reset();
7245  if (other.IsEmpty()) return;
7246  this->val_ = New(isolate, other.val_);
7247 }
7248 
7249 
7250 template <class T>
7251 template <typename S, typename P>
7252 void PersistentBase<T>::SetWeak(
7253  P* parameter,
7254  typename WeakCallbackData<S, P>::Callback callback) {
7255  TYPE_CHECK(S, T);
7256  typedef typename WeakCallbackData<Value, void>::Callback Callback;
7257  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7258  reinterpret_cast<Callback>(callback));
7259 }
7260 
7261 
7262 template <class T>
7263 template <typename P>
7264 void PersistentBase<T>::SetWeak(
7265  P* parameter,
7266  typename WeakCallbackData<T, P>::Callback callback) {
7267  SetWeak<T, P>(parameter, callback);
7268 }
7269 
7270 
7271 template <class T>
7272 template <typename P>
7273 void PersistentBase<T>::SetPhantom(
7274  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
7275  int internal_field_index1, int internal_field_index2) {
7276  typedef typename WeakCallbackInfo<void>::Callback Callback;
7277  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7278  internal_field_index1, internal_field_index2,
7279  reinterpret_cast<Callback>(callback));
7280 }
7281 
7282 
7283 template <class T>
7284 template <typename P>
7285 V8_INLINE void PersistentBase<T>::SetWeak(
7286  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
7287  WeakCallbackType type) {
7288  typedef typename WeakCallbackInfo<void>::Callback Callback;
7289  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7290  reinterpret_cast<Callback>(callback), type);
7291 }
7292 
7293 
7294 template <class T>
7295 template <typename P>
7296 P* PersistentBase<T>::ClearWeak() {
7297  return reinterpret_cast<P*>(
7298  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
7299 }
7300 
7301 
7302 template <class T>
7304  typedef internal::Internals I;
7305  if (this->IsEmpty()) return;
7306  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7307  true,
7308  I::kNodeIsIndependentShift);
7309 }
7310 
7311 
7312 template <class T>
7314  typedef internal::Internals I;
7315  if (this->IsEmpty()) return;
7316  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7317  true,
7318  I::kNodeIsPartiallyDependentShift);
7319 }
7320 
7321 
7322 template <class T>
7323 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
7324  typedef internal::Internals I;
7325  if (this->IsEmpty()) return;
7326  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
7327  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
7328  *reinterpret_cast<uint16_t*>(addr) = class_id;
7329 }
7330 
7331 
7332 template <class T>
7334  typedef internal::Internals I;
7335  if (this->IsEmpty()) return 0;
7336  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
7337  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
7338  return *reinterpret_cast<uint16_t*>(addr);
7339 }
7340 
7341 
7342 template<typename T>
7343 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
7344 
7345 template<typename T>
7346 template<typename S>
7347 void ReturnValue<T>::Set(const Persistent<S>& handle) {
7348  TYPE_CHECK(T, S);
7349  if (V8_UNLIKELY(handle.IsEmpty())) {
7350  *value_ = GetDefaultValue();
7351  } else {
7352  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7353  }
7354 }
7355 
7356 template <typename T>
7357 template <typename S>
7358 void ReturnValue<T>::Set(const Global<S>& handle) {
7359  TYPE_CHECK(T, S);
7360  if (V8_UNLIKELY(handle.IsEmpty())) {
7361  *value_ = GetDefaultValue();
7362  } else {
7363  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7364  }
7365 }
7366 
7367 template <typename T>
7368 template <typename S>
7369 void ReturnValue<T>::Set(const Local<S> handle) {
7370  TYPE_CHECK(T, S);
7371  if (V8_UNLIKELY(handle.IsEmpty())) {
7372  *value_ = GetDefaultValue();
7373  } else {
7374  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7375  }
7376 }
7377 
7378 template<typename T>
7379 void ReturnValue<T>::Set(double i) {
7380  TYPE_CHECK(T, Number);
7381  Set(Number::New(GetIsolate(), i));
7382 }
7383 
7384 template<typename T>
7385 void ReturnValue<T>::Set(int32_t i) {
7386  TYPE_CHECK(T, Integer);
7387  typedef internal::Internals I;
7388  if (V8_LIKELY(I::IsValidSmi(i))) {
7389  *value_ = I::IntToSmi(i);
7390  return;
7391  }
7392  Set(Integer::New(GetIsolate(), i));
7393 }
7394 
7395 template<typename T>
7396 void ReturnValue<T>::Set(uint32_t i) {
7397  TYPE_CHECK(T, Integer);
7398  // Can't simply use INT32_MAX here for whatever reason.
7399  bool fits_into_int32_t = (i & (1U << 31)) == 0;
7400  if (V8_LIKELY(fits_into_int32_t)) {
7401  Set(static_cast<int32_t>(i));
7402  return;
7403  }
7404  Set(Integer::NewFromUnsigned(GetIsolate(), i));
7405 }
7406 
7407 template<typename T>
7408 void ReturnValue<T>::Set(bool value) {
7409  TYPE_CHECK(T, Boolean);
7410  typedef internal::Internals I;
7411  int root_index;
7412  if (value) {
7413  root_index = I::kTrueValueRootIndex;
7414  } else {
7415  root_index = I::kFalseValueRootIndex;
7416  }
7417  *value_ = *I::GetRoot(GetIsolate(), root_index);
7418 }
7419 
7420 template<typename T>
7421 void ReturnValue<T>::SetNull() {
7422  TYPE_CHECK(T, Primitive);
7423  typedef internal::Internals I;
7424  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
7425 }
7426 
7427 template<typename T>
7428 void ReturnValue<T>::SetUndefined() {
7429  TYPE_CHECK(T, Primitive);
7430  typedef internal::Internals I;
7431  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
7432 }
7433 
7434 template<typename T>
7435 void ReturnValue<T>::SetEmptyString() {
7436  TYPE_CHECK(T, String);
7437  typedef internal::Internals I;
7438  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
7439 }
7440 
7441 template<typename T>
7442 Isolate* ReturnValue<T>::GetIsolate() {
7443  // Isolate is always the pointer below the default value on the stack.
7444  return *reinterpret_cast<Isolate**>(&value_[-2]);
7445 }
7446 
7447 template<typename T>
7448 template<typename S>
7449 void ReturnValue<T>::Set(S* whatever) {
7450  // Uncompilable to prevent inadvertent misuse.
7451  TYPE_CHECK(S*, Primitive);
7452 }
7453 
7454 template<typename T>
7455 internal::Object* ReturnValue<T>::GetDefaultValue() {
7456  // Default value is always the pointer below value_ on the stack.
7457  return value_[-1];
7458 }
7459 
7460 
7461 template<typename T>
7462 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
7463  internal::Object** values,
7464  int length,
7465  bool is_construct_call)
7466  : implicit_args_(implicit_args),
7467  values_(values),
7468  length_(length),
7469  is_construct_call_(is_construct_call) { }
7470 
7471 
7472 template<typename T>
7473 Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
7474  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
7475  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
7476 }
7477 
7478 
7479 template<typename T>
7480 Local<Function> FunctionCallbackInfo<T>::Callee() const {
7481  return Local<Function>(reinterpret_cast<Function*>(
7482  &implicit_args_[kCalleeIndex]));
7483 }
7484 
7485 
7486 template<typename T>
7487 Local<Object> FunctionCallbackInfo<T>::This() const {
7488  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
7489 }
7490 
7491 
7492 template<typename T>
7493 Local<Object> FunctionCallbackInfo<T>::Holder() const {
7494  return Local<Object>(reinterpret_cast<Object*>(
7495  &implicit_args_[kHolderIndex]));
7496 }
7497 
7498 
7499 template<typename T>
7500 Local<Value> FunctionCallbackInfo<T>::Data() const {
7501  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
7502 }
7503 
7504 
7505 template<typename T>
7506 Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
7507  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
7508 }
7509 
7510 
7511 template<typename T>
7512 ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const {
7513  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
7514 }
7515 
7516 
7517 template<typename T>
7518 bool FunctionCallbackInfo<T>::IsConstructCall() const {
7519  return is_construct_call_ & 0x1;
7520 }
7521 
7522 
7523 template<typename T>
7524 int FunctionCallbackInfo<T>::Length() const {
7525  return length_;
7526 }
7527 
7528 ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
7529  Local<Integer> resource_line_offset,
7530  Local<Integer> resource_column_offset,
7531  Local<Boolean> resource_is_shared_cross_origin,
7532  Local<Integer> script_id,
7533  Local<Boolean> resource_is_embedder_debug_script,
7534  Local<Value> source_map_url,
7535  Local<Boolean> resource_is_opaque)
7536  : resource_name_(resource_name),
7537  resource_line_offset_(resource_line_offset),
7538  resource_column_offset_(resource_column_offset),
7539  options_(!resource_is_embedder_debug_script.IsEmpty() &&
7540  resource_is_embedder_debug_script->IsTrue(),
7541  !resource_is_shared_cross_origin.IsEmpty() &&
7542  resource_is_shared_cross_origin->IsTrue(),
7543  !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue()),
7544  script_id_(script_id),
7545  source_map_url_(source_map_url) {}
7546 
7547 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
7548 
7549 
7550 Local<Integer> ScriptOrigin::ResourceLineOffset() const {
7551  return resource_line_offset_;
7552 }
7553 
7554 
7555 Local<Integer> ScriptOrigin::ResourceColumnOffset() const {
7556  return resource_column_offset_;
7557 }
7558 
7559 
7560 Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
7561 
7562 
7563 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
7564 
7565 
7566 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
7567  CachedData* data)
7568  : source_string(string),
7569  resource_name(origin.ResourceName()),
7570  resource_line_offset(origin.ResourceLineOffset()),
7571  resource_column_offset(origin.ResourceColumnOffset()),
7572  resource_options(origin.Options()),
7573  source_map_url(origin.SourceMapUrl()),
7574  cached_data(data) {}
7575 
7576 
7577 ScriptCompiler::Source::Source(Local<String> string,
7578  CachedData* data)
7579  : source_string(string), cached_data(data) {}
7580 
7581 
7582 ScriptCompiler::Source::~Source() {
7583  delete cached_data;
7584 }
7585 
7586 
7587 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
7588  const {
7589  return cached_data;
7590 }
7591 
7592 
7593 Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
7594  return value ? True(isolate) : False(isolate);
7595 }
7596 
7597 
7598 void Template::Set(Isolate* isolate, const char* name, v8::Local<Data> value) {
7599  Set(v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal)
7600  .ToLocalChecked(),
7601  value);
7602 }
7603 
7604 
7606 #ifndef V8_ENABLE_CHECKS
7607  typedef internal::Object O;
7608  typedef internal::HeapObject HO;
7609  typedef internal::Internals I;
7610  O* obj = *reinterpret_cast<O**>(this);
7611  // Fast path: If the object is a plain JSObject, which is the common case, we
7612  // know where to find the internal fields and can return the value directly.
7613  if (I::GetInstanceType(obj) == I::kJSObjectType) {
7614  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
7615  O* value = I::ReadField<O*>(obj, offset);
7616  O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
7617  return Local<Value>(reinterpret_cast<Value*>(result));
7618  }
7619 #endif
7620  return SlowGetInternalField(index);
7621 }
7622 
7623 
7625 #ifndef V8_ENABLE_CHECKS
7626  typedef internal::Object O;
7627  typedef internal::Internals I;
7628  O* obj = *reinterpret_cast<O**>(this);
7629  // Fast path: If the object is a plain JSObject, which is the common case, we
7630  // know where to find the internal fields and can return the value directly.
7631  if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) {
7632  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
7633  return I::ReadField<void*>(obj, offset);
7634  }
7635 #endif
7636  return SlowGetAlignedPointerFromInternalField(index);
7637 }
7638 
7639 
7640 String* String::Cast(v8::Value* value) {
7641 #ifdef V8_ENABLE_CHECKS
7642  CheckCast(value);
7643 #endif
7644  return static_cast<String*>(value);
7645 }
7646 
7647 
7649  typedef internal::Object* S;
7650  typedef internal::Internals I;
7651  I::CheckInitialized(isolate);
7652  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
7653  return Local<String>(reinterpret_cast<String*>(slot));
7654 }
7655 
7656 
7658  typedef internal::Object O;
7659  typedef internal::Internals I;
7660  O* obj = *reinterpret_cast<O* const*>(this);
7662  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
7663  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
7664  result = reinterpret_cast<String::ExternalStringResource*>(value);
7665  } else {
7666  result = NULL;
7667  }
7668 #ifdef V8_ENABLE_CHECKS
7669  VerifyExternalStringResource(result);
7670 #endif
7671  return result;
7672 }
7673 
7674 
7676  String::Encoding* encoding_out) const {
7677  typedef internal::Object O;
7678  typedef internal::Internals I;
7679  O* obj = *reinterpret_cast<O* const*>(this);
7680  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
7681  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
7682  ExternalStringResourceBase* resource = NULL;
7683  if (type == I::kExternalOneByteRepresentationTag ||
7684  type == I::kExternalTwoByteRepresentationTag) {
7685  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
7686  resource = static_cast<ExternalStringResourceBase*>(value);
7687  }
7688 #ifdef V8_ENABLE_CHECKS
7689  VerifyExternalStringResourceBase(resource, *encoding_out);
7690 #endif
7691  return resource;
7692 }
7693 
7694 
7695 bool Value::IsUndefined() const {
7696 #ifdef V8_ENABLE_CHECKS
7697  return FullIsUndefined();
7698 #else
7699  return QuickIsUndefined();
7700 #endif
7701 }
7702 
7703 bool Value::QuickIsUndefined() const {
7704  typedef internal::Object O;
7705  typedef internal::Internals I;
7706  O* obj = *reinterpret_cast<O* const*>(this);
7707  if (!I::HasHeapObjectTag(obj)) return false;
7708  if (I::GetInstanceType(obj) != I::kOddballType) return false;
7709  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
7710 }
7711 
7712 
7713 bool Value::IsNull() const {
7714 #ifdef V8_ENABLE_CHECKS
7715  return FullIsNull();
7716 #else
7717  return QuickIsNull();
7718 #endif
7719 }
7720 
7721 bool Value::QuickIsNull() const {
7722  typedef internal::Object O;
7723  typedef internal::Internals I;
7724  O* obj = *reinterpret_cast<O* const*>(this);
7725  if (!I::HasHeapObjectTag(obj)) return false;
7726  if (I::GetInstanceType(obj) != I::kOddballType) return false;
7727  return (I::GetOddballKind(obj) == I::kNullOddballKind);
7728 }
7729 
7730 
7731 bool Value::IsString() const {
7732 #ifdef V8_ENABLE_CHECKS
7733  return FullIsString();
7734 #else
7735  return QuickIsString();
7736 #endif
7737 }
7738 
7739 bool Value::QuickIsString() const {
7740  typedef internal::Object O;
7741  typedef internal::Internals I;
7742  O* obj = *reinterpret_cast<O* const*>(this);
7743  if (!I::HasHeapObjectTag(obj)) return false;
7744  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
7745 }
7746 
7747 
7748 template <class T> Value* Value::Cast(T* value) {
7749  return static_cast<Value*>(value);
7750 }
7751 
7752 
7753 Local<Boolean> Value::ToBoolean() const {
7754  return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
7755  .FromMaybe(Local<Boolean>());
7756 }
7757 
7758 
7759 Local<Number> Value::ToNumber() const {
7760  return ToNumber(Isolate::GetCurrent()->GetCurrentContext())
7761  .FromMaybe(Local<Number>());
7762 }
7763 
7764 
7765 Local<String> Value::ToString() const {
7766  return ToString(Isolate::GetCurrent()->GetCurrentContext())
7767  .FromMaybe(Local<String>());
7768 }
7769 
7770 
7771 Local<String> Value::ToDetailString() const {
7772  return ToDetailString(Isolate::GetCurrent()->GetCurrentContext())
7773  .FromMaybe(Local<String>());
7774 }
7775 
7776 
7777 Local<Object> Value::ToObject() const {
7778  return ToObject(Isolate::GetCurrent()->GetCurrentContext())
7779  .FromMaybe(Local<Object>());
7780 }
7781 
7782 
7783 Local<Integer> Value::ToInteger() const {
7784  return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
7785  .FromMaybe(Local<Integer>());
7786 }
7787 
7788 
7789 Local<Uint32> Value::ToUint32() const {
7790  return ToUint32(Isolate::GetCurrent()->GetCurrentContext())
7791  .FromMaybe(Local<Uint32>());
7792 }
7793 
7794 
7795 Local<Int32> Value::ToInt32() const {
7796  return ToInt32(Isolate::GetCurrent()->GetCurrentContext())
7797  .FromMaybe(Local<Int32>());
7798 }
7799 
7800 
7801 Boolean* Boolean::Cast(v8::Value* value) {
7802 #ifdef V8_ENABLE_CHECKS
7803  CheckCast(value);
7804 #endif
7805  return static_cast<Boolean*>(value);
7806 }
7807 
7808 
7809 Name* Name::Cast(v8::Value* value) {
7810 #ifdef V8_ENABLE_CHECKS
7811  CheckCast(value);
7812 #endif
7813  return static_cast<Name*>(value);
7814 }
7815 
7816 
7817 Symbol* Symbol::Cast(v8::Value* value) {
7818 #ifdef V8_ENABLE_CHECKS
7819  CheckCast(value);
7820 #endif
7821  return static_cast<Symbol*>(value);
7822 }
7823 
7824 
7825 Number* Number::Cast(v8::Value* value) {
7826 #ifdef V8_ENABLE_CHECKS
7827  CheckCast(value);
7828 #endif
7829  return static_cast<Number*>(value);
7830 }
7831 
7832 
7833 Integer* Integer::Cast(v8::Value* value) {
7834 #ifdef V8_ENABLE_CHECKS
7835  CheckCast(value);
7836 #endif
7837  return static_cast<Integer*>(value);
7838 }
7839 
7840 
7841 Int32* Int32::Cast(v8::Value* value) {
7842 #ifdef V8_ENABLE_CHECKS
7843  CheckCast(value);
7844 #endif
7845  return static_cast<Int32*>(value);
7846 }
7847 
7848 
7849 Uint32* Uint32::Cast(v8::Value* value) {
7850 #ifdef V8_ENABLE_CHECKS
7851  CheckCast(value);
7852 #endif
7853  return static_cast<Uint32*>(value);
7854 }
7855 
7856 
7857 Date* Date::Cast(v8::Value* value) {
7858 #ifdef V8_ENABLE_CHECKS
7859  CheckCast(value);
7860 #endif
7861  return static_cast<Date*>(value);
7862 }
7863 
7864 
7865 StringObject* StringObject::Cast(v8::Value* value) {
7866 #ifdef V8_ENABLE_CHECKS
7867  CheckCast(value);
7868 #endif
7869  return static_cast<StringObject*>(value);
7870 }
7871 
7872 
7873 SymbolObject* SymbolObject::Cast(v8::Value* value) {
7874 #ifdef V8_ENABLE_CHECKS
7875  CheckCast(value);
7876 #endif
7877  return static_cast<SymbolObject*>(value);
7878 }
7879 
7880 
7881 NumberObject* NumberObject::Cast(v8::Value* value) {
7882 #ifdef V8_ENABLE_CHECKS
7883  CheckCast(value);
7884 #endif
7885  return static_cast<NumberObject*>(value);
7886 }
7887 
7888 
7889 BooleanObject* BooleanObject::Cast(v8::Value* value) {
7890 #ifdef V8_ENABLE_CHECKS
7891  CheckCast(value);
7892 #endif
7893  return static_cast<BooleanObject*>(value);
7894 }
7895 
7896 
7897 RegExp* RegExp::Cast(v8::Value* value) {
7898 #ifdef V8_ENABLE_CHECKS
7899  CheckCast(value);
7900 #endif
7901  return static_cast<RegExp*>(value);
7902 }
7903 
7904 
7905 Object* Object::Cast(v8::Value* value) {
7906 #ifdef V8_ENABLE_CHECKS
7907  CheckCast(value);
7908 #endif
7909  return static_cast<Object*>(value);
7910 }
7911 
7912 
7913 Array* Array::Cast(v8::Value* value) {
7914 #ifdef V8_ENABLE_CHECKS
7915  CheckCast(value);
7916 #endif
7917  return static_cast<Array*>(value);
7918 }
7919 
7920 
7921 Map* Map::Cast(v8::Value* value) {
7922 #ifdef V8_ENABLE_CHECKS
7923  CheckCast(value);
7924 #endif
7925  return static_cast<Map*>(value);
7926 }
7927 
7928 
7929 Set* Set::Cast(v8::Value* value) {
7930 #ifdef V8_ENABLE_CHECKS
7931  CheckCast(value);
7932 #endif
7933  return static_cast<Set*>(value);
7934 }
7935 
7936 
7937 Promise* Promise::Cast(v8::Value* value) {
7938 #ifdef V8_ENABLE_CHECKS
7939  CheckCast(value);
7940 #endif
7941  return static_cast<Promise*>(value);
7942 }
7943 
7944 
7945 Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
7946 #ifdef V8_ENABLE_CHECKS
7947  CheckCast(value);
7948 #endif
7949  return static_cast<Promise::Resolver*>(value);
7950 }
7951 
7952 
7953 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
7954 #ifdef V8_ENABLE_CHECKS
7955  CheckCast(value);
7956 #endif
7957  return static_cast<ArrayBuffer*>(value);
7958 }
7959 
7960 
7961 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
7962 #ifdef V8_ENABLE_CHECKS
7963  CheckCast(value);
7964 #endif
7965  return static_cast<ArrayBufferView*>(value);
7966 }
7967 
7968 
7969 TypedArray* TypedArray::Cast(v8::Value* value) {
7970 #ifdef V8_ENABLE_CHECKS
7971  CheckCast(value);
7972 #endif
7973  return static_cast<TypedArray*>(value);
7974 }
7975 
7976 
7977 Uint8Array* Uint8Array::Cast(v8::Value* value) {
7978 #ifdef V8_ENABLE_CHECKS
7979  CheckCast(value);
7980 #endif
7981  return static_cast<Uint8Array*>(value);
7982 }
7983 
7984 
7985 Int8Array* Int8Array::Cast(v8::Value* value) {
7986 #ifdef V8_ENABLE_CHECKS
7987  CheckCast(value);
7988 #endif
7989  return static_cast<Int8Array*>(value);
7990 }
7991 
7992 
7993 Uint16Array* Uint16Array::Cast(v8::Value* value) {
7994 #ifdef V8_ENABLE_CHECKS
7995  CheckCast(value);
7996 #endif
7997  return static_cast<Uint16Array*>(value);
7998 }
7999 
8000 
8001 Int16Array* Int16Array::Cast(v8::Value* value) {
8002 #ifdef V8_ENABLE_CHECKS
8003  CheckCast(value);
8004 #endif
8005  return static_cast<Int16Array*>(value);
8006 }
8007 
8008 
8009 Uint32Array* Uint32Array::Cast(v8::Value* value) {
8010 #ifdef V8_ENABLE_CHECKS
8011  CheckCast(value);
8012 #endif
8013  return static_cast<Uint32Array*>(value);
8014 }
8015 
8016 
8017 Int32Array* Int32Array::Cast(v8::Value* value) {
8018 #ifdef V8_ENABLE_CHECKS
8019  CheckCast(value);
8020 #endif
8021  return static_cast<Int32Array*>(value);
8022 }
8023 
8024 
8025 Float32Array* Float32Array::Cast(v8::Value* value) {
8026 #ifdef V8_ENABLE_CHECKS
8027  CheckCast(value);
8028 #endif
8029  return static_cast<Float32Array*>(value);
8030 }
8031 
8032 
8033 Float64Array* Float64Array::Cast(v8::Value* value) {
8034 #ifdef V8_ENABLE_CHECKS
8035  CheckCast(value);
8036 #endif
8037  return static_cast<Float64Array*>(value);
8038 }
8039 
8040 
8041 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
8042 #ifdef V8_ENABLE_CHECKS
8043  CheckCast(value);
8044 #endif
8045  return static_cast<Uint8ClampedArray*>(value);
8046 }
8047 
8048 
8049 DataView* DataView::Cast(v8::Value* value) {
8050 #ifdef V8_ENABLE_CHECKS
8051  CheckCast(value);
8052 #endif
8053  return static_cast<DataView*>(value);
8054 }
8055 
8056 
8057 SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
8058 #ifdef V8_ENABLE_CHECKS
8059  CheckCast(value);
8060 #endif
8061  return static_cast<SharedArrayBuffer*>(value);
8062 }
8063 
8064 
8065 Function* Function::Cast(v8::Value* value) {
8066 #ifdef V8_ENABLE_CHECKS
8067  CheckCast(value);
8068 #endif
8069  return static_cast<Function*>(value);
8070 }
8071 
8072 
8073 External* External::Cast(v8::Value* value) {
8074 #ifdef V8_ENABLE_CHECKS
8075  CheckCast(value);
8076 #endif
8077  return static_cast<External*>(value);
8078 }
8079 
8080 
8081 template<typename T>
8082 Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
8083  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
8084 }
8085 
8086 
8087 template<typename T>
8088 Local<Value> PropertyCallbackInfo<T>::Data() const {
8089  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
8090 }
8091 
8092 
8093 template<typename T>
8094 Local<Object> PropertyCallbackInfo<T>::This() const {
8095  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
8096 }
8097 
8098 
8099 template<typename T>
8100 Local<Object> PropertyCallbackInfo<T>::Holder() const {
8101  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
8102 }
8103 
8104 
8105 template<typename T>
8106 ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
8107  return ReturnValue<T>(&args_[kReturnValueIndex]);
8108 }
8109 
8110 
8111 Local<Primitive> Undefined(Isolate* isolate) {
8112  typedef internal::Object* S;
8113  typedef internal::Internals I;
8114  I::CheckInitialized(isolate);
8115  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
8116  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
8117 }
8118 
8119 
8120 Local<Primitive> Null(Isolate* isolate) {
8121  typedef internal::Object* S;
8122  typedef internal::Internals I;
8123  I::CheckInitialized(isolate);
8124  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
8125  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
8126 }
8127 
8128 
8129 Local<Boolean> True(Isolate* isolate) {
8130  typedef internal::Object* S;
8131  typedef internal::Internals I;
8132  I::CheckInitialized(isolate);
8133  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
8134  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
8135 }
8136 
8137 
8138 Local<Boolean> False(Isolate* isolate) {
8139  typedef internal::Object* S;
8140  typedef internal::Internals I;
8141  I::CheckInitialized(isolate);
8142  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
8143  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
8144 }
8145 
8146 
8147 void Isolate::SetData(uint32_t slot, void* data) {
8148  typedef internal::Internals I;
8149  I::SetEmbedderData(this, slot, data);
8150 }
8151 
8152 
8153 void* Isolate::GetData(uint32_t slot) {
8154  typedef internal::Internals I;
8155  return I::GetEmbedderData(this, slot);
8156 }
8157 
8158 
8160  typedef internal::Internals I;
8161  return I::kNumIsolateDataSlots;
8162 }
8163 
8164 
8166  int64_t change_in_bytes) {
8167  typedef internal::Internals I;
8168  int64_t* amount_of_external_allocated_memory =
8169  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
8170  I::kAmountOfExternalAllocatedMemoryOffset);
8171  int64_t* amount_of_external_allocated_memory_at_last_global_gc =
8172  reinterpret_cast<int64_t*>(
8173  reinterpret_cast<uint8_t*>(this) +
8174  I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
8175  int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
8176  if (change_in_bytes > 0 &&
8177  amount - *amount_of_external_allocated_memory_at_last_global_gc >
8178  I::kExternalAllocationLimit) {
8179  CollectAllGarbage("external memory allocation limit reached.");
8180  }
8181  *amount_of_external_allocated_memory = amount;
8182  return *amount_of_external_allocated_memory;
8183 }
8184 
8185 
8186 template<typename T>
8188  UniqueId id) {
8189  TYPE_CHECK(Value, T);
8190  SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id);
8191 }
8192 
8193 
8194 template<typename T>
8196  const Persistent<T>& object) {
8197  TYPE_CHECK(Value, T);
8198  SetReferenceFromGroup(id,
8199  reinterpret_cast<v8::internal::Object**>(object.val_));
8200 }
8201 
8202 
8203 template<typename T, typename S>
8205  const Persistent<S>& child) {
8206  TYPE_CHECK(Object, T);
8207  TYPE_CHECK(Value, S);
8208  SetReference(reinterpret_cast<v8::internal::Object**>(parent.val_),
8209  reinterpret_cast<v8::internal::Object**>(child.val_));
8210 }
8211 
8212 
8214 #ifndef V8_ENABLE_CHECKS
8215  typedef internal::Object O;
8216  typedef internal::HeapObject HO;
8217  typedef internal::Internals I;
8218  HO* context = *reinterpret_cast<HO**>(this);
8219  O** result =
8220  HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
8221  return Local<Value>(reinterpret_cast<Value*>(result));
8222 #else
8223  return SlowGetEmbedderData(index);
8224 #endif
8225 }
8226 
8227 
8229 #ifndef V8_ENABLE_CHECKS
8230  typedef internal::Internals I;
8231  return I::ReadEmbedderData<void*>(this, index);
8232 #else
8233  return SlowGetAlignedPointerFromEmbedderData(index);
8234 #endif
8235 }
8236 
8237 
8238 void V8::SetAllowCodeGenerationFromStringsCallback(
8240  Isolate* isolate = Isolate::GetCurrent();
8241  isolate->SetAllowCodeGenerationFromStringsCallback(callback);
8242 }
8243 
8244 
8245 bool V8::IsDead() {
8246  Isolate* isolate = Isolate::GetCurrent();
8247  return isolate->IsDead();
8248 }
8249 
8250 
8251 bool V8::AddMessageListener(MessageCallback that, Local<Value> data) {
8252  Isolate* isolate = Isolate::GetCurrent();
8253  return isolate->AddMessageListener(that, data);
8254 }
8255 
8256 
8257 void V8::RemoveMessageListeners(MessageCallback that) {
8258  Isolate* isolate = Isolate::GetCurrent();
8259  isolate->RemoveMessageListeners(that);
8260 }
8261 
8262 
8263 void V8::SetFailedAccessCheckCallbackFunction(
8264  FailedAccessCheckCallback callback) {
8265  Isolate* isolate = Isolate::GetCurrent();
8266  isolate->SetFailedAccessCheckCallbackFunction(callback);
8267 }
8268 
8269 
8270 void V8::SetCaptureStackTraceForUncaughtExceptions(
8271  bool capture, int frame_limit, StackTrace::StackTraceOptions options) {
8272  Isolate* isolate = Isolate::GetCurrent();
8273  isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit,
8274  options);
8275 }
8276 
8277 
8278 void V8::SetFatalErrorHandler(FatalErrorCallback callback) {
8279  Isolate* isolate = Isolate::GetCurrent();
8280  isolate->SetFatalErrorHandler(callback);
8281 }
8282 
8283 
8284 void V8::RemoveGCPrologueCallback(GCCallback callback) {
8285  Isolate* isolate = Isolate::GetCurrent();
8286  isolate->RemoveGCPrologueCallback(
8287  reinterpret_cast<v8::Isolate::GCCallback>(callback));
8288 }
8289 
8290 
8291 void V8::RemoveGCEpilogueCallback(GCCallback callback) {
8292  Isolate* isolate = Isolate::GetCurrent();
8293  isolate->RemoveGCEpilogueCallback(
8294  reinterpret_cast<v8::Isolate::GCCallback>(callback));
8295 }
8296 
8297 
8298 void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback,
8299  ObjectSpace space,
8300  AllocationAction action) {
8301  Isolate* isolate = Isolate::GetCurrent();
8302  isolate->AddMemoryAllocationCallback(callback, space, action);
8303 }
8304 
8305 
8306 void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) {
8307  Isolate* isolate = Isolate::GetCurrent();
8308  isolate->RemoveMemoryAllocationCallback(callback);
8309 }
8310 
8311 
8312 void V8::TerminateExecution(Isolate* isolate) { isolate->TerminateExecution(); }
8313 
8314 
8315 bool V8::IsExecutionTerminating(Isolate* isolate) {
8316  if (isolate == NULL) {
8317  isolate = Isolate::GetCurrent();
8318  }
8319  return isolate->IsExecutionTerminating();
8320 }
8321 
8322 
8323 void V8::CancelTerminateExecution(Isolate* isolate) {
8324  isolate->CancelTerminateExecution();
8325 }
8326 
8327 
8328 void V8::VisitExternalResources(ExternalResourceVisitor* visitor) {
8329  Isolate* isolate = Isolate::GetCurrent();
8330  isolate->VisitExternalResources(visitor);
8331 }
8332 
8333 
8334 void V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
8335  Isolate* isolate = Isolate::GetCurrent();
8336  isolate->VisitHandlesWithClassIds(visitor);
8337 }
8338 
8339 
8340 void V8::VisitHandlesWithClassIds(Isolate* isolate,
8341  PersistentHandleVisitor* visitor) {
8342  isolate->VisitHandlesWithClassIds(visitor);
8343 }
8344 
8345 
8346 void V8::VisitHandlesForPartialDependence(Isolate* isolate,
8347  PersistentHandleVisitor* visitor) {
8348  isolate->VisitHandlesForPartialDependence(visitor);
8349 }
8350 
8363 } // namespace v8
8364 
8365 
8366 #undef TYPE_CHECK
8367 
8368 
8369 #endif // V8_H_
Definition: v8.h:2480
Definition: v8.h:3585
Definition: v8.h:1088
void(* NamedPropertyDeleterCallback)(Local< String > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:4114
UseCounterFeature
Definition: v8.h:5338
IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback getter=0, IndexedPropertySetterCallback setter=0, IndexedPropertyQueryCallback query=0, IndexedPropertyDeleterCallback deleter=0, IndexedPropertyEnumeratorCallback enumerator=0, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
Definition: v8.h:4476
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:4205
void SetReferenceFromGroup(UniqueId id, const Persistent< T > &child)
Definition: v8.h:8195
Definition: v8.h:3693
Definition: v8-profiler.h:582
V8_INLINE bool operator==(const Local< S > &that) const
Definition: v8.h:245
V8_INLINE uint16_t WrapperClassId() const
Definition: v8.h:7333
Definition: v8.h:1055
V8_INLINE bool IsWeak() const
Definition: v8.h:7213
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
Definition: v8.h:4244
void(* NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:4123
void SetReference(const Persistent< T > &parent, const Persistent< S > &child)
Definition: v8.h:8204
WriteOptions
Definition: v8.h:2136
static Isolate * GetCurrent()
Definition: v8.h:118
Definition: v8.h:5036
Definition: v8.h:3639
V8_INLINE void Clear()
Definition: v8.h:232
virtual ~ExternalStringResource()
Definition: v8.h:2214
Definition: v8.h:6814
GarbageCollectionType
Definition: v8.h:5328
V8_INLINE Local< T > Escape(Local< T > value)
Definition: v8.h:936
V8_INLINE void MarkPartiallyDependent()
Definition: v8.h:7313
Definition: v8.h:1021
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
Definition: v8.h:2764
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
Definition: v8.h:811
Definition: v8.h:3272
Definition: v8.h:3729
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Definition: v8.h:2783
void(* GenericNamedPropertyDeleterCallback)(Local< Name > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:4160
void(* NamedPropertySetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4093
Definition: v8.h:6950
EmbedderDataFields
Definition: v8.h:6640
virtual ~ExternalOneByteStringResource()
Definition: v8.h:2247
Definition: v8.h:4910
Definition: v8.h:85
Definition: v8.h:3747
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:2546
Definition: v8.h:2055
Definition: v8.h:6881
Definition: v8.h:1683
Definition: v8.h:2041
Definition: v8-util.h:161
Definition: v8.h:1510
Definition: v8.h:3397
Definition: v8.h:1123
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
Definition: v8.h:708
Definition: v8.h:6561
Definition: v8.h:136
Definition: v8.h:4672
Definition: v8.h:5114
JitCodeEventOptions
Definition: v8.h:5138
Definition: v8.h:2078
Definition: v8-platform.h:42
bool(* EntropySource)(unsigned char *buffer, size_t length)
Definition: v8.h:5942
Definition: v8.h:1167
Definition: v8.h:1628
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, v8::NewStringType type, int length=-1)
Definition: v8.h:4993
Definition: v8.h:3603
Definition: v8.h:109
V8_INLINE void * GetAlignedPointerFromEmbedderData(int index)
Definition: v8.h:8228
V8_INLINE Global()
Definition: v8.h:794
V8_INLINE Unlocker(Isolate *isolate)
Definition: v8.h:6819
V8_INLINE Persistent(const Persistent &that)
Definition: v8.h:728
Definition: v8.h:2034
Definition: v8.h:5187
CreateHistogramCallback create_histogram_callback
Definition: v8.h:5235
void(* GenericNamedPropertyQueryCallback)(Local< Name > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:4151
Definition: v8.h:2945
V8_INLINE Local< Integer > ScriptID() const
Definition: v8.h:7560
Definition: v8.h:5076
void(* GenericNamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:4168
size_t length() const
Definition: v8.h:4722
Definition: v8.h:449
Definition: v8.h:1562
StartupData * snapshot_blob
Definition: v8.h:5220
Definition: v8.h:5250
void SetAllowCodeGenerationFromStringsCallback(AllowCodeGenerationFromStringsCallback callback)
Definition: v8-debug.h:13
Definition: v8.h:873
Definition: v8.h:4345
Definition: v8.h:112
Definition: v8.h:1667
Definition: v8.h:5156
Definition: v8.h:3356
V8_INLINE Global & operator=(Global< S > &&rhs)
Definition: v8.h:826
Definition: v8.h:5106
CounterLookupCallback counter_lookup_callback
Definition: v8.h:5227
AccessType
Definition: v8.h:4221
static void * JSStackComparableAddress(v8::TryCatch *handler)
Definition: v8.h:6507
Definition: v8-util.h:419
Definition: v8.h:2415
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4176
V8_INLINE Local< Value > GetEmbedderData(int index)
Definition: v8.h:8213
Definition: v8.h:3180
void(* NamedPropertyGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4084
Definition: v8.h:404
FunctionEntryHook entry_hook
Definition: v8.h:5204
Definition: v8.h:4845
V8_INLINE Persistent()
Definition: v8.h:701
Definition: v8.h:116
Definition: v8.h:3621
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4185
Definition: v8.h:1430
Definition: v8.h:3274
Definition: v8.h:3882
Definition: v8.h:4687
Definition: v8.h:3657
Definition: v8.h:3019
Flags
Definition: v8.h:3954
V8_INLINE Local(Local< S > that)
Definition: v8.h:214
V8_INLINE ExternalStringResourceBase * GetExternalStringResourceBase(Encoding *encoding_out) const
Definition: v8.h:7675
Definition: v8.h:2393
V8_INLINE Locker(Isolate *isolate)
Definition: v8.h:6834
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:4214
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:4195
V8_INLINE void MarkIndependent()
Definition: v8.h:7303
Definition: v8.h:3760
Definition: v8.h:4016
V8_INLINE void SetData(uint32_t slot, void *data)
Definition: v8.h:8147
void Set(Local< Name > name, Local< Data > value, PropertyAttribute attributes=None)
Definition: v8-util.h:562
void(* JitCodeEventHandler)(const JitCodeEvent *event)
Definition: v8.h:5150
Definition: v8.h:3499
Definition: v8.h:989
Definition: v8.h:111
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Definition: v8.h:718
V8_INLINE Global(Isolate *isolate, Local< S > that)
Definition: v8.h:801
static V8_INLINE uint32_t GetNumberOfDataSlots()
Definition: v8.h:8159
Definition: v8.h:4732
Definition: v8.h:1637
V8_INLINE ExternalStringResource * GetExternalStringResource() const
Definition: v8.h:7657
V8_INLINE void SetWrapperClassId(uint16_t class_id)
Definition: v8.h:7323
V8_INLINE void * GetAlignedPointerFromInternalField(int index)
Definition: v8.h:7624
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8.h:7118
V8_INLINE bool operator!=(const Local< S > &that) const
Definition: v8.h:269
void(* GenericNamedPropertyGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4133
Definition: v8.h:6383
Definition: v8.h:155
const char * data() const
Definition: v8.h:4721
Definition: v8.h:4000
Definition: v8-profiler.h:181
Definition: v8.h:955
V8_INLINE bool IsNearDeath() const
Definition: v8.h:7202
StackTraceOptions
Definition: v8.h:1516
JitCodeEventHandler code_event_handler
Definition: v8.h:5210
Definition: v8.h:3547
Definition: v8.h:926
Definition: v8.h:3845
Definition: v8.h:3948
Definition: v8.h:2584
Definition: v8.h:677
Definition: v8.h:6716
static V8_INLINE v8::Local< v8::String > Empty(Isolate *isolate)
Definition: v8.h:7648
V8_INLINE Global(Global &&other)
Definition: v8.h:818
V8_INLINE void * GetData(uint32_t slot)
Definition: v8.h:8153
void SetObjectGroupId(const Persistent< T > &object, UniqueId id)
Definition: v8.h:8187
Definition: v8.h:129
ArrayBuffer::Allocator * array_buffer_allocator
Definition: v8.h:5242
V8_INLINE int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes)
Definition: v8.h:8165
V8_INLINE bool IsEmpty() const
Definition: v8.h:227
void Enter()
Definition: v8.h:5166
Definition: v8.h:2444
Definition: v8.h:3365
Definition: v8.h:4509
Definition: v8.h:130
GCType
Definition: v8.h:4960
V8_INLINE V8_DEPRECATE_SOON("use WeakCallbackInfo version", void SetWeak(P *parameter, typename WeakCallbackData< T, P >::Callback callback))
Definition: v8.h:1132
Definition: v8-profiler.h:425
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
Definition: v8.h:4234
Definition: v8.h:1646
Definition: v8.h:5931
Definition: v8.h:5965
Definition: v8.h:3932
Definition: v8.h:125
Definition: v8.h:6542
Definition: v8.h:4702
Definition: v8.h:5016
Definition: v8.h:980
Definition: v8.h:3567
virtual void Dispose()
Definition: v8.h:2191
void(* GenericNamedPropertySetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4141
Definition: v8.h:3675
Definition: v8.h:4790
Definition: v8.h:3898
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
Definition: v8.h:5958
Definition: v8.h:2509
V8_INLINE void Reset()
Definition: v8.h:7222
Definition: v8.h:6829
V8_INLINE bool IsNull() const
Definition: v8.h:7713
bool(* AllowCodeGenerationFromStringsCallback)(Local< Context > context)
Definition: v8.h:4949
Definition: v8.h:5182
Definition: v8.h:3914
Definition: v8.h:2523
AccessControl
Definition: v8.h:2573
void(* FunctionEntryHook)(uintptr_t function, uintptr_t return_addr_location)
Definition: v8.h:5068
V8_INLINE bool IsString() const
Definition: v8.h:7731
Definition: v8-util.h:352
Global Pass()
Definition: v8.h:838
Definition: v8.h:3711
void(* NamedPropertyQueryCallback)(Local< String > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:4104
ResourceConstraints constraints
Definition: v8.h:5215
Definition: v8.h:2974
Definition: v8.h:2494
V8_INLINE Local< Value > GetInternalField(int index)
Definition: v8.h:7605
Definition: v8.h:145
Definition: v8.h:114
V8_INLINE bool IsUndefined() const
Definition: v8.h:7695
V8_INLINE ~Persistent()
Definition: v8.h:749
NamedPropertyHandlerConfiguration(GenericNamedPropertyGetterCallback getter=0, GenericNamedPropertySetterCallback setter=0, GenericNamedPropertyQueryCallback query=0, GenericNamedPropertyDeleterCallback deleter=0, GenericNamedPropertyEnumeratorCallback enumerator=0, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
Definition: v8.h:4448