V8 API Reference Guide for node.js v4.8.3 - v4.8.5
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  template <class S>
513  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
514  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
515  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
516  if (a == NULL) return b == NULL;
517  if (b == NULL) return false;
518  return *a == *b;
519  }
520 
521  template <class S>
522  V8_INLINE bool operator==(const Local<S>& that) const {
523  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
524  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
525  if (a == NULL) return b == NULL;
526  if (b == NULL) return false;
527  return *a == *b;
528  }
529 
530  template <class S>
531  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
532  return !operator==(that);
533  }
534 
535  template <class S>
536  V8_INLINE bool operator!=(const Local<S>& that) const {
537  return !operator==(that);
538  }
539 
547  template <typename P>
548  V8_INLINE V8_DEPRECATE_SOON(
549  "use WeakCallbackInfo version",
550  void SetWeak(P* parameter,
551  typename WeakCallbackData<T, P>::Callback callback));
552 
553  template <typename S, typename P>
554  V8_INLINE V8_DEPRECATE_SOON(
555  "use WeakCallbackInfo version",
556  void SetWeak(P* parameter,
557  typename WeakCallbackData<S, P>::Callback callback));
558 
559  // Phantom persistents work like weak persistents, except that the pointer to
560  // the object being collected is not available in the finalization callback.
561  // This enables the garbage collector to collect the object and any objects
562  // it references transitively in one GC cycle. At the moment you can either
563  // specify a parameter for the callback or the location of two internal
564  // fields in the dying object.
565  template <typename P>
566  V8_INLINE V8_DEPRECATE_SOON(
567  "use SetWeak",
568  void SetPhantom(P* parameter,
569  typename WeakCallbackInfo<P>::Callback callback,
570  int internal_field_index1 = -1,
571  int internal_field_index2 = -1));
572 
573  template <typename P>
574  V8_INLINE void SetWeak(P* parameter,
575  typename WeakCallbackInfo<P>::Callback callback,
576  WeakCallbackType type);
577 
578  template<typename P>
579  V8_INLINE P* ClearWeak();
580 
581  // TODO(dcarney): remove this.
582  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
583 
590  V8_INLINE void MarkIndependent();
591 
600  V8_INLINE void MarkPartiallyDependent();
601 
602  V8_INLINE bool IsIndependent() const;
603 
605  V8_INLINE bool IsNearDeath() const;
606 
608  V8_INLINE bool IsWeak() const;
609 
614  V8_INLINE void SetWrapperClassId(uint16_t class_id);
615 
620  V8_INLINE uint16_t WrapperClassId() const;
621 
622  private:
623  friend class Isolate;
624  friend class Utils;
625  template<class F> friend class Local;
626  template<class F1, class F2> friend class Persistent;
627  template <class F>
628  friend class Global;
629  template<class F> friend class PersistentBase;
630  template<class F> friend class ReturnValue;
631  template <class F1, class F2, class F3>
632  friend class PersistentValueMapBase;
633  template<class F1, class F2> friend class PersistentValueVector;
634  friend class Object;
635 
636  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
637  PersistentBase(PersistentBase& other) = delete; // NOLINT
638  void operator=(PersistentBase&) = delete;
639  V8_INLINE static T* New(Isolate* isolate, T* that);
640 
641  T* val_;
642 };
643 
644 
651 template<class T>
653  public:
654  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
655  static const bool kResetInDestructor = false;
656  template<class S, class M>
657  V8_INLINE static void Copy(const Persistent<S, M>& source,
658  NonCopyablePersistent* dest) {
659  Uncompilable<Object>();
660  }
661  // TODO(dcarney): come up with a good compile error here.
662  template<class O> V8_INLINE static void Uncompilable() {
663  TYPE_CHECK(O, Primitive);
664  }
665 };
666 
667 
672 template<class T>
675  static const bool kResetInDestructor = true;
676  template<class S, class M>
677  static V8_INLINE void Copy(const Persistent<S, M>& source,
678  CopyablePersistent* dest) {
679  // do nothing, just allow copy
680  }
681 };
682 
683 
692 template <class T, class M> class Persistent : public PersistentBase<T> {
693  public:
697  V8_INLINE Persistent() : PersistentBase<T>(0) { }
703  template <class S>
704  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
705  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
706  TYPE_CHECK(T, S);
707  }
713  template <class S, class M2>
714  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
715  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
716  TYPE_CHECK(T, S);
717  }
724  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
725  Copy(that);
726  }
727  template <class S, class M2>
728  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
729  Copy(that);
730  }
731  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
732  Copy(that);
733  return *this;
734  }
735  template <class S, class M2>
736  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
737  Copy(that);
738  return *this;
739  }
745  V8_INLINE ~Persistent() {
746  if (M::kResetInDestructor) this->Reset();
747  }
748 
749  // TODO(dcarney): this is pretty useless, fix or remove
750  template <class S>
751  V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT
752 #ifdef V8_ENABLE_CHECKS
753  // If we're going to perform the type check then we have to check
754  // that the handle isn't empty before doing the checked cast.
755  if (!that.IsEmpty()) T::Cast(*that);
756 #endif
757  return reinterpret_cast<Persistent<T>&>(that);
758  }
759 
760  // TODO(dcarney): this is pretty useless, fix or remove
761  template <class S> V8_INLINE Persistent<S>& As() { // NOLINT
762  return Persistent<S>::Cast(*this);
763  }
764 
765  private:
766  friend class Isolate;
767  friend class Utils;
768  template<class F> friend class Local;
769  template<class F1, class F2> friend class Persistent;
770  template<class F> friend class ReturnValue;
771 
772  template <class S> V8_INLINE Persistent(S* that) : PersistentBase<T>(that) { }
773  V8_INLINE T* operator*() const { return this->val_; }
774  template<class S, class M2>
775  V8_INLINE void Copy(const Persistent<S, M2>& that);
776 };
777 
778 
784 template <class T>
785 class Global : public PersistentBase<T> {
786  public:
790  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
796  template <class S>
797  V8_INLINE Global(Isolate* isolate, Local<S> that)
798  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
799  TYPE_CHECK(T, S);
800  }
806  template <class S>
807  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
808  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
809  TYPE_CHECK(T, S);
810  }
814  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) {
815  other.val_ = nullptr;
816  }
817  V8_INLINE ~Global() { this->Reset(); }
821  template <class S>
822  V8_INLINE Global& operator=(Global<S>&& rhs) {
823  TYPE_CHECK(T, S);
824  if (this != &rhs) {
825  this->Reset();
826  this->val_ = rhs.val_;
827  rhs.val_ = nullptr;
828  }
829  return *this;
830  }
834  Global Pass() { return static_cast<Global&&>(*this); }
835 
836  /*
837  * For compatibility with Chromium's base::Bind (base::Passed).
838  */
839  typedef void MoveOnlyTypeForCPP03;
840 
841  private:
842  template <class F>
843  friend class ReturnValue;
844  Global(Global&) = delete;
845  void operator=(Global&) = delete;
846  V8_INLINE T* operator*() const { return this->val_; }
847 };
848 
849 
850 // UniquePersistent is an alias for Global for historical reason.
851 template <class T>
853 
854 
869 class V8_EXPORT HandleScope {
870  public:
871  HandleScope(Isolate* isolate);
872 
873  ~HandleScope();
874 
878  static int NumberOfHandles(Isolate* isolate);
879 
880  V8_INLINE Isolate* GetIsolate() const {
881  return reinterpret_cast<Isolate*>(isolate_);
882  }
883 
884  protected:
885  V8_INLINE HandleScope() {}
886 
887  void Initialize(Isolate* isolate);
888 
889  static internal::Object** CreateHandle(internal::Isolate* isolate,
890  internal::Object* value);
891 
892  private:
893  // Uses heap_object to obtain the current Isolate.
894  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
895  internal::Object* value);
896 
897  // Make it hard to create heap-allocated or illegal handle scopes by
898  // disallowing certain operations.
899  HandleScope(const HandleScope&);
900  void operator=(const HandleScope&);
901  void* operator new(size_t size);
902  void operator delete(void*, size_t);
903 
904  internal::Isolate* isolate_;
905  internal::Object** prev_next_;
906  internal::Object** prev_limit_;
907 
908  // Local::New uses CreateHandle with an Isolate* parameter.
909  template<class F> friend class Local;
910 
911  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
912  // a HeapObject* in their shortcuts.
913  friend class Object;
914  friend class Context;
915 };
916 
917 
922 class V8_EXPORT EscapableHandleScope : public HandleScope {
923  public:
924  EscapableHandleScope(Isolate* isolate);
925  V8_INLINE ~EscapableHandleScope() {}
926 
931  template <class T>
932  V8_INLINE Local<T> Escape(Local<T> value) {
933  internal::Object** slot =
934  Escape(reinterpret_cast<internal::Object**>(*value));
935  return Local<T>(reinterpret_cast<T*>(slot));
936  }
937 
938  private:
939  internal::Object** Escape(internal::Object** escape_value);
940 
941  // Make it hard to create heap-allocated or illegal handle scopes by
942  // disallowing certain operations.
944  void operator=(const EscapableHandleScope&);
945  void* operator new(size_t size);
946  void operator delete(void*, size_t);
947 
948  internal::Object** escape_slot_;
949 };
950 
951 class V8_EXPORT SealHandleScope {
952  public:
953  SealHandleScope(Isolate* isolate);
954  ~SealHandleScope();
955 
956  private:
957  // Make it hard to create heap-allocated or illegal handle scopes by
958  // disallowing certain operations.
960  void operator=(const SealHandleScope&);
961  void* operator new(size_t size);
962  void operator delete(void*, size_t);
963 
964  internal::Isolate* isolate_;
965  int prev_level_;
966  internal::Object** prev_limit_;
967 };
968 
969 
970 // --- Special objects ---
971 
972 
976 class V8_EXPORT Data {
977  private:
978  Data();
979 };
980 
981 
986  public:
987  V8_INLINE ScriptOriginOptions(bool is_embedder_debug_script = false,
988  bool is_shared_cross_origin = false,
989  bool is_opaque = false)
990  : flags_((is_embedder_debug_script ? kIsEmbedderDebugScript : 0) |
991  (is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
992  (is_opaque ? kIsOpaque : 0)) {}
993  V8_INLINE ScriptOriginOptions(int flags)
994  : flags_(flags &
995  (kIsEmbedderDebugScript | kIsSharedCrossOrigin | kIsOpaque)) {}
996  bool IsEmbedderDebugScript() const {
997  return (flags_ & kIsEmbedderDebugScript) != 0;
998  }
999  bool IsSharedCrossOrigin() const {
1000  return (flags_ & kIsSharedCrossOrigin) != 0;
1001  }
1002  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1003  int Flags() const { return flags_; }
1004 
1005  private:
1006  enum {
1007  kIsEmbedderDebugScript = 1,
1008  kIsSharedCrossOrigin = 1 << 1,
1009  kIsOpaque = 1 << 2
1010  };
1011  const int flags_;
1012 };
1013 
1018  public:
1019  V8_INLINE ScriptOrigin(
1020  Local<Value> resource_name,
1021  Local<Integer> resource_line_offset = Local<Integer>(),
1022  Local<Integer> resource_column_offset = Local<Integer>(),
1023  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1024  Local<Integer> script_id = Local<Integer>(),
1025  Local<Boolean> resource_is_embedder_debug_script = Local<Boolean>(),
1026  Local<Value> source_map_url = Local<Value>(),
1027  Local<Boolean> resource_is_opaque = Local<Boolean>());
1028  V8_INLINE Local<Value> ResourceName() const;
1029  V8_INLINE Local<Integer> ResourceLineOffset() const;
1030  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1034  V8_INLINE Local<Integer> ScriptID() const;
1035  V8_INLINE Local<Value> SourceMapUrl() const;
1036  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1037 
1038  private:
1039  Local<Value> resource_name_;
1040  Local<Integer> resource_line_offset_;
1041  Local<Integer> resource_column_offset_;
1042  ScriptOriginOptions options_;
1043  Local<Integer> script_id_;
1044  Local<Value> source_map_url_;
1045 };
1046 
1047 
1051 class V8_EXPORT UnboundScript {
1052  public:
1056  Local<Script> BindToCurrentContext();
1057 
1058  int GetId();
1059  Local<Value> GetScriptName();
1060 
1064  Local<Value> GetSourceURL();
1068  Local<Value> GetSourceMappingURL();
1069 
1074  int GetLineNumber(int code_pos);
1075 
1076  static const int kNoScriptId = 0;
1077 };
1078 
1079 
1084 class V8_EXPORT Script {
1085  public:
1089  static V8_DEPRECATE_SOON(
1090  "Use maybe version",
1091  Local<Script> Compile(Local<String> source,
1092  ScriptOrigin* origin = nullptr));
1093  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1094  Local<Context> context, Local<String> source,
1095  ScriptOrigin* origin = nullptr);
1096 
1097  static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
1098  Compile(Local<String> source,
1099  Local<String> file_name));
1100 
1106  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
1107  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1108 
1112  Local<UnboundScript> GetUnboundScript();
1113 
1114  V8_DEPRECATED("Use GetUnboundScript()->GetId()",
1115  int GetId()) {
1116  return GetUnboundScript()->GetId();
1117  }
1118 };
1119 
1120 
1124 class V8_EXPORT ScriptCompiler {
1125  public:
1133  struct V8_EXPORT CachedData {
1134  enum BufferPolicy {
1135  BufferNotOwned,
1136  BufferOwned
1137  };
1138 
1139  CachedData()
1140  : data(NULL),
1141  length(0),
1142  rejected(false),
1143  buffer_policy(BufferNotOwned) {}
1144 
1145  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1146  // data and guarantees that it stays alive until the CachedData object is
1147  // destroyed. If the policy is BufferOwned, the given data will be deleted
1148  // (with delete[]) when the CachedData object is destroyed.
1149  CachedData(const uint8_t* data, int length,
1150  BufferPolicy buffer_policy = BufferNotOwned);
1151  ~CachedData();
1152  // TODO(marja): Async compilation; add constructors which take a callback
1153  // which will be called when V8 no longer needs the data.
1154  const uint8_t* data;
1155  int length;
1156  bool rejected;
1157  BufferPolicy buffer_policy;
1158 
1159  private:
1160  // Prevent copying. Not implemented.
1161  CachedData(const CachedData&);
1162  CachedData& operator=(const CachedData&);
1163  };
1164 
1168  class Source {
1169  public:
1170  // Source takes ownership of CachedData.
1171  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1172  CachedData* cached_data = NULL);
1173  V8_INLINE Source(Local<String> source_string,
1174  CachedData* cached_data = NULL);
1175  V8_INLINE ~Source();
1176 
1177  // Ownership of the CachedData or its buffers is *not* transferred to the
1178  // caller. The CachedData object is alive as long as the Source object is
1179  // alive.
1180  V8_INLINE const CachedData* GetCachedData() const;
1181 
1182  private:
1183  friend class ScriptCompiler;
1184  // Prevent copying. Not implemented.
1185  Source(const Source&);
1186  Source& operator=(const Source&);
1187 
1188  Local<String> source_string;
1189 
1190  // Origin information
1191  Local<Value> resource_name;
1192  Local<Integer> resource_line_offset;
1193  Local<Integer> resource_column_offset;
1194  ScriptOriginOptions resource_options;
1195  Local<Value> source_map_url;
1196 
1197  // Cached data from previous compilation (if a kConsume*Cache flag is
1198  // set), or hold newly generated cache data (kProduce*Cache flags) are
1199  // set when calling a compile method.
1200  CachedData* cached_data;
1201  };
1202 
1207  class V8_EXPORT ExternalSourceStream {
1208  public:
1209  virtual ~ExternalSourceStream() {}
1210 
1228  virtual size_t GetMoreData(const uint8_t** src) = 0;
1229 
1240  virtual bool SetBookmark();
1241 
1245  virtual void ResetToBookmark();
1246  };
1247 
1248 
1255  class V8_EXPORT StreamedSource {
1256  public:
1257  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1258 
1259  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1260  ~StreamedSource();
1261 
1262  // Ownership of the CachedData or its buffers is *not* transferred to the
1263  // caller. The CachedData object is alive as long as the StreamedSource
1264  // object is alive.
1265  const CachedData* GetCachedData() const;
1266 
1267  internal::StreamedSource* impl() const { return impl_; }
1268 
1269  private:
1270  // Prevent copying. Not implemented.
1272  StreamedSource& operator=(const StreamedSource&);
1273 
1274  internal::StreamedSource* impl_;
1275  };
1276 
1282  public:
1283  virtual ~ScriptStreamingTask() {}
1284  virtual void Run() = 0;
1285  };
1286 
1287  enum CompileOptions {
1288  kNoCompileOptions = 0,
1289  kProduceParserCache,
1290  kConsumeParserCache,
1291  kProduceCodeCache,
1292  kConsumeCodeCache
1293  };
1294 
1308  static V8_DEPRECATE_SOON("Use maybe version",
1309  Local<UnboundScript> CompileUnbound(
1310  Isolate* isolate, Source* source,
1311  CompileOptions options = kNoCompileOptions));
1312  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1313  Isolate* isolate, Source* source,
1314  CompileOptions options = kNoCompileOptions);
1315 
1327  static V8_DEPRECATE_SOON(
1328  "Use maybe version",
1329  Local<Script> Compile(Isolate* isolate, Source* source,
1330  CompileOptions options = kNoCompileOptions));
1331  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1332  Local<Context> context, Source* source,
1333  CompileOptions options = kNoCompileOptions);
1334 
1346  static ScriptStreamingTask* StartStreamingScript(
1347  Isolate* isolate, StreamedSource* source,
1348  CompileOptions options = kNoCompileOptions);
1349 
1357  static V8_DEPRECATE_SOON(
1358  "Use maybe version",
1359  Local<Script> Compile(Isolate* isolate, StreamedSource* source,
1360  Local<String> full_source_string,
1361  const ScriptOrigin& origin));
1362  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1363  Local<Context> context, StreamedSource* source,
1364  Local<String> full_source_string, const ScriptOrigin& origin);
1365 
1384  static uint32_t CachedDataVersionTag();
1385 
1394  static V8_DEPRECATE_SOON(
1395  "Use maybe version",
1396  Local<Script> CompileModule(Isolate* isolate, Source* source,
1397  CompileOptions options = kNoCompileOptions));
1398  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> CompileModule(
1399  Local<Context> context, Source* source,
1400  CompileOptions options = kNoCompileOptions);
1401 
1412  static V8_DEPRECATE_SOON("Use maybe version",
1413  Local<Function> CompileFunctionInContext(
1414  Isolate* isolate, Source* source,
1415  Local<Context> context, size_t arguments_count,
1416  Local<String> arguments[],
1417  size_t context_extension_count,
1418  Local<Object> context_extensions[]));
1419  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1420  Local<Context> context, Source* source, size_t arguments_count,
1421  Local<String> arguments[], size_t context_extension_count,
1422  Local<Object> context_extensions[]);
1423 
1424  private:
1425  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1426  Isolate* isolate, Source* source, CompileOptions options, bool is_module);
1427 };
1428 
1429 
1433 class V8_EXPORT Message {
1434  public:
1435  Local<String> Get() const;
1436 
1437  V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
1438  V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
1439  Local<Context> context) const;
1440 
1445  ScriptOrigin GetScriptOrigin() const;
1446 
1451  Local<Value> GetScriptResourceName() const;
1452 
1458  Local<StackTrace> GetStackTrace() const;
1459 
1463  V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
1464  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1465 
1470  int GetStartPosition() const;
1471 
1476  int GetEndPosition() const;
1477 
1482  V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
1483  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1484 
1489  V8_DEPRECATE_SOON("Use maybe version", int GetEndColumn() const);
1490  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1491 
1496  bool IsSharedCrossOrigin() const;
1497  bool IsOpaque() const;
1498 
1499  // TODO(1245381): Print to a string instead of on a FILE.
1500  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1501 
1502  static const int kNoLineNumberInfo = 0;
1503  static const int kNoColumnInfo = 0;
1504  static const int kNoScriptIdInfo = 0;
1505 };
1506 
1507 
1513 class V8_EXPORT StackTrace {
1514  public:
1520  kLineNumber = 1,
1521  kColumnOffset = 1 << 1 | kLineNumber,
1522  kScriptName = 1 << 2,
1523  kFunctionName = 1 << 3,
1524  kIsEval = 1 << 4,
1525  kIsConstructor = 1 << 5,
1526  kScriptNameOrSourceURL = 1 << 6,
1527  kScriptId = 1 << 7,
1528  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1529  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1530  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1531  };
1532 
1536  Local<StackFrame> GetFrame(uint32_t index) const;
1537 
1541  int GetFrameCount() const;
1542 
1546  Local<Array> AsArray();
1547 
1555  static Local<StackTrace> CurrentStackTrace(
1556  Isolate* isolate,
1557  int frame_limit,
1558  StackTraceOptions options = kOverview);
1559 };
1560 
1561 
1565 class V8_EXPORT StackFrame {
1566  public:
1573  int GetLineNumber() const;
1574 
1582  int GetColumn() const;
1583 
1590  int GetScriptId() const;
1591 
1596  Local<String> GetScriptName() const;
1597 
1604  Local<String> GetScriptNameOrSourceURL() const;
1605 
1609  Local<String> GetFunctionName() const;
1610 
1615  bool IsEval() const;
1616 
1621  bool IsConstructor() const;
1622 };
1623 
1624 
1625 // A StateTag represents a possible state of the VM.
1626 enum StateTag { JS, GC, COMPILER, OTHER, EXTERNAL, IDLE };
1627 
1628 
1629 // A RegisterState represents the current state of registers used
1630 // by the sampling profiler API.
1632  RegisterState() : pc(NULL), sp(NULL), fp(NULL) {}
1633  void* pc; // Instruction pointer.
1634  void* sp; // Stack pointer.
1635  void* fp; // Frame pointer.
1636 };
1637 
1638 
1639 // The output structure filled up by GetStackSample API function.
1640 struct SampleInfo {
1641  size_t frames_count;
1642  StateTag vm_state;
1643 };
1644 
1645 
1649 class V8_EXPORT JSON {
1650  public:
1658  static V8_DEPRECATE_SOON("Use maybe version",
1659  Local<Value> Parse(Local<String> json_string));
1660  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1661  Isolate* isolate, Local<String> json_string);
1662 };
1663 
1664 
1670 class V8_EXPORT NativeWeakMap : public Data {
1671  public:
1672  static Local<NativeWeakMap> New(Isolate* isolate);
1673  void Set(Local<Value> key, Local<Value> value);
1674  Local<Value> Get(Local<Value> key);
1675  bool Has(Local<Value> key);
1676  bool Delete(Local<Value> key);
1677 };
1678 
1679 
1680 // --- Value ---
1681 
1682 
1686 class V8_EXPORT Value : public Data {
1687  public:
1692  V8_INLINE bool IsUndefined() const;
1693 
1698  V8_INLINE bool IsNull() const;
1699 
1703  bool IsTrue() const;
1704 
1708  bool IsFalse() const;
1709 
1714  bool IsName() const;
1715 
1720  V8_INLINE bool IsString() const;
1721 
1726  bool IsSymbol() const;
1727 
1731  bool IsFunction() const;
1732 
1736  bool IsArray() const;
1737 
1741  bool IsObject() const;
1742 
1746  bool IsBoolean() const;
1747 
1751  bool IsNumber() const;
1752 
1756  bool IsExternal() const;
1757 
1761  bool IsInt32() const;
1762 
1766  bool IsUint32() const;
1767 
1771  bool IsDate() const;
1772 
1776  bool IsArgumentsObject() const;
1777 
1781  bool IsBooleanObject() const;
1782 
1786  bool IsNumberObject() const;
1787 
1791  bool IsStringObject() const;
1792 
1797  bool IsSymbolObject() const;
1798 
1802  bool IsNativeError() const;
1803 
1807  bool IsRegExp() const;
1808 
1813  bool IsGeneratorFunction() const;
1814 
1819  bool IsGeneratorObject() const;
1820 
1825  bool IsPromise() const;
1826 
1830  bool IsMap() const;
1831 
1835  bool IsSet() const;
1836 
1840  bool IsMapIterator() const;
1841 
1845  bool IsSetIterator() const;
1846 
1850  bool IsWeakMap() const;
1851 
1855  bool IsWeakSet() const;
1856 
1861  bool IsArrayBuffer() const;
1862 
1867  bool IsArrayBufferView() const;
1868 
1873  bool IsTypedArray() const;
1874 
1879  bool IsUint8Array() const;
1880 
1885  bool IsUint8ClampedArray() const;
1886 
1891  bool IsInt8Array() const;
1892 
1897  bool IsUint16Array() const;
1898 
1903  bool IsInt16Array() const;
1904 
1909  bool IsUint32Array() const;
1910 
1915  bool IsInt32Array() const;
1916 
1921  bool IsFloat32Array() const;
1922 
1927  bool IsFloat64Array() const;
1928 
1933  bool IsFloat32x4() const;
1934 
1939  bool IsDataView() const;
1940 
1945  bool IsSharedArrayBuffer() const;
1946 
1947 
1948  V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
1949  Local<Context> context) const;
1950  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
1951  Local<Context> context) const;
1952  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
1953  Local<Context> context) const;
1954  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
1955  Local<Context> context) const;
1956  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
1957  Local<Context> context) const;
1958  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
1959  Local<Context> context) const;
1960  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
1961  Local<Context> context) const;
1962  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
1963 
1964  V8_DEPRECATE_SOON("Use maybe version",
1965  Local<Boolean> ToBoolean(Isolate* isolate) const);
1966  V8_DEPRECATE_SOON("Use maybe version",
1967  Local<Number> ToNumber(Isolate* isolate) const);
1968  V8_DEPRECATE_SOON("Use maybe version",
1969  Local<String> ToString(Isolate* isolate) const);
1970  V8_DEPRECATE_SOON("Use maybe version",
1971  Local<String> ToDetailString(Isolate* isolate) const);
1972  V8_DEPRECATE_SOON("Use maybe version",
1973  Local<Object> ToObject(Isolate* isolate) const);
1974  V8_DEPRECATE_SOON("Use maybe version",
1975  Local<Integer> ToInteger(Isolate* isolate) const);
1976  V8_DEPRECATE_SOON("Use maybe version",
1977  Local<Uint32> ToUint32(Isolate* isolate) const);
1978  V8_DEPRECATE_SOON("Use maybe version",
1979  Local<Int32> ToInt32(Isolate* isolate) const);
1980 
1981  inline V8_DEPRECATE_SOON("Use maybe version",
1982  Local<Boolean> ToBoolean() const);
1983  inline V8_DEPRECATE_SOON("Use maybe version", Local<Number> ToNumber() const);
1984  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
1985  inline V8_DEPRECATE_SOON("Use maybe version",
1986  Local<String> ToDetailString() const);
1987  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
1988  inline V8_DEPRECATE_SOON("Use maybe version",
1989  Local<Integer> ToInteger() const);
1990  inline V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToUint32() const);
1991  inline V8_DEPRECATE_SOON("Use maybe version", Local<Int32> ToInt32() const);
1992 
1997  V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToArrayIndex() const);
1998  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
1999  Local<Context> context) const;
2000 
2001  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2002  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2003  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2004  Local<Context> context) const;
2005  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2006  Local<Context> context) const;
2007  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2008 
2009  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2010  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2011  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2012  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2013  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2014 
2016  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2017  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2018  Local<Value> that) const;
2019  bool StrictEquals(Local<Value> that) const;
2020  bool SameValue(Local<Value> that) const;
2021 
2022  template <class T> V8_INLINE static Value* Cast(T* value);
2023 
2024  private:
2025  V8_INLINE bool QuickIsUndefined() const;
2026  V8_INLINE bool QuickIsNull() const;
2027  V8_INLINE bool QuickIsString() const;
2028  bool FullIsUndefined() const;
2029  bool FullIsNull() const;
2030  bool FullIsString() const;
2031 };
2032 
2033 
2037 class V8_EXPORT Primitive : public Value { };
2038 
2039 
2044 class V8_EXPORT Boolean : public Primitive {
2045  public:
2046  bool Value() const;
2047  V8_INLINE static Boolean* Cast(v8::Value* obj);
2048  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2049 
2050  private:
2051  static void CheckCast(v8::Value* obj);
2052 };
2053 
2054 
2058 class V8_EXPORT Name : public Primitive {
2059  public:
2067  int GetIdentityHash();
2068 
2069  V8_INLINE static Name* Cast(v8::Value* obj);
2070  private:
2071  static void CheckCast(v8::Value* obj);
2072 };
2073 
2074 
2075 enum class NewStringType { kNormal, kInternalized };
2076 
2077 
2081 class V8_EXPORT String : public Name {
2082  public:
2083  static const int kMaxLength = (1 << 28) - 16;
2084 
2085  enum Encoding {
2086  UNKNOWN_ENCODING = 0x1,
2087  TWO_BYTE_ENCODING = 0x0,
2088  ONE_BYTE_ENCODING = 0x4
2089  };
2093  int Length() const;
2094 
2099  int Utf8Length() const;
2100 
2106  bool IsOneByte() const;
2107 
2112  bool ContainsOnlyOneByte() const;
2113 
2140  NO_OPTIONS = 0,
2141  HINT_MANY_WRITES_EXPECTED = 1,
2142  NO_NULL_TERMINATION = 2,
2143  PRESERVE_ONE_BYTE_NULL = 4,
2144  // Used by WriteUtf8 to replace orphan surrogate code units with the
2145  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2146  // output.
2147  REPLACE_INVALID_UTF8 = 8
2148  };
2149 
2150  // 16-bit character codes.
2151  int Write(uint16_t* buffer,
2152  int start = 0,
2153  int length = -1,
2154  int options = NO_OPTIONS) const;
2155  // One byte characters.
2156  int WriteOneByte(uint8_t* buffer,
2157  int start = 0,
2158  int length = -1,
2159  int options = NO_OPTIONS) const;
2160  // UTF-8 encoded characters.
2161  int WriteUtf8(char* buffer,
2162  int length = -1,
2163  int* nchars_ref = NULL,
2164  int options = NO_OPTIONS) const;
2165 
2169  V8_INLINE static v8::Local<v8::String> Empty(Isolate* isolate);
2170 
2174  bool IsExternal() const;
2175 
2179  bool IsExternalOneByte() const;
2180 
2181  class V8_EXPORT ExternalStringResourceBase { // NOLINT
2182  public:
2183  virtual ~ExternalStringResourceBase() {}
2184 
2185  protected:
2187 
2194  virtual void Dispose() { delete this; }
2195 
2196  private:
2197  // Disallow copying and assigning.
2199  void operator=(const ExternalStringResourceBase&);
2200 
2201  friend class v8::internal::Heap;
2202  };
2203 
2210  class V8_EXPORT ExternalStringResource
2211  : public ExternalStringResourceBase {
2212  public:
2218 
2222  virtual const uint16_t* data() const = 0;
2223 
2227  virtual size_t length() const = 0;
2228 
2229  protected:
2231  };
2232 
2244  : public ExternalStringResourceBase {
2245  public:
2252  virtual const char* data() const = 0;
2254  virtual size_t length() const = 0;
2255  protected:
2257  };
2258 
2264  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2265  Encoding* encoding_out) const;
2266 
2271  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2272 
2277  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2278 
2279  V8_INLINE static String* Cast(v8::Value* obj);
2280 
2281  // TODO(dcarney): remove with deprecation of New functions.
2282  enum NewStringType {
2283  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2284  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2285  };
2286 
2288  static V8_DEPRECATE_SOON(
2289  "Use maybe version",
2290  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2291  NewStringType type = kNormalString,
2292  int length = -1));
2293 
2296  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2297  Isolate* isolate, const char* data, v8::NewStringType type,
2298  int length = -1);
2299 
2301  static V8_DEPRECATE_SOON(
2302  "Use maybe version",
2303  Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2304  NewStringType type = kNormalString,
2305  int length = -1));
2306 
2309  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2310  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2311  int length = -1);
2312 
2314  static V8_DEPRECATE_SOON(
2315  "Use maybe version",
2316  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2317  NewStringType type = kNormalString,
2318  int length = -1));
2319 
2322  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2323  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2324  int length = -1);
2325 
2330  static Local<String> Concat(Local<String> left, Local<String> right);
2331 
2340  static V8_DEPRECATE_SOON(
2341  "Use maybe version",
2342  Local<String> NewExternal(Isolate* isolate,
2343  ExternalStringResource* resource));
2344  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2345  Isolate* isolate, ExternalStringResource* resource);
2346 
2356  bool MakeExternal(ExternalStringResource* resource);
2357 
2366  static V8_DEPRECATE_SOON(
2367  "Use maybe version",
2368  Local<String> NewExternal(Isolate* isolate,
2369  ExternalOneByteStringResource* resource));
2370  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2371  Isolate* isolate, ExternalOneByteStringResource* resource);
2372 
2382  bool MakeExternal(ExternalOneByteStringResource* resource);
2383 
2387  bool CanMakeExternal();
2388 
2396  class V8_EXPORT Utf8Value {
2397  public:
2398  explicit Utf8Value(Local<v8::Value> obj);
2399  ~Utf8Value();
2400  char* operator*() { return str_; }
2401  const char* operator*() const { return str_; }
2402  int length() const { return length_; }
2403  private:
2404  char* str_;
2405  int length_;
2406 
2407  // Disallow copying and assigning.
2408  Utf8Value(const Utf8Value&);
2409  void operator=(const Utf8Value&);
2410  };
2411 
2418  class V8_EXPORT Value {
2419  public:
2420  explicit Value(Local<v8::Value> obj);
2421  ~Value();
2422  uint16_t* operator*() { return str_; }
2423  const uint16_t* operator*() const { return str_; }
2424  int length() const { return length_; }
2425  private:
2426  uint16_t* str_;
2427  int length_;
2428 
2429  // Disallow copying and assigning.
2430  Value(const Value&);
2431  void operator=(const Value&);
2432  };
2433 
2434  private:
2435  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2436  Encoding encoding) const;
2437  void VerifyExternalStringResource(ExternalStringResource* val) const;
2438  static void CheckCast(v8::Value* obj);
2439 };
2440 
2441 
2447 class V8_EXPORT Symbol : public Name {
2448  public:
2449  // Returns the print name string of the symbol, or undefined if none.
2450  Local<Value> Name() const;
2451 
2452  // Create a symbol. If name is not empty, it will be used as the description.
2453  static Local<Symbol> New(
2454  Isolate *isolate, Local<String> name = Local<String>());
2455 
2456  // Access global symbol registry.
2457  // Note that symbols created this way are never collected, so
2458  // they should only be used for statically fixed properties.
2459  // Also, there is only one global name space for the names used as keys.
2460  // To minimize the potential for clashes, use qualified names as keys.
2461  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2462 
2463  // Retrieve a global symbol. Similar to |For|, but using a separate
2464  // registry that is not accessible by (and cannot clash with) JavaScript code.
2465  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2466 
2467  // Well-known symbols
2468  static Local<Symbol> GetIterator(Isolate* isolate);
2469  static Local<Symbol> GetUnscopables(Isolate* isolate);
2470  static Local<Symbol> GetToStringTag(Isolate* isolate);
2471 
2472  V8_INLINE static Symbol* Cast(v8::Value* obj);
2473 
2474  private:
2475  Symbol();
2476  static void CheckCast(v8::Value* obj);
2477 };
2478 
2479 
2483 class V8_EXPORT Number : public Primitive {
2484  public:
2485  double Value() const;
2486  static Local<Number> New(Isolate* isolate, double value);
2487  V8_INLINE static Number* Cast(v8::Value* obj);
2488  private:
2489  Number();
2490  static void CheckCast(v8::Value* obj);
2491 };
2492 
2493 
2497 class V8_EXPORT Integer : public Number {
2498  public:
2499  static Local<Integer> New(Isolate* isolate, int32_t value);
2500  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2501  int64_t Value() const;
2502  V8_INLINE static Integer* Cast(v8::Value* obj);
2503  private:
2504  Integer();
2505  static void CheckCast(v8::Value* obj);
2506 };
2507 
2508 
2512 class V8_EXPORT Int32 : public Integer {
2513  public:
2514  int32_t Value() const;
2515  V8_INLINE static Int32* Cast(v8::Value* obj);
2516 
2517  private:
2518  Int32();
2519  static void CheckCast(v8::Value* obj);
2520 };
2521 
2522 
2526 class V8_EXPORT Uint32 : public Integer {
2527  public:
2528  uint32_t Value() const;
2529  V8_INLINE static Uint32* Cast(v8::Value* obj);
2530 
2531  private:
2532  Uint32();
2533  static void CheckCast(v8::Value* obj);
2534 };
2535 
2536 
2537 enum PropertyAttribute {
2538  None = 0,
2539  ReadOnly = 1 << 0,
2540  DontEnum = 1 << 1,
2541  DontDelete = 1 << 2
2542 };
2543 
2549 typedef void (*AccessorGetterCallback)(
2550  Local<String> property,
2551  const PropertyCallbackInfo<Value>& info);
2552 typedef void (*AccessorNameGetterCallback)(
2553  Local<Name> property,
2554  const PropertyCallbackInfo<Value>& info);
2555 
2556 
2557 typedef void (*AccessorSetterCallback)(
2558  Local<String> property,
2559  Local<Value> value,
2560  const PropertyCallbackInfo<void>& info);
2561 typedef void (*AccessorNameSetterCallback)(
2562  Local<Name> property,
2563  Local<Value> value,
2564  const PropertyCallbackInfo<void>& info);
2565 
2566 
2577  DEFAULT = 0,
2578  ALL_CAN_READ = 1,
2579  ALL_CAN_WRITE = 1 << 1,
2580  PROHIBITS_OVERWRITING = 1 << 2
2581 };
2582 
2583 
2587 class V8_EXPORT Object : public Value {
2588  public:
2589  V8_DEPRECATE_SOON("Use maybe version",
2590  bool Set(Local<Value> key, Local<Value> value));
2591  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
2592  Local<Value> key, Local<Value> value);
2593 
2594  V8_DEPRECATE_SOON("Use maybe version",
2595  bool Set(uint32_t index, Local<Value> value));
2596  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
2597  Local<Value> value);
2598 
2599  // Implements CreateDataProperty (ECMA-262, 7.3.4).
2600  //
2601  // Defines a configurable, writable, enumerable property with the given value
2602  // on the object unless the property already exists and is not configurable
2603  // or the object is not extensible.
2604  //
2605  // Returns true on success.
2606  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2607  Local<Name> key,
2608  Local<Value> value);
2609  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2610  uint32_t index,
2611  Local<Value> value);
2612 
2613  // Implements DefineOwnProperty.
2614  //
2615  // In general, CreateDataProperty will be faster, however, does not allow
2616  // for specifying attributes.
2617  //
2618  // Returns true on success.
2619  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
2620  Local<Context> context, Local<Name> key, Local<Value> value,
2621  PropertyAttribute attributes = None);
2622 
2623  // Sets an own property on this object bypassing interceptors and
2624  // overriding accessors or read-only properties.
2625  //
2626  // Note that if the object has an interceptor the property will be set
2627  // locally, but since the interceptor takes precedence the local property
2628  // will only be returned if the interceptor doesn't return a value.
2629  //
2630  // Note also that this only works for named properties.
2631  V8_DEPRECATE_SOON("Use CreateDataProperty",
2632  bool ForceSet(Local<Value> key, Local<Value> value,
2633  PropertyAttribute attribs = None));
2634  V8_DEPRECATE_SOON("Use CreateDataProperty",
2635  Maybe<bool> ForceSet(Local<Context> context,
2636  Local<Value> key, Local<Value> value,
2637  PropertyAttribute attribs = None));
2638 
2639  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
2640  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2641  Local<Value> key);
2642 
2643  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
2644  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2645  uint32_t index);
2646 
2652  V8_DEPRECATE_SOON("Use maybe version",
2653  PropertyAttribute GetPropertyAttributes(Local<Value> key));
2654  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
2655  Local<Context> context, Local<Value> key);
2656 
2660  V8_DEPRECATE_SOON("Use maybe version",
2661  Local<Value> GetOwnPropertyDescriptor(Local<String> key));
2662  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
2663  Local<Context> context, Local<String> key);
2664 
2665  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
2666  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
2667  Local<Value> key);
2668 
2669  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
2670  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2671  Maybe<bool> Delete(Local<Context> context, Local<Value> key);
2672 
2673  V8_DEPRECATE_SOON("Use maybe version", bool Has(uint32_t index));
2674  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
2675 
2676  V8_DEPRECATE_SOON("Use maybe version", bool Delete(uint32_t index));
2677  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2678  Maybe<bool> Delete(Local<Context> context, uint32_t index);
2679 
2680  V8_DEPRECATE_SOON("Use maybe version",
2681  bool SetAccessor(Local<String> name,
2682  AccessorGetterCallback getter,
2683  AccessorSetterCallback setter = 0,
2684  Local<Value> data = Local<Value>(),
2685  AccessControl settings = DEFAULT,
2686  PropertyAttribute attribute = None));
2687  V8_DEPRECATE_SOON("Use maybe version",
2688  bool SetAccessor(Local<Name> name,
2689  AccessorNameGetterCallback getter,
2690  AccessorNameSetterCallback setter = 0,
2691  Local<Value> data = Local<Value>(),
2692  AccessControl settings = DEFAULT,
2693  PropertyAttribute attribute = None));
2694  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2695  Maybe<bool> SetAccessor(Local<Context> context, Local<Name> name,
2696  AccessorNameGetterCallback getter,
2697  AccessorNameSetterCallback setter = 0,
2699  AccessControl settings = DEFAULT,
2700  PropertyAttribute attribute = None);
2701 
2702  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
2703  Local<Function> setter = Local<Function>(),
2704  PropertyAttribute attribute = None,
2705  AccessControl settings = DEFAULT);
2706 
2713  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
2714  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
2715  Local<Context> context);
2716 
2722  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
2723  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
2724  Local<Context> context);
2725 
2731  Local<Value> GetPrototype();
2732 
2738  V8_DEPRECATE_SOON("Use maybe version",
2739  bool SetPrototype(Local<Value> prototype));
2740  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
2741  Local<Value> prototype);
2742 
2747  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
2748 
2754  V8_DEPRECATE_SOON("Use maybe version", Local<String> ObjectProtoToString());
2755  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
2756  Local<Context> context);
2757 
2761  Local<String> GetConstructorName();
2762 
2764  int InternalFieldCount();
2765 
2767  V8_INLINE static int InternalFieldCount(
2768  const PersistentBase<Object>& object) {
2769  return object.val_->InternalFieldCount();
2770  }
2771 
2773  V8_INLINE Local<Value> GetInternalField(int index);
2774 
2776  void SetInternalField(int index, Local<Value> value);
2777 
2783  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
2784 
2786  V8_INLINE static void* GetAlignedPointerFromInternalField(
2787  const PersistentBase<Object>& object, int index) {
2788  return object.val_->GetAlignedPointerFromInternalField(index);
2789  }
2790 
2796  void SetAlignedPointerInInternalField(int index, void* value);
2797 
2798  // Testers for local properties.
2799  V8_DEPRECATE_SOON("Use maybe version",
2800  bool HasOwnProperty(Local<String> key));
2801  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
2802  Local<Name> key);
2803  V8_DEPRECATE_SOON("Use maybe version",
2804  bool HasRealNamedProperty(Local<String> key));
2805  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
2806  Local<Name> key);
2807  V8_DEPRECATE_SOON("Use maybe version",
2808  bool HasRealIndexedProperty(uint32_t index));
2809  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
2810  Local<Context> context, uint32_t index);
2811  V8_DEPRECATE_SOON("Use maybe version",
2812  bool HasRealNamedCallbackProperty(Local<String> key));
2813  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
2814  Local<Context> context, Local<Name> key);
2815 
2820  V8_DEPRECATE_SOON(
2821  "Use maybe version",
2822  Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
2823  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
2824  Local<Context> context, Local<Name> key);
2825 
2831  V8_DEPRECATE_SOON(
2832  "Use maybe version",
2833  Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
2834  Local<String> key));
2835  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
2836  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
2837  Local<Name> key);
2838 
2844  V8_DEPRECATE_SOON("Use maybe version",
2845  Local<Value> GetRealNamedProperty(Local<String> key));
2846  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
2847  Local<Context> context, Local<Name> key);
2848 
2854  V8_DEPRECATE_SOON("Use maybe version",
2855  Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
2856  Local<String> key));
2857  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
2858  Local<Context> context, Local<Name> key);
2859 
2861  bool HasNamedLookupInterceptor();
2862 
2864  bool HasIndexedLookupInterceptor();
2865 
2873  int GetIdentityHash();
2874 
2881  // TODO(dcarney): convert these to take a isolate and optionally bailout?
2882  bool SetHiddenValue(Local<String> key, Local<Value> value);
2883  Local<Value> GetHiddenValue(Local<String> key);
2884  bool DeleteHiddenValue(Local<String> key);
2885 
2890  // TODO(dcarney): take an isolate and optionally bail out?
2891  Local<Object> Clone();
2892 
2896  Local<Context> CreationContext();
2897 
2903  bool IsCallable();
2904 
2909  V8_DEPRECATE_SOON("Use maybe version",
2910  Local<Value> CallAsFunction(Local<Value> recv, int argc,
2911  Local<Value> argv[]));
2912  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
2913  Local<Value> recv,
2914  int argc,
2915  Local<Value> argv[]);
2916 
2922  V8_DEPRECATE_SOON("Use maybe version",
2923  Local<Value> CallAsConstructor(int argc,
2924  Local<Value> argv[]));
2925  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
2926  Local<Context> context, int argc, Local<Value> argv[]);
2927 
2931  V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
2932 
2933  static Local<Object> New(Isolate* isolate);
2934 
2935  V8_INLINE static Object* Cast(Value* obj);
2936 
2937  private:
2938  Object();
2939  static void CheckCast(Value* obj);
2940  Local<Value> SlowGetInternalField(int index);
2941  void* SlowGetAlignedPointerFromInternalField(int index);
2942 };
2943 
2944 
2948 class V8_EXPORT Array : public Object {
2949  public:
2950  uint32_t Length() const;
2951 
2956  V8_DEPRECATE_SOON("Use maybe version",
2957  Local<Object> CloneElementAt(uint32_t index));
2958  V8_WARN_UNUSED_RESULT MaybeLocal<Object> CloneElementAt(
2959  Local<Context> context, uint32_t index);
2960 
2965  static Local<Array> New(Isolate* isolate, int length = 0);
2966 
2967  V8_INLINE static Array* Cast(Value* obj);
2968  private:
2969  Array();
2970  static void CheckCast(Value* obj);
2971 };
2972 
2973 
2977 class V8_EXPORT Map : public Object {
2978  public:
2979  size_t Size() const;
2980  void Clear();
2981  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2982  Local<Value> key);
2983  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
2984  Local<Value> key,
2985  Local<Value> value);
2986  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
2987  Local<Value> key);
2988  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
2989  Local<Value> key);
2990 
2995  Local<Array> AsArray() const;
2996 
3000  static Local<Map> New(Isolate* isolate);
3001 
3007  static V8_WARN_UNUSED_RESULT MaybeLocal<Map> FromArray(Local<Context> context,
3008  Local<Array> array);
3009 
3010  V8_INLINE static Map* Cast(Value* obj);
3011 
3012  private:
3013  Map();
3014  static void CheckCast(Value* obj);
3015 };
3016 
3017 
3021 class V8_EXPORT Set : public Object {
3022  public:
3023  size_t Size() const;
3024  void Clear();
3025  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3026  Local<Value> key);
3027  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3028  Local<Value> key);
3029  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3030  Local<Value> key);
3031 
3035  Local<Array> AsArray() const;
3036 
3040  static Local<Set> New(Isolate* isolate);
3041 
3046  static V8_WARN_UNUSED_RESULT MaybeLocal<Set> FromArray(Local<Context> context,
3047  Local<Array> array);
3048 
3049  V8_INLINE static Set* Cast(Value* obj);
3050 
3051  private:
3052  Set();
3053  static void CheckCast(Value* obj);
3054 };
3055 
3056 
3057 template<typename T>
3058 class ReturnValue {
3059  public:
3060  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3061  : value_(that.value_) {
3062  TYPE_CHECK(T, S);
3063  }
3064  // Local setters
3065  template <typename S>
3066  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3067  void Set(const Persistent<S>& handle));
3068  template <typename S>
3069  V8_INLINE void Set(const Global<S>& handle);
3070  template <typename S>
3071  V8_INLINE void Set(const Local<S> handle);
3072  // Fast primitive setters
3073  V8_INLINE void Set(bool value);
3074  V8_INLINE void Set(double i);
3075  V8_INLINE void Set(int32_t i);
3076  V8_INLINE void Set(uint32_t i);
3077  // Fast JS primitive setters
3078  V8_INLINE void SetNull();
3079  V8_INLINE void SetUndefined();
3080  V8_INLINE void SetEmptyString();
3081  // Convenience getter for Isolate
3082  V8_INLINE Isolate* GetIsolate();
3083 
3084  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3085  template <typename S>
3086  V8_INLINE void Set(S* whatever);
3087 
3088  private:
3089  template<class F> friend class ReturnValue;
3090  template<class F> friend class FunctionCallbackInfo;
3091  template<class F> friend class PropertyCallbackInfo;
3092  template <class F, class G, class H>
3093  friend class PersistentValueMapBase;
3094  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3095  V8_INLINE internal::Object* GetDefaultValue();
3096  V8_INLINE explicit ReturnValue(internal::Object** slot);
3097  internal::Object** value_;
3098 };
3099 
3100 
3107 template<typename T>
3108 class FunctionCallbackInfo {
3109  public:
3110  V8_INLINE int Length() const;
3111  V8_INLINE Local<Value> operator[](int i) const;
3112  V8_INLINE Local<Function> Callee() const;
3113  V8_INLINE Local<Object> This() const;
3114  V8_INLINE Local<Object> Holder() const;
3115  V8_INLINE bool IsConstructCall() const;
3116  V8_INLINE Local<Value> Data() const;
3117  V8_INLINE Isolate* GetIsolate() const;
3118  V8_INLINE ReturnValue<T> GetReturnValue() const;
3119  // This shouldn't be public, but the arm compiler needs it.
3120  static const int kArgsLength = 7;
3121 
3122  protected:
3123  friend class internal::FunctionCallbackArguments;
3124  friend class internal::CustomArguments<FunctionCallbackInfo>;
3125  static const int kHolderIndex = 0;
3126  static const int kIsolateIndex = 1;
3127  static const int kReturnValueDefaultValueIndex = 2;
3128  static const int kReturnValueIndex = 3;
3129  static const int kDataIndex = 4;
3130  static const int kCalleeIndex = 5;
3131  static const int kContextSaveIndex = 6;
3132 
3133  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3134  internal::Object** values,
3135  int length,
3136  bool is_construct_call);
3137  internal::Object** implicit_args_;
3138  internal::Object** values_;
3139  int length_;
3140  int is_construct_call_;
3141 };
3142 
3143 
3148 template<typename T>
3149 class PropertyCallbackInfo {
3150  public:
3151  V8_INLINE Isolate* GetIsolate() const;
3152  V8_INLINE Local<Value> Data() const;
3153  V8_INLINE Local<Object> This() const;
3154  V8_INLINE Local<Object> Holder() const;
3155  V8_INLINE ReturnValue<T> GetReturnValue() const;
3156  // This shouldn't be public, but the arm compiler needs it.
3157  static const int kArgsLength = 6;
3158 
3159  protected:
3160  friend class MacroAssembler;
3161  friend class internal::PropertyCallbackArguments;
3162  friend class internal::CustomArguments<PropertyCallbackInfo>;
3163  static const int kHolderIndex = 0;
3164  static const int kIsolateIndex = 1;
3165  static const int kReturnValueDefaultValueIndex = 2;
3166  static const int kReturnValueIndex = 3;
3167  static const int kDataIndex = 4;
3168  static const int kThisIndex = 5;
3169 
3170  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
3171  internal::Object** args_;
3172 };
3173 
3174 
3175 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3176 
3177 
3181 class V8_EXPORT Function : public Object {
3182  public:
3187  static MaybeLocal<Function> New(Local<Context> context,
3188  FunctionCallback callback,
3189  Local<Value> data = Local<Value>(),
3190  int length = 0);
3191  static V8_DEPRECATE_SOON(
3192  "Use maybe version",
3193  Local<Function> New(Isolate* isolate, FunctionCallback callback,
3194  Local<Value> data = Local<Value>(), int length = 0));
3195 
3196  V8_DEPRECATE_SOON("Use maybe version",
3197  Local<Object> NewInstance(int argc, Local<Value> argv[])
3198  const);
3199  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
3200  Local<Context> context, int argc, Local<Value> argv[]) const;
3201 
3202  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance() const);
3203  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
3204  Local<Context> context) const {
3205  return NewInstance(context, 0, nullptr);
3206  }
3207 
3208  V8_DEPRECATE_SOON("Use maybe version",
3209  Local<Value> Call(Local<Value> recv, int argc,
3210  Local<Value> argv[]));
3211  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
3212  Local<Value> recv, int argc,
3213  Local<Value> argv[]);
3214 
3215  void SetName(Local<String> name);
3216  Local<Value> GetName() const;
3217 
3224  Local<Value> GetInferredName() const;
3225 
3230  Local<Value> GetDisplayName() const;
3231 
3236  int GetScriptLineNumber() const;
3241  int GetScriptColumnNumber() const;
3242 
3246  bool IsBuiltin() const;
3247 
3251  int ScriptId() const;
3252 
3257  Local<Value> GetBoundFunction() const;
3258 
3259  ScriptOrigin GetScriptOrigin() const;
3260  V8_INLINE static Function* Cast(Value* obj);
3261  static const int kLineOffsetNotFound;
3262 
3263  private:
3264  Function();
3265  static void CheckCast(Value* obj);
3266 };
3267 
3268 
3273 class V8_EXPORT Promise : public Object {
3274  public:
3275  class V8_EXPORT Resolver : public Object {
3276  public:
3280  static V8_DEPRECATE_SOON("Use maybe version",
3281  Local<Resolver> New(Isolate* isolate));
3282  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
3283  Local<Context> context);
3284 
3288  Local<Promise> GetPromise();
3289 
3294  V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
3295  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3296  Maybe<bool> Resolve(Local<Context> context, Local<Value> value);
3297 
3298  V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
3299  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3300  Maybe<bool> Reject(Local<Context> context, Local<Value> value);
3301 
3302  V8_INLINE static Resolver* Cast(Value* obj);
3303 
3304  private:
3305  Resolver();
3306  static void CheckCast(Value* obj);
3307  };
3308 
3315  V8_DEPRECATE_SOON("Use maybe version",
3316  Local<Promise> Chain(Local<Function> handler));
3317  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Chain(Local<Context> context,
3318  Local<Function> handler);
3319 
3320  V8_DEPRECATE_SOON("Use maybe version",
3321  Local<Promise> Catch(Local<Function> handler));
3322  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
3323  Local<Function> handler);
3324 
3325  V8_DEPRECATE_SOON("Use maybe version",
3326  Local<Promise> Then(Local<Function> handler));
3327  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
3328  Local<Function> handler);
3329 
3334  bool HasHandler();
3335 
3336  V8_INLINE static Promise* Cast(Value* obj);
3337 
3338  private:
3339  Promise();
3340  static void CheckCast(Value* obj);
3341 };
3342 
3343 
3344 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
3345 // The number of required internal fields can be defined by embedder.
3346 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
3347 #endif
3348 
3349 
3350 enum class ArrayBufferCreationMode { kInternalized, kExternalized };
3351 
3352 
3357 class V8_EXPORT ArrayBuffer : public Object {
3358  public:
3366  class V8_EXPORT Allocator { // NOLINT
3367  public:
3368  virtual ~Allocator() {}
3369 
3374  virtual void* Allocate(size_t length) = 0;
3375 
3380  virtual void* AllocateUninitialized(size_t length) = 0;
3385  virtual void Free(void* data, size_t length) = 0;
3386  };
3387 
3398  class V8_EXPORT Contents { // NOLINT
3399  public:
3400  Contents() : data_(NULL), byte_length_(0) {}
3401 
3402  void* Data() const { return data_; }
3403  size_t ByteLength() const { return byte_length_; }
3404 
3405  private:
3406  void* data_;
3407  size_t byte_length_;
3408 
3409  friend class ArrayBuffer;
3410  };
3411 
3412 
3416  size_t ByteLength() const;
3417 
3424  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
3425 
3432  static Local<ArrayBuffer> New(
3433  Isolate* isolate, void* data, size_t byte_length,
3434  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
3435 
3440  bool IsExternal() const;
3441 
3445  bool IsNeuterable() const;
3446 
3453  void Neuter();
3454 
3464  Contents Externalize();
3465 
3476  Contents GetContents();
3477 
3478  V8_INLINE static ArrayBuffer* Cast(Value* obj);
3479 
3480  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
3481 
3482  private:
3483  ArrayBuffer();
3484  static void CheckCast(Value* obj);
3485 };
3486 
3487 
3488 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
3489 // The number of required internal fields can be defined by embedder.
3490 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
3491 #endif
3492 
3493 
3500 class V8_EXPORT ArrayBufferView : public Object {
3501  public:
3505  Local<ArrayBuffer> Buffer();
3509  size_t ByteOffset();
3513  size_t ByteLength();
3514 
3524  size_t CopyContents(void* dest, size_t byte_length);
3525 
3530  bool HasBuffer() const;
3531 
3532  V8_INLINE static ArrayBufferView* Cast(Value* obj);
3533 
3534  static const int kInternalFieldCount =
3535  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
3536 
3537  private:
3538  ArrayBufferView();
3539  static void CheckCast(Value* obj);
3540 };
3541 
3542 
3548 class V8_EXPORT TypedArray : public ArrayBufferView {
3549  public:
3554  size_t Length();
3555 
3556  V8_INLINE static TypedArray* Cast(Value* obj);
3557 
3558  private:
3559  TypedArray();
3560  static void CheckCast(Value* obj);
3561 };
3562 
3563 
3568 class V8_EXPORT Uint8Array : public TypedArray {
3569  public:
3570  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
3571  size_t byte_offset, size_t length);
3572  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3573  size_t byte_offset, size_t length);
3574  V8_INLINE static Uint8Array* Cast(Value* obj);
3575 
3576  private:
3577  Uint8Array();
3578  static void CheckCast(Value* obj);
3579 };
3580 
3581 
3586 class V8_EXPORT Uint8ClampedArray : public TypedArray {
3587  public:
3588  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
3589  size_t byte_offset, size_t length);
3590  static Local<Uint8ClampedArray> New(
3591  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
3592  size_t length);
3593  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
3594 
3595  private:
3597  static void CheckCast(Value* obj);
3598 };
3599 
3604 class V8_EXPORT Int8Array : public TypedArray {
3605  public:
3606  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
3607  size_t byte_offset, size_t length);
3608  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3609  size_t byte_offset, size_t length);
3610  V8_INLINE static Int8Array* Cast(Value* obj);
3611 
3612  private:
3613  Int8Array();
3614  static void CheckCast(Value* obj);
3615 };
3616 
3617 
3622 class V8_EXPORT Uint16Array : public TypedArray {
3623  public:
3624  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
3625  size_t byte_offset, size_t length);
3626  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3627  size_t byte_offset, size_t length);
3628  V8_INLINE static Uint16Array* Cast(Value* obj);
3629 
3630  private:
3631  Uint16Array();
3632  static void CheckCast(Value* obj);
3633 };
3634 
3635 
3640 class V8_EXPORT Int16Array : public TypedArray {
3641  public:
3642  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
3643  size_t byte_offset, size_t length);
3644  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3645  size_t byte_offset, size_t length);
3646  V8_INLINE static Int16Array* Cast(Value* obj);
3647 
3648  private:
3649  Int16Array();
3650  static void CheckCast(Value* obj);
3651 };
3652 
3653 
3658 class V8_EXPORT Uint32Array : public TypedArray {
3659  public:
3660  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
3661  size_t byte_offset, size_t length);
3662  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3663  size_t byte_offset, size_t length);
3664  V8_INLINE static Uint32Array* Cast(Value* obj);
3665 
3666  private:
3667  Uint32Array();
3668  static void CheckCast(Value* obj);
3669 };
3670 
3671 
3676 class V8_EXPORT Int32Array : public TypedArray {
3677  public:
3678  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
3679  size_t byte_offset, size_t length);
3680  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3681  size_t byte_offset, size_t length);
3682  V8_INLINE static Int32Array* Cast(Value* obj);
3683 
3684  private:
3685  Int32Array();
3686  static void CheckCast(Value* obj);
3687 };
3688 
3689 
3694 class V8_EXPORT Float32Array : public TypedArray {
3695  public:
3696  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
3697  size_t byte_offset, size_t length);
3698  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3699  size_t byte_offset, size_t length);
3700  V8_INLINE static Float32Array* Cast(Value* obj);
3701 
3702  private:
3703  Float32Array();
3704  static void CheckCast(Value* obj);
3705 };
3706 
3707 
3712 class V8_EXPORT Float64Array : public TypedArray {
3713  public:
3714  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
3715  size_t byte_offset, size_t length);
3716  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3717  size_t byte_offset, size_t length);
3718  V8_INLINE static Float64Array* Cast(Value* obj);
3719 
3720  private:
3721  Float64Array();
3722  static void CheckCast(Value* obj);
3723 };
3724 
3725 
3730 class V8_EXPORT DataView : public ArrayBufferView {
3731  public:
3732  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
3733  size_t byte_offset, size_t length);
3734  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
3735  size_t byte_offset, size_t length);
3736  V8_INLINE static DataView* Cast(Value* obj);
3737 
3738  private:
3739  DataView();
3740  static void CheckCast(Value* obj);
3741 };
3742 
3743 
3748 class V8_EXPORT SharedArrayBuffer : public Object {
3749  public:
3761  class V8_EXPORT Contents { // NOLINT
3762  public:
3763  Contents() : data_(NULL), byte_length_(0) {}
3764 
3765  void* Data() const { return data_; }
3766  size_t ByteLength() const { return byte_length_; }
3767 
3768  private:
3769  void* data_;
3770  size_t byte_length_;
3771 
3772  friend class SharedArrayBuffer;
3773  };
3774 
3775 
3779  size_t ByteLength() const;
3780 
3787  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
3788 
3795  static Local<SharedArrayBuffer> New(
3796  Isolate* isolate, void* data, size_t byte_length,
3797  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
3798 
3803  bool IsExternal() const;
3804 
3817  Contents Externalize();
3818 
3831  Contents GetContents();
3832 
3833  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
3834 
3835  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
3836 
3837  private:
3839  static void CheckCast(Value* obj);
3840 };
3841 
3842 
3846 class V8_EXPORT Date : public Object {
3847  public:
3848  static V8_DEPRECATE_SOON("Use maybe version.",
3849  Local<Value> New(Isolate* isolate, double time));
3850  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
3851  double time);
3852 
3857  double ValueOf() const;
3858 
3859  V8_INLINE static Date* Cast(v8::Value* obj);
3860 
3873  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
3874 
3875  private:
3876  static void CheckCast(v8::Value* obj);
3877 };
3878 
3879 
3883 class V8_EXPORT NumberObject : public Object {
3884  public:
3885  static Local<Value> New(Isolate* isolate, double value);
3886 
3887  double ValueOf() const;
3888 
3889  V8_INLINE static NumberObject* Cast(v8::Value* obj);
3890 
3891  private:
3892  static void CheckCast(v8::Value* obj);
3893 };
3894 
3895 
3899 class V8_EXPORT BooleanObject : public Object {
3900  public:
3901  static Local<Value> New(bool value);
3902 
3903  bool ValueOf() const;
3904 
3905  V8_INLINE static BooleanObject* Cast(v8::Value* obj);
3906 
3907  private:
3908  static void CheckCast(v8::Value* obj);
3909 };
3910 
3911 
3915 class V8_EXPORT StringObject : public Object {
3916  public:
3917  static Local<Value> New(Local<String> value);
3918 
3919  Local<String> ValueOf() const;
3920 
3921  V8_INLINE static StringObject* Cast(v8::Value* obj);
3922 
3923  private:
3924  static void CheckCast(v8::Value* obj);
3925 };
3926 
3927 
3933 class V8_EXPORT SymbolObject : public Object {
3934  public:
3935  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
3936 
3937  Local<Symbol> ValueOf() const;
3938 
3939  V8_INLINE static SymbolObject* Cast(v8::Value* obj);
3940 
3941  private:
3942  static void CheckCast(v8::Value* obj);
3943 };
3944 
3945 
3949 class V8_EXPORT RegExp : public Object {
3950  public:
3955  enum Flags {
3956  kNone = 0,
3957  kGlobal = 1,
3958  kIgnoreCase = 2,
3959  kMultiline = 4
3960  };
3961 
3972  static V8_DEPRECATE_SOON("Use maybe version",
3973  Local<RegExp> New(Local<String> pattern,
3974  Flags flags));
3975  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
3976  Local<String> pattern,
3977  Flags flags);
3978 
3983  Local<String> GetSource() const;
3984 
3988  Flags GetFlags() const;
3989 
3990  V8_INLINE static RegExp* Cast(v8::Value* obj);
3991 
3992  private:
3993  static void CheckCast(v8::Value* obj);
3994 };
3995 
3996 
4001 class V8_EXPORT External : public Value {
4002  public:
4003  static Local<External> New(Isolate* isolate, void* value);
4004  V8_INLINE static External* Cast(Value* obj);
4005  void* Value() const;
4006  private:
4007  static void CheckCast(v8::Value* obj);
4008 };
4009 
4010 
4011 // --- Templates ---
4012 
4013 
4017 class V8_EXPORT Template : public Data {
4018  public:
4020  void Set(Local<Name> name, Local<Data> value,
4021  PropertyAttribute attributes = None);
4022  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
4023 
4024  void SetAccessorProperty(
4025  Local<Name> name,
4028  PropertyAttribute attribute = None,
4029  AccessControl settings = DEFAULT);
4030 
4058  void SetNativeDataProperty(
4060  AccessorSetterCallback setter = 0,
4061  // TODO(dcarney): gcc can't handle Local below
4062  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4064  AccessControl settings = DEFAULT);
4065  void SetNativeDataProperty(
4066  Local<Name> name, AccessorNameGetterCallback getter,
4067  AccessorNameSetterCallback setter = 0,
4068  // TODO(dcarney): gcc can't handle Local below
4069  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4071  AccessControl settings = DEFAULT);
4072 
4073  private:
4074  Template();
4075 
4076  friend class ObjectTemplate;
4077  friend class FunctionTemplate;
4078 };
4079 
4080 
4086  Local<String> property,
4087  const PropertyCallbackInfo<Value>& info);
4088 
4089 
4095  Local<String> property,
4096  Local<Value> value,
4097  const PropertyCallbackInfo<Value>& info);
4098 
4099 
4106  Local<String> property,
4107  const PropertyCallbackInfo<Integer>& info);
4108 
4109 
4116  Local<String> property,
4117  const PropertyCallbackInfo<Boolean>& info);
4118 
4119 
4125  const PropertyCallbackInfo<Array>& info);
4126 
4127 
4128 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
4129 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
4135  Local<Name> property, const PropertyCallbackInfo<Value>& info);
4136 
4137 
4143  Local<Name> property, Local<Value> value,
4144  const PropertyCallbackInfo<Value>& info);
4145 
4146 
4153  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
4154 
4155 
4162  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
4163 
4164 
4170  const PropertyCallbackInfo<Array>& info);
4171 
4172 
4178  uint32_t index,
4179  const PropertyCallbackInfo<Value>& info);
4180 
4181 
4187  uint32_t index,
4188  Local<Value> value,
4189  const PropertyCallbackInfo<Value>& info);
4190 
4191 
4197  uint32_t index,
4198  const PropertyCallbackInfo<Integer>& info);
4199 
4200 
4207  uint32_t index,
4208  const PropertyCallbackInfo<Boolean>& info);
4209 
4210 
4216  const PropertyCallbackInfo<Array>& info);
4217 
4218 
4223  ACCESS_GET,
4224  ACCESS_SET,
4225  ACCESS_HAS,
4226  ACCESS_DELETE,
4227  ACCESS_KEYS
4228 };
4229 
4230 
4236  Local<Value> key,
4237  AccessType type,
4238  Local<Value> data);
4239 
4240 
4246  uint32_t index,
4247  AccessType type,
4248  Local<Value> data);
4249 
4250 
4346 class V8_EXPORT FunctionTemplate : public Template {
4347  public:
4349  static Local<FunctionTemplate> New(
4350  Isolate* isolate, FunctionCallback callback = 0,
4351  Local<Value> data = Local<Value>(),
4352  Local<Signature> signature = Local<Signature>(), int length = 0);
4353 
4355  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
4356  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
4357  Local<Context> context);
4358 
4364  void SetCallHandler(FunctionCallback callback,
4365  Local<Value> data = Local<Value>());
4366 
4368  void SetLength(int length);
4369 
4371  Local<ObjectTemplate> InstanceTemplate();
4372 
4374  void Inherit(Local<FunctionTemplate> parent);
4375 
4380  Local<ObjectTemplate> PrototypeTemplate();
4381 
4387  void SetClassName(Local<String> name);
4388 
4389 
4394  void SetAcceptAnyReceiver(bool value);
4395 
4408  void SetHiddenPrototype(bool value);
4409 
4414  void ReadOnlyPrototype();
4415 
4420  void RemovePrototype();
4421 
4426  bool HasInstance(Local<Value> object);
4427 
4428  private:
4429  FunctionTemplate();
4430  friend class Context;
4431  friend class ObjectTemplate;
4432 };
4433 
4434 
4435 enum class PropertyHandlerFlags {
4436  kNone = 0,
4437  // See ALL_CAN_READ above.
4438  kAllCanRead = 1,
4439  // Will not call into interceptor for properties on the receiver or prototype
4440  // chain. Currently only valid for named interceptors.
4441  kNonMasking = 1 << 1,
4442  // Will not call into interceptor for symbol lookup. Only meaningful for
4443  // named interceptors.
4444  kOnlyInterceptStrings = 1 << 2,
4445 };
4446 
4447 
4456  Local<Value> data = Local<Value>(),
4457  PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
4458  : getter(getter),
4459  setter(setter),
4460  query(query),
4461  deleter(deleter),
4462  enumerator(enumerator),
4463  data(data),
4464  flags(flags) {}
4465 
4471  Local<Value> data;
4472  PropertyHandlerFlags flags;
4473 };
4474 
4475 
4479  IndexedPropertyGetterCallback getter = 0,
4480  IndexedPropertySetterCallback setter = 0,
4481  IndexedPropertyQueryCallback query = 0,
4482  IndexedPropertyDeleterCallback deleter = 0,
4483  IndexedPropertyEnumeratorCallback enumerator = 0,
4484  Local<Value> data = Local<Value>(),
4485  PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
4486  : getter(getter),
4487  setter(setter),
4488  query(query),
4489  deleter(deleter),
4490  enumerator(enumerator),
4491  data(data),
4492  flags(flags) {}
4493 
4499  Local<Value> data;
4500  PropertyHandlerFlags flags;
4501 };
4502 
4503 
4510 class V8_EXPORT ObjectTemplate : public Template {
4511  public:
4513  static Local<ObjectTemplate> New(
4514  Isolate* isolate,
4516  static V8_DEPRECATE_SOON("Use isolate version", Local<ObjectTemplate> New());
4517 
4519  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
4520  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
4521 
4551  void SetAccessor(
4553  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
4554  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
4556  void SetAccessor(
4557  Local<Name> name, AccessorNameGetterCallback getter,
4558  AccessorNameSetterCallback setter = 0, Local<Value> data = Local<Value>(),
4559  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
4561 
4582  // TODO(dcarney): deprecate
4583  void SetNamedPropertyHandler(NamedPropertyGetterCallback getter,
4584  NamedPropertySetterCallback setter = 0,
4585  NamedPropertyQueryCallback query = 0,
4586  NamedPropertyDeleterCallback deleter = 0,
4587  NamedPropertyEnumeratorCallback enumerator = 0,
4588  Local<Value> data = Local<Value>());
4589  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
4590 
4607  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
4608  // TODO(dcarney): deprecate
4609  void SetIndexedPropertyHandler(
4611  IndexedPropertySetterCallback setter = 0,
4612  IndexedPropertyQueryCallback query = 0,
4613  IndexedPropertyDeleterCallback deleter = 0,
4614  IndexedPropertyEnumeratorCallback enumerator = 0,
4615  Local<Value> data = Local<Value>()) {
4616  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
4617  deleter, enumerator, data));
4618  }
4625  void SetCallAsFunctionHandler(FunctionCallback callback,
4626  Local<Value> data = Local<Value>());
4627 
4636  void MarkAsUndetectable();
4637 
4646  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
4647  IndexedSecurityCallback indexed_handler,
4648  Local<Value> data = Local<Value>());
4649 
4654  int InternalFieldCount();
4655 
4660  void SetInternalFieldCount(int value);
4661 
4662  private:
4663  ObjectTemplate();
4664  static Local<ObjectTemplate> New(internal::Isolate* isolate,
4665  Local<FunctionTemplate> constructor);
4666  friend class FunctionTemplate;
4667 };
4668 
4669 
4673 class V8_EXPORT Signature : public Data {
4674  public:
4675  static Local<Signature> New(
4676  Isolate* isolate,
4678 
4679  private:
4680  Signature();
4681 };
4682 
4683 
4688 class V8_EXPORT AccessorSignature : public Data {
4689  public:
4690  static Local<AccessorSignature> New(
4691  Isolate* isolate,
4693 
4694  private:
4696 };
4697 
4698 
4703 class V8_EXPORT TypeSwitch : public Data {
4704  public:
4705  static Local<TypeSwitch> New(Local<FunctionTemplate> type);
4706  static Local<TypeSwitch> New(int argc, Local<FunctionTemplate> types[]);
4707  int match(Local<Value> value);
4708 
4709  private:
4710  TypeSwitch();
4711 };
4712 
4713 
4714 // --- Extensions ---
4715 
4718  public:
4719  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
4720  ExternalOneByteStringResourceImpl(const char* data, size_t length)
4721  : data_(data), length_(length) {}
4722  const char* data() const { return data_; }
4723  size_t length() const { return length_; }
4724 
4725  private:
4726  const char* data_;
4727  size_t length_;
4728 };
4729 
4733 class V8_EXPORT Extension { // NOLINT
4734  public:
4735  // Note that the strings passed into this constructor must live as long
4736  // as the Extension itself.
4737  Extension(const char* name,
4738  const char* source = 0,
4739  int dep_count = 0,
4740  const char** deps = 0,
4741  int source_length = -1);
4742  virtual ~Extension() { }
4743  virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
4744  v8::Isolate* isolate, v8::Local<v8::String> name) {
4746  }
4747 
4748  const char* name() const { return name_; }
4749  size_t source_length() const { return source_length_; }
4750  const String::ExternalOneByteStringResource* source() const {
4751  return &source_; }
4752  int dependency_count() { return dep_count_; }
4753  const char** dependencies() { return deps_; }
4754  void set_auto_enable(bool value) { auto_enable_ = value; }
4755  bool auto_enable() { return auto_enable_; }
4756 
4757  private:
4758  const char* name_;
4759  size_t source_length_; // expected to initialize before source_
4761  int dep_count_;
4762  const char** deps_;
4763  bool auto_enable_;
4764 
4765  // Disallow copying and assigning.
4766  Extension(const Extension&);
4767  void operator=(const Extension&);
4768 };
4769 
4770 
4771 void V8_EXPORT RegisterExtension(Extension* extension);
4772 
4773 
4774 // --- Statics ---
4775 
4776 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
4777 V8_INLINE Local<Primitive> Null(Isolate* isolate);
4778 V8_INLINE Local<Boolean> True(Isolate* isolate);
4779 V8_INLINE Local<Boolean> False(Isolate* isolate);
4780 
4781 
4791 class V8_EXPORT ResourceConstraints {
4792  public:
4794 
4804  void ConfigureDefaults(uint64_t physical_memory,
4805  uint64_t virtual_memory_limit);
4806 
4807  // Deprecated, will be removed soon.
4808  V8_DEPRECATED("Use two-args version instead",
4809  void ConfigureDefaults(uint64_t physical_memory,
4810  uint64_t virtual_memory_limit,
4811  uint32_t number_of_processors));
4812 
4813  int max_semi_space_size() const { return max_semi_space_size_; }
4814  void set_max_semi_space_size(int value) { max_semi_space_size_ = value; }
4815  int max_old_space_size() const { return max_old_space_size_; }
4816  void set_max_old_space_size(int value) { max_old_space_size_ = value; }
4817  int max_executable_size() const { return max_executable_size_; }
4818  void set_max_executable_size(int value) { max_executable_size_ = value; }
4819  uint32_t* stack_limit() const { return stack_limit_; }
4820  // Sets an address beyond which the VM's stack may not grow.
4821  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
4822  V8_DEPRECATED("Unused, will be removed", int max_available_threads() const) {
4823  return max_available_threads_;
4824  }
4825  // Set the number of threads available to V8, assuming at least 1.
4826  V8_DEPRECATED("Unused, will be removed",
4827  void set_max_available_threads(int value)) {
4828  max_available_threads_ = value;
4829  }
4830  size_t code_range_size() const { return code_range_size_; }
4831  void set_code_range_size(size_t value) {
4832  code_range_size_ = value;
4833  }
4834 
4835  private:
4836  int max_semi_space_size_;
4837  int max_old_space_size_;
4838  int max_executable_size_;
4839  uint32_t* stack_limit_;
4840  int max_available_threads_;
4841  size_t code_range_size_;
4842 };
4843 
4844 
4845 // --- Exceptions ---
4846 
4847 
4848 typedef void (*FatalErrorCallback)(const char* location, const char* message);
4849 
4850 
4851 typedef void (*MessageCallback)(Local<Message> message, Local<Value> error);
4852 
4853 // --- Tracing ---
4854 
4855 typedef void (*LogEventCallback)(const char* name, int event);
4856 
4861 class V8_EXPORT Exception {
4862  public:
4863  static Local<Value> RangeError(Local<String> message);
4864  static Local<Value> ReferenceError(Local<String> message);
4865  static Local<Value> SyntaxError(Local<String> message);
4866  static Local<Value> TypeError(Local<String> message);
4867  static Local<Value> Error(Local<String> message);
4868 
4874  static Local<Message> CreateMessage(Local<Value> exception);
4875 
4880  static Local<StackTrace> GetStackTrace(Local<Value> exception);
4881 };
4882 
4883 
4884 // --- Counters Callbacks ---
4885 
4886 typedef int* (*CounterLookupCallback)(const char* name);
4887 
4888 typedef void* (*CreateHistogramCallback)(const char* name,
4889  int min,
4890  int max,
4891  size_t buckets);
4892 
4893 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
4894 
4895 // --- Memory Allocation Callback ---
4896 enum ObjectSpace {
4897  kObjectSpaceNewSpace = 1 << 0,
4898  kObjectSpaceOldSpace = 1 << 1,
4899  kObjectSpaceCodeSpace = 1 << 2,
4900  kObjectSpaceMapSpace = 1 << 3,
4901  kObjectSpaceLoSpace = 1 << 4,
4902  kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldSpace |
4903  kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
4904  kObjectSpaceLoSpace
4905 };
4906 
4907  enum AllocationAction {
4908  kAllocationActionAllocate = 1 << 0,
4909  kAllocationActionFree = 1 << 1,
4910  kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
4911  };
4912 
4913 typedef void (*MemoryAllocationCallback)(ObjectSpace space,
4914  AllocationAction action,
4915  int size);
4916 
4917 // --- Leave Script Callback ---
4918 typedef void (*CallCompletedCallback)();
4919 
4920 // --- Promise Reject Callback ---
4921 enum PromiseRejectEvent {
4922  kPromiseRejectWithNoHandler = 0,
4923  kPromiseHandlerAddedAfterReject = 1
4924 };
4925 
4927  public:
4928  PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
4929  Local<Value> value, Local<StackTrace> stack_trace)
4930  : promise_(promise),
4931  event_(event),
4932  value_(value),
4933  stack_trace_(stack_trace) {}
4934 
4935  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
4936  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
4937  V8_INLINE Local<Value> GetValue() const { return value_; }
4938 
4939  // DEPRECATED. Use v8::Exception::CreateMessage(GetValue())->GetStackTrace()
4940  V8_INLINE Local<StackTrace> GetStackTrace() const { return stack_trace_; }
4941 
4942  private:
4943  Local<Promise> promise_;
4944  PromiseRejectEvent event_;
4945  Local<Value> value_;
4946  Local<StackTrace> stack_trace_;
4947 };
4948 
4949 typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
4950 
4951 // --- Microtask Callback ---
4952 typedef void (*MicrotaskCallback)(void* data);
4953 
4954 // --- Failed Access Check Callback ---
4955 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
4956  AccessType type,
4957  Local<Value> data);
4958 
4959 // --- AllowCodeGenerationFromStrings callbacks ---
4960 
4966 
4967 // --- Garbage Collection Callbacks ---
4968 
4976 enum GCType {
4977  kGCTypeScavenge = 1 << 0,
4978  kGCTypeMarkSweepCompact = 1 << 1,
4979  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
4980 };
4981 
4982 enum GCCallbackFlags {
4983  kNoGCCallbackFlags = 0,
4984  kGCCallbackFlagCompacted = 1 << 0,
4985  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
4986  kGCCallbackFlagForced = 1 << 2
4987 };
4988 
4989 typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
4990 typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
4991 
4992 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
4993 
4994 
5001 class V8_EXPORT HeapStatistics {
5002  public:
5003  HeapStatistics();
5004  size_t total_heap_size() { return total_heap_size_; }
5005  size_t total_heap_size_executable() { return total_heap_size_executable_; }
5006  size_t total_physical_size() { return total_physical_size_; }
5007  size_t total_available_size() { return total_available_size_; }
5008  size_t used_heap_size() { return used_heap_size_; }
5009  size_t heap_size_limit() { return heap_size_limit_; }
5010 
5011  private:
5012  size_t total_heap_size_;
5013  size_t total_heap_size_executable_;
5014  size_t total_physical_size_;
5015  size_t total_available_size_;
5016  size_t used_heap_size_;
5017  size_t heap_size_limit_;
5018 
5019  friend class V8;
5020  friend class Isolate;
5021 };
5022 
5023 
5024 class V8_EXPORT HeapSpaceStatistics {
5025  public:
5027  const char* space_name() { return space_name_; }
5028  size_t space_size() { return space_size_; }
5029  size_t space_used_size() { return space_used_size_; }
5030  size_t space_available_size() { return space_available_size_; }
5031  size_t physical_space_size() { return physical_space_size_; }
5032 
5033  private:
5034  const char* space_name_;
5035  size_t space_size_;
5036  size_t space_used_size_;
5037  size_t space_available_size_;
5038  size_t physical_space_size_;
5039 
5040  friend class Isolate;
5041 };
5042 
5043 
5044 class V8_EXPORT HeapObjectStatistics {
5045  public:
5047  const char* object_type() { return object_type_; }
5048  const char* object_sub_type() { return object_sub_type_; }
5049  size_t object_count() { return object_count_; }
5050  size_t object_size() { return object_size_; }
5051 
5052  private:
5053  const char* object_type_;
5054  const char* object_sub_type_;
5055  size_t object_count_;
5056  size_t object_size_;
5057 
5058  friend class Isolate;
5059 };
5060 
5061 
5062 class RetainedObjectInfo;
5063 
5064 
5076 typedef void (*FunctionEntryHook)(uintptr_t function,
5077  uintptr_t return_addr_location);
5078 
5085  enum EventType {
5086  CODE_ADDED,
5087  CODE_MOVED,
5088  CODE_REMOVED,
5089  CODE_ADD_LINE_POS_INFO,
5090  CODE_START_LINE_INFO_RECORDING,
5091  CODE_END_LINE_INFO_RECORDING
5092  };
5093  // Definition of the code position type. The "POSITION" type means the place
5094  // in the source code which are of interest when making stack traces to
5095  // pin-point the source location of a stack frame as close as possible.
5096  // The "STATEMENT_POSITION" means the place at the beginning of each
5097  // statement, and is used to indicate possible break locations.
5098  enum PositionType { POSITION, STATEMENT_POSITION };
5099 
5100  // Type of event.
5101  EventType type;
5102  // Start of the instructions.
5103  void* code_start;
5104  // Size of the instructions.
5105  size_t code_len;
5106  // Script info for CODE_ADDED event.
5107  Local<UnboundScript> script;
5108  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
5109  // code line information which is returned from the
5110  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
5111  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
5112  void* user_data;
5113 
5114  struct name_t {
5115  // Name of the object associated with the code, note that the string is not
5116  // zero-terminated.
5117  const char* str;
5118  // Number of chars in str.
5119  size_t len;
5120  };
5121 
5122  struct line_info_t {
5123  // PC offset
5124  size_t offset;
5125  // Code postion
5126  size_t pos;
5127  // The position type.
5128  PositionType position_type;
5129  };
5130 
5131  union {
5132  // Only valid for CODE_ADDED.
5133  struct name_t name;
5134 
5135  // Only valid for CODE_ADD_LINE_POS_INFO
5136  struct line_info_t line_info;
5137 
5138  // New location of instructions. Only valid for CODE_MOVED.
5139  void* new_code_start;
5140  };
5141 };
5142 
5147  kJitCodeEventDefault = 0,
5148  // Generate callbacks for already existent code.
5149  kJitCodeEventEnumExisting = 1
5150 };
5151 
5152 
5158 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
5159 
5160 
5164 class V8_EXPORT ExternalResourceVisitor { // NOLINT
5165  public:
5166  virtual ~ExternalResourceVisitor() {}
5167  virtual void VisitExternalString(Local<String> string) {}
5168 };
5169 
5170 
5174 class V8_EXPORT PersistentHandleVisitor { // NOLINT
5175  public:
5176  virtual ~PersistentHandleVisitor() {}
5177  virtual void VisitPersistentHandle(Persistent<Value>* value,
5178  uint16_t class_id) {}
5179 };
5180 
5181 
5190 class V8_EXPORT Isolate {
5191  public:
5195  struct CreateParams {
5196  CreateParams()
5197  : entry_hook(NULL),
5198  code_event_handler(NULL),
5199  snapshot_blob(NULL),
5200  counter_lookup_callback(NULL),
5201  create_histogram_callback(NULL),
5202  add_histogram_sample_callback(NULL),
5203  array_buffer_allocator(NULL) {}
5204 
5213 
5219 
5224 
5229 
5230 
5235  CounterLookupCallback counter_lookup_callback;
5236 
5243  CreateHistogramCallback create_histogram_callback;
5244  AddHistogramSampleCallback add_histogram_sample_callback;
5245 
5251  };
5252 
5253 
5258  class V8_EXPORT Scope {
5259  public:
5260  explicit Scope(Isolate* isolate) : isolate_(isolate) {
5261  isolate->Enter();
5262  }
5263 
5264  ~Scope() { isolate_->Exit(); }
5265 
5266  private:
5267  Isolate* const isolate_;
5268 
5269  // Prevent copying of Scope objects.
5270  Scope(const Scope&);
5271  Scope& operator=(const Scope&);
5272  };
5273 
5274 
5279  public:
5280  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
5281 
5282  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
5284 
5285  private:
5286  bool on_failure_;
5287  void* internal_;
5288 
5289  // Prevent copying of Scope objects.
5293  };
5294 
5295 
5300  public:
5301  explicit AllowJavascriptExecutionScope(Isolate* isolate);
5303 
5304  private:
5305  void* internal_throws_;
5306  void* internal_assert_;
5307 
5308  // Prevent copying of Scope objects.
5310  AllowJavascriptExecutionScope& operator=(
5312  };
5313 
5319  public:
5320  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
5322 
5323  private:
5324  internal::Isolate* isolate_;
5325 
5326  // Prevent copying of Scope objects.
5330  };
5331 
5337  kFullGarbageCollection,
5338  kMinorGarbageCollection
5339  };
5340 
5347  kUseAsm = 0,
5348  kBreakIterator = 1,
5349  kLegacyConst = 2,
5350  kMarkDequeOverflow = 3,
5351  kStoreBufferOverflow = 4,
5352  kSlotsBufferOverflow = 5,
5353  kObjectObserve = 6,
5354  kForcedGC = 7,
5355  kUseCounterFeatureCount // This enum value must be last.
5356  };
5357 
5358  typedef void (*UseCounterCallback)(Isolate* isolate,
5359  UseCounterFeature feature);
5360 
5361 
5371  static Isolate* New(const CreateParams& params);
5372 
5373  static V8_DEPRECATED("Always pass CreateParams", Isolate* New());
5374 
5381  static Isolate* GetCurrent();
5382 
5392  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
5393  void SetAbortOnUncaughtExceptionCallback(
5394  AbortOnUncaughtExceptionCallback callback);
5395 
5406  void Enter();
5407 
5415  void Exit();
5416 
5421  void Dispose();
5422 
5427  V8_INLINE void SetData(uint32_t slot, void* data);
5428 
5433  V8_INLINE void* GetData(uint32_t slot);
5434 
5439  V8_INLINE static uint32_t GetNumberOfDataSlots();
5440 
5444  void GetHeapStatistics(HeapStatistics* heap_statistics);
5445 
5449  size_t NumberOfHeapSpaces();
5450 
5460  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
5461  size_t index);
5462 
5466  size_t NumberOfTrackedHeapObjectTypes();
5467 
5477  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
5478  size_t type_index);
5479 
5492  void GetStackSample(const RegisterState& state, void** frames,
5493  size_t frames_limit, SampleInfo* sample_info);
5494 
5508  V8_INLINE int64_t
5509  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
5510 
5515  HeapProfiler* GetHeapProfiler();
5516 
5522  CpuProfiler* GetCpuProfiler();
5523 
5525  bool InContext();
5526 
5528  Local<Context> GetCurrentContext();
5529 
5535  Local<Context> GetCallingContext();
5536 
5538  Local<Context> GetEnteredContext();
5539 
5546  Local<Value> ThrowException(Local<Value> exception);
5547 
5559  template<typename T> void SetObjectGroupId(const Persistent<T>& object,
5560  UniqueId id);
5561 
5569  template<typename T> void SetReferenceFromGroup(UniqueId id,
5570  const Persistent<T>& child);
5571 
5578  template<typename T, typename S>
5579  void SetReference(const Persistent<T>& parent, const Persistent<S>& child);
5580 
5581  typedef void (*GCPrologueCallback)(Isolate* isolate,
5582  GCType type,
5583  GCCallbackFlags flags);
5584  typedef void (*GCEpilogueCallback)(Isolate* isolate,
5585  GCType type,
5586  GCCallbackFlags flags);
5587 
5597  void AddGCPrologueCallback(
5598  GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
5599 
5604  void RemoveGCPrologueCallback(GCPrologueCallback callback);
5605 
5615  void AddGCEpilogueCallback(
5616  GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
5617 
5622  void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
5623 
5624 
5632  void TerminateExecution();
5633 
5642  bool IsExecutionTerminating();
5643 
5658  void CancelTerminateExecution();
5659 
5668  void RequestInterrupt(InterruptCallback callback, void* data);
5669 
5680  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
5681 
5685  void SetEventLogger(LogEventCallback that);
5686 
5694  void AddCallCompletedCallback(CallCompletedCallback callback);
5695 
5699  void RemoveCallCompletedCallback(CallCompletedCallback callback);
5700 
5701 
5706  void SetPromiseRejectCallback(PromiseRejectCallback callback);
5707 
5712  void RunMicrotasks();
5713 
5717  void EnqueueMicrotask(Local<Function> microtask);
5718 
5722  void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
5723 
5728  void SetAutorunMicrotasks(bool autorun);
5729 
5734  bool WillAutorunMicrotasks() const;
5735 
5739  void SetUseCounterCallback(UseCounterCallback callback);
5740 
5745  void SetCounterFunction(CounterLookupCallback);
5746 
5753  void SetCreateHistogramFunction(CreateHistogramCallback);
5754  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
5755 
5770  bool IdleNotificationDeadline(double deadline_in_seconds);
5771 
5772  V8_DEPRECATE_SOON("use IdleNotificationDeadline()",
5773  bool IdleNotification(int idle_time_in_ms));
5774 
5779  void LowMemoryNotification();
5780 
5790  int ContextDisposedNotification(bool dependant_context = true);
5791 
5814  void SetJitCodeEventHandler(JitCodeEventOptions options,
5815  JitCodeEventHandler event_handler);
5816 
5826  void SetStackLimit(uintptr_t stack_limit);
5827 
5841  void GetCodeRange(void** start, size_t* length_in_bytes);
5842 
5844  void SetFatalErrorHandler(FatalErrorCallback that);
5845 
5850  void SetAllowCodeGenerationFromStringsCallback(
5852 
5857  bool IsDead();
5858 
5868  bool AddMessageListener(MessageCallback that,
5869  Local<Value> data = Local<Value>());
5870 
5874  void RemoveMessageListeners(MessageCallback that);
5875 
5877  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
5878 
5883  void SetCaptureStackTraceForUncaughtExceptions(
5884  bool capture, int frame_limit = 10,
5885  StackTrace::StackTraceOptions options = StackTrace::kOverview);
5886 
5891  void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
5892  ObjectSpace space, AllocationAction action);
5893 
5897  void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
5898 
5904  void VisitExternalResources(ExternalResourceVisitor* visitor);
5905 
5910  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
5911 
5919  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
5920 
5921  private:
5922  template <class K, class V, class Traits>
5923  friend class PersistentValueMapBase;
5924 
5925  Isolate();
5926  Isolate(const Isolate&);
5927  ~Isolate();
5928  Isolate& operator=(const Isolate&);
5929  void* operator new(size_t size);
5930  void operator delete(void*, size_t);
5931 
5932  void SetObjectGroupId(internal::Object** object, UniqueId id);
5933  void SetReferenceFromGroup(UniqueId id, internal::Object** object);
5934  void SetReference(internal::Object** parent, internal::Object** child);
5935  void CollectAllGarbage(const char* gc_reason);
5936 };
5937 
5938 class V8_EXPORT StartupData {
5939  public:
5940  const char* data;
5941  int raw_size;
5942 };
5943 
5944 
5949 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
5950 
5951 
5965 typedef uintptr_t (*ReturnAddressLocationResolver)(
5966  uintptr_t return_addr_location);
5967 
5968 
5972 class V8_EXPORT V8 {
5973  public:
5975  V8_INLINE static V8_DEPRECATE_SOON(
5976  "Use isolate version",
5977  void SetFatalErrorHandler(FatalErrorCallback that));
5978 
5983  V8_INLINE static V8_DEPRECATE_SOON(
5984  "Use isolate version", void SetAllowCodeGenerationFromStringsCallback(
5986 
5993  static V8_DEPRECATE_SOON(
5994  "Use isolate version",
5995  void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator));
5996 
6001  V8_INLINE static V8_DEPRECATE_SOON("no alternative", bool IsDead());
6002 
6018  static void SetNativesDataBlob(StartupData* startup_blob);
6019  static void SetSnapshotDataBlob(StartupData* startup_blob);
6020 
6026  static StartupData CreateSnapshotDataBlob(const char* custom_source = NULL);
6027 
6037  V8_INLINE static V8_DEPRECATE_SOON(
6038  "Use isolate version",
6039  bool AddMessageListener(MessageCallback that,
6040  Local<Value> data = Local<Value>()));
6041 
6045  V8_INLINE static V8_DEPRECATE_SOON(
6046  "Use isolate version", void RemoveMessageListeners(MessageCallback that));
6047 
6052  V8_INLINE static V8_DEPRECATE_SOON(
6053  "Use isolate version",
6054  void SetCaptureStackTraceForUncaughtExceptions(
6055  bool capture, int frame_limit = 10,
6056  StackTrace::StackTraceOptions options = StackTrace::kOverview));
6057 
6061  static void SetFlagsFromString(const char* str, int length);
6062 
6066  static void SetFlagsFromCommandLine(int* argc,
6067  char** argv,
6068  bool remove_flags);
6069 
6071  static const char* GetVersion();
6072 
6074  V8_INLINE static V8_DEPRECATE_SOON(
6075  "Use isolate version",
6076  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback));
6077 
6088  static V8_DEPRECATE_SOON(
6089  "Use isolate version",
6090  void AddGCPrologueCallback(GCPrologueCallback callback,
6091  GCType gc_type_filter = kGCTypeAll));
6092 
6097  V8_INLINE static V8_DEPRECATE_SOON(
6098  "Use isolate version",
6099  void RemoveGCPrologueCallback(GCPrologueCallback callback));
6100 
6111  static V8_DEPRECATE_SOON(
6112  "Use isolate version",
6113  void AddGCEpilogueCallback(GCEpilogueCallback callback,
6114  GCType gc_type_filter = kGCTypeAll));
6115 
6120  V8_INLINE static V8_DEPRECATE_SOON(
6121  "Use isolate version",
6122  void RemoveGCEpilogueCallback(GCEpilogueCallback callback));
6123 
6128  V8_INLINE static V8_DEPRECATE_SOON(
6129  "Use isolate version",
6130  void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
6131  ObjectSpace space,
6132  AllocationAction action));
6133 
6137  V8_INLINE static V8_DEPRECATE_SOON(
6138  "Use isolate version",
6139  void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback));
6140 
6145  static bool Initialize();
6146 
6151  static void SetEntropySource(EntropySource source);
6152 
6157  static void SetReturnAddressLocationResolver(
6158  ReturnAddressLocationResolver return_address_resolver);
6159 
6169  V8_INLINE static V8_DEPRECATE_SOON("Use isolate version",
6170  void TerminateExecution(Isolate* isolate));
6171 
6182  V8_INLINE static V8_DEPRECATE_SOON(
6183  "Use isolate version",
6184  bool IsExecutionTerminating(Isolate* isolate = NULL));
6185 
6202  V8_INLINE static V8_DEPRECATE_SOON(
6203  "Use isolate version", void CancelTerminateExecution(Isolate* isolate));
6204 
6214  static bool Dispose();
6215 
6221  V8_INLINE static V8_DEPRECATE_SOON(
6222  "Use isoalte version",
6223  void VisitExternalResources(ExternalResourceVisitor* visitor));
6224 
6229  V8_INLINE static V8_DEPRECATE_SOON(
6230  "Use isolate version",
6231  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor));
6232 
6237  V8_INLINE static V8_DEPRECATE_SOON(
6238  "Use isolate version",
6239  void VisitHandlesWithClassIds(Isolate* isolate,
6240  PersistentHandleVisitor* visitor));
6241 
6249  V8_INLINE static V8_DEPRECATE_SOON(
6250  "Use isolate version",
6251  void VisitHandlesForPartialDependence(Isolate* isolate,
6252  PersistentHandleVisitor* visitor));
6253 
6261  static bool InitializeICU(const char* icu_data_file = NULL);
6262 
6279  static void InitializeExternalStartupData(const char* directory_path);
6280  static void InitializeExternalStartupData(const char* natives_blob,
6281  const char* snapshot_blob);
6286  static void InitializePlatform(Platform* platform);
6287 
6292  static void ShutdownPlatform();
6293 
6294  private:
6295  V8();
6296 
6297  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
6298  internal::Object** handle);
6299  static internal::Object** CopyPersistent(internal::Object** handle);
6300  static void DisposeGlobal(internal::Object** global_handle);
6301  typedef WeakCallbackData<Value, void>::Callback WeakCallback;
6302  static void MakeWeak(internal::Object** global_handle, void* data,
6303  WeakCallback weak_callback);
6304  static void MakeWeak(internal::Object** global_handle, void* data,
6305  WeakCallbackInfo<void>::Callback weak_callback,
6306  WeakCallbackType type);
6307  static void MakeWeak(internal::Object** global_handle, void* data,
6308  // Must be 0 or -1.
6309  int internal_field_index1,
6310  // Must be 1 or -1.
6311  int internal_field_index2,
6312  WeakCallbackInfo<void>::Callback weak_callback);
6313  static void* ClearWeak(internal::Object** global_handle);
6314  static void Eternalize(Isolate* isolate,
6315  Value* handle,
6316  int* index);
6317  static Local<Value> GetEternal(Isolate* isolate, int index);
6318 
6319  static void FromJustIsNothing();
6320  static void ToLocalEmpty();
6321  static void InternalFieldOutOfBounds(int index);
6322  template <class T> friend class Local;
6323  template <class T>
6324  friend class MaybeLocal;
6325  template <class T>
6326  friend class Maybe;
6327  template <class T>
6328  friend class WeakCallbackInfo;
6329  template <class T> friend class Eternal;
6330  template <class T> friend class PersistentBase;
6331  template <class T, class M> friend class Persistent;
6332  friend class Context;
6333 };
6334 
6335 
6346 template <class T>
6347 class Maybe {
6348  public:
6349  V8_INLINE bool IsNothing() const { return !has_value; }
6350  V8_INLINE bool IsJust() const { return has_value; }
6351 
6352  // Will crash if the Maybe<> is nothing.
6353  V8_INLINE T FromJust() const {
6354  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
6355  return value;
6356  }
6357 
6358  V8_INLINE T FromMaybe(const T& default_value) const {
6359  return has_value ? value : default_value;
6360  }
6361 
6362  V8_INLINE bool operator==(const Maybe& other) const {
6363  return (IsJust() == other.IsJust()) &&
6364  (!IsJust() || FromJust() == other.FromJust());
6365  }
6366 
6367  V8_INLINE bool operator!=(const Maybe& other) const {
6368  return !operator==(other);
6369  }
6370 
6371  private:
6372  Maybe() : has_value(false) {}
6373  explicit Maybe(const T& t) : has_value(true), value(t) {}
6374 
6375  bool has_value;
6376  T value;
6377 
6378  template <class U>
6379  friend Maybe<U> Nothing();
6380  template <class U>
6381  friend Maybe<U> Just(const U& u);
6382 };
6383 
6384 
6385 template <class T>
6386 inline Maybe<T> Nothing() {
6387  return Maybe<T>();
6388 }
6389 
6390 
6391 template <class T>
6392 inline Maybe<T> Just(const T& t) {
6393  return Maybe<T>(t);
6394 }
6395 
6396 
6400 class V8_EXPORT TryCatch {
6401  public:
6407  V8_DEPRECATE_SOON("Use isolate version", TryCatch());
6408 
6414  TryCatch(Isolate* isolate);
6415 
6419  ~TryCatch();
6420 
6424  bool HasCaught() const;
6425 
6434  bool CanContinue() const;
6435 
6448  bool HasTerminated() const;
6449 
6457  Local<Value> ReThrow();
6458 
6465  Local<Value> Exception() const;
6466 
6471  V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace() const);
6472  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
6473  Local<Context> context) const;
6474 
6482  Local<v8::Message> Message() const;
6483 
6494  void Reset();
6495 
6504  void SetVerbose(bool value);
6505 
6511  void SetCaptureMessage(bool value);
6512 
6524  static void* JSStackComparableAddress(v8::TryCatch* handler) {
6525  if (handler == NULL) return NULL;
6526  return handler->js_stack_comparable_address_;
6527  }
6528 
6529  private:
6530  void ResetInternal();
6531 
6532  // Make it hard to create heap-allocated TryCatch blocks.
6533  TryCatch(const TryCatch&);
6534  void operator=(const TryCatch&);
6535  void* operator new(size_t size);
6536  void operator delete(void*, size_t);
6537 
6538  v8::internal::Isolate* isolate_;
6539  v8::TryCatch* next_;
6540  void* exception_;
6541  void* message_obj_;
6542  void* js_stack_comparable_address_;
6543  bool is_verbose_ : 1;
6544  bool can_continue_ : 1;
6545  bool capture_message_ : 1;
6546  bool rethrow_ : 1;
6547  bool has_terminated_ : 1;
6548 
6549  friend class v8::internal::Isolate;
6550 };
6551 
6552 
6553 // --- Context ---
6554 
6555 
6559 class V8_EXPORT ExtensionConfiguration {
6560  public:
6561  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
6562  ExtensionConfiguration(int name_count, const char* names[])
6563  : name_count_(name_count), names_(names) { }
6564 
6565  const char** begin() const { return &names_[0]; }
6566  const char** end() const { return &names_[name_count_]; }
6567 
6568  private:
6569  const int name_count_;
6570  const char** names_;
6571 };
6572 
6573 
6578 class V8_EXPORT Context {
6579  public:
6593 
6598  void DetachGlobal();
6599 
6618  static Local<Context> New(
6619  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
6620  Local<ObjectTemplate> global_template = Local<ObjectTemplate>(),
6621  Local<Value> global_object = Local<Value>());
6622 
6627  void SetSecurityToken(Local<Value> token);
6628 
6630  void UseDefaultSecurityToken();
6631 
6633  Local<Value> GetSecurityToken();
6634 
6641  void Enter();
6642 
6647  void Exit();
6648 
6650  v8::Isolate* GetIsolate();
6651 
6657  enum EmbedderDataFields { kDebugIdIndex = 0 };
6658 
6664  V8_INLINE Local<Value> GetEmbedderData(int index);
6665 
6670  Local<Object> GetExtrasExportsObject();
6671 
6677  void SetEmbedderData(int index, Local<Value> value);
6678 
6685  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
6686 
6692  void SetAlignedPointerInEmbedderData(int index, void* value);
6693 
6707  void AllowCodeGenerationFromStrings(bool allow);
6708 
6713  bool IsCodeGenerationFromStringsAllowed();
6714 
6720  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
6721 
6726  class Scope {
6727  public:
6728  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
6729  context_->Enter();
6730  }
6731  V8_INLINE ~Scope() { context_->Exit(); }
6732 
6733  private:
6734  Local<Context> context_;
6735  };
6736 
6737  private:
6738  friend class Value;
6739  friend class Script;
6740  friend class Object;
6741  friend class Function;
6742 
6743  Local<Value> SlowGetEmbedderData(int index);
6744  void* SlowGetAlignedPointerFromEmbedderData(int index);
6745 };
6746 
6747 
6824 class V8_EXPORT Unlocker {
6825  public:
6829  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
6830 
6831  ~Unlocker();
6832  private:
6833  void Initialize(Isolate* isolate);
6834 
6835  internal::Isolate* isolate_;
6836 };
6837 
6838 
6839 class V8_EXPORT Locker {
6840  public:
6844  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
6845 
6846  ~Locker();
6847 
6852  static bool IsLocked(Isolate* isolate);
6853 
6857  static bool IsActive();
6858 
6859  private:
6860  void Initialize(Isolate* isolate);
6861 
6862  bool has_lock_;
6863  bool top_level_;
6864  internal::Isolate* isolate_;
6865 
6866  // Disallow copying and assigning.
6867  Locker(const Locker&);
6868  void operator=(const Locker&);
6869 };
6870 
6871 
6872 // --- Implementation ---
6873 
6874 
6875 namespace internal {
6876 
6877 const int kApiPointerSize = sizeof(void*); // NOLINT
6878 const int kApiIntSize = sizeof(int); // NOLINT
6879 const int kApiInt64Size = sizeof(int64_t); // NOLINT
6880 
6881 // Tag information for HeapObject.
6882 const int kHeapObjectTag = 1;
6883 const int kHeapObjectTagSize = 2;
6884 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
6885 
6886 // Tag information for Smi.
6887 const int kSmiTag = 0;
6888 const int kSmiTagSize = 1;
6889 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
6890 
6891 template <size_t ptr_size> struct SmiTagging;
6892 
6893 template<int kSmiShiftSize>
6894 V8_INLINE internal::Object* IntToSmi(int value) {
6895  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
6896  uintptr_t tagged_value =
6897  (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
6898  return reinterpret_cast<internal::Object*>(tagged_value);
6899 }
6900 
6901 // Smi constants for 32-bit systems.
6902 template <> struct SmiTagging<4> {
6903  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
6904  static int SmiShiftSize() { return kSmiShiftSize; }
6905  static int SmiValueSize() { return kSmiValueSize; }
6906  V8_INLINE static int SmiToInt(const internal::Object* value) {
6907  int shift_bits = kSmiTagSize + kSmiShiftSize;
6908  // Throw away top 32 bits and shift down (requires >> to be sign extending).
6909  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
6910  }
6911  V8_INLINE static internal::Object* IntToSmi(int value) {
6912  return internal::IntToSmi<kSmiShiftSize>(value);
6913  }
6914  V8_INLINE static bool IsValidSmi(intptr_t value) {
6915  // To be representable as an tagged small integer, the two
6916  // most-significant bits of 'value' must be either 00 or 11 due to
6917  // sign-extension. To check this we add 01 to the two
6918  // most-significant bits, and check if the most-significant bit is 0
6919  //
6920  // CAUTION: The original code below:
6921  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
6922  // may lead to incorrect results according to the C language spec, and
6923  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
6924  // compiler may produce undefined results in case of signed integer
6925  // overflow. The computation must be done w/ unsigned ints.
6926  return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
6927  }
6928 };
6929 
6930 // Smi constants for 64-bit systems.
6931 template <> struct SmiTagging<8> {
6932  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
6933  static int SmiShiftSize() { return kSmiShiftSize; }
6934  static int SmiValueSize() { return kSmiValueSize; }
6935  V8_INLINE static int SmiToInt(const internal::Object* value) {
6936  int shift_bits = kSmiTagSize + kSmiShiftSize;
6937  // Shift down and throw away top 32 bits.
6938  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
6939  }
6940  V8_INLINE static internal::Object* IntToSmi(int value) {
6941  return internal::IntToSmi<kSmiShiftSize>(value);
6942  }
6943  V8_INLINE static bool IsValidSmi(intptr_t value) {
6944  // To be representable as a long smi, the value must be a 32-bit integer.
6945  return (value == static_cast<int32_t>(value));
6946  }
6947 };
6948 
6950 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
6951 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
6952 V8_INLINE static bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
6953 V8_INLINE static bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
6954 
6960 class Internals {
6961  public:
6962  // These values match non-compiler-dependent values defined within
6963  // the implementation of v8.
6964  static const int kHeapObjectMapOffset = 0;
6965  static const int kMapInstanceTypeAndBitFieldOffset =
6966  1 * kApiPointerSize + kApiIntSize;
6967  static const int kStringResourceOffset = 3 * kApiPointerSize;
6968 
6969  static const int kOddballKindOffset = 3 * kApiPointerSize;
6970  static const int kForeignAddressOffset = kApiPointerSize;
6971  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
6972  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
6973  static const int kContextHeaderSize = 2 * kApiPointerSize;
6974  static const int kContextEmbedderDataIndex = 81;
6975  static const int kFullStringRepresentationMask = 0x07;
6976  static const int kStringEncodingMask = 0x4;
6977  static const int kExternalTwoByteRepresentationTag = 0x02;
6978  static const int kExternalOneByteRepresentationTag = 0x06;
6979 
6980  static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
6981  static const int kAmountOfExternalAllocatedMemoryOffset =
6982  4 * kApiPointerSize;
6983  static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
6984  kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size;
6985  static const int kIsolateRootsOffset =
6986  kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size +
6987  kApiPointerSize;
6988  static const int kUndefinedValueRootIndex = 5;
6989  static const int kNullValueRootIndex = 7;
6990  static const int kTrueValueRootIndex = 8;
6991  static const int kFalseValueRootIndex = 9;
6992  static const int kEmptyStringRootIndex = 10;
6993 
6994  // The external allocation limit should be below 256 MB on all architectures
6995  // to avoid that resource-constrained embedders run low on memory.
6996  static const int kExternalAllocationLimit = 192 * 1024 * 1024;
6997 
6998  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
6999  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
7000  static const int kNodeStateMask = 0x7;
7001  static const int kNodeStateIsWeakValue = 2;
7002  static const int kNodeStateIsPendingValue = 3;
7003  static const int kNodeStateIsNearDeathValue = 4;
7004  static const int kNodeIsIndependentShift = 3;
7005  static const int kNodeIsPartiallyDependentShift = 4;
7006 
7007  static const int kJSObjectType = 0xbe;
7008  static const int kFirstNonstringType = 0x80;
7009  static const int kOddballType = 0x83;
7010  static const int kForeignType = 0x87;
7011 
7012  static const int kUndefinedOddballKind = 5;
7013  static const int kNullOddballKind = 3;
7014 
7015  static const uint32_t kNumIsolateDataSlots = 4;
7016 
7017  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
7018  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
7019 #ifdef V8_ENABLE_CHECKS
7020  CheckInitializedImpl(isolate);
7021 #endif
7022  }
7023 
7024  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
7025  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
7026  kHeapObjectTag);
7027  }
7028 
7029  V8_INLINE static int SmiValue(const internal::Object* value) {
7030  return PlatformSmiTagging::SmiToInt(value);
7031  }
7032 
7033  V8_INLINE static internal::Object* IntToSmi(int value) {
7034  return PlatformSmiTagging::IntToSmi(value);
7035  }
7036 
7037  V8_INLINE static bool IsValidSmi(intptr_t value) {
7038  return PlatformSmiTagging::IsValidSmi(value);
7039  }
7040 
7041  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
7042  typedef internal::Object O;
7043  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
7044  // Map::InstanceType is defined so that it will always be loaded into
7045  // the LS 8 bits of one 16-bit word, regardless of endianess.
7046  return ReadField<uint16_t>(map, kMapInstanceTypeAndBitFieldOffset) & 0xff;
7047  }
7048 
7049  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
7050  typedef internal::Object O;
7051  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
7052  }
7053 
7054  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
7055  int representation = (instance_type & kFullStringRepresentationMask);
7056  return representation == kExternalTwoByteRepresentationTag;
7057  }
7058 
7059  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
7060  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7061  return *addr & static_cast<uint8_t>(1U << shift);
7062  }
7063 
7064  V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
7065  bool value, int shift) {
7066  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7067  uint8_t mask = static_cast<uint8_t>(1U << shift);
7068  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
7069  }
7070 
7071  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
7072  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7073  return *addr & kNodeStateMask;
7074  }
7075 
7076  V8_INLINE static void UpdateNodeState(internal::Object** obj,
7077  uint8_t value) {
7078  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7079  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
7080  }
7081 
7082  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
7083  uint32_t slot,
7084  void* data) {
7085  uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) +
7086  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
7087  *reinterpret_cast<void**>(addr) = data;
7088  }
7089 
7090  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
7091  uint32_t slot) {
7092  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
7093  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
7094  return *reinterpret_cast<void* const*>(addr);
7095  }
7096 
7097  V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
7098  int index) {
7099  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
7100  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
7101  }
7102 
7103  template <typename T>
7104  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
7105  const uint8_t* addr =
7106  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
7107  return *reinterpret_cast<const T*>(addr);
7108  }
7109 
7110  template <typename T>
7111  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
7112  typedef internal::Object O;
7113  typedef internal::Internals I;
7114  O* ctx = *reinterpret_cast<O* const*>(context);
7115  int embedder_data_offset = I::kContextHeaderSize +
7116  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
7117  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
7118  int value_offset =
7119  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
7120  return I::ReadField<T>(embedder_data, value_offset);
7121  }
7122 };
7123 
7124 } // namespace internal
7125 
7126 
7127 template <class T>
7129  return New(isolate, that.val_);
7130 }
7131 
7132 template <class T>
7133 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
7134  return New(isolate, that.val_);
7135 }
7136 
7137 
7138 template <class T>
7139 Local<T> Local<T>::New(Isolate* isolate, T* that) {
7140  if (that == NULL) return Local<T>();
7141  T* that_ptr = that;
7142  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
7143  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
7144  reinterpret_cast<internal::Isolate*>(isolate), *p)));
7145 }
7146 
7147 
7148 template<class T>
7149 template<class S>
7150 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
7151  TYPE_CHECK(T, S);
7152  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_);
7153 }
7154 
7155 
7156 template<class T>
7157 Local<T> Eternal<T>::Get(Isolate* isolate) {
7158  return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_)));
7159 }
7160 
7161 
7162 template <class T>
7164  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
7165  return Local<T>(val_);
7166 }
7167 
7168 
7169 template <class T>
7170 void* WeakCallbackInfo<T>::GetInternalField(int index) const {
7171 #ifdef V8_ENABLE_CHECKS
7172  if (index < 0 || index >= kInternalFieldsInWeakCallback) {
7173  V8::InternalFieldOutOfBounds(index);
7174  }
7175 #endif
7176  return internal_fields_[index];
7177 }
7178 
7179 
7180 template <class T>
7181 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
7182  if (that == NULL) return NULL;
7183  internal::Object** p = reinterpret_cast<internal::Object**>(that);
7184  return reinterpret_cast<T*>(
7185  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
7186  p));
7187 }
7188 
7189 
7190 template <class T, class M>
7191 template <class S, class M2>
7192 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
7193  TYPE_CHECK(T, S);
7194  this->Reset();
7195  if (that.IsEmpty()) return;
7196  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
7197  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
7198  M::Copy(that, this);
7199 }
7200 
7201 
7202 template <class T>
7203 bool PersistentBase<T>::IsIndependent() const {
7204  typedef internal::Internals I;
7205  if (this->IsEmpty()) return false;
7206  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7207  I::kNodeIsIndependentShift);
7208 }
7209 
7210 
7211 template <class T>
7213  typedef internal::Internals I;
7214  if (this->IsEmpty()) return false;
7215  uint8_t node_state =
7216  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
7217  return node_state == I::kNodeStateIsNearDeathValue ||
7218  node_state == I::kNodeStateIsPendingValue;
7219 }
7220 
7221 
7222 template <class T>
7224  typedef internal::Internals I;
7225  if (this->IsEmpty()) return false;
7226  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
7227  I::kNodeStateIsWeakValue;
7228 }
7229 
7230 
7231 template <class T>
7233  if (this->IsEmpty()) return;
7234  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
7235  val_ = 0;
7236 }
7237 
7238 
7239 template <class T>
7240 template <class S>
7241 void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
7242  TYPE_CHECK(T, S);
7243  Reset();
7244  if (other.IsEmpty()) return;
7245  this->val_ = New(isolate, other.val_);
7246 }
7247 
7248 
7249 template <class T>
7250 template <class S>
7251 void PersistentBase<T>::Reset(Isolate* isolate,
7252  const PersistentBase<S>& other) {
7253  TYPE_CHECK(T, S);
7254  Reset();
7255  if (other.IsEmpty()) return;
7256  this->val_ = New(isolate, other.val_);
7257 }
7258 
7259 
7260 template <class T>
7261 template <typename S, typename P>
7263  P* parameter,
7264  typename WeakCallbackData<S, P>::Callback callback) {
7265  TYPE_CHECK(S, T);
7266  typedef typename WeakCallbackData<Value, void>::Callback Callback;
7267  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7268  reinterpret_cast<Callback>(callback));
7269 }
7270 
7271 
7272 template <class T>
7273 template <typename P>
7275  P* parameter,
7276  typename WeakCallbackData<T, P>::Callback callback) {
7277  SetWeak<T, P>(parameter, callback);
7278 }
7279 
7280 
7281 template <class T>
7282 template <typename P>
7284  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
7285  int internal_field_index1, int internal_field_index2) {
7286  typedef typename WeakCallbackInfo<void>::Callback Callback;
7287  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7288  internal_field_index1, internal_field_index2,
7289  reinterpret_cast<Callback>(callback));
7290 }
7291 
7292 
7293 template <class T>
7294 template <typename P>
7295 V8_INLINE void PersistentBase<T>::SetWeak(
7296  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
7297  WeakCallbackType type) {
7298  typedef typename WeakCallbackInfo<void>::Callback Callback;
7299  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7300  reinterpret_cast<Callback>(callback), type);
7301 }
7302 
7303 
7304 template <class T>
7305 template <typename P>
7307  return reinterpret_cast<P*>(
7308  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
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::kNodeIsIndependentShift);
7319 }
7320 
7321 
7322 template <class T>
7324  typedef internal::Internals I;
7325  if (this->IsEmpty()) return;
7326  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7327  true,
7328  I::kNodeIsPartiallyDependentShift);
7329 }
7330 
7331 
7332 template <class T>
7333 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
7334  typedef internal::Internals I;
7335  if (this->IsEmpty()) return;
7336  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
7337  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
7338  *reinterpret_cast<uint16_t*>(addr) = class_id;
7339 }
7340 
7341 
7342 template <class T>
7344  typedef internal::Internals I;
7345  if (this->IsEmpty()) return 0;
7346  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
7347  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
7348  return *reinterpret_cast<uint16_t*>(addr);
7349 }
7350 
7351 
7352 template<typename T>
7353 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
7354 
7355 template<typename T>
7356 template<typename S>
7357 void ReturnValue<T>::Set(const Persistent<S>& handle) {
7358  TYPE_CHECK(T, S);
7359  if (V8_UNLIKELY(handle.IsEmpty())) {
7360  *value_ = GetDefaultValue();
7361  } else {
7362  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7363  }
7364 }
7365 
7366 template <typename T>
7367 template <typename S>
7368 void ReturnValue<T>::Set(const Global<S>& handle) {
7369  TYPE_CHECK(T, S);
7370  if (V8_UNLIKELY(handle.IsEmpty())) {
7371  *value_ = GetDefaultValue();
7372  } else {
7373  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7374  }
7375 }
7376 
7377 template <typename T>
7378 template <typename S>
7379 void ReturnValue<T>::Set(const Local<S> handle) {
7380  TYPE_CHECK(T, S);
7381  if (V8_UNLIKELY(handle.IsEmpty())) {
7382  *value_ = GetDefaultValue();
7383  } else {
7384  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7385  }
7386 }
7387 
7388 template<typename T>
7389 void ReturnValue<T>::Set(double i) {
7390  TYPE_CHECK(T, Number);
7391  Set(Number::New(GetIsolate(), i));
7392 }
7393 
7394 template<typename T>
7395 void ReturnValue<T>::Set(int32_t i) {
7396  TYPE_CHECK(T, Integer);
7397  typedef internal::Internals I;
7398  if (V8_LIKELY(I::IsValidSmi(i))) {
7399  *value_ = I::IntToSmi(i);
7400  return;
7401  }
7402  Set(Integer::New(GetIsolate(), i));
7403 }
7404 
7405 template<typename T>
7406 void ReturnValue<T>::Set(uint32_t i) {
7407  TYPE_CHECK(T, Integer);
7408  // Can't simply use INT32_MAX here for whatever reason.
7409  bool fits_into_int32_t = (i & (1U << 31)) == 0;
7410  if (V8_LIKELY(fits_into_int32_t)) {
7411  Set(static_cast<int32_t>(i));
7412  return;
7413  }
7414  Set(Integer::NewFromUnsigned(GetIsolate(), i));
7415 }
7416 
7417 template<typename T>
7418 void ReturnValue<T>::Set(bool value) {
7419  TYPE_CHECK(T, Boolean);
7420  typedef internal::Internals I;
7421  int root_index;
7422  if (value) {
7423  root_index = I::kTrueValueRootIndex;
7424  } else {
7425  root_index = I::kFalseValueRootIndex;
7426  }
7427  *value_ = *I::GetRoot(GetIsolate(), root_index);
7428 }
7429 
7430 template<typename T>
7431 void ReturnValue<T>::SetNull() {
7432  TYPE_CHECK(T, Primitive);
7433  typedef internal::Internals I;
7434  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
7435 }
7436 
7437 template<typename T>
7439  TYPE_CHECK(T, Primitive);
7440  typedef internal::Internals I;
7441  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
7442 }
7443 
7444 template<typename T>
7446  TYPE_CHECK(T, String);
7447  typedef internal::Internals I;
7448  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
7449 }
7450 
7451 template<typename T>
7453  // Isolate is always the pointer below the default value on the stack.
7454  return *reinterpret_cast<Isolate**>(&value_[-2]);
7455 }
7456 
7457 template<typename T>
7458 template<typename S>
7459 void ReturnValue<T>::Set(S* whatever) {
7460  // Uncompilable to prevent inadvertent misuse.
7461  TYPE_CHECK(S*, Primitive);
7462 }
7463 
7464 template<typename T>
7465 internal::Object* ReturnValue<T>::GetDefaultValue() {
7466  // Default value is always the pointer below value_ on the stack.
7467  return value_[-1];
7468 }
7469 
7470 
7471 template<typename T>
7472 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
7473  internal::Object** values,
7474  int length,
7475  bool is_construct_call)
7476  : implicit_args_(implicit_args),
7477  values_(values),
7478  length_(length),
7479  is_construct_call_(is_construct_call) { }
7480 
7481 
7482 template<typename T>
7484  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
7485  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
7486 }
7487 
7488 
7489 template<typename T>
7491  return Local<Function>(reinterpret_cast<Function*>(
7492  &implicit_args_[kCalleeIndex]));
7493 }
7494 
7495 
7496 template<typename T>
7498  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
7499 }
7500 
7501 
7502 template<typename T>
7504  return Local<Object>(reinterpret_cast<Object*>(
7505  &implicit_args_[kHolderIndex]));
7506 }
7507 
7508 
7509 template<typename T>
7511  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
7512 }
7513 
7514 
7515 template<typename T>
7517  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
7518 }
7519 
7520 
7521 template<typename T>
7523  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
7524 }
7525 
7526 
7527 template<typename T>
7529  return is_construct_call_ & 0x1;
7530 }
7531 
7532 
7533 template<typename T>
7534 int FunctionCallbackInfo<T>::Length() const {
7535  return length_;
7536 }
7537 
7538 ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
7539  Local<Integer> resource_line_offset,
7540  Local<Integer> resource_column_offset,
7541  Local<Boolean> resource_is_shared_cross_origin,
7542  Local<Integer> script_id,
7543  Local<Boolean> resource_is_embedder_debug_script,
7544  Local<Value> source_map_url,
7545  Local<Boolean> resource_is_opaque)
7546  : resource_name_(resource_name),
7547  resource_line_offset_(resource_line_offset),
7548  resource_column_offset_(resource_column_offset),
7549  options_(!resource_is_embedder_debug_script.IsEmpty() &&
7550  resource_is_embedder_debug_script->IsTrue(),
7551  !resource_is_shared_cross_origin.IsEmpty() &&
7552  resource_is_shared_cross_origin->IsTrue(),
7553  !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue()),
7554  script_id_(script_id),
7555  source_map_url_(source_map_url) {}
7556 
7557 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
7558 
7559 
7560 Local<Integer> ScriptOrigin::ResourceLineOffset() const {
7561  return resource_line_offset_;
7562 }
7563 
7564 
7565 Local<Integer> ScriptOrigin::ResourceColumnOffset() const {
7566  return resource_column_offset_;
7567 }
7568 
7569 
7570 Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
7571 
7572 
7573 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
7574 
7575 
7576 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
7577  CachedData* data)
7578  : source_string(string),
7579  resource_name(origin.ResourceName()),
7580  resource_line_offset(origin.ResourceLineOffset()),
7581  resource_column_offset(origin.ResourceColumnOffset()),
7582  resource_options(origin.Options()),
7583  source_map_url(origin.SourceMapUrl()),
7584  cached_data(data) {}
7585 
7586 
7587 ScriptCompiler::Source::Source(Local<String> string,
7588  CachedData* data)
7589  : source_string(string), cached_data(data) {}
7590 
7591 
7592 ScriptCompiler::Source::~Source() {
7593  delete cached_data;
7594 }
7595 
7596 
7597 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
7598  const {
7599  return cached_data;
7600 }
7601 
7602 
7603 Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
7604  return value ? True(isolate) : False(isolate);
7605 }
7606 
7607 
7608 void Template::Set(Isolate* isolate, const char* name, v8::Local<Data> value) {
7609  Set(v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal)
7610  .ToLocalChecked(),
7611  value);
7612 }
7613 
7614 
7616 #ifndef V8_ENABLE_CHECKS
7617  typedef internal::Object O;
7618  typedef internal::HeapObject HO;
7619  typedef internal::Internals I;
7620  O* obj = *reinterpret_cast<O**>(this);
7621  // Fast path: If the object is a plain JSObject, which is the common case, we
7622  // know where to find the internal fields and can return the value directly.
7623  if (I::GetInstanceType(obj) == I::kJSObjectType) {
7624  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
7625  O* value = I::ReadField<O*>(obj, offset);
7626  O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
7627  return Local<Value>(reinterpret_cast<Value*>(result));
7628  }
7629 #endif
7630  return SlowGetInternalField(index);
7631 }
7632 
7633 
7635 #ifndef V8_ENABLE_CHECKS
7636  typedef internal::Object O;
7637  typedef internal::Internals I;
7638  O* obj = *reinterpret_cast<O**>(this);
7639  // Fast path: If the object is a plain JSObject, which is the common case, we
7640  // know where to find the internal fields and can return the value directly.
7641  if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) {
7642  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
7643  return I::ReadField<void*>(obj, offset);
7644  }
7645 #endif
7646  return SlowGetAlignedPointerFromInternalField(index);
7647 }
7648 
7649 
7650 String* String::Cast(v8::Value* value) {
7651 #ifdef V8_ENABLE_CHECKS
7652  CheckCast(value);
7653 #endif
7654  return static_cast<String*>(value);
7655 }
7656 
7657 
7659  typedef internal::Object* S;
7660  typedef internal::Internals I;
7661  I::CheckInitialized(isolate);
7662  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
7663  return Local<String>(reinterpret_cast<String*>(slot));
7664 }
7665 
7666 
7668  typedef internal::Object O;
7669  typedef internal::Internals I;
7670  O* obj = *reinterpret_cast<O* const*>(this);
7672  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
7673  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
7674  result = reinterpret_cast<String::ExternalStringResource*>(value);
7675  } else {
7676  result = NULL;
7677  }
7678 #ifdef V8_ENABLE_CHECKS
7679  VerifyExternalStringResource(result);
7680 #endif
7681  return result;
7682 }
7683 
7684 
7686  String::Encoding* encoding_out) const {
7687  typedef internal::Object O;
7688  typedef internal::Internals I;
7689  O* obj = *reinterpret_cast<O* const*>(this);
7690  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
7691  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
7692  ExternalStringResourceBase* resource = NULL;
7693  if (type == I::kExternalOneByteRepresentationTag ||
7694  type == I::kExternalTwoByteRepresentationTag) {
7695  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
7696  resource = static_cast<ExternalStringResourceBase*>(value);
7697  }
7698 #ifdef V8_ENABLE_CHECKS
7699  VerifyExternalStringResourceBase(resource, *encoding_out);
7700 #endif
7701  return resource;
7702 }
7703 
7704 
7705 bool Value::IsUndefined() const {
7706 #ifdef V8_ENABLE_CHECKS
7707  return FullIsUndefined();
7708 #else
7709  return QuickIsUndefined();
7710 #endif
7711 }
7712 
7713 bool Value::QuickIsUndefined() const {
7714  typedef internal::Object O;
7715  typedef internal::Internals I;
7716  O* obj = *reinterpret_cast<O* const*>(this);
7717  if (!I::HasHeapObjectTag(obj)) return false;
7718  if (I::GetInstanceType(obj) != I::kOddballType) return false;
7719  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
7720 }
7721 
7722 
7723 bool Value::IsNull() const {
7724 #ifdef V8_ENABLE_CHECKS
7725  return FullIsNull();
7726 #else
7727  return QuickIsNull();
7728 #endif
7729 }
7730 
7731 bool Value::QuickIsNull() const {
7732  typedef internal::Object O;
7733  typedef internal::Internals I;
7734  O* obj = *reinterpret_cast<O* const*>(this);
7735  if (!I::HasHeapObjectTag(obj)) return false;
7736  if (I::GetInstanceType(obj) != I::kOddballType) return false;
7737  return (I::GetOddballKind(obj) == I::kNullOddballKind);
7738 }
7739 
7740 
7741 bool Value::IsString() const {
7742 #ifdef V8_ENABLE_CHECKS
7743  return FullIsString();
7744 #else
7745  return QuickIsString();
7746 #endif
7747 }
7748 
7749 bool Value::QuickIsString() const {
7750  typedef internal::Object O;
7751  typedef internal::Internals I;
7752  O* obj = *reinterpret_cast<O* const*>(this);
7753  if (!I::HasHeapObjectTag(obj)) return false;
7754  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
7755 }
7756 
7757 
7758 template <class T> Value* Value::Cast(T* value) {
7759  return static_cast<Value*>(value);
7760 }
7761 
7762 
7763 Local<Boolean> Value::ToBoolean() const {
7764  return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
7765  .FromMaybe(Local<Boolean>());
7766 }
7767 
7768 
7769 Local<Number> Value::ToNumber() const {
7770  return ToNumber(Isolate::GetCurrent()->GetCurrentContext())
7771  .FromMaybe(Local<Number>());
7772 }
7773 
7774 
7775 Local<String> Value::ToString() const {
7776  return ToString(Isolate::GetCurrent()->GetCurrentContext())
7777  .FromMaybe(Local<String>());
7778 }
7779 
7780 
7781 Local<String> Value::ToDetailString() const {
7782  return ToDetailString(Isolate::GetCurrent()->GetCurrentContext())
7783  .FromMaybe(Local<String>());
7784 }
7785 
7786 
7787 Local<Object> Value::ToObject() const {
7788  return ToObject(Isolate::GetCurrent()->GetCurrentContext())
7789  .FromMaybe(Local<Object>());
7790 }
7791 
7792 
7793 Local<Integer> Value::ToInteger() const {
7794  return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
7795  .FromMaybe(Local<Integer>());
7796 }
7797 
7798 
7799 Local<Uint32> Value::ToUint32() const {
7800  return ToUint32(Isolate::GetCurrent()->GetCurrentContext())
7801  .FromMaybe(Local<Uint32>());
7802 }
7803 
7804 
7805 Local<Int32> Value::ToInt32() const {
7806  return ToInt32(Isolate::GetCurrent()->GetCurrentContext())
7807  .FromMaybe(Local<Int32>());
7808 }
7809 
7810 
7811 Boolean* Boolean::Cast(v8::Value* value) {
7812 #ifdef V8_ENABLE_CHECKS
7813  CheckCast(value);
7814 #endif
7815  return static_cast<Boolean*>(value);
7816 }
7817 
7818 
7819 Name* Name::Cast(v8::Value* value) {
7820 #ifdef V8_ENABLE_CHECKS
7821  CheckCast(value);
7822 #endif
7823  return static_cast<Name*>(value);
7824 }
7825 
7826 
7827 Symbol* Symbol::Cast(v8::Value* value) {
7828 #ifdef V8_ENABLE_CHECKS
7829  CheckCast(value);
7830 #endif
7831  return static_cast<Symbol*>(value);
7832 }
7833 
7834 
7835 Number* Number::Cast(v8::Value* value) {
7836 #ifdef V8_ENABLE_CHECKS
7837  CheckCast(value);
7838 #endif
7839  return static_cast<Number*>(value);
7840 }
7841 
7842 
7843 Integer* Integer::Cast(v8::Value* value) {
7844 #ifdef V8_ENABLE_CHECKS
7845  CheckCast(value);
7846 #endif
7847  return static_cast<Integer*>(value);
7848 }
7849 
7850 
7851 Int32* Int32::Cast(v8::Value* value) {
7852 #ifdef V8_ENABLE_CHECKS
7853  CheckCast(value);
7854 #endif
7855  return static_cast<Int32*>(value);
7856 }
7857 
7858 
7859 Uint32* Uint32::Cast(v8::Value* value) {
7860 #ifdef V8_ENABLE_CHECKS
7861  CheckCast(value);
7862 #endif
7863  return static_cast<Uint32*>(value);
7864 }
7865 
7866 
7867 Date* Date::Cast(v8::Value* value) {
7868 #ifdef V8_ENABLE_CHECKS
7869  CheckCast(value);
7870 #endif
7871  return static_cast<Date*>(value);
7872 }
7873 
7874 
7875 StringObject* StringObject::Cast(v8::Value* value) {
7876 #ifdef V8_ENABLE_CHECKS
7877  CheckCast(value);
7878 #endif
7879  return static_cast<StringObject*>(value);
7880 }
7881 
7882 
7883 SymbolObject* SymbolObject::Cast(v8::Value* value) {
7884 #ifdef V8_ENABLE_CHECKS
7885  CheckCast(value);
7886 #endif
7887  return static_cast<SymbolObject*>(value);
7888 }
7889 
7890 
7891 NumberObject* NumberObject::Cast(v8::Value* value) {
7892 #ifdef V8_ENABLE_CHECKS
7893  CheckCast(value);
7894 #endif
7895  return static_cast<NumberObject*>(value);
7896 }
7897 
7898 
7899 BooleanObject* BooleanObject::Cast(v8::Value* value) {
7900 #ifdef V8_ENABLE_CHECKS
7901  CheckCast(value);
7902 #endif
7903  return static_cast<BooleanObject*>(value);
7904 }
7905 
7906 
7907 RegExp* RegExp::Cast(v8::Value* value) {
7908 #ifdef V8_ENABLE_CHECKS
7909  CheckCast(value);
7910 #endif
7911  return static_cast<RegExp*>(value);
7912 }
7913 
7914 
7915 Object* Object::Cast(v8::Value* value) {
7916 #ifdef V8_ENABLE_CHECKS
7917  CheckCast(value);
7918 #endif
7919  return static_cast<Object*>(value);
7920 }
7921 
7922 
7923 Array* Array::Cast(v8::Value* value) {
7924 #ifdef V8_ENABLE_CHECKS
7925  CheckCast(value);
7926 #endif
7927  return static_cast<Array*>(value);
7928 }
7929 
7930 
7931 Map* Map::Cast(v8::Value* value) {
7932 #ifdef V8_ENABLE_CHECKS
7933  CheckCast(value);
7934 #endif
7935  return static_cast<Map*>(value);
7936 }
7937 
7938 
7939 Set* Set::Cast(v8::Value* value) {
7940 #ifdef V8_ENABLE_CHECKS
7941  CheckCast(value);
7942 #endif
7943  return static_cast<Set*>(value);
7944 }
7945 
7946 
7947 Promise* Promise::Cast(v8::Value* value) {
7948 #ifdef V8_ENABLE_CHECKS
7949  CheckCast(value);
7950 #endif
7951  return static_cast<Promise*>(value);
7952 }
7953 
7954 
7955 Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
7956 #ifdef V8_ENABLE_CHECKS
7957  CheckCast(value);
7958 #endif
7959  return static_cast<Promise::Resolver*>(value);
7960 }
7961 
7962 
7963 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
7964 #ifdef V8_ENABLE_CHECKS
7965  CheckCast(value);
7966 #endif
7967  return static_cast<ArrayBuffer*>(value);
7968 }
7969 
7970 
7971 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
7972 #ifdef V8_ENABLE_CHECKS
7973  CheckCast(value);
7974 #endif
7975  return static_cast<ArrayBufferView*>(value);
7976 }
7977 
7978 
7979 TypedArray* TypedArray::Cast(v8::Value* value) {
7980 #ifdef V8_ENABLE_CHECKS
7981  CheckCast(value);
7982 #endif
7983  return static_cast<TypedArray*>(value);
7984 }
7985 
7986 
7987 Uint8Array* Uint8Array::Cast(v8::Value* value) {
7988 #ifdef V8_ENABLE_CHECKS
7989  CheckCast(value);
7990 #endif
7991  return static_cast<Uint8Array*>(value);
7992 }
7993 
7994 
7995 Int8Array* Int8Array::Cast(v8::Value* value) {
7996 #ifdef V8_ENABLE_CHECKS
7997  CheckCast(value);
7998 #endif
7999  return static_cast<Int8Array*>(value);
8000 }
8001 
8002 
8003 Uint16Array* Uint16Array::Cast(v8::Value* value) {
8004 #ifdef V8_ENABLE_CHECKS
8005  CheckCast(value);
8006 #endif
8007  return static_cast<Uint16Array*>(value);
8008 }
8009 
8010 
8011 Int16Array* Int16Array::Cast(v8::Value* value) {
8012 #ifdef V8_ENABLE_CHECKS
8013  CheckCast(value);
8014 #endif
8015  return static_cast<Int16Array*>(value);
8016 }
8017 
8018 
8019 Uint32Array* Uint32Array::Cast(v8::Value* value) {
8020 #ifdef V8_ENABLE_CHECKS
8021  CheckCast(value);
8022 #endif
8023  return static_cast<Uint32Array*>(value);
8024 }
8025 
8026 
8027 Int32Array* Int32Array::Cast(v8::Value* value) {
8028 #ifdef V8_ENABLE_CHECKS
8029  CheckCast(value);
8030 #endif
8031  return static_cast<Int32Array*>(value);
8032 }
8033 
8034 
8035 Float32Array* Float32Array::Cast(v8::Value* value) {
8036 #ifdef V8_ENABLE_CHECKS
8037  CheckCast(value);
8038 #endif
8039  return static_cast<Float32Array*>(value);
8040 }
8041 
8042 
8043 Float64Array* Float64Array::Cast(v8::Value* value) {
8044 #ifdef V8_ENABLE_CHECKS
8045  CheckCast(value);
8046 #endif
8047  return static_cast<Float64Array*>(value);
8048 }
8049 
8050 
8051 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
8052 #ifdef V8_ENABLE_CHECKS
8053  CheckCast(value);
8054 #endif
8055  return static_cast<Uint8ClampedArray*>(value);
8056 }
8057 
8058 
8059 DataView* DataView::Cast(v8::Value* value) {
8060 #ifdef V8_ENABLE_CHECKS
8061  CheckCast(value);
8062 #endif
8063  return static_cast<DataView*>(value);
8064 }
8065 
8066 
8067 SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
8068 #ifdef V8_ENABLE_CHECKS
8069  CheckCast(value);
8070 #endif
8071  return static_cast<SharedArrayBuffer*>(value);
8072 }
8073 
8074 
8075 Function* Function::Cast(v8::Value* value) {
8076 #ifdef V8_ENABLE_CHECKS
8077  CheckCast(value);
8078 #endif
8079  return static_cast<Function*>(value);
8080 }
8081 
8082 
8083 External* External::Cast(v8::Value* value) {
8084 #ifdef V8_ENABLE_CHECKS
8085  CheckCast(value);
8086 #endif
8087  return static_cast<External*>(value);
8088 }
8089 
8090 
8091 template<typename T>
8093  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
8094 }
8095 
8096 
8097 template<typename T>
8099  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
8100 }
8101 
8102 
8103 template<typename T>
8105  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
8106 }
8107 
8108 
8109 template<typename T>
8111  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
8112 }
8113 
8114 
8115 template<typename T>
8117  return ReturnValue<T>(&args_[kReturnValueIndex]);
8118 }
8119 
8120 
8121 Local<Primitive> Undefined(Isolate* isolate) {
8122  typedef internal::Object* S;
8123  typedef internal::Internals I;
8124  I::CheckInitialized(isolate);
8125  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
8126  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
8127 }
8128 
8129 
8130 Local<Primitive> Null(Isolate* isolate) {
8131  typedef internal::Object* S;
8132  typedef internal::Internals I;
8133  I::CheckInitialized(isolate);
8134  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
8135  return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
8136 }
8137 
8138 
8139 Local<Boolean> True(Isolate* isolate) {
8140  typedef internal::Object* S;
8141  typedef internal::Internals I;
8142  I::CheckInitialized(isolate);
8143  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
8144  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
8145 }
8146 
8147 
8148 Local<Boolean> False(Isolate* isolate) {
8149  typedef internal::Object* S;
8150  typedef internal::Internals I;
8151  I::CheckInitialized(isolate);
8152  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
8153  return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
8154 }
8155 
8156 
8157 void Isolate::SetData(uint32_t slot, void* data) {
8158  typedef internal::Internals I;
8159  I::SetEmbedderData(this, slot, data);
8160 }
8161 
8162 
8163 void* Isolate::GetData(uint32_t slot) {
8164  typedef internal::Internals I;
8165  return I::GetEmbedderData(this, slot);
8166 }
8167 
8168 
8170  typedef internal::Internals I;
8171  return I::kNumIsolateDataSlots;
8172 }
8173 
8174 
8176  int64_t change_in_bytes) {
8177  typedef internal::Internals I;
8178  int64_t* amount_of_external_allocated_memory =
8179  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
8180  I::kAmountOfExternalAllocatedMemoryOffset);
8181  int64_t* amount_of_external_allocated_memory_at_last_global_gc =
8182  reinterpret_cast<int64_t*>(
8183  reinterpret_cast<uint8_t*>(this) +
8184  I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
8185  int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
8186  if (change_in_bytes > 0 &&
8187  amount - *amount_of_external_allocated_memory_at_last_global_gc >
8188  I::kExternalAllocationLimit) {
8189  CollectAllGarbage("external memory allocation limit reached.");
8190  }
8191  *amount_of_external_allocated_memory = amount;
8192  return *amount_of_external_allocated_memory;
8193 }
8194 
8195 
8196 template<typename T>
8198  UniqueId id) {
8199  TYPE_CHECK(Value, T);
8200  SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id);
8201 }
8202 
8203 
8204 template<typename T>
8206  const Persistent<T>& object) {
8207  TYPE_CHECK(Value, T);
8208  SetReferenceFromGroup(id,
8209  reinterpret_cast<v8::internal::Object**>(object.val_));
8210 }
8211 
8212 
8213 template<typename T, typename S>
8215  const Persistent<S>& child) {
8216  TYPE_CHECK(Object, T);
8217  TYPE_CHECK(Value, S);
8218  SetReference(reinterpret_cast<v8::internal::Object**>(parent.val_),
8219  reinterpret_cast<v8::internal::Object**>(child.val_));
8220 }
8221 
8222 
8224 #ifndef V8_ENABLE_CHECKS
8225  typedef internal::Object O;
8226  typedef internal::HeapObject HO;
8227  typedef internal::Internals I;
8228  HO* context = *reinterpret_cast<HO**>(this);
8229  O** result =
8230  HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
8231  return Local<Value>(reinterpret_cast<Value*>(result));
8232 #else
8233  return SlowGetEmbedderData(index);
8234 #endif
8235 }
8236 
8237 
8239 #ifndef V8_ENABLE_CHECKS
8240  typedef internal::Internals I;
8241  return I::ReadEmbedderData<void*>(this, index);
8242 #else
8243  return SlowGetAlignedPointerFromEmbedderData(index);
8244 #endif
8245 }
8246 
8247 
8248 void V8::SetAllowCodeGenerationFromStringsCallback(
8250  Isolate* isolate = Isolate::GetCurrent();
8251  isolate->SetAllowCodeGenerationFromStringsCallback(callback);
8252 }
8253 
8254 
8255 bool V8::IsDead() {
8256  Isolate* isolate = Isolate::GetCurrent();
8257  return isolate->IsDead();
8258 }
8259 
8260 
8261 bool V8::AddMessageListener(MessageCallback that, Local<Value> data) {
8262  Isolate* isolate = Isolate::GetCurrent();
8263  return isolate->AddMessageListener(that, data);
8264 }
8265 
8266 
8267 void V8::RemoveMessageListeners(MessageCallback that) {
8268  Isolate* isolate = Isolate::GetCurrent();
8269  isolate->RemoveMessageListeners(that);
8270 }
8271 
8272 
8273 void V8::SetFailedAccessCheckCallbackFunction(
8274  FailedAccessCheckCallback callback) {
8275  Isolate* isolate = Isolate::GetCurrent();
8276  isolate->SetFailedAccessCheckCallbackFunction(callback);
8277 }
8278 
8279 
8280 void V8::SetCaptureStackTraceForUncaughtExceptions(
8281  bool capture, int frame_limit, StackTrace::StackTraceOptions options) {
8282  Isolate* isolate = Isolate::GetCurrent();
8283  isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit,
8284  options);
8285 }
8286 
8287 
8288 void V8::SetFatalErrorHandler(FatalErrorCallback callback) {
8289  Isolate* isolate = Isolate::GetCurrent();
8290  isolate->SetFatalErrorHandler(callback);
8291 }
8292 
8293 
8294 void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) {
8295  Isolate* isolate = Isolate::GetCurrent();
8296  isolate->RemoveGCPrologueCallback(
8297  reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback));
8298 }
8299 
8300 
8301 void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) {
8302  Isolate* isolate = Isolate::GetCurrent();
8303  isolate->RemoveGCEpilogueCallback(
8304  reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback));
8305 }
8306 
8307 
8308 void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback,
8309  ObjectSpace space,
8310  AllocationAction action) {
8311  Isolate* isolate = Isolate::GetCurrent();
8312  isolate->AddMemoryAllocationCallback(callback, space, action);
8313 }
8314 
8315 
8316 void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) {
8317  Isolate* isolate = Isolate::GetCurrent();
8318  isolate->RemoveMemoryAllocationCallback(callback);
8319 }
8320 
8321 
8322 void V8::TerminateExecution(Isolate* isolate) { isolate->TerminateExecution(); }
8323 
8324 
8325 bool V8::IsExecutionTerminating(Isolate* isolate) {
8326  if (isolate == NULL) {
8327  isolate = Isolate::GetCurrent();
8328  }
8329  return isolate->IsExecutionTerminating();
8330 }
8331 
8332 
8333 void V8::CancelTerminateExecution(Isolate* isolate) {
8334  isolate->CancelTerminateExecution();
8335 }
8336 
8337 
8338 void V8::VisitExternalResources(ExternalResourceVisitor* visitor) {
8339  Isolate* isolate = Isolate::GetCurrent();
8340  isolate->VisitExternalResources(visitor);
8341 }
8342 
8343 
8344 void V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
8345  Isolate* isolate = Isolate::GetCurrent();
8346  isolate->VisitHandlesWithClassIds(visitor);
8347 }
8348 
8349 
8350 void V8::VisitHandlesWithClassIds(Isolate* isolate,
8351  PersistentHandleVisitor* visitor) {
8352  isolate->VisitHandlesWithClassIds(visitor);
8353 }
8354 
8355 
8356 void V8::VisitHandlesForPartialDependence(Isolate* isolate,
8357  PersistentHandleVisitor* visitor) {
8358  isolate->VisitHandlesForPartialDependence(visitor);
8359 }
8360 
8373 } // namespace v8
8374 
8375 
8376 #undef TYPE_CHECK
8377 
8378 
8379 #endif // V8_H_
Definition: v8.h:2483
Definition: v8.h:3586
Definition: v8.h:1084
void VisitHandlesWithClassIds(PersistentHandleVisitor *visitor)
void(* NamedPropertyDeleterCallback)(Local< String > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:4115
UseCounterFeature
Definition: v8.h:5346
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:4477
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:4206
void SetReferenceFromGroup(UniqueId id, const Persistent< T > &child)
Definition: v8.h:8205
Definition: v8.h:3694
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:7343
Definition: v8.h:1051
V8_INLINE bool IsWeak() const
Definition: v8.h:7223
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
Definition: v8.h:4245
void(* NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:4124
void SetReference(const Persistent< T > &parent, const Persistent< S > &child)
Definition: v8.h:8214
WriteOptions
Definition: v8.h:2139
static Isolate * GetCurrent()
Definition: v8.h:118
Definition: v8.h:5044
Definition: v8.h:3640
V8_INLINE void Clear()
Definition: v8.h:232
void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
virtual ~ExternalStringResource()
Definition: v8.h:2217
Definition: v8.h:6824
GarbageCollectionType
Definition: v8.h:5336
V8_INLINE Local< T > Escape(Local< T > value)
Definition: v8.h:932
V8_INLINE void MarkPartiallyDependent()
Definition: v8.h:7323
Definition: v8.h:1017
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
Definition: v8.h:2767
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
Definition: v8.h:807
Definition: v8.h:3273
void SetFatalErrorHandler(FatalErrorCallback that)
Definition: v8.h:3730
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Definition: v8.h:2786
void(* GenericNamedPropertyDeleterCallback)(Local< Name > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:4161
void(* NamedPropertySetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4094
Definition: v8.h:6960
EmbedderDataFields
Definition: v8.h:6657
virtual ~ExternalOneByteStringResource()
Definition: v8.h:2250
Definition: v8.h:4926
Definition: v8.h:85
Definition: v8.h:3748
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:2549
Definition: v8.h:2058
Definition: v8.h:6891
Definition: v8.h:1686
Definition: v8.h:2044
Definition: v8-util.h:159
Definition: v8.h:1513
Definition: v8.h:3398
Definition: v8.h:1124
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
Definition: v8.h:704
bool IsDead()
Definition: v8.h:6578
void VisitExternalResources(ExternalResourceVisitor *visitor)
Definition: v8.h:136
Definition: v8.h:4673
Definition: v8.h:5122
JitCodeEventOptions
Definition: v8.h:5146
Definition: v8.h:2081
Definition: v8-platform.h:28
bool(* EntropySource)(unsigned char *buffer, size_t length)
Definition: v8.h:5949
Definition: v8.h:1168
Definition: v8.h:1631
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, v8::NewStringType type, int length=-1)
Definition: v8.h:5001
Definition: v8.h:3604
Definition: v8.h:109
V8_INLINE void * GetAlignedPointerFromEmbedderData(int index)
Definition: v8.h:8238
V8_INLINE Global()
Definition: v8.h:790
V8_INLINE Unlocker(Isolate *isolate)
Definition: v8.h:6829
V8_INLINE Persistent(const Persistent &that)
Definition: v8.h:724
Definition: v8.h:2037
Definition: v8.h:5195
void AddMemoryAllocationCallback(MemoryAllocationCallback callback, ObjectSpace space, AllocationAction action)
CreateHistogramCallback create_histogram_callback
Definition: v8.h:5243
void(* GenericNamedPropertyQueryCallback)(Local< Name > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:4152
Definition: v8.h:2948
V8_INLINE Local< Integer > ScriptID() const
Definition: v8.h:7570
Definition: v8.h:5084
void(* GenericNamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:4169
size_t length() const
Definition: v8.h:4723
Definition: v8.h:449
void VisitHandlesForPartialDependence(PersistentHandleVisitor *visitor)
Definition: v8.h:1565
StartupData * snapshot_blob
Definition: v8.h:5228
Definition: v8.h:5258
void SetAllowCodeGenerationFromStringsCallback(AllowCodeGenerationFromStringsCallback callback)
Definition: v8-debug.h:13
Definition: v8.h:869
Definition: v8.h:4346
Definition: v8.h:112
Definition: v8.h:1670
Definition: v8.h:5164
Definition: v8.h:3357
V8_INLINE Global & operator=(Global< S > &&rhs)
Definition: v8.h:822
Definition: v8.h:5114
CounterLookupCallback counter_lookup_callback
Definition: v8.h:5235
AccessType
Definition: v8.h:4222
static void * JSStackComparableAddress(v8::TryCatch *handler)
Definition: v8.h:6524
Definition: v8-util.h:417
void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback)
Definition: v8.h:2418
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4177
V8_INLINE Local< Value > GetEmbedderData(int index)
Definition: v8.h:8223
Definition: v8.h:3181
void(* NamedPropertyGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4085
Definition: v8.h:404
FunctionEntryHook entry_hook
Definition: v8.h:5212
Definition: v8.h:4861
V8_INLINE Persistent()
Definition: v8.h:697
void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback)
void SetCaptureStackTraceForUncaughtExceptions(bool capture, int frame_limit=10, StackTrace::StackTraceOptions options=StackTrace::kOverview)
Definition: v8.h:116
Definition: v8.h:3622
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4186
Definition: v8.h:1433
Definition: v8.h:3275
Definition: v8.h:3883
Definition: v8.h:4688
Definition: v8.h:3658
Definition: v8.h:3021
Flags
Definition: v8.h:3955
V8_INLINE Local(Local< S > that)
Definition: v8.h:214
V8_INLINE ExternalStringResourceBase * GetExternalStringResourceBase(Encoding *encoding_out) const
Definition: v8.h:7685
Definition: v8.h:2396
V8_INLINE Locker(Isolate *isolate)
Definition: v8.h:6844
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:4215
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:4196
V8_INLINE void MarkIndependent()
Definition: v8.h:7313
Definition: v8.h:3761
Definition: v8.h:4017
V8_INLINE void SetData(uint32_t slot, void *data)
Definition: v8.h:8157
bool IsExecutionTerminating()
void Set(Local< Name > name, Local< Data > value, PropertyAttribute attributes=None)
Definition: v8-util.h:559
void(* JitCodeEventHandler)(const JitCodeEvent *event)
Definition: v8.h:5158
Definition: v8.h:3500
Definition: v8.h:985
Definition: v8.h:111
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Definition: v8.h:714
V8_INLINE Global(Isolate *isolate, Local< S > that)
Definition: v8.h:797
static V8_INLINE uint32_t GetNumberOfDataSlots()
Definition: v8.h:8169
Definition: v8.h:4733
Definition: v8.h:1640
V8_INLINE ExternalStringResource * GetExternalStringResource() const
Definition: v8.h:7667
V8_INLINE void SetWrapperClassId(uint16_t class_id)
Definition: v8.h:7333
V8_INLINE void * GetAlignedPointerFromInternalField(int index)
Definition: v8.h:7634
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8.h:7128
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:4134
Definition: v8.h:6400
Definition: v8.h:155
const char * data() const
Definition: v8.h:4722
Definition: v8.h:4001
Definition: v8-profiler.h:181
void RemoveGCPrologueCallback(GCPrologueCallback callback)
Definition: v8.h:951
V8_INLINE bool IsNearDeath() const
Definition: v8.h:7212
StackTraceOptions
Definition: v8.h:1519
JitCodeEventHandler code_event_handler
Definition: v8.h:5218
Definition: v8.h:3548
Definition: v8.h:922
Definition: v8.h:3846
Definition: v8.h:3949
Definition: v8.h:2587
Definition: v8.h:673
Definition: v8.h:6726
static V8_INLINE v8::Local< v8::String > Empty(Isolate *isolate)
Definition: v8.h:7658
V8_INLINE Global(Global &&other)
Definition: v8.h:814
V8_INLINE void * GetData(uint32_t slot)
Definition: v8.h:8163
void SetObjectGroupId(const Persistent< T > &object, UniqueId id)
Definition: v8.h:8197
bool AddMessageListener(MessageCallback that, Local< Value > data=Local< Value >())
Definition: v8.h:129
ArrayBuffer::Allocator * array_buffer_allocator
Definition: v8.h:5250
V8_INLINE int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes)
Definition: v8.h:8175
V8_INLINE bool IsEmpty() const
Definition: v8.h:227
void Enter()
Definition: v8.h:5174
Definition: v8.h:2447
Definition: v8.h:3366
void RemoveMessageListeners(MessageCallback that)
Definition: v8.h:4510
Definition: v8.h:130
GCType
Definition: v8.h:4976
Definition: v8.h:1133
Definition: v8-profiler.h:425
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
Definition: v8.h:4235
Definition: v8.h:1649
Definition: v8.h:5938
Definition: v8.h:5972
Definition: v8.h:3933
Definition: v8.h:125
Definition: v8.h:6559
Definition: v8.h:4703
Definition: v8.h:5024
Definition: v8.h:976
Definition: v8.h:3568
virtual void Dispose()
Definition: v8.h:2194
void(* GenericNamedPropertySetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:4142
void TerminateExecution()
Definition: v8.h:3676
Definition: v8.h:4791
Definition: v8.h:3899
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
Definition: v8.h:5965
Definition: v8.h:2512
V8_INLINE void Reset()
Definition: v8.h:7232
Definition: v8.h:6839
V8_INLINE bool IsNull() const
Definition: v8.h:7723
bool(* AllowCodeGenerationFromStringsCallback)(Local< Context > context)
Definition: v8.h:4965
Definition: v8.h:5190
Definition: v8.h:3915
Definition: v8.h:2526
void CancelTerminateExecution()
AccessControl
Definition: v8.h:2576
void(* FunctionEntryHook)(uintptr_t function, uintptr_t return_addr_location)
Definition: v8.h:5076
V8_INLINE bool IsString() const
Definition: v8.h:7741
Definition: v8-util.h:350
Global Pass()
Definition: v8.h:834
Definition: v8.h:3712
void(* NamedPropertyQueryCallback)(Local< String > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:4105
ResourceConstraints constraints
Definition: v8.h:5223
Definition: v8.h:2977
Definition: v8.h:2497
V8_INLINE Local< Value > GetInternalField(int index)
Definition: v8.h:7615
Definition: v8.h:145
Definition: v8.h:114
V8_INLINE bool IsUndefined() const
Definition: v8.h:7705
V8_INLINE ~Persistent()
Definition: v8.h:745
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:4449