v8  5.1.281(node6.17.1)
V8 is Google's open source JavaScript engine
v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <utility>
22 #include <vector>
23 
24 #include "v8-version.h" // NOLINT(build/include)
25 #include "v8config.h" // NOLINT(build/include)
26 
27 // We reserve the V8_* prefix for macros defined in V8 public API and
28 // assume there are no name conflicts with the embedder's code.
29 
30 #ifdef V8_OS_WIN
31 
32 // Setup for Windows DLL export/import. When building the V8 DLL the
33 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
34 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
35 // static library or building a program which uses the V8 static library neither
36 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
37 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
38 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
39  build configuration to ensure that at most one of these is set
40 #endif
41 
42 #ifdef BUILDING_V8_SHARED
43 # define V8_EXPORT __declspec(dllexport)
44 #elif USING_V8_SHARED
45 # define V8_EXPORT __declspec(dllimport)
46 #else
47 # define V8_EXPORT
48 #endif // BUILDING_V8_SHARED
49 
50 #else // V8_OS_WIN
51 
52 // Setup for Linux shared library export.
53 #if V8_HAS_ATTRIBUTE_VISIBILITY && defined(V8_SHARED)
54 # ifdef BUILDING_V8_SHARED
55 # define V8_EXPORT __attribute__ ((visibility("default")))
56 # else
57 # define V8_EXPORT
58 # endif
59 #else
60 # define V8_EXPORT
61 #endif
62 
63 #endif // V8_OS_WIN
64 
68 namespace v8 {
69 
70 class AccessorSignature;
71 class Array;
72 class Boolean;
73 class BooleanObject;
74 class Context;
75 class CpuProfiler;
76 class Data;
77 class Date;
78 class External;
79 class Function;
80 class FunctionTemplate;
81 class HeapProfiler;
82 class ImplementationUtilities;
83 class Int32;
84 class Integer;
85 class Isolate;
86 template <class T>
87 class Maybe;
88 class Name;
89 class Number;
90 class NumberObject;
91 class Object;
92 class ObjectOperationDescriptor;
93 class ObjectTemplate;
94 class Platform;
95 class Primitive;
96 class Promise;
97 class Proxy;
98 class RawOperationDescriptor;
99 class Script;
100 class SharedArrayBuffer;
101 class Signature;
102 class StartupData;
103 class StackFrame;
104 class StackTrace;
105 class String;
106 class StringObject;
107 class Symbol;
108 class SymbolObject;
109 class Private;
110 class Uint32;
111 class Utils;
112 class Value;
113 template <class T> class Local;
114 template <class T>
116 template <class T> class Eternal;
117 template<class T> class NonCopyablePersistentTraits;
118 template<class T> class PersistentBase;
119 template <class T, class M = NonCopyablePersistentTraits<T> >
121 template <class T>
122 class Global;
123 template<class K, class V, class T> class PersistentValueMap;
124 template <class K, class V, class T>
126 template <class K, class V, class T>
127 class GlobalValueMap;
128 template<class V, class T> class PersistentValueVector;
129 template<class T, class P> class WeakCallbackObject;
130 class FunctionTemplate;
131 class ObjectTemplate;
132 class Data;
133 template<typename T> class FunctionCallbackInfo;
134 template<typename T> class PropertyCallbackInfo;
135 class StackTrace;
136 class StackFrame;
137 class Isolate;
138 class CallHandlerHelper;
140 template<typename T> class ReturnValue;
141 
142 namespace experimental {
143 class FastAccessorBuilder;
144 } // namespace experimental
145 
146 namespace internal {
147 class Arguments;
148 class Heap;
149 class HeapObject;
150 class Isolate;
151 class Object;
152 struct StreamedSource;
153 template<typename T> class CustomArguments;
154 class PropertyCallbackArguments;
155 class FunctionCallbackArguments;
156 class GlobalHandles;
157 } // namespace internal
158 
159 
163 class UniqueId {
164  public:
165  explicit UniqueId(intptr_t data)
166  : data_(data) {}
167 
168  bool operator==(const UniqueId& other) const {
169  return data_ == other.data_;
170  }
171 
172  bool operator!=(const UniqueId& other) const {
173  return data_ != other.data_;
174  }
175 
176  bool operator<(const UniqueId& other) const {
177  return data_ < other.data_;
178  }
179 
180  private:
181  intptr_t data_;
182 };
183 
184 // --- Handles ---
185 
186 #define TYPE_CHECK(T, S) \
187  while (false) { \
188  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
189  }
190 
191 
217 template <class T>
218 class Local {
219  public:
220  V8_INLINE Local() : val_(0) {}
221  template <class S>
223  : val_(reinterpret_cast<T*>(*that)) {
229  TYPE_CHECK(T, S);
230  }
231 
235  V8_INLINE bool IsEmpty() const { return val_ == 0; }
236 
240  V8_INLINE void Clear() { val_ = 0; }
241 
242  V8_INLINE T* operator->() const { return val_; }
243 
244  V8_INLINE T* operator*() const { return val_; }
245 
252  template <class S>
253  V8_INLINE bool operator==(const Local<S>& that) const {
254  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
255  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
256  if (a == 0) return b == 0;
257  if (b == 0) return false;
258  return *a == *b;
259  }
260 
261  template <class S> V8_INLINE bool operator==(
262  const PersistentBase<S>& that) const {
263  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
264  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
265  if (a == 0) return b == 0;
266  if (b == 0) return false;
267  return *a == *b;
268  }
269 
276  template <class S>
277  V8_INLINE bool operator!=(const Local<S>& that) const {
278  return !operator==(that);
279  }
280 
281  template <class S> V8_INLINE bool operator!=(
282  const Persistent<S>& that) const {
283  return !operator==(that);
284  }
285 
286  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
287 #ifdef V8_ENABLE_CHECKS
288  // If we're going to perform the type check then we have to check
289  // that the handle isn't empty before doing the checked cast.
290  if (that.IsEmpty()) return Local<T>();
291 #endif
292  return Local<T>(T::Cast(*that));
293  }
294 
295 
296  template <class S> V8_INLINE Local<S> As() {
297  return Local<S>::Cast(*this);
298  }
299 
305  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
306  V8_INLINE static Local<T> New(Isolate* isolate,
307  const PersistentBase<T>& that);
308 
309  private:
310  friend class Utils;
311  template<class F> friend class Eternal;
312  template<class F> friend class PersistentBase;
313  template<class F, class M> friend class Persistent;
314  template<class F> friend class Local;
315  template <class F>
316  friend class MaybeLocal;
317  template<class F> friend class FunctionCallbackInfo;
318  template<class F> friend class PropertyCallbackInfo;
319  friend class String;
320  friend class Object;
321  friend class Context;
322  friend class Private;
323  template<class F> friend class internal::CustomArguments;
324  friend Local<Primitive> Undefined(Isolate* isolate);
325  friend Local<Primitive> Null(Isolate* isolate);
326  friend Local<Boolean> True(Isolate* isolate);
327  friend Local<Boolean> False(Isolate* isolate);
328  friend class HandleScope;
329  friend class EscapableHandleScope;
330  template <class F1, class F2, class F3>
332  template<class F1, class F2> friend class PersistentValueVector;
333 
334  explicit V8_INLINE Local(T* that) : val_(that) {}
335  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
336  T* val_;
337 };
338 
339 
340 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
341 // Local is an alias for Local for historical reasons.
342 template <class T>
343 using Handle = Local<T>;
344 #endif
345 
346 
357 template <class T>
358 class MaybeLocal {
359  public:
360  V8_INLINE MaybeLocal() : val_(nullptr) {}
361  template <class S>
363  : val_(reinterpret_cast<T*>(*that)) {
364  TYPE_CHECK(T, S);
365  }
366 
367  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
368 
369  template <class S>
371  out->val_ = IsEmpty() ? nullptr : this->val_;
372  return !IsEmpty();
373  }
374 
375  // Will crash if the MaybeLocal<> is empty.
377 
378  template <class S>
379  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
380  return IsEmpty() ? default_value : Local<S>(val_);
381  }
382 
383  private:
384  T* val_;
385 };
386 
387 
388 // Eternal handles are set-once handles that live for the life of the isolate.
389 template <class T> class Eternal {
390  public:
391  V8_INLINE Eternal() : index_(kInitialValue) { }
392  template<class S>
393  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
394  Set(isolate, handle);
395  }
396  // Can only be safely called if already set.
397  V8_INLINE Local<T> Get(Isolate* isolate);
398  V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
399  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
400 
401  private:
402  static const int kInitialValue = -1;
403  int index_;
404 };
405 
406 
407 static const int kInternalFieldsInWeakCallback = 2;
408 
409 
410 template <typename T>
412  public:
413  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
414 
415  WeakCallbackInfo(Isolate* isolate, T* parameter,
416  void* internal_fields[kInternalFieldsInWeakCallback],
417  Callback* callback)
418  : isolate_(isolate), parameter_(parameter), callback_(callback) {
419  for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) {
420  internal_fields_[i] = internal_fields[i];
421  }
422  }
423 
424  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
425  V8_INLINE T* GetParameter() const { return parameter_; }
426  V8_INLINE void* GetInternalField(int index) const;
427 
428  V8_INLINE V8_DEPRECATED("use indexed version",
429  void* GetInternalField1() const) {
430  return internal_fields_[0];
431  }
432  V8_INLINE V8_DEPRECATED("use indexed version",
433  void* GetInternalField2() const) {
434  return internal_fields_[1];
435  }
436 
437  V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.",
438  bool IsFirstPass() const) {
439  return callback_ != nullptr;
440  }
441 
442  // When first called, the embedder MUST Reset() the Global which triggered the
443  // callback. The Global itself is unusable for anything else. No v8 other api
444  // calls may be called in the first callback. Should additional work be
445  // required, the embedder must set a second pass callback, which will be
446  // called after all the initial callbacks are processed.
447  // Calling SetSecondPassCallback on the second pass will immediately crash.
448  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
449 
450  private:
451  Isolate* isolate_;
452  T* parameter_;
453  Callback* callback_;
454  void* internal_fields_[kInternalFieldsInWeakCallback];
455 };
456 
457 
458 template <class T, class P>
460  public:
461  typedef void (*Callback)(const WeakCallbackData<T, P>& data);
462 
463  WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle)
464  : isolate_(isolate), parameter_(parameter), handle_(handle) {}
465 
466  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
467  V8_INLINE P* GetParameter() const { return parameter_; }
468  V8_INLINE Local<T> GetValue() const { return handle_; }
469 
470  private:
471  Isolate* isolate_;
472  P* parameter_;
473  Local<T> handle_;
474 };
475 
476 
477 // TODO(dcarney): delete this with WeakCallbackData
478 template <class T>
480 
481 
483 
484 
498 template <class T> class PersistentBase {
499  public:
504  V8_INLINE void Reset();
509  template <class S>
510  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
511 
516  template <class S>
517  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
518 
519  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
520  V8_INLINE void Empty() { val_ = 0; }
521 
522  V8_INLINE Local<T> Get(Isolate* isolate) const {
523  return Local<T>::New(isolate, *this);
524  }
525 
526  template <class S>
527  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
528  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
529  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
530  if (a == NULL) return b == NULL;
531  if (b == NULL) return false;
532  return *a == *b;
533  }
534 
535  template <class S>
536  V8_INLINE bool operator==(const Local<S>& that) const {
537  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
538  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
539  if (a == NULL) return b == NULL;
540  if (b == NULL) return false;
541  return *a == *b;
542  }
543 
544  template <class S>
545  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
546  return !operator==(that);
547  }
548 
549  template <class S>
550  V8_INLINE bool operator!=(const Local<S>& that) const {
551  return !operator==(that);
552  }
553 
561  template <typename P>
563  "use WeakCallbackInfo version",
564  void SetWeak(P* parameter,
565  typename WeakCallbackData<T, P>::Callback callback));
566 
567  template <typename S, typename P>
569  "use WeakCallbackInfo version",
570  void SetWeak(P* parameter,
571  typename WeakCallbackData<S, P>::Callback callback));
572 
573  // Phantom persistents work like weak persistents, except that the pointer to
574  // the object being collected is not available in the finalization callback.
575  // This enables the garbage collector to collect the object and any objects
576  // it references transitively in one GC cycle. At the moment you can either
577  // specify a parameter for the callback or the location of two internal
578  // fields in the dying object.
579  template <typename P>
581  "use SetWeak",
582  void SetPhantom(P* parameter,
583  typename WeakCallbackInfo<P>::Callback callback,
584  int internal_field_index1 = -1,
585  int internal_field_index2 = -1));
586 
587  template <typename P>
588  V8_INLINE void SetWeak(P* parameter,
589  typename WeakCallbackInfo<P>::Callback callback,
590  WeakCallbackType type);
591 
592  template<typename P>
593  V8_INLINE P* ClearWeak();
594 
595  // TODO(dcarney): remove this.
596  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
597 
604 
611  V8_INLINE void MarkIndependent();
612 
622 
628  V8_INLINE void MarkActive();
629 
630  V8_INLINE bool IsIndependent() const;
631 
633  V8_INLINE bool IsNearDeath() const;
634 
636  V8_INLINE bool IsWeak() const;
637 
642  V8_INLINE void SetWrapperClassId(uint16_t class_id);
643 
648  V8_INLINE uint16_t WrapperClassId() const;
649 
650  private:
651  friend class Isolate;
652  friend class Utils;
653  template<class F> friend class Local;
654  template<class F1, class F2> friend class Persistent;
655  template <class F>
656  friend class Global;
657  template<class F> friend class PersistentBase;
658  template<class F> friend class ReturnValue;
659  template <class F1, class F2, class F3>
661  template<class F1, class F2> friend class PersistentValueVector;
662  friend class Object;
663 
664  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
665  PersistentBase(const PersistentBase& other) = delete; // NOLINT
666  void operator=(const PersistentBase&) = delete;
667  V8_INLINE static T* New(Isolate* isolate, T* that);
668 
669  T* val_;
670 };
671 
672 
679 template<class T>
680 class NonCopyablePersistentTraits {
681  public:
683  static const bool kResetInDestructor = false;
684  template<class S, class M>
685  V8_INLINE static void Copy(const Persistent<S, M>& source,
686  NonCopyablePersistent* dest) {
687  Uncompilable<Object>();
688  }
689  // TODO(dcarney): come up with a good compile error here.
690  template<class O> V8_INLINE static void Uncompilable() {
691  TYPE_CHECK(O, Primitive);
692  }
693 };
694 
695 
700 template<class T>
703  static const bool kResetInDestructor = true;
704  template<class S, class M>
705  static V8_INLINE void Copy(const Persistent<S, M>& source,
706  CopyablePersistent* dest) {
707  // do nothing, just allow copy
708  }
709 };
710 
711 
720 template <class T, class M> class Persistent : public PersistentBase<T> {
721  public:
731  template <class S>
733  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
734  TYPE_CHECK(T, S);
735  }
741  template <class S, class M2>
743  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
744  TYPE_CHECK(T, S);
745  }
753  Copy(that);
754  }
755  template <class S, class M2>
757  Copy(that);
758  }
759  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
760  Copy(that);
761  return *this;
762  }
763  template <class S, class M2>
765  Copy(that);
766  return *this;
767  }
774  if (M::kResetInDestructor) this->Reset();
775  }
776 
777  // TODO(dcarney): this is pretty useless, fix or remove
778  template <class S>
779  V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT
780 #ifdef V8_ENABLE_CHECKS
781  // If we're going to perform the type check then we have to check
782  // that the handle isn't empty before doing the checked cast.
783  if (!that.IsEmpty()) T::Cast(*that);
784 #endif
785  return reinterpret_cast<Persistent<T>&>(that);
786  }
787 
788  // TODO(dcarney): this is pretty useless, fix or remove
789  template <class S> V8_INLINE Persistent<S>& As() { // NOLINT
790  return Persistent<S>::Cast(*this);
791  }
792 
793  private:
794  friend class Isolate;
795  friend class Utils;
796  template<class F> friend class Local;
797  template<class F1, class F2> friend class Persistent;
798  template<class F> friend class ReturnValue;
799 
800  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
801  V8_INLINE T* operator*() const { return this->val_; }
802  template<class S, class M2>
803  V8_INLINE void Copy(const Persistent<S, M2>& that);
804 };
805 
806 
812 template <class T>
813 class Global : public PersistentBase<T> {
814  public:
818  V8_INLINE Global() : PersistentBase<T>(nullptr) {}
824  template <class S>
826  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
827  TYPE_CHECK(T, S);
828  }
834  template <class S>
835  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
836  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
837  TYPE_CHECK(T, S);
838  }
842  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
843  other.val_ = nullptr;
844  }
845  V8_INLINE ~Global() { this->Reset(); }
849  template <class S>
850  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
851  TYPE_CHECK(T, S);
852  if (this != &rhs) {
853  this->Reset();
854  this->val_ = rhs.val_;
855  rhs.val_ = nullptr;
856  }
857  return *this;
858  }
862  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
863 
864  /*
865  * For compatibility with Chromium's base::Bind (base::Passed).
866  */
867  typedef void MoveOnlyTypeForCPP03;
868 
869  private:
870  template <class F>
871  friend class ReturnValue;
872  Global(const Global&) = delete;
873  void operator=(const Global&) = delete;
874  V8_INLINE T* operator*() const { return this->val_; }
875 };
876 
877 
878 // UniquePersistent is an alias for Global for historical reason.
879 template <class T>
881 
882 
898  public:
899  explicit HandleScope(Isolate* isolate);
900 
901  ~HandleScope();
902 
906  static int NumberOfHandles(Isolate* isolate);
907 
909  return reinterpret_cast<Isolate*>(isolate_);
910  }
911 
912  protected:
914 
915  void Initialize(Isolate* isolate);
916 
917  static internal::Object** CreateHandle(internal::Isolate* isolate,
918  internal::Object* value);
919 
920  private:
921  // Uses heap_object to obtain the current Isolate.
922  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
923  internal::Object* value);
924 
925  // Make it hard to create heap-allocated or illegal handle scopes by
926  // disallowing certain operations.
927  HandleScope(const HandleScope&);
928  void operator=(const HandleScope&);
929  void* operator new(size_t size);
930  void operator delete(void*, size_t);
931 
932  internal::Isolate* isolate_;
933  internal::Object** prev_next_;
934  internal::Object** prev_limit_;
935 
936  // Local::New uses CreateHandle with an Isolate* parameter.
937  template<class F> friend class Local;
938 
939  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
940  // a HeapObject* in their shortcuts.
941  friend class Object;
942  friend class Context;
943 };
944 
945 
951  public:
952  explicit EscapableHandleScope(Isolate* isolate);
954 
959  template <class T>
961  internal::Object** slot =
962  Escape(reinterpret_cast<internal::Object**>(*value));
963  return Local<T>(reinterpret_cast<T*>(slot));
964  }
965 
966  private:
967  internal::Object** Escape(internal::Object** escape_value);
968 
969  // Make it hard to create heap-allocated or illegal handle scopes by
970  // disallowing certain operations.
972  void operator=(const EscapableHandleScope&);
973  void* operator new(size_t size);
974  void operator delete(void*, size_t);
975 
976  internal::Object** escape_slot_;
977 };
978 
980  public:
981  SealHandleScope(Isolate* isolate);
982  ~SealHandleScope();
983 
984  private:
985  // Make it hard to create heap-allocated or illegal handle scopes by
986  // disallowing certain operations.
988  void operator=(const SealHandleScope&);
989  void* operator new(size_t size);
990  void operator delete(void*, size_t);
991 
992  internal::Isolate* isolate_;
993  internal::Object** prev_limit_;
994  int prev_sealed_level_;
995 };
996 
997 
998 // --- Special objects ---
999 
1000 
1005  private:
1006  Data();
1007 };
1008 
1009 
1014  public:
1015  V8_INLINE ScriptOriginOptions(bool is_embedder_debug_script = false,
1016  bool is_shared_cross_origin = false,
1017  bool is_opaque = false)
1018  : flags_((is_embedder_debug_script ? kIsEmbedderDebugScript : 0) |
1019  (is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
1020  (is_opaque ? kIsOpaque : 0)) {}
1022  : flags_(flags &
1023  (kIsEmbedderDebugScript | kIsSharedCrossOrigin | kIsOpaque)) {}
1024  bool IsEmbedderDebugScript() const {
1025  return (flags_ & kIsEmbedderDebugScript) != 0;
1026  }
1027  bool IsSharedCrossOrigin() const {
1028  return (flags_ & kIsSharedCrossOrigin) != 0;
1029  }
1030  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
1031  int Flags() const { return flags_; }
1032 
1033  private:
1034  enum {
1035  kIsEmbedderDebugScript = 1,
1036  kIsSharedCrossOrigin = 1 << 1,
1037  kIsOpaque = 1 << 2
1038  };
1039  const int flags_;
1040 };
1041 
1046  public:
1048  Local<Value> resource_name,
1049  Local<Integer> resource_line_offset = Local<Integer>(),
1050  Local<Integer> resource_column_offset = Local<Integer>(),
1051  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1052  Local<Integer> script_id = Local<Integer>(),
1053  Local<Boolean> resource_is_embedder_debug_script = Local<Boolean>(),
1054  Local<Value> source_map_url = Local<Value>(),
1055  Local<Boolean> resource_is_opaque = Local<Boolean>());
1064  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1065 
1066  private:
1067  Local<Value> resource_name_;
1068  Local<Integer> resource_line_offset_;
1069  Local<Integer> resource_column_offset_;
1070  ScriptOriginOptions options_;
1071  Local<Integer> script_id_;
1072  Local<Value> source_map_url_;
1073 };
1074 
1075 
1080  public:
1084  Local<Script> BindToCurrentContext();
1085 
1086  int GetId();
1087  Local<Value> GetScriptName();
1088 
1092  Local<Value> GetSourceURL();
1096  Local<Value> GetSourceMappingURL();
1097 
1102  int GetLineNumber(int code_pos);
1103 
1104  static const int kNoScriptId = 0;
1105 };
1106 
1107 
1113  public:
1117  static V8_DEPRECATE_SOON(
1118  "Use maybe version",
1119  Local<Script> Compile(Local<String> source,
1120  ScriptOrigin* origin = nullptr));
1122  Local<Context> context, Local<String> source,
1123  ScriptOrigin* origin = nullptr);
1124 
1125  static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
1126  Compile(Local<String> source,
1127  Local<String> file_name));
1128 
1134  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
1136 
1140  Local<UnboundScript> GetUnboundScript();
1141 };
1142 
1143 
1148  public:
1159  BufferOwned
1160  };
1161 
1163  : data(NULL),
1164  length(0),
1165  rejected(false),
1166  buffer_policy(BufferNotOwned) {}
1167 
1168  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1169  // data and guarantees that it stays alive until the CachedData object is
1170  // destroyed. If the policy is BufferOwned, the given data will be deleted
1171  // (with delete[]) when the CachedData object is destroyed.
1172  CachedData(const uint8_t* data, int length,
1173  BufferPolicy buffer_policy = BufferNotOwned);
1174  ~CachedData();
1175  // TODO(marja): Async compilation; add constructors which take a callback
1176  // which will be called when V8 no longer needs the data.
1177  const uint8_t* data;
1178  int length;
1179  bool rejected;
1181 
1182  private:
1183  // Prevent copying. Not implemented.
1184  CachedData(const CachedData&);
1185  CachedData& operator=(const CachedData&);
1186  };
1187 
1191  class Source {
1192  public:
1193  // Source takes ownership of CachedData.
1194  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1195  CachedData* cached_data = NULL);
1196  V8_INLINE Source(Local<String> source_string,
1197  CachedData* cached_data = NULL);
1198  V8_INLINE ~Source();
1199 
1200  // Ownership of the CachedData or its buffers is *not* transferred to the
1201  // caller. The CachedData object is alive as long as the Source object is
1202  // alive.
1203  V8_INLINE const CachedData* GetCachedData() const;
1204 
1205  private:
1206  friend class ScriptCompiler;
1207  // Prevent copying. Not implemented.
1208  Source(const Source&);
1209  Source& operator=(const Source&);
1210 
1211  Local<String> source_string;
1212 
1213  // Origin information
1214  Local<Value> resource_name;
1215  Local<Integer> resource_line_offset;
1216  Local<Integer> resource_column_offset;
1217  ScriptOriginOptions resource_options;
1218  Local<Value> source_map_url;
1219 
1220  // Cached data from previous compilation (if a kConsume*Cache flag is
1221  // set), or hold newly generated cache data (kProduce*Cache flags) are
1222  // set when calling a compile method.
1223  CachedData* cached_data;
1224  };
1225 
1231  public:
1233 
1251  virtual size_t GetMoreData(const uint8_t** src) = 0;
1252 
1263  virtual bool SetBookmark();
1264 
1268  virtual void ResetToBookmark();
1269  };
1270 
1271 
1279  public:
1280  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1281 
1282  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1283  ~StreamedSource();
1284 
1285  // Ownership of the CachedData or its buffers is *not* transferred to the
1286  // caller. The CachedData object is alive as long as the StreamedSource
1287  // object is alive.
1288  const CachedData* GetCachedData() const;
1289 
1290  internal::StreamedSource* impl() const { return impl_; }
1291 
1292  private:
1293  // Prevent copying. Not implemented.
1295  StreamedSource& operator=(const StreamedSource&);
1296 
1297  internal::StreamedSource* impl_;
1298  };
1299 
1305  public:
1307  virtual void Run() = 0;
1308  };
1309 
1311  kNoCompileOptions = 0,
1315  kConsumeCodeCache
1316  };
1317 
1331  static V8_DEPRECATED("Use maybe version",
1332  Local<UnboundScript> CompileUnbound(
1333  Isolate* isolate, Source* source,
1334  CompileOptions options = kNoCompileOptions));
1335  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
1336  Isolate* isolate, Source* source,
1337  CompileOptions options = kNoCompileOptions);
1338 
1350  static V8_DEPRECATED(
1351  "Use maybe version",
1352  Local<Script> Compile(Isolate* isolate, Source* source,
1353  CompileOptions options = kNoCompileOptions));
1355  Local<Context> context, Source* source,
1356  CompileOptions options = kNoCompileOptions);
1357 
1369  static ScriptStreamingTask* StartStreamingScript(
1370  Isolate* isolate, StreamedSource* source,
1371  CompileOptions options = kNoCompileOptions);
1372 
1380  static V8_DEPRECATED("Use maybe version",
1381  Local<Script> Compile(Isolate* isolate,
1382  StreamedSource* source,
1383  Local<String> full_source_string,
1384  const ScriptOrigin& origin));
1386  Local<Context> context, StreamedSource* source,
1387  Local<String> full_source_string, const ScriptOrigin& origin);
1388 
1407  static uint32_t CachedDataVersionTag();
1408 
1419  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> CompileModule(
1420  Local<Context> context, Source* source,
1421  CompileOptions options = kNoCompileOptions);
1422 
1433  static V8_DEPRECATE_SOON("Use maybe version",
1434  Local<Function> CompileFunctionInContext(
1435  Isolate* isolate, Source* source,
1436  Local<Context> context, size_t arguments_count,
1437  Local<String> arguments[],
1438  size_t context_extension_count,
1439  Local<Object> context_extensions[]));
1440  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
1441  Local<Context> context, Source* source, size_t arguments_count,
1442  Local<String> arguments[], size_t context_extension_count,
1443  Local<Object> context_extensions[]);
1444 
1445  private:
1446  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1447  Isolate* isolate, Source* source, CompileOptions options, bool is_module);
1448 };
1449 
1450 
1455  public:
1456  Local<String> Get() const;
1457 
1458  V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
1460  Local<Context> context) const;
1461 
1466  ScriptOrigin GetScriptOrigin() const;
1467 
1472  Local<Value> GetScriptResourceName() const;
1473 
1479  Local<StackTrace> GetStackTrace() const;
1480 
1484  V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
1485  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1486 
1491  int GetStartPosition() const;
1492 
1497  int GetEndPosition() const;
1498 
1503  V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
1504  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1505 
1510  V8_DEPRECATED("Use maybe version", int GetEndColumn() const);
1511  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1512 
1517  bool IsSharedCrossOrigin() const;
1518  bool IsOpaque() const;
1519 
1520  // TODO(1245381): Print to a string instead of on a FILE.
1521  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1522 
1523  static const int kNoLineNumberInfo = 0;
1524  static const int kNoColumnInfo = 0;
1525  static const int kNoScriptIdInfo = 0;
1526 };
1527 
1528 
1535  public:
1541  kLineNumber = 1,
1542  kColumnOffset = 1 << 1 | kLineNumber,
1543  kScriptName = 1 << 2,
1544  kFunctionName = 1 << 3,
1545  kIsEval = 1 << 4,
1546  kIsConstructor = 1 << 5,
1547  kScriptNameOrSourceURL = 1 << 6,
1548  kScriptId = 1 << 7,
1549  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1550  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1551  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1552  };
1553 
1557  Local<StackFrame> GetFrame(uint32_t index) const;
1558 
1562  int GetFrameCount() const;
1563 
1567  Local<Array> AsArray();
1568 
1576  static Local<StackTrace> CurrentStackTrace(
1577  Isolate* isolate,
1578  int frame_limit,
1579  StackTraceOptions options = kOverview);
1580 };
1581 
1582 
1587  public:
1594  int GetLineNumber() const;
1595 
1603  int GetColumn() const;
1604 
1611  int GetScriptId() const;
1612 
1617  Local<String> GetScriptName() const;
1618 
1625  Local<String> GetScriptNameOrSourceURL() const;
1626 
1630  Local<String> GetFunctionName() const;
1631 
1636  bool IsEval() const;
1637 
1642  bool IsConstructor() const;
1643 };
1644 
1645 
1646 // A StateTag represents a possible state of the VM.
1648 
1649 
1650 // A RegisterState represents the current state of registers used
1651 // by the sampling profiler API.
1653  RegisterState() : pc(NULL), sp(NULL), fp(NULL) {}
1654  void* pc; // Instruction pointer.
1655  void* sp; // Stack pointer.
1656  void* fp; // Frame pointer.
1657 };
1658 
1659 
1660 // The output structure filled up by GetStackSample API function.
1661 struct SampleInfo {
1664 };
1665 
1666 
1671  public:
1679  static V8_DEPRECATED("Use maybe version",
1680  Local<Value> Parse(Local<String> json_string));
1682  Isolate* isolate, Local<String> json_string);
1683 };
1684 
1685 
1691 class V8_EXPORT NativeWeakMap : public Data {
1692  public:
1693  static Local<NativeWeakMap> New(Isolate* isolate);
1694  void Set(Local<Value> key, Local<Value> value);
1695  Local<Value> Get(Local<Value> key);
1696  bool Has(Local<Value> key);
1697  bool Delete(Local<Value> key);
1698 };
1699 
1700 
1701 // --- Value ---
1702 
1703 
1707 class V8_EXPORT Value : public Data {
1708  public:
1713  V8_INLINE bool IsUndefined() const;
1714 
1719  V8_INLINE bool IsNull() const;
1720 
1724  bool IsTrue() const;
1725 
1729  bool IsFalse() const;
1730 
1735  bool IsName() const;
1736 
1741  V8_INLINE bool IsString() const;
1742 
1747  bool IsSymbol() const;
1748 
1752  bool IsFunction() const;
1753 
1758  bool IsArray() const;
1759 
1763  bool IsObject() const;
1764 
1768  bool IsBoolean() const;
1769 
1773  bool IsNumber() const;
1774 
1778  bool IsExternal() const;
1779 
1783  bool IsInt32() const;
1784 
1788  bool IsUint32() const;
1789 
1793  bool IsDate() const;
1794 
1798  bool IsArgumentsObject() const;
1799 
1803  bool IsBooleanObject() const;
1804 
1808  bool IsNumberObject() const;
1809 
1813  bool IsStringObject() const;
1814 
1819  bool IsSymbolObject() const;
1820 
1824  bool IsNativeError() const;
1825 
1829  bool IsRegExp() const;
1830 
1835  bool IsGeneratorFunction() const;
1836 
1841  bool IsGeneratorObject() const;
1842 
1847  bool IsPromise() const;
1848 
1852  bool IsMap() const;
1853 
1857  bool IsSet() const;
1858 
1862  bool IsMapIterator() const;
1863 
1867  bool IsSetIterator() const;
1868 
1872  bool IsWeakMap() const;
1873 
1877  bool IsWeakSet() const;
1878 
1883  bool IsArrayBuffer() const;
1884 
1889  bool IsArrayBufferView() const;
1890 
1895  bool IsTypedArray() const;
1896 
1901  bool IsUint8Array() const;
1902 
1907  bool IsUint8ClampedArray() const;
1908 
1913  bool IsInt8Array() const;
1914 
1919  bool IsUint16Array() const;
1920 
1925  bool IsInt16Array() const;
1926 
1931  bool IsUint32Array() const;
1932 
1937  bool IsInt32Array() const;
1938 
1943  bool IsFloat32Array() const;
1944 
1949  bool IsFloat64Array() const;
1950 
1955  bool IsFloat32x4() const;
1956 
1961  bool IsDataView() const;
1962 
1967  bool IsSharedArrayBuffer() const;
1968 
1972  bool IsProxy() const;
1973 
1974 
1976  Local<Context> context) const;
1978  Local<Context> context) const;
1980  Local<Context> context) const;
1982  Local<Context> context) const;
1984  Local<Context> context) const;
1986  Local<Context> context) const;
1988  Local<Context> context) const;
1990 
1991  V8_DEPRECATE_SOON("Use maybe version",
1992  Local<Boolean> ToBoolean(Isolate* isolate) const);
1993  V8_DEPRECATE_SOON("Use maybe version",
1994  Local<Number> ToNumber(Isolate* isolate) const);
1995  V8_DEPRECATE_SOON("Use maybe version",
1996  Local<String> ToString(Isolate* isolate) const);
1997  V8_DEPRECATED("Use maybe version",
1998  Local<String> ToDetailString(Isolate* isolate) const);
1999  V8_DEPRECATE_SOON("Use maybe version",
2000  Local<Object> ToObject(Isolate* isolate) const);
2001  V8_DEPRECATE_SOON("Use maybe version",
2002  Local<Integer> ToInteger(Isolate* isolate) const);
2003  V8_DEPRECATED("Use maybe version",
2004  Local<Uint32> ToUint32(Isolate* isolate) const);
2005  V8_DEPRECATE_SOON("Use maybe version",
2006  Local<Int32> ToInt32(Isolate* isolate) const);
2007 
2008  inline V8_DEPRECATE_SOON("Use maybe version",
2009  Local<Boolean> ToBoolean() const);
2010  inline V8_DEPRECATED("Use maybe version", Local<Number> ToNumber() const);
2011  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
2012  inline V8_DEPRECATED("Use maybe version",
2013  Local<String> ToDetailString() const);
2014  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
2015  inline V8_DEPRECATE_SOON("Use maybe version",
2016  Local<Integer> ToInteger() const);
2017  inline V8_DEPRECATED("Use maybe version", Local<Uint32> ToUint32() const);
2018  inline V8_DEPRECATED("Use maybe version", Local<Int32> ToInt32() const);
2019 
2024  V8_DEPRECATED("Use maybe version", Local<Uint32> ToArrayIndex() const);
2026  Local<Context> context) const;
2027 
2028  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2029  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2031  Local<Context> context) const;
2033  Local<Context> context) const;
2034  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2035 
2036  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2037  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2038  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2039  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2040  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2041 
2043  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2045  Local<Value> that) const;
2046  bool StrictEquals(Local<Value> that) const;
2047  bool SameValue(Local<Value> that) const;
2048 
2049  template <class T> V8_INLINE static Value* Cast(T* value);
2050 
2051  private:
2052  V8_INLINE bool QuickIsUndefined() const;
2053  V8_INLINE bool QuickIsNull() const;
2054  V8_INLINE bool QuickIsString() const;
2055  bool FullIsUndefined() const;
2056  bool FullIsNull() const;
2057  bool FullIsString() const;
2058 };
2059 
2060 
2064 class V8_EXPORT Primitive : public Value { };
2065 
2066 
2071 class V8_EXPORT Boolean : public Primitive {
2072  public:
2073  bool Value() const;
2074  V8_INLINE static Boolean* Cast(v8::Value* obj);
2075  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2076 
2077  private:
2078  static void CheckCast(v8::Value* obj);
2079 };
2080 
2081 
2085 class V8_EXPORT Name : public Primitive {
2086  public:
2094  int GetIdentityHash();
2095 
2096  V8_INLINE static Name* Cast(v8::Value* obj);
2097  private:
2098  static void CheckCast(v8::Value* obj);
2099 };
2100 
2101 
2103 
2104 
2108 class V8_EXPORT String : public Name {
2109  public:
2110  static const int kMaxLength = (1 << 28) - 16;
2111 
2112  enum Encoding {
2113  UNKNOWN_ENCODING = 0x1,
2114  TWO_BYTE_ENCODING = 0x0,
2115  ONE_BYTE_ENCODING = 0x4
2116  };
2120  int Length() const;
2121 
2126  int Utf8Length() const;
2127 
2133  bool IsOneByte() const;
2134 
2139  bool ContainsOnlyOneByte() const;
2140 
2167  NO_OPTIONS = 0,
2168  HINT_MANY_WRITES_EXPECTED = 1,
2169  NO_NULL_TERMINATION = 2,
2170  PRESERVE_ONE_BYTE_NULL = 4,
2171  // Used by WriteUtf8 to replace orphan surrogate code units with the
2172  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2173  // output.
2174  REPLACE_INVALID_UTF8 = 8
2175  };
2176 
2177  // 16-bit character codes.
2178  int Write(uint16_t* buffer,
2179  int start = 0,
2180  int length = -1,
2181  int options = NO_OPTIONS) const;
2182  // One byte characters.
2183  int WriteOneByte(uint8_t* buffer,
2184  int start = 0,
2185  int length = -1,
2186  int options = NO_OPTIONS) const;
2187  // UTF-8 encoded characters.
2188  int WriteUtf8(char* buffer,
2189  int length = -1,
2190  int* nchars_ref = NULL,
2191  int options = NO_OPTIONS) const;
2192 
2196  V8_INLINE static v8::Local<v8::String> Empty(Isolate* isolate);
2197 
2201  bool IsExternal() const;
2202 
2206  bool IsExternalOneByte() const;
2207 
2209  public:
2211 
2212  virtual bool IsCompressible() const { return false; }
2213 
2214  protected:
2216 
2223  virtual void Dispose() { delete this; }
2224 
2225  private:
2226  // Disallow copying and assigning.
2228  void operator=(const ExternalStringResourceBase&);
2229 
2230  friend class v8::internal::Heap;
2231  };
2232 
2240  : public ExternalStringResourceBase {
2241  public:
2247 
2251  virtual const uint16_t* data() const = 0;
2252 
2256  virtual size_t length() const = 0;
2257 
2258  protected:
2260  };
2261 
2273  : public ExternalStringResourceBase {
2274  public:
2281  virtual const char* data() const = 0;
2283  virtual size_t length() const = 0;
2284  protected:
2286  };
2287 
2293  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
2294  Encoding* encoding_out) const;
2295 
2300  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2301 
2306  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2307 
2308  V8_INLINE static String* Cast(v8::Value* obj);
2309 
2310  // TODO(dcarney): remove with deprecation of New functions.
2312  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2313  kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2314  };
2315 
2317  static V8_DEPRECATE_SOON(
2318  "Use maybe version",
2319  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2320  NewStringType type = kNormalString,
2321  int length = -1));
2322 
2325  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2326  Isolate* isolate, const char* data, v8::NewStringType type,
2327  int length = -1);
2328 
2330  static V8_DEPRECATED(
2331  "Use maybe version",
2332  Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2333  NewStringType type = kNormalString,
2334  int length = -1));
2335 
2338  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2339  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2340  int length = -1);
2341 
2343  static V8_DEPRECATE_SOON(
2344  "Use maybe version",
2345  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2346  NewStringType type = kNormalString,
2347  int length = -1));
2348 
2351  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2352  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2353  int length = -1);
2354 
2359  static Local<String> Concat(Local<String> left, Local<String> right);
2360 
2369  static V8_DEPRECATED("Use maybe version",
2370  Local<String> NewExternal(
2371  Isolate* isolate, ExternalStringResource* resource));
2372  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2373  Isolate* isolate, ExternalStringResource* resource);
2374 
2384  bool MakeExternal(ExternalStringResource* resource);
2385 
2394  static V8_DEPRECATE_SOON(
2395  "Use maybe version",
2396  Local<String> NewExternal(Isolate* isolate,
2397  ExternalOneByteStringResource* resource));
2398  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2399  Isolate* isolate, ExternalOneByteStringResource* resource);
2400 
2410  bool MakeExternal(ExternalOneByteStringResource* resource);
2411 
2415  bool CanMakeExternal();
2416 
2425  public:
2426  explicit Utf8Value(Local<v8::Value> obj);
2427  ~Utf8Value();
2428  char* operator*() { return str_; }
2429  const char* operator*() const { return str_; }
2430  int length() const { return length_; }
2431  private:
2432  char* str_;
2433  int length_;
2434 
2435  // Disallow copying and assigning.
2436  Utf8Value(const Utf8Value&);
2437  void operator=(const Utf8Value&);
2438  };
2439 
2447  public:
2448  explicit Value(Local<v8::Value> obj);
2449  ~Value();
2450  uint16_t* operator*() { return str_; }
2451  const uint16_t* operator*() const { return str_; }
2452  int length() const { return length_; }
2453  private:
2454  uint16_t* str_;
2455  int length_;
2456 
2457  // Disallow copying and assigning.
2458  Value(const Value&);
2459  void operator=(const Value&);
2460  };
2461 
2462  private:
2463  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2464  Encoding encoding) const;
2465  void VerifyExternalStringResource(ExternalStringResource* val) const;
2466  static void CheckCast(v8::Value* obj);
2467 };
2468 
2469 
2475 class V8_EXPORT Symbol : public Name {
2476  public:
2477  // Returns the print name string of the symbol, or undefined if none.
2478  Local<Value> Name() const;
2479 
2480  // Create a symbol. If name is not empty, it will be used as the description.
2481  static Local<Symbol> New(Isolate* isolate,
2482  Local<String> name = Local<String>());
2483 
2484  // Access global symbol registry.
2485  // Note that symbols created this way are never collected, so
2486  // they should only be used for statically fixed properties.
2487  // Also, there is only one global name space for the names used as keys.
2488  // To minimize the potential for clashes, use qualified names as keys.
2489  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2490 
2491  // Retrieve a global symbol. Similar to |For|, but using a separate
2492  // registry that is not accessible by (and cannot clash with) JavaScript code.
2493  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2494 
2495  // Well-known symbols
2496  static Local<Symbol> GetIterator(Isolate* isolate);
2497  static Local<Symbol> GetUnscopables(Isolate* isolate);
2498  static Local<Symbol> GetToStringTag(Isolate* isolate);
2499  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
2500 
2501  V8_INLINE static Symbol* Cast(v8::Value* obj);
2502 
2503  private:
2504  Symbol();
2505  static void CheckCast(v8::Value* obj);
2506 };
2507 
2508 
2514 class V8_EXPORT Private : public Data {
2515  public:
2516  // Returns the print name string of the private symbol, or undefined if none.
2517  Local<Value> Name() const;
2518 
2519  // Create a private symbol. If name is not empty, it will be the description.
2520  static Local<Private> New(Isolate* isolate,
2521  Local<String> name = Local<String>());
2522 
2523  // Retrieve a global private symbol. If a symbol with this name has not
2524  // been retrieved in the same isolate before, it is created.
2525  // Note that private symbols created this way are never collected, so
2526  // they should only be used for statically fixed properties.
2527  // Also, there is only one global name space for the names used as keys.
2528  // To minimize the potential for clashes, use qualified names as keys,
2529  // e.g., "Class#property".
2530  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
2531 
2532  private:
2533  Private();
2534 };
2535 
2536 
2540 class V8_EXPORT Number : public Primitive {
2541  public:
2542  double Value() const;
2543  static Local<Number> New(Isolate* isolate, double value);
2544  V8_INLINE static Number* Cast(v8::Value* obj);
2545  private:
2546  Number();
2547  static void CheckCast(v8::Value* obj);
2548 };
2549 
2550 
2554 class V8_EXPORT Integer : public Number {
2555  public:
2556  static Local<Integer> New(Isolate* isolate, int32_t value);
2557  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2558  int64_t Value() const;
2559  V8_INLINE static Integer* Cast(v8::Value* obj);
2560  private:
2561  Integer();
2562  static void CheckCast(v8::Value* obj);
2563 };
2564 
2565 
2569 class V8_EXPORT Int32 : public Integer {
2570  public:
2571  int32_t Value() const;
2572  V8_INLINE static Int32* Cast(v8::Value* obj);
2573 
2574  private:
2575  Int32();
2576  static void CheckCast(v8::Value* obj);
2577 };
2578 
2579 
2583 class V8_EXPORT Uint32 : public Integer {
2584  public:
2585  uint32_t Value() const;
2586  V8_INLINE static Uint32* Cast(v8::Value* obj);
2587 
2588  private:
2589  Uint32();
2590  static void CheckCast(v8::Value* obj);
2591 };
2592 
2593 
2595  None = 0,
2596  ReadOnly = 1 << 0,
2597  DontEnum = 1 << 1,
2598  DontDelete = 1 << 2
2599 };
2600 
2606 typedef void (*AccessorGetterCallback)(
2607  Local<String> property,
2608  const PropertyCallbackInfo<Value>& info);
2610  Local<Name> property,
2611  const PropertyCallbackInfo<Value>& info);
2612 
2613 
2614 typedef void (*AccessorSetterCallback)(
2615  Local<String> property,
2616  Local<Value> value,
2617  const PropertyCallbackInfo<void>& info);
2619  Local<Name> property,
2620  Local<Value> value,
2621  const PropertyCallbackInfo<void>& info);
2622 
2623 
2634  DEFAULT = 0,
2636  ALL_CAN_WRITE = 1 << 1,
2638 };
2639 
2640 
2644 class V8_EXPORT Object : public Value {
2645  public:
2646  V8_DEPRECATE_SOON("Use maybe version",
2647  bool Set(Local<Value> key, Local<Value> value));
2649  Local<Value> key, Local<Value> value);
2650 
2651  V8_DEPRECATE_SOON("Use maybe version",
2652  bool Set(uint32_t index, Local<Value> value));
2653  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
2654  Local<Value> value);
2655 
2656  // Implements CreateDataProperty (ECMA-262, 7.3.4).
2657  //
2658  // Defines a configurable, writable, enumerable property with the given value
2659  // on the object unless the property already exists and is not configurable
2660  // or the object is not extensible.
2661  //
2662  // Returns true on success.
2663  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2664  Local<Name> key,
2665  Local<Value> value);
2666  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2667  uint32_t index,
2668  Local<Value> value);
2669 
2670  // Implements DefineOwnProperty.
2671  //
2672  // In general, CreateDataProperty will be faster, however, does not allow
2673  // for specifying attributes.
2674  //
2675  // Returns true on success.
2676  V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
2677  Local<Context> context, Local<Name> key, Local<Value> value,
2678  PropertyAttribute attributes = None);
2679 
2680  // Sets an own property on this object bypassing interceptors and
2681  // overriding accessors or read-only properties.
2682  //
2683  // Note that if the object has an interceptor the property will be set
2684  // locally, but since the interceptor takes precedence the local property
2685  // will only be returned if the interceptor doesn't return a value.
2686  //
2687  // Note also that this only works for named properties.
2688  V8_DEPRECATED("Use CreateDataProperty / DefineOwnProperty",
2689  bool ForceSet(Local<Value> key, Local<Value> value,
2690  PropertyAttribute attribs = None));
2691  V8_DEPRECATE_SOON("Use CreateDataProperty / DefineOwnProperty",
2692  Maybe<bool> ForceSet(Local<Context> context,
2693  Local<Value> key, Local<Value> value,
2694  PropertyAttribute attribs = None));
2695 
2696  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
2698  Local<Value> key);
2699 
2700  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
2702  uint32_t index);
2703 
2709  V8_DEPRECATED("Use maybe version",
2710  PropertyAttribute GetPropertyAttributes(Local<Value> key));
2711  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
2712  Local<Context> context, Local<Value> key);
2713 
2717  V8_DEPRECATED("Use maybe version",
2718  Local<Value> GetOwnPropertyDescriptor(Local<String> key));
2719  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
2720  Local<Context> context, Local<String> key);
2721 
2722  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
2724  Local<Value> key);
2725 
2726  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
2727  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2728  Maybe<bool> Delete(Local<Context> context, Local<Value> key);
2729 
2730  V8_DEPRECATED("Use maybe version", bool Has(uint32_t index));
2731  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
2732 
2733  V8_DEPRECATED("Use maybe version", bool Delete(uint32_t index));
2734  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2735  Maybe<bool> Delete(Local<Context> context, uint32_t index);
2736 
2737  V8_DEPRECATED("Use maybe version",
2738  bool SetAccessor(Local<String> name,
2739  AccessorGetterCallback getter,
2740  AccessorSetterCallback setter = 0,
2741  Local<Value> data = Local<Value>(),
2742  AccessControl settings = DEFAULT,
2743  PropertyAttribute attribute = None));
2744  V8_DEPRECATED("Use maybe version",
2745  bool SetAccessor(Local<Name> name,
2747  AccessorNameSetterCallback setter = 0,
2748  Local<Value> data = Local<Value>(),
2749  AccessControl settings = DEFAULT,
2750  PropertyAttribute attribute = None));
2751  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
2752  Maybe<bool> SetAccessor(Local<Context> context, Local<Name> name,
2754  AccessorNameSetterCallback setter = 0,
2756  AccessControl settings = DEFAULT,
2757  PropertyAttribute attribute = None);
2758 
2759  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
2760  Local<Function> setter = Local<Function>(),
2761  PropertyAttribute attribute = None,
2762  AccessControl settings = DEFAULT);
2763 
2770  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
2771  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
2772  Local<Value> value);
2773  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
2774  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
2775 
2782  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
2783  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
2784  Local<Context> context);
2785 
2791  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
2792  V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
2793  Local<Context> context);
2794 
2800  Local<Value> GetPrototype();
2801 
2807  V8_DEPRECATED("Use maybe version", bool SetPrototype(Local<Value> prototype));
2808  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
2809  Local<Value> prototype);
2810 
2815  Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
2816 
2822  V8_DEPRECATED("Use maybe version", Local<String> ObjectProtoToString());
2823  V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
2824  Local<Context> context);
2825 
2829  Local<String> GetConstructorName();
2830 
2832  int InternalFieldCount();
2833 
2836  const PersistentBase<Object>& object) {
2837  return object.val_->InternalFieldCount();
2838  }
2839 
2841  V8_INLINE Local<Value> GetInternalField(int index);
2842 
2844  void SetInternalField(int index, Local<Value> value);
2845 
2851  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
2852 
2855  const PersistentBase<Object>& object, int index) {
2856  return object.val_->GetAlignedPointerFromInternalField(index);
2857  }
2858 
2864  void SetAlignedPointerInInternalField(int index, void* value);
2865 
2866  // Testers for local properties.
2867  V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
2868  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
2869  Local<Name> key);
2870  V8_DEPRECATE_SOON("Use maybe version",
2871  bool HasRealNamedProperty(Local<String> key));
2872  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
2873  Local<Name> key);
2874  V8_DEPRECATE_SOON("Use maybe version",
2875  bool HasRealIndexedProperty(uint32_t index));
2876  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
2877  Local<Context> context, uint32_t index);
2878  V8_DEPRECATE_SOON("Use maybe version",
2879  bool HasRealNamedCallbackProperty(Local<String> key));
2880  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
2881  Local<Context> context, Local<Name> key);
2882 
2887  V8_DEPRECATED(
2888  "Use maybe version",
2889  Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
2890  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
2891  Local<Context> context, Local<Name> key);
2892 
2898  V8_DEPRECATED(
2899  "Use maybe version",
2900  Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
2901  Local<String> key));
2903  GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
2904  Local<Name> key);
2905 
2911  V8_DEPRECATED("Use maybe version",
2912  Local<Value> GetRealNamedProperty(Local<String> key));
2913  V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
2914  Local<Context> context, Local<Name> key);
2915 
2921  V8_DEPRECATED("Use maybe version",
2922  Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
2923  Local<String> key));
2924  V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
2925  Local<Context> context, Local<Name> key);
2926 
2928  bool HasNamedLookupInterceptor();
2929 
2931  bool HasIndexedLookupInterceptor();
2932 
2940  int GetIdentityHash();
2941 
2942  V8_DEPRECATED("Use v8::Object::SetPrivate instead.",
2943  bool SetHiddenValue(Local<String> key, Local<Value> value));
2944  V8_DEPRECATED("Use v8::Object::GetPrivate instead.",
2945  Local<Value> GetHiddenValue(Local<String> key));
2946  V8_DEPRECATED("Use v8::Object::DeletePrivate instead.",
2947  bool DeleteHiddenValue(Local<String> key));
2948 
2953  // TODO(dcarney): take an isolate and optionally bail out?
2954  Local<Object> Clone();
2955 
2959  Local<Context> CreationContext();
2960 
2966  bool IsCallable();
2967 
2972  V8_DEPRECATED("Use maybe version",
2973  Local<Value> CallAsFunction(Local<Value> recv, int argc,
2974  Local<Value> argv[]));
2976  Local<Value> recv,
2977  int argc,
2978  Local<Value> argv[]);
2979 
2985  V8_DEPRECATED("Use maybe version",
2986  Local<Value> CallAsConstructor(int argc, Local<Value> argv[]));
2987  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
2988  Local<Context> context, int argc, Local<Value> argv[]);
2989 
2993  V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
2994 
2995  static Local<Object> New(Isolate* isolate);
2996 
2997  V8_INLINE static Object* Cast(Value* obj);
2998 
2999  private:
3000  Object();
3001  static void CheckCast(Value* obj);
3002  Local<Value> SlowGetInternalField(int index);
3003  void* SlowGetAlignedPointerFromInternalField(int index);
3004 };
3005 
3006 
3010 class V8_EXPORT Array : public Object {
3011  public:
3012  uint32_t Length() const;
3013 
3018  V8_DEPRECATED("Cloning is not supported.",
3019  Local<Object> CloneElementAt(uint32_t index));
3020  V8_DEPRECATED("Cloning is not supported.",
3021  MaybeLocal<Object> CloneElementAt(Local<Context> context,
3022  uint32_t index));
3023 
3028  static Local<Array> New(Isolate* isolate, int length = 0);
3029 
3030  V8_INLINE static Array* Cast(Value* obj);
3031  private:
3032  Array();
3033  static void CheckCast(Value* obj);
3034 };
3035 
3036 
3040 class V8_EXPORT Map : public Object {
3041  public:
3042  size_t Size() const;
3043  void Clear();
3045  Local<Value> key);
3047  Local<Value> key,
3048  Local<Value> value);
3050  Local<Value> key);
3052  Local<Value> key);
3053 
3058  Local<Array> AsArray() const;
3059 
3063  static Local<Map> New(Isolate* isolate);
3064 
3065  V8_INLINE static Map* Cast(Value* obj);
3066 
3067  private:
3068  Map();
3069  static void CheckCast(Value* obj);
3070 };
3071 
3072 
3076 class V8_EXPORT Set : public Object {
3077  public:
3078  size_t Size() const;
3079  void Clear();
3081  Local<Value> key);
3083  Local<Value> key);
3085  Local<Value> key);
3086 
3090  Local<Array> AsArray() const;
3091 
3095  static Local<Set> New(Isolate* isolate);
3096 
3097  V8_INLINE static Set* Cast(Value* obj);
3098 
3099  private:
3100  Set();
3101  static void CheckCast(Value* obj);
3102 };
3103 
3104 
3105 template<typename T>
3106 class ReturnValue {
3107  public:
3108  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3109  : value_(that.value_) {
3110  TYPE_CHECK(T, S);
3111  }
3112  // Local setters
3113  template <typename S>
3114  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3115  void Set(const Persistent<S>& handle));
3116  template <typename S>
3117  V8_INLINE void Set(const Global<S>& handle);
3118  template <typename S>
3119  V8_INLINE void Set(const Local<S> handle);
3120  // Fast primitive setters
3121  V8_INLINE void Set(bool value);
3122  V8_INLINE void Set(double i);
3123  V8_INLINE void Set(int32_t i);
3124  V8_INLINE void Set(uint32_t i);
3125  // Fast JS primitive setters
3126  V8_INLINE void SetNull();
3127  V8_INLINE void SetUndefined();
3128  V8_INLINE void SetEmptyString();
3129  // Convenience getter for Isolate
3131 
3132  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3133  template <typename S>
3134  V8_INLINE void Set(S* whatever);
3135 
3136  private:
3137  template<class F> friend class ReturnValue;
3138  template<class F> friend class FunctionCallbackInfo;
3139  template<class F> friend class PropertyCallbackInfo;
3140  template <class F, class G, class H>
3142  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3143  V8_INLINE internal::Object* GetDefaultValue();
3144  V8_INLINE explicit ReturnValue(internal::Object** slot);
3145  internal::Object** value_;
3146 };
3147 
3148 
3155 template<typename T>
3156 class FunctionCallbackInfo {
3157  public:
3158  V8_INLINE int Length() const;
3159  V8_INLINE Local<Value> operator[](int i) const;
3160  V8_INLINE V8_DEPRECATED("Use Data() to explicitly pass Callee instead",
3161  Local<Function> Callee() const);
3162  V8_INLINE Local<Object> This() const;
3163  V8_INLINE Local<Object> Holder() const;
3164  V8_INLINE bool IsConstructCall() const;
3165  V8_INLINE Local<Value> Data() const;
3166  V8_INLINE Isolate* GetIsolate() const;
3167  V8_INLINE ReturnValue<T> GetReturnValue() const;
3168  // This shouldn't be public, but the arm compiler needs it.
3169  static const int kArgsLength = 7;
3170 
3171  protected:
3174  static const int kHolderIndex = 0;
3175  static const int kIsolateIndex = 1;
3176  static const int kReturnValueDefaultValueIndex = 2;
3177  static const int kReturnValueIndex = 3;
3178  static const int kDataIndex = 4;
3179  static const int kCalleeIndex = 5;
3180  static const int kContextSaveIndex = 6;
3181 
3182  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3183  internal::Object** values,
3184  int length,
3185  bool is_construct_call);
3186  internal::Object** implicit_args_;
3187  internal::Object** values_;
3188  int length_;
3190 };
3191 
3192 
3197 template<typename T>
3198 class PropertyCallbackInfo {
3199  public:
3200  V8_INLINE Isolate* GetIsolate() const;
3201  V8_INLINE Local<Value> Data() const;
3202  V8_INLINE Local<Object> This() const;
3203  V8_INLINE Local<Object> Holder() const;
3205  V8_INLINE bool ShouldThrowOnError() const;
3206  // This shouldn't be public, but the arm compiler needs it.
3207  static const int kArgsLength = 7;
3208 
3209  protected:
3210  friend class MacroAssembler;
3211  friend class internal::PropertyCallbackArguments;
3213  static const int kShouldThrowOnErrorIndex = 0;
3214  static const int kHolderIndex = 1;
3215  static const int kIsolateIndex = 2;
3216  static const int kReturnValueDefaultValueIndex = 3;
3217  static const int kReturnValueIndex = 4;
3218  static const int kDataIndex = 5;
3219  static const int kThisIndex = 6;
3220 
3221  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
3222  internal::Object** args_;
3223 };
3224 
3225 
3226 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3227 
3228 
3232 class V8_EXPORT Function : public Object {
3233  public:
3238  static MaybeLocal<Function> New(Local<Context> context,
3239  FunctionCallback callback,
3240  Local<Value> data = Local<Value>(),
3241  int length = 0);
3242  static V8_DEPRECATE_SOON(
3243  "Use maybe version",
3244  Local<Function> New(Isolate* isolate, FunctionCallback callback,
3245  Local<Value> data = Local<Value>(), int length = 0));
3246 
3247  V8_DEPRECATED("Use maybe version",
3248  Local<Object> NewInstance(int argc, Local<Value> argv[]) const);
3250  Local<Context> context, int argc, Local<Value> argv[]) const;
3251 
3252  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
3254  Local<Context> context) const {
3255  return NewInstance(context, 0, nullptr);
3256  }
3257 
3258  V8_DEPRECATE_SOON("Use maybe version",
3259  Local<Value> Call(Local<Value> recv, int argc,
3260  Local<Value> argv[]));
3262  Local<Value> recv, int argc,
3263  Local<Value> argv[]);
3264 
3265  void SetName(Local<String> name);
3266  Local<Value> GetName() const;
3267 
3274  Local<Value> GetInferredName() const;
3275 
3280  Local<Value> GetDebugName() const;
3281 
3286  Local<Value> GetDisplayName() const;
3287 
3292  int GetScriptLineNumber() const;
3297  int GetScriptColumnNumber() const;
3298 
3302  bool IsBuiltin() const;
3303 
3307  int ScriptId() const;
3308 
3313  Local<Value> GetBoundFunction() const;
3314 
3315  ScriptOrigin GetScriptOrigin() const;
3316  V8_INLINE static Function* Cast(Value* obj);
3317  static const int kLineOffsetNotFound;
3318 
3319  private:
3320  Function();
3321  static void CheckCast(Value* obj);
3322 };
3323 
3324 
3329 class V8_EXPORT Promise : public Object {
3330  public:
3331  class V8_EXPORT Resolver : public Object {
3332  public:
3336  static V8_DEPRECATE_SOON("Use maybe version",
3337  Local<Resolver> New(Isolate* isolate));
3339  Local<Context> context);
3340 
3344  Local<Promise> GetPromise();
3345 
3350  V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
3351  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3352  Maybe<bool> Resolve(Local<Context> context, Local<Value> value);
3353 
3354  V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
3355  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3356  Maybe<bool> Reject(Local<Context> context, Local<Value> value);
3357 
3358  V8_INLINE static Resolver* Cast(Value* obj);
3359 
3360  private:
3361  Resolver();
3362  static void CheckCast(Value* obj);
3363  };
3364 
3371  V8_DEPRECATED("Use maybe version of Then",
3372  Local<Promise> Chain(Local<Function> handler));
3373  V8_DEPRECATED("Use Then",
3375  Local<Context> context, Local<Function> handler));
3376 
3377  V8_DEPRECATED("Use maybe version",
3378  Local<Promise> Catch(Local<Function> handler));
3380  Local<Function> handler);
3381 
3382  V8_DEPRECATED("Use maybe version",
3383  Local<Promise> Then(Local<Function> handler));
3385  Local<Function> handler);
3386 
3391  bool HasHandler();
3392 
3393  V8_INLINE static Promise* Cast(Value* obj);
3394 
3395  private:
3396  Promise();
3397  static void CheckCast(Value* obj);
3398 };
3399 
3400 
3405 class V8_EXPORT Proxy : public Object {
3406  public:
3407  Local<Object> GetTarget();
3408  Local<Value> GetHandler();
3409  bool IsRevoked();
3410  void Revoke();
3411 
3415  static MaybeLocal<Proxy> New(Local<Context> context,
3416  Local<Object> local_target,
3417  Local<Object> local_handler);
3418 
3419  V8_INLINE static Proxy* Cast(Value* obj);
3420 
3421  private:
3422  Proxy();
3423  static void CheckCast(Value* obj);
3424 };
3425 
3426 
3427 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
3428 // The number of required internal fields can be defined by embedder.
3429 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
3430 #endif
3431 
3432 
3434 
3435 
3440 class V8_EXPORT ArrayBuffer : public Object {
3441  public:
3449  class V8_EXPORT Allocator { // NOLINT
3450  public:
3451  virtual ~Allocator() {}
3452 
3457  virtual void* Allocate(size_t length) = 0;
3458 
3463  virtual void* AllocateUninitialized(size_t length) = 0;
3468  virtual void Free(void* data, size_t length) = 0;
3469  };
3470 
3481  class V8_EXPORT Contents { // NOLINT
3482  public:
3483  Contents() : data_(NULL), byte_length_(0) {}
3484 
3485  void* Data() const { return data_; }
3486  size_t ByteLength() const { return byte_length_; }
3487 
3488  private:
3489  void* data_;
3490  size_t byte_length_;
3491 
3492  friend class ArrayBuffer;
3493  };
3494 
3495 
3499  size_t ByteLength() const;
3500 
3507  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
3508 
3515  static Local<ArrayBuffer> New(
3516  Isolate* isolate, void* data, size_t byte_length,
3518 
3523  bool IsExternal() const;
3524 
3528  bool IsNeuterable() const;
3529 
3536  void Neuter();
3537 
3547  Contents Externalize();
3548 
3559  Contents GetContents();
3560 
3561  V8_INLINE static ArrayBuffer* Cast(Value* obj);
3562 
3563  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
3564 
3565  private:
3566  ArrayBuffer();
3567  static void CheckCast(Value* obj);
3568 };
3569 
3570 
3571 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
3572 // The number of required internal fields can be defined by embedder.
3573 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
3574 #endif
3575 
3576 
3584  public:
3588  Local<ArrayBuffer> Buffer();
3592  size_t ByteOffset();
3596  size_t ByteLength();
3597 
3607  size_t CopyContents(void* dest, size_t byte_length);
3608 
3613  bool HasBuffer() const;
3614 
3615  V8_INLINE static ArrayBufferView* Cast(Value* obj);
3616 
3617  static const int kInternalFieldCount =
3619 
3620  private:
3621  ArrayBufferView();
3622  static void CheckCast(Value* obj);
3623 };
3624 
3625 
3632  public:
3637  size_t Length();
3638 
3639  V8_INLINE static TypedArray* Cast(Value* obj);
3640 
3641  private:
3642  TypedArray();
3643  static void CheckCast(Value* obj);
3644 };
3645 
3646 
3652  public:
3653  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
3654  size_t byte_offset, size_t length);
3655  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3656  size_t byte_offset, size_t length);
3657  V8_INLINE static Uint8Array* Cast(Value* obj);
3658 
3659  private:
3660  Uint8Array();
3661  static void CheckCast(Value* obj);
3662 };
3663 
3664 
3670  public:
3671  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
3672  size_t byte_offset, size_t length);
3673  static Local<Uint8ClampedArray> New(
3674  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
3675  size_t length);
3676  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
3677 
3678  private:
3680  static void CheckCast(Value* obj);
3681 };
3682 
3688  public:
3689  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
3690  size_t byte_offset, size_t length);
3691  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3692  size_t byte_offset, size_t length);
3693  V8_INLINE static Int8Array* Cast(Value* obj);
3694 
3695  private:
3696  Int8Array();
3697  static void CheckCast(Value* obj);
3698 };
3699 
3700 
3706  public:
3707  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
3708  size_t byte_offset, size_t length);
3709  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3710  size_t byte_offset, size_t length);
3711  V8_INLINE static Uint16Array* Cast(Value* obj);
3712 
3713  private:
3714  Uint16Array();
3715  static void CheckCast(Value* obj);
3716 };
3717 
3718 
3724  public:
3725  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
3726  size_t byte_offset, size_t length);
3727  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3728  size_t byte_offset, size_t length);
3729  V8_INLINE static Int16Array* Cast(Value* obj);
3730 
3731  private:
3732  Int16Array();
3733  static void CheckCast(Value* obj);
3734 };
3735 
3736 
3742  public:
3743  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
3744  size_t byte_offset, size_t length);
3745  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3746  size_t byte_offset, size_t length);
3747  V8_INLINE static Uint32Array* Cast(Value* obj);
3748 
3749  private:
3750  Uint32Array();
3751  static void CheckCast(Value* obj);
3752 };
3753 
3754 
3760  public:
3761  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
3762  size_t byte_offset, size_t length);
3763  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3764  size_t byte_offset, size_t length);
3765  V8_INLINE static Int32Array* Cast(Value* obj);
3766 
3767  private:
3768  Int32Array();
3769  static void CheckCast(Value* obj);
3770 };
3771 
3772 
3778  public:
3779  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
3780  size_t byte_offset, size_t length);
3781  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3782  size_t byte_offset, size_t length);
3783  V8_INLINE static Float32Array* Cast(Value* obj);
3784 
3785  private:
3786  Float32Array();
3787  static void CheckCast(Value* obj);
3788 };
3789 
3790 
3796  public:
3797  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
3798  size_t byte_offset, size_t length);
3799  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
3800  size_t byte_offset, size_t length);
3801  V8_INLINE static Float64Array* Cast(Value* obj);
3802 
3803  private:
3804  Float64Array();
3805  static void CheckCast(Value* obj);
3806 };
3807 
3808 
3814  public:
3815  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
3816  size_t byte_offset, size_t length);
3817  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
3818  size_t byte_offset, size_t length);
3819  V8_INLINE static DataView* Cast(Value* obj);
3820 
3821  private:
3822  DataView();
3823  static void CheckCast(Value* obj);
3824 };
3825 
3826 
3832  public:
3844  class V8_EXPORT Contents { // NOLINT
3845  public:
3846  Contents() : data_(NULL), byte_length_(0) {}
3847 
3848  void* Data() const { return data_; }
3849  size_t ByteLength() const { return byte_length_; }
3850 
3851  private:
3852  void* data_;
3853  size_t byte_length_;
3854 
3855  friend class SharedArrayBuffer;
3856  };
3857 
3858 
3862  size_t ByteLength() const;
3863 
3870  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
3871 
3878  static Local<SharedArrayBuffer> New(
3879  Isolate* isolate, void* data, size_t byte_length,
3881 
3886  bool IsExternal() const;
3887 
3900  Contents Externalize();
3901 
3914  Contents GetContents();
3915 
3916  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
3917 
3918  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
3919 
3920  private:
3922  static void CheckCast(Value* obj);
3923 };
3924 
3925 
3929 class V8_EXPORT Date : public Object {
3930  public:
3931  static V8_DEPRECATE_SOON("Use maybe version.",
3932  Local<Value> New(Isolate* isolate, double time));
3934  double time);
3935 
3940  double ValueOf() const;
3941 
3942  V8_INLINE static Date* Cast(v8::Value* obj);
3943 
3956  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
3957 
3958  private:
3959  static void CheckCast(v8::Value* obj);
3960 };
3961 
3962 
3967  public:
3968  static Local<Value> New(Isolate* isolate, double value);
3969 
3970  double ValueOf() const;
3971 
3972  V8_INLINE static NumberObject* Cast(v8::Value* obj);
3973 
3974  private:
3975  static void CheckCast(v8::Value* obj);
3976 };
3977 
3978 
3983  public:
3984  static Local<Value> New(Isolate* isolate, bool value);
3985  V8_DEPRECATED("Pass an isolate", static Local<Value> New(bool value));
3986 
3987  bool ValueOf() const;
3988 
3989  V8_INLINE static BooleanObject* Cast(v8::Value* obj);
3990 
3991  private:
3992  static void CheckCast(v8::Value* obj);
3993 };
3994 
3995 
4000  public:
4001  static Local<Value> New(Local<String> value);
4002 
4003  Local<String> ValueOf() const;
4004 
4005  V8_INLINE static StringObject* Cast(v8::Value* obj);
4006 
4007  private:
4008  static void CheckCast(v8::Value* obj);
4009 };
4010 
4011 
4018  public:
4019  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
4020 
4021  Local<Symbol> ValueOf() const;
4022 
4023  V8_INLINE static SymbolObject* Cast(v8::Value* obj);
4024 
4025  private:
4026  static void CheckCast(v8::Value* obj);
4027 };
4028 
4029 
4033 class V8_EXPORT RegExp : public Object {
4034  public:
4039  enum Flags {
4040  kNone = 0,
4041  kGlobal = 1,
4042  kIgnoreCase = 2,
4043  kMultiline = 4,
4044  kSticky = 8,
4045  kUnicode = 16
4046  };
4047 
4058  static V8_DEPRECATE_SOON("Use maybe version",
4059  Local<RegExp> New(Local<String> pattern,
4060  Flags flags));
4062  Local<String> pattern,
4063  Flags flags);
4064 
4069  Local<String> GetSource() const;
4070 
4074  Flags GetFlags() const;
4075 
4076  V8_INLINE static RegExp* Cast(v8::Value* obj);
4077 
4078  private:
4079  static void CheckCast(v8::Value* obj);
4080 };
4081 
4082 
4087 class V8_EXPORT External : public Value {
4088  public:
4089  static Local<External> New(Isolate* isolate, void* value);
4090  V8_INLINE static External* Cast(Value* obj);
4091  void* Value() const;
4092  private:
4093  static void CheckCast(v8::Value* obj);
4094 };
4095 
4096 
4097 #define V8_INTRINSICS_LIST(F) F(ArrayProto_values, array_values_iterator)
4098 
4100 #define V8_DECL_INTRINSIC(name, iname) k##name,
4102 #undef V8_DECL_INTRINSIC
4103 };
4104 
4105 
4106 // --- Templates ---
4107 
4108 
4112 class V8_EXPORT Template : public Data {
4113  public:
4115  void Set(Local<Name> name, Local<Data> value,
4116  PropertyAttribute attributes = None);
4117  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
4118 
4119  void SetAccessorProperty(
4120  Local<Name> name,
4123  PropertyAttribute attribute = None,
4124  AccessControl settings = DEFAULT);
4125 
4153  void SetNativeDataProperty(
4155  AccessorSetterCallback setter = 0,
4156  // TODO(dcarney): gcc can't handle Local below
4157  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4159  AccessControl settings = DEFAULT);
4160  void SetNativeDataProperty(
4162  AccessorNameSetterCallback setter = 0,
4163  // TODO(dcarney): gcc can't handle Local below
4164  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4166  AccessControl settings = DEFAULT);
4167 
4172  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
4173  PropertyAttribute attribute = None);
4174 
4175  private:
4176  Template();
4177 
4178  friend class ObjectTemplate;
4179  friend class FunctionTemplate;
4180 };
4181 
4182 
4188  Local<String> property,
4189  const PropertyCallbackInfo<Value>& info);
4190 
4191 
4197  Local<String> property,
4198  Local<Value> value,
4199  const PropertyCallbackInfo<Value>& info);
4200 
4201 
4208  Local<String> property,
4209  const PropertyCallbackInfo<Integer>& info);
4210 
4211 
4218  Local<String> property,
4219  const PropertyCallbackInfo<Boolean>& info);
4220 
4221 
4227  const PropertyCallbackInfo<Array>& info);
4228 
4229 
4230 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
4231 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
4237  Local<Name> property, const PropertyCallbackInfo<Value>& info);
4238 
4239 
4245  Local<Name> property, Local<Value> value,
4246  const PropertyCallbackInfo<Value>& info);
4247 
4248 
4255  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
4256 
4257 
4264  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
4265 
4266 
4272  const PropertyCallbackInfo<Array>& info);
4273 
4274 
4280  uint32_t index,
4281  const PropertyCallbackInfo<Value>& info);
4282 
4283 
4289  uint32_t index,
4290  Local<Value> value,
4291  const PropertyCallbackInfo<Value>& info);
4292 
4293 
4299  uint32_t index,
4300  const PropertyCallbackInfo<Integer>& info);
4301 
4302 
4309  uint32_t index,
4310  const PropertyCallbackInfo<Boolean>& info);
4311 
4312 
4318  const PropertyCallbackInfo<Array>& info);
4319 
4320 
4330 };
4331 
4332 
4337 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
4338  Local<Object> accessed_object,
4339  Local<Value> data);
4340 typedef bool (*DeprecatedAccessCheckCallback)(Local<Context> accessing_context,
4341  Local<Object> accessed_object);
4342 
4348  Local<Value> key,
4349  AccessType type,
4350  Local<Value> data);
4351 
4352 
4358  uint32_t index,
4359  AccessType type,
4360  Local<Value> data);
4361 
4362 
4459  public:
4461  static Local<FunctionTemplate> New(
4462  Isolate* isolate, FunctionCallback callback = 0,
4463  Local<Value> data = Local<Value>(),
4464  Local<Signature> signature = Local<Signature>(), int length = 0);
4465 
4470  static Local<FunctionTemplate> NewWithFastHandler(
4471  Isolate* isolate, FunctionCallback callback,
4472  experimental::FastAccessorBuilder* fast_handler = nullptr,
4473  Local<Value> data = Local<Value>(),
4474  Local<Signature> signature = Local<Signature>(), int length = 0);
4475 
4477  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
4479  Local<Context> context);
4480 
4486  void SetCallHandler(
4487  FunctionCallback callback, Local<Value> data = Local<Value>(),
4488  experimental::FastAccessorBuilder* fast_handler = nullptr);
4489 
4491  void SetLength(int length);
4492 
4494  Local<ObjectTemplate> InstanceTemplate();
4495 
4497  void Inherit(Local<FunctionTemplate> parent);
4498 
4503  Local<ObjectTemplate> PrototypeTemplate();
4504 
4510  void SetClassName(Local<String> name);
4511 
4512 
4517  void SetAcceptAnyReceiver(bool value);
4518 
4531  void SetHiddenPrototype(bool value);
4532 
4537  void ReadOnlyPrototype();
4538 
4543  void RemovePrototype();
4544 
4549  bool HasInstance(Local<Value> object);
4550 
4551  private:
4552  FunctionTemplate();
4553  friend class Context;
4554  friend class ObjectTemplate;
4555 };
4556 
4557 
4559  kNone = 0,
4560  // See ALL_CAN_READ above.
4561  kAllCanRead = 1,
4562  // Will not call into interceptor for properties on the receiver or prototype
4563  // chain. Currently only valid for named interceptors.
4564  kNonMasking = 1 << 1,
4565  // Will not call into interceptor for symbol lookup. Only meaningful for
4566  // named interceptors.
4567  kOnlyInterceptStrings = 1 << 2,
4568 };
4569 
4570 
4581  : getter(getter),
4582  setter(setter),
4583  query(query),
4584  deleter(deleter),
4586  data(data),
4587  flags(flags) {}
4588 
4596 };
4597 
4598 
4609  : getter(getter),
4610  setter(setter),
4611  query(query),
4612  deleter(deleter),
4614  data(data),
4615  flags(flags) {}
4616 
4624 };
4625 
4626 
4634  public:
4636  static Local<ObjectTemplate> New(
4637  Isolate* isolate,
4639  static V8_DEPRECATED("Use isolate version", Local<ObjectTemplate> New());
4640 
4642  V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
4644 
4674  void SetAccessor(
4676  AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
4677  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
4679  void SetAccessor(
4682  AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
4684 
4705  // TODO(dcarney): deprecate
4706  void SetNamedPropertyHandler(NamedPropertyGetterCallback getter,
4707  NamedPropertySetterCallback setter = 0,
4708  NamedPropertyQueryCallback query = 0,
4709  NamedPropertyDeleterCallback deleter = 0,
4710  NamedPropertyEnumeratorCallback enumerator = 0,
4711  Local<Value> data = Local<Value>());
4712  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
4713 
4730  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
4731  // TODO(dcarney): deprecate
4734  IndexedPropertySetterCallback setter = 0,
4735  IndexedPropertyQueryCallback query = 0,
4736  IndexedPropertyDeleterCallback deleter = 0,
4737  IndexedPropertyEnumeratorCallback enumerator = 0,
4738  Local<Value> data = Local<Value>()) {
4739  SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
4740  deleter, enumerator, data));
4741  }
4748  void SetCallAsFunctionHandler(FunctionCallback callback,
4749  Local<Value> data = Local<Value>());
4750 
4759  void MarkAsUndetectable();
4760 
4769  void SetAccessCheckCallback(AccessCheckCallback callback,
4770  Local<Value> data = Local<Value>());
4771  V8_DEPRECATED(
4772  "Use SetAccessCheckCallback with new AccessCheckCallback signature.",
4773  void SetAccessCheckCallback(DeprecatedAccessCheckCallback callback,
4774  Local<Value> data = Local<Value>()));
4775 
4776  V8_DEPRECATED(
4777  "Use SetAccessCheckCallback instead",
4778  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
4779  IndexedSecurityCallback indexed_handler,
4780  Local<Value> data = Local<Value>()));
4781 
4786  int InternalFieldCount();
4787 
4792  void SetInternalFieldCount(int value);
4793 
4794  private:
4795  ObjectTemplate();
4796  static Local<ObjectTemplate> New(internal::Isolate* isolate,
4797  Local<FunctionTemplate> constructor);
4798  friend class FunctionTemplate;
4799 };
4800 
4801 
4805 class V8_EXPORT Signature : public Data {
4806  public:
4807  static Local<Signature> New(
4808  Isolate* isolate,
4810 
4811  private:
4812  Signature();
4813 };
4814 
4815 
4821  public:
4822  static Local<AccessorSignature> New(
4823  Isolate* isolate,
4825 
4826  private:
4828 };
4829 
4830 
4831 // --- Extensions ---
4832 
4835  public:
4836  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
4837  ExternalOneByteStringResourceImpl(const char* data, size_t length)
4838  : data_(data), length_(length) {}
4839  const char* data() const { return data_; }
4840  size_t length() const { return length_; }
4841 
4842  private:
4843  const char* data_;
4844  size_t length_;
4845 };
4846 
4850 class V8_EXPORT Extension { // NOLINT
4851  public:
4852  // Note that the strings passed into this constructor must live as long
4853  // as the Extension itself.
4854  Extension(const char* name,
4855  const char* source = 0,
4856  int dep_count = 0,
4857  const char** deps = 0,
4858  int source_length = -1);
4859  virtual ~Extension() { }
4861  v8::Isolate* isolate, v8::Local<v8::String> name) {
4863  }
4864 
4865  const char* name() const { return name_; }
4866  size_t source_length() const { return source_length_; }
4868  return &source_; }
4869  int dependency_count() { return dep_count_; }
4870  const char** dependencies() { return deps_; }
4871  void set_auto_enable(bool value) { auto_enable_ = value; }
4872  bool auto_enable() { return auto_enable_; }
4873 
4874  private:
4875  const char* name_;
4876  size_t source_length_; // expected to initialize before source_
4878  int dep_count_;
4879  const char** deps_;
4880  bool auto_enable_;
4881 
4882  // Disallow copying and assigning.
4883  Extension(const Extension&);
4884  void operator=(const Extension&);
4885 };
4886 
4887 
4888 void V8_EXPORT RegisterExtension(Extension* extension);
4889 
4890 
4891 // --- Statics ---
4892 
4893 V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
4894 V8_INLINE Local<Primitive> Null(Isolate* isolate);
4895 V8_INLINE Local<Boolean> True(Isolate* isolate);
4896 V8_INLINE Local<Boolean> False(Isolate* isolate);
4897 
4911  public:
4913 
4923  void ConfigureDefaults(uint64_t physical_memory,
4924  uint64_t virtual_memory_limit);
4925 
4926  int max_semi_space_size() const { return max_semi_space_size_; }
4927  void set_max_semi_space_size(int limit_in_mb) {
4928  max_semi_space_size_ = limit_in_mb;
4929  }
4930  int max_old_space_size() const { return max_old_space_size_; }
4931  void set_max_old_space_size(int limit_in_mb) {
4932  max_old_space_size_ = limit_in_mb;
4933  }
4934  int max_executable_size() const { return max_executable_size_; }
4935  void set_max_executable_size(int limit_in_mb) {
4936  max_executable_size_ = limit_in_mb;
4937  }
4938  uint32_t* stack_limit() const { return stack_limit_; }
4939  // Sets an address beyond which the VM's stack may not grow.
4940  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
4941  size_t code_range_size() const { return code_range_size_; }
4942  void set_code_range_size(size_t limit_in_mb) {
4943  code_range_size_ = limit_in_mb;
4944  }
4945 
4946  private:
4947  int max_semi_space_size_;
4948  int max_old_space_size_;
4949  int max_executable_size_;
4950  uint32_t* stack_limit_;
4951  size_t code_range_size_;
4952 };
4953 
4954 
4955 // --- Exceptions ---
4956 
4957 
4958 typedef void (*FatalErrorCallback)(const char* location, const char* message);
4959 
4960 
4961 typedef void (*MessageCallback)(Local<Message> message, Local<Value> error);
4962 
4963 // --- Tracing ---
4964 
4965 typedef void (*LogEventCallback)(const char* name, int event);
4966 
4972  public:
4973  static Local<Value> RangeError(Local<String> message);
4974  static Local<Value> ReferenceError(Local<String> message);
4975  static Local<Value> SyntaxError(Local<String> message);
4976  static Local<Value> TypeError(Local<String> message);
4977  static Local<Value> Error(Local<String> message);
4978 
4984  static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
4985  V8_DEPRECATED("Use version with an Isolate*",
4986  static Local<Message> CreateMessage(Local<Value> exception));
4987 
4992  static Local<StackTrace> GetStackTrace(Local<Value> exception);
4993 };
4994 
4995 
4996 // --- Counters Callbacks ---
4997 
4998 typedef int* (*CounterLookupCallback)(const char* name);
4999 
5000 typedef void* (*CreateHistogramCallback)(const char* name,
5001  int min,
5002  int max,
5003  size_t buckets);
5004 
5005 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
5006 
5007 // --- Memory Allocation Callback ---
5017 };
5018 
5023  };
5024 
5026  AllocationAction action,
5027  int size);
5028 
5029 // --- Enter/Leave Script Callback ---
5031 typedef void (*CallCompletedCallback)(Isolate*);
5033 
5034 // --- Promise Reject Callback ---
5038 };
5039 
5041  public:
5043  Local<Value> value, Local<StackTrace> stack_trace)
5044  : promise_(promise),
5045  event_(event),
5046  value_(value),
5047  stack_trace_(stack_trace) {}
5048 
5049  V8_INLINE Local<Promise> GetPromise() const { return promise_; }
5050  V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
5051  V8_INLINE Local<Value> GetValue() const { return value_; }
5052 
5053  V8_DEPRECATED("Use v8::Exception::CreateMessage(GetValue())->GetStackTrace()",
5054  V8_INLINE Local<StackTrace> GetStackTrace() const) {
5055  return stack_trace_;
5056  }
5057 
5058  private:
5059  Local<Promise> promise_;
5060  PromiseRejectEvent event_;
5061  Local<Value> value_;
5062  Local<StackTrace> stack_trace_;
5063 };
5064 
5066 
5067 // --- Microtasks Callbacks ---
5069 typedef void (*MicrotaskCallback)(void* data);
5070 
5071 
5080 
5081 
5092  public:
5093  enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
5094 
5095  MicrotasksScope(Isolate* isolate, Type type);
5096  ~MicrotasksScope();
5097 
5101  static void PerformCheckpoint(Isolate* isolate);
5102 
5106  static int GetCurrentDepth(Isolate* isolate);
5107 
5108  private:
5109  internal::Isolate* const isolate_;
5110  bool run_;
5111 
5112  // Prevent copying.
5114  MicrotasksScope& operator=(const MicrotasksScope&);
5115 };
5116 
5117 
5118 // --- Failed Access Check Callback ---
5120  AccessType type,
5121  Local<Value> data);
5122 
5123 // --- AllowCodeGenerationFromStrings callbacks ---
5124 
5130 
5131 // --- Garbage Collection Callbacks ---
5132 
5140 enum GCType {
5147 };
5148 
5167 };
5168 
5169 typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
5170 
5171 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
5172 
5173 
5181  public:
5182  HeapStatistics();
5183  size_t total_heap_size() { return total_heap_size_; }
5184  size_t total_heap_size_executable() { return total_heap_size_executable_; }
5185  size_t total_physical_size() { return total_physical_size_; }
5186  size_t total_available_size() { return total_available_size_; }
5187  size_t used_heap_size() { return used_heap_size_; }
5188  size_t heap_size_limit() { return heap_size_limit_; }
5189  size_t malloced_memory() { return malloced_memory_; }
5190  size_t does_zap_garbage() { return does_zap_garbage_; }
5191 
5192  private:
5193  size_t total_heap_size_;
5194  size_t total_heap_size_executable_;
5195  size_t total_physical_size_;
5196  size_t total_available_size_;
5197  size_t used_heap_size_;
5198  size_t heap_size_limit_;
5199  size_t malloced_memory_;
5200  bool does_zap_garbage_;
5201 
5202  friend class V8;
5203  friend class Isolate;
5204 };
5205 
5206 
5208  public:
5210  const char* space_name() { return space_name_; }
5211  size_t space_size() { return space_size_; }
5212  size_t space_used_size() { return space_used_size_; }
5213  size_t space_available_size() { return space_available_size_; }
5214  size_t physical_space_size() { return physical_space_size_; }
5215 
5216  private:
5217  const char* space_name_;
5218  size_t space_size_;
5219  size_t space_used_size_;
5220  size_t space_available_size_;
5221  size_t physical_space_size_;
5222 
5223  friend class Isolate;
5224 };
5225 
5226 
5228  public:
5230  const char* object_type() { return object_type_; }
5231  const char* object_sub_type() { return object_sub_type_; }
5232  size_t object_count() { return object_count_; }
5233  size_t object_size() { return object_size_; }
5234 
5235  private:
5236  const char* object_type_;
5237  const char* object_sub_type_;
5238  size_t object_count_;
5239  size_t object_size_;
5240 
5241  friend class Isolate;
5242 };
5243 
5244 
5245 class RetainedObjectInfo;
5246 
5247 
5259 typedef void (*FunctionEntryHook)(uintptr_t function,
5260  uintptr_t return_addr_location);
5261 
5268  enum EventType {
5275  };
5276  // Definition of the code position type. The "POSITION" type means the place
5277  // in the source code which are of interest when making stack traces to
5278  // pin-point the source location of a stack frame as close as possible.
5279  // The "STATEMENT_POSITION" means the place at the beginning of each
5280  // statement, and is used to indicate possible break locations.
5282 
5283  // Type of event.
5285  // Start of the instructions.
5286  void* code_start;
5287  // Size of the instructions.
5288  size_t code_len;
5289  // Script info for CODE_ADDED event.
5291  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
5292  // code line information which is returned from the
5293  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
5294  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
5295  void* user_data;
5296 
5297  struct name_t {
5298  // Name of the object associated with the code, note that the string is not
5299  // zero-terminated.
5300  const char* str;
5301  // Number of chars in str.
5302  size_t len;
5303  };
5304 
5305  struct line_info_t {
5306  // PC offset
5307  size_t offset;
5308  // Code postion
5309  size_t pos;
5310  // The position type.
5312  };
5313 
5314  union {
5315  // Only valid for CODE_ADDED.
5316  struct name_t name;
5317 
5318  // Only valid for CODE_ADD_LINE_POS_INFO
5320 
5321  // New location of instructions. Only valid for CODE_MOVED.
5323  };
5324 };
5325 
5331  // Generate callbacks for already existent code.
5333 };
5334 
5335 
5341 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
5342 
5343 
5348  public:
5350  virtual void VisitExternalString(Local<String> string) {}
5351 };
5352 
5353 
5358  public:
5361  uint16_t class_id) {}
5362 };
5363 
5373 
5386  public:
5390  virtual void TraceRoots(Isolate* isolate) = 0;
5391 
5398  virtual void TraceWrappableFrom(
5399  Isolate* isolate,
5400  const std::vector<std::pair<void*, void*> >& internal_fields) = 0;
5405  virtual void ClearTracingMarks(Isolate* isolate) = 0;
5406 
5407  protected:
5408  virtual ~EmbedderHeapTracer() = default;
5409 };
5410 
5420  public:
5424  struct CreateParams {
5426  : entry_hook(NULL),
5427  code_event_handler(NULL),
5428  snapshot_blob(NULL),
5429  counter_lookup_callback(NULL),
5430  create_histogram_callback(NULL),
5431  add_histogram_sample_callback(NULL),
5432  array_buffer_allocator(NULL) {}
5433 
5442 
5448 
5453 
5458 
5459 
5465 
5474 
5480  };
5481 
5482 
5488  public:
5489  explicit Scope(Isolate* isolate) : isolate_(isolate) {
5490  isolate->Enter();
5491  }
5492 
5493  ~Scope() { isolate_->Exit(); }
5494 
5495  private:
5496  Isolate* const isolate_;
5497 
5498  // Prevent copying of Scope objects.
5499  Scope(const Scope&);
5500  Scope& operator=(const Scope&);
5501  };
5502 
5503 
5508  public:
5509  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
5510 
5511  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
5513 
5514  private:
5515  bool on_failure_;
5516  void* internal_;
5517 
5518  // Prevent copying of Scope objects.
5522  };
5523 
5524 
5529  public:
5530  explicit AllowJavascriptExecutionScope(Isolate* isolate);
5532 
5533  private:
5534  void* internal_throws_;
5535  void* internal_assert_;
5536 
5537  // Prevent copying of Scope objects.
5539  AllowJavascriptExecutionScope& operator=(
5541  };
5542 
5548  public:
5549  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
5551 
5552  private:
5553  internal::Isolate* isolate_;
5554 
5555  // Prevent copying of Scope objects.
5559  };
5560 
5567  kMinorGarbageCollection
5568  };
5569 
5576  kUseAsm = 0,
5577  kBreakIterator = 1,
5578  kLegacyConst = 2,
5579  kMarkDequeOverflow = 3,
5580  kStoreBufferOverflow = 4,
5581  kSlotsBufferOverflow = 5,
5582  kObjectObserve = 6,
5583  kForcedGC = 7,
5584  kSloppyMode = 8,
5585  kStrictMode = 9,
5586  kStrongMode = 10,
5587  kRegExpPrototypeStickyGetter = 11,
5588  kRegExpPrototypeToString = 12,
5589  kRegExpPrototypeUnicodeGetter = 13,
5590  kIntlV8Parse = 14,
5591  kIntlPattern = 15,
5592  kIntlResolved = 16,
5593  kPromiseChain = 17,
5594  kPromiseAccept = 18,
5595  kPromiseDefer = 19,
5596  kHtmlCommentInExternalScript = 20,
5597  kHtmlComment = 21,
5598  kSloppyModeBlockScopedFunctionRedefinition = 22,
5599  kForInInitializer = 23,
5600  kArrayProtectorDirtied = 24,
5601  kArraySpeciesModified = 25,
5602  kArrayPrototypeConstructorModified = 26,
5603  kArrayInstanceProtoModified = 27,
5604  kArrayInstanceConstructorModified = 28,
5605  kLegacyFunctionDeclaration = 29,
5606  kRegExpPrototypeSourceGetter = 30,
5607  kRegExpPrototypeOldFlagGetter = 31,
5608 
5609  // If you add new values here, you'll also need to update V8Initializer.cpp
5610  // in Chromium.
5611  kUseCounterFeatureCount // This enum value must be last.
5612  };
5613 
5614  typedef void (*UseCounterCallback)(Isolate* isolate,
5615  UseCounterFeature feature);
5616 
5617 
5627  static Isolate* New(const CreateParams& params);
5628 
5635  static Isolate* GetCurrent();
5636 
5646  typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
5647  void SetAbortOnUncaughtExceptionCallback(
5648  AbortOnUncaughtExceptionCallback callback);
5649 
5656  void MemoryPressureNotification(MemoryPressureLevel level);
5657 
5668  void Enter();
5669 
5677  void Exit();
5678 
5683  void Dispose();
5684 
5692  void DiscardThreadSpecificMetadata();
5693 
5698  V8_INLINE void SetData(uint32_t slot, void* data);
5699 
5704  V8_INLINE void* GetData(uint32_t slot);
5705 
5710  V8_INLINE static uint32_t GetNumberOfDataSlots();
5711 
5715  void GetHeapStatistics(HeapStatistics* heap_statistics);
5716 
5720  size_t NumberOfHeapSpaces();
5721 
5731  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
5732  size_t index);
5733 
5737  size_t NumberOfTrackedHeapObjectTypes();
5738 
5748  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
5749  size_t type_index);
5750 
5763  void GetStackSample(const RegisterState& state, void** frames,
5764  size_t frames_limit, SampleInfo* sample_info);
5765 
5779  V8_INLINE int64_t
5780  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
5781 
5786  HeapProfiler* GetHeapProfiler();
5787 
5793  CpuProfiler* GetCpuProfiler();
5794 
5796  bool InContext();
5797 
5802  Local<Context> GetCurrentContext();
5803 
5810  "Calling context concept is not compatible with tail calls, and will be "
5811  "removed.",
5812  Local<Context> GetCallingContext());
5813 
5815  Local<Context> GetEnteredContext();
5816 
5823  Local<Value> ThrowException(Local<Value> exception);
5824 
5836  template<typename T> void SetObjectGroupId(const Persistent<T>& object,
5837  UniqueId id);
5838 
5846  template<typename T> void SetReferenceFromGroup(UniqueId id,
5847  const Persistent<T>& child);
5848 
5855  template<typename T, typename S>
5856  void SetReference(const Persistent<T>& parent, const Persistent<S>& child);
5857 
5858  typedef void (*GCCallback)(Isolate* isolate, GCType type,
5859  GCCallbackFlags flags);
5860 
5870  void AddGCPrologueCallback(GCCallback callback,
5871  GCType gc_type_filter = kGCTypeAll);
5872 
5877  void RemoveGCPrologueCallback(GCCallback callback);
5878 
5882  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
5883 
5893  void AddGCEpilogueCallback(GCCallback callback,
5894  GCType gc_type_filter = kGCTypeAll);
5895 
5900  void RemoveGCEpilogueCallback(GCCallback callback);
5901 
5909  void TerminateExecution();
5910 
5919  bool IsExecutionTerminating();
5920 
5935  void CancelTerminateExecution();
5936 
5945  void RequestInterrupt(InterruptCallback callback, void* data);
5946 
5957  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
5958 
5962  void SetEventLogger(LogEventCallback that);
5963 
5970  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
5971 
5975  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
5976 
5984  void AddCallCompletedCallback(CallCompletedCallback callback);
5986  "Use callback with parameter",
5987  void AddCallCompletedCallback(DeprecatedCallCompletedCallback callback));
5988 
5992  void RemoveCallCompletedCallback(CallCompletedCallback callback);
5994  "Use callback with parameter",
5995  void RemoveCallCompletedCallback(
5997 
6002  void SetPromiseRejectCallback(PromiseRejectCallback callback);
6003 
6008  void RunMicrotasks();
6009 
6013  void EnqueueMicrotask(Local<Function> microtask);
6014 
6018  void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
6019 
6024  void SetMicrotasksPolicy(MicrotasksPolicy policy);
6025  V8_DEPRECATE_SOON("Use SetMicrotasksPolicy",
6026  void SetAutorunMicrotasks(bool autorun));
6027 
6031  MicrotasksPolicy GetMicrotasksPolicy() const;
6032  V8_DEPRECATE_SOON("Use GetMicrotasksPolicy",
6033  bool WillAutorunMicrotasks() const);
6034 
6047  void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
6048 
6052  void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
6053 
6057  void SetUseCounterCallback(UseCounterCallback callback);
6058 
6063  void SetCounterFunction(CounterLookupCallback);
6064 
6071  void SetCreateHistogramFunction(CreateHistogramCallback);
6072  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
6073 
6088  bool IdleNotificationDeadline(double deadline_in_seconds);
6089 
6090  V8_DEPRECATED("use IdleNotificationDeadline()",
6091  bool IdleNotification(int idle_time_in_ms));
6092 
6097  void LowMemoryNotification();
6098 
6108  int ContextDisposedNotification(bool dependant_context = true);
6109 
6114  void IsolateInForegroundNotification();
6115 
6120  void IsolateInBackgroundNotification();
6121 
6144  void SetJitCodeEventHandler(JitCodeEventOptions options,
6145  JitCodeEventHandler event_handler);
6146 
6156  void SetStackLimit(uintptr_t stack_limit);
6157 
6171  void GetCodeRange(void** start, size_t* length_in_bytes);
6172 
6174  void SetFatalErrorHandler(FatalErrorCallback that);
6175 
6180  void SetAllowCodeGenerationFromStringsCallback(
6182 
6187  bool IsDead();
6188 
6198  bool AddMessageListener(MessageCallback that,
6199  Local<Value> data = Local<Value>());
6200 
6204  void RemoveMessageListeners(MessageCallback that);
6205 
6207  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
6208 
6213  void SetCaptureStackTraceForUncaughtExceptions(
6214  bool capture, int frame_limit = 10,
6216 
6221  void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
6222  ObjectSpace space, AllocationAction action);
6223 
6227  void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
6228 
6234  void VisitExternalResources(ExternalResourceVisitor* visitor);
6235 
6240  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
6241 
6249  void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
6250 
6256  void VisitWeakHandles(PersistentHandleVisitor* visitor);
6257 
6258  private:
6259  template <class K, class V, class Traits>
6261 
6262  Isolate();
6263  Isolate(const Isolate&);
6264  ~Isolate();
6265  Isolate& operator=(const Isolate&);
6266  void* operator new(size_t size);
6267  void operator delete(void*, size_t);
6268 
6269  void SetObjectGroupId(internal::Object** object, UniqueId id);
6270  void SetReferenceFromGroup(UniqueId id, internal::Object** object);
6271  void SetReference(internal::Object** parent, internal::Object** child);
6272  void ReportExternalAllocationLimitReached();
6273 };
6274 
6276  public:
6277  const char* data;
6279 };
6280 
6281 
6286 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
6287 
6288 
6302 typedef uintptr_t (*ReturnAddressLocationResolver)(
6303  uintptr_t return_addr_location);
6304 
6305 
6309 class V8_EXPORT V8 {
6310  public:
6312  V8_INLINE static V8_DEPRECATED(
6313  "Use isolate version",
6314  void SetFatalErrorHandler(FatalErrorCallback that));
6315 
6320  V8_INLINE static V8_DEPRECATED(
6321  "Use isolate version", void SetAllowCodeGenerationFromStringsCallback(
6323 
6328  V8_INLINE static V8_DEPRECATED("Use isolate version", bool IsDead());
6329 
6345  static void SetNativesDataBlob(StartupData* startup_blob);
6346  static void SetSnapshotDataBlob(StartupData* startup_blob);
6347 
6354  static StartupData CreateSnapshotDataBlob(const char* embedded_source = NULL);
6355 
6364  static StartupData WarmUpSnapshotDataBlob(StartupData cold_startup_blob,
6365  const char* warmup_source);
6366 
6376  V8_INLINE static V8_DEPRECATED(
6377  "Use isolate version",
6378  bool AddMessageListener(MessageCallback that,
6379  Local<Value> data = Local<Value>()));
6380 
6384  V8_INLINE static V8_DEPRECATED(
6385  "Use isolate version", void RemoveMessageListeners(MessageCallback that));
6386 
6391  V8_INLINE static V8_DEPRECATED(
6392  "Use isolate version",
6393  void SetCaptureStackTraceForUncaughtExceptions(
6394  bool capture, int frame_limit = 10,
6396 
6400  static void SetFlagsFromString(const char* str, int length);
6401 
6405  static void SetFlagsFromCommandLine(int* argc,
6406  char** argv,
6407  bool remove_flags);
6408 
6410  static const char* GetVersion();
6411 
6413  V8_INLINE static V8_DEPRECATED(
6414  "Use isolate version",
6415  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback));
6416 
6427  static V8_DEPRECATED(
6428  "Use isolate version",
6429  void AddGCPrologueCallback(GCCallback callback,
6430  GCType gc_type_filter = kGCTypeAll));
6431 
6436  V8_INLINE static V8_DEPRECATED(
6437  "Use isolate version",
6438  void RemoveGCPrologueCallback(GCCallback callback));
6439 
6450  static V8_DEPRECATED(
6451  "Use isolate version",
6452  void AddGCEpilogueCallback(GCCallback callback,
6453  GCType gc_type_filter = kGCTypeAll));
6454 
6459  V8_INLINE static V8_DEPRECATED(
6460  "Use isolate version",
6461  void RemoveGCEpilogueCallback(GCCallback callback));
6462 
6467  V8_INLINE static V8_DEPRECATED(
6468  "Use isolate version",
6469  void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
6470  ObjectSpace space,
6471  AllocationAction action));
6472 
6476  V8_INLINE static V8_DEPRECATED(
6477  "Use isolate version",
6478  void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback));
6479 
6484  static bool Initialize();
6485 
6490  static void SetEntropySource(EntropySource source);
6491 
6496  static void SetReturnAddressLocationResolver(
6497  ReturnAddressLocationResolver return_address_resolver);
6498 
6508  V8_INLINE static V8_DEPRECATED("Use isolate version",
6509  void TerminateExecution(Isolate* isolate));
6510 
6521  V8_INLINE static V8_DEPRECATED(
6522  "Use isolate version",
6523  bool IsExecutionTerminating(Isolate* isolate = NULL));
6524 
6541  V8_INLINE static V8_DEPRECATED(
6542  "Use isolate version", void CancelTerminateExecution(Isolate* isolate));
6543 
6553  static bool Dispose();
6554 
6560  V8_INLINE static V8_DEPRECATED(
6561  "Use isolate version",
6562  void VisitExternalResources(ExternalResourceVisitor* visitor));
6563 
6568  V8_INLINE static V8_DEPRECATED(
6569  "Use isolate version",
6570  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor));
6571 
6576  V8_INLINE static V8_DEPRECATED(
6577  "Use isolate version",
6578  void VisitHandlesWithClassIds(Isolate* isolate,
6579  PersistentHandleVisitor* visitor));
6580 
6588  V8_INLINE static V8_DEPRECATED(
6589  "Use isolate version",
6590  void VisitHandlesForPartialDependence(Isolate* isolate,
6591  PersistentHandleVisitor* visitor));
6592 
6600  static bool InitializeICU(const char* icu_data_file = NULL);
6601 
6618  static void InitializeExternalStartupData(const char* directory_path);
6619  static void InitializeExternalStartupData(const char* natives_blob,
6620  const char* snapshot_blob);
6625  static void InitializePlatform(Platform* platform);
6626 
6631  static void ShutdownPlatform();
6632 
6633  private:
6634  V8();
6635 
6636  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
6637  internal::Object** handle);
6638  static internal::Object** CopyPersistent(internal::Object** handle);
6639  static void DisposeGlobal(internal::Object** global_handle);
6640  typedef WeakCallbackData<Value, void>::Callback WeakCallback;
6641  static void RegisterExternallyReferencedObject(internal::Object** object,
6642  internal::Isolate* isolate);
6643  static void MakeWeak(internal::Object** global_handle, void* data,
6644  WeakCallback weak_callback);
6645  static void MakeWeak(internal::Object** global_handle, void* data,
6646  WeakCallbackInfo<void>::Callback weak_callback,
6647  WeakCallbackType type);
6648  static void MakeWeak(internal::Object** global_handle, void* data,
6649  // Must be 0 or -1.
6650  int internal_field_index1,
6651  // Must be 1 or -1.
6652  int internal_field_index2,
6653  WeakCallbackInfo<void>::Callback weak_callback);
6654  static void* ClearWeak(internal::Object** global_handle);
6655  static void Eternalize(Isolate* isolate,
6656  Value* handle,
6657  int* index);
6658  static Local<Value> GetEternal(Isolate* isolate, int index);
6659 
6660  static void FromJustIsNothing();
6661  static void ToLocalEmpty();
6662  static void InternalFieldOutOfBounds(int index);
6663  template <class T> friend class Local;
6664  template <class T>
6665  friend class MaybeLocal;
6666  template <class T>
6667  friend class Maybe;
6668  template <class T>
6669  friend class WeakCallbackInfo;
6670  template <class T> friend class Eternal;
6671  template <class T> friend class PersistentBase;
6672  template <class T, class M> friend class Persistent;
6673  friend class Context;
6674 };
6675 
6676 
6687 template <class T>
6688 class Maybe {
6689  public:
6690  V8_INLINE bool IsNothing() const { return !has_value; }
6691  V8_INLINE bool IsJust() const { return has_value; }
6692 
6693  // Will crash if the Maybe<> is nothing.
6694  V8_INLINE T FromJust() const {
6695  if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
6696  return value;
6697  }
6698 
6699  V8_INLINE T FromMaybe(const T& default_value) const {
6700  return has_value ? value : default_value;
6701  }
6702 
6703  V8_INLINE bool operator==(const Maybe& other) const {
6704  return (IsJust() == other.IsJust()) &&
6705  (!IsJust() || FromJust() == other.FromJust());
6706  }
6707 
6708  V8_INLINE bool operator!=(const Maybe& other) const {
6709  return !operator==(other);
6710  }
6711 
6712  private:
6713  Maybe() : has_value(false) {}
6714  explicit Maybe(const T& t) : has_value(true), value(t) {}
6715 
6716  bool has_value;
6717  T value;
6718 
6719  template <class U>
6720  friend Maybe<U> Nothing();
6721  template <class U>
6722  friend Maybe<U> Just(const U& u);
6723 };
6724 
6725 
6726 template <class T>
6727 inline Maybe<T> Nothing() {
6728  return Maybe<T>();
6729 }
6730 
6731 
6732 template <class T>
6733 inline Maybe<T> Just(const T& t) {
6734  return Maybe<T>(t);
6735 }
6736 
6737 
6742  public:
6748  V8_DEPRECATED("Use isolate version", TryCatch());
6749 
6755  TryCatch(Isolate* isolate);
6756 
6760  ~TryCatch();
6761 
6765  bool HasCaught() const;
6766 
6775  bool CanContinue() const;
6776 
6789  bool HasTerminated() const;
6790 
6798  Local<Value> ReThrow();
6799 
6806  Local<Value> Exception() const;
6807 
6812  V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace() const);
6814  Local<Context> context) const;
6815 
6823  Local<v8::Message> Message() const;
6824 
6835  void Reset();
6836 
6845  void SetVerbose(bool value);
6846 
6852  void SetCaptureMessage(bool value);
6853 
6865  static void* JSStackComparableAddress(v8::TryCatch* handler) {
6866  if (handler == NULL) return NULL;
6867  return handler->js_stack_comparable_address_;
6868  }
6869 
6870  private:
6871  void ResetInternal();
6872 
6873  // Make it hard to create heap-allocated TryCatch blocks.
6874  TryCatch(const TryCatch&);
6875  void operator=(const TryCatch&);
6876  void* operator new(size_t size);
6877  void operator delete(void*, size_t);
6878 
6879  v8::internal::Isolate* isolate_;
6880  v8::TryCatch* next_;
6881  void* exception_;
6882  void* message_obj_;
6883  void* js_stack_comparable_address_;
6884  bool is_verbose_ : 1;
6885  bool can_continue_ : 1;
6886  bool capture_message_ : 1;
6887  bool rethrow_ : 1;
6888  bool has_terminated_ : 1;
6889 
6890  friend class v8::internal::Isolate;
6891 };
6892 
6893 
6894 // --- Context ---
6895 
6896 
6901  public:
6902  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
6903  ExtensionConfiguration(int name_count, const char* names[])
6904  : name_count_(name_count), names_(names) { }
6905 
6906  const char** begin() const { return &names_[0]; }
6907  const char** end() const { return &names_[name_count_]; }
6908 
6909  private:
6910  const int name_count_;
6911  const char** names_;
6912 };
6913 
6914 
6920  public:
6934 
6939  void DetachGlobal();
6940 
6959  static Local<Context> New(
6960  Isolate* isolate, ExtensionConfiguration* extensions = NULL,
6961  Local<ObjectTemplate> global_template = Local<ObjectTemplate>(),
6962  Local<Value> global_object = Local<Value>());
6963 
6968  void SetSecurityToken(Local<Value> token);
6969 
6971  void UseDefaultSecurityToken();
6972 
6974  Local<Value> GetSecurityToken();
6975 
6982  void Enter();
6983 
6988  void Exit();
6989 
6991  v8::Isolate* GetIsolate();
6992 
6998  enum EmbedderDataFields { kDebugIdIndex = 0 };
6999 
7005  V8_INLINE Local<Value> GetEmbedderData(int index);
7006 
7013  Local<Object> GetExtrasBindingObject();
7014 
7020  void SetEmbedderData(int index, Local<Value> value);
7021 
7028  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
7029 
7035  void SetAlignedPointerInEmbedderData(int index, void* value);
7036 
7050  void AllowCodeGenerationFromStrings(bool allow);
7051 
7056  bool IsCodeGenerationFromStringsAllowed();
7057 
7063  void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
7064 
7068  size_t EstimatedSize();
7069 
7074  class Scope {
7075  public:
7076  explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
7077  context_->Enter();
7078  }
7079  V8_INLINE ~Scope() { context_->Exit(); }
7080 
7081  private:
7082  Local<Context> context_;
7083  };
7084 
7085  private:
7086  friend class Value;
7087  friend class Script;
7088  friend class Object;
7089  friend class Function;
7090 
7091  Local<Value> SlowGetEmbedderData(int index);
7092  void* SlowGetAlignedPointerFromEmbedderData(int index);
7093 };
7094 
7095 
7173  public:
7177  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
7178 
7179  ~Unlocker();
7180  private:
7181  void Initialize(Isolate* isolate);
7182 
7183  internal::Isolate* isolate_;
7184 };
7185 
7186 
7188  public:
7192  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
7193 
7194  ~Locker();
7195 
7200  static bool IsLocked(Isolate* isolate);
7201 
7205  static bool IsActive();
7206 
7207  private:
7208  void Initialize(Isolate* isolate);
7209 
7210  bool has_lock_;
7211  bool top_level_;
7212  internal::Isolate* isolate_;
7213 
7214  // Disallow copying and assigning.
7215  Locker(const Locker&);
7216  void operator=(const Locker&);
7217 };
7218 
7219 
7220 // --- Implementation ---
7221 
7222 
7223 namespace internal {
7224 
7225 const int kApiPointerSize = sizeof(void*); // NOLINT
7226 const int kApiIntSize = sizeof(int); // NOLINT
7227 const int kApiInt64Size = sizeof(int64_t); // NOLINT
7228 
7229 // Tag information for HeapObject.
7230 const int kHeapObjectTag = 1;
7231 const int kHeapObjectTagSize = 2;
7232 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
7233 
7234 // Tag information for Smi.
7235 const int kSmiTag = 0;
7236 const int kSmiTagSize = 1;
7237 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
7238 
7239 template <size_t ptr_size> struct SmiTagging;
7240 
7241 template<int kSmiShiftSize>
7242 V8_INLINE internal::Object* IntToSmi(int value) {
7243  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
7244  uintptr_t tagged_value =
7245  (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
7246  return reinterpret_cast<internal::Object*>(tagged_value);
7247 }
7248 
7249 // Smi constants for 32-bit systems.
7250 template <> struct SmiTagging<4> {
7251  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
7252  static int SmiShiftSize() { return kSmiShiftSize; }
7253  static int SmiValueSize() { return kSmiValueSize; }
7254  V8_INLINE static int SmiToInt(const internal::Object* value) {
7255  int shift_bits = kSmiTagSize + kSmiShiftSize;
7256  // Throw away top 32 bits and shift down (requires >> to be sign extending).
7257  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
7258  }
7259  V8_INLINE static internal::Object* IntToSmi(int value) {
7260  return internal::IntToSmi<kSmiShiftSize>(value);
7261  }
7262  V8_INLINE static bool IsValidSmi(intptr_t value) {
7263  // To be representable as an tagged small integer, the two
7264  // most-significant bits of 'value' must be either 00 or 11 due to
7265  // sign-extension. To check this we add 01 to the two
7266  // most-significant bits, and check if the most-significant bit is 0
7267  //
7268  // CAUTION: The original code below:
7269  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
7270  // may lead to incorrect results according to the C language spec, and
7271  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
7272  // compiler may produce undefined results in case of signed integer
7273  // overflow. The computation must be done w/ unsigned ints.
7274  return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
7275  }
7276 };
7277 
7278 // Smi constants for 64-bit systems.
7279 template <> struct SmiTagging<8> {
7280  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
7281  static int SmiShiftSize() { return kSmiShiftSize; }
7282  static int SmiValueSize() { return kSmiValueSize; }
7283  V8_INLINE static int SmiToInt(const internal::Object* value) {
7284  int shift_bits = kSmiTagSize + kSmiShiftSize;
7285  // Shift down and throw away top 32 bits.
7286  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
7287  }
7288  V8_INLINE static internal::Object* IntToSmi(int value) {
7289  return internal::IntToSmi<kSmiShiftSize>(value);
7290  }
7291  V8_INLINE static bool IsValidSmi(intptr_t value) {
7292  // To be representable as a long smi, the value must be a 32-bit integer.
7293  return (value == static_cast<int32_t>(value));
7294  }
7295 };
7296 
7300 V8_INLINE static bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
7301 V8_INLINE static bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
7302 
7308 class Internals {
7309  public:
7310  // These values match non-compiler-dependent values defined within
7311  // the implementation of v8.
7312  static const int kHeapObjectMapOffset = 0;
7315  static const int kStringResourceOffset = 3 * kApiPointerSize;
7316 
7317  static const int kOddballKindOffset = 5 * kApiPointerSize;
7319  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
7320  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
7321  static const int kContextHeaderSize = 2 * kApiPointerSize;
7322  static const int kContextEmbedderDataIndex = 5;
7323  static const int kFullStringRepresentationMask = 0x07;
7324  static const int kStringEncodingMask = 0x4;
7325  static const int kExternalTwoByteRepresentationTag = 0x02;
7326  static const int kExternalOneByteRepresentationTag = 0x06;
7327 
7330  4 * kApiPointerSize;
7333  static const int kIsolateRootsOffset =
7336  static const int kUndefinedValueRootIndex = 4;
7337  static const int kNullValueRootIndex = 6;
7338  static const int kTrueValueRootIndex = 7;
7339  static const int kFalseValueRootIndex = 8;
7340  static const int kEmptyStringRootIndex = 9;
7341 
7342  // The external allocation limit should be below 256 MB on all architectures
7343  // to avoid that resource-constrained embedders run low on memory.
7344  static const int kExternalAllocationLimit = 192 * 1024 * 1024;
7345 
7346  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
7347  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
7348  static const int kNodeStateMask = 0x7;
7349  static const int kNodeStateIsWeakValue = 2;
7350  static const int kNodeStateIsPendingValue = 3;
7351  static const int kNodeStateIsNearDeathValue = 4;
7352  static const int kNodeIsIndependentShift = 3;
7353  static const int kNodeIsPartiallyDependentShift = 4;
7354  static const int kNodeIsActiveShift = 4;
7355 
7356  static const int kJSObjectType = 0xb8;
7357  static const int kFirstNonstringType = 0x80;
7358  static const int kOddballType = 0x83;
7359  static const int kForeignType = 0x87;
7360 
7361  static const int kUndefinedOddballKind = 5;
7362  static const int kNullOddballKind = 3;
7363 
7364  static const uint32_t kNumIsolateDataSlots = 4;
7365 
7366  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
7367  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
7368 #ifdef V8_ENABLE_CHECKS
7369  CheckInitializedImpl(isolate);
7370 #endif
7371  }
7372 
7373  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
7374  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
7375  kHeapObjectTag);
7376  }
7377 
7378  V8_INLINE static int SmiValue(const internal::Object* value) {
7379  return PlatformSmiTagging::SmiToInt(value);
7380  }
7381 
7382  V8_INLINE static internal::Object* IntToSmi(int value) {
7383  return PlatformSmiTagging::IntToSmi(value);
7384  }
7385 
7386  V8_INLINE static bool IsValidSmi(intptr_t value) {
7387  return PlatformSmiTagging::IsValidSmi(value);
7388  }
7389 
7390  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
7391  typedef internal::Object O;
7392  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
7393  // Map::InstanceType is defined so that it will always be loaded into
7394  // the LS 8 bits of one 16-bit word, regardless of endianess.
7395  return ReadField<uint16_t>(map, kMapInstanceTypeAndBitFieldOffset) & 0xff;
7396  }
7397 
7398  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
7399  typedef internal::Object O;
7400  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
7401  }
7402 
7403  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
7404  int representation = (instance_type & kFullStringRepresentationMask);
7405  return representation == kExternalTwoByteRepresentationTag;
7406  }
7407 
7408  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
7409  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7410  return *addr & static_cast<uint8_t>(1U << shift);
7411  }
7412 
7413  V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
7414  bool value, int shift) {
7415  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7416  uint8_t mask = static_cast<uint8_t>(1U << shift);
7417  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
7418  }
7419 
7420  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
7421  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7422  return *addr & kNodeStateMask;
7423  }
7424 
7425  V8_INLINE static void UpdateNodeState(internal::Object** obj,
7426  uint8_t value) {
7427  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
7428  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
7429  }
7430 
7431  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
7432  uint32_t slot,
7433  void* data) {
7434  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
7436  *reinterpret_cast<void**>(addr) = data;
7437  }
7438 
7439  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
7440  uint32_t slot) {
7441  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
7443  return *reinterpret_cast<void* const*>(addr);
7444  }
7445 
7446  V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
7447  int index) {
7448  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
7449  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
7450  }
7451 
7452  template <typename T>
7453  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
7454  const uint8_t* addr =
7455  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
7456  return *reinterpret_cast<const T*>(addr);
7457  }
7458 
7459  template <typename T>
7460  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
7461  typedef internal::Object O;
7462  typedef internal::Internals I;
7463  O* ctx = *reinterpret_cast<O* const*>(context);
7464  int embedder_data_offset = I::kContextHeaderSize +
7465  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
7466  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
7467  int value_offset =
7468  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
7469  return I::ReadField<T>(embedder_data, value_offset);
7470  }
7471 };
7472 
7473 } // namespace internal
7474 
7475 
7476 template <class T>
7478  return New(isolate, that.val_);
7479 }
7480 
7481 template <class T>
7483  return New(isolate, that.val_);
7484 }
7485 
7486 
7487 template <class T>
7488 Local<T> Local<T>::New(Isolate* isolate, T* that) {
7489  if (that == NULL) return Local<T>();
7490  T* that_ptr = that;
7491  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
7492  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
7493  reinterpret_cast<internal::Isolate*>(isolate), *p)));
7494 }
7495 
7496 
7497 template<class T>
7498 template<class S>
7499 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
7500  TYPE_CHECK(T, S);
7501  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_);
7502 }
7503 
7504 
7505 template<class T>
7507  return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_)));
7508 }
7509 
7510 
7511 template <class T>
7513  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
7514  return Local<T>(val_);
7515 }
7516 
7517 
7518 template <class T>
7520 #ifdef V8_ENABLE_CHECKS
7521  if (index < 0 || index >= kInternalFieldsInWeakCallback) {
7522  V8::InternalFieldOutOfBounds(index);
7523  }
7524 #endif
7525  return internal_fields_[index];
7526 }
7527 
7528 
7529 template <class T>
7530 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
7531  if (that == NULL) return NULL;
7532  internal::Object** p = reinterpret_cast<internal::Object**>(that);
7533  return reinterpret_cast<T*>(
7534  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
7535  p));
7536 }
7537 
7538 
7539 template <class T, class M>
7540 template <class S, class M2>
7542  TYPE_CHECK(T, S);
7543  this->Reset();
7544  if (that.IsEmpty()) return;
7545  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
7546  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
7547  M::Copy(that, this);
7548 }
7549 
7550 
7551 template <class T>
7553  typedef internal::Internals I;
7554  if (this->IsEmpty()) return false;
7555  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7556  I::kNodeIsIndependentShift);
7557 }
7558 
7559 
7560 template <class T>
7562  typedef internal::Internals I;
7563  if (this->IsEmpty()) return false;
7564  uint8_t node_state =
7565  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
7566  return node_state == I::kNodeStateIsNearDeathValue ||
7567  node_state == I::kNodeStateIsPendingValue;
7568 }
7569 
7570 
7571 template <class T>
7573  typedef internal::Internals I;
7574  if (this->IsEmpty()) return false;
7575  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
7576  I::kNodeStateIsWeakValue;
7577 }
7578 
7579 
7580 template <class T>
7582  if (this->IsEmpty()) return;
7583  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
7584  val_ = 0;
7585 }
7586 
7587 
7588 template <class T>
7589 template <class S>
7590 void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
7591  TYPE_CHECK(T, S);
7592  Reset();
7593  if (other.IsEmpty()) return;
7594  this->val_ = New(isolate, other.val_);
7595 }
7596 
7597 
7598 template <class T>
7599 template <class S>
7601  const PersistentBase<S>& other) {
7602  TYPE_CHECK(T, S);
7603  Reset();
7604  if (other.IsEmpty()) return;
7605  this->val_ = New(isolate, other.val_);
7606 }
7607 
7608 
7609 template <class T>
7610 template <typename S, typename P>
7612  P* parameter,
7613  typename WeakCallbackData<S, P>::Callback callback) {
7614  TYPE_CHECK(S, T);
7615  typedef typename WeakCallbackData<Value, void>::Callback Callback;
7616  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7617  reinterpret_cast<Callback>(callback));
7618 }
7619 
7620 
7621 template <class T>
7622 template <typename P>
7624  P* parameter,
7625  typename WeakCallbackData<T, P>::Callback callback) {
7626  SetWeak<T, P>(parameter, callback);
7627 }
7628 
7629 
7630 template <class T>
7631 template <typename P>
7633  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
7634  int internal_field_index1, int internal_field_index2) {
7635  typedef typename WeakCallbackInfo<void>::Callback Callback;
7636  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7637  internal_field_index1, internal_field_index2,
7638  reinterpret_cast<Callback>(callback));
7639 }
7640 
7641 
7642 template <class T>
7643 template <typename P>
7645  P* parameter, typename WeakCallbackInfo<P>::Callback callback,
7646  WeakCallbackType type) {
7647  typedef typename WeakCallbackInfo<void>::Callback Callback;
7648  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
7649  reinterpret_cast<Callback>(callback), type);
7650 }
7651 
7652 
7653 template <class T>
7654 template <typename P>
7656  return reinterpret_cast<P*>(
7657  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
7658 }
7659 
7660 template <class T>
7662  if (IsEmpty()) return;
7663  V8::RegisterExternallyReferencedObject(
7664  reinterpret_cast<internal::Object**>(this->val_),
7665  reinterpret_cast<internal::Isolate*>(isolate));
7666 }
7667 
7668 template <class T>
7670  typedef internal::Internals I;
7671  if (this->IsEmpty()) return;
7672  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7673  true,
7674  I::kNodeIsIndependentShift);
7675 }
7676 
7677 
7678 template <class T>
7680  typedef internal::Internals I;
7681  if (this->IsEmpty()) return;
7682  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
7683  true,
7684  I::kNodeIsPartiallyDependentShift);
7685 }
7686 
7687 
7688 template <class T>
7690  typedef internal::Internals I;
7691  if (this->IsEmpty()) return;
7692  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
7693  I::kNodeIsActiveShift);
7694 }
7695 
7696 
7697 template <class T>
7698 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
7699  typedef internal::Internals I;
7700  if (this->IsEmpty()) return;
7701  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
7702  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
7703  *reinterpret_cast<uint16_t*>(addr) = class_id;
7704 }
7705 
7706 
7707 template <class T>
7709  typedef internal::Internals I;
7710  if (this->IsEmpty()) return 0;
7711  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
7712  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
7713  return *reinterpret_cast<uint16_t*>(addr);
7714 }
7715 
7716 
7717 template<typename T>
7718 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
7719 
7720 template<typename T>
7721 template<typename S>
7722 void ReturnValue<T>::Set(const Persistent<S>& handle) {
7723  TYPE_CHECK(T, S);
7724  if (V8_UNLIKELY(handle.IsEmpty())) {
7725  *value_ = GetDefaultValue();
7726  } else {
7727  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7728  }
7729 }
7730 
7731 template <typename T>
7732 template <typename S>
7733 void ReturnValue<T>::Set(const Global<S>& handle) {
7734  TYPE_CHECK(T, S);
7735  if (V8_UNLIKELY(handle.IsEmpty())) {
7736  *value_ = GetDefaultValue();
7737  } else {
7738  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7739  }
7740 }
7741 
7742 template <typename T>
7743 template <typename S>
7744 void ReturnValue<T>::Set(const Local<S> handle) {
7745  TYPE_CHECK(T, S);
7746  if (V8_UNLIKELY(handle.IsEmpty())) {
7747  *value_ = GetDefaultValue();
7748  } else {
7749  *value_ = *reinterpret_cast<internal::Object**>(*handle);
7750  }
7751 }
7752 
7753 template<typename T>
7754 void ReturnValue<T>::Set(double i) {
7755  TYPE_CHECK(T, Number);
7756  Set(Number::New(GetIsolate(), i));
7757 }
7758 
7759 template<typename T>
7760 void ReturnValue<T>::Set(int32_t i) {
7761  TYPE_CHECK(T, Integer);
7762  typedef internal::Internals I;
7763  if (V8_LIKELY(I::IsValidSmi(i))) {
7764  *value_ = I::IntToSmi(i);
7765  return;
7766  }
7767  Set(Integer::New(GetIsolate(), i));
7768 }
7769 
7770 template<typename T>
7771 void ReturnValue<T>::Set(uint32_t i) {
7772  TYPE_CHECK(T, Integer);
7773  // Can't simply use INT32_MAX here for whatever reason.
7774  bool fits_into_int32_t = (i & (1U << 31)) == 0;
7775  if (V8_LIKELY(fits_into_int32_t)) {
7776  Set(static_cast<int32_t>(i));
7777  return;
7778  }
7779  Set(Integer::NewFromUnsigned(GetIsolate(), i));
7780 }
7781 
7782 template<typename T>
7783 void ReturnValue<T>::Set(bool value) {
7784  TYPE_CHECK(T, Boolean);
7785  typedef internal::Internals I;
7786  int root_index;
7787  if (value) {
7788  root_index = I::kTrueValueRootIndex;
7789  } else {
7790  root_index = I::kFalseValueRootIndex;
7791  }
7792  *value_ = *I::GetRoot(GetIsolate(), root_index);
7793 }
7794 
7795 template<typename T>
7797  TYPE_CHECK(T, Primitive);
7798  typedef internal::Internals I;
7799  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
7800 }
7801 
7802 template<typename T>
7804  TYPE_CHECK(T, Primitive);
7805  typedef internal::Internals I;
7806  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
7807 }
7808 
7809 template<typename T>
7811  TYPE_CHECK(T, String);
7812  typedef internal::Internals I;
7813  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
7814 }
7815 
7816 template<typename T>
7818  // Isolate is always the pointer below the default value on the stack.
7819  return *reinterpret_cast<Isolate**>(&value_[-2]);
7820 }
7821 
7822 template<typename T>
7823 template<typename S>
7824 void ReturnValue<T>::Set(S* whatever) {
7825  // Uncompilable to prevent inadvertent misuse.
7826  TYPE_CHECK(S*, Primitive);
7827 }
7828 
7829 template<typename T>
7830 internal::Object* ReturnValue<T>::GetDefaultValue() {
7831  // Default value is always the pointer below value_ on the stack.
7832  return value_[-1];
7833 }
7834 
7835 
7836 template<typename T>
7837 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
7838  internal::Object** values,
7839  int length,
7840  bool is_construct_call)
7841  : implicit_args_(implicit_args),
7842  values_(values),
7843  length_(length),
7844  is_construct_call_(is_construct_call) { }
7845 
7846 
7847 template<typename T>
7849  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
7850  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
7851 }
7852 
7853 
7854 template<typename T>
7856  return Local<Function>(reinterpret_cast<Function*>(
7857  &implicit_args_[kCalleeIndex]));
7858 }
7859 
7860 
7861 template<typename T>
7863  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
7864 }
7865 
7866 
7867 template<typename T>
7869  return Local<Object>(reinterpret_cast<Object*>(
7870  &implicit_args_[kHolderIndex]));
7871 }
7872 
7873 
7874 template<typename T>
7876  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
7877 }
7878 
7879 
7880 template<typename T>
7882  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
7883 }
7884 
7885 
7886 template<typename T>
7888  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
7889 }
7890 
7891 
7892 template<typename T>
7894  return is_construct_call_ & 0x1;
7895 }
7896 
7897 
7898 template<typename T>
7900  return length_;
7901 }
7902 
7904  Local<Integer> resource_line_offset,
7905  Local<Integer> resource_column_offset,
7906  Local<Boolean> resource_is_shared_cross_origin,
7907  Local<Integer> script_id,
7908  Local<Boolean> resource_is_embedder_debug_script,
7909  Local<Value> source_map_url,
7910  Local<Boolean> resource_is_opaque)
7911  : resource_name_(resource_name),
7912  resource_line_offset_(resource_line_offset),
7913  resource_column_offset_(resource_column_offset),
7914  options_(!resource_is_embedder_debug_script.IsEmpty() &&
7915  resource_is_embedder_debug_script->IsTrue(),
7916  !resource_is_shared_cross_origin.IsEmpty() &&
7917  resource_is_shared_cross_origin->IsTrue(),
7918  !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue()),
7919  script_id_(script_id),
7920  source_map_url_(source_map_url) {}
7921 
7922 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
7923 
7924 
7926  return resource_line_offset_;
7927 }
7928 
7929 
7931  return resource_column_offset_;
7932 }
7933 
7934 
7935 Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
7936 
7937 
7938 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
7939 
7940 
7942  CachedData* data)
7943  : source_string(string),
7944  resource_name(origin.ResourceName()),
7945  resource_line_offset(origin.ResourceLineOffset()),
7946  resource_column_offset(origin.ResourceColumnOffset()),
7947  resource_options(origin.Options()),
7948  source_map_url(origin.SourceMapUrl()),
7949  cached_data(data) {}
7950 
7951 
7953  CachedData* data)
7954  : source_string(string), cached_data(data) {}
7955 
7956 
7958  delete cached_data;
7959 }
7960 
7961