V8 API Reference Guide for node.js v0.12.11 - v0.12.14
v8.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
15 #ifndef V8_H_
16 #define V8_H_
17 
18 #include "v8stdint.h"
19 
20 // We reserve the V8_* prefix for macros defined in V8 public API and
21 // assume there are no name conflicts with the embedder's code.
22 
23 #ifdef V8_OS_WIN
24 
25 // Setup for Windows DLL export/import. When building the V8 DLL the
26 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
27 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
28 // static library or building a program which uses the V8 static library neither
29 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
30 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
31 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
32  build configuration to ensure that at most one of these is set
33 #endif
34 
35 #ifdef BUILDING_V8_SHARED
36 # define V8_EXPORT __declspec(dllexport)
37 #elif USING_V8_SHARED
38 # define V8_EXPORT __declspec(dllimport)
39 #else
40 # define V8_EXPORT
41 #endif // BUILDING_V8_SHARED
42 
43 #else // V8_OS_WIN
44 
45 // Setup for Linux shared library export.
46 #if V8_HAS_ATTRIBUTE_VISIBILITY && defined(V8_SHARED)
47 # ifdef BUILDING_V8_SHARED
48 # define V8_EXPORT __attribute__ ((visibility("default")))
49 # else
50 # define V8_EXPORT
51 # endif
52 #else
53 # define V8_EXPORT
54 #endif
55 
56 #endif // V8_OS_WIN
57 
61 namespace v8 {
62 
63 class AccessorSignature;
64 class Array;
65 class Boolean;
66 class BooleanObject;
67 class Context;
68 class CpuProfiler;
69 class Data;
70 class Date;
71 class DeclaredAccessorDescriptor;
72 class External;
73 class Function;
74 class FunctionTemplate;
75 class HeapProfiler;
76 class ImplementationUtilities;
77 class Int32;
78 class Integer;
79 class Isolate;
80 class Number;
81 class NumberObject;
82 class Object;
83 class ObjectOperationDescriptor;
84 class ObjectTemplate;
85 class Platform;
86 class Primitive;
87 class RawOperationDescriptor;
88 class Script;
89 class Signature;
90 class StackFrame;
91 class StackTrace;
92 class String;
93 class StringObject;
94 class Symbol;
95 class SymbolObject;
96 class Private;
97 class Uint32;
98 class Utils;
99 class Value;
100 template <class T> class Handle;
101 template <class T> class Local;
102 template <class T> class Eternal;
103 template<class T> class NonCopyablePersistentTraits;
104 template<class T> class PersistentBase;
105 template<class T,
107 template<class T> class UniquePersistent;
108 template<class K, class V, class T> class PersistentValueMap;
109 template<class V, class T> class PersistentValueVector;
110 template<class T, class P> class WeakCallbackObject;
111 class FunctionTemplate;
112 class ObjectTemplate;
113 class Data;
114 template<typename T> class FunctionCallbackInfo;
115 template<typename T> class PropertyCallbackInfo;
116 class StackTrace;
117 class StackFrame;
118 class Isolate;
122 class CallHandlerHelper;
124 template<typename T> class ReturnValue;
125 
126 namespace internal {
127 class Arguments;
128 class Heap;
129 class HeapObject;
130 class Isolate;
131 class Object;
132 template<typename T> class CustomArguments;
133 class PropertyCallbackArguments;
134 class FunctionCallbackArguments;
135 class GlobalHandles;
136 }
137 
138 
142 class UniqueId {
143  public:
144  explicit UniqueId(intptr_t data)
145  : data_(data) {}
146 
147  bool operator==(const UniqueId& other) const {
148  return data_ == other.data_;
149  }
150 
151  bool operator!=(const UniqueId& other) const {
152  return data_ != other.data_;
153  }
154 
155  bool operator<(const UniqueId& other) const {
156  return data_ < other.data_;
157  }
158 
159  private:
160  intptr_t data_;
161 };
162 
163 // --- Handles ---
164 
165 #define TYPE_CHECK(T, S) \
166  while (false) { \
167  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
168  }
169 
170 
196 template <class T> class Handle {
197  public:
201  V8_INLINE Handle() : val_(0) {}
202 
213  template <class S> V8_INLINE Handle(Handle<S> that)
214  : val_(reinterpret_cast<T*>(*that)) {
220  TYPE_CHECK(T, S);
221  }
222 
226  V8_INLINE bool IsEmpty() const { return val_ == 0; }
227 
231  V8_INLINE void Clear() { val_ = 0; }
232 
233  V8_INLINE T* operator->() const { return val_; }
234 
235  V8_INLINE T* operator*() const { return val_; }
236 
243  template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
244  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
245  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
246  if (a == 0) return b == 0;
247  if (b == 0) return false;
248  return *a == *b;
249  }
250 
251  template <class S> V8_INLINE bool operator==(
252  const PersistentBase<S>& that) const {
253  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
254  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
255  if (a == 0) return b == 0;
256  if (b == 0) return false;
257  return *a == *b;
258  }
259 
266  template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const {
267  return !operator==(that);
268  }
269 
270  template <class S> V8_INLINE bool operator!=(
271  const Persistent<S>& that) const {
272  return !operator==(that);
273  }
274 
275  template <class S> V8_INLINE static Handle<T> Cast(Handle<S> that) {
276 #ifdef V8_ENABLE_CHECKS
277  // If we're going to perform the type check then we have to check
278  // that the handle isn't empty before doing the checked cast.
279  if (that.IsEmpty()) return Handle<T>();
280 #endif
281  return Handle<T>(T::Cast(*that));
282  }
283 
284  template <class S> V8_INLINE Handle<S> As() {
285  return Handle<S>::Cast(*this);
286  }
287 
288  V8_INLINE static Handle<T> New(Isolate* isolate, Handle<T> that) {
289  return New(isolate, that.val_);
290  }
291  V8_INLINE static Handle<T> New(Isolate* isolate,
292  const PersistentBase<T>& that) {
293  return New(isolate, that.val_);
294  }
295 
296  private:
297  friend class Utils;
298  template<class F, class M> friend class Persistent;
299  template<class F> friend class PersistentBase;
300  template<class F> friend class Handle;
301  template<class F> friend class Local;
302  template<class F> friend class FunctionCallbackInfo;
303  template<class F> friend class PropertyCallbackInfo;
304  template<class F> friend class internal::CustomArguments;
305  friend Handle<Primitive> Undefined(Isolate* isolate);
306  friend Handle<Primitive> Null(Isolate* isolate);
307  friend Handle<Boolean> True(Isolate* isolate);
308  friend Handle<Boolean> False(Isolate* isolate);
309  friend class Context;
310  friend class HandleScope;
311  friend class Object;
312  friend class Private;
313 
317  V8_INLINE explicit Handle(T* val) : val_(val) {}
318 
319  V8_INLINE static Handle<T> New(Isolate* isolate, T* that);
320 
321  T* val_;
322 };
323 
324 
332 template <class T> class Local : public Handle<T> {
333  public:
334  V8_INLINE Local();
335  template <class S> V8_INLINE Local(Local<S> that)
336  : Handle<T>(reinterpret_cast<T*>(*that)) {
342  TYPE_CHECK(T, S);
343  }
344 
345 
346  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
347 #ifdef V8_ENABLE_CHECKS
348  // If we're going to perform the type check then we have to check
349  // that the handle isn't empty before doing the checked cast.
350  if (that.IsEmpty()) return Local<T>();
351 #endif
352  return Local<T>(T::Cast(*that));
353  }
354  template <class S> V8_INLINE Local(Handle<S> that)
355  : Handle<T>(reinterpret_cast<T*>(*that)) {
356  TYPE_CHECK(T, S);
357  }
358 
359  template <class S> V8_INLINE Local<S> As() {
360  return Local<S>::Cast(*this);
361  }
362 
368  V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that);
369  V8_INLINE static Local<T> New(Isolate* isolate,
370  const PersistentBase<T>& that);
371 
372  private:
373  friend class Utils;
374  template<class F> friend class Eternal;
375  template<class F> friend class PersistentBase;
376  template<class F, class M> friend class Persistent;
377  template<class F> friend class Handle;
378  template<class F> friend class Local;
379  template<class F> friend class FunctionCallbackInfo;
380  template<class F> friend class PropertyCallbackInfo;
381  friend class String;
382  friend class Object;
383  friend class Context;
384  template<class F> friend class internal::CustomArguments;
385  friend class HandleScope;
386  friend class EscapableHandleScope;
387  template<class F1, class F2, class F3> friend class PersistentValueMap;
388  template<class F1, class F2> friend class PersistentValueVector;
389 
390  template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { }
391  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
392 };
393 
394 
395 // Eternal handles are set-once handles that live for the life of the isolate.
396 template <class T> class Eternal {
397  public:
398  V8_INLINE Eternal() : index_(kInitialValue) { }
399  template<class S>
400  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
401  Set(isolate, handle);
402  }
403  // Can only be safely called if already set.
404  V8_INLINE Local<T> Get(Isolate* isolate);
405  V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
406  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
407 
408  private:
409  static const int kInitialValue = -1;
410  int index_;
411 };
412 
413 
414 template<class T, class P>
416  public:
417  typedef void (*Callback)(const WeakCallbackData<T, P>& data);
418 
419  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
420  V8_INLINE Local<T> GetValue() const { return handle_; }
421  V8_INLINE P* GetParameter() const { return parameter_; }
422 
423  private:
424  friend class internal::GlobalHandles;
425  WeakCallbackData(Isolate* isolate, Local<T> handle, P* parameter)
426  : isolate_(isolate), handle_(handle), parameter_(parameter) { }
427  Isolate* isolate_;
428  Local<T> handle_;
429  P* parameter_;
430 };
431 
432 
446 template <class T> class PersistentBase {
447  public:
452  V8_INLINE void Reset();
457  template <class S>
458  V8_INLINE void Reset(Isolate* isolate, const Handle<S>& other);
459 
464  template <class S>
465  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
466 
467  V8_INLINE bool IsEmpty() const { return val_ == 0; }
468 
469  template <class S>
470  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
471  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
472  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
473  if (a == 0) return b == 0;
474  if (b == 0) return false;
475  return *a == *b;
476  }
477 
478  template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
479  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
480  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
481  if (a == 0) return b == 0;
482  if (b == 0) return false;
483  return *a == *b;
484  }
485 
486  template <class S>
487  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
488  return !operator==(that);
489  }
490 
491  template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const {
492  return !operator==(that);
493  }
494 
502  template<typename P>
503  V8_INLINE void SetWeak(
504  P* parameter,
505  typename WeakCallbackData<T, P>::Callback callback);
506 
507  template<typename S, typename P>
508  V8_INLINE void SetWeak(
509  P* parameter,
510  typename WeakCallbackData<S, P>::Callback callback);
511 
512  template<typename P>
513  V8_INLINE P* ClearWeak();
514 
515  // TODO(dcarney): remove this.
516  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
517 
524  V8_INLINE void MarkIndependent();
525 
534  V8_INLINE void MarkPartiallyDependent();
535 
536  V8_INLINE bool IsIndependent() const;
537 
539  V8_INLINE bool IsNearDeath() const;
540 
542  V8_INLINE bool IsWeak() const;
543 
548  V8_INLINE void SetWrapperClassId(uint16_t class_id);
549 
554  V8_INLINE uint16_t WrapperClassId() const;
555 
556  private:
557  friend class Isolate;
558  friend class Utils;
559  template<class F> friend class Handle;
560  template<class F> friend class Local;
561  template<class F1, class F2> friend class Persistent;
562  template<class F> friend class UniquePersistent;
563  template<class F> friend class PersistentBase;
564  template<class F> friend class ReturnValue;
565  template<class F1, class F2, class F3> friend class PersistentValueMap;
566  template<class F1, class F2> friend class PersistentValueVector;
567  friend class Object;
568 
569  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
570  PersistentBase(PersistentBase& other); // NOLINT
571  void operator=(PersistentBase&);
572  V8_INLINE static T* New(Isolate* isolate, T* that);
573 
574  T* val_;
575 };
576 
577 
584 template<class T>
585 class NonCopyablePersistentTraits {
586  public:
587  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
588  static const bool kResetInDestructor = false;
589  template<class S, class M>
590  V8_INLINE static void Copy(const Persistent<S, M>& source,
591  NonCopyablePersistent* dest) {
592  Uncompilable<Object>();
593  }
594  // TODO(dcarney): come up with a good compile error here.
595  template<class O> V8_INLINE static void Uncompilable() {
596  TYPE_CHECK(O, Primitive);
597  }
598 };
599 
600 
605 template<class T>
608  static const bool kResetInDestructor = true;
609  template<class S, class M>
610  static V8_INLINE void Copy(const Persistent<S, M>& source,
611  CopyablePersistent* dest) {
612  // do nothing, just allow copy
613  }
614 };
615 
616 
625 template <class T, class M> class Persistent : public PersistentBase<T> {
626  public:
630  V8_INLINE Persistent() : PersistentBase<T>(0) { }
636  template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that)
637  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
638  TYPE_CHECK(T, S);
639  }
645  template <class S, class M2>
646  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
647  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
648  TYPE_CHECK(T, S);
649  }
656  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
657  Copy(that);
658  }
659  template <class S, class M2>
660  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
661  Copy(that);
662  }
663  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
664  Copy(that);
665  return *this;
666  }
667  template <class S, class M2>
668  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
669  Copy(that);
670  return *this;
671  }
677  V8_INLINE ~Persistent() {
678  if (M::kResetInDestructor) this->Reset();
679  }
680 
681  // TODO(dcarney): this is pretty useless, fix or remove
682  template <class S>
683  V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT
684 #ifdef V8_ENABLE_CHECKS
685  // If we're going to perform the type check then we have to check
686  // that the handle isn't empty before doing the checked cast.
687  if (!that.IsEmpty()) T::Cast(*that);
688 #endif
689  return reinterpret_cast<Persistent<T>&>(that);
690  }
691 
692  // TODO(dcarney): this is pretty useless, fix or remove
693  template <class S> V8_INLINE Persistent<S>& As() { // NOLINT
694  return Persistent<S>::Cast(*this);
695  }
696 
697  // This will be removed.
698  V8_INLINE T* ClearAndLeak();
699 
700  private:
701  friend class Isolate;
702  friend class Utils;
703  template<class F> friend class Handle;
704  template<class F> friend class Local;
705  template<class F1, class F2> friend class Persistent;
706  template<class F> friend class ReturnValue;
707 
708  template <class S> V8_INLINE Persistent(S* that) : PersistentBase<T>(that) { }
709  V8_INLINE T* operator*() const { return this->val_; }
710  template<class S, class M2>
711  V8_INLINE void Copy(const Persistent<S, M2>& that);
712 };
713 
714 
720 template<class T>
721 class UniquePersistent : public PersistentBase<T> {
722  struct RValue {
723  V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {}
724  UniquePersistent* object;
725  };
726 
727  public:
731  V8_INLINE UniquePersistent() : PersistentBase<T>(0) { }
737  template <class S>
738  V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that)
739  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
740  TYPE_CHECK(T, S);
741  }
747  template <class S>
748  V8_INLINE UniquePersistent(Isolate* isolate, const PersistentBase<S>& that)
749  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
750  TYPE_CHECK(T, S);
751  }
755  V8_INLINE UniquePersistent(RValue rvalue)
756  : PersistentBase<T>(rvalue.object->val_) {
757  rvalue.object->val_ = 0;
758  }
759  V8_INLINE ~UniquePersistent() { this->Reset(); }
763  template<class S>
765  TYPE_CHECK(T, S);
766  this->Reset();
767  this->val_ = rhs.val_;
768  rhs.val_ = 0;
769  return *this;
770  }
774  V8_INLINE operator RValue() { return RValue(this); }
778  UniquePersistent Pass() { return UniquePersistent(RValue(this)); }
779 
780  private:
783 };
784 
785 
800 class V8_EXPORT HandleScope {
801  public:
802  HandleScope(Isolate* isolate);
803 
804  ~HandleScope();
805 
809  static int NumberOfHandles(Isolate* isolate);
810 
811  V8_INLINE Isolate* GetIsolate() const {
812  return reinterpret_cast<Isolate*>(isolate_);
813  }
814 
815  protected:
816  V8_INLINE HandleScope() {}
817 
818  void Initialize(Isolate* isolate);
819 
820  static internal::Object** CreateHandle(internal::Isolate* isolate,
821  internal::Object* value);
822 
823  private:
824  // Uses heap_object to obtain the current Isolate.
825  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
826  internal::Object* value);
827 
828  // Make it hard to create heap-allocated or illegal handle scopes by
829  // disallowing certain operations.
830  HandleScope(const HandleScope&);
831  void operator=(const HandleScope&);
832  void* operator new(size_t size);
833  void operator delete(void*, size_t);
834 
835  internal::Isolate* isolate_;
836  internal::Object** prev_next_;
837  internal::Object** prev_limit_;
838 
839  // Local::New uses CreateHandle with an Isolate* parameter.
840  template<class F> friend class Local;
841 
842  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
843  // a HeapObject* in their shortcuts.
844  friend class Object;
845  friend class Context;
846 };
847 
848 
853 class V8_EXPORT EscapableHandleScope : public HandleScope {
854  public:
855  EscapableHandleScope(Isolate* isolate);
856  V8_INLINE ~EscapableHandleScope() {}
857 
862  template <class T>
863  V8_INLINE Local<T> Escape(Local<T> value) {
864  internal::Object** slot =
865  Escape(reinterpret_cast<internal::Object**>(*value));
866  return Local<T>(reinterpret_cast<T*>(slot));
867  }
868 
869  private:
870  internal::Object** Escape(internal::Object** escape_value);
871 
872  // Make it hard to create heap-allocated or illegal handle scopes by
873  // disallowing certain operations.
875  void operator=(const EscapableHandleScope&);
876  void* operator new(size_t size);
877  void operator delete(void*, size_t);
878 
879  internal::Object** escape_slot_;
880 };
881 
882 
887 template<class T>
888 struct Maybe {
889  Maybe() : has_value(false) {}
890  explicit Maybe(T t) : has_value(true), value(t) {}
891  Maybe(bool has, T t) : has_value(has), value(t) {}
892 
893  bool has_value;
894  T value;
895 };
896 
897 
898 // Convenience wrapper.
899 template <class T>
900 inline Maybe<T> maybe(T t) {
901  return Maybe<T>(t);
902 }
903 
904 
905 // --- Special objects ---
906 
907 
911 class V8_EXPORT Data {
912  private:
913  Data();
914 };
915 
916 
921  public:
922  V8_INLINE ScriptOrigin(
923  Handle<Value> resource_name,
924  Handle<Integer> resource_line_offset = Handle<Integer>(),
925  Handle<Integer> resource_column_offset = Handle<Integer>(),
926  Handle<Boolean> resource_is_shared_cross_origin = Handle<Boolean>(),
927  Handle<Integer> script_id = Handle<Integer>())
928  : resource_name_(resource_name),
929  resource_line_offset_(resource_line_offset),
930  resource_column_offset_(resource_column_offset),
931  resource_is_shared_cross_origin_(resource_is_shared_cross_origin),
932  script_id_(script_id) { }
933  V8_INLINE Handle<Value> ResourceName() const;
934  V8_INLINE Handle<Integer> ResourceLineOffset() const;
935  V8_INLINE Handle<Integer> ResourceColumnOffset() const;
936  V8_INLINE Handle<Boolean> ResourceIsSharedCrossOrigin() const;
937  V8_INLINE Handle<Integer> ScriptID() const;
938  private:
939  Handle<Value> resource_name_;
940  Handle<Integer> resource_line_offset_;
941  Handle<Integer> resource_column_offset_;
942  Handle<Boolean> resource_is_shared_cross_origin_;
943  Handle<Integer> script_id_;
944 };
945 
946 
947 class V8_EXPORT SealHandleScope {
948  public:
949  SealHandleScope(Isolate* isolate);
950  ~SealHandleScope();
951 
952  private:
953  // Make it hard to create heap-allocated or illegal handle scopes by
954  // disallowing certain operations.
956  void operator=(const SealHandleScope&);
957  void* operator new(size_t size);
958  void operator delete(void*, size_t);
959 
960  internal::Isolate* isolate_;
961  int prev_level_;
962  internal::Object** prev_limit_;
963 };
964 
965 
966 
967 
971 class V8_EXPORT UnboundScript {
972  public:
976  Local<Script> BindToCurrentContext();
977 
978  int GetId();
979  Handle<Value> GetScriptName();
980 
984  Handle<Value> GetSourceURL();
988  Handle<Value> GetSourceMappingURL();
989 
994  int GetLineNumber(int code_pos);
995 
996  static const int kNoScriptId = 0;
997 };
998 
999 
1004 class V8_EXPORT Script {
1005  public:
1009  static Local<Script> Compile(Handle<String> source,
1010  ScriptOrigin* origin = NULL);
1011 
1012  // To be decprecated, use the Compile above.
1013  static Local<Script> Compile(Handle<String> source,
1014  Handle<String> file_name);
1015 
1021  Local<Value> Run();
1022 
1026  Local<UnboundScript> GetUnboundScript();
1027 
1028  V8_DEPRECATED("Use GetUnboundScript()->GetId()",
1029  int GetId()) {
1030  return GetUnboundScript()->GetId();
1031  }
1032 };
1033 
1034 
1038 class V8_EXPORT ScriptCompiler {
1039  public:
1047  struct V8_EXPORT CachedData {
1048  enum BufferPolicy {
1049  BufferNotOwned,
1050  BufferOwned
1051  };
1052 
1053  CachedData() : data(NULL), length(0), buffer_policy(BufferNotOwned) {}
1054 
1055  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1056  // data and guarantees that it stays alive until the CachedData object is
1057  // destroyed. If the policy is BufferOwned, the given data will be deleted
1058  // (with delete[]) when the CachedData object is destroyed.
1059  CachedData(const uint8_t* data, int length,
1060  BufferPolicy buffer_policy = BufferNotOwned);
1061  ~CachedData();
1062  // TODO(marja): Async compilation; add constructors which take a callback
1063  // which will be called when V8 no longer needs the data.
1064  const uint8_t* data;
1065  int length;
1066  BufferPolicy buffer_policy;
1067 
1068  private:
1069  // Prevent copying. Not implemented.
1070  CachedData(const CachedData&);
1071  CachedData& operator=(const CachedData&);
1072  };
1073 
1077  class Source {
1078  public:
1079  // Source takes ownership of CachedData.
1080  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1081  CachedData* cached_data = NULL);
1082  V8_INLINE Source(Local<String> source_string,
1083  CachedData* cached_data = NULL);
1084  V8_INLINE ~Source();
1085 
1086  // Ownership of the CachedData or its buffers is *not* transferred to the
1087  // caller. The CachedData object is alive as long as the Source object is
1088  // alive.
1089  V8_INLINE const CachedData* GetCachedData() const;
1090 
1091  private:
1092  friend class ScriptCompiler;
1093  // Prevent copying. Not implemented.
1094  Source(const Source&);
1095  Source& operator=(const Source&);
1096 
1097  Local<String> source_string;
1098 
1099  // Origin information
1100  Handle<Value> resource_name;
1101  Handle<Integer> resource_line_offset;
1102  Handle<Integer> resource_column_offset;
1103  Handle<Boolean> resource_is_shared_cross_origin;
1104 
1105  // Cached data from previous compilation (if a kConsume*Cache flag is
1106  // set), or hold newly generated cache data (kProduce*Cache flags) are
1107  // set when calling a compile method.
1108  CachedData* cached_data;
1109  };
1110 
1111  enum CompileOptions {
1112  kNoCompileOptions = 0,
1113  kProduceParserCache,
1114  kConsumeParserCache,
1115  kProduceCodeCache,
1116  kConsumeCodeCache,
1117 
1118  // Support the previous API for a transition period.
1119  kProduceDataToCache
1120  };
1121 
1135  static Local<UnboundScript> CompileUnbound(
1136  Isolate* isolate, Source* source,
1137  CompileOptions options = kNoCompileOptions);
1138 
1150  static Local<Script> Compile(
1151  Isolate* isolate, Source* source,
1152  CompileOptions options = kNoCompileOptions);
1153 };
1154 
1155 
1159 class V8_EXPORT Message {
1160  public:
1161  Local<String> Get() const;
1162  Local<String> GetSourceLine() const;
1163 
1168  ScriptOrigin GetScriptOrigin() const;
1169 
1174  Handle<Value> GetScriptResourceName() const;
1175 
1181  Handle<StackTrace> GetStackTrace() const;
1182 
1186  int GetLineNumber() const;
1187 
1192  int GetStartPosition() const;
1193 
1198  int GetEndPosition() const;
1199 
1204  int GetStartColumn() const;
1205 
1210  int GetEndColumn() const;
1211 
1216  bool IsSharedCrossOrigin() const;
1217 
1218  // TODO(1245381): Print to a string instead of on a FILE.
1219  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1220 
1221  static const int kNoLineNumberInfo = 0;
1222  static const int kNoColumnInfo = 0;
1223  static const int kNoScriptIdInfo = 0;
1224 };
1225 
1226 
1232 class V8_EXPORT StackTrace {
1233  public:
1239  kLineNumber = 1,
1240  kColumnOffset = 1 << 1 | kLineNumber,
1241  kScriptName = 1 << 2,
1242  kFunctionName = 1 << 3,
1243  kIsEval = 1 << 4,
1244  kIsConstructor = 1 << 5,
1245  kScriptNameOrSourceURL = 1 << 6,
1246  kScriptId = 1 << 7,
1247  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1248  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1249  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1250  };
1251 
1255  Local<StackFrame> GetFrame(uint32_t index) const;
1256 
1260  int GetFrameCount() const;
1261 
1265  Local<Array> AsArray();
1266 
1274  static Local<StackTrace> CurrentStackTrace(
1275  Isolate* isolate,
1276  int frame_limit,
1277  StackTraceOptions options = kOverview);
1278 };
1279 
1280 
1284 class V8_EXPORT StackFrame {
1285  public:
1292  int GetLineNumber() const;
1293 
1301  int GetColumn() const;
1302 
1309  int GetScriptId() const;
1310 
1315  Local<String> GetScriptName() const;
1316 
1323  Local<String> GetScriptNameOrSourceURL() const;
1324 
1328  Local<String> GetFunctionName() const;
1329 
1334  bool IsEval() const;
1335 
1340  bool IsConstructor() const;
1341 };
1342 
1343 
1347 class V8_EXPORT JSON {
1348  public:
1356  static Local<Value> Parse(Local<String> json_string);
1357 };
1358 
1359 
1360 // --- Value ---
1361 
1362 
1366 class V8_EXPORT Value : public Data {
1367  public:
1372  V8_INLINE bool IsUndefined() const;
1373 
1378  V8_INLINE bool IsNull() const;
1379 
1383  bool IsTrue() const;
1384 
1388  bool IsFalse() const;
1389 
1394  V8_INLINE bool IsString() const;
1395 
1400  bool IsSymbol() const;
1401 
1405  bool IsFunction() const;
1406 
1410  bool IsArray() const;
1411 
1415  bool IsObject() const;
1416 
1420  bool IsBoolean() const;
1421 
1425  bool IsNumber() const;
1426 
1430  bool IsExternal() const;
1431 
1435  bool IsInt32() const;
1436 
1440  bool IsUint32() const;
1441 
1445  bool IsDate() const;
1446 
1450  bool IsBooleanObject() const;
1451 
1455  bool IsNumberObject() const;
1456 
1460  bool IsStringObject() const;
1461 
1466  bool IsSymbolObject() const;
1467 
1471  bool IsNativeError() const;
1472 
1476  bool IsRegExp() const;
1477 
1482  bool IsPromise() const;
1483 
1488  bool IsArrayBuffer() const;
1489 
1494  bool IsArrayBufferView() const;
1495 
1500  bool IsTypedArray() const;
1501 
1506  bool IsUint8Array() const;
1507 
1512  bool IsUint8ClampedArray() const;
1513 
1518  bool IsInt8Array() const;
1519 
1524  bool IsUint16Array() const;
1525 
1530  bool IsInt16Array() const;
1531 
1536  bool IsUint32Array() const;
1537 
1542  bool IsInt32Array() const;
1543 
1548  bool IsFloat32Array() const;
1549 
1554  bool IsFloat64Array() const;
1555 
1560  bool IsDataView() const;
1561 
1562  Local<Boolean> ToBoolean() const;
1563  Local<Number> ToNumber() const;
1564  Local<String> ToString() const;
1565  Local<String> ToDetailString() const;
1566  Local<Object> ToObject() const;
1567  Local<Integer> ToInteger() const;
1568  Local<Uint32> ToUint32() const;
1569  Local<Int32> ToInt32() const;
1570 
1575  Local<Uint32> ToArrayIndex() const;
1576 
1577  bool BooleanValue() const;
1578  double NumberValue() const;
1579  int64_t IntegerValue() const;
1580  uint32_t Uint32Value() const;
1581  int32_t Int32Value() const;
1582 
1584  bool Equals(Handle<Value> that) const;
1585  bool StrictEquals(Handle<Value> that) const;
1586  bool SameValue(Handle<Value> that) const;
1587 
1588  template <class T> V8_INLINE static Value* Cast(T* value);
1589 
1590  private:
1591  V8_INLINE bool QuickIsUndefined() const;
1592  V8_INLINE bool QuickIsNull() const;
1593  V8_INLINE bool QuickIsString() const;
1594  bool FullIsUndefined() const;
1595  bool FullIsNull() const;
1596  bool FullIsString() const;
1597 };
1598 
1599 
1603 class V8_EXPORT Primitive : public Value { };
1604 
1605 
1610 class V8_EXPORT Boolean : public Primitive {
1611  public:
1612  bool Value() const;
1613  V8_INLINE static Handle<Boolean> New(Isolate* isolate, bool value);
1614 };
1615 
1616 
1620 class V8_EXPORT String : public Primitive {
1621  public:
1622  enum Encoding {
1623  UNKNOWN_ENCODING = 0x1,
1624  TWO_BYTE_ENCODING = 0x0,
1625  ASCII_ENCODING = 0x4,
1626  ONE_BYTE_ENCODING = 0x4
1627  };
1631  int Length() const;
1632 
1637  int Utf8Length() const;
1638 
1644  bool IsOneByte() const;
1645 
1650  bool ContainsOnlyOneByte() const;
1651 
1678  NO_OPTIONS = 0,
1679  HINT_MANY_WRITES_EXPECTED = 1,
1680  NO_NULL_TERMINATION = 2,
1681  PRESERVE_ASCII_NULL = 4,
1682  // Used by WriteUtf8 to replace orphan surrogate code units with the
1683  // unicode replacement character. Needs to be set to guarantee valid UTF-8
1684  // output.
1685  REPLACE_INVALID_UTF8 = 8
1686  };
1687 
1688  // 16-bit character codes.
1689  int Write(uint16_t* buffer,
1690  int start = 0,
1691  int length = -1,
1692  int options = NO_OPTIONS) const;
1693  // One byte characters.
1694  int WriteOneByte(uint8_t* buffer,
1695  int start = 0,
1696  int length = -1,
1697  int options = NO_OPTIONS) const;
1698  // UTF-8 encoded characters.
1699  int WriteUtf8(char* buffer,
1700  int length = -1,
1701  int* nchars_ref = NULL,
1702  int options = NO_OPTIONS) const;
1703 
1707  V8_INLINE static v8::Local<v8::String> Empty(Isolate* isolate);
1708 
1712  bool IsExternal() const;
1713 
1717  bool IsExternalAscii() const;
1718 
1719  class V8_EXPORT ExternalStringResourceBase { // NOLINT
1720  public:
1721  virtual ~ExternalStringResourceBase() {}
1722 
1723  protected:
1725 
1732  virtual void Dispose() { delete this; }
1733 
1734  private:
1735  // Disallow copying and assigning.
1737  void operator=(const ExternalStringResourceBase&);
1738 
1739  friend class v8::internal::Heap;
1740  };
1741 
1748  class V8_EXPORT ExternalStringResource
1749  : public ExternalStringResourceBase {
1750  public:
1756 
1760  virtual const uint16_t* data() const = 0;
1761 
1765  virtual size_t length() const = 0;
1766 
1767  protected:
1769  };
1770 
1783  : public ExternalStringResourceBase {
1784  public:
1791  virtual const char* data() const = 0;
1793  virtual size_t length() const = 0;
1794  protected:
1796  };
1797 
1798  typedef ExternalAsciiStringResource ExternalOneByteStringResource;
1799 
1805  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
1806  Encoding* encoding_out) const;
1807 
1812  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
1813 
1818  const ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
1819 
1820  V8_INLINE static String* Cast(v8::Value* obj);
1821 
1822  enum NewStringType {
1823  kNormalString, kInternalizedString, kUndetectableString
1824  };
1825 
1827  static Local<String> NewFromUtf8(Isolate* isolate,
1828  const char* data,
1829  NewStringType type = kNormalString,
1830  int length = -1);
1831 
1833  static Local<String> NewFromOneByte(
1834  Isolate* isolate,
1835  const uint8_t* data,
1836  NewStringType type = kNormalString,
1837  int length = -1);
1838 
1840  static Local<String> NewFromTwoByte(
1841  Isolate* isolate,
1842  const uint16_t* data,
1843  NewStringType type = kNormalString,
1844  int length = -1);
1845 
1850  static Local<String> Concat(Handle<String> left, Handle<String> right);
1851 
1860  static Local<String> NewExternal(Isolate* isolate,
1861  ExternalStringResource* resource);
1862 
1872  bool MakeExternal(ExternalStringResource* resource);
1873 
1882  static Local<String> NewExternal(Isolate* isolate,
1883  ExternalAsciiStringResource* resource);
1884 
1894  bool MakeExternal(ExternalAsciiStringResource* resource);
1895 
1899  bool CanMakeExternal();
1900 
1908  class V8_EXPORT Utf8Value {
1909  public:
1910  explicit Utf8Value(Handle<v8::Value> obj);
1911  ~Utf8Value();
1912  char* operator*() { return str_; }
1913  const char* operator*() const { return str_; }
1914  int length() const { return length_; }
1915  private:
1916  char* str_;
1917  int length_;
1918 
1919  // Disallow copying and assigning.
1920  Utf8Value(const Utf8Value&);
1921  void operator=(const Utf8Value&);
1922  };
1923 
1930  class V8_EXPORT Value {
1931  public:
1932  explicit Value(Handle<v8::Value> obj);
1933  ~Value();
1934  uint16_t* operator*() { return str_; }
1935  const uint16_t* operator*() const { return str_; }
1936  int length() const { return length_; }
1937  private:
1938  uint16_t* str_;
1939  int length_;
1940 
1941  // Disallow copying and assigning.
1942  Value(const Value&);
1943  void operator=(const Value&);
1944  };
1945 
1946  private:
1947  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
1948  Encoding encoding) const;
1949  void VerifyExternalStringResource(ExternalStringResource* val) const;
1950  static void CheckCast(v8::Value* obj);
1951 };
1952 
1953 
1959 class V8_EXPORT Symbol : public Primitive {
1960  public:
1961  // Returns the print name string of the symbol, or undefined if none.
1962  Local<Value> Name() const;
1963 
1964  // Create a symbol. If name is not empty, it will be used as the description.
1965  static Local<Symbol> New(
1966  Isolate *isolate, Local<String> name = Local<String>());
1967 
1968  // Access global symbol registry.
1969  // Note that symbols created this way are never collected, so
1970  // they should only be used for statically fixed properties.
1971  // Also, there is only one global name space for the names used as keys.
1972  // To minimize the potential for clashes, use qualified names as keys.
1973  static Local<Symbol> For(Isolate *isolate, Local<String> name);
1974 
1975  // Retrieve a global symbol. Similar to |For|, but using a separate
1976  // registry that is not accessible by (and cannot clash with) JavaScript code.
1977  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
1978 
1979  V8_INLINE static Symbol* Cast(v8::Value* obj);
1980  private:
1981  Symbol();
1982  static void CheckCast(v8::Value* obj);
1983 };
1984 
1985 
1991 class V8_EXPORT Private : public Data {
1992  public:
1993  // Returns the print name string of the private symbol, or undefined if none.
1994  Local<Value> Name() const;
1995 
1996  // Create a private symbol. If name is not empty, it will be the description.
1997  static Local<Private> New(
1998  Isolate *isolate, Local<String> name = Local<String>());
1999 
2000  // Retrieve a global private symbol. If a symbol with this name has not
2001  // been retrieved in the same isolate before, it is created.
2002  // Note that private symbols created this way are never collected, so
2003  // they should only be used for statically fixed properties.
2004  // Also, there is only one global name space for the names used as keys.
2005  // To minimize the potential for clashes, use qualified names as keys,
2006  // e.g., "Class#property".
2007  static Local<Private> ForApi(Isolate *isolate, Local<String> name);
2008 
2009  private:
2010  Private();
2011 };
2012 
2013 
2017 class V8_EXPORT Number : public Primitive {
2018  public:
2019  double Value() const;
2020  static Local<Number> New(Isolate* isolate, double value);
2021  V8_INLINE static Number* Cast(v8::Value* obj);
2022  private:
2023  Number();
2024  static void CheckCast(v8::Value* obj);
2025 };
2026 
2027 
2031 class V8_EXPORT Integer : public Number {
2032  public:
2033  static Local<Integer> New(Isolate* isolate, int32_t value);
2034  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2035  int64_t Value() const;
2036  V8_INLINE static Integer* Cast(v8::Value* obj);
2037  private:
2038  Integer();
2039  static void CheckCast(v8::Value* obj);
2040 };
2041 
2042 
2046 class V8_EXPORT Int32 : public Integer {
2047  public:
2048  int32_t Value() const;
2049  private:
2050  Int32();
2051 };
2052 
2053 
2057 class V8_EXPORT Uint32 : public Integer {
2058  public:
2059  uint32_t Value() const;
2060  private:
2061  Uint32();
2062 };
2063 
2064 
2065 enum PropertyAttribute {
2066  None = 0,
2067  ReadOnly = 1 << 0,
2068  DontEnum = 1 << 1,
2069  DontDelete = 1 << 2
2070 };
2071 
2072 enum ExternalArrayType {
2073  kExternalInt8Array = 1,
2074  kExternalUint8Array,
2075  kExternalInt16Array,
2076  kExternalUint16Array,
2077  kExternalInt32Array,
2078  kExternalUint32Array,
2079  kExternalFloat32Array,
2080  kExternalFloat64Array,
2081  kExternalUint8ClampedArray,
2082 
2083  // Legacy constant names
2084  kExternalByteArray = kExternalInt8Array,
2085  kExternalUnsignedByteArray = kExternalUint8Array,
2086  kExternalShortArray = kExternalInt16Array,
2087  kExternalUnsignedShortArray = kExternalUint16Array,
2088  kExternalIntArray = kExternalInt32Array,
2089  kExternalUnsignedIntArray = kExternalUint32Array,
2090  kExternalFloatArray = kExternalFloat32Array,
2091  kExternalDoubleArray = kExternalFloat64Array,
2092  kExternalPixelArray = kExternalUint8ClampedArray
2093 };
2094 
2100 typedef void (*AccessorGetterCallback)(
2101  Local<String> property,
2102  const PropertyCallbackInfo<Value>& info);
2103 
2104 
2105 typedef void (*AccessorSetterCallback)(
2106  Local<String> property,
2107  Local<Value> value,
2108  const PropertyCallbackInfo<void>& info);
2109 
2110 
2121  DEFAULT = 0,
2122  ALL_CAN_READ = 1,
2123  ALL_CAN_WRITE = 1 << 1,
2124  PROHIBITS_OVERWRITING = 1 << 2
2125 };
2126 
2127 
2131 class V8_EXPORT Object : public Value {
2132  public:
2133  bool Set(Handle<Value> key, Handle<Value> value);
2134 
2135  bool Set(uint32_t index, Handle<Value> value);
2136 
2137  // Sets an own property on this object bypassing interceptors and
2138  // overriding accessors or read-only properties.
2139  //
2140  // Note that if the object has an interceptor the property will be set
2141  // locally, but since the interceptor takes precedence the local property
2142  // will only be returned if the interceptor doesn't return a value.
2143  //
2144  // Note also that this only works for named properties.
2145  bool ForceSet(Handle<Value> key,
2146  Handle<Value> value,
2147  PropertyAttribute attribs = None);
2148 
2149  Local<Value> Get(Handle<Value> key);
2150 
2151  Local<Value> Get(uint32_t index);
2152 
2158  PropertyAttribute GetPropertyAttributes(Handle<Value> key);
2159 
2163  Local<Value> GetOwnPropertyDescriptor(Local<String> key);
2164 
2165  bool Has(Handle<Value> key);
2166 
2167  bool Delete(Handle<Value> key);
2168 
2169  // Delete a property on this object bypassing interceptors and
2170  // ignoring dont-delete attributes.
2171  bool ForceDelete(Handle<Value> key);
2172 
2173  bool Has(uint32_t index);
2174 
2175  bool Delete(uint32_t index);
2176 
2177  bool SetAccessor(Handle<String> name,
2178  AccessorGetterCallback getter,
2179  AccessorSetterCallback setter = 0,
2180  Handle<Value> data = Handle<Value>(),
2181  AccessControl settings = DEFAULT,
2182  PropertyAttribute attribute = None);
2183 
2184  // This function is not yet stable and should not be used at this time.
2185  bool SetDeclaredAccessor(Local<String> name,
2187  PropertyAttribute attribute = None,
2188  AccessControl settings = DEFAULT);
2189 
2190  void SetAccessorProperty(Local<String> name,
2191  Local<Function> getter,
2193  PropertyAttribute attribute = None,
2194  AccessControl settings = DEFAULT);
2195 
2202  bool HasPrivate(Handle<Private> key);
2203  bool SetPrivate(Handle<Private> key, Handle<Value> value);
2204  bool DeletePrivate(Handle<Private> key);
2205  Local<Value> GetPrivate(Handle<Private> key);
2206 
2213  Local<Array> GetPropertyNames();
2214 
2220  Local<Array> GetOwnPropertyNames();
2221 
2227  Local<Value> GetPrototype();
2228 
2234  bool SetPrototype(Handle<Value> prototype);
2235 
2240  Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl);
2241 
2247  Local<String> ObjectProtoToString();
2248 
2252  Local<String> GetConstructorName();
2253 
2255  int InternalFieldCount();
2256 
2258  V8_INLINE static int InternalFieldCount(
2259  const PersistentBase<Object>& object) {
2260  return object.val_->InternalFieldCount();
2261  }
2262 
2264  V8_INLINE Local<Value> GetInternalField(int index);
2265 
2267  void SetInternalField(int index, Handle<Value> value);
2268 
2274  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
2275 
2277  V8_INLINE static void* GetAlignedPointerFromInternalField(
2278  const PersistentBase<Object>& object, int index) {
2279  return object.val_->GetAlignedPointerFromInternalField(index);
2280  }
2281 
2287  void SetAlignedPointerInInternalField(int index, void* value);
2288 
2289  // Testers for local properties.
2290  bool HasOwnProperty(Handle<String> key);
2291  bool HasRealNamedProperty(Handle<String> key);
2292  bool HasRealIndexedProperty(uint32_t index);
2293  bool HasRealNamedCallbackProperty(Handle<String> key);
2294 
2299  Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
2300 
2306  Local<Value> GetRealNamedProperty(Handle<String> key);
2307 
2309  bool HasNamedLookupInterceptor();
2310 
2312  bool HasIndexedLookupInterceptor();
2313 
2319  void TurnOnAccessCheck();
2320 
2328  int GetIdentityHash();
2329 
2336  bool SetHiddenValue(Handle<String> key, Handle<Value> value);
2337  Local<Value> GetHiddenValue(Handle<String> key);
2338  bool DeleteHiddenValue(Handle<String> key);
2339 
2347  bool IsDirty();
2348 
2353  Local<Object> Clone();
2354 
2358  Local<Context> CreationContext();
2359 
2367  void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
2368  bool HasIndexedPropertiesInPixelData();
2369  uint8_t* GetIndexedPropertiesPixelData();
2370  int GetIndexedPropertiesPixelDataLength();
2371 
2379  void SetIndexedPropertiesToExternalArrayData(void* data,
2380  ExternalArrayType array_type,
2381  int number_of_elements);
2382  bool HasIndexedPropertiesInExternalArrayData();
2383  void* GetIndexedPropertiesExternalArrayData();
2384  ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
2385  int GetIndexedPropertiesExternalArrayDataLength();
2386 
2392  bool IsCallable();
2393 
2398  Local<Value> CallAsFunction(Handle<Value> recv,
2399  int argc,
2400  Handle<Value> argv[]);
2401 
2407  Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]);
2408 
2409  static Local<Object> New(Isolate* isolate);
2410 
2411  V8_INLINE static Object* Cast(Value* obj);
2412 
2413  private:
2414  Object();
2415  static void CheckCast(Value* obj);
2416  Local<Value> SlowGetInternalField(int index);
2417  void* SlowGetAlignedPointerFromInternalField(int index);
2418 };
2419 
2420 
2424 class V8_EXPORT Array : public Object {
2425  public:
2426  uint32_t Length() const;
2427 
2432  Local<Object> CloneElementAt(uint32_t index);
2433 
2438  static Local<Array> New(Isolate* isolate, int length = 0);
2439 
2440  V8_INLINE static Array* Cast(Value* obj);
2441  private:
2442  Array();
2443  static void CheckCast(Value* obj);
2444 };
2445 
2446 
2447 template<typename T>
2448 class ReturnValue {
2449  public:
2450  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
2451  : value_(that.value_) {
2452  TYPE_CHECK(T, S);
2453  }
2454  // Handle setters
2455  template <typename S> V8_INLINE void Set(const Persistent<S>& handle);
2456  template <typename S> V8_INLINE void Set(const Handle<S> handle);
2457  // Fast primitive setters
2458  V8_INLINE void Set(bool value);
2459  V8_INLINE void Set(double i);
2460  V8_INLINE void Set(int32_t i);
2461  V8_INLINE void Set(uint32_t i);
2462  // Fast JS primitive setters
2463  V8_INLINE void SetNull();
2464  V8_INLINE void SetUndefined();
2465  V8_INLINE void SetEmptyString();
2466  // Convenience getter for Isolate
2467  V8_INLINE Isolate* GetIsolate();
2468 
2469  // Pointer setter: Uncompilable to prevent inadvertent misuse.
2470  template <typename S>
2471  V8_INLINE void Set(S* whatever);
2472 
2473  private:
2474  template<class F> friend class ReturnValue;
2475  template<class F> friend class FunctionCallbackInfo;
2476  template<class F> friend class PropertyCallbackInfo;
2477  template<class F, class G, class H> friend class PersistentValueMap;
2478  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
2479  V8_INLINE internal::Object* GetDefaultValue();
2480  V8_INLINE explicit ReturnValue(internal::Object** slot);
2481  internal::Object** value_;
2482 };
2483 
2484 
2491 template<typename T>
2492 class FunctionCallbackInfo {
2493  public:
2494  V8_INLINE int Length() const;
2495  V8_INLINE Local<Value> operator[](int i) const;
2496  V8_INLINE Local<Function> Callee() const;
2497  V8_INLINE Local<Object> This() const;
2498  V8_INLINE Local<Object> Holder() const;
2499  V8_INLINE bool IsConstructCall() const;
2500  V8_INLINE Local<Value> Data() const;
2501  V8_INLINE Isolate* GetIsolate() const;
2502  V8_INLINE ReturnValue<T> GetReturnValue() const;
2503  // This shouldn't be public, but the arm compiler needs it.
2504  static const int kArgsLength = 7;
2505 
2506  protected:
2507  friend class internal::FunctionCallbackArguments;
2508  friend class internal::CustomArguments<FunctionCallbackInfo>;
2509  static const int kHolderIndex = 0;
2510  static const int kIsolateIndex = 1;
2511  static const int kReturnValueDefaultValueIndex = 2;
2512  static const int kReturnValueIndex = 3;
2513  static const int kDataIndex = 4;
2514  static const int kCalleeIndex = 5;
2515  static const int kContextSaveIndex = 6;
2516 
2517  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
2518  internal::Object** values,
2519  int length,
2520  bool is_construct_call);
2521  internal::Object** implicit_args_;
2522  internal::Object** values_;
2523  int length_;
2524  bool is_construct_call_;
2525 };
2526 
2527 
2532 template<typename T>
2533 class PropertyCallbackInfo {
2534  public:
2535  V8_INLINE Isolate* GetIsolate() const;
2536  V8_INLINE Local<Value> Data() const;
2537  V8_INLINE Local<Object> This() const;
2538  V8_INLINE Local<Object> Holder() const;
2539  V8_INLINE ReturnValue<T> GetReturnValue() const;
2540  // This shouldn't be public, but the arm compiler needs it.
2541  static const int kArgsLength = 6;
2542 
2543  protected:
2544  friend class MacroAssembler;
2545  friend class internal::PropertyCallbackArguments;
2546  friend class internal::CustomArguments<PropertyCallbackInfo>;
2547  static const int kHolderIndex = 0;
2548  static const int kIsolateIndex = 1;
2549  static const int kReturnValueDefaultValueIndex = 2;
2550  static const int kReturnValueIndex = 3;
2551  static const int kDataIndex = 4;
2552  static const int kThisIndex = 5;
2553 
2554  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
2555  internal::Object** args_;
2556 };
2557 
2558 
2559 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
2560 
2561 
2565 class V8_EXPORT Function : public Object {
2566  public:
2571  static Local<Function> New(Isolate* isolate,
2572  FunctionCallback callback,
2573  Local<Value> data = Local<Value>(),
2574  int length = 0);
2575 
2576  Local<Object> NewInstance() const;
2577  Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
2578  Local<Value> Call(Handle<Value> recv, int argc, Handle<Value> argv[]);
2579  void SetName(Handle<String> name);
2580  Handle<Value> GetName() const;
2581 
2588  Handle<Value> GetInferredName() const;
2589 
2594  Handle<Value> GetDisplayName() const;
2595 
2600  int GetScriptLineNumber() const;
2605  int GetScriptColumnNumber() const;
2606 
2610  bool IsBuiltin() const;
2611 
2615  int ScriptId() const;
2616 
2621  Local<Value> GetBoundFunction() const;
2622 
2623  ScriptOrigin GetScriptOrigin() const;
2624  V8_INLINE static Function* Cast(Value* obj);
2625  static const int kLineOffsetNotFound;
2626 
2627  private:
2628  Function();
2629  static void CheckCast(Value* obj);
2630 };
2631 
2632 
2637 class V8_EXPORT Promise : public Object {
2638  public:
2639  class V8_EXPORT Resolver : public Object {
2640  public:
2644  static Local<Resolver> New(Isolate* isolate);
2645 
2649  Local<Promise> GetPromise();
2650 
2655  void Resolve(Handle<Value> value);
2656  void Reject(Handle<Value> value);
2657 
2658  V8_INLINE static Resolver* Cast(Value* obj);
2659 
2660  private:
2661  Resolver();
2662  static void CheckCast(Value* obj);
2663  };
2664 
2671  Local<Promise> Chain(Handle<Function> handler);
2672  Local<Promise> Catch(Handle<Function> handler);
2673  Local<Promise> Then(Handle<Function> handler);
2674 
2675  V8_INLINE static Promise* Cast(Value* obj);
2676 
2677  private:
2678  Promise();
2679  static void CheckCast(Value* obj);
2680 };
2681 
2682 
2683 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
2684 // The number of required internal fields can be defined by embedder.
2685 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
2686 #endif
2687 
2692 class V8_EXPORT ArrayBuffer : public Object {
2693  public:
2701  class V8_EXPORT Allocator { // NOLINT
2702  public:
2703  virtual ~Allocator() {}
2704 
2709  virtual void* Allocate(size_t length) = 0;
2710 
2715  virtual void* AllocateUninitialized(size_t length) = 0;
2720  virtual void Free(void* data, size_t length) = 0;
2721  };
2722 
2733  class V8_EXPORT Contents { // NOLINT
2734  public:
2735  Contents() : data_(NULL), byte_length_(0) {}
2736 
2737  void* Data() const { return data_; }
2738  size_t ByteLength() const { return byte_length_; }
2739 
2740  private:
2741  void* data_;
2742  size_t byte_length_;
2743 
2744  friend class ArrayBuffer;
2745  };
2746 
2747 
2751  size_t ByteLength() const;
2752 
2759  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
2760 
2767  static Local<ArrayBuffer> New(Isolate* isolate, void* data,
2768  size_t byte_length);
2769 
2774  bool IsExternal() const;
2775 
2782  void Neuter();
2783 
2793  Contents Externalize();
2794 
2795  V8_INLINE static ArrayBuffer* Cast(Value* obj);
2796 
2797  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
2798 
2799  private:
2800  ArrayBuffer();
2801  static void CheckCast(Value* obj);
2802 };
2803 
2804 
2805 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
2806 // The number of required internal fields can be defined by embedder.
2807 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
2808 #endif
2809 
2810 
2817 class V8_EXPORT ArrayBufferView : public Object {
2818  public:
2822  Local<ArrayBuffer> Buffer();
2826  size_t ByteOffset();
2830  size_t ByteLength();
2831 
2832  V8_INLINE static ArrayBufferView* Cast(Value* obj);
2833 
2834  static const int kInternalFieldCount =
2835  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
2836 
2837  private:
2838  ArrayBufferView();
2839  static void CheckCast(Value* obj);
2840 };
2841 
2842 
2848 class V8_EXPORT TypedArray : public ArrayBufferView {
2849  public:
2854  size_t Length();
2855 
2856  V8_INLINE static TypedArray* Cast(Value* obj);
2857 
2858  private:
2859  TypedArray();
2860  static void CheckCast(Value* obj);
2861 };
2862 
2863 
2868 class V8_EXPORT Uint8Array : public TypedArray {
2869  public:
2870  static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer,
2871  size_t byte_offset, size_t length);
2872  V8_INLINE static Uint8Array* Cast(Value* obj);
2873 
2874  private:
2875  Uint8Array();
2876  static void CheckCast(Value* obj);
2877 };
2878 
2879 
2884 class V8_EXPORT Uint8ClampedArray : public TypedArray {
2885  public:
2886  static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer,
2887  size_t byte_offset, size_t length);
2888  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
2889 
2890  private:
2892  static void CheckCast(Value* obj);
2893 };
2894 
2899 class V8_EXPORT Int8Array : public TypedArray {
2900  public:
2901  static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer,
2902  size_t byte_offset, size_t length);
2903  V8_INLINE static Int8Array* Cast(Value* obj);
2904 
2905  private:
2906  Int8Array();
2907  static void CheckCast(Value* obj);
2908 };
2909 
2910 
2915 class V8_EXPORT Uint16Array : public TypedArray {
2916  public:
2917  static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer,
2918  size_t byte_offset, size_t length);
2919  V8_INLINE static Uint16Array* Cast(Value* obj);
2920 
2921  private:
2922  Uint16Array();
2923  static void CheckCast(Value* obj);
2924 };
2925 
2926 
2931 class V8_EXPORT Int16Array : public TypedArray {
2932  public:
2933  static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer,
2934  size_t byte_offset, size_t length);
2935  V8_INLINE static Int16Array* Cast(Value* obj);
2936 
2937  private:
2938  Int16Array();
2939  static void CheckCast(Value* obj);
2940 };
2941 
2942 
2947 class V8_EXPORT Uint32Array : public TypedArray {
2948  public:
2949  static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer,
2950  size_t byte_offset, size_t length);
2951  V8_INLINE static Uint32Array* Cast(Value* obj);
2952 
2953  private:
2954  Uint32Array();
2955  static void CheckCast(Value* obj);
2956 };
2957 
2958 
2963 class V8_EXPORT Int32Array : public TypedArray {
2964  public:
2965  static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer,
2966  size_t byte_offset, size_t length);
2967  V8_INLINE static Int32Array* Cast(Value* obj);
2968 
2969  private:
2970  Int32Array();
2971  static void CheckCast(Value* obj);
2972 };
2973 
2974 
2979 class V8_EXPORT Float32Array : public TypedArray {
2980  public:
2981  static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer,
2982  size_t byte_offset, size_t length);
2983  V8_INLINE static Float32Array* Cast(Value* obj);
2984 
2985  private:
2986  Float32Array();
2987  static void CheckCast(Value* obj);
2988 };
2989 
2990 
2995 class V8_EXPORT Float64Array : public TypedArray {
2996  public:
2997  static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer,
2998  size_t byte_offset, size_t length);
2999  V8_INLINE static Float64Array* Cast(Value* obj);
3000 
3001  private:
3002  Float64Array();
3003  static void CheckCast(Value* obj);
3004 };
3005 
3006 
3011 class V8_EXPORT DataView : public ArrayBufferView {
3012  public:
3013  static Local<DataView> New(Handle<ArrayBuffer> array_buffer,
3014  size_t byte_offset, size_t length);
3015  V8_INLINE static DataView* Cast(Value* obj);
3016 
3017  private:
3018  DataView();
3019  static void CheckCast(Value* obj);
3020 };
3021 
3022 
3026 class V8_EXPORT Date : public Object {
3027  public:
3028  static Local<Value> New(Isolate* isolate, double time);
3029 
3034  double ValueOf() const;
3035 
3036  V8_INLINE static Date* Cast(v8::Value* obj);
3037 
3050  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
3051 
3052  private:
3053  static void CheckCast(v8::Value* obj);
3054 };
3055 
3056 
3060 class V8_EXPORT NumberObject : public Object {
3061  public:
3062  static Local<Value> New(Isolate* isolate, double value);
3063 
3064  double ValueOf() const;
3065 
3066  V8_INLINE static NumberObject* Cast(v8::Value* obj);
3067 
3068  private:
3069  static void CheckCast(v8::Value* obj);
3070 };
3071 
3072 
3076 class V8_EXPORT BooleanObject : public Object {
3077  public:
3078  static Local<Value> New(bool value);
3079 
3080  bool ValueOf() const;
3081 
3082  V8_INLINE static BooleanObject* Cast(v8::Value* obj);
3083 
3084  private:
3085  static void CheckCast(v8::Value* obj);
3086 };
3087 
3088 
3092 class V8_EXPORT StringObject : public Object {
3093  public:
3094  static Local<Value> New(Handle<String> value);
3095 
3096  Local<String> ValueOf() const;
3097 
3098  V8_INLINE static StringObject* Cast(v8::Value* obj);
3099 
3100  private:
3101  static void CheckCast(v8::Value* obj);
3102 };
3103 
3104 
3110 class V8_EXPORT SymbolObject : public Object {
3111  public:
3112  static Local<Value> New(Isolate* isolate, Handle<Symbol> value);
3113 
3114  Local<Symbol> ValueOf() const;
3115 
3116  V8_INLINE static SymbolObject* Cast(v8::Value* obj);
3117 
3118  private:
3119  static void CheckCast(v8::Value* obj);
3120 };
3121 
3122 
3126 class V8_EXPORT RegExp : public Object {
3127  public:
3132  enum Flags {
3133  kNone = 0,
3134  kGlobal = 1,
3135  kIgnoreCase = 2,
3136  kMultiline = 4
3137  };
3138 
3149  static Local<RegExp> New(Handle<String> pattern, Flags flags);
3150 
3155  Local<String> GetSource() const;
3156 
3160  Flags GetFlags() const;
3161 
3162  V8_INLINE static RegExp* Cast(v8::Value* obj);
3163 
3164  private:
3165  static void CheckCast(v8::Value* obj);
3166 };
3167 
3168 
3173 class V8_EXPORT External : public Value {
3174  public:
3175  static Local<External> New(Isolate* isolate, void* value);
3176  V8_INLINE static External* Cast(Value* obj);
3177  void* Value() const;
3178  private:
3179  static void CheckCast(v8::Value* obj);
3180 };
3181 
3182 
3183 // --- Templates ---
3184 
3185 
3189 class V8_EXPORT Template : public Data {
3190  public:
3192  void Set(Handle<String> name, Handle<Data> value,
3193  PropertyAttribute attributes = None);
3194  V8_INLINE void Set(Isolate* isolate, const char* name, Handle<Data> value);
3195 
3196  void SetAccessorProperty(
3197  Local<String> name,
3200  PropertyAttribute attribute = None,
3201  AccessControl settings = DEFAULT);
3202 
3230  void SetNativeDataProperty(Local<String> name,
3231  AccessorGetterCallback getter,
3232  AccessorSetterCallback setter = 0,
3233  // TODO(dcarney): gcc can't handle Local below
3234  Handle<Value> data = Handle<Value>(),
3235  PropertyAttribute attribute = None,
3236  Local<AccessorSignature> signature =
3238  AccessControl settings = DEFAULT);
3239 
3240  // This function is not yet stable and should not be used at this time.
3241  bool SetDeclaredAccessor(Local<String> name,
3243  PropertyAttribute attribute = None,
3244  Local<AccessorSignature> signature =
3246  AccessControl settings = DEFAULT);
3247 
3248  private:
3249  Template();
3250 
3251  friend class ObjectTemplate;
3252  friend class FunctionTemplate;
3253 };
3254 
3255 
3261  Local<String> property,
3262  const PropertyCallbackInfo<Value>& info);
3263 
3264 
3270  Local<String> property,
3271  Local<Value> value,
3272  const PropertyCallbackInfo<Value>& info);
3273 
3274 
3281  Local<String> property,
3282  const PropertyCallbackInfo<Integer>& info);
3283 
3284 
3291  Local<String> property,
3292  const PropertyCallbackInfo<Boolean>& info);
3293 
3294 
3300  const PropertyCallbackInfo<Array>& info);
3301 
3302 
3308  uint32_t index,
3309  const PropertyCallbackInfo<Value>& info);
3310 
3311 
3317  uint32_t index,
3318  Local<Value> value,
3319  const PropertyCallbackInfo<Value>& info);
3320 
3321 
3327  uint32_t index,
3328  const PropertyCallbackInfo<Integer>& info);
3329 
3330 
3337  uint32_t index,
3338  const PropertyCallbackInfo<Boolean>& info);
3339 
3340 
3346  const PropertyCallbackInfo<Array>& info);
3347 
3348 
3353  ACCESS_GET,
3354  ACCESS_SET,
3355  ACCESS_HAS,
3356  ACCESS_DELETE,
3357  ACCESS_KEYS
3358 };
3359 
3360 
3366  Local<Value> key,
3367  AccessType type,
3368  Local<Value> data);
3369 
3370 
3376  uint32_t index,
3377  AccessType type,
3378  Local<Value> data);
3379 
3380 
3473 class V8_EXPORT FunctionTemplate : public Template {
3474  public:
3476  static Local<FunctionTemplate> New(
3477  Isolate* isolate,
3478  FunctionCallback callback = 0,
3479  Handle<Value> data = Handle<Value>(),
3480  Handle<Signature> signature = Handle<Signature>(),
3481  int length = 0);
3482 
3484  Local<Function> GetFunction();
3485 
3491  void SetCallHandler(FunctionCallback callback,
3492  Handle<Value> data = Handle<Value>());
3493 
3495  void SetLength(int length);
3496 
3498  Local<ObjectTemplate> InstanceTemplate();
3499 
3501  void Inherit(Handle<FunctionTemplate> parent);
3502 
3507  Local<ObjectTemplate> PrototypeTemplate();
3508 
3514  void SetClassName(Handle<String> name);
3515 
3528  void SetHiddenPrototype(bool value);
3529 
3534  void ReadOnlyPrototype();
3535 
3540  void RemovePrototype();
3541 
3546  bool HasInstance(Handle<Value> object);
3547 
3548  private:
3549  FunctionTemplate();
3550  friend class Context;
3551  friend class ObjectTemplate;
3552 };
3553 
3554 
3561 class V8_EXPORT ObjectTemplate : public Template {
3562  public:
3564  static Local<ObjectTemplate> New(Isolate* isolate);
3565  // Will be deprecated soon.
3566  static Local<ObjectTemplate> New();
3567 
3569  Local<Object> NewInstance();
3570 
3600  void SetAccessor(Handle<String> name,
3601  AccessorGetterCallback getter,
3602  AccessorSetterCallback setter = 0,
3603  Handle<Value> data = Handle<Value>(),
3604  AccessControl settings = DEFAULT,
3605  PropertyAttribute attribute = None,
3606  Handle<AccessorSignature> signature =
3608 
3626  void SetNamedPropertyHandler(
3628  NamedPropertySetterCallback setter = 0,
3629  NamedPropertyQueryCallback query = 0,
3630  NamedPropertyDeleterCallback deleter = 0,
3631  NamedPropertyEnumeratorCallback enumerator = 0,
3632  Handle<Value> data = Handle<Value>());
3633 
3650  void SetIndexedPropertyHandler(
3652  IndexedPropertySetterCallback setter = 0,
3653  IndexedPropertyQueryCallback query = 0,
3654  IndexedPropertyDeleterCallback deleter = 0,
3655  IndexedPropertyEnumeratorCallback enumerator = 0,
3656  Handle<Value> data = Handle<Value>());
3657 
3664  void SetCallAsFunctionHandler(FunctionCallback callback,
3665  Handle<Value> data = Handle<Value>());
3666 
3675  void MarkAsUndetectable();
3676 
3688  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
3689  IndexedSecurityCallback indexed_handler,
3690  Handle<Value> data = Handle<Value>(),
3691  bool turned_on_by_default = true);
3692 
3697  int InternalFieldCount();
3698 
3703  void SetInternalFieldCount(int value);
3704 
3705  private:
3706  ObjectTemplate();
3707  static Local<ObjectTemplate> New(internal::Isolate* isolate,
3708  Handle<FunctionTemplate> constructor);
3709  friend class FunctionTemplate;
3710 };
3711 
3712 
3717 class V8_EXPORT Signature : public Data {
3718  public:
3719  static Local<Signature> New(Isolate* isolate,
3720  Handle<FunctionTemplate> receiver =
3722  int argc = 0,
3723  Handle<FunctionTemplate> argv[] = 0);
3724 
3725  private:
3726  Signature();
3727 };
3728 
3729 
3734 class V8_EXPORT AccessorSignature : public Data {
3735  public:
3736  static Local<AccessorSignature> New(Isolate* isolate,
3737  Handle<FunctionTemplate> receiver =
3739 
3740  private:
3742 };
3743 
3744 
3745 class V8_EXPORT DeclaredAccessorDescriptor : public Data {
3746  private:
3748 };
3749 
3750 
3751 class V8_EXPORT ObjectOperationDescriptor : public Data {
3752  public:
3753  // This function is not yet stable and should not be used at this time.
3754  static Local<RawOperationDescriptor> NewInternalFieldDereference(
3755  Isolate* isolate,
3756  int internal_field);
3757  private:
3759 };
3760 
3761 
3762 enum DeclaredAccessorDescriptorDataType {
3763  kDescriptorBoolType,
3764  kDescriptorInt8Type, kDescriptorUint8Type,
3765  kDescriptorInt16Type, kDescriptorUint16Type,
3766  kDescriptorInt32Type, kDescriptorUint32Type,
3767  kDescriptorFloatType, kDescriptorDoubleType
3768 };
3769 
3770 
3771 class V8_EXPORT RawOperationDescriptor : public Data {
3772  public:
3773  Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate);
3774  Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate);
3775  Local<RawOperationDescriptor> NewRawShift(Isolate* isolate,
3776  int16_t byte_offset);
3777  Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate,
3778  void* compare_value);
3779  Local<DeclaredAccessorDescriptor> NewPrimitiveValue(
3780  Isolate* isolate,
3781  DeclaredAccessorDescriptorDataType data_type,
3782  uint8_t bool_offset = 0);
3783  Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate,
3784  uint8_t bitmask,
3785  uint8_t compare_value);
3786  Local<DeclaredAccessorDescriptor> NewBitmaskCompare16(
3787  Isolate* isolate,
3788  uint16_t bitmask,
3789  uint16_t compare_value);
3790  Local<DeclaredAccessorDescriptor> NewBitmaskCompare32(
3791  Isolate* isolate,
3792  uint32_t bitmask,
3793  uint32_t compare_value);
3794 
3795  private:
3797 };
3798 
3799 
3804 class V8_EXPORT TypeSwitch : public Data {
3805  public:
3807  static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
3808  int match(Handle<Value> value);
3809  private:
3810  TypeSwitch();
3811 };
3812 
3813 
3814 // --- Extensions ---
3815 
3818  public:
3819  ExternalAsciiStringResourceImpl() : data_(0), length_(0) {}
3820  ExternalAsciiStringResourceImpl(const char* data, size_t length)
3821  : data_(data), length_(length) {}
3822  const char* data() const { return data_; }
3823  size_t length() const { return length_; }
3824 
3825  private:
3826  const char* data_;
3827  size_t length_;
3828 };
3829 
3833 class V8_EXPORT Extension { // NOLINT
3834  public:
3835  // Note that the strings passed into this constructor must live as long
3836  // as the Extension itself.
3837  Extension(const char* name,
3838  const char* source = 0,
3839  int dep_count = 0,
3840  const char** deps = 0,
3841  int source_length = -1);
3842  virtual ~Extension() { }
3843  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
3844  v8::Isolate* isolate, v8::Handle<v8::String> name) {
3846  }
3847 
3848  const char* name() const { return name_; }
3849  size_t source_length() const { return source_length_; }
3850  const String::ExternalAsciiStringResource* source() const {
3851  return &source_; }
3852  int dependency_count() { return dep_count_; }
3853  const char** dependencies() { return deps_; }
3854  void set_auto_enable(bool value) { auto_enable_ = value; }
3855  bool auto_enable() { return auto_enable_; }
3856 
3857  private:
3858  const char* name_;
3859  size_t source_length_; // expected to initialize before source_
3861  int dep_count_;
3862  const char** deps_;
3863  bool auto_enable_;
3864 
3865  // Disallow copying and assigning.
3866  Extension(const Extension&);
3867  void operator=(const Extension&);
3868 };
3869 
3870 
3871 void V8_EXPORT RegisterExtension(Extension* extension);
3872 
3873 
3874 // --- Statics ---
3875 
3876 V8_INLINE Handle<Primitive> Undefined(Isolate* isolate);
3877 V8_INLINE Handle<Primitive> Null(Isolate* isolate);
3878 V8_INLINE Handle<Boolean> True(Isolate* isolate);
3879 V8_INLINE Handle<Boolean> False(Isolate* isolate);
3880 
3881 
3891 class V8_EXPORT ResourceConstraints {
3892  public:
3894 
3906  void ConfigureDefaults(uint64_t physical_memory,
3907  uint64_t virtual_memory_limit,
3908  uint32_t number_of_processors);
3909 
3910  int max_semi_space_size() const { return max_semi_space_size_; }
3911  void set_max_semi_space_size(int value) { max_semi_space_size_ = value; }
3912  int max_old_space_size() const { return max_old_space_size_; }
3913  void set_max_old_space_size(int value) { max_old_space_size_ = value; }
3914  int max_executable_size() const { return max_executable_size_; }
3915  void set_max_executable_size(int value) { max_executable_size_ = value; }
3916  uint32_t* stack_limit() const { return stack_limit_; }
3917  // Sets an address beyond which the VM's stack may not grow.
3918  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
3919  int max_available_threads() const { return max_available_threads_; }
3920  // Set the number of threads available to V8, assuming at least 1.
3921  void set_max_available_threads(int value) {
3922  max_available_threads_ = value;
3923  }
3924  size_t code_range_size() const { return code_range_size_; }
3925  void set_code_range_size(size_t value) {
3926  code_range_size_ = value;
3927  }
3928 
3929  private:
3930  int max_semi_space_size_;
3931  int max_old_space_size_;
3932  int max_executable_size_;
3933  uint32_t* stack_limit_;
3934  int max_available_threads_;
3935  size_t code_range_size_;
3936 };
3937 
3938 
3942 bool V8_EXPORT SetResourceConstraints(Isolate* isolate,
3943  ResourceConstraints* constraints);
3944 
3945 
3946 // --- Exceptions ---
3947 
3948 
3949 typedef void (*FatalErrorCallback)(const char* location, const char* message);
3950 
3951 
3952 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error);
3953 
3954 // --- Tracing ---
3955 
3956 typedef void (*LogEventCallback)(const char* name, int event);
3957 
3962 class V8_EXPORT Exception {
3963  public:
3964  static Local<Value> RangeError(Handle<String> message);
3965  static Local<Value> ReferenceError(Handle<String> message);
3966  static Local<Value> SyntaxError(Handle<String> message);
3967  static Local<Value> TypeError(Handle<String> message);
3968  static Local<Value> Error(Handle<String> message);
3969 };
3970 
3971 
3972 // --- Counters Callbacks ---
3973 
3974 typedef int* (*CounterLookupCallback)(const char* name);
3975 
3976 typedef void* (*CreateHistogramCallback)(const char* name,
3977  int min,
3978  int max,
3979  size_t buckets);
3980 
3981 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
3982 
3983 // --- Memory Allocation Callback ---
3984  enum ObjectSpace {
3985  kObjectSpaceNewSpace = 1 << 0,
3986  kObjectSpaceOldPointerSpace = 1 << 1,
3987  kObjectSpaceOldDataSpace = 1 << 2,
3988  kObjectSpaceCodeSpace = 1 << 3,
3989  kObjectSpaceMapSpace = 1 << 4,
3990  kObjectSpaceLoSpace = 1 << 5,
3991 
3992  kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
3993  kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
3994  kObjectSpaceLoSpace
3995  };
3996 
3997  enum AllocationAction {
3998  kAllocationActionAllocate = 1 << 0,
3999  kAllocationActionFree = 1 << 1,
4000  kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
4001  };
4002 
4003 typedef void (*MemoryAllocationCallback)(ObjectSpace space,
4004  AllocationAction action,
4005  int size);
4006 
4007 // --- Leave Script Callback ---
4008 typedef void (*CallCompletedCallback)();
4009 
4010 // --- Microtask Callback ---
4011 typedef void (*MicrotaskCallback)(void* data);
4012 
4013 // --- Failed Access Check Callback ---
4014 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
4015  AccessType type,
4016  Local<Value> data);
4017 
4018 // --- AllowCodeGenerationFromStrings callbacks ---
4019 
4025 
4026 // --- Garbage Collection Callbacks ---
4027 
4035 enum GCType {
4036  kGCTypeScavenge = 1 << 0,
4037  kGCTypeMarkSweepCompact = 1 << 1,
4038  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
4039 };
4040 
4041 enum GCCallbackFlags {
4042  kNoGCCallbackFlags = 0,
4043  kGCCallbackFlagCompacted = 1 << 0,
4044  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
4045  kGCCallbackFlagForced = 1 << 2
4046 };
4047 
4048 typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
4049 typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
4050 
4051 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
4052 
4053 
4060 class V8_EXPORT HeapStatistics {
4061  public:
4062  HeapStatistics();
4063  size_t total_heap_size() { return total_heap_size_; }
4064  size_t total_heap_size_executable() { return total_heap_size_executable_; }
4065  size_t total_physical_size() { return total_physical_size_; }
4066  size_t used_heap_size() { return used_heap_size_; }
4067  size_t heap_size_limit() { return heap_size_limit_; }
4068 
4069  private:
4070  size_t total_heap_size_;
4071  size_t total_heap_size_executable_;
4072  size_t total_physical_size_;
4073  size_t used_heap_size_;
4074  size_t heap_size_limit_;
4075 
4076  friend class V8;
4077  friend class Isolate;
4078 };
4079 
4080 
4081 class RetainedObjectInfo;
4082 
4092 class V8_EXPORT Isolate {
4093  public:
4098  class V8_EXPORT Scope {
4099  public:
4100  explicit Scope(Isolate* isolate) : isolate_(isolate) {
4101  isolate->Enter();
4102  }
4103 
4104  ~Scope() { isolate_->Exit(); }
4105 
4106  private:
4107  Isolate* const isolate_;
4108 
4109  // Prevent copying of Scope objects.
4110  Scope(const Scope&);
4111  Scope& operator=(const Scope&);
4112  };
4113 
4114 
4119  public:
4120  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
4121 
4122  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
4124 
4125  private:
4126  bool on_failure_;
4127  void* internal_;
4128 
4129  // Prevent copying of Scope objects.
4133  };
4134 
4135 
4140  public:
4141  explicit AllowJavascriptExecutionScope(Isolate* isolate);
4143 
4144  private:
4145  void* internal_throws_;
4146  void* internal_assert_;
4147 
4148  // Prevent copying of Scope objects.
4150  AllowJavascriptExecutionScope& operator=(
4152  };
4153 
4159  public:
4160  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
4162 
4163  private:
4164  internal::Isolate* isolate_;
4165 
4166  // Prevent copying of Scope objects.
4170  };
4171 
4177  kFullGarbageCollection,
4178  kMinorGarbageCollection
4179  };
4180 
4187  kUseAsm = 0,
4188  kUseCounterFeatureCount // This enum value must be last.
4189  };
4190 
4191  typedef void (*UseCounterCallback)(Isolate* isolate,
4192  UseCounterFeature feature);
4193 
4194 
4202  static Isolate* New();
4203 
4208  static Isolate* GetCurrent();
4209 
4218  typedef bool (*abort_on_uncaught_exception_t)(Isolate*);
4219  void SetAbortOnUncaughtException(abort_on_uncaught_exception_t callback);
4220 
4231  void Enter();
4232 
4240  void Exit();
4241 
4246  void Dispose();
4247 
4252  V8_INLINE void SetData(uint32_t slot, void* data);
4253 
4258  V8_INLINE void* GetData(uint32_t slot);
4259 
4264  V8_INLINE static uint32_t GetNumberOfDataSlots();
4265 
4269  void GetHeapStatistics(HeapStatistics* heap_statistics);
4270 
4284  V8_INLINE int64_t
4285  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
4286 
4291  HeapProfiler* GetHeapProfiler();
4292 
4298  CpuProfiler* GetCpuProfiler();
4299 
4301  bool InContext();
4302 
4304  Local<Context> GetCurrentContext();
4305 
4311  Local<Context> GetCallingContext();
4312 
4314  Local<Context> GetEnteredContext();
4315 
4322  Local<Value> ThrowException(Local<Value> exception);
4323 
4335  template<typename T> void SetObjectGroupId(const Persistent<T>& object,
4336  UniqueId id);
4337 
4345  template<typename T> void SetReferenceFromGroup(UniqueId id,
4346  const Persistent<T>& child);
4347 
4354  template<typename T, typename S>
4355  void SetReference(const Persistent<T>& parent, const Persistent<S>& child);
4356 
4357  typedef void (*GCPrologueCallback)(Isolate* isolate,
4358  GCType type,
4359  GCCallbackFlags flags);
4360  typedef void (*GCEpilogueCallback)(Isolate* isolate,
4361  GCType type,
4362  GCCallbackFlags flags);
4363 
4373  void AddGCPrologueCallback(
4374  GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
4375 
4380  void RemoveGCPrologueCallback(GCPrologueCallback callback);
4381 
4391  void AddGCEpilogueCallback(
4392  GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
4393 
4398  void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
4399 
4409  void RequestInterrupt(InterruptCallback callback, void* data);
4410 
4415  void ClearInterrupt();
4416 
4426  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
4427 
4431  void SetEventLogger(LogEventCallback that);
4432 
4440  void AddCallCompletedCallback(CallCompletedCallback callback);
4441 
4445  void RemoveCallCompletedCallback(CallCompletedCallback callback);
4446 
4451  void RunMicrotasks();
4452 
4456  void EnqueueMicrotask(Handle<Function> microtask);
4457 
4461  void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
4462 
4467  void SetAutorunMicrotasks(bool autorun);
4468 
4473  bool WillAutorunMicrotasks() const;
4474 
4478  void SetUseCounterCallback(UseCounterCallback callback);
4479 
4484  void SetCounterFunction(CounterLookupCallback);
4485 
4492  void SetCreateHistogramFunction(CreateHistogramCallback);
4493  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
4494 
4507  bool IdleNotification(int idle_time_in_ms);
4508 
4513  void LowMemoryNotification();
4514 
4521  int ContextDisposedNotification();
4522 
4523  private:
4524  template<class K, class V, class Traits> friend class PersistentValueMap;
4525 
4526  Isolate();
4527  Isolate(const Isolate&);
4528  ~Isolate();
4529  Isolate& operator=(const Isolate&);
4530  void* operator new(size_t size);
4531  void operator delete(void*, size_t);
4532 
4533  void SetObjectGroupId(internal::Object** object, UniqueId id);
4534  void SetReferenceFromGroup(UniqueId id, internal::Object** object);
4535  void SetReference(internal::Object** parent, internal::Object** child);
4536  void CollectAllGarbage(const char* gc_reason);
4537 };
4538 
4539 class V8_EXPORT StartupData {
4540  public:
4541  enum CompressionAlgorithm {
4542  kUncompressed,
4543  kBZip2
4544  };
4545 
4546  const char* data;
4547  int compressed_size;
4548  int raw_size;
4549 };
4550 
4551 
4560 class V8_EXPORT StartupDataDecompressor { // NOLINT
4561  public:
4563  virtual ~StartupDataDecompressor();
4564  int Decompress();
4565 
4566  protected:
4567  virtual int DecompressData(char* raw_data,
4568  int* raw_data_size,
4569  const char* compressed_data,
4570  int compressed_data_size) = 0;
4571 
4572  private:
4573  char** raw_data;
4574 };
4575 
4576 
4581 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
4582 
4583 
4597 typedef uintptr_t (*ReturnAddressLocationResolver)(
4598  uintptr_t return_addr_location);
4599 
4600 
4612 typedef void (*FunctionEntryHook)(uintptr_t function,
4613  uintptr_t return_addr_location);
4614 
4615 
4622  enum EventType {
4623  CODE_ADDED,
4624  CODE_MOVED,
4625  CODE_REMOVED,
4626  CODE_ADD_LINE_POS_INFO,
4627  CODE_START_LINE_INFO_RECORDING,
4628  CODE_END_LINE_INFO_RECORDING
4629  };
4630  // Definition of the code position type. The "POSITION" type means the place
4631  // in the source code which are of interest when making stack traces to
4632  // pin-point the source location of a stack frame as close as possible.
4633  // The "STATEMENT_POSITION" means the place at the beginning of each
4634  // statement, and is used to indicate possible break locations.
4635  enum PositionType {
4636  POSITION,
4637  STATEMENT_POSITION
4638  };
4639 
4640  // Type of event.
4641  EventType type;
4642  // Start of the instructions.
4643  void* code_start;
4644  // Size of the instructions.
4645  size_t code_len;
4646  // Script info for CODE_ADDED event.
4647  Handle<UnboundScript> script;
4648  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
4649  // code line information which is returned from the
4650  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
4651  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
4652  void* user_data;
4653 
4654  struct name_t {
4655  // Name of the object associated with the code, note that the string is not
4656  // zero-terminated.
4657  const char* str;
4658  // Number of chars in str.
4659  size_t len;
4660  };
4661 
4662  struct line_info_t {
4663  // PC offset
4664  size_t offset;
4665  // Code postion
4666  size_t pos;
4667  // The position type.
4668  PositionType position_type;
4669  };
4670 
4671  union {
4672  // Only valid for CODE_ADDED.
4673  struct name_t name;
4674 
4675  // Only valid for CODE_ADD_LINE_POS_INFO
4676  struct line_info_t line_info;
4677 
4678  // New location of instructions. Only valid for CODE_MOVED.
4679  void* new_code_start;
4680  };
4681 };
4682 
4687  kJitCodeEventDefault = 0,
4688  // Generate callbacks for already existent code.
4689  kJitCodeEventEnumExisting = 1
4690 };
4691 
4692 
4698 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
4699 
4700 
4704 class V8_EXPORT ExternalResourceVisitor { // NOLINT
4705  public:
4706  virtual ~ExternalResourceVisitor() {}
4707  virtual void VisitExternalString(Handle<String> string) {}
4708 };
4709 
4710 
4714 class V8_EXPORT PersistentHandleVisitor { // NOLINT
4715  public:
4716  virtual ~PersistentHandleVisitor() {}
4717  virtual void VisitPersistentHandle(Persistent<Value>* value,
4718  uint16_t class_id) {}
4719 };
4720 
4721 
4725 class V8_EXPORT V8 {
4726  public:
4728  static void SetFatalErrorHandler(FatalErrorCallback that);
4729 
4734  static void SetAllowCodeGenerationFromStringsCallback(
4736 
4743  static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator);
4744 
4749  static bool IsDead();
4750 
4770  static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
4771  static int GetCompressedStartupDataCount();
4772  static void GetCompressedStartupData(StartupData* compressed_data);
4773  static void SetDecompressedStartupData(StartupData* decompressed_data);
4774 
4790  static void SetNativesDataBlob(StartupData* startup_blob);
4791  static void SetSnapshotDataBlob(StartupData* startup_blob);
4792 
4802  static bool AddMessageListener(MessageCallback that,
4803  Handle<Value> data = Handle<Value>());
4804 
4808  static void RemoveMessageListeners(MessageCallback that);
4809 
4814  static void SetCaptureStackTraceForUncaughtExceptions(
4815  bool capture,
4816  int frame_limit = 10,
4817  StackTrace::StackTraceOptions options = StackTrace::kOverview);
4818 
4822  static void SetFlagsFromString(const char* str, int length);
4823 
4827  static void SetFlagsFromCommandLine(int* argc,
4828  char** argv,
4829  bool remove_flags);
4830 
4832  static const char* GetVersion();
4833 
4835  static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
4836 
4847  static void AddGCPrologueCallback(
4848  GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
4849 
4854  static void RemoveGCPrologueCallback(GCPrologueCallback callback);
4855 
4866  static void AddGCEpilogueCallback(
4867  GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
4868 
4873  static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
4874 
4879  static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
4880  ObjectSpace space,
4881  AllocationAction action);
4882 
4886  static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
4887 
4893  static bool Initialize();
4894 
4899  static void SetEntropySource(EntropySource source);
4900 
4905  static void SetReturnAddressLocationResolver(
4906  ReturnAddressLocationResolver return_address_resolver);
4907 
4921  static bool SetFunctionEntryHook(Isolate* isolate,
4922  FunctionEntryHook entry_hook);
4923 
4944  static void SetJitCodeEventHandler(JitCodeEventOptions options,
4945  JitCodeEventHandler event_handler);
4946 
4956  static void TerminateExecution(Isolate* isolate);
4957 
4968  static bool IsExecutionTerminating(Isolate* isolate = NULL);
4969 
4986  static void CancelTerminateExecution(Isolate* isolate);
4987 
4997  static bool Dispose();
4998 
5004  static void VisitExternalResources(ExternalResourceVisitor* visitor);
5005 
5010  static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
5011 
5019  static void VisitHandlesForPartialDependence(
5020  Isolate* isolate, PersistentHandleVisitor* visitor);
5021 
5029  static bool InitializeICU(const char* icu_data_file = NULL);
5030 
5035  static void InitializePlatform(Platform* platform);
5036 
5041  static void ShutdownPlatform();
5042 
5043  private:
5044  V8();
5045 
5046  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
5047  internal::Object** handle);
5048  static internal::Object** CopyPersistent(internal::Object** handle);
5049  static void DisposeGlobal(internal::Object** global_handle);
5050  typedef WeakCallbackData<Value, void>::Callback WeakCallback;
5051  static void MakeWeak(internal::Object** global_handle,
5052  void* data,
5053  WeakCallback weak_callback);
5054  static void* ClearWeak(internal::Object** global_handle);
5055  static void Eternalize(Isolate* isolate,
5056  Value* handle,
5057  int* index);
5058  static Local<Value> GetEternal(Isolate* isolate, int index);
5059 
5060  template <class T> friend class Handle;
5061  template <class T> friend class Local;
5062  template <class T> friend class Eternal;
5063  template <class T> friend class PersistentBase;
5064  template <class T, class M> friend class Persistent;
5065  friend class Context;
5066 };
5067 
5068 
5072 class V8_EXPORT TryCatch {
5073  public:
5079  TryCatch();
5080 
5084  ~TryCatch();
5085 
5089  bool HasCaught() const;
5090 
5099  bool CanContinue() const;
5100 
5113  bool HasTerminated() const;
5114 
5122  Handle<Value> ReThrow();
5123 
5130  Local<Value> Exception() const;
5131 
5136  Local<Value> StackTrace() const;
5137 
5145  Local<v8::Message> Message() const;
5146 
5157  void Reset();
5158 
5167  void SetVerbose(bool value);
5168 
5174  void SetCaptureMessage(bool value);
5175 
5187  static void* JSStackComparableAddress(v8::TryCatch* handler) {
5188  if (handler == NULL) return NULL;
5189  return handler->js_stack_comparable_address_;
5190  }
5191 
5192  private:
5193  void ResetInternal();
5194 
5195  // Make it hard to create heap-allocated TryCatch blocks.
5196  TryCatch(const TryCatch&);
5197  void operator=(const TryCatch&);
5198  void* operator new(size_t size);
5199  void operator delete(void*, size_t);
5200 
5201  v8::internal::Isolate* isolate_;
5202  v8::TryCatch* next_;
5203  void* exception_;
5204  void* message_obj_;
5205  void* message_script_;
5206  void* js_stack_comparable_address_;
5207  int message_start_pos_;
5208  int message_end_pos_;
5209  bool is_verbose_ : 1;
5210  bool can_continue_ : 1;
5211  bool capture_message_ : 1;
5212  bool rethrow_ : 1;
5213  bool has_terminated_ : 1;
5214 
5215  friend class v8::internal::Isolate;
5216 };
5217 
5218 
5219 // --- Context ---
5220 
5221 
5225 class V8_EXPORT ExtensionConfiguration {
5226  public:
5227  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
5228  ExtensionConfiguration(int name_count, const char* names[])
5229  : name_count_(name_count), names_(names) { }
5230 
5231  const char** begin() const { return &names_[0]; }
5232  const char** end() const { return &names_[name_count_]; }
5233 
5234  private:
5235  const int name_count_;
5236  const char** names_;
5237 };
5238 
5239 
5244 class V8_EXPORT Context {
5245  public:
5258  Local<Object> Global();
5259 
5264  void DetachGlobal();
5265 
5284  static Local<Context> New(
5285  Isolate* isolate,
5286  ExtensionConfiguration* extensions = NULL,
5287  Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
5288  Handle<Value> global_object = Handle<Value>());
5289 
5294  void SetSecurityToken(Handle<Value> token);
5295 
5297  void UseDefaultSecurityToken();
5298 
5300  Handle<Value> GetSecurityToken();
5301 
5308  void Enter();
5309 
5314  void Exit();
5315 
5317  v8::Isolate* GetIsolate();
5318 
5324  V8_INLINE Local<Value> GetEmbedderData(int index);
5325 
5331  void SetEmbedderData(int index, Handle<Value> value);
5332 
5339  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
5340 
5346  void SetAlignedPointerInEmbedderData(int index, void* value);
5347 
5361  void AllowCodeGenerationFromStrings(bool allow);
5362 
5367  bool IsCodeGenerationFromStringsAllowed();
5368 
5374  void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message);
5375 
5380  class Scope {
5381  public:
5382  explicit V8_INLINE Scope(Handle<Context> context) : context_(context) {
5383  context_->Enter();
5384  }
5385  V8_INLINE ~Scope() { context_->Exit(); }
5386 
5387  private:
5388  Handle<Context> context_;
5389  };
5390 
5391  private:
5392  friend class Value;
5393  friend class Script;
5394  friend class Object;
5395  friend class Function;
5396 
5397  Local<Value> SlowGetEmbedderData(int index);
5398  void* SlowGetAlignedPointerFromEmbedderData(int index);
5399 };
5400 
5401 
5478 class V8_EXPORT Unlocker {
5479  public:
5483  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
5484 
5485  ~Unlocker();
5486  private:
5487  void Initialize(Isolate* isolate);
5488 
5489  internal::Isolate* isolate_;
5490 };
5491 
5492 
5493 class V8_EXPORT Locker {
5494  public:
5498  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
5499 
5500  ~Locker();
5501 
5506  static bool IsLocked(Isolate* isolate);
5507 
5511  static bool IsActive();
5512 
5513  private:
5514  void Initialize(Isolate* isolate);
5515 
5516  bool has_lock_;
5517  bool top_level_;
5518  internal::Isolate* isolate_;
5519 
5520  static bool active_;
5521 
5522  // Disallow copying and assigning.
5523  Locker(const Locker&);
5524  void operator=(const Locker&);
5525 };
5526 
5527 
5528 // --- Implementation ---
5529 
5530 
5531 namespace internal {
5532 
5533 const int kApiPointerSize = sizeof(void*); // NOLINT
5534 const int kApiIntSize = sizeof(int); // NOLINT
5535 const int kApiInt64Size = sizeof(int64_t); // NOLINT
5536 
5537 // Tag information for HeapObject.
5538 const int kHeapObjectTag = 1;
5539 const int kHeapObjectTagSize = 2;
5540 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
5541 
5542 // Tag information for Smi.
5543 const int kSmiTag = 0;
5544 const int kSmiTagSize = 1;
5545 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
5546 
5547 template <size_t ptr_size> struct SmiTagging;
5548 
5549 template<int kSmiShiftSize>
5550 V8_INLINE internal::Object* IntToSmi(int value) {
5551  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
5552  intptr_t tagged_value =
5553  (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
5554  return reinterpret_cast<internal::Object*>(tagged_value);
5555 }
5556 
5557 // Smi constants for 32-bit systems.
5558 template <> struct SmiTagging<4> {
5559  static const int kSmiShiftSize = 0;
5560  static const int kSmiValueSize = 31;
5561  V8_INLINE static int SmiToInt(const internal::Object* value) {
5562  int shift_bits = kSmiTagSize + kSmiShiftSize;
5563  // Throw away top 32 bits and shift down (requires >> to be sign extending).
5564  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
5565  }
5566  V8_INLINE static internal::Object* IntToSmi(int value) {
5567  return internal::IntToSmi<kSmiShiftSize>(value);
5568  }
5569  V8_INLINE static bool IsValidSmi(intptr_t value) {
5570  // To be representable as an tagged small integer, the two
5571  // most-significant bits of 'value' must be either 00 or 11 due to
5572  // sign-extension. To check this we add 01 to the two
5573  // most-significant bits, and check if the most-significant bit is 0
5574  //
5575  // CAUTION: The original code below:
5576  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
5577  // may lead to incorrect results according to the C language spec, and
5578  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
5579  // compiler may produce undefined results in case of signed integer
5580  // overflow. The computation must be done w/ unsigned ints.
5581  return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
5582  }
5583 };
5584 
5585 // Smi constants for 64-bit systems.
5586 template <> struct SmiTagging<8> {
5587  static const int kSmiShiftSize = 31;
5588  static const int kSmiValueSize = 32;
5589  V8_INLINE static int SmiToInt(const internal::Object* value) {
5590  int shift_bits = kSmiTagSize + kSmiShiftSize;
5591  // Shift down and throw away top 32 bits.
5592  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
5593  }
5594  V8_INLINE static internal::Object* IntToSmi(int value) {
5595  return internal::IntToSmi<kSmiShiftSize>(value);
5596  }
5597  V8_INLINE static bool IsValidSmi(intptr_t value) {
5598  // To be representable as a long smi, the value must be a 32-bit integer.
5599  return (value == static_cast<int32_t>(value));
5600  }
5601 };
5602 
5604 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
5605 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
5606 V8_INLINE static bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
5607 V8_INLINE static bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
5608 
5614 class Internals {
5615  public:
5616  // These values match non-compiler-dependent values defined within
5617  // the implementation of v8.
5618  static const int kHeapObjectMapOffset = 0;
5619  static const int kMapInstanceTypeAndBitFieldOffset =
5620  1 * kApiPointerSize + kApiIntSize;
5621  static const int kStringResourceOffset = 3 * kApiPointerSize;
5622 
5623  static const int kOddballKindOffset = 3 * kApiPointerSize;
5624  static const int kForeignAddressOffset = kApiPointerSize;
5625  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
5626  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
5627  static const int kContextHeaderSize = 2 * kApiPointerSize;
5628  static const int kContextEmbedderDataIndex = 95;
5629  static const int kFullStringRepresentationMask = 0x07;
5630  static const int kStringEncodingMask = 0x4;
5631  static const int kExternalTwoByteRepresentationTag = 0x02;
5632  static const int kExternalAsciiRepresentationTag = 0x06;
5633 
5634  static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
5635  static const int kAmountOfExternalAllocatedMemoryOffset =
5636  4 * kApiPointerSize;
5637  static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
5638  kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size;
5639  static const int kIsolateRootsOffset =
5640  kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size +
5641  kApiPointerSize;
5642  static const int kUndefinedValueRootIndex = 5;
5643  static const int kNullValueRootIndex = 7;
5644  static const int kTrueValueRootIndex = 8;
5645  static const int kFalseValueRootIndex = 9;
5646  static const int kEmptyStringRootIndex = 164;
5647 
5648  // The external allocation limit should be below 256 MB on all architectures
5649  // to avoid that resource-constrained embedders run low on memory.
5650  static const int kExternalAllocationLimit = 192 * 1024 * 1024;
5651 
5652  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
5653  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
5654  static const int kNodeStateMask = 0xf;
5655  static const int kNodeStateIsWeakValue = 2;
5656  static const int kNodeStateIsPendingValue = 3;
5657  static const int kNodeStateIsNearDeathValue = 4;
5658  static const int kNodeIsIndependentShift = 4;
5659  static const int kNodeIsPartiallyDependentShift = 5;
5660 
5661  static const int kJSObjectType = 0xbc;
5662  static const int kFirstNonstringType = 0x80;
5663  static const int kOddballType = 0x83;
5664  static const int kForeignType = 0x88;
5665 
5666  static const int kUndefinedOddballKind = 5;
5667  static const int kNullOddballKind = 3;
5668 
5669  static const uint32_t kNumIsolateDataSlots = 4;
5670 
5671  V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
5672  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
5673 #ifdef V8_ENABLE_CHECKS
5674  CheckInitializedImpl(isolate);
5675 #endif
5676  }
5677 
5678  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
5679  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
5680  kHeapObjectTag);
5681  }
5682 
5683  V8_INLINE static int SmiValue(const internal::Object* value) {
5684  return PlatformSmiTagging::SmiToInt(value);
5685  }
5686 
5687  V8_INLINE static internal::Object* IntToSmi(int value) {
5688  return PlatformSmiTagging::IntToSmi(value);
5689  }
5690 
5691  V8_INLINE static bool IsValidSmi(intptr_t value) {
5692  return PlatformSmiTagging::IsValidSmi(value);
5693  }
5694 
5695  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
5696  typedef internal::Object O;
5697  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
5698  // Map::InstanceType is defined so that it will always be loaded into
5699  // the LS 8 bits of one 16-bit word, regardless of endianess.
5700  return ReadField<uint16_t>(map, kMapInstanceTypeAndBitFieldOffset) & 0xff;
5701  }
5702 
5703  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
5704  typedef internal::Object O;
5705  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
5706  }
5707 
5708  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
5709  int representation = (instance_type & kFullStringRepresentationMask);
5710  return representation == kExternalTwoByteRepresentationTag;
5711  }
5712 
5713  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
5714  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5715  return *addr & static_cast<uint8_t>(1U << shift);
5716  }
5717 
5718  V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
5719  bool value, int shift) {
5720  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5721  uint8_t mask = static_cast<uint8_t>(1 << shift);
5722  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
5723  }
5724 
5725  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
5726  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5727  return *addr & kNodeStateMask;
5728  }
5729 
5730  V8_INLINE static void UpdateNodeState(internal::Object** obj,
5731  uint8_t value) {
5732  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5733  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
5734  }
5735 
5736  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
5737  uint32_t slot,
5738  void* data) {
5739  uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) +
5740  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
5741  *reinterpret_cast<void**>(addr) = data;
5742  }
5743 
5744  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
5745  uint32_t slot) {
5746  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
5747  kIsolateEmbedderDataOffset + slot * kApiPointerSize;
5748  return *reinterpret_cast<void* const*>(addr);
5749  }
5750 
5751  V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
5752  int index) {
5753  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
5754  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
5755  }
5756 
5757  template <typename T>
5758  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
5759  const uint8_t* addr =
5760  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
5761  return *reinterpret_cast<const T*>(addr);
5762  }
5763 
5764  template <typename T>
5765  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
5766  typedef internal::Object O;
5767  typedef internal::Internals I;
5768  O* ctx = *reinterpret_cast<O* const*>(context);
5769  int embedder_data_offset = I::kContextHeaderSize +
5770  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
5771  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
5772  int value_offset =
5773  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
5774  return I::ReadField<T>(embedder_data, value_offset);
5775  }
5776 };
5777 
5778 } // namespace internal
5779 
5780 
5781 template <class T>
5782 Local<T>::Local() : Handle<T>() { }
5783 
5784 
5785 template <class T>
5787  return New(isolate, that.val_);
5788 }
5789 
5790 template <class T>
5791 Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
5792  return New(isolate, that.val_);
5793 }
5794 
5795 template <class T>
5796 Handle<T> Handle<T>::New(Isolate* isolate, T* that) {
5797  if (that == NULL) return Handle<T>();
5798  T* that_ptr = that;
5799  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
5800  return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
5801  reinterpret_cast<internal::Isolate*>(isolate), *p)));
5802 }
5803 
5804 
5805 template <class T>
5806 Local<T> Local<T>::New(Isolate* isolate, T* that) {
5807  if (that == NULL) return Local<T>();
5808  T* that_ptr = that;
5809  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
5810  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
5811  reinterpret_cast<internal::Isolate*>(isolate), *p)));
5812 }
5813 
5814 
5815 template<class T>
5816 template<class S>
5817 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
5818  TYPE_CHECK(T, S);
5819  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_);
5820 }
5821 
5822 
5823 template<class T>
5824 Local<T> Eternal<T>::Get(Isolate* isolate) {
5825  return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_)));
5826 }
5827 
5828 
5829 template <class T>
5830 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
5831  if (that == NULL) return NULL;
5832  internal::Object** p = reinterpret_cast<internal::Object**>(that);
5833  return reinterpret_cast<T*>(
5834  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
5835  p));
5836 }
5837 
5838 
5839 template <class T, class M>
5840 template <class S, class M2>
5841 void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
5842  TYPE_CHECK(T, S);
5843  this->Reset();
5844  if (that.IsEmpty()) return;
5845  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
5846  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
5847  M::Copy(that, this);
5848 }
5849 
5850 
5851 template <class T>
5852 bool PersistentBase<T>::IsIndependent() const {
5853  typedef internal::Internals I;
5854  if (this->IsEmpty()) return false;
5855  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5856  I::kNodeIsIndependentShift);
5857 }
5858 
5859 
5860 template <class T>
5862  typedef internal::Internals I;
5863  if (this->IsEmpty()) return false;
5864  uint8_t node_state =
5865  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
5866  return node_state == I::kNodeStateIsNearDeathValue ||
5867  node_state == I::kNodeStateIsPendingValue;
5868 }
5869 
5870 
5871 template <class T>
5873  typedef internal::Internals I;
5874  if (this->IsEmpty()) return false;
5875  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
5876  I::kNodeStateIsWeakValue;
5877 }
5878 
5879 
5880 template <class T>
5882  if (this->IsEmpty()) return;
5883  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
5884  val_ = 0;
5885 }
5886 
5887 
5888 template <class T>
5889 template <class S>
5890 void PersistentBase<T>::Reset(Isolate* isolate, const Handle<S>& other) {
5891  TYPE_CHECK(T, S);
5892  Reset();
5893  if (other.IsEmpty()) return;
5894  this->val_ = New(isolate, other.val_);
5895 }
5896 
5897 
5898 template <class T>
5899 template <class S>
5900 void PersistentBase<T>::Reset(Isolate* isolate,
5901  const PersistentBase<S>& other) {
5902  TYPE_CHECK(T, S);
5903  Reset();
5904  if (other.IsEmpty()) return;
5905  this->val_ = New(isolate, other.val_);
5906 }
5907 
5908 
5909 template <class T>
5910 template <typename S, typename P>
5912  P* parameter,
5913  typename WeakCallbackData<S, P>::Callback callback) {
5914  TYPE_CHECK(S, T);
5915  typedef typename WeakCallbackData<Value, void>::Callback Callback;
5916  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
5917  parameter,
5918  reinterpret_cast<Callback>(callback));
5919 }
5920 
5921 
5922 template <class T>
5923 template <typename P>
5925  P* parameter,
5926  typename WeakCallbackData<T, P>::Callback callback) {
5927  SetWeak<T, P>(parameter, callback);
5928 }
5929 
5930 
5931 template <class T>
5932 template<typename P>
5933 P* PersistentBase<T>::ClearWeak() {
5934  return reinterpret_cast<P*>(
5935  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
5936 }
5937 
5938 
5939 template <class T>
5941  typedef internal::Internals I;
5942  if (this->IsEmpty()) return;
5943  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5944  true,
5945  I::kNodeIsIndependentShift);
5946 }
5947 
5948 
5949 template <class T>
5951  typedef internal::Internals I;
5952  if (this->IsEmpty()) return;
5953  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5954  true,
5955  I::kNodeIsPartiallyDependentShift);
5956 }
5957 
5958 
5959 template <class T, class M>
5961  T* old;
5962  old = this->val_;
5963  this->val_ = NULL;
5964  return old;
5965 }
5966 
5967 
5968 template <class T>
5969 void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
5970  typedef internal::Internals I;
5971  if (this->IsEmpty()) return;
5972  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5973  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5974  *reinterpret_cast<uint16_t*>(addr) = class_id;
5975 }
5976 
5977 
5978 template <class T>
5980  typedef internal::Internals I;
5981  if (this->IsEmpty()) return 0;
5982  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5983  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5984  return *reinterpret_cast<uint16_t*>(addr);
5985 }
5986 
5987 
5988 template<typename T>
5989 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
5990 
5991 template<typename T>
5992 template<typename S>
5993 void ReturnValue<T>::Set(const Persistent<S>& handle) {
5994  TYPE_CHECK(T, S);
5995  if (V8_UNLIKELY(handle.IsEmpty())) {
5996  *value_ = GetDefaultValue();
5997  } else {
5998  *value_ = *reinterpret_cast<internal::Object**>(*handle);
5999  }
6000 }
6001 
6002 template<typename T>
6003 template<typename S>
6004 void ReturnValue<T>::Set(const Handle<S> handle) {
6005  TYPE_CHECK(T, S);
6006  if (V8_UNLIKELY(handle.IsEmpty())) {
6007  *value_ = GetDefaultValue();
6008  } else {
6009  *value_ = *reinterpret_cast<internal::Object**>(*handle);
6010  }
6011 }
6012 
6013 template<typename T>
6014 void ReturnValue<T>::Set(double i) {
6015  TYPE_CHECK(T, Number);
6016  Set(Number::New(GetIsolate(), i));
6017 }
6018 
6019 template<typename T>
6020 void ReturnValue<T>::Set(int32_t i) {
6021  TYPE_CHECK(T, Integer);
6022  typedef internal::Internals I;
6023  if (V8_LIKELY(I::IsValidSmi(i))) {
6024  *value_ = I::IntToSmi(i);
6025  return;
6026  }
6027  Set(Integer::New(GetIsolate(), i));
6028 }
6029 
6030 template<typename T>
6031 void ReturnValue<T>::Set(uint32_t i) {
6032  TYPE_CHECK(T, Integer);
6033  // Can't simply use INT32_MAX here for whatever reason.
6034  bool fits_into_int32_t = (i & (1U << 31)) == 0;
6035  if (V8_LIKELY(fits_into_int32_t)) {
6036  Set(static_cast<int32_t>(i));
6037  return;
6038  }
6039  Set(Integer::NewFromUnsigned(GetIsolate(), i));
6040 }
6041 
6042 template<typename T>
6043 void ReturnValue<T>::Set(bool value) {
6044  TYPE_CHECK(T, Boolean);
6045  typedef internal::Internals I;
6046  int root_index;
6047  if (value) {
6048  root_index = I::kTrueValueRootIndex;
6049  } else {
6050  root_index = I::kFalseValueRootIndex;
6051  }
6052  *value_ = *I::GetRoot(GetIsolate(), root_index);
6053 }
6054 
6055 template<typename T>
6056 void ReturnValue<T>::SetNull() {
6057  TYPE_CHECK(T, Primitive);
6058  typedef internal::Internals I;
6059  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
6060 }
6061 
6062 template<typename T>
6063 void ReturnValue<T>::SetUndefined() {
6064  TYPE_CHECK(T, Primitive);
6065  typedef internal::Internals I;
6066  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
6067 }
6068 
6069 template<typename T>
6070 void ReturnValue<T>::SetEmptyString() {
6071  TYPE_CHECK(T, String);
6072  typedef internal::Internals I;
6073  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
6074 }
6075 
6076 template<typename T>
6077 Isolate* ReturnValue<T>::GetIsolate() {
6078  // Isolate is always the pointer below the default value on the stack.
6079  return *reinterpret_cast<Isolate**>(&value_[-2]);
6080 }
6081 
6082 template<typename T>
6083 template<typename S>
6084 void ReturnValue<T>::Set(S* whatever) {
6085  // Uncompilable to prevent inadvertent misuse.
6086  TYPE_CHECK(S*, Primitive);
6087 }
6088 
6089 template<typename T>
6090 internal::Object* ReturnValue<T>::GetDefaultValue() {
6091  // Default value is always the pointer below value_ on the stack.
6092  return value_[-1];
6093 }
6094 
6095 
6096 template<typename T>
6097 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
6098  internal::Object** values,
6099  int length,
6100  bool is_construct_call)
6101  : implicit_args_(implicit_args),
6102  values_(values),
6103  length_(length),
6104  is_construct_call_(is_construct_call) { }
6105 
6106 
6107 template<typename T>
6108 Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
6109  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
6110  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
6111 }
6112 
6113 
6114 template<typename T>
6115 Local<Function> FunctionCallbackInfo<T>::Callee() const {
6116  return Local<Function>(reinterpret_cast<Function*>(
6117  &implicit_args_[kCalleeIndex]));
6118 }
6119 
6120 
6121 template<typename T>
6122 Local<Object> FunctionCallbackInfo<T>::This() const {
6123  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
6124 }
6125 
6126 
6127 template<typename T>
6128 Local<Object> FunctionCallbackInfo<T>::Holder() const {
6129  return Local<Object>(reinterpret_cast<Object*>(
6130  &implicit_args_[kHolderIndex]));
6131 }
6132 
6133 
6134 template<typename T>
6135 Local<Value> FunctionCallbackInfo<T>::Data() const {
6136  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
6137 }
6138 
6139 
6140 template<typename T>
6141 Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
6142  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
6143 }
6144 
6145 
6146 template<typename T>
6147 ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const {
6148  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
6149 }
6150 
6151 
6152 template<typename T>
6153 bool FunctionCallbackInfo<T>::IsConstructCall() const {
6154  return is_construct_call_;
6155 }
6156 
6157 
6158 template<typename T>
6159 int FunctionCallbackInfo<T>::Length() const {
6160  return length_;
6161 }
6162 
6163 
6164 Handle<Value> ScriptOrigin::ResourceName() const {
6165  return resource_name_;
6166 }
6167 
6168 
6169 Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
6170  return resource_line_offset_;
6171 }
6172 
6173 
6174 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
6175  return resource_column_offset_;
6176 }
6177 
6178 
6179 Handle<Boolean> ScriptOrigin::ResourceIsSharedCrossOrigin() const {
6180  return resource_is_shared_cross_origin_;
6181 }
6182 
6183 
6184 Handle<Integer> ScriptOrigin::ScriptID() const {
6185  return script_id_;
6186 }
6187 
6188 
6189 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
6190  CachedData* data)
6191  : source_string(string),
6192  resource_name(origin.ResourceName()),
6193  resource_line_offset(origin.ResourceLineOffset()),
6194  resource_column_offset(origin.ResourceColumnOffset()),
6195  resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()),
6196  cached_data(data) {}
6197 
6198 
6199 ScriptCompiler::Source::Source(Local<String> string,
6200  CachedData* data)
6201  : source_string(string), cached_data(data) {}
6202 
6203 
6204 ScriptCompiler::Source::~Source() {
6205  delete cached_data;
6206 }
6207 
6208 
6209 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
6210  const {
6211  return cached_data;
6212 }
6213 
6214 
6215 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) {
6216  return value ? True(isolate) : False(isolate);
6217 }
6218 
6219 
6220 void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) {
6221  Set(v8::String::NewFromUtf8(isolate, name), value);
6222 }
6223 
6224 
6226 #ifndef V8_ENABLE_CHECKS
6227  typedef internal::Object O;
6228  typedef internal::HeapObject HO;
6229  typedef internal::Internals I;
6230  O* obj = *reinterpret_cast<O**>(this);
6231  // Fast path: If the object is a plain JSObject, which is the common case, we
6232  // know where to find the internal fields and can return the value directly.
6233  if (I::GetInstanceType(obj) == I::kJSObjectType) {
6234  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
6235  O* value = I::ReadField<O*>(obj, offset);
6236  O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
6237  return Local<Value>(reinterpret_cast<Value*>(result));
6238  }
6239 #endif
6240  return SlowGetInternalField(index);
6241 }
6242 
6243 
6245 #ifndef V8_ENABLE_CHECKS
6246  typedef internal::Object O;
6247  typedef internal::Internals I;
6248  O* obj = *reinterpret_cast<O**>(this);
6249  // Fast path: If the object is a plain JSObject, which is the common case, we
6250  // know where to find the internal fields and can return the value directly.
6251  if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) {
6252  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
6253  return I::ReadField<void*>(obj, offset);
6254  }
6255 #endif
6256  return SlowGetAlignedPointerFromInternalField(index);
6257 }
6258 
6259 
6260 String* String::Cast(v8::Value* value) {
6261 #ifdef V8_ENABLE_CHECKS
6262  CheckCast(value);
6263 #endif
6264  return static_cast<String*>(value);
6265 }
6266 
6267 
6269  typedef internal::Object* S;
6270  typedef internal::Internals I;
6271  I::CheckInitialized(isolate);
6272  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
6273  return Local<String>(reinterpret_cast<String*>(slot));
6274 }
6275 
6276 
6278  typedef internal::Object O;
6279  typedef internal::Internals I;
6280  O* obj = *reinterpret_cast<O* const*>(this);
6282  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
6283  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
6284  result = reinterpret_cast<String::ExternalStringResource*>(value);
6285  } else {
6286  result = NULL;
6287  }
6288 #ifdef V8_ENABLE_CHECKS
6289  VerifyExternalStringResource(result);
6290 #endif
6291  return result;
6292 }
6293 
6294 
6296  String::Encoding* encoding_out) const {
6297  typedef internal::Object O;
6298  typedef internal::Internals I;
6299  O* obj = *reinterpret_cast<O* const*>(this);
6300  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
6301  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
6302  ExternalStringResourceBase* resource = NULL;
6303  if (type == I::kExternalAsciiRepresentationTag ||
6304  type == I::kExternalTwoByteRepresentationTag) {
6305  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
6306  resource = static_cast<ExternalStringResourceBase*>(value);
6307  }
6308 #ifdef V8_ENABLE_CHECKS
6309  VerifyExternalStringResourceBase(resource, *encoding_out);
6310 #endif
6311  return resource;
6312 }
6313 
6314 
6315 bool Value::IsUndefined() const {
6316 #ifdef V8_ENABLE_CHECKS
6317  return FullIsUndefined();
6318 #else
6319  return QuickIsUndefined();
6320 #endif
6321 }
6322 
6323 bool Value::QuickIsUndefined() const {
6324  typedef internal::Object O;
6325  typedef internal::Internals I;
6326  O* obj = *reinterpret_cast<O* const*>(this);
6327  if (!I::HasHeapObjectTag(obj)) return false;
6328  if (I::GetInstanceType(obj) != I::kOddballType) return false;
6329  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
6330 }
6331 
6332 
6333 bool Value::IsNull() const {
6334 #ifdef V8_ENABLE_CHECKS
6335  return FullIsNull();
6336 #else
6337  return QuickIsNull();
6338 #endif
6339 }
6340 
6341 bool Value::QuickIsNull() const {
6342  typedef internal::Object O;
6343  typedef internal::Internals I;
6344  O* obj = *reinterpret_cast<O* const*>(this);
6345  if (!I::HasHeapObjectTag(obj)) return false;
6346  if (I::GetInstanceType(obj) != I::kOddballType) return false;
6347  return (I::GetOddballKind(obj) == I::kNullOddballKind);
6348 }
6349 
6350 
6351 bool Value::IsString() const {
6352 #ifdef V8_ENABLE_CHECKS
6353  return FullIsString();
6354 #else
6355  return QuickIsString();
6356 #endif
6357 }
6358 
6359 bool Value::QuickIsString() const {
6360  typedef internal::Object O;
6361  typedef internal::Internals I;
6362  O* obj = *reinterpret_cast<O* const*>(this);
6363  if (!I::HasHeapObjectTag(obj)) return false;
6364  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
6365 }
6366 
6367 
6368 template <class T> Value* Value::Cast(T* value) {
6369  return static_cast<Value*>(value);
6370 }
6371 
6372 
6373 Symbol* Symbol::Cast(v8::Value* value) {
6374 #ifdef V8_ENABLE_CHECKS
6375  CheckCast(value);
6376 #endif
6377  return static_cast<Symbol*>(value);
6378 }
6379 
6380 
6381 Number* Number::Cast(v8::Value* value) {
6382 #ifdef V8_ENABLE_CHECKS
6383  CheckCast(value);
6384 #endif
6385  return static_cast<Number*>(value);
6386 }
6387 
6388 
6389 Integer* Integer::Cast(v8::Value* value) {
6390 #ifdef V8_ENABLE_CHECKS
6391  CheckCast(value);
6392 #endif
6393  return static_cast<Integer*>(value);
6394 }
6395 
6396 
6397 Date* Date::Cast(v8::Value* value) {
6398 #ifdef V8_ENABLE_CHECKS
6399  CheckCast(value);
6400 #endif
6401  return static_cast<Date*>(value);
6402 }
6403 
6404 
6405 StringObject* StringObject::Cast(v8::Value* value) {
6406 #ifdef V8_ENABLE_CHECKS
6407  CheckCast(value);
6408 #endif
6409  return static_cast<StringObject*>(value);
6410 }
6411 
6412 
6413 SymbolObject* SymbolObject::Cast(v8::Value* value) {
6414 #ifdef V8_ENABLE_CHECKS
6415  CheckCast(value);
6416 #endif
6417  return static_cast<SymbolObject*>(value);
6418 }
6419 
6420 
6421 NumberObject* NumberObject::Cast(v8::Value* value) {
6422 #ifdef V8_ENABLE_CHECKS
6423  CheckCast(value);
6424 #endif
6425  return static_cast<NumberObject*>(value);
6426 }
6427 
6428 
6429 BooleanObject* BooleanObject::Cast(v8::Value* value) {
6430 #ifdef V8_ENABLE_CHECKS
6431  CheckCast(value);
6432 #endif
6433  return static_cast<BooleanObject*>(value);
6434 }
6435 
6436 
6437 RegExp* RegExp::Cast(v8::Value* value) {
6438 #ifdef V8_ENABLE_CHECKS
6439  CheckCast(value);
6440 #endif
6441  return static_cast<RegExp*>(value);
6442 }
6443 
6444 
6445 Object* Object::Cast(v8::Value* value) {
6446 #ifdef V8_ENABLE_CHECKS
6447  CheckCast(value);
6448 #endif
6449  return static_cast<Object*>(value);
6450 }
6451 
6452 
6453 Array* Array::Cast(v8::Value* value) {
6454 #ifdef V8_ENABLE_CHECKS
6455  CheckCast(value);
6456 #endif
6457  return static_cast<Array*>(value);
6458 }
6459 
6460 
6461 Promise* Promise::Cast(v8::Value* value) {
6462 #ifdef V8_ENABLE_CHECKS
6463  CheckCast(value);
6464 #endif
6465  return static_cast<Promise*>(value);
6466 }
6467 
6468 
6469 Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
6470 #ifdef V8_ENABLE_CHECKS
6471  CheckCast(value);
6472 #endif
6473  return static_cast<Promise::Resolver*>(value);
6474 }
6475 
6476 
6477 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
6478 #ifdef V8_ENABLE_CHECKS
6479  CheckCast(value);
6480 #endif
6481  return static_cast<ArrayBuffer*>(value);
6482 }
6483 
6484 
6485 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
6486 #ifdef V8_ENABLE_CHECKS
6487  CheckCast(value);
6488 #endif
6489  return static_cast<ArrayBufferView*>(value);
6490 }
6491 
6492 
6493 TypedArray* TypedArray::Cast(v8::Value* value) {
6494 #ifdef V8_ENABLE_CHECKS
6495  CheckCast(value);
6496 #endif
6497  return static_cast<TypedArray*>(value);
6498 }
6499 
6500 
6501 Uint8Array* Uint8Array::Cast(v8::Value* value) {
6502 #ifdef V8_ENABLE_CHECKS
6503  CheckCast(value);
6504 #endif
6505  return static_cast<Uint8Array*>(value);
6506 }
6507 
6508 
6509 Int8Array* Int8Array::Cast(v8::Value* value) {
6510 #ifdef V8_ENABLE_CHECKS
6511  CheckCast(value);
6512 #endif
6513  return static_cast<Int8Array*>(value);
6514 }
6515 
6516 
6517 Uint16Array* Uint16Array::Cast(v8::Value* value) {
6518 #ifdef V8_ENABLE_CHECKS
6519  CheckCast(value);
6520 #endif
6521  return static_cast<Uint16Array*>(value);
6522 }
6523 
6524 
6525 Int16Array* Int16Array::Cast(v8::Value* value) {
6526 #ifdef V8_ENABLE_CHECKS
6527  CheckCast(value);
6528 #endif
6529  return static_cast<Int16Array*>(value);
6530 }
6531 
6532 
6533 Uint32Array* Uint32Array::Cast(v8::Value* value) {
6534 #ifdef V8_ENABLE_CHECKS
6535  CheckCast(value);
6536 #endif
6537  return static_cast<Uint32Array*>(value);
6538 }
6539 
6540 
6541 Int32Array* Int32Array::Cast(v8::Value* value) {
6542 #ifdef V8_ENABLE_CHECKS
6543  CheckCast(value);
6544 #endif
6545  return static_cast<Int32Array*>(value);
6546 }
6547 
6548 
6549 Float32Array* Float32Array::Cast(v8::Value* value) {
6550 #ifdef V8_ENABLE_CHECKS
6551  CheckCast(value);
6552 #endif
6553  return static_cast<Float32Array*>(value);
6554 }
6555 
6556 
6557 Float64Array* Float64Array::Cast(v8::Value* value) {
6558 #ifdef V8_ENABLE_CHECKS
6559  CheckCast(value);
6560 #endif
6561  return static_cast<Float64Array*>(value);
6562 }
6563 
6564 
6565 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
6566 #ifdef V8_ENABLE_CHECKS
6567  CheckCast(value);
6568 #endif
6569  return static_cast<Uint8ClampedArray*>(value);
6570 }
6571 
6572 
6573 DataView* DataView::Cast(v8::Value* value) {
6574 #ifdef V8_ENABLE_CHECKS
6575  CheckCast(value);
6576 #endif
6577  return static_cast<DataView*>(value);
6578 }
6579 
6580 
6581 Function* Function::Cast(v8::Value* value) {
6582 #ifdef V8_ENABLE_CHECKS
6583  CheckCast(value);
6584 #endif
6585  return static_cast<Function*>(value);
6586 }
6587 
6588 
6589 External* External::Cast(v8::Value* value) {
6590 #ifdef V8_ENABLE_CHECKS
6591  CheckCast(value);
6592 #endif
6593  return static_cast<External*>(value);
6594 }
6595 
6596 
6597 template<typename T>
6598 Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
6599  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
6600 }
6601 
6602 
6603 template<typename T>
6604 Local<Value> PropertyCallbackInfo<T>::Data() const {
6605  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
6606 }
6607 
6608 
6609 template<typename T>
6610 Local<Object> PropertyCallbackInfo<T>::This() const {
6611  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
6612 }
6613 
6614 
6615 template<typename T>
6616 Local<Object> PropertyCallbackInfo<T>::Holder() const {
6617  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
6618 }
6619 
6620 
6621 template<typename T>
6622 ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
6623  return ReturnValue<T>(&args_[kReturnValueIndex]);
6624 }
6625 
6626 
6627 Handle<Primitive> Undefined(Isolate* isolate) {
6628  typedef internal::Object* S;
6629  typedef internal::Internals I;
6630  I::CheckInitialized(isolate);
6631  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
6632  return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
6633 }
6634 
6635 
6636 Handle<Primitive> Null(Isolate* isolate) {
6637  typedef internal::Object* S;
6638  typedef internal::Internals I;
6639  I::CheckInitialized(isolate);
6640  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
6641  return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
6642 }
6643 
6644 
6645 Handle<Boolean> True(Isolate* isolate) {
6646  typedef internal::Object* S;
6647  typedef internal::Internals I;
6648  I::CheckInitialized(isolate);
6649  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
6650  return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
6651 }
6652 
6653 
6654 Handle<Boolean> False(Isolate* isolate) {
6655  typedef internal::Object* S;
6656  typedef internal::Internals I;
6657  I::CheckInitialized(isolate);
6658  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
6659  return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
6660 }
6661 
6662 
6663 void Isolate::SetData(uint32_t slot, void* data) {
6664  typedef internal::Internals I;
6665  I::SetEmbedderData(this, slot, data);
6666 }
6667 
6668 
6669 void* Isolate::GetData(uint32_t slot) {
6670  typedef internal::Internals I;
6671  return I::GetEmbedderData(this, slot);
6672 }
6673 
6674 
6676  typedef internal::Internals I;
6677  return I::kNumIsolateDataSlots;
6678 }
6679 
6680 
6682  int64_t change_in_bytes) {
6683  typedef internal::Internals I;
6684  int64_t* amount_of_external_allocated_memory =
6685  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
6686  I::kAmountOfExternalAllocatedMemoryOffset);
6687  int64_t* amount_of_external_allocated_memory_at_last_global_gc =
6688  reinterpret_cast<int64_t*>(
6689  reinterpret_cast<uint8_t*>(this) +
6690  I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
6691  int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
6692  if (change_in_bytes > 0 &&
6693  amount - *amount_of_external_allocated_memory_at_last_global_gc >
6694  I::kExternalAllocationLimit) {
6695  CollectAllGarbage("external memory allocation limit reached.");
6696  } else {
6697  *amount_of_external_allocated_memory = amount;
6698  }
6699  return *amount_of_external_allocated_memory;
6700 }
6701 
6702 
6703 template<typename T>
6705  UniqueId id) {
6706  TYPE_CHECK(Value, T);
6707  SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id);
6708 }
6709 
6710 
6711 template<typename T>
6713  const Persistent<T>& object) {
6714  TYPE_CHECK(Value, T);
6715  SetReferenceFromGroup(id,
6716  reinterpret_cast<v8::internal::Object**>(object.val_));
6717 }
6718 
6719 
6720 template<typename T, typename S>
6722  const Persistent<S>& child) {
6723  TYPE_CHECK(Object, T);
6724  TYPE_CHECK(Value, S);
6725  SetReference(reinterpret_cast<v8::internal::Object**>(parent.val_),
6726  reinterpret_cast<v8::internal::Object**>(child.val_));
6727 }
6728 
6729 
6731 #ifndef V8_ENABLE_CHECKS
6732  typedef internal::Object O;
6733  typedef internal::HeapObject HO;
6734  typedef internal::Internals I;
6735  HO* context = *reinterpret_cast<HO**>(this);
6736  O** result =
6737  HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
6738  return Local<Value>(reinterpret_cast<Value*>(result));
6739 #else
6740  return SlowGetEmbedderData(index);
6741 #endif
6742 }
6743 
6744 
6746 #ifndef V8_ENABLE_CHECKS
6747  typedef internal::Internals I;
6748  return I::ReadEmbedderData<void*>(this, index);
6749 #else
6750  return SlowGetAlignedPointerFromEmbedderData(index);
6751 #endif
6752 }
6753 
6754 
6767 } // namespace v8
6768 
6769 
6770 #undef TYPE_CHECK
6771 
6772 
6773 #endif // V8_H_
Definition: v8.h:2017
Definition: v8.h:2884
Definition: v8.h:1004
void(* NamedPropertyDeleterCallback)(Local< String > property, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:3290
UseCounterFeature
Definition: v8.h:4186
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Definition: v8.h:3336
void SetReferenceFromGroup(UniqueId id, const Persistent< T > &child)
Definition: v8.h:6712
V8_INLINE bool operator==(const Handle< S > &that) const
Definition: v8.h:243
Definition: v8.h:2979
Definition: v8.h:3745
Definition: v8-profiler.h:545
V8_INLINE uint16_t WrapperClassId() const
Definition: v8.h:5979
Definition: v8.h:971
V8_INLINE bool IsWeak() const
Definition: v8.h:5872
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
Definition: v8.h:3375
Definition: v8.h:3751
void(* NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:3299
void SetReference(const Persistent< T > &parent, const Persistent< S > &child)
Definition: v8.h:6721
WriteOptions
Definition: v8.h:1677
V8_INLINE UniquePersistent()
Definition: v8.h:731
static V8_INLINE Local< T > New(Isolate *isolate, Handle< T > that)
Definition: v8.h:5786
Definition: v8.h:3771
Definition: v8.h:2931
virtual ~ExternalStringResource()
Definition: v8.h:1755
Definition: v8.h:5478
GarbageCollectionType
Definition: v8.h:4176
V8_INLINE Local< T > Escape(Local< T > value)
Definition: v8.h:863
V8_INLINE void MarkPartiallyDependent()
Definition: v8.h:5950
Definition: v8.h:920
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
Definition: v8.h:2258
Definition: v8.h:888
Definition: v8.h:2637
V8_INLINE void Clear()
Definition: v8.h:231
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
Definition: v8.h:3011
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Definition: v8.h:2277
void(* NamedPropertySetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:3269
Definition: v8.h:5614
Definition: v8.h:1991
V8_INLINE UniquePersistent(RValue rvalue)
Definition: v8.h:755
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:2100
Definition: v8.h:5547
Definition: v8.h:1366
Definition: v8.h:1610
Definition: v8.h:1232
Definition: v8.h:2733
Definition: v8.h:1038
Definition: v8.h:5244
V8_INLINE bool operator!=(const Handle< S > &that) const
Definition: v8.h:266
Definition: v8.h:124
const char * data() const
Definition: v8.h:3822
Definition: v8.h:3717
Definition: v8.h:4662
JitCodeEventOptions
Definition: v8.h:4686
Definition: v8.h:1620
Definition: v8-platform.h:28
bool(* EntropySource)(unsigned char *buffer, size_t length)
Definition: v8.h:4581
Definition: v8.h:1077
Definition: v8.h:4060
Definition: v8.h:2899
Definition: v8.h:101
V8_INLINE void * GetAlignedPointerFromEmbedderData(int index)
Definition: v8.h:6745
V8_INLINE Unlocker(Isolate *isolate)
Definition: v8.h:5483
V8_INLINE Persistent(const Persistent &that)
Definition: v8.h:656
Definition: v8.h:1603
Definition: v8.h:2424
Definition: v8.h:4621
Definition: v8.h:415
Definition: v8.h:1284
Definition: v8.h:4098
Definition: v8-debug.h:13
Definition: v8.h:800
V8_INLINE Handle(Handle< S > that)
Definition: v8.h:213
Definition: v8.h:3473
Definition: v8.h:102
Definition: v8.h:4704
Definition: v8.h:2692
Definition: v8.h:4654
AccessType
Definition: v8.h:3352
static void * JSStackComparableAddress(v8::TryCatch *handler)
Definition: v8.h:5187
V8_INLINE Handle()
Definition: v8.h:201
Definition: v8.h:1930
size_t length() const
Definition: v8.h:3823
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:3307
V8_INLINE Local< Value > GetEmbedderData(int index)
Definition: v8.h:6730
Definition: v8.h:2565
void(* NamedPropertyGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:3260
V8_INLINE UniquePersistent & operator=(UniquePersistent< S > rhs)
Definition: v8.h:764
Definition: v8.h:3962
V8_INLINE Persistent()
Definition: v8.h:630
Definition: v8.h:106
Definition: v8.h:2915
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:3316
Definition: v8.h:100
Definition: v8.h:1159
Definition: v8.h:2639
V8_INLINE bool IsEmpty() const
Definition: v8.h:226
Definition: v8.h:3060
Definition: v8.h:3734
Definition: v8.h:2947
Flags
Definition: v8.h:3132
V8_INLINE Local(Local< S > that)
Definition: v8.h:335
virtual ~ExternalAsciiStringResource()
Definition: v8.h:1789
V8_INLINE ExternalStringResourceBase * GetExternalStringResourceBase(Encoding *encoding_out) const
Definition: v8.h:6295
Definition: v8.h:1908
V8_INLINE Locker(Isolate *isolate)
Definition: v8.h:5498
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Definition: v8.h:3345
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:3326
V8_INLINE void MarkIndependent()
Definition: v8.h:5940
Definition: v8.h:3189
V8_INLINE UniquePersistent(Isolate *isolate, Handle< S > that)
Definition: v8.h:738
V8_INLINE void SetData(uint32_t slot, void *data)
Definition: v8.h:6663
Definition: v8-util.h:405
void(* JitCodeEventHandler)(const JitCodeEvent *event)
Definition: v8.h:4698
Definition: v8.h:2817
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Definition: v8.h:646
static V8_INLINE uint32_t GetNumberOfDataSlots()
Definition: v8.h:6675
Definition: v8.h:3833
V8_INLINE ExternalStringResource * GetExternalStringResource() const
Definition: v8.h:6277
V8_INLINE void SetWrapperClassId(uint16_t class_id)
Definition: v8.h:5969
V8_INLINE void * GetAlignedPointerFromInternalField(int index)
Definition: v8.h:6244
Definition: v8.h:5072
Definition: v8.h:142
UniquePersistent Pass()
Definition: v8.h:778
Definition: v8.h:3173
V8_INLINE void SetWeak(P *parameter, typename WeakCallbackData< T, P >::Callback callback)
Definition: v8-profiler.h:129
Definition: v8.h:107
Definition: v8.h:947
V8_INLINE bool IsNearDeath() const
Definition: v8.h:5861
StackTraceOptions
Definition: v8.h:1238
Definition: v8.h:2848
Definition: v8.h:853
Definition: v8.h:3026
Definition: v8.h:3126
Definition: v8.h:2131
Definition: v8.h:606
Definition: v8.h:5380
static V8_INLINE v8::Local< v8::String > Empty(Isolate *isolate)
Definition: v8.h:6268
V8_INLINE void * GetData(uint32_t slot)
Definition: v8.h:6669
void SetObjectGroupId(const Persistent< T > &object, UniqueId id)
Definition: v8.h:6704
Definition: v8.h:114
V8_INLINE int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes)
Definition: v8.h:6681
void Enter()
Definition: v8.h:4714
Definition: v8.h:1959
Definition: v8.h:4560
Definition: v8.h:2701
Definition: v8.h:3561
Definition: v8.h:115
GCType
Definition: v8.h:4035
Definition: v8.h:1047
Definition: v8-profiler.h:390
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
Definition: v8.h:3365
Definition: v8.h:1347
Definition: v8.h:4539
Definition: v8.h:4725
Definition: v8.h:3110
Definition: v8.h:110
Definition: v8.h:5225
Definition: v8.h:3804
bool V8_EXPORT SetResourceConstraints(Isolate *isolate, ResourceConstraints *constraints)
Definition: v8.h:911
Definition: v8.h:2868
virtual void Dispose()
Definition: v8.h:1732
Definition: v8.h:2963
Definition: v8.h:3891
Definition: v8.h:3076
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
Definition: v8.h:4597
Definition: v8.h:2046
V8_INLINE UniquePersistent(Isolate *isolate, const PersistentBase< S > &that)
Definition: v8.h:748
V8_INLINE void Reset()
Definition: v8.h:5881
Definition: v8.h:5493
V8_INLINE bool IsNull() const
Definition: v8.h:6333
bool(* AllowCodeGenerationFromStringsCallback)(Local< Context > context)
Definition: v8.h:4024
Definition: v8.h:4092
Definition: v8.h:3092
Definition: v8.h:2057
AccessControl
Definition: v8.h:2120
void(* FunctionEntryHook)(uintptr_t function, uintptr_t return_addr_location)
Definition: v8.h:4612
V8_INLINE bool IsString() const
Definition: v8.h:6351
V8_INLINE Persistent(Isolate *isolate, Handle< S > that)
Definition: v8.h:636
Definition: v8-util.h:119
Definition: v8.h:2995
void(* NamedPropertyQueryCallback)(Local< String > property, const PropertyCallbackInfo< Integer > &info)
Definition: v8.h:3280
Definition: v8.h:2031
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
V8_INLINE Local< Value > GetInternalField(int index)
Definition: v8.h:6225
Definition: v8.h:132
Definition: v8.h:104
V8_INLINE bool IsUndefined() const
Definition: v8.h:6315
V8_INLINE ~Persistent()
Definition: v8.h:677