V8 Project
v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 /** \mainpage V8 API Reference Guide
6  *
7  * V8 is Google's open source JavaScript engine.
8  *
9  * This set of documents provides reference material generated from the
10  * V8 header file, include/v8.h.
11  *
12  * For other documentation see http://code.google.com/apis/v8/
13  */
14 
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 
58 /**
59  * The v8 JavaScript engine.
60  */
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 Name;
81 class Number;
82 class NumberObject;
83 class Object;
84 class ObjectOperationDescriptor;
85 class ObjectTemplate;
86 class Platform;
87 class Primitive;
88 class RawOperationDescriptor;
89 class Script;
90 class Signature;
91 class StackFrame;
92 class StackTrace;
93 class String;
94 class StringObject;
95 class Symbol;
96 class SymbolObject;
97 class Private;
98 class Uint32;
99 class Utils;
100 class Value;
101 template <class T> class Handle;
102 template <class T> class Local;
103 template <class T> class Eternal;
104 template<class T> class NonCopyablePersistentTraits;
105 template<class T> class PersistentBase;
106 template<class T,
107  class M = NonCopyablePersistentTraits<T> > class Persistent;
108 template<class T> class UniquePersistent;
109 template<class K, class V, class T> class PersistentValueMap;
110 template<class V, class T> class PersistentValueVector;
111 template<class T, class P> class WeakCallbackObject;
112 class FunctionTemplate;
113 class ObjectTemplate;
114 class Data;
115 template<typename T> class FunctionCallbackInfo;
116 template<typename T> class PropertyCallbackInfo;
117 class StackTrace;
118 class StackFrame;
119 class Isolate;
123 class CallHandlerHelper;
125 template<typename T> class ReturnValue;
126 
127 namespace internal {
128 class Arguments;
129 class Heap;
130 class HeapObject;
131 class Isolate;
132 class Object;
133 struct StreamedSource;
134 template<typename T> class CustomArguments;
135 class PropertyCallbackArguments;
136 class FunctionCallbackArguments;
137 class GlobalHandles;
138 }
139 
140 
141 /**
142  * General purpose unique identifier.
143  */
144 class UniqueId {
145  public:
146  explicit UniqueId(intptr_t data)
147  : data_(data) {}
148 
149  bool operator==(const UniqueId& other) const {
150  return data_ == other.data_;
151  }
152 
153  bool operator!=(const UniqueId& other) const {
154  return data_ != other.data_;
155  }
156 
157  bool operator<(const UniqueId& other) const {
158  return data_ < other.data_;
159  }
160 
161  private:
162  intptr_t data_;
163 };
164 
165 // --- Handles ---
166 
167 #define TYPE_CHECK(T, S) \
168  while (false) { \
169  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
170  }
171 
172 
173 /**
174  * An object reference managed by the v8 garbage collector.
175  *
176  * All objects returned from v8 have to be tracked by the garbage
177  * collector so that it knows that the objects are still alive. Also,
178  * because the garbage collector may move objects, it is unsafe to
179  * point directly to an object. Instead, all objects are stored in
180  * handles which are known by the garbage collector and updated
181  * whenever an object moves. Handles should always be passed by value
182  * (except in cases like out-parameters) and they should never be
183  * allocated on the heap.
184  *
185  * There are two types of handles: local and persistent handles.
186  * Local handles are light-weight and transient and typically used in
187  * local operations. They are managed by HandleScopes. Persistent
188  * handles can be used when storing objects across several independent
189  * operations and have to be explicitly deallocated when they're no
190  * longer used.
191  *
192  * It is safe to extract the object stored in the handle by
193  * dereferencing the handle (for instance, to extract the Object* from
194  * a Handle<Object>); the value will still be governed by a handle
195  * behind the scenes and the same rules apply to these values as to
196  * their handles.
197  */
198 template <class T> class Handle {
199  public:
200  /**
201  * Creates an empty handle.
202  */
204 
205  /**
206  * Creates a handle for the contents of the specified handle. This
207  * constructor allows you to pass handles as arguments by value and
208  * to assign between handles. However, if you try to assign between
209  * incompatible handles, for instance from a Handle<String> to a
210  * Handle<Number> it will cause a compile-time error. Assigning
211  * between compatible handles, for instance assigning a
212  * Handle<String> to a variable declared as Handle<Value>, is legal
213  * because String is a subclass of Value.
214  */
215  template <class S> V8_INLINE Handle(Handle<S> that)
216  : val_(reinterpret_cast<T*>(*that)) {
217  /**
218  * This check fails when trying to convert between incompatible
219  * handles. For example, converting from a Handle<String> to a
220  * Handle<Number>.
221  */
222  TYPE_CHECK(T, S);
223  }
224 
225  /**
226  * Returns true if the handle is empty.
227  */
228  V8_INLINE bool IsEmpty() const { return val_ == 0; }
229 
230  /**
231  * Sets the handle to be empty. IsEmpty() will then return true.
232  */
233  V8_INLINE void Clear() { val_ = 0; }
234 
235  V8_INLINE T* operator->() const { return val_; }
236 
237  V8_INLINE T* operator*() const { return val_; }
238 
239  /**
240  * Checks whether two handles are the same.
241  * Returns true if both are empty, or if the objects
242  * to which they refer are identical.
243  * The handles' references are not checked.
244  */
245  template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
246  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
247  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
248  if (a == 0) return b == 0;
249  if (b == 0) return false;
250  return *a == *b;
251  }
252 
253  template <class S> V8_INLINE bool operator==(
254  const PersistentBase<S>& that) const {
255  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
256  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
257  if (a == 0) return b == 0;
258  if (b == 0) return false;
259  return *a == *b;
260  }
261 
262  /**
263  * Checks whether two handles are different.
264  * Returns true if only one of the handles is empty, or if
265  * the objects to which they refer are different.
266  * The handles' references are not checked.
267  */
268  template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const {
269  return !operator==(that);
270  }
271 
272  template <class S> V8_INLINE bool operator!=(
273  const Persistent<S>& that) const {
274  return !operator==(that);
275  }
276 
277  template <class S> V8_INLINE static Handle<T> Cast(Handle<S> that) {
278 #ifdef V8_ENABLE_CHECKS
279  // If we're going to perform the type check then we have to check
280  // that the handle isn't empty before doing the checked cast.
281  if (that.IsEmpty()) return Handle<T>();
282 #endif
283  return Handle<T>(T::Cast(*that));
284  }
285 
286  template <class S> V8_INLINE Handle<S> As() {
287  return Handle<S>::Cast(*this);
288  }
289 
290  V8_INLINE static Handle<T> New(Isolate* isolate, Handle<T> that) {
291  return New(isolate, that.val_);
292  }
293  V8_INLINE static Handle<T> New(Isolate* isolate,
294  const PersistentBase<T>& that) {
295  return New(isolate, that.val_);
296  }
297 
298  private:
299  friend class Utils;
300  template<class F, class M> friend class Persistent;
301  template<class F> friend class PersistentBase;
302  template<class F> friend class Handle;
303  template<class F> friend class Local;
304  template<class F> friend class FunctionCallbackInfo;
305  template<class F> friend class PropertyCallbackInfo;
306  template<class F> friend class internal::CustomArguments;
308  friend Handle<Primitive> Null(Isolate* isolate);
309  friend Handle<Boolean> True(Isolate* isolate);
310  friend Handle<Boolean> False(Isolate* isolate);
311  friend class Context;
312  friend class HandleScope;
313  friend class Object;
314  friend class Private;
315 
316  /**
317  * Creates a new handle for the specified value.
318  */
319  V8_INLINE explicit Handle(T* val) : val_(val) {}
320 
321  V8_INLINE static Handle<T> New(Isolate* isolate, T* that);
322 
323  T* val_;
324 };
325 
326 
327 /**
328  * A light-weight stack-allocated object handle. All operations
329  * that return objects from within v8 return them in local handles. They
330  * are created within HandleScopes, and all local handles allocated within a
331  * handle scope are destroyed when the handle scope is destroyed. Hence it
332  * is not necessary to explicitly deallocate local handles.
333  */
334 template <class T> class Local : public Handle<T> {
335  public:
337  template <class S> V8_INLINE Local(Local<S> that)
338  : Handle<T>(reinterpret_cast<T*>(*that)) {
339  /**
340  * This check fails when trying to convert between incompatible
341  * handles. For example, converting from a Handle<String> to a
342  * Handle<Number>.
343  */
344  TYPE_CHECK(T, S);
345  }
346 
347 
348  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
349 #ifdef V8_ENABLE_CHECKS
350  // If we're going to perform the type check then we have to check
351  // that the handle isn't empty before doing the checked cast.
352  if (that.IsEmpty()) return Local<T>();
353 #endif
354  return Local<T>(T::Cast(*that));
355  }
356  template <class S> V8_INLINE Local(Handle<S> that)
357  : Handle<T>(reinterpret_cast<T*>(*that)) {
358  TYPE_CHECK(T, S);
359  }
360 
361  template <class S> V8_INLINE Local<S> As() {
362  return Local<S>::Cast(*this);
363  }
364 
365  /**
366  * Create a local handle for the content of another handle.
367  * The referee is kept alive by the local handle even when
368  * the original handle is destroyed/disposed.
369  */
370  V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that);
371  V8_INLINE static Local<T> New(Isolate* isolate,
372  const PersistentBase<T>& that);
373 
374  private:
375  friend class Utils;
376  template<class F> friend class Eternal;
377  template<class F> friend class PersistentBase;
378  template<class F, class M> friend class Persistent;
379  template<class F> friend class Handle;
380  template<class F> friend class Local;
381  template<class F> friend class FunctionCallbackInfo;
382  template<class F> friend class PropertyCallbackInfo;
383  friend class String;
384  friend class Object;
385  friend class Context;
386  template<class F> friend class internal::CustomArguments;
387  friend class HandleScope;
388  friend class EscapableHandleScope;
389  template<class F1, class F2, class F3> friend class PersistentValueMap;
390  template<class F1, class F2> friend class PersistentValueVector;
391 
392  template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { }
393  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
394 };
395 
396 
397 // Eternal handles are set-once handles that live for the life of the isolate.
398 template <class T> class Eternal {
399  public:
401  template<class S>
403  Set(isolate, handle);
404  }
405  // Can only be safely called if already set.
406  V8_INLINE Local<T> Get(Isolate* isolate);
407  V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
408  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
409 
410  private:
411  static const int kInitialValue = -1;
412  int index_;
413 };
414 
415 
416 template<class T, class P>
418  public:
419  typedef void (*Callback)(const WeakCallbackData<T, P>& data);
420 
421  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
422  V8_INLINE Local<T> GetValue() const { return handle_; }
423  V8_INLINE P* GetParameter() const { return parameter_; }
424 
425  private:
427  WeakCallbackData(Isolate* isolate, Local<T> handle, P* parameter)
428  : isolate_(isolate), handle_(handle), parameter_(parameter) { }
432 };
433 
434 
435 /**
436  * An object reference that is independent of any handle scope. Where
437  * a Local handle only lives as long as the HandleScope in which it was
438  * allocated, a PersistentBase handle remains valid until it is explicitly
439  * disposed.
440  *
441  * A persistent handle contains a reference to a storage cell within
442  * the v8 engine which holds an object value and which is updated by
443  * the garbage collector whenever the object is moved. A new storage
444  * cell can be created using the constructor or PersistentBase::Reset and
445  * existing handles can be disposed using PersistentBase::Reset.
446  *
447  */
448 template <class T> class PersistentBase {
449  public:
450  /**
451  * If non-empty, destroy the underlying storage cell
452  * IsEmpty() will return true after this call.
453  */
454  V8_INLINE void Reset();
455  /**
456  * If non-empty, destroy the underlying storage cell
457  * and create a new one with the contents of other if other is non empty
458  */
459  template <class S>
460  V8_INLINE void Reset(Isolate* isolate, const Handle<S>& other);
461 
462  /**
463  * If non-empty, destroy the underlying storage cell
464  * and create a new one with the contents of other if other is non empty
465  */
466  template <class S>
467  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
468 
469  V8_INLINE bool IsEmpty() const { return val_ == 0; }
470 
471  template <class S>
472  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
473  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
474  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
475  if (a == 0) return b == 0;
476  if (b == 0) return false;
477  return *a == *b;
478  }
479 
480  template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
481  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
482  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
483  if (a == 0) return b == 0;
484  if (b == 0) return false;
485  return *a == *b;
486  }
487 
488  template <class S>
489  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
490  return !operator==(that);
491  }
492 
493  template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const {
494  return !operator==(that);
495  }
496 
497  /**
498  * Install a finalization callback on this object.
499  * NOTE: There is no guarantee as to *when* or even *if* the callback is
500  * invoked. The invocation is performed solely on a best effort basis.
501  * As always, GC-based finalization should *not* be relied upon for any
502  * critical form of resource management!
503  */
504  template<typename P>
505  V8_INLINE void SetWeak(
506  P* parameter,
507  typename WeakCallbackData<T, P>::Callback callback);
508 
509  template<typename S, typename P>
510  V8_INLINE void SetWeak(
511  P* parameter,
512  typename WeakCallbackData<S, P>::Callback callback);
513 
514  template<typename P>
515  V8_INLINE P* ClearWeak();
516 
517  // TODO(dcarney): remove this.
518  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
519 
520  /**
521  * Marks the reference to this object independent. Garbage collector is free
522  * to ignore any object groups containing this object. Weak callback for an
523  * independent handle should not assume that it will be preceded by a global
524  * GC prologue callback or followed by a global GC epilogue callback.
525  */
526  V8_INLINE void MarkIndependent();
527 
528  /**
529  * Marks the reference to this object partially dependent. Partially dependent
530  * handles only depend on other partially dependent handles and these
531  * dependencies are provided through object groups. It provides a way to build
532  * smaller object groups for young objects that represent only a subset of all
533  * external dependencies. This mark is automatically cleared after each
534  * garbage collection.
535  */
537 
538  V8_INLINE bool IsIndependent() const;
539 
540  /** Checks if the handle holds the only reference to an object. */
541  V8_INLINE bool IsNearDeath() const;
542 
543  /** Returns true if the handle's reference is weak. */
544  V8_INLINE bool IsWeak() const;
545 
546  /**
547  * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
548  * description in v8-profiler.h for details.
549  */
550  V8_INLINE void SetWrapperClassId(uint16_t class_id);
551 
552  /**
553  * Returns the class ID previously assigned to this handle or 0 if no class ID
554  * was previously assigned.
555  */
557 
558  private:
559  friend class Isolate;
560  friend class Utils;
561  template<class F> friend class Handle;
562  template<class F> friend class Local;
563  template<class F1, class F2> friend class Persistent;
564  template<class F> friend class UniquePersistent;
565  template<class F> friend class PersistentBase;
566  template<class F> friend class ReturnValue;
567  template<class F1, class F2, class F3> friend class PersistentValueMap;
568  template<class F1, class F2> friend class PersistentValueVector;
569  friend class Object;
570 
571  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
572  PersistentBase(PersistentBase& other); // NOLINT
574  V8_INLINE static T* New(Isolate* isolate, T* that);
575 
576  T* val_;
577 };
578 
579 
580 /**
581  * Default traits for Persistent. This class does not allow
582  * use of the copy constructor or assignment operator.
583  * At present kResetInDestructor is not set, but that will change in a future
584  * version.
585  */
586 template<class T>
588  public:
590  static const bool kResetInDestructor = false;
591  template<class S, class M>
592  V8_INLINE static void Copy(const Persistent<S, M>& source,
593  NonCopyablePersistent* dest) {
594  Uncompilable<Object>();
595  }
596  // TODO(dcarney): come up with a good compile error here.
597  template<class O> V8_INLINE static void Uncompilable() {
598  TYPE_CHECK(O, Primitive);
599  }
600 };
601 
602 
603 /**
604  * Helper class traits to allow copying and assignment of Persistent.
605  * This will clone the contents of storage cell, but not any of the flags, etc.
606  */
607 template<class T>
610  static const bool kResetInDestructor = true;
611  template<class S, class M>
612  static V8_INLINE void Copy(const Persistent<S, M>& source,
613  CopyablePersistent* dest) {
614  // do nothing, just allow copy
615  }
616 };
617 
618 
619 /**
620  * A PersistentBase which allows copy and assignment.
621  *
622  * Copy, assignment and destructor bevavior is controlled by the traits
623  * class M.
624  *
625  * Note: Persistent class hierarchy is subject to future changes.
626  */
627 template <class T, class M> class Persistent : public PersistentBase<T> {
628  public:
629  /**
630  * A Persistent with no storage cell.
631  */
633  /**
634  * Construct a Persistent from a Handle.
635  * When the Handle is non-empty, a new storage cell is created
636  * pointing to the same object, and no flags are set.
637  */
638  template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that)
639  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
640  TYPE_CHECK(T, S);
641  }
642  /**
643  * Construct a Persistent from a Persistent.
644  * When the Persistent is non-empty, a new storage cell is created
645  * pointing to the same object, and no flags are set.
646  */
647  template <class S, class M2>
649  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
650  TYPE_CHECK(T, S);
651  }
652  /**
653  * The copy constructors and assignment operator create a Persistent
654  * exactly as the Persistent constructor, but the Copy function from the
655  * traits class is called, allowing the setting of flags based on the
656  * copied Persistent.
657  */
659  Copy(that);
660  }
661  template <class S, class M2>
663  Copy(that);
664  }
665  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
666  Copy(that);
667  return *this;
668  }
669  template <class S, class M2>
671  Copy(that);
672  return *this;
673  }
674  /**
675  * The destructor will dispose the Persistent based on the
676  * kResetInDestructor flags in the traits class. Since not calling dispose
677  * can result in a memory leak, it is recommended to always set this flag.
678  */
680  if (M::kResetInDestructor) this->Reset();
681  }
682 
683  // TODO(dcarney): this is pretty useless, fix or remove
684  template <class S>
685  V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT
686 #ifdef V8_ENABLE_CHECKS
687  // If we're going to perform the type check then we have to check
688  // that the handle isn't empty before doing the checked cast.
689  if (!that.IsEmpty()) T::Cast(*that);
690 #endif
691  return reinterpret_cast<Persistent<T>&>(that);
692  }
693 
694  // TODO(dcarney): this is pretty useless, fix or remove
695  template <class S> V8_INLINE Persistent<S>& As() { // NOLINT
696  return Persistent<S>::Cast(*this);
697  }
698 
699  // This will be removed.
701 
702  private:
703  friend class Isolate;
704  friend class Utils;
705  template<class F> friend class Handle;
706  template<class F> friend class Local;
707  template<class F1, class F2> friend class Persistent;
708  template<class F> friend class ReturnValue;
709 
710  template <class S> V8_INLINE Persistent(S* that) : PersistentBase<T>(that) { }
711  V8_INLINE T* operator*() const { return this->val_; }
712  template<class S, class M2>
713  V8_INLINE void Copy(const Persistent<S, M2>& that);
714 };
715 
716 
717 /**
718  * A PersistentBase which has move semantics.
719  *
720  * Note: Persistent class hierarchy is subject to future changes.
721  */
722 template<class T>
723 class UniquePersistent : public PersistentBase<T> {
724  struct RValue {
725  V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {}
727  };
728 
729  public:
730  /**
731  * A UniquePersistent with no storage cell.
732  */
734  /**
735  * Construct a UniquePersistent from a Handle.
736  * When the Handle is non-empty, a new storage cell is created
737  * pointing to the same object, and no flags are set.
738  */
739  template <class S>
741  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
742  TYPE_CHECK(T, S);
743  }
744  /**
745  * Construct a UniquePersistent from a PersistentBase.
746  * When the Persistent is non-empty, a new storage cell is created
747  * pointing to the same object, and no flags are set.
748  */
749  template <class S>
751  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
752  TYPE_CHECK(T, S);
753  }
754  /**
755  * Move constructor.
756  */
758  : PersistentBase<T>(rvalue.object->val_) {
759  rvalue.object->val_ = 0;
760  }
762  /**
763  * Move via assignment.
764  */
765  template<class S>
767  TYPE_CHECK(T, S);
768  this->Reset();
769  this->val_ = rhs.val_;
770  rhs.val_ = 0;
771  return *this;
772  }
773  /**
774  * Cast operator for moves.
775  */
776  V8_INLINE operator RValue() { return RValue(this); }
777  /**
778  * Pass allows returning uniques from functions, etc.
779  */
781 
782  private:
785 };
786 
787 
788  /**
789  * A stack-allocated class that governs a number of local handles.
790  * After a handle scope has been created, all local handles will be
791  * allocated within that handle scope until either the handle scope is
792  * deleted or another handle scope is created. If there is already a
793  * handle scope and a new one is created, all allocations will take
794  * place in the new handle scope until it is deleted. After that,
795  * new handles will again be allocated in the original handle scope.
796  *
797  * After the handle scope of a local handle has been deleted the
798  * garbage collector will no longer track the object stored in the
799  * handle and may deallocate it. The behavior of accessing a handle
800  * for which the handle scope has been deleted is undefined.
801  */
803  public:
804  HandleScope(Isolate* isolate);
805 
806  ~HandleScope();
807 
808  /**
809  * Counts the number of allocated handles.
810  */
811  static int NumberOfHandles(Isolate* isolate);
812 
814  return reinterpret_cast<Isolate*>(isolate_);
815  }
816 
817  protected:
819 
820  void Initialize(Isolate* isolate);
821 
822  static internal::Object** CreateHandle(internal::Isolate* isolate,
823  internal::Object* value);
824 
825  private:
826  // Uses heap_object to obtain the current Isolate.
827  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
828  internal::Object* value);
829 
830  // Make it hard to create heap-allocated or illegal handle scopes by
831  // disallowing certain operations.
833  void operator=(const HandleScope&);
834  void* operator new(size_t size);
835  void operator delete(void*, size_t);
836 
840 
841  // Local::New uses CreateHandle with an Isolate* parameter.
842  template<class F> friend class Local;
843 
844  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
845  // a HeapObject* in their shortcuts.
846  friend class Object;
847  friend class Context;
848 };
849 
850 
851 /**
852  * A HandleScope which first allocates a handle in the current scope
853  * which will be later filled with the escape value.
854  */
856  public:
857  EscapableHandleScope(Isolate* isolate);
859 
860  /**
861  * Pushes the value into the previous scope and returns a handle to it.
862  * Cannot be called twice.
863  */
864  template <class T>
866  internal::Object** slot =
867  Escape(reinterpret_cast<internal::Object**>(*value));
868  return Local<T>(reinterpret_cast<T*>(slot));
869  }
870 
871  private:
872  internal::Object** Escape(internal::Object** escape_value);
873 
874  // Make it hard to create heap-allocated or illegal handle scopes by
875  // disallowing certain operations.
878  void* operator new(size_t size);
879  void operator delete(void*, size_t);
880 
882 };
883 
884 
885 /**
886  * A simple Maybe type, representing an object which may or may not have a
887  * value.
888  */
889 template<class T>
890 struct Maybe {
892  explicit Maybe(T t) : has_value(true), value(t) {}
893  Maybe(bool has, T t) : has_value(has), value(t) {}
894 
895  bool has_value;
897 };
898 
899 
900 // Convenience wrapper.
901 template <class T>
902 inline Maybe<T> maybe(T t) {
903  return Maybe<T>(t);
904 }
905 
906 
907 // --- Special objects ---
908 
909 
910 /**
911  * The superclass of values and API object templates.
912  */
914  private:
915  Data();
916 };
917 
918 
919 /**
920  * The origin, within a file, of a script.
921  */
923  public:
925  Handle<Value> resource_name,
926  Handle<Integer> resource_line_offset = Handle<Integer>(),
927  Handle<Integer> resource_column_offset = Handle<Integer>(),
928  Handle<Boolean> resource_is_shared_cross_origin = Handle<Boolean>(),
929  Handle<Integer> script_id = Handle<Integer>())
930  : resource_name_(resource_name),
931  resource_line_offset_(resource_line_offset),
932  resource_column_offset_(resource_column_offset),
933  resource_is_shared_cross_origin_(resource_is_shared_cross_origin),
934  script_id_(script_id) { }
940  private:
946 };
947 
948 
949 /**
950  * A compiled JavaScript script, not yet tied to a Context.
951  */
953  public:
954  /**
955  * Binds the script to the currently entered context.
956  */
957  Local<Script> BindToCurrentContext();
958 
959  int GetId();
960  Handle<Value> GetScriptName();
961 
962  /**
963  * Data read from magic sourceURL comments.
964  */
965  Handle<Value> GetSourceURL();
966  /**
967  * Data read from magic sourceMappingURL comments.
968  */
969  Handle<Value> GetSourceMappingURL();
970 
971  /**
972  * Returns zero based line number of the code_pos location in the script.
973  * -1 will be returned if no information available.
974  */
975  int GetLineNumber(int code_pos);
976 
977  static const int kNoScriptId = 0;
978 };
979 
980 
981 /**
982  * A compiled JavaScript script, tied to a Context which was active when the
983  * script was compiled.
984  */
986  public:
987  /**
988  * A shorthand for ScriptCompiler::Compile().
989  */
990  static Local<Script> Compile(Handle<String> source,
991  ScriptOrigin* origin = NULL);
992 
993  // To be decprecated, use the Compile above.
994  static Local<Script> Compile(Handle<String> source,
995  Handle<String> file_name);
996 
997  /**
998  * Runs the script returning the resulting value. It will be run in the
999  * context in which it was created (ScriptCompiler::CompileBound or
1000  * UnboundScript::BindToGlobalContext()).
1001  */
1002  Local<Value> Run();
1003 
1004  /**
1005  * Returns the corresponding context-unbound script.
1006  */
1007  Local<UnboundScript> GetUnboundScript();
1008 
1009  V8_DEPRECATED("Use GetUnboundScript()->GetId()",
1010  int GetId()) {
1011  return GetUnboundScript()->GetId();
1012  }
1013 };
1014 
1015 
1016 /**
1017  * For compiling scripts.
1018  */
1020  public:
1021  /**
1022  * Compilation data that the embedder can cache and pass back to speed up
1023  * future compilations. The data is produced if the CompilerOptions passed to
1024  * the compilation functions in ScriptCompiler contains produce_data_to_cache
1025  * = true. The data to cache can then can be retrieved from
1026  * UnboundScript.
1027  */
1031  BufferOwned
1032  };
1033 
1034  CachedData() : data(NULL), length(0), buffer_policy(BufferNotOwned) {}
1035 
1036  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1037  // data and guarantees that it stays alive until the CachedData object is
1038  // destroyed. If the policy is BufferOwned, the given data will be deleted
1039  // (with delete[]) when the CachedData object is destroyed.
1040  CachedData(const uint8_t* data, int length,
1041  BufferPolicy buffer_policy = BufferNotOwned);
1042  ~CachedData();
1043  // TODO(marja): Async compilation; add constructors which take a callback
1044  // which will be called when V8 no longer needs the data.
1045  const uint8_t* data;
1046  int length;
1048 
1049  private:
1050  // Prevent copying. Not implemented.
1053  };
1054 
1055  /**
1056  * Source code which can be then compiled to a UnboundScript or Script.
1057  */
1058  class Source {
1059  public:
1060  // Source takes ownership of CachedData.
1061  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1062  CachedData* cached_data = NULL);
1063  V8_INLINE Source(Local<String> source_string,
1064  CachedData* cached_data = NULL);
1065  V8_INLINE ~Source();
1066 
1067  // Ownership of the CachedData or its buffers is *not* transferred to the
1068  // caller. The CachedData object is alive as long as the Source object is
1069  // alive.
1070  V8_INLINE const CachedData* GetCachedData() const;
1071 
1072  private:
1073  friend class ScriptCompiler;
1074  // Prevent copying. Not implemented.
1075  Source(const Source&);
1077 
1079 
1080  // Origin information
1085 
1086  // Cached data from previous compilation (if a kConsume*Cache flag is
1087  // set), or hold newly generated cache data (kProduce*Cache flags) are
1088  // set when calling a compile method.
1090  };
1091 
1092  /**
1093  * For streaming incomplete script data to V8. The embedder should implement a
1094  * subclass of this class.
1095  */
1097  public:
1099 
1100  /**
1101  * V8 calls this to request the next chunk of data from the embedder. This
1102  * function will be called on a background thread, so it's OK to block and
1103  * wait for the data, if the embedder doesn't have data yet. Returns the
1104  * length of the data returned. When the data ends, GetMoreData should
1105  * return 0. Caller takes ownership of the data.
1106  *
1107  * When streaming UTF-8 data, V8 handles multi-byte characters split between
1108  * two data chunks, but doesn't handle multi-byte characters split between
1109  * more than two data chunks. The embedder can avoid this problem by always
1110  * returning at least 2 bytes of data.
1111  *
1112  * If the embedder wants to cancel the streaming, they should make the next
1113  * GetMoreData call return 0. V8 will interpret it as end of data (and most
1114  * probably, parsing will fail). The streaming task will return as soon as
1115  * V8 has parsed the data it received so far.
1116  */
1117  virtual size_t GetMoreData(const uint8_t** src) = 0;
1118  };
1119 
1120 
1121  /**
1122  * Source code which can be streamed into V8 in pieces. It will be parsed
1123  * while streaming. It can be compiled after the streaming is complete.
1124  * StreamedSource must be kept alive while the streaming task is ran (see
1125  * ScriptStreamingTask below).
1126  */
1128  public:
1129  enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
1130 
1131  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1132  ~StreamedSource();
1133 
1134  // Ownership of the CachedData or its buffers is *not* transferred to the
1135  // caller. The CachedData object is alive as long as the StreamedSource
1136  // object is alive.
1137  const CachedData* GetCachedData() const;
1138 
1139  internal::StreamedSource* impl() const { return impl_; }
1140 
1141  private:
1142  // Prevent copying. Not implemented.
1145 
1147  };
1148 
1149  /**
1150  * A streaming task which the embedder must run on a background thread to
1151  * stream scripts into V8. Returned by ScriptCompiler::StartStreamingScript.
1152  */
1154  public:
1156  virtual void Run() = 0;
1157  };
1158 
1160  kNoCompileOptions = 0,
1165 
1166  // Support the previous API for a transition period.
1167  kProduceDataToCache
1168  };
1169 
1170  /**
1171  * Compiles the specified script (context-independent).
1172  * Cached data as part of the source object can be optionally produced to be
1173  * consumed later to speed up compilation of identical source scripts.
1174  *
1175  * Note that when producing cached data, the source must point to NULL for
1176  * cached data. When consuming cached data, the cached data must have been
1177  * produced by the same version of V8.
1178  *
1179  * \param source Script source code.
1180  * \return Compiled script object (context independent; for running it must be
1181  * bound to a context).
1182  */
1183  static Local<UnboundScript> CompileUnbound(
1184  Isolate* isolate, Source* source,
1185  CompileOptions options = kNoCompileOptions);
1186 
1187  /**
1188  * Compiles the specified script (bound to current context).
1189  *
1190  * \param source Script source code.
1191  * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1192  * using pre_data speeds compilation if it's done multiple times.
1193  * Owned by caller, no references are kept when this function returns.
1194  * \return Compiled script object, bound to the context that was active
1195  * when this function was called. When run it will always use this
1196  * context.
1197  */
1198  static Local<Script> Compile(
1199  Isolate* isolate, Source* source,
1200  CompileOptions options = kNoCompileOptions);
1201 
1202  /**
1203  * Returns a task which streams script data into V8, or NULL if the script
1204  * cannot be streamed. The user is responsible for running the task on a
1205  * background thread and deleting it. When ran, the task starts parsing the
1206  * script, and it will request data from the StreamedSource as needed. When
1207  * ScriptStreamingTask::Run exits, all data has been streamed and the script
1208  * can be compiled (see Compile below).
1209  *
1210  * This API allows to start the streaming with as little data as possible, and
1211  * the remaining data (for example, the ScriptOrigin) is passed to Compile.
1212  */
1213  static ScriptStreamingTask* StartStreamingScript(
1214  Isolate* isolate, StreamedSource* source,
1215  CompileOptions options = kNoCompileOptions);
1216 
1217  /**
1218  * Compiles a streamed script (bound to current context).
1219  *
1220  * This can only be called after the streaming has finished
1221  * (ScriptStreamingTask has been run). V8 doesn't construct the source string
1222  * during streaming, so the embedder needs to pass the full source here.
1223  */
1224  static Local<Script> Compile(Isolate* isolate, StreamedSource* source,
1225  Handle<String> full_source_string,
1226  const ScriptOrigin& origin);
1227 };
1228 
1229 
1230 /**
1231  * An error message.
1232  */
1234  public:
1235  Local<String> Get() const;
1236  Local<String> GetSourceLine() const;
1237 
1238  /**
1239  * Returns the origin for the script from where the function causing the
1240  * error originates.
1241  */
1242  ScriptOrigin GetScriptOrigin() const;
1243 
1244  /**
1245  * Returns the resource name for the script from where the function causing
1246  * the error originates.
1247  */
1248  Handle<Value> GetScriptResourceName() const;
1249 
1250  /**
1251  * Exception stack trace. By default stack traces are not captured for
1252  * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
1253  * to change this option.
1254  */
1255  Handle<StackTrace> GetStackTrace() const;
1256 
1257  /**
1258  * Returns the number, 1-based, of the line where the error occurred.
1259  */
1260  int GetLineNumber() const;
1261 
1262  /**
1263  * Returns the index within the script of the first character where
1264  * the error occurred.
1265  */
1266  int GetStartPosition() const;
1267 
1268  /**
1269  * Returns the index within the script of the last character where
1270  * the error occurred.
1271  */
1272  int GetEndPosition() const;
1273 
1274  /**
1275  * Returns the index within the line of the first character where
1276  * the error occurred.
1277  */
1278  int GetStartColumn() const;
1279 
1280  /**
1281  * Returns the index within the line of the last character where
1282  * the error occurred.
1283  */
1284  int GetEndColumn() const;
1285 
1286  /**
1287  * Passes on the value set by the embedder when it fed the script from which
1288  * this Message was generated to V8.
1289  */
1290  bool IsSharedCrossOrigin() const;
1291 
1292  // TODO(1245381): Print to a string instead of on a FILE.
1293  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1294 
1295  static const int kNoLineNumberInfo = 0;
1296  static const int kNoColumnInfo = 0;
1297  static const int kNoScriptIdInfo = 0;
1298 };
1299 
1300 
1301 /**
1302  * Representation of a JavaScript stack trace. The information collected is a
1303  * snapshot of the execution stack and the information remains valid after
1304  * execution continues.
1305  */
1307  public:
1308  /**
1309  * Flags that determine what information is placed captured for each
1310  * StackFrame when grabbing the current stack trace.
1311  */
1313  kLineNumber = 1,
1314  kColumnOffset = 1 << 1 | kLineNumber,
1315  kScriptName = 1 << 2,
1316  kFunctionName = 1 << 3,
1317  kIsEval = 1 << 4,
1318  kIsConstructor = 1 << 5,
1319  kScriptNameOrSourceURL = 1 << 6,
1320  kScriptId = 1 << 7,
1321  kExposeFramesAcrossSecurityOrigins = 1 << 8,
1322  kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
1323  kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
1324  };
1325 
1326  /**
1327  * Returns a StackFrame at a particular index.
1328  */
1329  Local<StackFrame> GetFrame(uint32_t index) const;
1330 
1331  /**
1332  * Returns the number of StackFrames.
1333  */
1334  int GetFrameCount() const;
1335 
1336  /**
1337  * Returns StackTrace as a v8::Array that contains StackFrame objects.
1338  */
1339  Local<Array> AsArray();
1340 
1341  /**
1342  * Grab a snapshot of the current JavaScript execution stack.
1343  *
1344  * \param frame_limit The maximum number of stack frames we want to capture.
1345  * \param options Enumerates the set of things we will capture for each
1346  * StackFrame.
1347  */
1348  static Local<StackTrace> CurrentStackTrace(
1349  Isolate* isolate,
1350  int frame_limit,
1351  StackTraceOptions options = kOverview);
1352 };
1353 
1354 
1355 /**
1356  * A single JavaScript stack frame.
1357  */
1359  public:
1360  /**
1361  * Returns the number, 1-based, of the line for the associate function call.
1362  * This method will return Message::kNoLineNumberInfo if it is unable to
1363  * retrieve the line number, or if kLineNumber was not passed as an option
1364  * when capturing the StackTrace.
1365  */
1366  int GetLineNumber() const;
1367 
1368  /**
1369  * Returns the 1-based column offset on the line for the associated function
1370  * call.
1371  * This method will return Message::kNoColumnInfo if it is unable to retrieve
1372  * the column number, or if kColumnOffset was not passed as an option when
1373  * capturing the StackTrace.
1374  */
1375  int GetColumn() const;
1376 
1377  /**
1378  * Returns the id of the script for the function for this StackFrame.
1379  * This method will return Message::kNoScriptIdInfo if it is unable to
1380  * retrieve the script id, or if kScriptId was not passed as an option when
1381  * capturing the StackTrace.
1382  */
1383  int GetScriptId() const;
1384 
1385  /**
1386  * Returns the name of the resource that contains the script for the
1387  * function for this StackFrame.
1388  */
1389  Local<String> GetScriptName() const;
1390 
1391  /**
1392  * Returns the name of the resource that contains the script for the
1393  * function for this StackFrame or sourceURL value if the script name
1394  * is undefined and its source ends with //# sourceURL=... string or
1395  * deprecated //@ sourceURL=... string.
1396  */
1397  Local<String> GetScriptNameOrSourceURL() const;
1398 
1399  /**
1400  * Returns the name of the function associated with this stack frame.
1401  */
1402  Local<String> GetFunctionName() const;
1403 
1404  /**
1405  * Returns whether or not the associated function is compiled via a call to
1406  * eval().
1407  */
1408  bool IsEval() const;
1409 
1410  /**
1411  * Returns whether or not the associated function is called as a
1412  * constructor via "new".
1413  */
1414  bool IsConstructor() const;
1415 };
1416 
1417 
1418 /**
1419  * A JSON Parser.
1420  */
1422  public:
1423  /**
1424  * Tries to parse the string |json_string| and returns it as value if
1425  * successful.
1426  *
1427  * \param json_string The string to parse.
1428  * \return The corresponding value if successfully parsed.
1429  */
1430  static Local<Value> Parse(Local<String> json_string);
1431 };
1432 
1433 
1434 // --- Value ---
1435 
1436 
1437 /**
1438  * The superclass of all JavaScript values and objects.
1439  */
1440 class V8_EXPORT Value : public Data {
1441  public:
1442  /**
1443  * Returns true if this value is the undefined value. See ECMA-262
1444  * 4.3.10.
1445  */
1446  V8_INLINE bool IsUndefined() const;
1447 
1448  /**
1449  * Returns true if this value is the null value. See ECMA-262
1450  * 4.3.11.
1451  */
1452  V8_INLINE bool IsNull() const;
1453 
1454  /**
1455  * Returns true if this value is true.
1456  */
1457  bool IsTrue() const;
1458 
1459  /**
1460  * Returns true if this value is false.
1461  */
1462  bool IsFalse() const;
1463 
1464  /**
1465  * Returns true if this value is a symbol or a string.
1466  * This is an experimental feature.
1467  */
1468  bool IsName() const;
1469 
1470  /**
1471  * Returns true if this value is an instance of the String type.
1472  * See ECMA-262 8.4.
1473  */
1474  V8_INLINE bool IsString() const;
1475 
1476  /**
1477  * Returns true if this value is a symbol.
1478  * This is an experimental feature.
1479  */
1480  bool IsSymbol() const;
1481 
1482  /**
1483  * Returns true if this value is a function.
1484  */
1485  bool IsFunction() const;
1486 
1487  /**
1488  * Returns true if this value is an array.
1489  */
1490  bool IsArray() const;
1491 
1492  /**
1493  * Returns true if this value is an object.
1494  */
1495  bool IsObject() const;
1496 
1497  /**
1498  * Returns true if this value is boolean.
1499  */
1500  bool IsBoolean() const;
1501 
1502  /**
1503  * Returns true if this value is a number.
1504  */
1505  bool IsNumber() const;
1506 
1507  /**
1508  * Returns true if this value is external.
1509  */
1510  bool IsExternal() const;
1511 
1512  /**
1513  * Returns true if this value is a 32-bit signed integer.
1514  */
1515  bool IsInt32() const;
1516 
1517  /**
1518  * Returns true if this value is a 32-bit unsigned integer.
1519  */
1520  bool IsUint32() const;
1521 
1522  /**
1523  * Returns true if this value is a Date.
1524  */
1525  bool IsDate() const;
1526 
1527  /**
1528  * Returns true if this value is an Arguments object.
1529  */
1530  bool IsArgumentsObject() const;
1531 
1532  /**
1533  * Returns true if this value is a Boolean object.
1534  */
1535  bool IsBooleanObject() const;
1536 
1537  /**
1538  * Returns true if this value is a Number object.
1539  */
1540  bool IsNumberObject() const;
1541 
1542  /**
1543  * Returns true if this value is a String object.
1544  */
1545  bool IsStringObject() const;
1546 
1547  /**
1548  * Returns true if this value is a Symbol object.
1549  * This is an experimental feature.
1550  */
1551  bool IsSymbolObject() const;
1552 
1553  /**
1554  * Returns true if this value is a NativeError.
1555  */
1556  bool IsNativeError() const;
1557 
1558  /**
1559  * Returns true if this value is a RegExp.
1560  */
1561  bool IsRegExp() const;
1562 
1563  /**
1564  * Returns true if this value is a Generator function.
1565  * This is an experimental feature.
1566  */
1567  bool IsGeneratorFunction() const;
1568 
1569  /**
1570  * Returns true if this value is a Generator object (iterator).
1571  * This is an experimental feature.
1572  */
1573  bool IsGeneratorObject() const;
1574 
1575  /**
1576  * Returns true if this value is a Promise.
1577  * This is an experimental feature.
1578  */
1579  bool IsPromise() const;
1580 
1581  /**
1582  * Returns true if this value is a Map.
1583  * This is an experimental feature.
1584  */
1585  bool IsMap() const;
1586 
1587  /**
1588  * Returns true if this value is a Set.
1589  * This is an experimental feature.
1590  */
1591  bool IsSet() const;
1592 
1593  /**
1594  * Returns true if this value is a WeakMap.
1595  * This is an experimental feature.
1596  */
1597  bool IsWeakMap() const;
1598 
1599  /**
1600  * Returns true if this value is a WeakSet.
1601  * This is an experimental feature.
1602  */
1603  bool IsWeakSet() const;
1604 
1605  /**
1606  * Returns true if this value is an ArrayBuffer.
1607  * This is an experimental feature.
1608  */
1609  bool IsArrayBuffer() const;
1610 
1611  /**
1612  * Returns true if this value is an ArrayBufferView.
1613  * This is an experimental feature.
1614  */
1615  bool IsArrayBufferView() const;
1616 
1617  /**
1618  * Returns true if this value is one of TypedArrays.
1619  * This is an experimental feature.
1620  */
1621  bool IsTypedArray() const;
1622 
1623  /**
1624  * Returns true if this value is an Uint8Array.
1625  * This is an experimental feature.
1626  */
1627  bool IsUint8Array() const;
1628 
1629  /**
1630  * Returns true if this value is an Uint8ClampedArray.
1631  * This is an experimental feature.
1632  */
1633  bool IsUint8ClampedArray() const;
1634 
1635  /**
1636  * Returns true if this value is an Int8Array.
1637  * This is an experimental feature.
1638  */
1639  bool IsInt8Array() const;
1640 
1641  /**
1642  * Returns true if this value is an Uint16Array.
1643  * This is an experimental feature.
1644  */
1645  bool IsUint16Array() const;
1646 
1647  /**
1648  * Returns true if this value is an Int16Array.
1649  * This is an experimental feature.
1650  */
1651  bool IsInt16Array() const;
1652 
1653  /**
1654  * Returns true if this value is an Uint32Array.
1655  * This is an experimental feature.
1656  */
1657  bool IsUint32Array() const;
1658 
1659  /**
1660  * Returns true if this value is an Int32Array.
1661  * This is an experimental feature.
1662  */
1663  bool IsInt32Array() const;
1664 
1665  /**
1666  * Returns true if this value is a Float32Array.
1667  * This is an experimental feature.
1668  */
1669  bool IsFloat32Array() const;
1670 
1671  /**
1672  * Returns true if this value is a Float64Array.
1673  * This is an experimental feature.
1674  */
1675  bool IsFloat64Array() const;
1676 
1677  /**
1678  * Returns true if this value is a DataView.
1679  * This is an experimental feature.
1680  */
1681  bool IsDataView() const;
1682 
1683  Local<Boolean> ToBoolean() const;
1684  Local<Number> ToNumber() const;
1685  Local<String> ToString() const;
1686  Local<String> ToDetailString() const;
1687  Local<Object> ToObject() const;
1688  Local<Integer> ToInteger() const;
1689  Local<Uint32> ToUint32() const;
1690  Local<Int32> ToInt32() const;
1691 
1692  /**
1693  * Attempts to convert a string to an array index.
1694  * Returns an empty handle if the conversion fails.
1695  */
1696  Local<Uint32> ToArrayIndex() const;
1697 
1698  bool BooleanValue() const;
1699  double NumberValue() const;
1700  int64_t IntegerValue() const;
1701  uint32_t Uint32Value() const;
1702  int32_t Int32Value() const;
1703 
1704  /** JS == */
1705  bool Equals(Handle<Value> that) const;
1706  bool StrictEquals(Handle<Value> that) const;
1707  bool SameValue(Handle<Value> that) const;
1708 
1709  template <class T> V8_INLINE static Value* Cast(T* value);
1710 
1711  private:
1712  V8_INLINE bool QuickIsUndefined() const;
1713  V8_INLINE bool QuickIsNull() const;
1714  V8_INLINE bool QuickIsString() const;
1715  bool FullIsUndefined() const;
1716  bool FullIsNull() const;
1717  bool FullIsString() const;
1718 };
1719 
1720 
1721 /**
1722  * The superclass of primitive values. See ECMA-262 4.3.2.
1723  */
1724 class V8_EXPORT Primitive : public Value { };
1725 
1726 
1727 /**
1728  * A primitive boolean value (ECMA-262, 4.3.14). Either the true
1729  * or false value.
1730  */
1731 class V8_EXPORT Boolean : public Primitive {
1732  public:
1733  bool Value() const;
1734  V8_INLINE static Handle<Boolean> New(Isolate* isolate, bool value);
1735 };
1736 
1737 
1738 /**
1739  * A superclass for symbols and strings.
1740  */
1741 class V8_EXPORT Name : public Primitive {
1742  public:
1743  V8_INLINE static Name* Cast(v8::Value* obj);
1744  private:
1745  static void CheckCast(v8::Value* obj);
1746 };
1747 
1748 
1749 /**
1750  * A JavaScript string value (ECMA-262, 4.3.17).
1751  */
1752 class V8_EXPORT String : public Name {
1753  public:
1754  enum Encoding {
1755  UNKNOWN_ENCODING = 0x1,
1756  TWO_BYTE_ENCODING = 0x0,
1757  ASCII_ENCODING = 0x4, // TODO(yangguo): deprecate this.
1758  ONE_BYTE_ENCODING = 0x4
1759  };
1760  /**
1761  * Returns the number of characters in this string.
1762  */
1763  int Length() const;
1764 
1765  /**
1766  * Returns the number of bytes in the UTF-8 encoded
1767  * representation of this string.
1768  */
1769  int Utf8Length() const;
1770 
1771  /**
1772  * Returns whether this string is known to contain only one byte data.
1773  * Does not read the string.
1774  * False negatives are possible.
1775  */
1776  bool IsOneByte() const;
1777 
1778  /**
1779  * Returns whether this string contain only one byte data.
1780  * Will read the entire string in some cases.
1781  */
1782  bool ContainsOnlyOneByte() const;
1783 
1784  /**
1785  * Write the contents of the string to an external buffer.
1786  * If no arguments are given, expects the buffer to be large
1787  * enough to hold the entire string and NULL terminator. Copies
1788  * the contents of the string and the NULL terminator into the
1789  * buffer.
1790  *
1791  * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
1792  * before the end of the buffer.
1793  *
1794  * Copies up to length characters into the output buffer.
1795  * Only null-terminates if there is enough space in the buffer.
1796  *
1797  * \param buffer The buffer into which the string will be copied.
1798  * \param start The starting position within the string at which
1799  * copying begins.
1800  * \param length The number of characters to copy from the string. For
1801  * WriteUtf8 the number of bytes in the buffer.
1802  * \param nchars_ref The number of characters written, can be NULL.
1803  * \param options Various options that might affect performance of this or
1804  * subsequent operations.
1805  * \return The number of characters copied to the buffer excluding the null
1806  * terminator. For WriteUtf8: The number of bytes copied to the buffer
1807  * including the null terminator (if written).
1808  */
1810  NO_OPTIONS = 0,
1811  HINT_MANY_WRITES_EXPECTED = 1,
1812  NO_NULL_TERMINATION = 2,
1813  PRESERVE_ASCII_NULL = 4, // TODO(yangguo): deprecate this.
1814  PRESERVE_ONE_BYTE_NULL = 4,
1815  // Used by WriteUtf8 to replace orphan surrogate code units with the
1816  // unicode replacement character. Needs to be set to guarantee valid UTF-8
1817  // output.
1818  REPLACE_INVALID_UTF8 = 8
1819  };
1820 
1821  // 16-bit character codes.
1822  int Write(uint16_t* buffer,
1823  int start = 0,
1824  int length = -1,
1825  int options = NO_OPTIONS) const;
1826  // One byte characters.
1827  int WriteOneByte(uint8_t* buffer,
1828  int start = 0,
1829  int length = -1,
1830  int options = NO_OPTIONS) const;
1831  // UTF-8 encoded characters.
1832  int WriteUtf8(char* buffer,
1833  int length = -1,
1834  int* nchars_ref = NULL,
1835  int options = NO_OPTIONS) const;
1836 
1837  /**
1838  * A zero length string.
1839  */
1840  V8_INLINE static v8::Local<v8::String> Empty(Isolate* isolate);
1841 
1842  /**
1843  * Returns true if the string is external
1844  */
1845  bool IsExternal() const;
1846 
1847  /**
1848  * Returns true if the string is both external and one-byte.
1849  */
1850  bool IsExternalOneByte() const;
1851 
1852  // TODO(yangguo): deprecate this.
1853  bool IsExternalAscii() const { return IsExternalOneByte(); }
1854 
1856  public:
1858 
1859  protected:
1861 
1862  /**
1863  * Internally V8 will call this Dispose method when the external string
1864  * resource is no longer needed. The default implementation will use the
1865  * delete operator. This method can be overridden in subclasses to
1866  * control how allocated external string resources are disposed.
1867  */
1868  virtual void Dispose() { delete this; }
1869 
1870  private:
1871  // Disallow copying and assigning.
1874 
1875  friend class v8::internal::Heap;
1876  };
1877 
1878  /**
1879  * An ExternalStringResource is a wrapper around a two-byte string
1880  * buffer that resides outside V8's heap. Implement an
1881  * ExternalStringResource to manage the life cycle of the underlying
1882  * buffer. Note that the string data must be immutable.
1883  */
1885  : public ExternalStringResourceBase {
1886  public:
1887  /**
1888  * Override the destructor to manage the life cycle of the underlying
1889  * buffer.
1890  */
1892 
1893  /**
1894  * The string data from the underlying buffer.
1895  */
1896  virtual const uint16_t* data() const = 0;
1897 
1898  /**
1899  * The length of the string. That is, the number of two-byte characters.
1900  */
1901  virtual size_t length() const = 0;
1902 
1903  protected:
1905  };
1906 
1907  /**
1908  * An ExternalOneByteStringResource is a wrapper around an one-byte
1909  * string buffer that resides outside V8's heap. Implement an
1910  * ExternalOneByteStringResource to manage the life cycle of the
1911  * underlying buffer. Note that the string data must be immutable
1912  * and that the data must be Latin-1 and not UTF-8, which would require
1913  * special treatment internally in the engine and do not allow efficient
1914  * indexing. Use String::New or convert to 16 bit data for non-Latin1.
1915  */
1916 
1918  : public ExternalStringResourceBase {
1919  public:
1920  /**
1921  * Override the destructor to manage the life cycle of the underlying
1922  * buffer.
1923  */
1925  /** The string data from the underlying buffer.*/
1926  virtual const char* data() const = 0;
1927  /** The number of Latin-1 characters in the string.*/
1928  virtual size_t length() const = 0;
1929  protected:
1931  };
1932 
1934 
1935  /**
1936  * If the string is an external string, return the ExternalStringResourceBase
1937  * regardless of the encoding, otherwise return NULL. The encoding of the
1938  * string is returned in encoding_out.
1939  */
1940  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
1941  Encoding* encoding_out) const;
1942 
1943  /**
1944  * Get the ExternalStringResource for an external string. Returns
1945  * NULL if IsExternal() doesn't return true.
1946  */
1947  V8_INLINE ExternalStringResource* GetExternalStringResource() const;
1948 
1949  /**
1950  * Get the ExternalOneByteStringResource for an external one-byte string.
1951  * Returns NULL if IsExternalOneByte() doesn't return true.
1952  */
1953  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
1954 
1955  // TODO(yangguo): deprecate this.
1957  return GetExternalOneByteStringResource();
1958  }
1959 
1960  V8_INLINE static String* Cast(v8::Value* obj);
1961 
1963  kNormalString, kInternalizedString, kUndetectableString
1964  };
1965 
1966  /** Allocates a new string from UTF-8 data.*/
1967  static Local<String> NewFromUtf8(Isolate* isolate,
1968  const char* data,
1969  NewStringType type = kNormalString,
1970  int length = -1);
1971 
1972  /** Allocates a new string from Latin-1 data.*/
1973  static Local<String> NewFromOneByte(
1974  Isolate* isolate,
1975  const uint8_t* data,
1976  NewStringType type = kNormalString,
1977  int length = -1);
1978 
1979  /** Allocates a new string from UTF-16 data.*/
1980  static Local<String> NewFromTwoByte(
1981  Isolate* isolate,
1982  const uint16_t* data,
1983  NewStringType type = kNormalString,
1984  int length = -1);
1985 
1986  /**
1987  * Creates a new string by concatenating the left and the right strings
1988  * passed in as parameters.
1989  */
1990  static Local<String> Concat(Handle<String> left, Handle<String> right);
1991 
1992  /**
1993  * Creates a new external string using the data defined in the given
1994  * resource. When the external string is no longer live on V8's heap the
1995  * resource will be disposed by calling its Dispose method. The caller of
1996  * this function should not otherwise delete or modify the resource. Neither
1997  * should the underlying buffer be deallocated or modified except through the
1998  * destructor of the external string resource.
1999  */
2000  static Local<String> NewExternal(Isolate* isolate,
2001  ExternalStringResource* resource);
2002 
2003  /**
2004  * Associate an external string resource with this string by transforming it
2005  * in place so that existing references to this string in the JavaScript heap
2006  * will use the external string resource. The external string resource's
2007  * character contents need to be equivalent to this string.
2008  * Returns true if the string has been changed to be an external string.
2009  * The string is not modified if the operation fails. See NewExternal for
2010  * information on the lifetime of the resource.
2011  */
2012  bool MakeExternal(ExternalStringResource* resource);
2013 
2014  /**
2015  * Creates a new external string using the one-byte data defined in the given
2016  * resource. When the external string is no longer live on V8's heap the
2017  * resource will be disposed by calling its Dispose method. The caller of
2018  * this function should not otherwise delete or modify the resource. Neither
2019  * should the underlying buffer be deallocated or modified except through the
2020  * destructor of the external string resource.
2021  */
2022  static Local<String> NewExternal(Isolate* isolate,
2023  ExternalOneByteStringResource* resource);
2024 
2025  /**
2026  * Associate an external string resource with this string by transforming it
2027  * in place so that existing references to this string in the JavaScript heap
2028  * will use the external string resource. The external string resource's
2029  * character contents need to be equivalent to this string.
2030  * Returns true if the string has been changed to be an external string.
2031  * The string is not modified if the operation fails. See NewExternal for
2032  * information on the lifetime of the resource.
2033  */
2034  bool MakeExternal(ExternalOneByteStringResource* resource);
2035 
2036  /**
2037  * Returns true if this string can be made external.
2038  */
2039  bool CanMakeExternal();
2040 
2041  /**
2042  * Converts an object to a UTF-8-encoded character array. Useful if
2043  * you want to print the object. If conversion to a string fails
2044  * (e.g. due to an exception in the toString() method of the object)
2045  * then the length() method returns 0 and the * operator returns
2046  * NULL.
2047  */
2049  public:
2050  explicit Utf8Value(Handle<v8::Value> obj);
2051  ~Utf8Value();
2052  char* operator*() { return str_; }
2053  const char* operator*() const { return str_; }
2054  int length() const { return length_; }
2055  private:
2056  char* str_;
2057  int length_;
2058 
2059  // Disallow copying and assigning.
2061  void operator=(const Utf8Value&);
2062  };
2063 
2064  /**
2065  * Converts an object to a two-byte string.
2066  * If conversion to a string fails (eg. due to an exception in the toString()
2067  * method of the object) then the length() method returns 0 and the * operator
2068  * returns NULL.
2069  */
2071  public:
2072  explicit Value(Handle<v8::Value> obj);
2073  ~Value();
2074  uint16_t* operator*() { return str_; }
2075  const uint16_t* operator*() const { return str_; }
2076  int length() const { return length_; }
2077  private:
2079  int length_;
2080 
2081  // Disallow copying and assigning.
2082  Value(const Value&);
2083  void operator=(const Value&);
2084  };
2085 
2086  private:
2087  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2088  Encoding encoding) const;
2089  void VerifyExternalStringResource(ExternalStringResource* val) const;
2090  static void CheckCast(v8::Value* obj);
2091 };
2092 
2093 
2094 /**
2095  * A JavaScript symbol (ECMA-262 edition 6)
2096  *
2097  * This is an experimental feature. Use at your own risk.
2098  */
2099 class V8_EXPORT Symbol : public Name {
2100  public:
2101  // Returns the print name string of the symbol, or undefined if none.
2102  Local<Value> Name() const;
2103 
2104  // Create a symbol. If name is not empty, it will be used as the description.
2105  static Local<Symbol> New(
2106  Isolate *isolate, Local<String> name = Local<String>());
2107 
2108  // Access global symbol registry.
2109  // Note that symbols created this way are never collected, so
2110  // they should only be used for statically fixed properties.
2111  // Also, there is only one global name space for the names used as keys.
2112  // To minimize the potential for clashes, use qualified names as keys.
2113  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2114 
2115  // Retrieve a global symbol. Similar to |For|, but using a separate
2116  // registry that is not accessible by (and cannot clash with) JavaScript code.
2117  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2118 
2119  // Well-known symbols
2120  static Local<Symbol> GetIterator(Isolate* isolate);
2121  static Local<Symbol> GetUnscopables(Isolate* isolate);
2122 
2123  V8_INLINE static Symbol* Cast(v8::Value* obj);
2124 
2125  private:
2127  static void CheckCast(v8::Value* obj);
2128 };
2129 
2130 
2131 /**
2132  * A private symbol
2133  *
2134  * This is an experimental feature. Use at your own risk.
2135  */
2136 class V8_EXPORT Private : public Data {
2137  public:
2138  // Returns the print name string of the private symbol, or undefined if none.
2139  Local<Value> Name() const;
2140 
2141  // Create a private symbol. If name is not empty, it will be the description.
2142  static Local<Private> New(
2143  Isolate *isolate, Local<String> name = Local<String>());
2144 
2145  // Retrieve a global private symbol. If a symbol with this name has not
2146  // been retrieved in the same isolate before, it is created.
2147  // Note that private symbols created this way are never collected, so
2148  // they should only be used for statically fixed properties.
2149  // Also, there is only one global name space for the names used as keys.
2150  // To minimize the potential for clashes, use qualified names as keys,
2151  // e.g., "Class#property".
2152  static Local<Private> ForApi(Isolate *isolate, Local<String> name);
2153 
2154  private:
2156 };
2157 
2158 
2159 /**
2160  * A JavaScript number value (ECMA-262, 4.3.20)
2161  */
2162 class V8_EXPORT Number : public Primitive {
2163  public:
2164  double Value() const;
2165  static Local<Number> New(Isolate* isolate, double value);
2166  V8_INLINE static Number* Cast(v8::Value* obj);
2167  private:
2169  static void CheckCast(v8::Value* obj);
2170 };
2171 
2172 
2173 /**
2174  * A JavaScript value representing a signed integer.
2175  */
2176 class V8_EXPORT Integer : public Number {
2177  public:
2178  static Local<Integer> New(Isolate* isolate, int32_t value);
2179  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2180  int64_t Value() const;
2181  V8_INLINE static Integer* Cast(v8::Value* obj);
2182  private:
2184  static void CheckCast(v8::Value* obj);
2185 };
2186 
2187 
2188 /**
2189  * A JavaScript value representing a 32-bit signed integer.
2190  */
2191 class V8_EXPORT Int32 : public Integer {
2192  public:
2193  int32_t Value() const;
2194  private:
2196 };
2197 
2198 
2199 /**
2200  * A JavaScript value representing a 32-bit unsigned integer.
2201  */
2202 class V8_EXPORT Uint32 : public Integer {
2203  public:
2204  uint32_t Value() const;
2205  private:
2207 };
2208 
2209 
2211  None = 0,
2212  ReadOnly = 1 << 0,
2213  DontEnum = 1 << 1,
2214  DontDelete = 1 << 2
2215 };
2216 
2227 
2228  // Legacy constant names
2238 };
2239 
2240 /**
2241  * Accessor[Getter|Setter] are used as callback functions when
2242  * setting|getting a particular property. See Object and ObjectTemplate's
2243  * method SetAccessor.
2244  */
2245 typedef void (*AccessorGetterCallback)(
2246  Local<String> property,
2247  const PropertyCallbackInfo<Value>& info);
2249  Local<Name> property,
2250  const PropertyCallbackInfo<Value>& info);
2251 
2252 
2253 typedef void (*AccessorSetterCallback)(
2254  Local<String> property,
2255  Local<Value> value,
2256  const PropertyCallbackInfo<void>& info);
2258  Local<Name> property,
2259  Local<Value> value,
2260  const PropertyCallbackInfo<void>& info);
2261 
2262 
2263 /**
2264  * Access control specifications.
2265  *
2266  * Some accessors should be accessible across contexts. These
2267  * accessors have an explicit access control parameter which specifies
2268  * the kind of cross-context access that should be allowed.
2269  *
2270  * TODO(dcarney): Remove PROHIBITS_OVERWRITING as it is now unused.
2271  */
2273  DEFAULT = 0,
2275  ALL_CAN_WRITE = 1 << 1,
2276  PROHIBITS_OVERWRITING = 1 << 2
2277 };
2278 
2279 
2280 /**
2281  * A JavaScript object (ECMA-262, 4.3.3)
2282  */
2283 class V8_EXPORT Object : public Value {
2284  public:
2285  bool Set(Handle<Value> key, Handle<Value> value);
2286 
2287  bool Set(uint32_t index, Handle<Value> value);
2288 
2289  // Sets an own property on this object bypassing interceptors and
2290  // overriding accessors or read-only properties.
2291  //
2292  // Note that if the object has an interceptor the property will be set
2293  // locally, but since the interceptor takes precedence the local property
2294  // will only be returned if the interceptor doesn't return a value.
2295  //
2296  // Note also that this only works for named properties.
2297  bool ForceSet(Handle<Value> key,
2298  Handle<Value> value,
2299  PropertyAttribute attribs = None);
2300 
2301  Local<Value> Get(Handle<Value> key);
2302 
2303  Local<Value> Get(uint32_t index);
2304 
2305  /**
2306  * Gets the property attributes of a property which can be None or
2307  * any combination of ReadOnly, DontEnum and DontDelete. Returns
2308  * None when the property doesn't exist.
2309  */
2310  PropertyAttribute GetPropertyAttributes(Handle<Value> key);
2311 
2312  /**
2313  * Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
2314  */
2315  Local<Value> GetOwnPropertyDescriptor(Local<String> key);
2316 
2317  bool Has(Handle<Value> key);
2318 
2319  bool Delete(Handle<Value> key);
2320 
2321  // Delete a property on this object bypassing interceptors and
2322  // ignoring dont-delete attributes.
2323  bool ForceDelete(Handle<Value> key);
2324 
2325  bool Has(uint32_t index);
2326 
2327  bool Delete(uint32_t index);
2328 
2329  bool SetAccessor(Handle<String> name,
2330  AccessorGetterCallback getter,
2331  AccessorSetterCallback setter = 0,
2332  Handle<Value> data = Handle<Value>(),
2333  AccessControl settings = DEFAULT,
2334  PropertyAttribute attribute = None);
2335  bool SetAccessor(Handle<Name> name,
2337  AccessorNameSetterCallback setter = 0,
2338  Handle<Value> data = Handle<Value>(),
2339  AccessControl settings = DEFAULT,
2340  PropertyAttribute attribute = None);
2341 
2342  // This function is not yet stable and should not be used at this time.
2343  bool SetDeclaredAccessor(Local<Name> name,
2345  PropertyAttribute attribute = None,
2346  AccessControl settings = DEFAULT);
2347 
2348  void SetAccessorProperty(Local<Name> name,
2349  Local<Function> getter,
2351  PropertyAttribute attribute = None,
2352  AccessControl settings = DEFAULT);
2353 
2354  /**
2355  * Functionality for private properties.
2356  * This is an experimental feature, use at your own risk.
2357  * Note: Private properties are inherited. Do not rely on this, since it may
2358  * change.
2359  */
2360  bool HasPrivate(Handle<Private> key);
2361  bool SetPrivate(Handle<Private> key, Handle<Value> value);
2362  bool DeletePrivate(Handle<Private> key);
2363  Local<Value> GetPrivate(Handle<Private> key);
2364 
2365  /**
2366  * Returns an array containing the names of the enumerable properties
2367  * of this object, including properties from prototype objects. The
2368  * array returned by this method contains the same values as would
2369  * be enumerated by a for-in statement over this object.
2370  */
2371  Local<Array> GetPropertyNames();
2372 
2373  /**
2374  * This function has the same functionality as GetPropertyNames but
2375  * the returned array doesn't contain the names of properties from
2376  * prototype objects.
2377  */
2378  Local<Array> GetOwnPropertyNames();
2379 
2380  /**
2381  * Get the prototype object. This does not skip objects marked to
2382  * be skipped by __proto__ and it does not consult the security
2383  * handler.
2384  */
2385  Local<Value> GetPrototype();
2386 
2387  /**
2388  * Set the prototype object. This does not skip objects marked to
2389  * be skipped by __proto__ and it does not consult the security
2390  * handler.
2391  */
2392  bool SetPrototype(Handle<Value> prototype);
2393 
2394  /**
2395  * Finds an instance of the given function template in the prototype
2396  * chain.
2397  */
2398  Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl);
2399 
2400  /**
2401  * Call builtin Object.prototype.toString on this object.
2402  * This is different from Value::ToString() that may call
2403  * user-defined toString function. This one does not.
2404  */
2405  Local<String> ObjectProtoToString();
2406 
2407  /**
2408  * Returns the name of the function invoked as a constructor for this object.
2409  */
2410  Local<String> GetConstructorName();
2411 
2412  /** Gets the number of internal fields for this Object. */
2413  int InternalFieldCount();
2414 
2415  /** Same as above, but works for Persistents */
2417  const PersistentBase<Object>& object) {
2418  return object.val_->InternalFieldCount();
2419  }
2420 
2421  /** Gets the value from an internal field. */
2422  V8_INLINE Local<Value> GetInternalField(int index);
2423 
2424  /** Sets the value in an internal field. */
2425  void SetInternalField(int index, Handle<Value> value);
2426 
2427  /**
2428  * Gets a 2-byte-aligned native pointer from an internal field. This field
2429  * must have been set by SetAlignedPointerInInternalField, everything else
2430  * leads to undefined behavior.
2431  */
2432  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
2433 
2434  /** Same as above, but works for Persistents */
2436  const PersistentBase<Object>& object, int index) {
2437  return object.val_->GetAlignedPointerFromInternalField(index);
2438  }
2439 
2440  /**
2441  * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
2442  * a field, GetAlignedPointerFromInternalField must be used, everything else
2443  * leads to undefined behavior.
2444  */
2445  void SetAlignedPointerInInternalField(int index, void* value);
2446 
2447  // Testers for local properties.
2448  bool HasOwnProperty(Handle<String> key);
2449  bool HasRealNamedProperty(Handle<String> key);
2450  bool HasRealIndexedProperty(uint32_t index);
2451  bool HasRealNamedCallbackProperty(Handle<String> key);
2452 
2453  /**
2454  * If result.IsEmpty() no real property was located in the prototype chain.
2455  * This means interceptors in the prototype chain are not called.
2456  */
2457  Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
2458 
2459  /**
2460  * If result.IsEmpty() no real property was located on the object or
2461  * in the prototype chain.
2462  * This means interceptors in the prototype chain are not called.
2463  */
2464  Local<Value> GetRealNamedProperty(Handle<String> key);
2465 
2466  /** Tests for a named lookup interceptor.*/
2467  bool HasNamedLookupInterceptor();
2468 
2469  /** Tests for an index lookup interceptor.*/
2470  bool HasIndexedLookupInterceptor();
2471 
2472  /**
2473  * Turns on access check on the object if the object is an instance of
2474  * a template that has access check callbacks. If an object has no
2475  * access check info, the object cannot be accessed by anyone.
2476  */
2477  void TurnOnAccessCheck();
2478 
2479  /**
2480  * Returns the identity hash for this object. The current implementation
2481  * uses a hidden property on the object to store the identity hash.
2482  *
2483  * The return value will never be 0. Also, it is not guaranteed to be
2484  * unique.
2485  */
2486  int GetIdentityHash();
2487 
2488  /**
2489  * Access hidden properties on JavaScript objects. These properties are
2490  * hidden from the executing JavaScript and only accessible through the V8
2491  * C++ API. Hidden properties introduced by V8 internally (for example the
2492  * identity hash) are prefixed with "v8::".
2493  */
2494  bool SetHiddenValue(Handle<String> key, Handle<Value> value);
2495  Local<Value> GetHiddenValue(Handle<String> key);
2496  bool DeleteHiddenValue(Handle<String> key);
2497 
2498  /**
2499  * Returns true if this is an instance of an api function (one
2500  * created from a function created from a function template) and has
2501  * been modified since it was created. Note that this method is
2502  * conservative and may return true for objects that haven't actually
2503  * been modified.
2504  */
2505  bool IsDirty();
2506 
2507  /**
2508  * Clone this object with a fast but shallow copy. Values will point
2509  * to the same values as the original object.
2510  */
2511  Local<Object> Clone();
2512 
2513  /**
2514  * Returns the context in which the object was created.
2515  */
2516  Local<Context> CreationContext();
2517 
2518  /**
2519  * Set the backing store of the indexed properties to be managed by the
2520  * embedding layer. Access to the indexed properties will follow the rules
2521  * spelled out in CanvasPixelArray.
2522  * Note: The embedding program still owns the data and needs to ensure that
2523  * the backing store is preserved while V8 has a reference.
2524  */
2525  void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
2526  bool HasIndexedPropertiesInPixelData();
2527  uint8_t* GetIndexedPropertiesPixelData();
2528  int GetIndexedPropertiesPixelDataLength();
2529 
2530  /**
2531  * Set the backing store of the indexed properties to be managed by the
2532  * embedding layer. Access to the indexed properties will follow the rules
2533  * spelled out for the CanvasArray subtypes in the WebGL specification.
2534  * Note: The embedding program still owns the data and needs to ensure that
2535  * the backing store is preserved while V8 has a reference.
2536  */
2537  void SetIndexedPropertiesToExternalArrayData(void* data,
2538  ExternalArrayType array_type,
2539  int number_of_elements);
2540  bool HasIndexedPropertiesInExternalArrayData();
2541  void* GetIndexedPropertiesExternalArrayData();
2542  ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
2543  int GetIndexedPropertiesExternalArrayDataLength();
2544 
2545  /**
2546  * Checks whether a callback is set by the
2547  * ObjectTemplate::SetCallAsFunctionHandler method.
2548  * When an Object is callable this method returns true.
2549  */
2550  bool IsCallable();
2551 
2552  /**
2553  * Call an Object as a function if a callback is set by the
2554  * ObjectTemplate::SetCallAsFunctionHandler method.
2555  */
2556  Local<Value> CallAsFunction(Handle<Value> recv,
2557  int argc,
2558  Handle<Value> argv[]);
2559 
2560  /**
2561  * Call an Object as a constructor if a callback is set by the
2562  * ObjectTemplate::SetCallAsFunctionHandler method.
2563  * Note: This method behaves like the Function::NewInstance method.
2564  */
2565  Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]);
2566 
2567  static Local<Object> New(Isolate* isolate);
2568 
2569  V8_INLINE static Object* Cast(Value* obj);
2570 
2571  private:
2573  static void CheckCast(Value* obj);
2574  Local<Value> SlowGetInternalField(int index);
2575  void* SlowGetAlignedPointerFromInternalField(int index);
2576 };
2577 
2578 
2579 /**
2580  * An instance of the built-in array constructor (ECMA-262, 15.4.2).
2581  */
2582 class V8_EXPORT Array : public Object {
2583  public:
2584  uint32_t Length() const;
2585 
2586  /**
2587  * Clones an element at index |index|. Returns an empty
2588  * handle if cloning fails (for any reason).
2589  */
2590  Local<Object> CloneElementAt(uint32_t index);
2591 
2592  /**
2593  * Creates a JavaScript array with the given length. If the length
2594  * is negative the returned array will have length 0.
2595  */
2596  static Local<Array> New(Isolate* isolate, int length = 0);
2597 
2598  V8_INLINE static Array* Cast(Value* obj);
2599  private:
2601  static void CheckCast(Value* obj);
2602 };
2603 
2604 
2605 template<typename T>
2607  public:
2608  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
2609  : value_(that.value_) {
2610  TYPE_CHECK(T, S);
2611  }
2612  // Handle setters
2613  template <typename S> V8_INLINE void Set(const Persistent<S>& handle);
2614  template <typename S> V8_INLINE void Set(const Handle<S> handle);
2615  // Fast primitive setters
2616  V8_INLINE void Set(bool value);
2617  V8_INLINE void Set(double i);
2618  V8_INLINE void Set(int32_t i);
2619  V8_INLINE void Set(uint32_t i);
2620  // Fast JS primitive setters
2621  V8_INLINE void SetNull();
2622  V8_INLINE void SetUndefined();
2623  V8_INLINE void SetEmptyString();
2624  // Convenience getter for Isolate
2626 
2627  // Pointer setter: Uncompilable to prevent inadvertent misuse.
2628  template <typename S>
2629  V8_INLINE void Set(S* whatever);
2630 
2631  private:
2632  template<class F> friend class ReturnValue;
2633  template<class F> friend class FunctionCallbackInfo;
2634  template<class F> friend class PropertyCallbackInfo;
2635  template<class F, class G, class H> friend class PersistentValueMap;
2636  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
2638  V8_INLINE explicit ReturnValue(internal::Object** slot);
2640 };
2641 
2642 
2643 /**
2644  * The argument information given to function call callbacks. This
2645  * class provides access to information about the context of the call,
2646  * including the receiver, the number and values of arguments, and
2647  * the holder of the function.
2648  */
2649 template<typename T>
2651  public:
2652  V8_INLINE int Length() const;
2653  V8_INLINE Local<Value> operator[](int i) const;
2655  V8_INLINE Local<Object> This() const;
2656  V8_INLINE Local<Object> Holder() const;
2657  V8_INLINE bool IsConstructCall() const;
2658  V8_INLINE Local<Value> Data() const;
2659  V8_INLINE Isolate* GetIsolate() const;
2661  // This shouldn't be public, but the arm compiler needs it.
2662  static const int kArgsLength = 7;
2663 
2664  protected:
2667  static const int kHolderIndex = 0;
2668  static const int kIsolateIndex = 1;
2669  static const int kReturnValueDefaultValueIndex = 2;
2670  static const int kReturnValueIndex = 3;
2671  static const int kDataIndex = 4;
2672  static const int kCalleeIndex = 5;
2673  static const int kContextSaveIndex = 6;
2674 
2676  internal::Object** values,
2677  int length,
2678  bool is_construct_call);
2681  int length_;
2683 };
2684 
2685 
2686 /**
2687  * The information passed to a property callback about the context
2688  * of the property access.
2689  */
2690 template<typename T>
2692  public:
2693  V8_INLINE Isolate* GetIsolate() const;
2694  V8_INLINE Local<Value> Data() const;
2695  V8_INLINE Local<Object> This() const;
2696  V8_INLINE Local<Object> Holder() const;
2698  // This shouldn't be public, but the arm compiler needs it.
2699  static const int kArgsLength = 6;
2700 
2701  protected:
2702  friend class MacroAssembler;
2705  static const int kHolderIndex = 0;
2706  static const int kIsolateIndex = 1;
2707  static const int kReturnValueDefaultValueIndex = 2;
2708  static const int kReturnValueIndex = 3;
2709  static const int kDataIndex = 4;
2710  static const int kThisIndex = 5;
2711 
2714 };
2715 
2716 
2717 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
2718 
2719 
2720 /**
2721  * A JavaScript function object (ECMA-262, 15.3).
2722  */
2723 class V8_EXPORT Function : public Object {
2724  public:
2725  /**
2726  * Create a function in the current execution context
2727  * for a given FunctionCallback.
2728  */
2729  static Local<Function> New(Isolate* isolate,
2730  FunctionCallback callback,
2731  Local<Value> data = Local<Value>(),
2732  int length = 0);
2733 
2734  Local<Object> NewInstance() const;
2735  Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
2736  Local<Value> Call(Handle<Value> recv, int argc, Handle<Value> argv[]);
2737  void SetName(Handle<String> name);
2738  Handle<Value> GetName() const;
2739 
2740  /**
2741  * Name inferred from variable or property assignment of this function.
2742  * Used to facilitate debugging and profiling of JavaScript code written
2743  * in an OO style, where many functions are anonymous but are assigned
2744  * to object properties.
2745  */
2746  Handle<Value> GetInferredName() const;
2747 
2748  /**
2749  * User-defined name assigned to the "displayName" property of this function.
2750  * Used to facilitate debugging and profiling of JavaScript code.
2751  */
2752  Handle<Value> GetDisplayName() const;
2753 
2754  /**
2755  * Returns zero based line number of function body and
2756  * kLineOffsetNotFound if no information available.
2757  */
2758  int GetScriptLineNumber() const;
2759  /**
2760  * Returns zero based column number of function body and
2761  * kLineOffsetNotFound if no information available.
2762  */
2763  int GetScriptColumnNumber() const;
2764 
2765  /**
2766  * Tells whether this function is builtin.
2767  */
2768  bool IsBuiltin() const;
2769 
2770  /**
2771  * Returns scriptId.
2772  */
2773  int ScriptId() const;
2774 
2775  /**
2776  * Returns the original function if this function is bound, else returns
2777  * v8::Undefined.
2778  */
2779  Local<Value> GetBoundFunction() const;
2780 
2781  ScriptOrigin GetScriptOrigin() const;
2782  V8_INLINE static Function* Cast(Value* obj);
2783  static const int kLineOffsetNotFound;
2784 
2785  private:
2787  static void CheckCast(Value* obj);
2788 };
2789 
2790 
2791 /**
2792  * An instance of the built-in Promise constructor (ES6 draft).
2793  * This API is experimental. Only works with --harmony flag.
2794  */
2795 class V8_EXPORT Promise : public Object {
2796  public:
2797  class V8_EXPORT Resolver : public Object {
2798  public:
2799  /**
2800  * Create a new resolver, along with an associated promise in pending state.
2801  */
2802  static Local<Resolver> New(Isolate* isolate);
2803 
2804  /**
2805  * Extract the associated promise.
2806  */
2807  Local<Promise> GetPromise();
2808 
2809  /**
2810  * Resolve/reject the associated promise with a given value.
2811  * Ignored if the promise is no longer pending.
2812  */
2813  void Resolve(Handle<Value> value);
2814  void Reject(Handle<Value> value);
2815 
2816  V8_INLINE static Resolver* Cast(Value* obj);
2817 
2818  private:
2820  static void CheckCast(Value* obj);
2821  };
2822 
2823  /**
2824  * Register a resolution/rejection handler with a promise.
2825  * The handler is given the respective resolution/rejection value as
2826  * an argument. If the promise is already resolved/rejected, the handler is
2827  * invoked at the end of turn.
2828  */
2829  Local<Promise> Chain(Handle<Function> handler);
2830  Local<Promise> Catch(Handle<Function> handler);
2831  Local<Promise> Then(Handle<Function> handler);
2832 
2833  V8_INLINE static Promise* Cast(Value* obj);
2834 
2835  private:
2837  static void CheckCast(Value* obj);
2838 };
2839 
2840 
2841 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
2842 // The number of required internal fields can be defined by embedder.
2843 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
2844 #endif
2845 
2846 /**
2847  * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
2848  * This API is experimental and may change significantly.
2849  */
2850 class V8_EXPORT ArrayBuffer : public Object {
2851  public:
2852  /**
2853  * Allocator that V8 uses to allocate |ArrayBuffer|'s memory.
2854  * The allocator is a global V8 setting. It should be set with
2855  * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer.
2856  *
2857  * This API is experimental and may change significantly.
2858  */
2859  class V8_EXPORT Allocator { // NOLINT
2860  public:
2861  virtual ~Allocator() {}
2862 
2863  /**
2864  * Allocate |length| bytes. Return NULL if allocation is not successful.
2865  * Memory should be initialized to zeroes.
2866  */
2867  virtual void* Allocate(size_t length) = 0;
2868 
2869  /**
2870  * Allocate |length| bytes. Return NULL if allocation is not successful.
2871  * Memory does not have to be initialized.
2872  */
2873  virtual void* AllocateUninitialized(size_t length) = 0;
2874  /**
2875  * Free the memory block of size |length|, pointed to by |data|.
2876  * That memory is guaranteed to be previously allocated by |Allocate|.
2877  */
2878  virtual void Free(void* data, size_t length) = 0;
2879  };
2880 
2881  /**
2882  * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer|
2883  * returns an instance of this class, populated, with a pointer to data
2884  * and byte length.
2885  *
2886  * The Data pointer of ArrayBuffer::Contents is always allocated with
2887  * Allocator::Allocate that is set with V8::SetArrayBufferAllocator.
2888  *
2889  * This API is experimental and may change significantly.
2890  */
2891  class V8_EXPORT Contents { // NOLINT
2892  public:
2893  Contents() : data_(NULL), byte_length_(0) {}
2894 
2895  void* Data() const { return data_; }
2896  size_t ByteLength() const { return byte_length_; }
2897 
2898  private:
2899  void* data_;
2901 
2902  friend class ArrayBuffer;
2903  };
2904 
2905 
2906  /**
2907  * Data length in bytes.
2908  */
2909  size_t ByteLength() const;
2910 
2911  /**
2912  * Create a new ArrayBuffer. Allocate |byte_length| bytes.
2913  * Allocated memory will be owned by a created ArrayBuffer and
2914  * will be deallocated when it is garbage-collected,
2915  * unless the object is externalized.
2916  */
2917  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
2918 
2919  /**
2920  * Create a new ArrayBuffer over an existing memory block.
2921  * The created array buffer is immediately in externalized state.
2922  * The memory block will not be reclaimed when a created ArrayBuffer
2923  * is garbage-collected.
2924  */
2925  static Local<ArrayBuffer> New(Isolate* isolate, void* data,
2926  size_t byte_length);
2927 
2928  /**
2929  * Returns true if ArrayBuffer is extrenalized, that is, does not
2930  * own its memory block.
2931  */
2932  bool IsExternal() const;
2933 
2934  /**
2935  * Neuters this ArrayBuffer and all its views (typed arrays).
2936  * Neutering sets the byte length of the buffer and all typed arrays to zero,
2937  * preventing JavaScript from ever accessing underlying backing store.
2938  * ArrayBuffer should have been externalized.
2939  */
2940  void Neuter();
2941 
2942  /**
2943  * Make this ArrayBuffer external. The pointer to underlying memory block
2944  * and byte length are returned as |Contents| structure. After ArrayBuffer
2945  * had been etxrenalized, it does no longer owns the memory block. The caller
2946  * should take steps to free memory when it is no longer needed.
2947  *
2948  * The memory block is guaranteed to be allocated with |Allocator::Allocate|
2949  * that has been set with V8::SetArrayBufferAllocator.
2950  */
2951  Contents Externalize();
2952 
2953  V8_INLINE static ArrayBuffer* Cast(Value* obj);
2954 
2955  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
2956 
2957  private:
2959  static void CheckCast(Value* obj);
2960 };
2961 
2962 
2963 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
2964 // The number of required internal fields can be defined by embedder.
2965 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
2966 #endif
2967 
2968 
2969 /**
2970  * A base class for an instance of one of "views" over ArrayBuffer,
2971  * including TypedArrays and DataView (ES6 draft 15.13).
2972  *
2973  * This API is experimental and may change significantly.
2974  */
2976  public:
2977  /**
2978  * Returns underlying ArrayBuffer.
2979  */
2980  Local<ArrayBuffer> Buffer();
2981  /**
2982  * Byte offset in |Buffer|.
2983  */
2984  size_t ByteOffset();
2985  /**
2986  * Size of a view in bytes.
2987  */
2988  size_t ByteLength();
2989 
2990  V8_INLINE static ArrayBufferView* Cast(Value* obj);
2991 
2992  static const int kInternalFieldCount =
2994 
2995  private:
2997  static void CheckCast(Value* obj);
2998 };
2999 
3000 
3001 /**
3002  * A base class for an instance of TypedArray series of constructors
3003  * (ES6 draft 15.13.6).
3004  * This API is experimental and may change significantly.
3005  */
3007  public:
3008  /**
3009  * Number of elements in this typed array
3010  * (e.g. for Int16Array, |ByteLength|/2).
3011  */
3012  size_t Length();
3013 
3014  V8_INLINE static TypedArray* Cast(Value* obj);
3015 
3016  private:
3018  static void CheckCast(Value* obj);
3019 };
3020 
3021 
3022 /**
3023  * An instance of Uint8Array constructor (ES6 draft 15.13.6).
3024  * This API is experimental and may change significantly.
3025  */
3027  public:
3029  size_t byte_offset, size_t length);
3030  V8_INLINE static Uint8Array* Cast(Value* obj);
3031 
3032  private:
3034  static void CheckCast(Value* obj);
3035 };
3036 
3037 
3038 /**
3039  * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
3040  * This API is experimental and may change significantly.
3041  */
3043  public:
3045  size_t byte_offset, size_t length);
3046  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
3047 
3048  private:
3050  static void CheckCast(Value* obj);
3051 };
3052 
3053 /**
3054  * An instance of Int8Array constructor (ES6 draft 15.13.6).
3055  * This API is experimental and may change significantly.
3056  */
3058  public:
3060  size_t byte_offset, size_t length);
3061  V8_INLINE static Int8Array* Cast(Value* obj);
3062 
3063  private:
3065  static void CheckCast(Value* obj);
3066 };
3067 
3068 
3069 /**
3070  * An instance of Uint16Array constructor (ES6 draft 15.13.6).
3071  * This API is experimental and may change significantly.
3072  */
3074  public:
3076  size_t byte_offset, size_t length);
3077  V8_INLINE static Uint16Array* Cast(Value* obj);
3078 
3079  private:
3081  static void CheckCast(Value* obj);
3082 };
3083 
3084 
3085 /**
3086  * An instance of Int16Array constructor (ES6 draft 15.13.6).
3087  * This API is experimental and may change significantly.
3088  */
3090  public:
3092  size_t byte_offset, size_t length);
3093  V8_INLINE static Int16Array* Cast(Value* obj);
3094 
3095  private:
3097  static void CheckCast(Value* obj);
3098 };
3099 
3100 
3101 /**
3102  * An instance of Uint32Array constructor (ES6 draft 15.13.6).
3103  * This API is experimental and may change significantly.
3104  */
3106  public:
3108  size_t byte_offset, size_t length);
3109  V8_INLINE static Uint32Array* Cast(Value* obj);
3110 
3111  private:
3113  static void CheckCast(Value* obj);
3114 };
3115 
3116 
3117 /**
3118  * An instance of Int32Array constructor (ES6 draft 15.13.6).
3119  * This API is experimental and may change significantly.
3120  */
3122  public:
3124  size_t byte_offset, size_t length);
3125  V8_INLINE static Int32Array* Cast(Value* obj);
3126 
3127  private:
3129  static void CheckCast(Value* obj);
3130 };
3131 
3132 
3133 /**
3134  * An instance of Float32Array constructor (ES6 draft 15.13.6).
3135  * This API is experimental and may change significantly.
3136  */
3138  public:
3140  size_t byte_offset, size_t length);
3141  V8_INLINE static Float32Array* Cast(Value* obj);
3142 
3143  private:
3145  static void CheckCast(Value* obj);
3146 };
3147 
3148 
3149 /**
3150  * An instance of Float64Array constructor (ES6 draft 15.13.6).
3151  * This API is experimental and may change significantly.
3152  */
3154  public:
3156  size_t byte_offset, size_t length);
3157  V8_INLINE static Float64Array* Cast(Value* obj);
3158 
3159  private:
3161  static void CheckCast(Value* obj);
3162 };
3163 
3164 
3165 /**
3166  * An instance of DataView constructor (ES6 draft 15.13.7).
3167  * This API is experimental and may change significantly.
3168  */
3170  public:
3171  static Local<DataView> New(Handle<ArrayBuffer> array_buffer,
3172  size_t byte_offset, size_t length);
3173  V8_INLINE static DataView* Cast(Value* obj);
3174 
3175  private:
3177  static void CheckCast(Value* obj);
3178 };
3179 
3180 
3181 /**
3182  * An instance of the built-in Date constructor (ECMA-262, 15.9).
3183  */
3184 class V8_EXPORT Date : public Object {
3185  public:
3186  static Local<Value> New(Isolate* isolate, double time);
3187 
3188  /**
3189  * A specialization of Value::NumberValue that is more efficient
3190  * because we know the structure of this object.
3191  */
3192  double ValueOf() const;
3193 
3194  V8_INLINE static Date* Cast(v8::Value* obj);
3195 
3196  /**
3197  * Notification that the embedder has changed the time zone,
3198  * daylight savings time, or other date / time configuration
3199  * parameters. V8 keeps a cache of various values used for
3200  * date / time computation. This notification will reset
3201  * those cached values for the current context so that date /
3202  * time configuration changes would be reflected in the Date
3203  * object.
3204  *
3205  * This API should not be called more than needed as it will
3206  * negatively impact the performance of date operations.
3207  */
3208  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
3209 
3210  private:
3211  static void CheckCast(v8::Value* obj);
3212 };
3213 
3214 
3215 /**
3216  * A Number object (ECMA-262, 4.3.21).
3217  */
3219  public:
3220  static Local<Value> New(Isolate* isolate, double value);
3221 
3222  double ValueOf() const;
3223 
3224  V8_INLINE static NumberObject* Cast(v8::Value* obj);
3225 
3226  private:
3227  static void CheckCast(v8::Value* obj);
3228 };
3229 
3230 
3231 /**
3232  * A Boolean object (ECMA-262, 4.3.15).
3233  */
3235  public:
3236  static Local<Value> New(bool value);
3237 
3238  bool ValueOf() const;
3239 
3240  V8_INLINE static BooleanObject* Cast(v8::Value* obj);
3241 
3242  private:
3243  static void CheckCast(v8::Value* obj);
3244 };
3245 
3246 
3247 /**
3248  * A String object (ECMA-262, 4.3.18).
3249  */
3251  public:
3252  static Local<Value> New(Handle<String> value);
3253 
3254  Local<String> ValueOf() const;
3255 
3256  V8_INLINE static StringObject* Cast(v8::Value* obj);
3257 
3258  private:
3259  static void CheckCast(v8::Value* obj);
3260 };
3261 
3262 
3263 /**
3264  * A Symbol object (ECMA-262 edition 6).
3265  *
3266  * This is an experimental feature. Use at your own risk.
3267  */
3269  public:
3270  static Local<Value> New(Isolate* isolate, Handle<Symbol> value);
3271 
3272  Local<Symbol> ValueOf() const;
3273 
3274  V8_INLINE static SymbolObject* Cast(v8::Value* obj);
3275 
3276  private:
3277  static void CheckCast(v8::Value* obj);
3278 };
3279 
3280 
3281 /**
3282  * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
3283  */
3284 class V8_EXPORT RegExp : public Object {
3285  public:
3286  /**
3287  * Regular expression flag bits. They can be or'ed to enable a set
3288  * of flags.
3289  */
3290  enum Flags {
3291  kNone = 0,
3292  kGlobal = 1,
3293  kIgnoreCase = 2,
3294  kMultiline = 4
3295  };
3296 
3297  /**
3298  * Creates a regular expression from the given pattern string and
3299  * the flags bit field. May throw a JavaScript exception as
3300  * described in ECMA-262, 15.10.4.1.
3301  *
3302  * For example,
3303  * RegExp::New(v8::String::New("foo"),
3304  * static_cast<RegExp::Flags>(kGlobal | kMultiline))
3305  * is equivalent to evaluating "/foo/gm".
3306  */
3307  static Local<RegExp> New(Handle<String> pattern, Flags flags);
3308 
3309  /**
3310  * Returns the value of the source property: a string representing
3311  * the regular expression.
3312  */
3313  Local<String> GetSource() const;
3314 
3315  /**
3316  * Returns the flags bit field.
3317  */
3318  Flags GetFlags() const;
3319 
3320  V8_INLINE static RegExp* Cast(v8::Value* obj);
3321 
3322  private:
3323  static void CheckCast(v8::Value* obj);
3324 };
3325 
3326 
3327 /**
3328  * A JavaScript value that wraps a C++ void*. This type of value is mainly used
3329  * to associate C++ data structures with JavaScript objects.
3330  */
3331 class V8_EXPORT External : public Value {
3332  public:
3333  static Local<External> New(Isolate* isolate, void* value);
3334  V8_INLINE static External* Cast(Value* obj);
3335  void* Value() const;
3336  private:
3337  static void CheckCast(v8::Value* obj);
3338 };
3339 
3340 
3341 // --- Templates ---
3342 
3343 
3344 /**
3345  * The superclass of object and function templates.
3346  */
3347 class V8_EXPORT Template : public Data {
3348  public:
3349  /** Adds a property to each instance created by this template.*/
3350  void Set(Handle<Name> name, Handle<Data> value,
3351  PropertyAttribute attributes = None);
3352  V8_INLINE void Set(Isolate* isolate, const char* name, Handle<Data> value);
3353 
3354  void SetAccessorProperty(
3355  Local<Name> name,
3358  PropertyAttribute attribute = None,
3359  AccessControl settings = DEFAULT);
3360 
3361  /**
3362  * Whenever the property with the given name is accessed on objects
3363  * created from this Template the getter and setter callbacks
3364  * are called instead of getting and setting the property directly
3365  * on the JavaScript object.
3366  *
3367  * \param name The name of the property for which an accessor is added.
3368  * \param getter The callback to invoke when getting the property.
3369  * \param setter The callback to invoke when setting the property.
3370  * \param data A piece of data that will be passed to the getter and setter
3371  * callbacks whenever they are invoked.
3372  * \param settings Access control settings for the accessor. This is a bit
3373  * field consisting of one of more of
3374  * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
3375  * The default is to not allow cross-context access.
3376  * ALL_CAN_READ means that all cross-context reads are allowed.
3377  * ALL_CAN_WRITE means that all cross-context writes are allowed.
3378  * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
3379  * cross-context access.
3380  * \param attribute The attributes of the property for which an accessor
3381  * is added.
3382  * \param signature The signature describes valid receivers for the accessor
3383  * and is used to perform implicit instance checks against them. If the
3384  * receiver is incompatible (i.e. is not an instance of the constructor as
3385  * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
3386  * thrown and no callback is invoked.
3387  */
3388  void SetNativeDataProperty(Local<String> name,
3389  AccessorGetterCallback getter,
3390  AccessorSetterCallback setter = 0,
3391  // TODO(dcarney): gcc can't handle Local below
3392  Handle<Value> data = Handle<Value>(),
3393  PropertyAttribute attribute = None,
3394  Local<AccessorSignature> signature =
3396  AccessControl settings = DEFAULT);
3397  void SetNativeDataProperty(Local<Name> name,
3399  AccessorNameSetterCallback setter = 0,
3400  // TODO(dcarney): gcc can't handle Local below
3401  Handle<Value> data = Handle<Value>(),
3402  PropertyAttribute attribute = None,
3403  Local<AccessorSignature> signature =
3405  AccessControl settings = DEFAULT);
3406 
3407  // This function is not yet stable and should not be used at this time.
3408  bool SetDeclaredAccessor(Local<Name> name,
3410  PropertyAttribute attribute = None,
3411  Local<AccessorSignature> signature =
3413  AccessControl settings = DEFAULT);
3414 
3415  private:
3417 
3418  friend class ObjectTemplate;
3419  friend class FunctionTemplate;
3420 };
3421 
3422 
3423 /**
3424  * NamedProperty[Getter|Setter] are used as interceptors on object.
3425  * See ObjectTemplate::SetNamedPropertyHandler.
3426  */
3428  Local<String> property,
3429  const PropertyCallbackInfo<Value>& info);
3430 
3431 
3432 /**
3433  * Returns the value if the setter intercepts the request.
3434  * Otherwise, returns an empty handle.
3435  */
3437  Local<String> property,
3438  Local<Value> value,
3439  const PropertyCallbackInfo<Value>& info);
3440 
3441 
3442 /**
3443  * Returns a non-empty handle if the interceptor intercepts the request.
3444  * The result is an integer encoding property attributes (like v8::None,
3445  * v8::DontEnum, etc.)
3446  */
3448  Local<String> property,
3449  const PropertyCallbackInfo<Integer>& info);
3450 
3451 
3452 /**
3453  * Returns a non-empty handle if the deleter intercepts the request.
3454  * The return value is true if the property could be deleted and false
3455  * otherwise.
3456  */
3458  Local<String> property,
3459  const PropertyCallbackInfo<Boolean>& info);
3460 
3461 
3462 /**
3463  * Returns an array containing the names of the properties the named
3464  * property getter intercepts.
3465  */
3467  const PropertyCallbackInfo<Array>& info);
3468 
3469 
3470 /**
3471  * Returns the value of the property if the getter intercepts the
3472  * request. Otherwise, returns an empty handle.
3473  */
3475  uint32_t index,
3476  const PropertyCallbackInfo<Value>& info);
3477 
3478 
3479 /**
3480  * Returns the value if the setter intercepts the request.
3481  * Otherwise, returns an empty handle.
3482  */
3484  uint32_t index,
3485  Local<Value> value,
3486  const PropertyCallbackInfo<Value>& info);
3487 
3488 
3489 /**
3490  * Returns a non-empty handle if the interceptor intercepts the request.
3491  * The result is an integer encoding property attributes.
3492  */
3494  uint32_t index,
3495  const PropertyCallbackInfo<Integer>& info);
3496 
3497 
3498 /**
3499  * Returns a non-empty handle if the deleter intercepts the request.
3500  * The return value is true if the property could be deleted and false
3501  * otherwise.
3502  */
3504  uint32_t index,
3505  const PropertyCallbackInfo<Boolean>& info);
3506 
3507 
3508 /**
3509  * Returns an array containing the indices of the properties the
3510  * indexed property getter intercepts.
3511  */
3513  const PropertyCallbackInfo<Array>& info);
3514 
3515 
3516 /**
3517  * Access type specification.
3518  */
3524  ACCESS_KEYS
3525 };
3526 
3527 
3528 /**
3529  * Returns true if cross-context access should be allowed to the named
3530  * property with the given key on the host object.
3531  */
3533  Local<Value> key,
3534  AccessType type,
3535  Local<Value> data);
3536 
3537 
3538 /**
3539  * Returns true if cross-context access should be allowed to the indexed
3540  * property with the given index on the host object.
3541  */
3543  uint32_t index,
3544  AccessType type,
3545  Local<Value> data);
3546 
3547 
3548 /**
3549  * A FunctionTemplate is used to create functions at runtime. There
3550  * can only be one function created from a FunctionTemplate in a
3551  * context. The lifetime of the created function is equal to the
3552  * lifetime of the context. So in case the embedder needs to create
3553  * temporary functions that can be collected using Scripts is
3554  * preferred.
3555  *
3556  * A FunctionTemplate can have properties, these properties are added to the
3557  * function object when it is created.
3558  *
3559  * A FunctionTemplate has a corresponding instance template which is
3560  * used to create object instances when the function is used as a
3561  * constructor. Properties added to the instance template are added to
3562  * each object instance.
3563  *
3564  * A FunctionTemplate can have a prototype template. The prototype template
3565  * is used to create the prototype object of the function.
3566  *
3567  * The following example shows how to use a FunctionTemplate:
3568  *
3569  * \code
3570  * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
3571  * t->Set("func_property", v8::Number::New(1));
3572  *
3573  * v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
3574  * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
3575  * proto_t->Set("proto_const", v8::Number::New(2));
3576  *
3577  * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
3578  * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
3579  * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
3580  * instance_t->Set("instance_property", Number::New(3));
3581  *
3582  * v8::Local<v8::Function> function = t->GetFunction();
3583  * v8::Local<v8::Object> instance = function->NewInstance();
3584  * \endcode
3585  *
3586  * Let's use "function" as the JS variable name of the function object
3587  * and "instance" for the instance object created above. The function
3588  * and the instance will have the following properties:
3589  *
3590  * \code
3591  * func_property in function == true;
3592  * function.func_property == 1;
3593  *
3594  * function.prototype.proto_method() invokes 'InvokeCallback'
3595  * function.prototype.proto_const == 2;
3596  *
3597  * instance instanceof function == true;
3598  * instance.instance_accessor calls 'InstanceAccessorCallback'
3599  * instance.instance_property == 3;
3600  * \endcode
3601  *
3602  * A FunctionTemplate can inherit from another one by calling the
3603  * FunctionTemplate::Inherit method. The following graph illustrates
3604  * the semantics of inheritance:
3605  *
3606  * \code
3607  * FunctionTemplate Parent -> Parent() . prototype -> { }
3608  * ^ ^
3609  * | Inherit(Parent) | .__proto__
3610  * | |
3611  * FunctionTemplate Child -> Child() . prototype -> { }
3612  * \endcode
3613  *
3614  * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
3615  * object of the Child() function has __proto__ pointing to the
3616  * Parent() function's prototype object. An instance of the Child
3617  * function has all properties on Parent's instance templates.
3618  *
3619  * Let Parent be the FunctionTemplate initialized in the previous
3620  * section and create a Child FunctionTemplate by:
3621  *
3622  * \code
3623  * Local<FunctionTemplate> parent = t;
3624  * Local<FunctionTemplate> child = FunctionTemplate::New();
3625  * child->Inherit(parent);
3626  *
3627  * Local<Function> child_function = child->GetFunction();
3628  * Local<Object> child_instance = child_function->NewInstance();
3629  * \endcode
3630  *
3631  * The Child function and Child instance will have the following
3632  * properties:
3633  *
3634  * \code
3635  * child_func.prototype.__proto__ == function.prototype;
3636  * child_instance.instance_accessor calls 'InstanceAccessorCallback'
3637  * child_instance.instance_property == 3;
3638  * \endcode
3639  */
3641  public:
3642  /** Creates a function template.*/
3643  static Local<FunctionTemplate> New(
3644  Isolate* isolate,
3645  FunctionCallback callback = 0,
3646  Handle<Value> data = Handle<Value>(),
3647  Handle<Signature> signature = Handle<Signature>(),
3648  int length = 0);
3649 
3650  /** Returns the unique function instance in the current execution context.*/
3651  Local<Function> GetFunction();
3652 
3653  /**
3654  * Set the call-handler callback for a FunctionTemplate. This
3655  * callback is called whenever the function created from this
3656  * FunctionTemplate is called.
3657  */
3658  void SetCallHandler(FunctionCallback callback,
3659  Handle<Value> data = Handle<Value>());
3660 
3661  /** Set the predefined length property for the FunctionTemplate. */
3662  void SetLength(int length);
3663 
3664  /** Get the InstanceTemplate. */
3665  Local<ObjectTemplate> InstanceTemplate();
3666 
3667  /** Causes the function template to inherit from a parent function template.*/
3668  void Inherit(Handle<FunctionTemplate> parent);
3669 
3670  /**
3671  * A PrototypeTemplate is the template used to create the prototype object
3672  * of the function created by this template.
3673  */
3674  Local<ObjectTemplate> PrototypeTemplate();
3675 
3676  /**
3677  * Set the class name of the FunctionTemplate. This is used for
3678  * printing objects created with the function created from the
3679  * FunctionTemplate as its constructor.
3680  */
3681  void SetClassName(Handle<String> name);
3682 
3683  /**
3684  * Determines whether the __proto__ accessor ignores instances of
3685  * the function template. If instances of the function template are
3686  * ignored, __proto__ skips all instances and instead returns the
3687  * next object in the prototype chain.
3688  *
3689  * Call with a value of true to make the __proto__ accessor ignore
3690  * instances of the function template. Call with a value of false
3691  * to make the __proto__ accessor not ignore instances of the
3692  * function template. By default, instances of a function template
3693  * are not ignored.
3694  */
3695  void SetHiddenPrototype(bool value);
3696 
3697  /**
3698  * Sets the ReadOnly flag in the attributes of the 'prototype' property
3699  * of functions created from this FunctionTemplate to true.
3700  */
3701  void ReadOnlyPrototype();
3702 
3703  /**
3704  * Removes the prototype property from functions created from this
3705  * FunctionTemplate.
3706  */
3707  void RemovePrototype();
3708 
3709  /**
3710  * Returns true if the given object is an instance of this function
3711  * template.
3712  */
3713  bool HasInstance(Handle<Value> object);
3714 
3715  private:
3717  friend class Context;
3718  friend class ObjectTemplate;
3719 };
3720 
3721 
3722 /**
3723  * An ObjectTemplate is used to create objects at runtime.
3724  *
3725  * Properties added to an ObjectTemplate are added to each object
3726  * created from the ObjectTemplate.
3727  */
3729  public:
3730  /** Creates an ObjectTemplate. */
3731  static Local<ObjectTemplate> New(Isolate* isolate);
3732  // Will be deprecated soon.
3733  static Local<ObjectTemplate> New();
3734 
3735  /** Creates a new instance of this template.*/
3736  Local<Object> NewInstance();
3737 
3738  /**
3739  * Sets an accessor on the object template.
3740  *
3741  * Whenever the property with the given name is accessed on objects
3742  * created from this ObjectTemplate the getter and setter callbacks
3743  * are called instead of getting and setting the property directly
3744  * on the JavaScript object.
3745  *
3746  * \param name The name of the property for which an accessor is added.
3747  * \param getter The callback to invoke when getting the property.
3748  * \param setter The callback to invoke when setting the property.
3749  * \param data A piece of data that will be passed to the getter and setter
3750  * callbacks whenever they are invoked.
3751  * \param settings Access control settings for the accessor. This is a bit
3752  * field consisting of one of more of
3753  * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
3754  * The default is to not allow cross-context access.
3755  * ALL_CAN_READ means that all cross-context reads are allowed.
3756  * ALL_CAN_WRITE means that all cross-context writes are allowed.
3757  * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
3758  * cross-context access.
3759  * \param attribute The attributes of the property for which an accessor
3760  * is added.
3761  * \param signature The signature describes valid receivers for the accessor
3762  * and is used to perform implicit instance checks against them. If the
3763  * receiver is incompatible (i.e. is not an instance of the constructor as
3764  * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
3765  * thrown and no callback is invoked.
3766  */
3767  void SetAccessor(Handle<String> name,
3768  AccessorGetterCallback getter,
3769  AccessorSetterCallback setter = 0,
3770  Handle<Value> data = Handle<Value>(),
3771  AccessControl settings = DEFAULT,
3772  PropertyAttribute attribute = None,
3773  Handle<AccessorSignature> signature =
3775  void SetAccessor(Handle<Name> name,
3777  AccessorNameSetterCallback setter = 0,
3778  Handle<Value> data = Handle<Value>(),
3779  AccessControl settings = DEFAULT,
3780  PropertyAttribute attribute = None,
3781  Handle<AccessorSignature> signature =
3783 
3784  /**
3785  * Sets a named property handler on the object template.
3786  *
3787  * Whenever a property whose name is a string is accessed on objects created
3788  * from this object template, the provided callback is invoked instead of
3789  * accessing the property directly on the JavaScript object.
3790  *
3791  * \param getter The callback to invoke when getting a property.
3792  * \param setter The callback to invoke when setting a property.
3793  * \param query The callback to invoke to check if a property is present,
3794  * and if present, get its attributes.
3795  * \param deleter The callback to invoke when deleting a property.
3796  * \param enumerator The callback to invoke to enumerate all the named
3797  * properties of an object.
3798  * \param data A piece of data that will be passed to the callbacks
3799  * whenever they are invoked.
3800  */
3801  void SetNamedPropertyHandler(
3803  NamedPropertySetterCallback setter = 0,
3804  NamedPropertyQueryCallback query = 0,
3805  NamedPropertyDeleterCallback deleter = 0,
3806  NamedPropertyEnumeratorCallback enumerator = 0,
3807  Handle<Value> data = Handle<Value>());
3808 
3809  /**
3810  * Sets an indexed property handler on the object template.
3811  *
3812  * Whenever an indexed property is accessed on objects created from
3813  * this object template, the provided callback is invoked instead of
3814  * accessing the property directly on the JavaScript object.
3815  *
3816  * \param getter The callback to invoke when getting a property.
3817  * \param setter The callback to invoke when setting a property.
3818  * \param query The callback to invoke to check if an object has a property.
3819  * \param deleter The callback to invoke when deleting a property.
3820  * \param enumerator The callback to invoke to enumerate all the indexed
3821  * properties of an object.
3822  * \param data A piece of data that will be passed to the callbacks
3823  * whenever they are invoked.
3824  */
3825  void SetIndexedPropertyHandler(
3827  IndexedPropertySetterCallback setter = 0,
3828  IndexedPropertyQueryCallback query = 0,
3829  IndexedPropertyDeleterCallback deleter = 0,
3830  IndexedPropertyEnumeratorCallback enumerator = 0,
3831  Handle<Value> data = Handle<Value>());
3832 
3833  /**
3834  * Sets the callback to be used when calling instances created from
3835  * this template as a function. If no callback is set, instances
3836  * behave like normal JavaScript objects that cannot be called as a
3837  * function.
3838  */
3839  void SetCallAsFunctionHandler(FunctionCallback callback,
3840  Handle<Value> data = Handle<Value>());
3841 
3842  /**
3843  * Mark object instances of the template as undetectable.
3844  *
3845  * In many ways, undetectable objects behave as though they are not
3846  * there. They behave like 'undefined' in conditionals and when
3847  * printed. However, properties can be accessed and called as on
3848  * normal objects.
3849  */
3850  void MarkAsUndetectable();
3851 
3852  /**
3853  * Sets access check callbacks on the object template.
3854  *
3855  * When accessing properties on instances of this object template,
3856  * the access check callback will be called to determine whether or
3857  * not to allow cross-context access to the properties.
3858  * The last parameter specifies whether access checks are turned
3859  * on by default on instances. If access checks are off by default,
3860  * they can be turned on on individual instances by calling
3861  * Object::TurnOnAccessCheck().
3862  */
3863  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
3864  IndexedSecurityCallback indexed_handler,
3865  Handle<Value> data = Handle<Value>(),
3866  bool turned_on_by_default = true);
3867 
3868  /**
3869  * Gets the number of internal fields for objects generated from
3870  * this template.
3871  */
3872  int InternalFieldCount();
3873 
3874  /**
3875  * Sets the number of internal fields for objects generated from
3876  * this template.
3877  */
3878  void SetInternalFieldCount(int value);
3879 
3880  private:
3882  static Local<ObjectTemplate> New(internal::Isolate* isolate,
3883  Handle<FunctionTemplate> constructor);
3884  friend class FunctionTemplate;
3885 };
3886 
3887 
3888 /**
3889  * A Signature specifies which receivers and arguments are valid
3890  * parameters to a function.
3891  */
3892 class V8_EXPORT Signature : public Data {
3893  public:
3894  static Local<Signature> New(Isolate* isolate,
3895  Handle<FunctionTemplate> receiver =
3897  int argc = 0,
3898  Handle<FunctionTemplate> argv[] = 0);
3899 
3900  private:
3902 };
3903 
3904 
3905 /**
3906  * An AccessorSignature specifies which receivers are valid parameters
3907  * to an accessor callback.
3908  */
3910  public:
3911  static Local<AccessorSignature> New(Isolate* isolate,
3912  Handle<FunctionTemplate> receiver =
3914 
3915  private:
3917 };
3918 
3919 
3921  private:
3923 };
3924 
3925 
3927  public:
3928  // This function is not yet stable and should not be used at this time.
3929  static Local<RawOperationDescriptor> NewInternalFieldDereference(
3930  Isolate* isolate,
3931  int internal_field);
3932  private:
3934 };
3935 
3936 
3943 };
3944 
3945 
3947  public:
3948  Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate);
3949  Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate);
3950  Local<RawOperationDescriptor> NewRawShift(Isolate* isolate,
3951  int16_t byte_offset);
3952  Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate,
3953  void* compare_value);
3954  Local<DeclaredAccessorDescriptor> NewPrimitiveValue(
3955  Isolate* isolate,
3957  uint8_t bool_offset = 0);
3958  Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate,
3959  uint8_t bitmask,
3960  uint8_t compare_value);
3961  Local<DeclaredAccessorDescriptor> NewBitmaskCompare16(
3962  Isolate* isolate,
3963  uint16_t bitmask,
3964  uint16_t compare_value);
3965  Local<DeclaredAccessorDescriptor> NewBitmaskCompare32(
3966  Isolate* isolate,
3967  uint32_t bitmask,
3968  uint32_t compare_value);
3969 
3970  private:
3972 };
3973 
3974 
3975 /**
3976  * A utility for determining the type of objects based on the template
3977  * they were constructed from.
3978  */
3979 class V8_EXPORT TypeSwitch : public Data {
3980  public:
3982  static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
3983  int match(Handle<Value> value);
3984  private:
3986 };
3987 
3988 
3989 // --- Extensions ---
3990 
3993  public:
3994  ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
3995  ExternalOneByteStringResourceImpl(const char* data, size_t length)
3996  : data_(data), length_(length) {}
3997  const char* data() const { return data_; }
3998  size_t length() const { return length_; }
3999 
4000  private:
4001  const char* data_;
4002  size_t length_;
4003 };
4004 
4005 /**
4006  * Ignore
4007  */
4008 class V8_EXPORT Extension { // NOLINT
4009  public:
4010  // Note that the strings passed into this constructor must live as long
4011  // as the Extension itself.
4012  Extension(const char* name,
4013  const char* source = 0,
4014  int dep_count = 0,
4015  const char** deps = 0,
4016  int source_length = -1);
4017  virtual ~Extension() { }
4021  }
4022 
4023  const char* name() const { return name_; }
4024  size_t source_length() const { return source_length_; }
4026  return &source_; }
4027  int dependency_count() { return dep_count_; }
4028  const char** dependencies() { return deps_; }
4029  void set_auto_enable(bool value) { auto_enable_ = value; }
4030  bool auto_enable() { return auto_enable_; }
4031 
4032  private:
4033  const char* name_;
4034  size_t source_length_; // expected to initialize before source_
4037  const char** deps_;
4039 
4040  // Disallow copying and assigning.
4042  void operator=(const Extension&);
4043 };
4044 
4045 
4046 void V8_EXPORT RegisterExtension(Extension* extension);
4047 
4048 
4049 // --- Statics ---
4050 
4055 
4056 
4057 /**
4058  * A set of constraints that specifies the limits of the runtime's memory use.
4059  * You must set the heap size before initializing the VM - the size cannot be
4060  * adjusted after the VM is initialized.
4061  *
4062  * If you are using threads then you should hold the V8::Locker lock while
4063  * setting the stack limit and you must set a non-default stack limit separately
4064  * for each thread.
4065  */
4067  public:
4069 
4070  /**
4071  * Configures the constraints with reasonable default values based on the
4072  * capabilities of the current device the VM is running on.
4073  *
4074  * \param physical_memory The total amount of physical memory on the current
4075  * device, in bytes.
4076  * \param virtual_memory_limit The amount of virtual memory on the current
4077  * device, in bytes, or zero, if there is no limit.
4078  * \param number_of_processors The number of CPUs available on the current
4079  * device.
4080  */
4081  void ConfigureDefaults(uint64_t physical_memory,
4082  uint64_t virtual_memory_limit,
4083  uint32_t number_of_processors);
4084 
4085  int max_semi_space_size() const { return max_semi_space_size_; }
4086  void set_max_semi_space_size(int value) { max_semi_space_size_ = value; }
4087  int max_old_space_size() const { return max_old_space_size_; }
4088  void set_max_old_space_size(int value) { max_old_space_size_ = value; }
4089  int max_executable_size() const { return max_executable_size_; }
4090  void set_max_executable_size(int value) { max_executable_size_ = value; }
4091  uint32_t* stack_limit() const { return stack_limit_; }
4092  // Sets an address beyond which the VM's stack may not grow.
4093  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
4094  int max_available_threads() const { return max_available_threads_; }
4095  // Set the number of threads available to V8, assuming at least 1.
4096  void set_max_available_threads(int value) {
4097  max_available_threads_ = value;
4098  }
4099  size_t code_range_size() const { return code_range_size_; }
4100  void set_code_range_size(size_t value) {
4101  code_range_size_ = value;
4102  }
4103 
4104  private:
4111 };
4112 
4113 
4114 // --- Exceptions ---
4115 
4116 
4117 typedef void (*FatalErrorCallback)(const char* location, const char* message);
4118 
4119 
4120 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error);
4121 
4122 // --- Tracing ---
4123 
4124 typedef void (*LogEventCallback)(const char* name, int event);
4125 
4126 /**
4127  * Create new error objects by calling the corresponding error object
4128  * constructor with the message.
4129  */
4131  public:
4137 };
4138 
4139 
4140 // --- Counters Callbacks ---
4141 
4142 typedef int* (*CounterLookupCallback)(const char* name);
4143 
4144 typedef void* (*CreateHistogramCallback)(const char* name,
4145  int min,
4146  int max,
4147  size_t buckets);
4148 
4149 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
4150 
4151 // --- Memory Allocation Callback ---
4159 
4163  };
4164 
4169  };
4170 
4172  AllocationAction action,
4173  int size);
4174 
4175 // --- Leave Script Callback ---
4176 typedef void (*CallCompletedCallback)();
4177 
4178 // --- Microtask Callback ---
4179 typedef void (*MicrotaskCallback)(void* data);
4180 
4181 // --- Failed Access Check Callback ---
4183  AccessType type,
4184  Local<Value> data);
4185 
4186 // --- AllowCodeGenerationFromStrings callbacks ---
4187 
4188 /**
4189  * Callback to check if code generation from strings is allowed. See
4190  * Context::AllowCodeGenerationFromStrings.
4191  */
4193 
4194 // --- Garbage Collection Callbacks ---
4195 
4196 /**
4197  * Applications can register callback functions which will be called
4198  * before and after a garbage collection. Allocations are not
4199  * allowed in the callback functions, you therefore cannot manipulate
4200  * objects (set or delete properties for example) since it is possible
4201  * such operations will result in the allocation of objects.
4202  */
4203 enum GCType {
4207 };
4208 
4213  kGCCallbackFlagForced = 1 << 2
4214 };
4215 
4218 
4219 typedef void (*InterruptCallback)(Isolate* isolate, void* data);
4220 
4221 
4222 /**
4223  * Collection of V8 heap information.
4224  *
4225  * Instances of this class can be passed to v8::V8::HeapStatistics to
4226  * get heap statistics from V8.
4227  */
4229  public:
4230  HeapStatistics();
4231  size_t total_heap_size() { return total_heap_size_; }
4232  size_t total_heap_size_executable() { return total_heap_size_executable_; }
4233  size_t total_physical_size() { return total_physical_size_; }
4234  size_t used_heap_size() { return used_heap_size_; }
4235  size_t heap_size_limit() { return heap_size_limit_; }
4236 
4237  private:
4243 
4244  friend class V8;
4245  friend class Isolate;
4246 };
4247 
4248 
4249 class RetainedObjectInfo;
4250 
4251 
4252 /**
4253  * FunctionEntryHook is the type of the profile entry hook called at entry to
4254  * any generated function when function-level profiling is enabled.
4255  *
4256  * \param function the address of the function that's being entered.
4257  * \param return_addr_location points to a location on stack where the machine
4258  * return address resides. This can be used to identify the caller of
4259  * \p function, and/or modified to divert execution when \p function exits.
4260  *
4261  * \note the entry hook must not cause garbage collection.
4262  */
4263 typedef void (*FunctionEntryHook)(uintptr_t function,
4264  uintptr_t return_addr_location);
4265 
4266 /**
4267  * A JIT code event is issued each time code is added, moved or removed.
4268  *
4269  * \note removal events are not currently issued.
4270  */
4272  enum EventType {
4279  };
4280  // Definition of the code position type. The "POSITION" type means the place
4281  // in the source code which are of interest when making stack traces to
4282  // pin-point the source location of a stack frame as close as possible.
4283  // The "STATEMENT_POSITION" means the place at the beginning of each
4284  // statement, and is used to indicate possible break locations.
4286 
4287  // Type of event.
4289  // Start of the instructions.
4290  void* code_start;
4291  // Size of the instructions.
4292  size_t code_len;
4293  // Script info for CODE_ADDED event.
4295  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
4296  // code line information which is returned from the
4297  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
4298  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
4299  void* user_data;
4300 
4301  struct name_t {
4302  // Name of the object associated with the code, note that the string is not
4303  // zero-terminated.
4304  const char* str;
4305  // Number of chars in str.
4306  size_t len;
4307  };
4308 
4309  struct line_info_t {
4310  // PC offset
4311  size_t offset;
4312  // Code postion
4313  size_t pos;
4314  // The position type.
4316  };
4317 
4318  union {
4319  // Only valid for CODE_ADDED.
4320  struct name_t name;
4321 
4322  // Only valid for CODE_ADD_LINE_POS_INFO
4323  struct line_info_t line_info;
4324 
4325  // New location of instructions. Only valid for CODE_MOVED.
4327  };
4328 };
4329 
4330 /**
4331  * Option flags passed to the SetJitCodeEventHandler function.
4332  */
4335  // Generate callbacks for already existent code.
4337 };
4338 
4339 
4340 /**
4341  * Callback function passed to SetJitCodeEventHandler.
4342  *
4343  * \param event code add, move or removal event.
4344  */
4345 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
4346 
4347 
4348 /**
4349  * Isolate represents an isolated instance of the V8 engine. V8 isolates have
4350  * completely separate states. Objects from one isolate must not be used in
4351  * other isolates. The embedder can create multiple isolates and use them in
4352  * parallel in multiple threads. An isolate can be entered by at most one
4353  * thread at any given time. The Locker/Unlocker API must be used to
4354  * synchronize.
4355  */
4357  public:
4358  /**
4359  * Initial configuration parameters for a new Isolate.
4360  */
4361  struct CreateParams {
4363  : entry_hook(NULL),
4364  code_event_handler(NULL),
4365  enable_serializer(false) {}
4366 
4367  /**
4368  * The optional entry_hook allows the host application to provide the
4369  * address of a function that's invoked on entry to every V8-generated
4370  * function. Note that entry_hook is invoked at the very start of each
4371  * generated function. Furthermore, if an entry_hook is given, V8 will
4372  * always run without a context snapshot.
4373  */
4375 
4376  /**
4377  * Allows the host application to provide the address of a function that is
4378  * notified each time code is added, moved or removed.
4379  */
4381 
4382  /**
4383  * ResourceConstraints to use for the new Isolate.
4384  */
4386 
4387  /**
4388  * This flag currently renders the Isolate unusable.
4389  */
4391  };
4392 
4393 
4394  /**
4395  * Stack-allocated class which sets the isolate for all operations
4396  * executed within a local scope.
4397  */
4399  public:
4400  explicit Scope(Isolate* isolate) : isolate_(isolate) {
4401  isolate->Enter();
4402  }
4403 
4404  ~Scope() { isolate_->Exit(); }
4405 
4406  private:
4408 
4409  // Prevent copying of Scope objects.
4410  Scope(const Scope&);
4412  };
4413 
4414 
4415  /**
4416  * Assert that no Javascript code is invoked.
4417  */
4419  public:
4420  enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
4421 
4422  DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
4424 
4425  private:
4427  void* internal_;
4428 
4429  // Prevent copying of Scope objects.
4433  };
4434 
4435 
4436  /**
4437  * Introduce exception to DisallowJavascriptExecutionScope.
4438  */
4440  public:
4441  explicit AllowJavascriptExecutionScope(Isolate* isolate);
4443 
4444  private:
4447 
4448  // Prevent copying of Scope objects.
4452  };
4453 
4454  /**
4455  * Do not run microtasks while this scope is active, even if microtasks are
4456  * automatically executed otherwise.
4457  */
4459  public:
4460  explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
4462 
4463  private:
4465 
4466  // Prevent copying of Scope objects.
4470  };
4471 
4472  /**
4473  * Types of garbage collections that can be requested via
4474  * RequestGarbageCollectionForTesting.
4475  */
4478  kMinorGarbageCollection
4479  };
4480 
4481  /**
4482  * Features reported via the SetUseCounterCallback callback. Do not chang
4483  * assigned numbers of existing items; add new features to the end of this
4484  * list.
4485  */
4487  kUseAsm = 0,
4488  kUseCounterFeatureCount // This enum value must be last.
4489  };
4490 
4491  typedef void (*UseCounterCallback)(Isolate* isolate,
4492  UseCounterFeature feature);
4493 
4494 
4495  /**
4496  * Creates a new isolate. Does not change the currently entered
4497  * isolate.
4498  *
4499  * When an isolate is no longer used its resources should be freed
4500  * by calling Dispose(). Using the delete operator is not allowed.
4501  *
4502  * V8::Initialize() must have run prior to this.
4503  */
4504  static Isolate* New(const CreateParams& params = CreateParams());
4505 
4506  /**
4507  * Returns the entered isolate for the current thread or NULL in
4508  * case there is no current isolate.
4509  */
4510  static Isolate* GetCurrent();
4511 
4512  /**
4513  * Methods below this point require holding a lock (using Locker) in
4514  * a multi-threaded environment.
4515  */
4516 
4517  /**
4518  * Sets this isolate as the entered one for the current thread.
4519  * Saves the previously entered one (if any), so that it can be
4520  * restored when exiting. Re-entering an isolate is allowed.
4521  */
4522  void Enter();
4523 
4524  /**
4525  * Exits this isolate by restoring the previously entered one in the
4526  * current thread. The isolate may still stay the same, if it was
4527  * entered more than once.
4528  *
4529  * Requires: this == Isolate::GetCurrent().
4530  */
4531  void Exit();
4532 
4533  /**
4534  * Disposes the isolate. The isolate must not be entered by any
4535  * thread to be disposable.
4536  */
4537  void Dispose();
4538 
4539  /**
4540  * Associate embedder-specific data with the isolate. |slot| has to be
4541  * between 0 and GetNumberOfDataSlots() - 1.
4542  */
4543  V8_INLINE void SetData(uint32_t slot, void* data);
4544 
4545  /**
4546  * Retrieve embedder-specific data from the isolate.
4547  * Returns NULL if SetData has never been called for the given |slot|.
4548  */
4549  V8_INLINE void* GetData(uint32_t slot);
4550 
4551  /**
4552  * Returns the maximum number of available embedder data slots. Valid slots
4553  * are in the range of 0 - GetNumberOfDataSlots() - 1.
4554  */
4555  V8_INLINE static uint32_t GetNumberOfDataSlots();
4556 
4557  /**
4558  * Get statistics about the heap memory usage.
4559  */
4560  void GetHeapStatistics(HeapStatistics* heap_statistics);
4561 
4562  /**
4563  * Adjusts the amount of registered external memory. Used to give V8 an
4564  * indication of the amount of externally allocated memory that is kept alive
4565  * by JavaScript objects. V8 uses this to decide when to perform global
4566  * garbage collections. Registering externally allocated memory will trigger
4567  * global garbage collections more often than it would otherwise in an attempt
4568  * to garbage collect the JavaScript objects that keep the externally
4569  * allocated memory alive.
4570  *
4571  * \param change_in_bytes the change in externally allocated memory that is
4572  * kept alive by JavaScript objects.
4573  * \returns the adjusted value.
4574  */
4575  V8_INLINE int64_t
4576  AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
4577 
4578  /**
4579  * Returns heap profiler for this isolate. Will return NULL until the isolate
4580  * is initialized.
4581  */
4582  HeapProfiler* GetHeapProfiler();
4583 
4584  /**
4585  * Returns CPU profiler for this isolate. Will return NULL unless the isolate
4586  * is initialized. It is the embedder's responsibility to stop all CPU
4587  * profiling activities if it has started any.
4588  */
4589  CpuProfiler* GetCpuProfiler();
4590 
4591  /** Returns true if this isolate has a current context. */
4592  bool InContext();
4593 
4594  /** Returns the context that is on the top of the stack. */
4595  Local<Context> GetCurrentContext();
4596 
4597  /**
4598  * Returns the context of the calling JavaScript code. That is the
4599  * context of the top-most JavaScript frame. If there are no
4600  * JavaScript frames an empty handle is returned.
4601  */
4602  Local<Context> GetCallingContext();
4603 
4604  /** Returns the last entered context. */
4605  Local<Context> GetEnteredContext();
4606 
4607  /**
4608  * Schedules an exception to be thrown when returning to JavaScript. When an
4609  * exception has been scheduled it is illegal to invoke any JavaScript
4610  * operation; the caller must return immediately and only after the exception
4611  * has been handled does it become legal to invoke JavaScript operations.
4612  */
4613  Local<Value> ThrowException(Local<Value> exception);
4614 
4615  /**
4616  * Allows the host application to group objects together. If one
4617  * object in the group is alive, all objects in the group are alive.
4618  * After each garbage collection, object groups are removed. It is
4619  * intended to be used in the before-garbage-collection callback
4620  * function, for instance to simulate DOM tree connections among JS
4621  * wrapper objects. Object groups for all dependent handles need to
4622  * be provided for kGCTypeMarkSweepCompact collections, for all other
4623  * garbage collection types it is sufficient to provide object groups
4624  * for partially dependent handles only.
4625  */
4626  template<typename T> void SetObjectGroupId(const Persistent<T>& object,
4627  UniqueId id);
4628 
4629  /**
4630  * Allows the host application to declare implicit references from an object
4631  * group to an object. If the objects of the object group are alive, the child
4632  * object is alive too. After each garbage collection, all implicit references
4633  * are removed. It is intended to be used in the before-garbage-collection
4634  * callback function.
4635  */
4636  template<typename T> void SetReferenceFromGroup(UniqueId id,
4637  const Persistent<T>& child);
4638 
4639  /**
4640  * Allows the host application to declare implicit references from an object
4641  * to another object. If the parent object is alive, the child object is alive
4642  * too. After each garbage collection, all implicit references are removed. It
4643  * is intended to be used in the before-garbage-collection callback function.
4644  */
4645  template<typename T, typename S>
4646  void SetReference(const Persistent<T>& parent, const Persistent<S>& child);
4647 
4648  typedef void (*GCPrologueCallback)(Isolate* isolate,
4649  GCType type,
4651  typedef void (*GCEpilogueCallback)(Isolate* isolate,
4652  GCType type,
4654 
4655  /**
4656  * Enables the host application to receive a notification before a
4657  * garbage collection. Allocations are allowed in the callback function,
4658  * but the callback is not re-entrant: if the allocation inside it will
4659  * trigger the garbage collection, the callback won't be called again.
4660  * It is possible to specify the GCType filter for your callback. But it is
4661  * not possible to register the same callback function two times with
4662  * different GCType filters.
4663  */
4664  void AddGCPrologueCallback(
4665  GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
4666 
4667  /**
4668  * This function removes callback which was installed by
4669  * AddGCPrologueCallback function.
4670  */
4671  void RemoveGCPrologueCallback(GCPrologueCallback callback);
4672 
4673  /**
4674  * Enables the host application to receive a notification after a
4675  * garbage collection. Allocations are allowed in the callback function,
4676  * but the callback is not re-entrant: if the allocation inside it will
4677  * trigger the garbage collection, the callback won't be called again.
4678  * It is possible to specify the GCType filter for your callback. But it is
4679  * not possible to register the same callback function two times with
4680  * different GCType filters.
4681  */
4682  void AddGCEpilogueCallback(
4683  GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
4684 
4685  /**
4686  * This function removes callback which was installed by
4687  * AddGCEpilogueCallback function.
4688  */
4689  void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
4690 
4691  /**
4692  * Request V8 to interrupt long running JavaScript code and invoke
4693  * the given |callback| passing the given |data| to it. After |callback|
4694  * returns control will be returned to the JavaScript code.
4695  * At any given moment V8 can remember only a single callback for the very
4696  * last interrupt request.
4697  * Can be called from another thread without acquiring a |Locker|.
4698  * Registered |callback| must not reenter interrupted Isolate.
4699  */
4700  void RequestInterrupt(InterruptCallback callback, void* data);
4701 
4702  /**
4703  * Clear interrupt request created by |RequestInterrupt|.
4704  * Can be called from another thread without acquiring a |Locker|.
4705  */
4706  void ClearInterrupt();
4707 
4708  /**
4709  * Request garbage collection in this Isolate. It is only valid to call this
4710  * function if --expose_gc was specified.
4711  *
4712  * This should only be used for testing purposes and not to enforce a garbage
4713  * collection schedule. It has strong negative impact on the garbage
4714  * collection performance. Use IdleNotification() or LowMemoryNotification()
4715  * instead to influence the garbage collection schedule.
4716  */
4717  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
4718 
4719  /**
4720  * Set the callback to invoke for logging event.
4721  */
4722  void SetEventLogger(LogEventCallback that);
4723 
4724  /**
4725  * Adds a callback to notify the host application when a script finished
4726  * running. If a script re-enters the runtime during executing, the
4727  * CallCompletedCallback is only invoked when the outer-most script
4728  * execution ends. Executing scripts inside the callback do not trigger
4729  * further callbacks.
4730  */
4731  void AddCallCompletedCallback(CallCompletedCallback callback);
4732 
4733  /**
4734  * Removes callback that was installed by AddCallCompletedCallback.
4735  */
4736  void RemoveCallCompletedCallback(CallCompletedCallback callback);
4737 
4738  /**
4739  * Experimental: Runs the Microtask Work Queue until empty
4740  * Any exceptions thrown by microtask callbacks are swallowed.
4741  */
4742  void RunMicrotasks();
4743 
4744  /**
4745  * Experimental: Enqueues the callback to the Microtask Work Queue
4746  */
4747  void EnqueueMicrotask(Handle<Function> microtask);
4748 
4749  /**
4750  * Experimental: Enqueues the callback to the Microtask Work Queue
4751  */
4752  void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
4753 
4754  /**
4755  * Experimental: Controls whether the Microtask Work Queue is automatically
4756  * run when the script call depth decrements to zero.
4757  */
4758  void SetAutorunMicrotasks(bool autorun);
4759 
4760  /**
4761  * Experimental: Returns whether the Microtask Work Queue is automatically
4762  * run when the script call depth decrements to zero.
4763  */
4764  bool WillAutorunMicrotasks() const;
4765 
4766  /**
4767  * Sets a callback for counting the number of times a feature of V8 is used.
4768  */
4769  void SetUseCounterCallback(UseCounterCallback callback);
4770 
4771  /**
4772  * Enables the host application to provide a mechanism for recording
4773  * statistics counters.
4774  */
4775  void SetCounterFunction(CounterLookupCallback);
4776 
4777  /**
4778  * Enables the host application to provide a mechanism for recording
4779  * histograms. The CreateHistogram function returns a
4780  * histogram which will later be passed to the AddHistogramSample
4781  * function.
4782  */
4783  void SetCreateHistogramFunction(CreateHistogramCallback);
4784  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
4785 
4786  /**
4787  * Optional notification that the embedder is idle.
4788  * V8 uses the notification to reduce memory footprint.
4789  * This call can be used repeatedly if the embedder remains idle.
4790  * Returns true if the embedder should stop calling IdleNotification
4791  * until real work has been done. This indicates that V8 has done
4792  * as much cleanup as it will be able to do.
4793  *
4794  * The idle_time_in_ms argument specifies the time V8 has to do reduce
4795  * the memory footprint. There is no guarantee that the actual work will be
4796  * done within the time limit.
4797  */
4798  bool IdleNotification(int idle_time_in_ms);
4799 
4800  /**
4801  * Optional notification that the system is running low on memory.
4802  * V8 uses these notifications to attempt to free memory.
4803  */
4804  void LowMemoryNotification();
4805 
4806  /**
4807  * Optional notification that a context has been disposed. V8 uses
4808  * these notifications to guide the GC heuristic. Returns the number
4809  * of context disposals - including this one - since the last time
4810  * V8 had a chance to clean up.
4811  */
4812  int ContextDisposedNotification();
4813 
4814  /**
4815  * Allows the host application to provide the address of a function that is
4816  * notified each time code is added, moved or removed.
4817  *
4818  * \param options options for the JIT code event handler.
4819  * \param event_handler the JIT code event handler, which will be invoked
4820  * each time code is added, moved or removed.
4821  * \note \p event_handler won't get notified of existent code.
4822  * \note since code removal notifications are not currently issued, the
4823  * \p event_handler may get notifications of code that overlaps earlier
4824  * code notifications. This happens when code areas are reused, and the
4825  * earlier overlapping code areas should therefore be discarded.
4826  * \note the events passed to \p event_handler and the strings they point to
4827  * are not guaranteed to live past each call. The \p event_handler must
4828  * copy strings and other parameters it needs to keep around.
4829  * \note the set of events declared in JitCodeEvent::EventType is expected to
4830  * grow over time, and the JitCodeEvent structure is expected to accrue
4831  * new members. The \p event_handler function must ignore event codes
4832  * it does not recognize to maintain future compatibility.
4833  * \note Use Isolate::CreateParams to get events for code executed during
4834  * Isolate setup.
4835  */
4836  void SetJitCodeEventHandler(JitCodeEventOptions options,
4837  JitCodeEventHandler event_handler);
4838 
4839  /**
4840  * Modifies the stack limit for this Isolate.
4841  *
4842  * \param stack_limit An address beyond which the Vm's stack may not grow.
4843  *
4844  * \note If you are using threads then you should hold the V8::Locker lock
4845  * while setting the stack limit and you must set a non-default stack
4846  * limit separately for each thread.
4847  */
4848  void SetStackLimit(uintptr_t stack_limit);
4849 
4850  /**
4851  * Returns a memory range that can potentially contain jitted code.
4852  *
4853  * On Win64, embedders are advised to install function table callbacks for
4854  * these ranges, as default SEH won't be able to unwind through jitted code.
4855  *
4856  * Might be empty on other platforms.
4857  *
4858  * https://code.google.com/p/v8/issues/detail?id=3598
4859  */
4860  void GetCodeRange(void** start, size_t* length_in_bytes);
4861 
4862  private:
4863  template<class K, class V, class Traits> friend class PersistentValueMap;
4864 
4866  Isolate(const Isolate&);
4869  void* operator new(size_t size);
4870  void operator delete(void*, size_t);
4871 
4872  void SetObjectGroupId(internal::Object** object, UniqueId id);
4873  void SetReferenceFromGroup(UniqueId id, internal::Object** object);
4874  void SetReference(internal::Object** parent, internal::Object** child);
4875  void CollectAllGarbage(const char* gc_reason);
4876 };
4877 
4879  public:
4882  kBZip2
4883  };
4884 
4885  const char* data;
4888 };
4889 
4890 
4891 /**
4892  * A helper class for driving V8 startup data decompression. It is based on
4893  * "CompressedStartupData" API functions from the V8 class. It isn't mandatory
4894  * for an embedder to use this class, instead, API functions can be used
4895  * directly.
4896  *
4897  * For an example of the class usage, see the "shell.cc" sample application.
4898  */
4900  public:
4902  virtual ~StartupDataDecompressor();
4903  int Decompress();
4904 
4905  protected:
4906  virtual int DecompressData(char* raw_data,
4907  int* raw_data_size,
4908  const char* compressed_data,
4909  int compressed_data_size) = 0;
4910 
4911  private:
4912  char** raw_data;
4913 };
4914 
4915 
4916 /**
4917  * EntropySource is used as a callback function when v8 needs a source
4918  * of entropy.
4919  */
4920 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
4921 
4922 
4923 /**
4924  * ReturnAddressLocationResolver is used as a callback function when v8 is
4925  * resolving the location of a return address on the stack. Profilers that
4926  * change the return address on the stack can use this to resolve the stack
4927  * location to whereever the profiler stashed the original return address.
4928  *
4929  * \param return_addr_location points to a location on stack where a machine
4930  * return address resides.
4931  * \returns either return_addr_location, or else a pointer to the profiler's
4932  * copy of the original return address.
4933  *
4934  * \note the resolver function must not cause garbage collection.
4935  */
4937  uintptr_t return_addr_location);
4938 
4939 
4940 /**
4941  * Interface for iterating through all external resources in the heap.
4942  */
4944  public:
4946  virtual void VisitExternalString(Handle<String> string) {}
4947 };
4948 
4949 
4950 /**
4951  * Interface for iterating through all the persistent handles in the heap.
4952  */
4954  public:
4957  uint16_t class_id) {}
4958 };
4959 
4960 
4961 /**
4962  * Container class for static utility functions.
4963  */
4964 class V8_EXPORT V8 {
4965  public:
4966  /** Set the callback to invoke in case of fatal errors. */
4967  static void SetFatalErrorHandler(FatalErrorCallback that);
4968 
4969  /**
4970  * Set the callback to invoke to check if code generation from
4971  * strings should be allowed.
4972  */
4973  static void SetAllowCodeGenerationFromStringsCallback(
4975 
4976  /**
4977  * Set allocator to use for ArrayBuffer memory.
4978  * The allocator should be set only once. The allocator should be set
4979  * before any code tha uses ArrayBuffers is executed.
4980  * This allocator is used in all isolates.
4981  */
4982  static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator);
4983 
4984  /**
4985  * Check if V8 is dead and therefore unusable. This is the case after
4986  * fatal errors such as out-of-memory situations.
4987  */
4988  static bool IsDead();
4989 
4990  /**
4991  * The following 4 functions are to be used when V8 is built with
4992  * the 'compress_startup_data' flag enabled. In this case, the
4993  * embedder must decompress startup data prior to initializing V8.
4994  *
4995  * This is how interaction with V8 should look like:
4996  * int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
4997  * v8::StartupData* compressed_data =
4998  * new v8::StartupData[compressed_data_count];
4999  * v8::V8::GetCompressedStartupData(compressed_data);
5000  * ... decompress data (compressed_data can be updated in-place) ...
5001  * v8::V8::SetDecompressedStartupData(compressed_data);
5002  * ... now V8 can be initialized
5003  * ... make sure the decompressed data stays valid until V8 shutdown
5004  *
5005  * A helper class StartupDataDecompressor is provided. It implements
5006  * the protocol of the interaction described above, and can be used in
5007  * most cases instead of calling these API functions directly.
5008  */
5009  static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
5010  static int GetCompressedStartupDataCount();
5011  static void GetCompressedStartupData(StartupData* compressed_data);
5012  static void SetDecompressedStartupData(StartupData* decompressed_data);
5013 
5014  /**
5015  * Hand startup data to V8, in case the embedder has chosen to build
5016  * V8 with external startup data.
5017  *
5018  * Note:
5019  * - By default the startup data is linked into the V8 library, in which
5020  * case this function is not meaningful.
5021  * - If this needs to be called, it needs to be called before V8
5022  * tries to make use of its built-ins.
5023  * - To avoid unnecessary copies of data, V8 will point directly into the
5024  * given data blob, so pretty please keep it around until V8 exit.
5025  * - Compression of the startup blob might be useful, but needs to
5026  * handled entirely on the embedders' side.
5027  * - The call will abort if the data is invalid.
5028  */
5029  static void SetNativesDataBlob(StartupData* startup_blob);
5030  static void SetSnapshotDataBlob(StartupData* startup_blob);
5031 
5032  /**
5033  * Adds a message listener.
5034  *
5035  * The same message listener can be added more than once and in that
5036  * case it will be called more than once for each message.
5037  *
5038  * If data is specified, it will be passed to the callback when it is called.
5039  * Otherwise, the exception object will be passed to the callback instead.
5040  */
5041  static bool AddMessageListener(MessageCallback that,
5042  Handle<Value> data = Handle<Value>());
5043 
5044  /**
5045  * Remove all message listeners from the specified callback function.
5046  */
5047  static void RemoveMessageListeners(MessageCallback that);
5048 
5049  /**
5050  * Tells V8 to capture current stack trace when uncaught exception occurs
5051  * and report it to the message listeners. The option is off by default.
5052  */
5053  static void SetCaptureStackTraceForUncaughtExceptions(
5054  bool capture,
5055  int frame_limit = 10,
5057 
5058  /**
5059  * Sets V8 flags from a string.
5060  */
5061  static void SetFlagsFromString(const char* str, int length);
5062 
5063  /**
5064  * Sets V8 flags from the command line.
5065  */
5066  static void SetFlagsFromCommandLine(int* argc,
5067  char** argv,
5068  bool remove_flags);
5069 
5070  /** Get the version string. */
5071  static const char* GetVersion();
5072 
5073  /** Callback function for reporting failed access checks.*/
5074  static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
5075 
5076  /**
5077  * Enables the host application to receive a notification before a
5078  * garbage collection. Allocations are not allowed in the
5079  * callback function, you therefore cannot manipulate objects (set
5080  * or delete properties for example) since it is possible such
5081  * operations will result in the allocation of objects. It is possible
5082  * to specify the GCType filter for your callback. But it is not possible to
5083  * register the same callback function two times with different
5084  * GCType filters.
5085  */
5086  static void AddGCPrologueCallback(
5087  GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
5088 
5089  /**
5090  * This function removes callback which was installed by
5091  * AddGCPrologueCallback function.
5092  */
5093  static void RemoveGCPrologueCallback(GCPrologueCallback callback);
5094 
5095  /**
5096  * Enables the host application to receive a notification after a
5097  * garbage collection. Allocations are not allowed in the
5098  * callback function, you therefore cannot manipulate objects (set
5099  * or delete properties for example) since it is possible such
5100  * operations will result in the allocation of objects. It is possible
5101  * to specify the GCType filter for your callback. But it is not possible to
5102  * register the same callback function two times with different
5103  * GCType filters.
5104  */
5105  static void AddGCEpilogueCallback(
5106  GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
5107 
5108  /**
5109  * This function removes callback which was installed by
5110  * AddGCEpilogueCallback function.
5111  */
5112  static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
5113 
5114  /**
5115  * Enables the host application to provide a mechanism to be notified
5116  * and perform custom logging when V8 Allocates Executable Memory.
5117  */
5118  static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
5120  AllocationAction action);
5121 
5122  /**
5123  * Removes callback that was installed by AddMemoryAllocationCallback.
5124  */
5125  static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
5126 
5127  /**
5128  * Initializes V8. This function needs to be called before the first Isolate
5129  * is created. It always returns true.
5130  */
5131  static bool Initialize();
5132 
5133  /**
5134  * Allows the host application to provide a callback which can be used
5135  * as a source of entropy for random number generators.
5136  */
5137  static void SetEntropySource(EntropySource source);
5138 
5139  /**
5140  * Allows the host application to provide a callback that allows v8 to
5141  * cooperate with a profiler that rewrites return addresses on stack.
5142  */
5143  static void SetReturnAddressLocationResolver(
5144  ReturnAddressLocationResolver return_address_resolver);
5145 
5146  /**
5147  * Forcefully terminate the current thread of JavaScript execution
5148  * in the given isolate.
5149  *
5150  * This method can be used by any thread even if that thread has not
5151  * acquired the V8 lock with a Locker object.
5152  *
5153  * \param isolate The isolate in which to terminate the current JS execution.
5154  */
5155  static void TerminateExecution(Isolate* isolate);
5156 
5157  /**
5158  * Is V8 terminating JavaScript execution.
5159  *
5160  * Returns true if JavaScript execution is currently terminating
5161  * because of a call to TerminateExecution. In that case there are
5162  * still JavaScript frames on the stack and the termination
5163  * exception is still active.
5164  *
5165  * \param isolate The isolate in which to check.
5166  */
5167  static bool IsExecutionTerminating(Isolate* isolate = NULL);
5168 
5169  /**
5170  * Resume execution capability in the given isolate, whose execution
5171  * was previously forcefully terminated using TerminateExecution().
5172  *
5173  * When execution is forcefully terminated using TerminateExecution(),
5174  * the isolate can not resume execution until all JavaScript frames
5175  * have propagated the uncatchable exception which is generated. This
5176  * method allows the program embedding the engine to handle the
5177  * termination event and resume execution capability, even if
5178  * JavaScript frames remain on the stack.
5179  *
5180  * This method can be used by any thread even if that thread has not
5181  * acquired the V8 lock with a Locker object.
5182  *
5183  * \param isolate The isolate in which to resume execution capability.
5184  */
5185  static void CancelTerminateExecution(Isolate* isolate);
5186 
5187  /**
5188  * Releases any resources used by v8 and stops any utility threads
5189  * that may be running. Note that disposing v8 is permanent, it
5190  * cannot be reinitialized.
5191  *
5192  * It should generally not be necessary to dispose v8 before exiting
5193  * a process, this should happen automatically. It is only necessary
5194  * to use if the process needs the resources taken up by v8.
5195  */
5196  static bool Dispose();
5197 
5198  /**
5199  * Iterates through all external resources referenced from current isolate
5200  * heap. GC is not invoked prior to iterating, therefore there is no
5201  * guarantee that visited objects are still alive.
5202  */
5203  static void VisitExternalResources(ExternalResourceVisitor* visitor);
5204 
5205  /**
5206  * Iterates through all the persistent handles in the current isolate's heap
5207  * that have class_ids.
5208  */
5209  static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
5210 
5211  /**
5212  * Iterates through all the persistent handles in the current isolate's heap
5213  * that have class_ids and are candidates to be marked as partially dependent
5214  * handles. This will visit handles to young objects created since the last
5215  * garbage collection but is free to visit an arbitrary superset of these
5216  * objects.
5217  */
5218  static void VisitHandlesForPartialDependence(
5219  Isolate* isolate, PersistentHandleVisitor* visitor);
5220 
5221  /**
5222  * Initialize the ICU library bundled with V8. The embedder should only
5223  * invoke this method when using the bundled ICU. Returns true on success.
5224  *
5225  * If V8 was compiled with the ICU data in an external file, the location
5226  * of the data file has to be provided.
5227  */
5228  static bool InitializeICU(const char* icu_data_file = NULL);
5229 
5230  /**
5231  * Sets the v8::Platform to use. This should be invoked before V8 is
5232  * initialized.
5233  */
5234  static void InitializePlatform(Platform* platform);
5235 
5236  /**
5237  * Clears all references to the v8::Platform. This should be invoked after
5238  * V8 was disposed.
5239  */
5240  static void ShutdownPlatform();
5241 
5242  private:
5243  V8();
5244 
5245  static internal::Object** GlobalizeReference(internal::Isolate* isolate,
5247  static internal::Object** CopyPersistent(internal::Object** handle);
5248  static void DisposeGlobal(internal::Object** global_handle);
5250  static void MakeWeak(internal::Object** global_handle,
5251  void* data,
5252  WeakCallback weak_callback);
5253  static void* ClearWeak(internal::Object** global_handle);
5254  static void Eternalize(Isolate* isolate,
5255  Value* handle,
5256  int* index);
5257  static Local<Value> GetEternal(Isolate* isolate, int index);
5258 
5259  template <class T> friend class Handle;
5260  template <class T> friend class Local;
5261  template <class T> friend class Eternal;
5262  template <class T> friend class PersistentBase;
5263  template <class T, class M> friend class Persistent;
5264  friend class Context;
5265 };
5266 
5267 
5268 /**
5269  * An external exception handler.
5270  */
5272  public:
5273  /**
5274  * Creates a new try/catch block and registers it with v8. Note that
5275  * all TryCatch blocks should be stack allocated because the memory
5276  * location itself is compared against JavaScript try/catch blocks.
5277  */
5278  TryCatch();
5279 
5280  /**
5281  * Unregisters and deletes this try/catch block.
5282  */
5283  ~TryCatch();
5284 
5285  /**
5286  * Returns true if an exception has been caught by this try/catch block.
5287  */
5288  bool HasCaught() const;
5289 
5290  /**
5291  * For certain types of exceptions, it makes no sense to continue execution.
5292  *
5293  * If CanContinue returns false, the correct action is to perform any C++
5294  * cleanup needed and then return. If CanContinue returns false and
5295  * HasTerminated returns true, it is possible to call
5296  * CancelTerminateExecution in order to continue calling into the engine.
5297  */
5298  bool CanContinue() const;
5299 
5300  /**
5301  * Returns true if an exception has been caught due to script execution
5302  * being terminated.
5303  *
5304  * There is no JavaScript representation of an execution termination
5305  * exception. Such exceptions are thrown when the TerminateExecution
5306  * methods are called to terminate a long-running script.
5307  *
5308  * If such an exception has been thrown, HasTerminated will return true,
5309  * indicating that it is possible to call CancelTerminateExecution in order
5310  * to continue calling into the engine.
5311  */
5312  bool HasTerminated() const;
5313 
5314  /**
5315  * Throws the exception caught by this TryCatch in a way that avoids
5316  * it being caught again by this same TryCatch. As with ThrowException
5317  * it is illegal to execute any JavaScript operations after calling
5318  * ReThrow; the caller must return immediately to where the exception
5319  * is caught.
5320  */
5321  Handle<Value> ReThrow();
5322 
5323  /**
5324  * Returns the exception caught by this try/catch block. If no exception has
5325  * been caught an empty handle is returned.
5326  *
5327  * The returned handle is valid until this TryCatch block has been destroyed.
5328  */
5329  Local<Value> Exception() const;
5330 
5331  /**
5332  * Returns the .stack property of the thrown object. If no .stack
5333  * property is present an empty handle is returned.
5334  */
5335  Local<Value> StackTrace() const;
5336 
5337  /**
5338  * Returns the message associated with this exception. If there is
5339  * no message associated an empty handle is returned.
5340  *
5341  * The returned handle is valid until this TryCatch block has been
5342  * destroyed.
5343  */
5344  Local<v8::Message> Message() const;
5345 
5346  /**
5347  * Clears any exceptions that may have been caught by this try/catch block.
5348  * After this method has been called, HasCaught() will return false. Cancels
5349  * the scheduled exception if it is caught and ReThrow() is not called before.
5350  *
5351  * It is not necessary to clear a try/catch block before using it again; if
5352  * another exception is thrown the previously caught exception will just be
5353  * overwritten. However, it is often a good idea since it makes it easier
5354  * to determine which operation threw a given exception.
5355  */
5356  void Reset();
5357 
5358  /**
5359  * Set verbosity of the external exception handler.
5360  *
5361  * By default, exceptions that are caught by an external exception
5362  * handler are not reported. Call SetVerbose with true on an
5363  * external exception handler to have exceptions caught by the
5364  * handler reported as if they were not caught.
5365  */
5366  void SetVerbose(bool value);
5367 
5368  /**
5369  * Set whether or not this TryCatch should capture a Message object
5370  * which holds source information about where the exception
5371  * occurred. True by default.
5372  */
5373  void SetCaptureMessage(bool value);
5374 
5375  /**
5376  * There are cases when the raw address of C++ TryCatch object cannot be
5377  * used for comparisons with addresses into the JS stack. The cases are:
5378  * 1) ARM, ARM64 and MIPS simulators which have separate JS stack.
5379  * 2) Address sanitizer allocates local C++ object in the heap when
5380  * UseAfterReturn mode is enabled.
5381  * This method returns address that can be used for comparisons with
5382  * addresses into the JS stack. When neither simulator nor ASAN's
5383  * UseAfterReturn is enabled, then the address returned will be the address
5384  * of the C++ try catch handler itself.
5385  */
5386  static void* JSStackComparableAddress(v8::TryCatch* handler) {
5387  if (handler == NULL) return NULL;
5388  return handler->js_stack_comparable_address_;
5389  }
5390 
5391  private:
5392  void ResetInternal();
5393 
5394  // Make it hard to create heap-allocated TryCatch blocks.
5396  void operator=(const TryCatch&);
5397  void* operator new(size_t size);
5398  void operator delete(void*, size_t);
5399 
5402  void* exception_;
5408  bool is_verbose_ : 1;
5409  bool can_continue_ : 1;
5411  bool rethrow_ : 1;
5413 
5415 };
5416 
5417 
5418 // --- Context ---
5419 
5420 
5421 /**
5422  * A container for extension names.
5423  */
5425  public:
5426  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
5427  ExtensionConfiguration(int name_count, const char* names[])
5428  : name_count_(name_count), names_(names) { }
5429 
5430  const char** begin() const { return &names_[0]; }
5431  const char** end() const { return &names_[name_count_]; }
5432 
5433  private:
5434  const int name_count_;
5435  const char** names_;
5436 };
5437 
5438 
5439 /**
5440  * A sandboxed execution context with its own set of built-in objects
5441  * and functions.
5442  */
5444  public:
5445  /**
5446  * Returns the global proxy object.
5447  *
5448  * Global proxy object is a thin wrapper whose prototype points to actual
5449  * context's global object with the properties like Object, etc. This is done
5450  * that way for security reasons (for more details see
5451  * https://wiki.mozilla.org/Gecko:SplitWindow).
5452  *
5453  * Please note that changes to global proxy object prototype most probably
5454  * would break VM---v8 expects only global object as a prototype of global
5455  * proxy object.
5456  */
5457  Local<Object> Global();
5458 
5459  /**
5460  * Detaches the global object from its context before
5461  * the global object can be reused to create a new context.
5462  */
5463  void DetachGlobal();
5464 
5465  /**
5466  * Creates a new context and returns a handle to the newly allocated
5467  * context.
5468  *
5469  * \param isolate The isolate in which to create the context.
5470  *
5471  * \param extensions An optional extension configuration containing
5472  * the extensions to be installed in the newly created context.
5473  *
5474  * \param global_template An optional object template from which the
5475  * global object for the newly created context will be created.
5476  *
5477  * \param global_object An optional global object to be reused for
5478  * the newly created context. This global object must have been
5479  * created by a previous call to Context::New with the same global
5480  * template. The state of the global object will be completely reset
5481  * and only object identify will remain.
5482  */
5483  static Local<Context> New(
5484  Isolate* isolate,
5485  ExtensionConfiguration* extensions = NULL,
5486  Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
5487  Handle<Value> global_object = Handle<Value>());
5488 
5489  /**
5490  * Sets the security token for the context. To access an object in
5491  * another context, the security tokens must match.
5492  */
5493  void SetSecurityToken(Handle<Value> token);
5494 
5495  /** Restores the security token to the default value. */
5496  void UseDefaultSecurityToken();
5497 
5498  /** Returns the security token of this context.*/
5499  Handle<Value> GetSecurityToken();
5500 
5501  /**
5502  * Enter this context. After entering a context, all code compiled
5503  * and run is compiled and run in this context. If another context
5504  * is already entered, this old context is saved so it can be
5505  * restored when the new context is exited.
5506  */
5507  void Enter();
5508 
5509  /**
5510  * Exit this context. Exiting the current context restores the
5511  * context that was in place when entering the current context.
5512  */
5513  void Exit();
5514 
5515  /** Returns an isolate associated with a current context. */
5516  v8::Isolate* GetIsolate();
5517 
5518  /**
5519  * Gets the embedder data with the given index, which must have been set by a
5520  * previous call to SetEmbedderData with the same index. Note that index 0
5521  * currently has a special meaning for Chrome's debugger.
5522  */
5523  V8_INLINE Local<Value> GetEmbedderData(int index);
5524 
5525  /**
5526  * Sets the embedder data with the given index, growing the data as
5527  * needed. Note that index 0 currently has a special meaning for Chrome's
5528  * debugger.
5529  */
5530  void SetEmbedderData(int index, Handle<Value> value);
5531 
5532  /**
5533  * Gets a 2-byte-aligned native pointer from the embedder data with the given
5534  * index, which must have bees set by a previous call to
5535  * SetAlignedPointerInEmbedderData with the same index. Note that index 0
5536  * currently has a special meaning for Chrome's debugger.
5537  */
5538  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
5539 
5540  /**
5541  * Sets a 2-byte-aligned native pointer in the embedder data with the given
5542  * index, growing the data as needed. Note that index 0 currently has a
5543  * special meaning for Chrome's debugger.
5544  */
5545  void SetAlignedPointerInEmbedderData(int index, void* value);
5546 
5547  /**
5548  * Control whether code generation from strings is allowed. Calling
5549  * this method with false will disable 'eval' and the 'Function'
5550  * constructor for code running in this context. If 'eval' or the
5551  * 'Function' constructor are used an exception will be thrown.
5552  *
5553  * If code generation from strings is not allowed the
5554  * V8::AllowCodeGenerationFromStrings callback will be invoked if
5555  * set before blocking the call to 'eval' or the 'Function'
5556  * constructor. If that callback returns true, the call will be
5557  * allowed, otherwise an exception will be thrown. If no callback is
5558  * set an exception will be thrown.
5559  */
5560  void AllowCodeGenerationFromStrings(bool allow);
5561 
5562  /**
5563  * Returns true if code generation from strings is allowed for the context.
5564  * For more details see AllowCodeGenerationFromStrings(bool) documentation.
5565  */
5566  bool IsCodeGenerationFromStringsAllowed();
5567 
5568  /**
5569  * Sets the error description for the exception that is thrown when
5570  * code generation from strings is not allowed and 'eval' or the 'Function'
5571  * constructor are called.
5572  */
5573  void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message);
5574 
5575  /**
5576  * Stack-allocated class which sets the execution context for all
5577  * operations executed within a local scope.
5578  */
5579  class Scope {
5580  public:
5581  explicit V8_INLINE Scope(Handle<Context> context) : context_(context) {
5582  context_->Enter();
5583  }
5584  V8_INLINE ~Scope() { context_->Exit(); }
5585 
5586  private:
5588  };
5589 
5590  private:
5591  friend class Value;
5592  friend class Script;
5593  friend class Object;
5594  friend class Function;
5595 
5596  Local<Value> SlowGetEmbedderData(int index);
5597  void* SlowGetAlignedPointerFromEmbedderData(int index);
5598 };
5599 
5600 
5601 /**
5602  * Multiple threads in V8 are allowed, but only one thread at a time is allowed
5603  * to use any given V8 isolate, see the comments in the Isolate class. The
5604  * definition of 'using a V8 isolate' includes accessing handles or holding onto
5605  * object pointers obtained from V8 handles while in the particular V8 isolate.
5606  * It is up to the user of V8 to ensure, perhaps with locking, that this
5607  * constraint is not violated. In addition to any other synchronization
5608  * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be
5609  * used to signal thead switches to V8.
5610  *
5611  * v8::Locker is a scoped lock object. While it's active, i.e. between its
5612  * construction and destruction, the current thread is allowed to use the locked
5613  * isolate. V8 guarantees that an isolate can be locked by at most one thread at
5614  * any time. In other words, the scope of a v8::Locker is a critical section.
5615  *
5616  * Sample usage:
5617 * \code
5618  * ...
5619  * {
5620  * v8::Locker locker(isolate);
5621  * v8::Isolate::Scope isolate_scope(isolate);
5622  * ...
5623  * // Code using V8 and isolate goes here.
5624  * ...
5625  * } // Destructor called here
5626  * \endcode
5627  *
5628  * If you wish to stop using V8 in a thread A you can do this either by
5629  * destroying the v8::Locker object as above or by constructing a v8::Unlocker
5630  * object:
5631  *
5632  * \code
5633  * {
5634  * isolate->Exit();
5635  * v8::Unlocker unlocker(isolate);
5636  * ...
5637  * // Code not using V8 goes here while V8 can run in another thread.
5638  * ...
5639  * } // Destructor called here.
5640  * isolate->Enter();
5641  * \endcode
5642  *
5643  * The Unlocker object is intended for use in a long-running callback from V8,
5644  * where you want to release the V8 lock for other threads to use.
5645  *
5646  * The v8::Locker is a recursive lock, i.e. you can lock more than once in a
5647  * given thread. This can be useful if you have code that can be called either
5648  * from code that holds the lock or from code that does not. The Unlocker is
5649  * not recursive so you can not have several Unlockers on the stack at once, and
5650  * you can not use an Unlocker in a thread that is not inside a Locker's scope.
5651  *
5652  * An unlocker will unlock several lockers if it has to and reinstate the
5653  * correct depth of locking on its destruction, e.g.:
5654  *
5655  * \code
5656  * // V8 not locked.
5657  * {
5658  * v8::Locker locker(isolate);
5659  * Isolate::Scope isolate_scope(isolate);
5660  * // V8 locked.
5661  * {
5662  * v8::Locker another_locker(isolate);
5663  * // V8 still locked (2 levels).
5664  * {
5665  * isolate->Exit();
5666  * v8::Unlocker unlocker(isolate);
5667  * // V8 not locked.
5668  * }
5669  * isolate->Enter();
5670  * // V8 locked again (2 levels).
5671  * }
5672  * // V8 still locked (1 level).
5673  * }
5674  * // V8 Now no longer locked.
5675  * \endcode
5676  */
5678  public:
5679  /**
5680  * Initialize Unlocker for a given Isolate.
5681  */
5682  V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
5683 
5684  ~Unlocker();
5685  private:
5686  void Initialize(Isolate* isolate);
5687 
5689 };
5690 
5691 
5693  public:
5694  /**
5695  * Initialize Locker for a given Isolate.
5696  */
5697  V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
5698 
5699  ~Locker();
5700 
5701  /**
5702  * Returns whether or not the locker for a given isolate, is locked by the
5703  * current thread.
5704  */
5705  static bool IsLocked(Isolate* isolate);
5706 
5707  /**
5708  * Returns whether v8::Locker is being used by this V8 instance.
5709  */
5710  static bool IsActive();
5711 
5712  private:
5713  void Initialize(Isolate* isolate);
5714 
5718 
5719  static bool active_;
5720 
5721  // Disallow copying and assigning.
5722  Locker(const Locker&);
5723  void operator=(const Locker&);
5724 };
5725 
5726 
5727 // --- Implementation ---
5728 
5729 
5730 namespace internal {
5731 
5732 const int kApiPointerSize = sizeof(void*); // NOLINT
5733 const int kApiIntSize = sizeof(int); // NOLINT
5734 const int kApiInt64Size = sizeof(int64_t); // NOLINT
5735 
5736 // Tag information for HeapObject.
5737 const int kHeapObjectTag = 1;
5738 const int kHeapObjectTagSize = 2;
5739 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
5740 
5741 // Tag information for Smi.
5742 const int kSmiTag = 0;
5743 const int kSmiTagSize = 1;
5744 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
5745 
5746 template <size_t ptr_size> struct SmiTagging;
5747 
5748 template<int kSmiShiftSize>
5750  int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
5751  uintptr_t tagged_value =
5752  (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
5753  return reinterpret_cast<internal::Object*>(tagged_value);
5754 }
5755 
5756 // Smi constants for 32-bit systems.
5757 template <> struct SmiTagging<4> {
5758  enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
5759  static int SmiShiftSize() { return kSmiShiftSize; }
5760  static int SmiValueSize() { return kSmiValueSize; }
5761  V8_INLINE static int SmiToInt(const internal::Object* value) {
5762  int shift_bits = kSmiTagSize + kSmiShiftSize;
5763  // Throw away top 32 bits and shift down (requires >> to be sign extending).
5764  return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
5765  }
5766  V8_INLINE static internal::Object* IntToSmi(int value) {
5767  return internal::IntToSmi<kSmiShiftSize>(value);
5768  }
5769  V8_INLINE static bool IsValidSmi(intptr_t value) {
5770  // To be representable as an tagged small integer, the two
5771  // most-significant bits of 'value' must be either 00 or 11 due to
5772  // sign-extension. To check this we add 01 to the two
5773  // most-significant bits, and check if the most-significant bit is 0
5774  //
5775  // CAUTION: The original code below:
5776  // bool result = ((value + 0x40000000) & 0x80000000) == 0;
5777  // may lead to incorrect results according to the C language spec, and
5778  // in fact doesn't work correctly with gcc4.1.1 in some cases: The
5779  // compiler may produce undefined results in case of signed integer
5780  // overflow. The computation must be done w/ unsigned ints.
5781  return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
5782  }
5783 };
5784 
5785 // Smi constants for 64-bit systems.
5786 template <> struct SmiTagging<8> {
5787  enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
5788  static int SmiShiftSize() { return kSmiShiftSize; }
5789  static int SmiValueSize() { return kSmiValueSize; }
5790  V8_INLINE static int SmiToInt(const internal::Object* value) {
5791  int shift_bits = kSmiTagSize + kSmiShiftSize;
5792  // Shift down and throw away top 32 bits.
5793  return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
5794  }
5795  V8_INLINE static internal::Object* IntToSmi(int value) {
5796  return internal::IntToSmi<kSmiShiftSize>(value);
5797  }
5798  V8_INLINE static bool IsValidSmi(intptr_t value) {
5799  // To be representable as a long smi, the value must be a 32-bit integer.
5800  return (value == static_cast<int32_t>(value));
5801  }
5802 };
5803 
5807 V8_INLINE static bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
5808 V8_INLINE static bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
5809 
5810 /**
5811  * This class exports constants and functionality from within v8 that
5812  * is necessary to implement inline functions in the v8 api. Don't
5813  * depend on functions and constants defined here.
5814  */
5815 class Internals {
5816  public:
5817  // These values match non-compiler-dependent values defined within
5818  // the implementation of v8.
5819  static const int kHeapObjectMapOffset = 0;
5822  static const int kStringResourceOffset = 3 * kApiPointerSize;
5823 
5824  static const int kOddballKindOffset = 3 * kApiPointerSize;
5826  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
5827  static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
5828  static const int kContextHeaderSize = 2 * kApiPointerSize;
5829  static const int kContextEmbedderDataIndex = 95;
5830  static const int kFullStringRepresentationMask = 0x07;
5831  static const int kStringEncodingMask = 0x4;
5832  static const int kExternalTwoByteRepresentationTag = 0x02;
5833  static const int kExternalOneByteRepresentationTag = 0x06;
5834 
5837  4 * kApiPointerSize;
5840  static const int kIsolateRootsOffset =
5843  static const int kUndefinedValueRootIndex = 5;
5844  static const int kNullValueRootIndex = 7;
5845  static const int kTrueValueRootIndex = 8;
5846  static const int kFalseValueRootIndex = 9;
5847  static const int kEmptyStringRootIndex = 164;
5848 
5849  // The external allocation limit should be below 256 MB on all architectures
5850  // to avoid that resource-constrained embedders run low on memory.
5851  static const int kExternalAllocationLimit = 192 * 1024 * 1024;
5852 
5853  static const int kNodeClassIdOffset = 1 * kApiPointerSize;
5854  static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
5855  static const int kNodeStateMask = 0xf;
5856  static const int kNodeStateIsWeakValue = 2;
5857  static const int kNodeStateIsPendingValue = 3;
5858  static const int kNodeStateIsNearDeathValue = 4;
5859  static const int kNodeIsIndependentShift = 4;
5860  static const int kNodeIsPartiallyDependentShift = 5;
5861 
5862  static const int kJSObjectType = 0xbc;
5863  static const int kFirstNonstringType = 0x80;
5864  static const int kOddballType = 0x83;
5865  static const int kForeignType = 0x88;
5866 
5867  static const int kUndefinedOddballKind = 5;
5868  static const int kNullOddballKind = 3;
5869 
5870  static const uint32_t kNumIsolateDataSlots = 4;
5871 
5873  V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
5874 #ifdef V8_ENABLE_CHECKS
5875  CheckInitializedImpl(isolate);
5876 #endif
5877  }
5878 
5879  V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
5880  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
5881  kHeapObjectTag);
5882  }
5883 
5884  V8_INLINE static int SmiValue(const internal::Object* value) {
5885  return PlatformSmiTagging::SmiToInt(value);
5886  }
5887 
5888  V8_INLINE static internal::Object* IntToSmi(int value) {
5889  return PlatformSmiTagging::IntToSmi(value);
5890  }
5891 
5892  V8_INLINE static bool IsValidSmi(intptr_t value) {
5893  return PlatformSmiTagging::IsValidSmi(value);
5894  }
5895 
5896  V8_INLINE static int GetInstanceType(const internal::Object* obj) {
5897  typedef internal::Object O;
5898  O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
5899  // Map::InstanceType is defined so that it will always be loaded into
5900  // the LS 8 bits of one 16-bit word, regardless of endianess.
5901  return ReadField<uint16_t>(map, kMapInstanceTypeAndBitFieldOffset) & 0xff;
5902  }
5903 
5904  V8_INLINE static int GetOddballKind(const internal::Object* obj) {
5905  typedef internal::Object O;
5906  return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
5907  }
5908 
5909  V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
5910  int representation = (instance_type & kFullStringRepresentationMask);
5911  return representation == kExternalTwoByteRepresentationTag;
5912  }
5913 
5914  V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
5915  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5916  return *addr & static_cast<uint8_t>(1U << shift);
5917  }
5918 
5920  bool value, int shift) {
5921  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5922  uint8_t mask = static_cast<uint8_t>(1U << shift);
5923  *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
5924  }
5925 
5926  V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
5927  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5928  return *addr & kNodeStateMask;
5929  }
5930 
5932  uint8_t value) {
5933  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5934  *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
5935  }
5936 
5937  V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
5938  uint32_t slot,
5939  void* data) {
5940  uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) +
5942  *reinterpret_cast<void**>(addr) = data;
5943  }
5944 
5945  V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
5946  uint32_t slot) {
5947  const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
5949  return *reinterpret_cast<void* const*>(addr);
5950  }
5951 
5953  int index) {
5954  uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
5955  return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
5956  }
5957 
5958  template <typename T>
5959  V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
5960  const uint8_t* addr =
5961  reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
5962  return *reinterpret_cast<const T*>(addr);
5963  }
5964 
5965  template <typename T>
5966  V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
5967  typedef internal::Object O;
5968  typedef internal::Internals I;
5969  O* ctx = *reinterpret_cast<O* const*>(context);
5970  int embedder_data_offset = I::kContextHeaderSize +
5971  (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
5972  O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
5973  int value_offset =
5974  I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
5975  return I::ReadField<T>(embedder_data, value_offset);
5976  }
5977 };
5978 
5979 } // namespace internal
5980 
5981 
5982 template <class T>
5984 
5985 
5986 template <class T>
5988  return New(isolate, that.val_);
5989 }
5990 
5991 template <class T>
5993  return New(isolate, that.val_);
5994 }
5995 
5996 template <class T>
5997 Handle<T> Handle<T>::New(Isolate* isolate, T* that) {
5998  if (that == NULL) return Handle<T>();
5999  T* that_ptr = that;
6000  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
6001  return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
6002  reinterpret_cast<internal::Isolate*>(isolate), *p)));
6003 }
6004 
6005 
6006 template <class T>
6007 Local<T> Local<T>::New(Isolate* isolate, T* that) {
6008  if (that == NULL) return Local<T>();
6009  T* that_ptr = that;
6010  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
6011  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
6012  reinterpret_cast<internal::Isolate*>(isolate), *p)));
6013 }
6014 
6015 
6016 template<class T>
6017 template<class S>
6019  TYPE_CHECK(T, S);
6020  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_);
6021 }
6022 
6023 
6024 template<class T>
6026  return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_)));
6027 }
6028 
6029 
6030 template <class T>
6031 T* PersistentBase<T>::New(Isolate* isolate, T* that) {
6032  if (that == NULL) return NULL;
6033  internal::Object** p = reinterpret_cast<internal::Object**>(that);
6034  return reinterpret_cast<T*>(
6035  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
6036  p));
6037 }
6038 
6039 
6040 template <class T, class M>
6041 template <class S, class M2>
6043  TYPE_CHECK(T, S);
6044  this->Reset();
6045  if (that.IsEmpty()) return;
6046  internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
6047  this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
6048  M::Copy(that, this);
6049 }
6050 
6051 
6052 template <class T>
6054  typedef internal::Internals I;
6055  if (this->IsEmpty()) return false;
6056  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
6057  I::kNodeIsIndependentShift);
6058 }
6059 
6060 
6061 template <class T>
6063  typedef internal::Internals I;
6064  if (this->IsEmpty()) return false;
6065  uint8_t node_state =
6066  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
6067  return node_state == I::kNodeStateIsNearDeathValue ||
6068  node_state == I::kNodeStateIsPendingValue;
6069 }
6070 
6071 
6072 template <class T>
6074  typedef internal::Internals I;
6075  if (this->IsEmpty()) return false;
6076  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
6077  I::kNodeStateIsWeakValue;
6078 }
6079 
6080 
6081 template <class T>
6083  if (this->IsEmpty()) return;
6084  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
6085  val_ = 0;
6086 }
6087 
6088 
6089 template <class T>
6090 template <class S>
6091 void PersistentBase<T>::Reset(Isolate* isolate, const Handle<S>& other) {
6092  TYPE_CHECK(T, S);
6093  Reset();
6094  if (other.IsEmpty()) return;
6095  this->val_ = New(isolate, other.val_);
6096 }
6097 
6098 
6099 template <class T>
6100 template <class S>
6102  const PersistentBase<S>& other) {
6103  TYPE_CHECK(T, S);
6104  Reset();
6105  if (other.IsEmpty()) return;
6106  this->val_ = New(isolate, other.val_);
6107 }
6108 
6109 
6110 template <class T>
6111 template <typename S, typename P>
6113  P* parameter,
6114  typename WeakCallbackData<S, P>::Callback callback) {
6115  TYPE_CHECK(S, T);
6116  typedef typename WeakCallbackData<Value, void>::Callback Callback;
6117  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
6118  parameter,
6119  reinterpret_cast<Callback>(callback));
6120 }
6121 
6122 
6123 template <class T>
6124 template <typename P>
6126  P* parameter,
6127  typename WeakCallbackData<T, P>::Callback callback) {
6128  SetWeak<T, P>(parameter, callback);
6129 }
6130 
6131 
6132 template <class T>
6133 template<typename P>
6135  return reinterpret_cast<P*>(
6136  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
6137 }
6138 
6139 
6140 template <class T>
6142  typedef internal::Internals I;
6143  if (this->IsEmpty()) return;
6144  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
6145  true,
6146  I::kNodeIsIndependentShift);
6147 }
6148 
6149 
6150 template <class T>
6152  typedef internal::Internals I;
6153  if (this->IsEmpty()) return;
6154  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
6155  true,
6156  I::kNodeIsPartiallyDependentShift);
6157 }
6158 
6159 
6160 template <class T, class M>
6162  T* old;
6163  old = this->val_;
6164  this->val_ = NULL;
6165  return old;
6166 }
6167 
6168 
6169 template <class T>
6171  typedef internal::Internals I;
6172  if (this->IsEmpty()) return;
6173  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
6174  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
6175  *reinterpret_cast<uint16_t*>(addr) = class_id;
6176 }
6177 
6178 
6179 template <class T>
6181  typedef internal::Internals I;
6182  if (this->IsEmpty()) return 0;
6183  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
6184  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
6185  return *reinterpret_cast<uint16_t*>(addr);
6186 }
6187 
6188 
6189 template<typename T>
6191 
6192 template<typename T>
6193 template<typename S>
6195  TYPE_CHECK(T, S);
6196  if (V8_UNLIKELY(handle.IsEmpty())) {
6197  *value_ = GetDefaultValue();
6198  } else {
6199  *value_ = *reinterpret_cast<internal::Object**>(*handle);
6200  }
6201 }
6202 
6203 template<typename T>
6204 template<typename S>
6206  TYPE_CHECK(T, S);
6207  if (V8_UNLIKELY(handle.IsEmpty())) {
6208  *value_ = GetDefaultValue();
6209  } else {
6210  *value_ = *reinterpret_cast<internal::Object**>(*handle);
6211  }
6212 }
6213 
6214 template<typename T>
6215 void ReturnValue<T>::Set(double i) {
6216  TYPE_CHECK(T, Number);
6217  Set(Number::New(GetIsolate(), i));
6218 }
6219 
6220 template<typename T>
6222  TYPE_CHECK(T, Integer);
6223  typedef internal::Internals I;
6224  if (V8_LIKELY(I::IsValidSmi(i))) {
6225  *value_ = I::IntToSmi(i);
6226  return;
6227  }
6228  Set(Integer::New(GetIsolate(), i));
6229 }
6230 
6231 template<typename T>
6233  TYPE_CHECK(T, Integer);
6234  // Can't simply use INT32_MAX here for whatever reason.
6235  bool fits_into_int32_t = (i & (1U << 31)) == 0;
6236  if (V8_LIKELY(fits_into_int32_t)) {
6237  Set(static_cast<int32_t>(i));
6238  return;
6239  }
6240  Set(Integer::NewFromUnsigned(GetIsolate(), i));
6241 }
6242 
6243 template<typename T>
6244 void ReturnValue<T>::Set(bool value) {
6245  TYPE_CHECK(T, Boolean);
6246  typedef internal::Internals I;
6247  int root_index;
6248  if (value) {
6249  root_index = I::kTrueValueRootIndex;
6250  } else {
6251  root_index = I::kFalseValueRootIndex;
6252  }
6253  *value_ = *I::GetRoot(GetIsolate(), root_index);
6254 }
6255 
6256 template<typename T>
6259  typedef internal::Internals I;
6260  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
6261 }
6262 
6263 template<typename T>
6266  typedef internal::Internals I;
6267  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
6268 }
6269 
6270 template<typename T>
6272  TYPE_CHECK(T, String);
6273  typedef internal::Internals I;
6274  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
6275 }
6276 
6277 template<typename T>
6279  // Isolate is always the pointer below the default value on the stack.
6280  return *reinterpret_cast<Isolate**>(&value_[-2]);
6281 }
6282 
6283 template<typename T>
6284 template<typename S>
6285 void ReturnValue<T>::Set(S* whatever) {
6286  // Uncompilable to prevent inadvertent misuse.
6287  TYPE_CHECK(S*, Primitive);
6288 }
6289 
6290 template<typename T>
6292  // Default value is always the pointer below value_ on the stack.
6293  return value_[-1];
6294 }
6295 
6296 
6297 template<typename T>
6299  internal::Object** values,
6300  int length,
6301  bool is_construct_call)
6302  : implicit_args_(implicit_args),
6303  values_(values),
6304  length_(length),
6305  is_construct_call_(is_construct_call) { }
6306 
6307 
6308 template<typename T>
6310  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
6311  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
6312 }
6313 
6314 
6315 template<typename T>
6317  return Local<Function>(reinterpret_cast<Function*>(
6318  &implicit_args_[kCalleeIndex]));
6319 }
6320 
6321 
6322 template<typename T>
6324  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
6325 }
6326 
6327 
6328 template<typename T>
6330  return Local<Object>(reinterpret_cast<Object*>(
6331  &implicit_args_[kHolderIndex]));
6332 }
6333 
6334 
6335 template<typename T>
6337  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
6338 }
6339 
6340 
6341 template<typename T>
6343  return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
6344 }
6345 
6346 
6347 template<typename T>
6349  return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
6350 }
6351 
6352 
6353 template<typename T>
6355  return is_construct_call_;
6356 }
6357 
6358 
6359 template<typename T>
6361  return length_;
6362 }
6363 
6364 
6366  return resource_name_;
6367 }
6368 
6369 
6371  return resource_line_offset_;
6372 }
6373 
6374 
6376  return resource_column_offset_;
6377 }
6378 
6379 
6382 }
6383 
6384 
6386  return script_id_;
6387 }
6388 
6389 
6391  CachedData* data)
6392  : source_string(string),
6393  resource_name(origin.ResourceName()),
6394  resource_line_offset(origin.ResourceLineOffset()),
6395  resource_column_offset(origin.ResourceColumnOffset()),
6396  resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()),
6397  cached_data(data) {}
6398 
6399 
6401  CachedData* data)
6402  : source_string(string), cached_data(data) {}
6403 
6404 
6406  delete cached_data;
6407 }
6408 
6409 
6411  const {
6412  return cached_data;
6413 }
6414 
6415 
6416 Handle<Boolean> Boolean::New(Isolate* isolate, bool value) {
6417  return value ? True(isolate) : False(isolate);
6418 }
6419 
6420 
6421 void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) {
6422  Set(v8::String::NewFromUtf8(isolate, name), value);
6423 }
6424 
6425 
6427 #ifndef V8_ENABLE_CHECKS
6428  typedef internal::Object O;
6429  typedef internal::HeapObject HO;
6430  typedef internal::Internals I;
6431  O* obj = *reinterpret_cast<O**>(this);
6432  // Fast path: If the object is a plain JSObject, which is the common case, we
6433  // know where to find the internal fields and can return the value directly.
6434  if (I::GetInstanceType(obj) == I::kJSObjectType) {
6435  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
6436  O* value = I::ReadField<O*>(obj, offset);
6437  O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
6438  return Local<Value>(reinterpret_cast<Value*>(result));
6439  }
6440 #endif
6441  return SlowGetInternalField(index);
6442 }
6443 
6444 
6446 #ifndef V8_ENABLE_CHECKS
6447  typedef internal::Object O;
6448  typedef internal::Internals I;
6449  O* obj = *reinterpret_cast<O**>(this);
6450  // Fast path: If the object is a plain JSObject, which is the common case, we
6451  // know where to find the internal fields and can return the value directly.
6452  if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) {
6453  int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
6454  return I::ReadField<void*>(obj, offset);
6455  }
6456 #endif
6457  return SlowGetAlignedPointerFromInternalField(index);
6458 }
6459 
6460 
6462 #ifdef V8_ENABLE_CHECKS
6463  CheckCast(value);
6464 #endif
6465  return static_cast<String*>(value);
6466 }
6467 
6468 
6470  typedef internal::Object* S;
6471  typedef internal::Internals I;
6472  I::CheckInitialized(isolate);
6473  S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
6474  return Local<String>(reinterpret_cast<String*>(slot));
6475 }
6476 
6477 
6479  typedef internal::Object O;
6480  typedef internal::Internals I;
6481  O* obj = *reinterpret_cast<O* const*>(this);
6483  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
6484  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
6485  result = reinterpret_cast<String::ExternalStringResource*>(value);
6486  } else {
6487  result = NULL;
6488  }
6489 #ifdef V8_ENABLE_CHECKS
6490  VerifyExternalStringResource(result);
6491 #endif
6492  return result;
6493 }
6494 
6495 
6497  String::Encoding* encoding_out) const {
6498  typedef internal::Object O;
6499  typedef internal::Internals I;
6500  O* obj = *reinterpret_cast<O* const*>(this);
6501  int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
6502  *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
6503  ExternalStringResourceBase* resource = NULL;
6504  if (type == I::kExternalOneByteRepresentationTag ||
6505  type == I::kExternalTwoByteRepresentationTag) {
6506  void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
6507  resource = static_cast<ExternalStringResourceBase*>(value);
6508  }
6509 #ifdef V8_ENABLE_CHECKS
6510  VerifyExternalStringResourceBase(resource, *encoding_out);
6511 #endif
6512  return resource;
6513 }
6514 
6515 
6516 bool Value::IsUndefined() const {
6517 #ifdef V8_ENABLE_CHECKS
6518  return FullIsUndefined();
6519 #else
6520  return QuickIsUndefined();
6521 #endif
6522 }
6523 
6525  typedef internal::Object O;
6526  typedef internal::Internals I;
6527  O* obj = *reinterpret_cast<O* const*>(this);
6528  if (!I::HasHeapObjectTag(obj)) return false;
6529  if (I::GetInstanceType(obj) != I::kOddballType) return false;
6530  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
6531 }
6532 
6533 
6534 bool Value::IsNull() const {
6535 #ifdef V8_ENABLE_CHECKS
6536  return FullIsNull();
6537 #else
6538  return QuickIsNull();
6539 #endif
6540 }
6541 
6542 bool Value::QuickIsNull() const {
6543  typedef internal::Object O;
6544  typedef internal::Internals I;
6545  O* obj = *reinterpret_cast<O* const*>(this);
6546  if (!I::HasHeapObjectTag(obj)) return false;
6547  if (I::GetInstanceType(obj) != I::kOddballType) return false;
6548  return (I::GetOddballKind(obj) == I::kNullOddballKind);
6549 }
6550 
6551 
6552 bool Value::IsString() const {
6553 #ifdef V8_ENABLE_CHECKS
6554  return FullIsString();
6555 #else
6556  return QuickIsString();
6557 #endif
6558 }
6559 
6560 bool Value::QuickIsString() const {
6561  typedef internal::Object O;
6562  typedef internal::Internals I;
6563  O* obj = *reinterpret_cast<O* const*>(this);
6564  if (!I::HasHeapObjectTag(obj)) return false;
6565  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
6566 }
6567 
6568 
6569 template <class T> Value* Value::Cast(T* value) {
6570  return static_cast<Value*>(value);
6571 }
6572 
6573 
6575 #ifdef V8_ENABLE_CHECKS
6576  CheckCast(value);
6577 #endif
6578  return static_cast<Name*>(value);
6579 }
6580 
6581 
6583 #ifdef V8_ENABLE_CHECKS
6584  CheckCast(value);
6585 #endif
6586  return static_cast<Symbol*>(value);
6587 }
6588 
6589 
6591 #ifdef V8_ENABLE_CHECKS
6592  CheckCast(value);
6593 #endif
6594  return static_cast<Number*>(value);
6595 }
6596 
6597 
6599 #ifdef V8_ENABLE_CHECKS
6600  CheckCast(value);
6601 #endif
6602  return static_cast<Integer*>(value);
6603 }
6604 
6605 
6607 #ifdef V8_ENABLE_CHECKS
6608  CheckCast(value);
6609 #endif
6610  return static_cast<Date*>(value);
6611 }
6612 
6613 
6615 #ifdef V8_ENABLE_CHECKS
6616  CheckCast(value);
6617 #endif
6618  return static_cast<StringObject*>(value);
6619 }
6620 
6621 
6623 #ifdef V8_ENABLE_CHECKS
6624  CheckCast(value);
6625 #endif
6626  return static_cast<SymbolObject*>(value);
6627 }
6628 
6629 
6631 #ifdef V8_ENABLE_CHECKS
6632  CheckCast(value);
6633 #endif
6634  return static_cast<NumberObject*>(value);
6635 }
6636 
6637 
6639 #ifdef V8_ENABLE_CHECKS
6640  CheckCast(value);
6641 #endif
6642  return static_cast<BooleanObject*>(value);
6643 }
6644 
6645 
6647 #ifdef V8_ENABLE_CHECKS
6648  CheckCast(value);
6649 #endif
6650  return static_cast<RegExp*>(value);
6651 }
6652 
6653 
6655 #ifdef V8_ENABLE_CHECKS
6656  CheckCast(value);
6657 #endif
6658  return static_cast<Object*>(value);
6659 }
6660 
6661 
6663 #ifdef V8_ENABLE_CHECKS
6664  CheckCast(value);
6665 #endif
6666  return static_cast<Array*>(value);
6667 }
6668 
6669 
6671 #ifdef V8_ENABLE_CHECKS
6672  CheckCast(value);
6673 #endif
6674  return static_cast<Promise*>(value);
6675 }
6676 
6677 
6679 #ifdef V8_ENABLE_CHECKS
6680  CheckCast(value);
6681 #endif
6682  return static_cast<Promise::Resolver*>(value);
6683 }
6684 
6685 
6687 #ifdef V8_ENABLE_CHECKS
6688  CheckCast(value);
6689 #endif
6690  return static_cast<ArrayBuffer*>(value);
6691 }
6692 
6693 
6695 #ifdef V8_ENABLE_CHECKS
6696  CheckCast(value);
6697 #endif
6698  return static_cast<ArrayBufferView*>(value);
6699 }
6700 
6701 
6703 #ifdef V8_ENABLE_CHECKS
6704  CheckCast(value);
6705 #endif
6706  return static_cast<TypedArray*>(value);
6707 }
6708 
6709 
6711 #ifdef V8_ENABLE_CHECKS
6712  CheckCast(value);
6713 #endif
6714  return static_cast<Uint8Array*>(value);
6715 }
6716 
6717 
6719 #ifdef V8_ENABLE_CHECKS
6720  CheckCast(value);
6721 #endif
6722  return static_cast<Int8Array*>(value);
6723 }
6724 
6725 
6727 #ifdef V8_ENABLE_CHECKS
6728  CheckCast(value);
6729 #endif
6730  return static_cast<Uint16Array*>(value);
6731 }
6732 
6733 
6735 #ifdef V8_ENABLE_CHECKS
6736  CheckCast(value);
6737 #endif
6738  return static_cast<Int16Array*>(value);
6739 }
6740 
6741 
6743 #ifdef V8_ENABLE_CHECKS
6744  CheckCast(value);
6745 #endif
6746  return static_cast<Uint32Array*>(value);
6747 }
6748 
6749 
6751 #ifdef V8_ENABLE_CHECKS
6752  CheckCast(value);
6753 #endif
6754  return static_cast<Int32Array*>(value);
6755 }
6756 
6757 
6759 #ifdef V8_ENABLE_CHECKS
6760  CheckCast(value);
6761 #endif
6762  return static_cast<Float32Array*>(value);
6763 }
6764 
6765 
6767 #ifdef V8_ENABLE_CHECKS
6768  CheckCast(value);
6769 #endif
6770  return static_cast<Float64Array*>(value);
6771 }
6772 
6773 
6775 #ifdef V8_ENABLE_CHECKS
6776  CheckCast(value);
6777 #endif
6778  return static_cast<Uint8ClampedArray*>(value);
6779 }
6780 
6781 
6783 #ifdef V8_ENABLE_CHECKS
6784  CheckCast(value);
6785 #endif
6786  return static_cast<DataView*>(value);
6787 }
6788 
6789 
6791 #ifdef V8_ENABLE_CHECKS
6792  CheckCast(value);
6793 #endif
6794  return static_cast<Function*>(value);
6795 }
6796 
6797 
6799 #ifdef V8_ENABLE_CHECKS
6800  CheckCast(value);
6801 #endif
6802  return static_cast<External*>(value);
6803 }
6804 
6805 
6806 template<typename T>
6808  return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
6809 }
6810 
6811 
6812 template<typename T>
6814  return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
6815 }
6816 
6817 
6818 template<typename T>
6820  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
6821 }
6822 
6823 
6824 template<typename T>
6826  return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
6827 }
6828 
6829 
6830 template<typename T>
6832  return ReturnValue<T>(&args_[kReturnValueIndex]);
6833 }
6834 
6835 
6837  typedef internal::Object* S;
6838  typedef internal::Internals I;
6839  I::CheckInitialized(isolate);
6840  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
6841  return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
6842 }
6843 
6844 
6846  typedef internal::Object* S;
6847  typedef internal::Internals I;
6848  I::CheckInitialized(isolate);
6849  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
6850  return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
6851 }
6852 
6853 
6855  typedef internal::Object* S;
6856  typedef internal::Internals I;
6857  I::CheckInitialized(isolate);
6858  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
6859  return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
6860 }
6861 
6862 
6864  typedef internal::Object* S;
6865  typedef internal::Internals I;
6866  I::CheckInitialized(isolate);
6867  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
6868  return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
6869 }
6870 
6871 
6872 void Isolate::SetData(uint32_t slot, void* data) {
6873  typedef internal::Internals I;
6874  I::SetEmbedderData(this, slot, data);
6875 }
6876 
6877 
6879  typedef internal::Internals I;
6880  return I::GetEmbedderData(this, slot);
6881 }
6882 
6883 
6885  typedef internal::Internals I;
6886  return I::kNumIsolateDataSlots;
6887 }
6888 
6889 
6891  int64_t change_in_bytes) {
6892  typedef internal::Internals I;
6893  int64_t* amount_of_external_allocated_memory =
6894  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
6895  I::kAmountOfExternalAllocatedMemoryOffset);
6896  int64_t* amount_of_external_allocated_memory_at_last_global_gc =
6897  reinterpret_cast<int64_t*>(
6898  reinterpret_cast<uint8_t*>(this) +
6899  I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
6900  int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
6901  if (change_in_bytes > 0 &&
6902  amount - *amount_of_external_allocated_memory_at_last_global_gc >
6903  I::kExternalAllocationLimit) {
6904  CollectAllGarbage("external memory allocation limit reached.");
6905  } else {
6906  *amount_of_external_allocated_memory = amount;
6907  }
6908  return *amount_of_external_allocated_memory;
6909 }
6910 
6911 
6912 template<typename T>
6914  UniqueId id) {
6915  TYPE_CHECK(Value, T);
6916  SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id);
6917 }
6918 
6919 
6920 template<typename T>
6922  const Persistent<T>& object) {
6923  TYPE_CHECK(Value, T);
6924  SetReferenceFromGroup(id,
6925  reinterpret_cast<v8::internal::Object**>(object.val_));
6926 }
6927 
6928 
6929 template<typename T, typename S>
6931  const Persistent<S>& child) {
6932  TYPE_CHECK(Object, T);
6933  TYPE_CHECK(Value, S);
6934  SetReference(reinterpret_cast<v8::internal::Object**>(parent.val_),
6935  reinterpret_cast<v8::internal::Object**>(child.val_));
6936 }
6937 
6938 
6940 #ifndef V8_ENABLE_CHECKS
6941  typedef internal::Object O;
6942  typedef internal::HeapObject HO;
6943  typedef internal::Internals I;
6944  HO* context = *reinterpret_cast<HO**>(this);
6945  O** result =
6946  HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
6947  return Local<Value>(reinterpret_cast<Value*>(result));
6948 #else
6949  return SlowGetEmbedderData(index);
6950 #endif
6951 }
6952 
6953 
6955 #ifndef V8_ENABLE_CHECKS
6956  typedef internal::Internals I;
6957  return I::ReadEmbedderData<void*>(this, index);
6958 #else
6959  return SlowGetAlignedPointerFromEmbedderData(index);
6960 #endif
6961 }
6962 
6963 
6964 /**
6965  * \example shell.cc
6966  * A simple shell that takes a list of expressions on the
6967  * command-line and executes them.
6968  */
6969 
6970 
6971 /**
6972  * \example process.cc
6973  */
6974 
6975 
6976 } // namespace v8
6977 
6978 
6979 #undef TYPE_CHECK
6980 
6981 
6982 #endif // V8_H_
An AccessorSignature specifies which receivers are valid parameters to an accessor callback.
Definition: v8.h:3909
A base class for an instance of one of "views" over ArrayBuffer, including TypedArrays and DataView (...
Definition: v8.h:2975
static ArrayBufferView * Cast(Value *obj)
Definition: v8.h:6694
Allocator that V8 uses to allocate |ArrayBuffer|'s memory.
Definition: v8.h:2859
virtual void * Allocate(size_t length)=0
Allocate |length| bytes.
virtual void Free(void *data, size_t length)=0
Free the memory block of size |length|, pointed to by |data|.
virtual void * AllocateUninitialized(size_t length)=0
Allocate |length| bytes.
virtual ~Allocator()
Definition: v8.h:2861
The contents of an |ArrayBuffer|.
Definition: v8.h:2891
void * Data() const
Definition: v8.h:2895
size_t ByteLength() const
Definition: v8.h:2896
An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
Definition: v8.h:2850
static ArrayBuffer * Cast(Value *obj)
Definition: v8.h:6686
An instance of the built-in array constructor (ECMA-262, 15.4.2).
Definition: v8.h:2582
static Array * Cast(Value *obj)
Definition: v8.h:6662
A Boolean object (ECMA-262, 4.3.15).
Definition: v8.h:3234
static BooleanObject * Cast(v8::Value *obj)
Definition: v8.h:6638
A primitive boolean value (ECMA-262, 4.3.14).
Definition: v8.h:1731
static Handle< Boolean > New(Isolate *isolate, bool value)
Definition: v8.h:6416
Stack-allocated class which sets the execution context for all operations executed within a local sco...
Definition: v8.h:5579
Handle< Context > context_
Definition: v8.h:5587
Scope(Handle< Context > context)
Definition: v8.h:5581
A sandboxed execution context with its own set of built-in objects and functions.
Definition: v8.h:5443
Local< Value > GetEmbedderData(int index)
Gets the embedder data with the given index, which must have been set by a previous call to SetEmbedd...
Definition: v8.h:6939
void * GetAlignedPointerFromEmbedderData(int index)
Gets a 2-byte-aligned native pointer from the embedder data with the given index, which must have bee...
Definition: v8.h:6954
Interface for controlling CPU profiling.
Definition: v8-profiler.h:129
An instance of DataView constructor (ES6 draft 15.13.7).
Definition: v8.h:3169
static DataView * Cast(Value *obj)
Definition: v8.h:6782
The superclass of values and API object templates.
Definition: v8.h:913
An instance of the built-in Date constructor (ECMA-262, 15.9).
Definition: v8.h:3184
static Date * Cast(v8::Value *obj)
Definition: v8.h:6606
A HandleScope which first allocates a handle in the current scope which will be later filled with the...
Definition: v8.h:855
EscapableHandleScope(const EscapableHandleScope &)
Local< T > Escape(Local< T > value)
Pushes the value into the previous scope and returns a handle to it.
Definition: v8.h:865
void operator=(const EscapableHandleScope &)
internal::Object ** escape_slot_
Definition: v8.h:881
void Set(Isolate *isolate, Local< S > handle)
Definition: v8.h:6018
Eternal()
Definition: v8.h:400
bool IsEmpty()
Definition: v8.h:407
int index_
Definition: v8.h:412
static const int kInitialValue
Definition: v8.h:411
Local< T > Get(Isolate *isolate)
Definition: v8.h:6025
Eternal(Isolate *isolate, Local< S > handle)
Definition: v8.h:402
Create new error objects by calling the corresponding error object constructor with the message.
Definition: v8.h:4130
static Local< Value > RangeError(Handle< String > message)
static Local< Value > TypeError(Handle< String > message)
static Local< Value > SyntaxError(Handle< String > message)
static Local< Value > ReferenceError(Handle< String > message)
static Local< Value > Error(Handle< String > message)
A container for extension names.
Definition: v8.h:5424
ExtensionConfiguration(int name_count, const char *names[])
Definition: v8.h:5427
const char ** begin() const
Definition: v8.h:5430
const int name_count_
Definition: v8.h:5434
const char ** names_
Definition: v8.h:5435
const char ** end() const
Definition: v8.h:5431
Ignore.
Definition: v8.h:4008
Extension(const Extension &)
const char * name() const
Definition: v8.h:4023
bool auto_enable_
Definition: v8.h:4038
const String::ExternalOneByteStringResource * source() const
Definition: v8.h:4025
size_t source_length() const
Definition: v8.h:4024
void operator=(const Extension &)
int dependency_count()
Definition: v8.h:4027
size_t source_length_
Definition: v8.h:4034
virtual ~Extension()
Definition: v8.h:4017
int dep_count_
Definition: v8.h:4036
ExternalOneByteStringResourceImpl source_
Definition: v8.h:4035
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunctionTemplate(v8::Isolate *isolate, v8::Handle< v8::String > name)
Definition: v8.h:4018
const char ** dependencies()
Definition: v8.h:4028
const char * name_
Definition: v8.h:4033
const char ** deps_
Definition: v8.h:4037
bool auto_enable()
Definition: v8.h:4030
void set_auto_enable(bool value)
Definition: v8.h:4029
size_t length() const
The number of Latin-1 characters in the string.
Definition: v8.h:3998
const char * data() const
The string data from the underlying buffer.
Definition: v8.h:3997
ExternalOneByteStringResourceImpl(const char *data, size_t length)
Definition: v8.h:3995
Interface for iterating through all external resources in the heap.
Definition: v8.h:4943
virtual ~ExternalResourceVisitor()
Definition: v8.h:4945
virtual void VisitExternalString(Handle< String > string)
Definition: v8.h:4946
A JavaScript value that wraps a C++ void*.
Definition: v8.h:3331
static External * Cast(Value *obj)
Definition: v8.h:6798
An instance of Float32Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3137
static void CheckCast(Value *obj)
static Local< Float32Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Float32Array * Cast(Value *obj)
Definition: v8.h:6758
An instance of Float64Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3153
static Float64Array * Cast(Value *obj)
Definition: v8.h:6766
static Local< Float64Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static void CheckCast(Value *obj)
The argument information given to function call callbacks.
Definition: v8.h:2650
static const int kHolderIndex
Definition: v8.h:2667
static const int kCalleeIndex
Definition: v8.h:2672
static const int kReturnValueDefaultValueIndex
Definition: v8.h:2669
static const int kIsolateIndex
Definition: v8.h:2668
static const int kDataIndex
Definition: v8.h:2671
static const int kArgsLength
Definition: v8.h:2662
internal::Object ** values_
Definition: v8.h:2680
ReturnValue< T > GetReturnValue() const
Definition: v8.h:6348
Local< Object > This() const
Definition: v8.h:6323
Local< Object > Holder() const
Definition: v8.h:6329
Local< Value > operator[](int i) const
Definition: v8.h:6309
Isolate * GetIsolate() const
Definition: v8.h:6342
FunctionCallbackInfo(internal::Object **implicit_args, internal::Object **values, int length, bool is_construct_call)
Definition: v8.h:6298
static const int kContextSaveIndex
Definition: v8.h:2673
Local< Value > Data() const
Definition: v8.h:6336
internal::Object ** implicit_args_
Definition: v8.h:2679
static const int kReturnValueIndex
Definition: v8.h:2670
bool IsConstructCall() const
Definition: v8.h:6354
Local< Function > Callee() const
Definition: v8.h:6316
int Length() const
Definition: v8.h:6360
A FunctionTemplate is used to create functions at runtime.
Definition: v8.h:3640
A JavaScript function object (ECMA-262, 15.3).
Definition: v8.h:2723
static const int kLineOffsetNotFound
Definition: v8.h:2783
static Function * Cast(Value *obj)
Definition: v8.h:6790
A stack-allocated class that governs a number of local handles.
Definition: v8.h:802
void operator=(const HandleScope &)
internal::Isolate * isolate_
Definition: v8.h:837
internal::Object ** prev_next_
Definition: v8.h:838
HandleScope()
Definition: v8.h:818
HandleScope(const HandleScope &)
static internal::Object ** CreateHandle(internal::Isolate *isolate, internal::Object *value)
Definition: api.cc:579
internal::Object ** prev_limit_
Definition: v8.h:839
Isolate * GetIsolate() const
Definition: v8.h:813
An object reference managed by the v8 garbage collector.
Definition: v8.h:198
static Handle< T > New(Isolate *isolate, Handle< T > that)
Definition: v8.h:290
static Handle< T > New(Isolate *isolate, const PersistentBase< T > &that)
Definition: v8.h:293
bool operator==(const Handle< S > &that) const
Checks whether two handles are the same.
Definition: v8.h:245
T * operator->() const
Definition: v8.h:235
Handle< S > As()
Definition: v8.h:286
friend Handle< Boolean > True(Isolate *isolate)
Definition: v8.h:6854
bool operator==(const PersistentBase< S > &that) const
Definition: v8.h:253
static Handle< T > New(Isolate *isolate, T *that)
Definition: v8.h:5997
bool IsEmpty() const
Returns true if the handle is empty.
Definition: v8.h:228
void Clear()
Sets the handle to be empty.
Definition: v8.h:233
friend Handle< Primitive > Null(Isolate *isolate)
Definition: v8.h:6845
friend Handle< Primitive > Undefined(Isolate *isolate)
Definition: v8.h:6836
Handle(Handle< S > that)
Creates a handle for the contents of the specified handle.
Definition: v8.h:215
static Handle< T > Cast(Handle< S > that)
Definition: v8.h:277
bool operator!=(const Persistent< S > &that) const
Definition: v8.h:272
T * val_
Definition: v8.h:323
Handle()
Creates an empty handle.
Definition: v8.h:203
Handle(T *val)
Creates a new handle for the specified value.
Definition: v8.h:319
T * operator*() const
Definition: v8.h:237
bool operator!=(const Handle< S > &that) const
Checks whether two handles are different.
Definition: v8.h:268
friend Handle< Boolean > False(Isolate *isolate)
Definition: v8.h:6863
Interface for controlling heap profiling.
Definition: v8-profiler.h:390
Collection of V8 heap information.
Definition: v8.h:4228
size_t used_heap_size()
Definition: v8.h:4234
size_t total_physical_size()
Definition: v8.h:4233
size_t heap_size_limit()
Definition: v8.h:4235
size_t total_heap_size_executable_
Definition: v8.h:4239
size_t used_heap_size_
Definition: v8.h:4241
size_t total_heap_size_executable()
Definition: v8.h:4232
size_t total_heap_size()
Definition: v8.h:4231
size_t total_physical_size_
Definition: v8.h:4240
size_t heap_size_limit_
Definition: v8.h:4242
size_t total_heap_size_
Definition: v8.h:4238
An instance of Int16Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3089
static void CheckCast(Value *obj)
static Int16Array * Cast(Value *obj)
Definition: v8.h:6734
static Local< Int16Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
An instance of Int32Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3121
static Local< Int32Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static void CheckCast(Value *obj)
static Int32Array * Cast(Value *obj)
Definition: v8.h:6750
A JavaScript value representing a 32-bit signed integer.
Definition: v8.h:2191
An instance of Int8Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3057
static Int8Array * Cast(Value *obj)
Definition: v8.h:6718
static Local< Int8Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static void CheckCast(Value *obj)
A JavaScript value representing a signed integer.
Definition: v8.h:2176
static Integer * Cast(v8::Value *obj)
Definition: v8.h:6598
static Local< Integer > New(Isolate *isolate, int32_t value)
Definition: api.cc:6281
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
Definition: api.cc:6294
Introduce exception to DisallowJavascriptExecutionScope.
Definition: v8.h:4439
AllowJavascriptExecutionScope & operator=(const AllowJavascriptExecutionScope &)
AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope &)
Assert that no Javascript code is invoked.
Definition: v8.h:4418
DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope &)
DisallowJavascriptExecutionScope & operator=(const DisallowJavascriptExecutionScope &)
Stack-allocated class which sets the isolate for all operations executed within a local scope.
Definition: v8.h:4398
Scope & operator=(const Scope &)
Scope(Isolate *isolate)
Definition: v8.h:4400
Isolate *const isolate_
Definition: v8.h:4407
Scope(const Scope &)
Do not run microtasks while this scope is active, even if microtasks are automatically executed other...
Definition: v8.h:4458
SuppressMicrotaskExecutionScope & operator=(const SuppressMicrotaskExecutionScope &)
SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope &)
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
void SetReference(const Persistent< T > &parent, const Persistent< S > &child)
Allows the host application to declare implicit references from an object to another object.
Definition: v8.h:6930
void SetReferenceFromGroup(UniqueId id, const Persistent< T > &child)
Allows the host application to declare implicit references from an object group to an object.
Definition: v8.h:6921
void SetData(uint32_t slot, void *data)
Associate embedder-specific data with the isolate.
Definition: v8.h:6872
GarbageCollectionType
Types of garbage collections that can be requested via RequestGarbageCollectionForTesting.
Definition: v8.h:4476
@ kFullGarbageCollection
Definition: v8.h:4477
Isolate & operator=(const Isolate &)
static uint32_t GetNumberOfDataSlots()
Returns the maximum number of available embedder data slots.
Definition: v8.h:6884
Isolate(const Isolate &)
int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes)
Adjusts the amount of registered external memory.
Definition: v8.h:6890
void SetObjectGroupId(const Persistent< T > &object, UniqueId id)
Allows the host application to group objects together.
Definition: v8.h:6913
void Enter()
Methods below this point require holding a lock (using Locker) in a multi-threaded environment.
Definition: api.cc:6620
UseCounterFeature
Features reported via the SetUseCounterCallback callback.
Definition: v8.h:4486
void * GetData(uint32_t slot)
Retrieve embedder-specific data from the isolate.
Definition: v8.h:6878
A JSON Parser.
Definition: v8.h:1421
A light-weight stack-allocated object handle.
Definition: v8.h:334
static Local< T > New(Isolate *isolate, T *that)
Definition: v8.h:6007
Local(Handle< S > that)
Definition: v8.h:356
static Local< T > Cast(Local< S > that)
Definition: v8.h:348
static Local< T > New(Isolate *isolate, const PersistentBase< T > &that)
Definition: v8.h:5992
Local(S *that)
Definition: v8.h:392
Local()
Definition: v8.h:5983
static Local< T > New(Isolate *isolate, Handle< T > that)
Create a local handle for the content of another handle.
Definition: v8.h:5987
Local(Local< S > that)
Definition: v8.h:337
friend class Local
Definition: v8.h:380
Local< S > As()
Definition: v8.h:361
bool top_level_
Definition: v8.h:5716
Locker(const Locker &)
Locker(Isolate *isolate)
Initialize Locker for a given Isolate.
Definition: v8.h:5697
bool has_lock_
Definition: v8.h:5715
static bool active_
Definition: v8.h:5719
internal::Isolate * isolate_
Definition: v8.h:5717
void operator=(const Locker &)
An error message.
Definition: v8.h:1233
A superclass for symbols and strings.
Definition: v8.h:1741
static Name * Cast(v8::Value *obj)
Definition: v8.h:6574
Default traits for Persistent.
Definition: v8.h:587
static void Uncompilable()
Definition: v8.h:597
static const bool kResetInDestructor
Definition: v8.h:590
static void Copy(const Persistent< S, M > &source, NonCopyablePersistent *dest)
Definition: v8.h:592
Persistent< T, NonCopyablePersistentTraits< T > > NonCopyablePersistent
Definition: v8.h:589
A Number object (ECMA-262, 4.3.21).
Definition: v8.h:3218
static NumberObject * Cast(v8::Value *obj)
Definition: v8.h:6630
A JavaScript number value (ECMA-262, 4.3.20)
Definition: v8.h:2162
static Number * Cast(v8::Value *obj)
Definition: v8.h:6590
static Local< Number > New(Isolate *isolate, double value)
Definition: api.cc:6268
An ObjectTemplate is used to create objects at runtime.
Definition: v8.h:3728
A JavaScript object (ECMA-262, 4.3.3)
Definition: v8.h:2283
static Object * Cast(Value *obj)
Definition: v8.h:6654
void * GetAlignedPointerFromInternalField(int index)
Gets a 2-byte-aligned native pointer from an internal field.
Definition: v8.h:6445
static int InternalFieldCount(const PersistentBase< Object > &object)
Same as above, but works for Persistents.
Definition: v8.h:2416
static void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Same as above, but works for Persistents.
Definition: v8.h:2435
Local< Value > GetInternalField(int index)
Gets the value from an internal field.
Definition: v8.h:6426
An object reference that is independent of any handle scope.
Definition: v8.h:448
void Reset()
If non-empty, destroy the underlying storage cell IsEmpty() will return true after this call.
Definition: v8.h:6082
bool operator==(const Handle< S > &that) const
Definition: v8.h:480
void ClearWeak()
Definition: v8.h:518
PersistentBase(PersistentBase &other)
bool IsWeak() const
Returns true if the handle's reference is weak.
Definition: v8.h:6073
void MarkPartiallyDependent()
Marks the reference to this object partially dependent.
Definition: v8.h:6151
bool IsIndependent() const
Definition: v8.h:6053
bool IsNearDeath() const
Checks if the handle holds the only reference to an object.
Definition: v8.h:6062
bool operator!=(const Handle< S > &that) const
Definition: v8.h:493
P * ClearWeak()
Definition: v8.h:6134
bool operator!=(const PersistentBase< S > &that) const
Definition: v8.h:489
void SetWeak(P *parameter, typename WeakCallbackData< T, P >::Callback callback)
Install a finalization callback on this object.
Definition: v8.h:6125
void operator=(PersistentBase &)
bool operator==(const PersistentBase< S > &that) const
Definition: v8.h:472
bool IsEmpty() const
Definition: v8.h:469
void SetWrapperClassId(uint16_t class_id)
Assigns a wrapper class ID to the handle.
Definition: v8.h:6170
uint16_t WrapperClassId() const
Returns the class ID previously assigned to this handle or 0 if no class ID was previously assigned.
Definition: v8.h:6180
static T * New(Isolate *isolate, T *that)
Definition: v8.h:6031
void MarkIndependent()
Marks the reference to this object independent.
Definition: v8.h:6141
PersistentBase(T *val)
Definition: v8.h:571
Interface for iterating through all the persistent handles in the heap.
Definition: v8.h:4953
virtual void VisitPersistentHandle(Persistent< Value > *value, uint16_t class_id)
Definition: v8.h:4956
virtual ~PersistentHandleVisitor()
Definition: v8.h:4955
A map wrapper that allows using UniquePersistent as a mapped value.
Definition: v8-util.h:119
A vector wrapper that safely stores UniquePersistent values.
Definition: v8-util.h:405
A PersistentBase which allows copy and assignment.
Definition: v8.h:627
T * operator*() const
Definition: v8.h:711
Persistent< S > & As()
Definition: v8.h:695
Persistent(Isolate *isolate, Handle< S > that)
Construct a Persistent from a Handle.
Definition: v8.h:638
~Persistent()
The destructor will dispose the Persistent based on the kResetInDestructor flags in the traits class.
Definition: v8.h:679
Persistent(const Persistent< S, M2 > &that)
Definition: v8.h:662
Persistent()
A Persistent with no storage cell.
Definition: v8.h:632
Persistent & operator=(const Persistent &that)
Definition: v8.h:665
Persistent(S *that)
Definition: v8.h:710
Persistent & operator=(const Persistent< S, M2 > &that)
Definition: v8.h:670
static Persistent< T > & Cast(Persistent< S > &that)
Definition: v8.h:685
T * ClearAndLeak()
Definition: v8.h:6161
void Copy(const Persistent< S, M2 > &that)
Definition: v8.h:6042
Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Construct a Persistent from a Persistent.
Definition: v8.h:648
Persistent(const Persistent &that)
The copy constructors and assignment operator create a Persistent exactly as the Persistent construct...
Definition: v8.h:658
V8 Platform abstraction layer.
Definition: v8-platform.h:28
The superclass of primitive values.
Definition: v8.h:1724
A private symbol.
Definition: v8.h:2136
static Resolver * Cast(Value *obj)
Definition: v8.h:6678
An instance of the built-in Promise constructor (ES6 draft).
Definition: v8.h:2795
static Promise * Cast(Value *obj)
Definition: v8.h:6670
The information passed to a property callback about the context of the property access.
Definition: v8.h:2691
static const int kReturnValueDefaultValueIndex
Definition: v8.h:2707
Local< Value > Data() const
Definition: v8.h:6813
static const int kDataIndex
Definition: v8.h:2709
PropertyCallbackInfo(internal::Object **args)
Definition: v8.h:2712
internal::Object ** args_
Definition: v8.h:2713
static const int kIsolateIndex
Definition: v8.h:2706
Local< Object > Holder() const
Definition: v8.h:6825
static const int kThisIndex
Definition: v8.h:2710
static const int kHolderIndex
Definition: v8.h:2705
static const int kArgsLength
Definition: v8.h:2699
ReturnValue< T > GetReturnValue() const
Definition: v8.h:6831
static const int kReturnValueIndex
Definition: v8.h:2708
friend class MacroAssembler
Definition: v8.h:2702
Local< Object > This() const
Definition: v8.h:6819
Isolate * GetIsolate() const
Definition: v8.h:6807
An instance of the built-in RegExp constructor (ECMA-262, 15.10).
Definition: v8.h:3284
Flags
Regular expression flag bits.
Definition: v8.h:3290
static RegExp * Cast(v8::Value *obj)
Definition: v8.h:6646
A set of constraints that specifies the limits of the runtime's memory use.
Definition: v8.h:4066
uint32_t * stack_limit_
Definition: v8.h:4108
void set_max_available_threads(int value)
Definition: v8.h:4096
void set_stack_limit(uint32_t *value)
Definition: v8.h:4093
int max_semi_space_size() const
Definition: v8.h:4085
void set_max_executable_size(int value)
Definition: v8.h:4090
int max_old_space_size() const
Definition: v8.h:4087
int max_semi_space_size_
Definition: v8.h:4105
int max_available_threads_
Definition: v8.h:4109
void set_max_old_space_size(int value)
Definition: v8.h:4088
int max_executable_size_
Definition: v8.h:4107
int max_available_threads() const
Definition: v8.h:4094
int max_executable_size() const
Definition: v8.h:4089
uint32_t * stack_limit() const
Definition: v8.h:4091
void set_max_semi_space_size(int value)
Definition: v8.h:4086
size_t code_range_size() const
Definition: v8.h:4099
size_t code_range_size_
Definition: v8.h:4110
void set_code_range_size(size_t value)
Definition: v8.h:4100
Interface for providing information about embedder's objects held by global handles.
Definition: v8-profiler.h:545
void Set(const Persistent< S > &handle)
Definition: v8.h:6194
void SetEmptyString()
Definition: v8.h:6271
friend class ReturnValue
Definition: v8.h:2632
ReturnValue(const ReturnValue< S > &that)
Definition: v8.h:2608
Isolate * GetIsolate()
Definition: v8.h:6278
void SetInternal(internal::Object *value)
Definition: v8.h:2636
void SetNull()
Definition: v8.h:6257
internal::Object ** value_
Definition: v8.h:2639
internal::Object * GetDefaultValue()
Definition: v8.h:6291
void SetUndefined()
Definition: v8.h:6264
For streaming incomplete script data to V8.
Definition: v8.h:1096
virtual size_t GetMoreData(const uint8_t **src)=0
V8 calls this to request the next chunk of data from the embedder.
A streaming task which the embedder must run on a background thread to stream scripts into V8.
Definition: v8.h:1153
Source code which can be then compiled to a UnboundScript or Script.
Definition: v8.h:1058
Local< String > source_string
Definition: v8.h:1078
CachedData * cached_data
Definition: v8.h:1089
Handle< Integer > resource_column_offset
Definition: v8.h:1083
const CachedData * GetCachedData() const
Definition: v8.h:6410
Handle< Value > resource_name
Definition: v8.h:1081
Handle< Integer > resource_line_offset
Definition: v8.h:1082
Handle< Boolean > resource_is_shared_cross_origin
Definition: v8.h:1084
Source(Local< String > source_string, const ScriptOrigin &origin, CachedData *cached_data=NULL)
Definition: v8.h:6390
Source & operator=(const Source &)
Source code which can be streamed into V8 in pieces.
Definition: v8.h:1127
StreamedSource & operator=(const StreamedSource &)
internal::StreamedSource * impl_
Definition: v8.h:1146
internal::StreamedSource * impl() const
Definition: v8.h:1139
StreamedSource(const StreamedSource &)
For compiling scripts.
Definition: v8.h:1019
@ kProduceParserCache
Definition: v8.h:1161
@ kConsumeParserCache
Definition: v8.h:1162
@ kProduceCodeCache
Definition: v8.h:1163
@ kConsumeCodeCache
Definition: v8.h:1164
The origin, within a file, of a script.
Definition: v8.h:922
Handle< Boolean > resource_is_shared_cross_origin_
Definition: v8.h:944
Handle< Integer > resource_line_offset_
Definition: v8.h:942
Handle< Boolean > ResourceIsSharedCrossOrigin() const
Definition: v8.h:6380
Handle< Integer > ScriptID() const
Definition: v8.h:6385
Handle< Integer > ResourceColumnOffset() const
Definition: v8.h:6375
Handle< Integer > ResourceLineOffset() const
Definition: v8.h:6370
Handle< Integer > script_id_
Definition: v8.h:945
ScriptOrigin(Handle< Value > resource_name, Handle< Integer > resource_line_offset=Handle< Integer >(), Handle< Integer > resource_column_offset=Handle< Integer >(), Handle< Boolean > resource_is_shared_cross_origin=Handle< Boolean >(), Handle< Integer > script_id=Handle< Integer >())
Definition: v8.h:924
Handle< Value > ResourceName() const
Definition: v8.h:6365
Handle< Value > resource_name_
Definition: v8.h:941
Handle< Integer > resource_column_offset_
Definition: v8.h:943
A compiled JavaScript script, tied to a Context which was active when the script was compiled.
Definition: v8.h:985
V8_DEPRECATED("Use GetUnboundScript()->GetId()", int GetId())
Definition: v8.h:1009
A Signature specifies which receivers and arguments are valid parameters to a function.
Definition: v8.h:3892
A single JavaScript stack frame.
Definition: v8.h:1358
Representation of a JavaScript stack trace.
Definition: v8.h:1306
StackTraceOptions
Flags that determine what information is placed captured for each StackFrame when grabbing the curren...
Definition: v8.h:1312
@ kOverview
Definition: v8.h:1322
A helper class for driving V8 startup data decompression.
Definition: v8.h:4899
virtual int DecompressData(char *raw_data, int *raw_data_size, const char *compressed_data, int compressed_data_size)=0
int raw_size
Definition: v8.h:4887
int compressed_size
Definition: v8.h:4886
const char * data
Definition: v8.h:4885
CompressionAlgorithm
Definition: v8.h:4880
@ kUncompressed
Definition: v8.h:4881
A String object (ECMA-262, 4.3.18).
Definition: v8.h:3250
static StringObject * Cast(v8::Value *obj)
Definition: v8.h:6614
An ExternalOneByteStringResource is a wrapper around an one-byte string buffer that resides outside V...
Definition: v8.h:1918
virtual ~ExternalOneByteStringResource()
Override the destructor to manage the life cycle of the underlying buffer.
Definition: v8.h:1924
virtual const char * data() const =0
The string data from the underlying buffer.
virtual size_t length() const =0
The number of Latin-1 characters in the string.
ExternalStringResourceBase(const ExternalStringResourceBase &)
void operator=(const ExternalStringResourceBase &)
virtual void Dispose()
Internally V8 will call this Dispose method when the external string resource is no longer needed.
Definition: v8.h:1868
An ExternalStringResource is a wrapper around a two-byte string buffer that resides outside V8's heap...
Definition: v8.h:1885
virtual ~ExternalStringResource()
Override the destructor to manage the life cycle of the underlying buffer.
Definition: v8.h:1891
virtual const uint16_t * data() const =0
The string data from the underlying buffer.
virtual size_t length() const =0
The length of the string.
Converts an object to a UTF-8-encoded character array.
Definition: v8.h:2048
char * operator*()
Definition: v8.h:2052
Utf8Value(const Utf8Value &)
void operator=(const Utf8Value &)
int length() const
Definition: v8.h:2054
const char * operator*() const
Definition: v8.h:2053
Converts an object to a two-byte string.
Definition: v8.h:2070
const uint16_t * operator*() const
Definition: v8.h:2075
Value(const Value &)
void operator=(const Value &)
uint16_t * str_
Definition: v8.h:2078
uint16_t * operator*()
Definition: v8.h:2074
int length() const
Definition: v8.h:2076
A JavaScript string value (ECMA-262, 4.3.17).
Definition: v8.h:1752
bool IsExternalAscii() const
Definition: v8.h:1853
Encoding
Definition: v8.h:1754
ExternalStringResourceBase * GetExternalStringResourceBase(Encoding *encoding_out) const
If the string is an external string, return the ExternalStringResourceBase regardless of the encoding...
Definition: v8.h:6496
NewStringType
Definition: v8.h:1962
@ kInternalizedString
Definition: v8.h:1963
static String * Cast(v8::Value *obj)
Definition: v8.h:6461
WriteOptions
Write the contents of the string to an external buffer.
Definition: v8.h:1809
static v8::Local< v8::String > Empty(Isolate *isolate)
A zero length string.
Definition: v8.h:6469
ExternalStringResource * GetExternalStringResource() const
Get the ExternalStringResource for an external string.
Definition: v8.h:6478
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
Allocates a new string from UTF-8 data.
Definition: api.cc:5447
const ExternalAsciiStringResource * GetExternalAsciiStringResource() const
Definition: v8.h:1956
ExternalOneByteStringResource ExternalAsciiStringResource
Definition: v8.h:1933
A Symbol object (ECMA-262 edition 6).
Definition: v8.h:3268
static SymbolObject * Cast(v8::Value *obj)
Definition: v8.h:6622
A JavaScript symbol (ECMA-262 edition 6)
Definition: v8.h:2099
static Symbol * Cast(v8::Value *obj)
Definition: v8.h:6582
The superclass of object and function templates.
Definition: v8.h:3347
void Set(Handle< Name > name, Handle< Data > value, PropertyAttribute attributes=None)
Adds a property to each instance created by this template.
Definition: api.cc:802
An external exception handler.
Definition: v8.h:5271
bool has_terminated_
Definition: v8.h:5412
void * js_stack_comparable_address_
Definition: v8.h:5405
v8::TryCatch * next_
Definition: v8.h:5401
TryCatch(const TryCatch &)
bool is_verbose_
Definition: v8.h:5408
void * message_script_
Definition: v8.h:5404
v8::internal::Isolate * isolate_
Definition: v8.h:5400
int message_end_pos_
Definition: v8.h:5407
void * exception_
Definition: v8.h:5402
bool rethrow_
Definition: v8.h:5411
void * message_obj_
Definition: v8.h:5403
int message_start_pos_
Definition: v8.h:5406
bool can_continue_
Definition: v8.h:5409
static void * JSStackComparableAddress(v8::TryCatch *handler)
There are cases when the raw address of C++ TryCatch object cannot be used for comparisons with addre...
Definition: v8.h:5386
bool capture_message_
Definition: v8.h:5410
void operator=(const TryCatch &)
A utility for determining the type of objects based on the template they were constructed from.
Definition: v8.h:3979
A base class for an instance of TypedArray series of constructors (ES6 draft 15.13....
Definition: v8.h:3006
static TypedArray * Cast(Value *obj)
Definition: v8.h:6702
An instance of Uint16Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3073
static Local< Uint16Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Uint16Array * Cast(Value *obj)
Definition: v8.h:6726
static void CheckCast(Value *obj)
An instance of Uint32Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3105
static Local< Uint32Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static void CheckCast(Value *obj)
static Uint32Array * Cast(Value *obj)
Definition: v8.h:6742
A JavaScript value representing a 32-bit unsigned integer.
Definition: v8.h:2202
An instance of Uint8Array constructor (ES6 draft 15.13.6).
Definition: v8.h:3026
static Uint8Array * Cast(Value *obj)
Definition: v8.h:6710
static Local< Uint8Array > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static void CheckCast(Value *obj)
An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
Definition: v8.h:3042
static void CheckCast(Value *obj)
static Uint8ClampedArray * Cast(Value *obj)
Definition: v8.h:6774
static Local< Uint8ClampedArray > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
A compiled JavaScript script, not yet tied to a Context.
Definition: v8.h:952
General purpose unique identifier.
Definition: v8.h:144
intptr_t data_
Definition: v8.h:162
bool operator<(const UniqueId &other) const
Definition: v8.h:157
bool operator==(const UniqueId &other) const
Definition: v8.h:149
UniqueId(intptr_t data)
Definition: v8.h:146
bool operator!=(const UniqueId &other) const
Definition: v8.h:153
A PersistentBase which has move semantics.
Definition: v8.h:723
UniquePersistent & operator=(UniquePersistent< S > rhs)
Move via assignment.
Definition: v8.h:766
void operator=(UniquePersistent &)
UniquePersistent(RValue rvalue)
Move constructor.
Definition: v8.h:757
UniquePersistent(UniquePersistent &)
UniquePersistent()
A UniquePersistent with no storage cell.
Definition: v8.h:733
UniquePersistent(Isolate *isolate, Handle< S > that)
Construct a UniquePersistent from a Handle.
Definition: v8.h:740
UniquePersistent Pass()
Pass allows returning uniques from functions, etc.
Definition: v8.h:780
UniquePersistent(Isolate *isolate, const PersistentBase< S > &that)
Construct a UniquePersistent from a PersistentBase.
Definition: v8.h:750
Multiple threads in V8 are allowed, but only one thread at a time is allowed to use any given V8 isol...
Definition: v8.h:5677
internal::Isolate * isolate_
Definition: v8.h:5688
Unlocker(Isolate *isolate)
Initialize Unlocker for a given Isolate.
Definition: v8.h:5682
Definition: api.h:175
Container class for static utility functions.
Definition: v8.h:4964
WeakCallbackData< Value, void >::Callback WeakCallback
Definition: v8.h:5249
static Local< Value > GetEternal(Isolate *isolate, int index)
Definition: api.cc:537
static void Eternalize(Isolate *isolate, Value *handle, int *index)
Definition: api.cc:530
static internal::Object ** GlobalizeReference(internal::Isolate *isolate, internal::Object **handle)
Definition: api.cc:494
static void MakeWeak(internal::Object **global_handle, void *data, WeakCallback weak_callback)
Definition: api.cc:513
static void DisposeGlobal(internal::Object **global_handle)
Definition: api.cc:525
static internal::Object ** CopyPersistent(internal::Object **handle)
Definition: api.cc:504
static void * ClearWeak(internal::Object **global_handle)
Definition: api.cc:520
The superclass of all JavaScript values and objects.
Definition: v8.h:1440
bool IsSet() const
Returns true if this value is a Set.
bool IsSymbolObject() const
Returns true if this value is a Symbol object.
static Value * Cast(T *value)
Definition: v8.h:6569
bool IsStringObject() const
Returns true if this value is a String object.
bool IsWeakMap() const
Returns true if this value is a WeakMap.
bool IsNumberObject() const
Returns true if this value is a Number object.
bool IsBooleanObject() const
Returns true if this value is a Boolean object.
bool IsUint32Array() const
Returns true if this value is an Uint32Array.
bool QuickIsUndefined() const
Definition: v8.h:6524
bool IsUint8ClampedArray() const
Returns true if this value is an Uint8ClampedArray.
bool IsWeakSet() const
Returns true if this value is a WeakSet.
bool IsString() const
Returns true if this value is an instance of the String type.
Definition: v8.h:6552
bool IsNull() const
Returns true if this value is the null value.
Definition: v8.h:6534
bool IsFloat64Array() const
Returns true if this value is a Float64Array.
bool IsMap() const
Returns true if this value is a Map.
bool IsInt16Array() const
Returns true if this value is an Int16Array.
bool QuickIsString() const
Definition: v8.h:6560
bool IsDate() const
Returns true if this value is a Date.
bool IsFloat32Array() const
Returns true if this value is a Float32Array.
bool QuickIsNull() const
Definition: v8.h:6542
bool IsUndefined() const
Returns true if this value is the undefined value.
Definition: v8.h:6516
bool IsInt8Array() const
Returns true if this value is an Int8Array.
bool IsArgumentsObject() const
Returns true if this value is an Arguments object.
bool IsUint8Array() const
Returns true if this value is an Uint8Array.
bool IsUint16Array() const
Returns true if this value is an Uint16Array.
bool IsInt32Array() const
Returns true if this value is an Int32Array.
Isolate * GetIsolate() const
Definition: v8.h:421
void(* Callback)(const WeakCallbackData< T, P > &data)
Definition: v8.h:419
WeakCallbackData(Isolate *isolate, Local< T > handle, P *parameter)
Definition: v8.h:427
Local< T > handle_
Definition: v8.h:430
P * GetParameter() const
Definition: v8.h:423
Local< T > GetValue() const
Definition: v8.h:422
Isolate * isolate_
Definition: v8.h:429
This class exports constants and functionality from within v8 that is necessary to implement inline f...
Definition: v8.h:5815
static internal::Object ** GetRoot(v8::Isolate *isolate, int index)
Definition: v8.h:5952
static bool IsExternalTwoByteString(int instance_type)
Definition: v8.h:5909
static const int kHeapObjectMapOffset
Definition: v8.h:5819
static int GetOddballKind(const internal::Object *obj)
Definition: v8.h:5904
static const int kOddballType
Definition: v8.h:5864
static const int kNodeStateIsNearDeathValue
Definition: v8.h:5858
static const int kStringEncodingMask
Definition: v8.h:5831
static const int kNodeIsIndependentShift
Definition: v8.h:5859
static const uint32_t kNumIsolateDataSlots
Definition: v8.h:5870
static uint8_t GetNodeFlag(internal::Object **obj, int shift)
Definition: v8.h:5914
static const int kForeignType
Definition: v8.h:5865
static int GetInstanceType(const internal::Object *obj)
Definition: v8.h:5896
static const int kIsolateRootsOffset
Definition: v8.h:5840
static T ReadEmbedderData(const v8::Context *context, int index)
Definition: v8.h:5966
static const int kUndefinedOddballKind
Definition: v8.h:5867
static void UpdateNodeState(internal::Object **obj, uint8_t value)
Definition: v8.h:5931
static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset
Definition: v8.h:5838
static void CheckInitialized(v8::Isolate *isolate)
Definition: v8.h:5873
static const int kJSObjectType
Definition: v8.h:5862
static const int kFullStringRepresentationMask
Definition: v8.h:5830
static T ReadField(const internal::Object *ptr, int offset)
Definition: v8.h:5959
static const int kFirstNonstringType
Definition: v8.h:5863
static const int kEmptyStringRootIndex
Definition: v8.h:5847
static const int kAmountOfExternalAllocatedMemoryOffset
Definition: v8.h:5836
static const int kFixedArrayHeaderSize
Definition: v8.h:5827
static const int kNullOddballKind
Definition: v8.h:5868
static const int kUndefinedValueRootIndex
Definition: v8.h:5843
static const int kExternalTwoByteRepresentationTag
Definition: v8.h:5832
static void CheckInitializedImpl(v8::Isolate *isolate)
static const int kNodeStateIsPendingValue
Definition: v8.h:5857
static const int kNodeStateMask
Definition: v8.h:5855
static uint8_t GetNodeState(internal::Object **obj)
Definition: v8.h:5926
static const int kNodeStateIsWeakValue
Definition: v8.h:5856
static const int kStringResourceOffset
Definition: v8.h:5822
static const int kFalseValueRootIndex
Definition: v8.h:5846
static const int kTrueValueRootIndex
Definition: v8.h:5845
static internal::Object * IntToSmi(int value)
Definition: v8.h:5888
static const int kOddballKindOffset
Definition: v8.h:5824
static int SmiValue(const internal::Object *value)
Definition: v8.h:5884
static const int kContextHeaderSize
Definition: v8.h:5828
static const int kExternalAllocationLimit
Definition: v8.h:5851
static void UpdateNodeFlag(internal::Object **obj, bool value, int shift)
Definition: v8.h:5919
static const int kNullValueRootIndex
Definition: v8.h:5844
static void SetEmbedderData(v8::Isolate *isolate, uint32_t slot, void *data)
Definition: v8.h:5937
static const int kExternalOneByteRepresentationTag
Definition: v8.h:5833
static bool IsValidSmi(intptr_t value)
Definition: v8.h:5892
static const int kForeignAddressOffset
Definition: v8.h:5825
static const int kIsolateEmbedderDataOffset
Definition: v8.h:5835
static void * GetEmbedderData(const v8::Isolate *isolate, uint32_t slot)
Definition: v8.h:5945
static const int kMapInstanceTypeAndBitFieldOffset
Definition: v8.h:5820
static const int kNodeIsPartiallyDependentShift
Definition: v8.h:5860
static const int kNodeFlagsOffset
Definition: v8.h:5854
static const int kNodeClassIdOffset
Definition: v8.h:5853
static const int kJSObjectHeaderSize
Definition: v8.h:5826
static bool HasHeapObjectTag(const internal::Object *value)
Definition: v8.h:5879
static const int kContextEmbedderDataIndex
Definition: v8.h:5829
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions true
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi space(in MBytes)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
enable harmony numeric enable harmony object literal extensions Optimize object Array shift
#define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
Definition: v8.h:2843
#define V8_EXPORT
Definition: v8.h:53
#define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
Definition: v8.h:2965
#define TYPE_CHECK(T, S)
Definition: v8.h:167
unsigned short uint16_t
Definition: unicode.cc:23
signed short int16_t
Definition: unicode.cc:22
int int32_t
Definition: unicode.cc:24
HANDLE HANDLE LPSTACKFRAME64 StackFrame
IN DWORD64 OUT PDWORD64 OUT PIMAGEHLP_SYMBOL64 Symbol
Handle< ObjectTemplateInfo > GetEternal(Isolate *isolate)
Definition: i18n.cc:208
static void Parse(Handle< JSFunction > function, CompilationInfoWithZone *info)
Definition: js-inlining.cc:56
const intptr_t kHeapObjectTagMask
Definition: v8.h:5739
const uint32_t kStringEncodingMask
Definition: objects.h:555
bool InitializeICU(const char *icu_data_file)
Definition: icu_util.cc:41
SmiTagging< kApiPointerSize > PlatformSmiTagging
Definition: v8.h:5804
static int min(int a, int b)
Definition: liveedit.cc:273
const int kSmiTagSize
Definition: v8.h:5743
const int kApiInt64Size
Definition: v8.h:5734
const int kApiIntSize
Definition: v8.h:5733
bool IsGeneratorFunction(FunctionKind kind)
Definition: globals.h:799
const int kApiPointerSize
Definition: v8.h:5732
int ToNumber(Register reg)
kSerializedDataOffset Object
Definition: objects-inl.h:5322
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
static bool SmiValuesAre32Bits()
Definition: v8.h:5808
internal::Object * IntToSmi(int value)
Definition: v8.h:5749
const int kHeapObjectTag
Definition: v8.h:5737
const int kSmiShiftSize
Definition: v8.h:5805
const int kSmiValueSize
Definition: v8.h:5806
static bool SmiValuesAre31Bits()
Definition: v8.h:5807
const intptr_t kSmiTagMask
Definition: v8.h:5744
const int kHeapObjectTagSize
Definition: v8.h:5738
const int kSmiTag
Definition: v8.h:5742
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
PropertyAttribute
Definition: v8.h:2210
@ DontEnum
Definition: v8.h:2213
@ None
Definition: v8.h:2211
@ DontDelete
Definition: v8.h:2214
@ ReadOnly
Definition: v8.h:2212
JitCodeEventOptions
Option flags passed to the SetJitCodeEventHandler function.
Definition: v8.h:4333
@ kJitCodeEventEnumExisting
Definition: v8.h:4336
@ kJitCodeEventDefault
Definition: v8.h:4334
void(* GCPrologueCallback)(GCType type, GCCallbackFlags flags)
Definition: v8.h:4216
static void SetFlagsFromString(const char *flags)
Definition: api.cc:7473
static int Utf8Length(i::String *str, i::Isolate *isolate)
Definition: api.cc:4549
void(* FailedAccessCheckCallback)(Local< Object > target, AccessType type, Local< Value > data)
Definition: v8.h:4182
void(* LogEventCallback)(const char *name, int event)
Definition: v8.h:4124
void(* MemoryAllocationCallback)(ObjectSpace space, AllocationAction action, int size)
Definition: v8.h:4171
GCCallbackFlags
Definition: v8.h:4209
@ kGCCallbackFlagConstructRetainedObjectInfos
Definition: v8.h:4212
@ kGCCallbackFlagForced
Definition: v8.h:4213
@ kNoGCCallbackFlags
Definition: v8.h:4210
@ kGCCallbackFlagCompacted
Definition: v8.h:4211
void(* MessageCallback)(Handle< Message > message, Handle< Value > error)
Definition: v8.h:4120
AccessControl
Access control specifications.
Definition: v8.h:2272
@ PROHIBITS_OVERWRITING
Definition: v8.h:2276
@ ALL_CAN_WRITE
Definition: v8.h:2275
@ ALL_CAN_READ
Definition: v8.h:2274
@ DEFAULT
Definition: v8.h:2273
void(* JitCodeEventHandler)(const JitCodeEvent *event)
Callback function passed to SetJitCodeEventHandler.
Definition: v8.h:4345
@ Exception
Definition: v8-debug.h:18
DeclaredAccessorDescriptorDataType
Definition: v8.h:3937
@ kDescriptorInt8Type
Definition: v8.h:3939
@ kDescriptorUint16Type
Definition: v8.h:3940
@ kDescriptorDoubleType
Definition: v8.h:3942
@ kDescriptorFloatType
Definition: v8.h:3942
@ kDescriptorInt16Type
Definition: v8.h:3940
@ kDescriptorUint8Type
Definition: v8.h:3939
@ kDescriptorUint32Type
Definition: v8.h:3941
@ kDescriptorInt32Type
Definition: v8.h:3941
@ kDescriptorBoolType
Definition: v8.h:3938
void(* AccessorNameSetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< void > &info)
Definition: v8.h:2257
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Returns the value of the property if the getter intercepts the request.
Definition: v8.h:3474
void(* GCEpilogueCallback)(GCType type, GCCallbackFlags flags)
Definition: v8.h:4217
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Returns the value if the setter intercepts the request.
Definition: v8.h:3483
void(* NamedPropertyGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
NamedProperty[Getter|Setter] are used as interceptors on object.
Definition: v8.h:3427
bool(* AllowCodeGenerationFromStringsCallback)(Local< Context > context)
Callback to check if code generation from strings is allowed.
Definition: v8.h:4192
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Returns a non-empty handle if the deleter intercepts the request.
Definition: v8.h:3503
void(* AddHistogramSampleCallback)(void *histogram, int sample)
Definition: v8.h:4149
int *(* CounterLookupCallback)(const char *name)
Definition: v8.h:4142
void(* NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Returns an array containing the names of the properties the named property getter intercepts.
Definition: v8.h:3466
void(* MicrotaskCallback)(void *data)
Definition: v8.h:4179
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Accessor[Getter|Setter] are used as callback functions when setting|getting a particular property.
Definition: v8.h:2245
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
ReturnAddressLocationResolver is used as a callback function when v8 is resolving the location of a r...
Definition: v8.h:4936
void(* CallCompletedCallback)()
Definition: v8.h:4176
void(* AccessorSetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< void > &info)
Definition: v8.h:2253
Maybe< T > maybe(T t)
Definition: v8.h:902
void(* AccessorNameGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:2248
void(* NamedPropertySetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Returns the value if the setter intercepts the request.
Definition: v8.h:3436
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Returns a non-empty handle if the interceptor intercepts the request.
Definition: v8.h:3493
void(* FunctionCallback)(const FunctionCallbackInfo< Value > &info)
Definition: v8.h:2717
Handle< Boolean > False(Isolate *isolate)
Definition: v8.h:6863
void RegisterExtension(Extension *that)
Definition: api.cc:398
void(* NamedPropertyDeleterCallback)(Local< String > property, const PropertyCallbackInfo< Boolean > &info)
Returns a non-empty handle if the deleter intercepts the request.
Definition: v8.h:3457
ExternalArrayType
Definition: v8.h:2217
@ kExternalFloat32Array
Definition: v8.h:2224
@ kExternalIntArray
Definition: v8.h:2233
@ kExternalUnsignedByteArray
Definition: v8.h:2230
@ kExternalInt32Array
Definition: v8.h:2222
@ kExternalUint32Array
Definition: v8.h:2223
@ kExternalUint16Array
Definition: v8.h:2221
@ kExternalPixelArray
Definition: v8.h:2237
@ kExternalShortArray
Definition: v8.h:2231
@ kExternalFloatArray
Definition: v8.h:2235
@ kExternalInt8Array
Definition: v8.h:2218
@ kExternalUint8Array
Definition: v8.h:2219
@ kExternalInt16Array
Definition: v8.h:2220
@ kExternalDoubleArray
Definition: v8.h:2236
@ kExternalUnsignedIntArray
Definition: v8.h:2234
@ kExternalUint8ClampedArray
Definition: v8.h:2226
@ kExternalUnsignedShortArray
Definition: v8.h:2232
@ kExternalFloat64Array
Definition: v8.h:2225
@ kExternalByteArray
Definition: v8.h:2229
void(* FunctionEntryHook)(uintptr_t function, uintptr_t return_addr_location)
FunctionEntryHook is the type of the profile entry hook called at entry to any generated function whe...
Definition: v8.h:4263
void *(* CreateHistogramCallback)(const char *name, int min, int max, size_t buckets)
Definition: v8.h:4144
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
Returns true if cross-context access should be allowed to the named property with the given key on th...
Definition: v8.h:3532
bool(* EntropySource)(unsigned char *buffer, size_t length)
EntropySource is used as a callback function when v8 needs a source of entropy.
Definition: v8.h:4920
void(* FatalErrorCallback)(const char *location, const char *message)
Definition: v8.h:4117
GCType
Applications can register callback functions which will be called before and after a garbage collecti...
Definition: v8.h:4203
@ kGCTypeScavenge
Definition: v8.h:4204
@ kGCTypeMarkSweepCompact
Definition: v8.h:4205
@ kGCTypeAll
Definition: v8.h:4206
void(* NamedPropertyQueryCallback)(Local< String > property, const PropertyCallbackInfo< Integer > &info)
Returns a non-empty handle if the interceptor intercepts the request.
Definition: v8.h:3447
Handle< Boolean > True(Isolate *isolate)
Definition: v8.h:6854
Handle< Primitive > Null(Isolate *isolate)
Definition: v8.h:6845
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Returns an array containing the indices of the properties the indexed property getter intercepts.
Definition: v8.h:3512
AccessType
Access type specification.
Definition: v8.h:3519
@ ACCESS_SET
Definition: v8.h:3521
@ ACCESS_HAS
Definition: v8.h:3522
@ ACCESS_KEYS
Definition: v8.h:3524
@ ACCESS_GET
Definition: v8.h:3520
@ ACCESS_DELETE
Definition: v8.h:3523
AllocationAction
Definition: v8.h:4165
@ kAllocationActionAllocate
Definition: v8.h:4166
@ kAllocationActionAll
Definition: v8.h:4168
@ kAllocationActionFree
Definition: v8.h:4167
ObjectSpace
Definition: v8.h:4152
@ kObjectSpaceAll
Definition: v8.h:4160
@ kObjectSpaceMapSpace
Definition: v8.h:4157
@ kObjectSpaceNewSpace
Definition: v8.h:4153
@ kObjectSpaceOldDataSpace
Definition: v8.h:4155
@ kObjectSpaceOldPointerSpace
Definition: v8.h:4154
@ kObjectSpaceLoSpace
Definition: v8.h:4158
@ kObjectSpaceCodeSpace
Definition: v8.h:4156
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
Returns true if cross-context access should be allowed to the indexed property with the given index o...
Definition: v8.h:3542
void(* InterruptCallback)(Isolate *isolate, void *data)
Definition: v8.h:4219
Handle< Primitive > Undefined(Isolate *isolate)
Definition: v8.h:6836
#define P(name, number_of_args, result_size)
Definition: runtime.cc:53
#define I(name, number_of_args, result_size)
Definition: runtime.cc:9248
Helper class traits to allow copying and assignment of Persistent.
Definition: v8.h:608
static const bool kResetInDestructor
Definition: v8.h:610
Persistent< T, CopyablePersistentTraits< T > > CopyablePersistent
Definition: v8.h:609
static void Copy(const Persistent< S, M > &source, CopyablePersistent *dest)
Definition: v8.h:612
Initial configuration parameters for a new Isolate.
Definition: v8.h:4361
ResourceConstraints constraints
ResourceConstraints to use for the new Isolate.
Definition: v8.h:4385
bool enable_serializer
This flag currently renders the Isolate unusable.
Definition: v8.h:4390
JitCodeEventHandler code_event_handler
Allows the host application to provide the address of a function that is notified each time code is a...
Definition: v8.h:4380
FunctionEntryHook entry_hook
The optional entry_hook allows the host application to provide the address of a function that's invok...
Definition: v8.h:4374
PositionType position_type
Definition: v8.h:4315
const char * str
Definition: v8.h:4304
A JIT code event is issued each time code is added, moved or removed.
Definition: v8.h:4271
@ STATEMENT_POSITION
Definition: v8.h:4285
struct name_t name
Definition: v8.h:4320
Handle< UnboundScript > script
Definition: v8.h:4294
struct line_info_t line_info
Definition: v8.h:4323
void * user_data
Definition: v8.h:4299
void * new_code_start
Definition: v8.h:4326
@ CODE_END_LINE_INFO_RECORDING
Definition: v8.h:4278
@ CODE_ADD_LINE_POS_INFO
Definition: v8.h:4276
@ CODE_REMOVED
Definition: v8.h:4275
@ CODE_START_LINE_INFO_RECORDING
Definition: v8.h:4277
EventType type
Definition: v8.h:4288
size_t code_len
Definition: v8.h:4292
void * code_start
Definition: v8.h:4290
A simple Maybe type, representing an object which may or may not have a value.
Definition: v8.h:890
T value
Definition: v8.h:896
Maybe(T t)
Definition: v8.h:892
Maybe()
Definition: v8.h:891
Maybe(bool has, T t)
Definition: v8.h:893
bool has_value
Definition: v8.h:895
Compilation data that the embedder can cache and pass back to speed up future compilations.
Definition: v8.h:1028
CachedData(const CachedData &)
BufferPolicy buffer_policy
Definition: v8.h:1047
const uint8_t * data
Definition: v8.h:1045
CachedData & operator=(const CachedData &)
RValue(UniquePersistent *obj)
Definition: v8.h:725
UniquePersistent * object
Definition: v8.h:726
static int SmiValueSize()
Definition: v8.h:5760
static bool IsValidSmi(intptr_t value)
Definition: v8.h:5769
static internal::Object * IntToSmi(int value)
Definition: v8.h:5766
static int SmiShiftSize()
Definition: v8.h:5759
static int SmiToInt(const internal::Object *value)
Definition: v8.h:5761
static int SmiShiftSize()
Definition: v8.h:5788
static internal::Object * IntToSmi(int value)
Definition: v8.h:5795
static int SmiValueSize()
Definition: v8.h:5789
static int SmiToInt(const internal::Object *value)
Definition: v8.h:5790
static bool IsValidSmi(intptr_t value)
Definition: v8.h:5798
#define T(name, string, precedence)
Definition: token.cc:25
#define V8_INLINE
Definition: v8config.h:306
#define V8_LIKELY(condition)
Definition: v8config.h:343
#define V8_UNLIKELY(condition)
Definition: v8config.h:342
#define S(x)
Definition: version.cc:55