v8.h revision 8a31eba00023874d4a1dcdc5f411cc4336776874
1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2007-2009 the V8 project authors. All rights reserved.
2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without
3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are
4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met:
5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions of source code must retain the above copyright
7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       notice, this list of conditions and the following disclaimer.
8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions in binary form must reproduce the above
9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       copyright notice, this list of conditions and the following
10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       disclaimer in the documentation and/or other materials provided
11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       with the distribution.
12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Neither the name of Google Inc. nor the names of its
13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       contributors may be used to endorse or promote products derived
14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       from this software without specific prior written permission.
15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** \mainpage V8 API Reference Guide
29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 is Google's open source JavaScript engine.
31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This set of documents provides reference material generated from the
33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 header file, include/v8.h.
34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * For other documentation see http://code.google.com/apis/v8/
36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_H_
39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_H_
40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
413e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu#include "v8stdint.h"
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef _WIN32
44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Windows DLL export/import. When building the V8 DLL the
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// BUILDING_V8_SHARED needs to be defined. When building a program which uses
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// static library or building a program which uses the V8 static library neither
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  build configuration to ensure that at most one of these is set
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef BUILDING_V8_SHARED
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __declspec(dllexport)
57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#elif USING_V8_SHARED
58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __declspec(dllimport)
59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT
61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // BUILDING_V8_SHARED
62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else  // _WIN32
64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Linux shared library export. There is no need to distinguish
66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// between building or using the V8 shared library, but we should not
67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// export symbols when we are building a static library.
68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __attribute__ ((visibility("default")))
70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else  // defined(__GNUC__) && (__GNUC__ >= 4)
71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT
72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // defined(__GNUC__) && (__GNUC__ >= 4)
73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // _WIN32
75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The v8 JavaScript engine.
78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 {
80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Context;
82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass String;
83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Value;
84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Utils;
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Number;
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Object;
87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Array;
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Int32;
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Uint32;
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass External;
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Primitive;
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Boolean;
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Integer;
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Function;
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Date;
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ImplementationUtilities;
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Signature;
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Handle;
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Local;
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Persistent;
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass FunctionTemplate;
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ObjectTemplate;
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Data;
104f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeclass AccessorInfo;
10525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackTrace;
10625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackFrame;
107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Arguments;
111d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blockclass Object;
1127f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochclass Heap;
113d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blockclass Top;
114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- W e a k  H a n d l e s
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A weak reference callback function.
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
12350ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * This callback should either explicitly invoke Dispose on |object| if
12450ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak.
12550ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen *
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param object the weak global object to be reclaimed by the garbage collector
127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param parameter the value passed in when making the weak global object
128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*WeakReferenceCallback)(Persistent<Value> object,
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      void* parameter);
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- H a n d l e s ---
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
13550ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen#define TYPE_CHECK(T, S)                                       \
13650ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen  while (false) {                                              \
13750ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen    *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference managed by the v8 garbage collector.
142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * All objects returned from v8 have to be tracked by the garbage
144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * collector so that it knows that the objects are still alive.  Also,
145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * because the garbage collector may move objects, it is unsafe to
146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * point directly to an object.  Instead, all objects are stored in
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles which are known by the garbage collector and updated
148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * whenever an object moves.  Handles should always be passed by value
149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * (except in cases like out-parameters) and they should never be
150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated on the heap.
151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * There are two types of handles: local and persistent handles.
153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local handles are light-weight and transient and typically used in
154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * local operations.  They are managed by HandleScopes.  Persistent
155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles can be used when storing objects across several independent
156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operations and have to be explicitly deallocated when they're no
157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * longer used.
158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * It is safe to extract the object stored in the handle by
160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * dereferencing the handle (for instance, to extract the Object* from
161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * an Handle<Object>); the value will still be governed by a handle
162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * behind the scenes and the same rules apply to these values as to
163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * their handles.
164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1658defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Handle {
166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates an empty handle.
170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle();
172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new handle for the specified value.
175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1768defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline explicit Handle(T* val) : val_(val) { }
177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a handle for the contents of the specified handle.  This
180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * constructor allows you to pass handles as arguments by value and
181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to assign between handles.  However, if you try to assign between
182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * incompatible handles, for instance from a Handle<String> to a
183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Handle<Number> it will cause a compiletime error.  Assigning
184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * between compatible handles, for instance assigning a
185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Handle<String> to a variable declared as Handle<Value>, is legal
186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * because String is a subclass of Value.
187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Handle(Handle<S> that)
189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : val_(reinterpret_cast<T*>(*that)) {
190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the handle is empty.
200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2018defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline bool IsEmpty() const { return val_ == 0; }
202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2038defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline T* operator->() const { return val_; }
204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2058defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline T* operator*() const { return val_; }
206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the handle to be empty. IsEmpty() will then return true.
209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2108defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline void Clear() { this->val_ = 0; }
211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Checks whether two handles are the same.
214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if both are empty, or if the objects
215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to which they refer are identical.
216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The handles' references are not checked.
217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2188defd9ff6930b4e24729971a61cf7469daf119beSteve Block  template <class S> inline bool operator==(Handle<S> that) const {
219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** a = reinterpret_cast<internal::Object**>(**this);
220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** b = reinterpret_cast<internal::Object**>(*that);
221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (a == 0) return b == 0;
222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (b == 0) return false;
223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return *a == *b;
224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Checks whether two handles are different.
228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if only one of the handles is empty, or if
229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the objects to which they refer are different.
230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The handles' references are not checked.
231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2328defd9ff6930b4e24729971a61cf7469daf119beSteve Block  template <class S> inline bool operator!=(Handle<S> that) const {
233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return !operator==(that);
234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Handle<T> Cast(Handle<S> that) {
237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Handle<T>();
241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Handle<T>(T::Cast(*that));
243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2456ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Handle<S> As() {
2466ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Handle<S>::Cast(*this);
2476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
2486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  T* val_;
251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A light-weight stack-allocated object handle.  All operations
256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that return objects from within v8 return them in local handles.  They
257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are created within HandleScopes, and all local handles allocated within a
258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope are destroyed when the handle scope is destroyed.  Hence it
259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is not necessary to explicitly deallocate local handles.
260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2618defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Local : public Handle<T> {
262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local();
264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Local(Local<S> that)
265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(reinterpret_cast<T*>(*that)) {
266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Local(S* that) : Handle<T>(that) { }
274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Local<T> Cast(Local<S> that) {
275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Local<T>();
279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<T>(T::Cast(*that));
281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Local<S> As() {
2846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Local<S>::Cast(*this);
2856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
2866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Create a local handle for the content of another handle.
288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *  The referee is kept alive by the local handle even when
289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *  the original handle is destroyed/disposed.
290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline static Local<T> New(Handle<T> that);
292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference that is independent of any handle scope.  Where
297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a Local handle only lives as long as the HandleScope in which it was
298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated, a Persistent handle remains valid until it is explicitly
299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * disposed.
300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A persistent handle contains a reference to a storage cell within
302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the v8 engine which holds an object value and which is updated by
303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the garbage collector whenever the object is moved.  A new storage
304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * cell can be created using Persistent::New and existing handles can
305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be disposed using Persistent::Dispose.  Since persistent handles
306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are passed by value you may have many persistent handle objects
307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that point to the same storage cell.  For instance, if you pass a
308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * persistent handle as an argument to a function you will not get two
309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * different storage cells but rather two references to the same
310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * storage cell.
311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3128defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Persistent : public Handle<T> {
313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates an empty persistent handle that doesn't point to any
317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * storage cell.
318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Persistent();
320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a persistent handle for the same storage cell as the
323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * specified handle.  This constructor allows you to pass persistent
324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handles as arguments by value and to assign between persistent
325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handles.  However, attempting to assign between incompatible
326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * persistent handles, for instance from a Persistent<String> to a
327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Persistent<Number> will cause a compiletime error.  Assigning
328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * between compatible persistent handles, for instance assigning a
329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Persistent<String> to a variable declared as Persistent<Value>,
330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is allowed as String is a subclass of Value.
331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Persistent(Persistent<S> that)
333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(reinterpret_cast<T*>(*that)) {
334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Persistent(S* that) : Handle<T>(that) { }
343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * "Casts" a plain handle which is known to be a persistent handle
346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to a persistent handle.
347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> explicit inline Persistent(Handle<S> that)
349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(*that) { }
350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Persistent<T>();
356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Persistent<T>(T::Cast(*that));
358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Persistent<S> As() {
3616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Persistent<S>::Cast(*this);
3626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
3636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new persistent handle for an existing local or
366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * persistent handle.
367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline static Persistent<T> New(Handle<T> that);
369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Releases the storage cell referenced by this persistent handle.
372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Does not remove the reference to the cell from any handles.
373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This handle's reference, and any any other references to the storage
374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * cell remain and IsEmpty will still return false.
375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Dispose();
377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Make the reference to this object weak.  When only weak handles
380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * refer to the object, the garbage collector will perform a
381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback to the given V8::WeakReferenceCallback function, passing
382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * it the object reference and the given parameters.
383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Clears the weak reference to this object.*/
387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ClearWeak();
388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *Checks if the handle holds the only reference to an object.
391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsNearDeath() const;
393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the handle's reference is weak.
396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsWeak() const;
398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /**
406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A stack-allocated class that governs a number of local handles.
407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After a handle scope has been created, all local handles will be
408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated within that handle scope until either the handle scope is
409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * deleted or another handle scope is created.  If there is already a
410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope and a new one is created, all allocations will take
411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * place in the new handle scope until it is deleted.  After that,
412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * new handles will again be allocated in the original handle scope.
413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After the handle scope of a local handle has been deleted the
415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * garbage collector will no longer track the object stored in the
416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle and may deallocate it.  The behavior of accessing a handle
417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for which the handle scope has been deleted is undefined.
418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT HandleScope {
420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  HandleScope();
422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~HandleScope();
424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Closes the handle scope and returns the value as a handle in the
427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * previous scope, which is the new current scope after the call.
428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> Local<T> Close(Handle<T> value);
430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Counts the number of allocated handles.
433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int NumberOfHandles();
435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new handle with the given value.
438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static internal::Object** CreateHandle(internal::Object* value);
440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Make it impossible to create heap-allocated or illegal handle
443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // scopes by disallowing certain operations.
444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  HandleScope(const HandleScope&);
445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const HandleScope&);
446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* operator new(size_t size);
447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator delete(void*, size_t);
448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
449d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // This Data class is accessible internally as HandleScopeData through a
450d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // typedef in the ImplementationUtilities class.
451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Data {
452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** next;
454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** limit;
4555913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    int level;
4565913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline void Initialize() {
458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      next = limit = NULL;
4595913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      level = 0;
460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
4623e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu
4635913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  void Leave();
464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4653e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu
4665913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  internal::Object** prev_next_;
4675913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  internal::Object** prev_limit_;
468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Allow for the active closing of HandleScopes which allows to pass a handle
470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // from the HandleScope being closed to the next top most HandleScope.
471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_closed_;
472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** RawClose(internal::Object** value);
473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- S p e c i a l   o b j e c t s ---
479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of values and API object templates.
483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Data {
485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Data();
487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Pre-compilation data that can be associated with a script.  This
492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data can be calculated for a script in advance of actually
493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * compiling it, and can be stored between compilations.  When script
494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data is given to the compile method compilation will be faster.
495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ScriptData {  // NOLINT
497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~ScriptData() { }
4997f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
500f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
501f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Pre-compiles the specified script (context-independent).
502f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
503f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param input Pointer to UTF-8 script source code.
504f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param length Length of UTF-8 script source code.
505f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static ScriptData* PreCompile(const char* input, int length);
507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
508f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
5097f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * Pre-compiles the specified script (context-independent).
5107f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   *
5117f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * NOTE: Pre-compilation using this method cannot happen on another thread
5127f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * without using Lockers.
5137f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   *
5147f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * \param source Script source code.
5157f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   */
5167f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static ScriptData* PreCompile(Handle<String> source);
5177f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
5187f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  /**
519f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Load previous pre-compilation data.
520f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
521f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param data Pointer to data returned by a call to Data() of a previous
522f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *   ScriptData. Ownership is not transferred.
523f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param length Length of data.
524f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
525f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  static ScriptData* New(const char* data, int length);
526f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
527f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
528f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns the length of Data().
529f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual int Length() = 0;
531f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
532f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
533f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns a serialized representation of this ScriptData that can later be
534f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * passed to New(). NOTE: Serialized data is platform-dependent.
535f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
536f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  virtual const char* Data() = 0;
537f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
538f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
539f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns true if the source code could not be parsed.
540f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
541e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  virtual bool HasError() = 0;
542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The origin, within a file, of a script.
547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
5488defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass ScriptOrigin {
549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5508defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline ScriptOrigin(
5518defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Value> resource_name,
5528defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Integer> resource_line_offset = Handle<Integer>(),
5538defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Integer> resource_column_offset = Handle<Integer>())
554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : resource_name_(resource_name),
555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        resource_line_offset_(resource_line_offset),
556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        resource_column_offset_(resource_column_offset) { }
557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Value> ResourceName() const;
558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Integer> ResourceLineOffset() const;
559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Integer> ResourceColumnOffset() const;
560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> resource_name_;
562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Integer> resource_line_offset_;
563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Integer> resource_column_offset_;
564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A compiled JavaScript script.
569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Script {
571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
573402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
574402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script (context-independent).
575402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
576402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
5776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param origin Script origin, owned by caller, no references are kept
578402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when New() returns
579402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
580402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   using pre_data speeds compilation if it's done multiple times.
581402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   Owned by caller, no references are kept when New() returns.
582402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
5836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *   this has same effect as calling SetData(), but allows data to be
584402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   available to compile event handlers.
585402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object (context independent; when run it
586402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   will use the currently entered context).
587402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
588402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static Local<Script> New(Handle<String> source,
589402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           ScriptOrigin* origin = NULL,
590402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           ScriptData* pre_data = NULL,
591402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           Handle<String> script_data = Handle<String>());
592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
593402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
594402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script using the specified file name
595402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * object (typically a string) as the script's origin.
596402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
597402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
5986ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param file_name file name object (typically a string) to be used
599402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   as the script's origin.
600402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object (context independent; when run it
601402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   will use the currently entered context).
602402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
603402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static Local<Script> New(Handle<String> source,
604402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           Handle<Value> file_name);
605402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
606402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
607402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script (bound to current context).
608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
609402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
6106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param origin Script origin, owned by caller, no references are kept
611402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when Compile() returns
612402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
613402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   using pre_data speeds compilation if it's done multiple times.
614402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   Owned by caller, no references are kept when Compile() returns.
615402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
616402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   this has same effect as calling SetData(), but makes data available
617402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   earlier (i.e. to compile event handlers).
618402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object, bound to the context that was active
619402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when this function was called.  When run it will always use this
620402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   context.
621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Script> Compile(Handle<String> source,
623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               ScriptOrigin* origin = NULL,
624402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               ScriptData* pre_data = NULL,
625402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<String> script_data = Handle<String>());
626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Compiles the specified script using the specified file name
629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * object (typically a string) as the script's origin.
630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
631402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
632402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param file_name File name to use as script's origin
633402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
634402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   this has same effect as calling SetData(), but makes data available
635402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   earlier (i.e. to compile event handlers).
636402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object, bound to the context that was active
637402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when this function was called.  When run it will always use this
638402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   context.
639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Script> Compile(Handle<String> source,
641402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<Value> file_name,
642402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<String> script_data = Handle<String>());
643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Runs the script returning the resulting value.  If the script is
646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context independent (created using ::New) it will be run in the
647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * currently entered context.  If it is context specific (created
648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * using ::Compile) it will be run in the context in which it was
649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * compiled.
650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Run();
652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the script id value.
655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Id();
657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an additional data object with the script. This is mainly used
660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * with the debugger as this data object is only available through the
661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * debugger API.
662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
663d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void SetData(Handle<String> data);
664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An error message.
669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Message {
671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<String> Get() const;
673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<String> GetSourceLine() const;
674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the resource name for the script from where the function causing
677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error originates.
678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetScriptResourceName() const;
680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the resource data for the script from where the function causing
683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error originates.
684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetScriptData() const;
686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
6883bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * Exception stack trace. By default stack traces are not captured for
6893bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
6903bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * to change this option.
6913bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   */
6923bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  Handle<StackTrace> GetStackTrace() const;
6933bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
6943bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  /**
695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number, 1-based, of the line where the error occurred.
696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetLineNumber() const;
698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the script of the first character where
701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetStartPosition() const;
704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the script of the last character where
707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetEndPosition() const;
710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the line of the first character where
713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetStartColumn() const;
716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the line of the last character where
719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetEndColumn() const;
722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // TODO(1245381): Print to a string instead of on a FILE.
724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void PrintCurrentStackTrace(FILE* out);
72525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
72625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kNoLineNumberInfo = 0;
72725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kNoColumnInfo = 0;
72825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen};
72925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
73025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
73125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/**
73225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Representation of a JavaScript stack trace. The information collected is a
73325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * snapshot of the execution stack and the information remains valid after
73425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * execution continues.
73525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */
73625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackTrace {
73725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public:
73825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
73925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Flags that determine what information is placed captured for each
74025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * StackFrame when grabbing the current stack trace.
74125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
74225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  enum StackTraceOptions {
74325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kLineNumber = 1,
74425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kColumnOffset = 1 << 1 | kLineNumber,
74525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kScriptName = 1 << 2,
74625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kFunctionName = 1 << 3,
74725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kIsEval = 1 << 4,
74825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kIsConstructor = 1 << 5,
749f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kScriptNameOrSourceURL = 1 << 6,
75025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
751f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
75225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  };
75325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
75425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
75525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns a StackFrame at a particular index.
75625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
75725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<StackFrame> GetFrame(uint32_t index) const;
75825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
75925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
76025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the number of StackFrames.
76125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
76225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetFrameCount() const;
76325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
76425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
76525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns StackTrace as a v8::Array that contains StackFrame objects.
76625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
76725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<Array> AsArray();
76825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
76925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
77025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Grab a snapshot of the the current JavaScript execution stack.
77125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   *
77225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * \param frame_limit The maximum number of stack frames we want to capture.
77325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * \param options Enumerates the set of things we will capture for each
77425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   *   StackFrame.
77525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
77625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static Local<StackTrace> CurrentStackTrace(
77725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen      int frame_limit,
77825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen      StackTraceOptions options = kOverview);
77925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen};
78025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
78125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
78225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/**
78325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * A single JavaScript stack frame.
78425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */
78525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackFrame {
78625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public:
78725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
78825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the number, 1-based, of the line for the associate function call.
78925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * This method will return Message::kNoLineNumberInfo if it is unable to
79025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * retrieve the line number, or if kLineNumber was not passed as an option
79125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * when capturing the StackTrace.
79225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
79325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetLineNumber() const;
79425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
79525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
79625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the 1-based column offset on the line for the associated function
79725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * call.
79825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * This method will return Message::kNoColumnInfo if it is unable to retrieve
79925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * the column number, or if kColumnOffset was not passed as an option when
80025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * capturing the StackTrace.
80125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
80225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetColumn() const;
80325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
80425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
80525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the name of the resource that contains the script for the
80625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * function for this StackFrame.
80725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
80825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<String> GetScriptName() const;
80925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
81025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
811f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Returns the name of the resource that contains the script for the
812f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * function for this StackFrame or sourceURL value if the script name
813f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * is undefined and its source ends with //@ sourceURL=... string.
814f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
815f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  Local<String> GetScriptNameOrSourceURL() const;
816f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
817f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
81825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the name of the function associated with this stack frame.
81925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
82025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<String> GetFunctionName() const;
82125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
82225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
82325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns whether or not the associated function is compiled via a call to
82425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * eval().
82525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
82625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  bool IsEval() const;
82725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
82825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
82925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns whther or not the associated function is called as a
83025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * constructor via "new".
83125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
83225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  bool IsConstructor() const;
833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- V a l u e ---
837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of all JavaScript values and objects.
841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
8428defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Value : public Data {
843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is the undefined value.  See ECMA-262
847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 4.3.10.
848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8498defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsUndefined() const;
850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is the null value.  See ECMA-262
853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 4.3.11.
854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8558defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsNull() const;
856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   /**
858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is true.
859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsTrue() const;
861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is false.
864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8658defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsFalse() const;
866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an instance of the String type.
869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ECMA-262 8.4.
870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsString() const;
872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a function.
875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8768defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsFunction() const;
877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an array.
880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsArray() const;
882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an object.
885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8868defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsObject() const;
887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is boolean.
890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8918defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsBoolean() const;
892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a number.
895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8968defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsNumber() const;
897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is external.
900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9018defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternal() const;
902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a 32-bit signed integer.
905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9068defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsInt32() const;
907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
9096ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Returns true if this value is a 32-bit unsigned integer.
9106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
9118defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsUint32() const;
9126ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
9136ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a Date.
915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9168defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsDate() const;
917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
918756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  /**
919756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   * Returns true if this value is a RegExp.
920756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   */
921756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V8EXPORT bool IsRegExp() const;
922756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
9238defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Boolean> ToBoolean() const;
9248defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Number> ToNumber() const;
9258defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ToString() const;
9268defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ToDetailString() const;
9278defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> ToObject() const;
9288defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Integer> ToInteger() const;
9298defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Uint32> ToUint32() const;
9308defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Int32> ToInt32() const;
931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Attempts to convert a string to an array index.
934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns an empty handle if the conversion fails.
935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9368defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Uint32> ToArrayIndex() const;
937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
9388defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool BooleanValue() const;
9398defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double NumberValue() const;
9408defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int64_t IntegerValue() const;
9418defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Uint32Value() const;
9428defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int32_t Int32Value() const;
943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** JS == */
9458defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Equals(Handle<Value> that) const;
9468defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool StrictEquals(Handle<Value> that) const;
9473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool QuickIsString() const;
9508defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool FullIsString() const;
951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of primitive values.  See ECMA-262 4.3.2.
956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
9578defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Primitive : public Value { };
958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A primitive boolean value (ECMA-262, 4.3.14).  Either the true
962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * or false value.
963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
9648defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Boolean : public Primitive {
965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
9668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Value() const;
967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Handle<Boolean> New(bool value);
968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript string value (ECMA-262, 4.3.17).
973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
9748defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass String : public Primitive {
975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number of characters in this string.
979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9808defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Length() const;
981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number of bytes in the UTF-8 encoded
984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * representation of this string.
985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9868defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Utf8Length() const;
987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Write the contents of the string to an external buffer.
990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If no arguments are given, expects the buffer to be large
991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enough to hold the entire string and NULL terminator. Copies
992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the contents of the string and the NULL terminator into the
993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer.
994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Copies up to length characters into the output buffer.
996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Only null-terminates if there is enough space in the buffer.
997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param buffer The buffer into which the string will be copied.
999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param start The starting position within the string at which
1000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * copying begins.
1001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param length The number of bytes to copy from the string.
10026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param nchars_ref The number of characters written, can be NULL.
10036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param hints Various hints that might affect performance of this or
10046ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *    subsequent operations.
10056ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \return The number of bytes copied to the buffer
1006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * excluding the NULL terminator.
1007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10086ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  enum WriteHints {
10096ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    NO_HINTS = 0,
10106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    HINT_MANY_WRITES_EXPECTED = 1
10116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  };
10126ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
10138defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Write(uint16_t* buffer,
10148defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     int start = 0,
10158defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     int length = -1,
10168defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     WriteHints hints = NO_HINTS) const;  // UTF-16
10178defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int WriteAscii(char* buffer,
10188defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          int start = 0,
10198defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          int length = -1,
10208defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          WriteHints hints = NO_HINTS) const;  // ASCII
10218defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int WriteUtf8(char* buffer,
10228defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         int length = -1,
10238defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         int* nchars_ref = NULL,
10248defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         WriteHints hints = NO_HINTS) const;  // UTF-8
1025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A zero length string.
1028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10298defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static v8::Local<v8::String> Empty();
1030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string is external
1033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10348defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternal() const;
1035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string is both external and ascii
1038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10398defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternalAscii() const;
1040e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
10413e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  class V8EXPORT ExternalStringResourceBase {  // NOLINT
1042e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   public:
1043e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    virtual ~ExternalStringResourceBase() {}
10447f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1045e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   protected:
1046e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    ExternalStringResourceBase() {}
10477f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
10487f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
10497f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * Internally V8 will call this Dispose method when the external string
10507f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * resource is no longer needed. The default implementation will use the
10517f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * delete operator. This method can be overridden in subclasses to
10527f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * control how allocated external string resources are disposed.
10537f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
10547f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    virtual void Dispose() { delete this; }
10557f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1056e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   private:
1057e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    // Disallow copying and assigning.
1058e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    ExternalStringResourceBase(const ExternalStringResourceBase&);
1059e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    void operator=(const ExternalStringResourceBase&);
10607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
10617f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    friend class v8::internal::Heap;
1062e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  };
1063e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
1064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * An ExternalStringResource is a wrapper around a two-byte string
1066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer that resides outside V8's heap. Implement an
1067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ExternalStringResource to manage the life cycle of the underlying
1068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer.  Note that the string data must be immutable.
1069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1070e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  class V8EXPORT ExternalStringResource
1071e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      : public ExternalStringResourceBase {
1072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
1074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Override the destructor to manage the life cycle of the underlying
1075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * buffer.
1076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
1077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~ExternalStringResource() {}
10787f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
10797f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
10807f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * The string data from the underlying buffer.
10817f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
1082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual const uint16_t* data() const = 0;
10837f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
10847f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
10857f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * The length of the string. That is, the number of two-byte characters.
10867f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
1087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual size_t length() const = 0;
10887f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   protected:
1090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalStringResource() {}
1091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * An ExternalAsciiStringResource is a wrapper around an ascii
1095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * string buffer that resides outside V8's heap. Implement an
1096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ExternalAsciiStringResource to manage the life cycle of the
1097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * underlying buffer.  Note that the string data must be immutable
1098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * and that the data must be strict 7-bit ASCII, not Latin1 or
1099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * UTF-8, which would require special treatment internally in the
1100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * engine and, in the case of UTF-8, do not allow efficient indexing.
1101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Use String::New or convert to 16 bit data for non-ASCII.
1102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1104e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  class V8EXPORT ExternalAsciiStringResource
1105e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      : public ExternalStringResourceBase {
1106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
1108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Override the destructor to manage the life cycle of the underlying
1109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * buffer.
1110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
1111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~ExternalAsciiStringResource() {}
1112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /** The string data from the underlying buffer.*/
1113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual const char* data() const = 0;
1114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /** The number of ascii characters in the string.*/
1115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual size_t length() const = 0;
1116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   protected:
1117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalAsciiStringResource() {}
1118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the ExternalStringResource for an external string.  Returns
1122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * NULL if IsExternal() doesn't return true.
1123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline ExternalStringResource* GetExternalStringResource() const;
1125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the ExternalAsciiStringResource for an external ascii string.
1128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns NULL if IsExternalAscii() doesn't return true.
1129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11308defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
1131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline String* Cast(v8::Value* obj);
1133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Allocates a new string from either utf-8 encoded or ascii data.
1136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The second parameter 'length' gives the buffer length.
1137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If the data is utf-8 encoded, the caller must
1138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be careful to supply the length parameter.
1139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If it is not given, the function calls
1140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 'strlen' to determine the buffer length, it might be
1141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * wrong if 'data' contains a null character.
1142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11438defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> New(const char* data, int length = -1);
1144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Allocates a new string from utf16 data.*/
11468defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> New(const uint16_t* data, int length = -1);
1147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a symbol. Returns one if it exists already.*/
11498defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1);
1150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
11523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Creates a new string by concatenating the left and the right strings
11533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * passed in as parameters.
11543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
11558defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> Concat(Handle<String> left,
11568defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                       Handle<String>right);
11573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
11583ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
1159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new external string using the data defined in the given
11607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource. When the external string is no longer live on V8's heap the
11617f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource will be disposed by calling its Dispose method. The caller of
11627f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * this function should not otherwise delete or modify the resource. Neither
11637f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * should the underlying buffer be deallocated or modified except through the
11647f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * destructor of the external string resource.
1165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource);
1167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an external string resource with this string by transforming it
1170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in place so that existing references to this string in the JavaScript heap
1171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * will use the external string resource. The external string resource's
1172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * character contents needs to be equivalent to this string.
1173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string has been changed to be an external string.
11747f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * The string is not modified if the operation fails. See NewExternal for
11757f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * information on the lifetime of the resource.
1176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11778defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool MakeExternal(ExternalStringResource* resource);
1178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new external string using the ascii data defined in the given
11817f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource. When the external string is no longer live on V8's heap the
11827f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource will be disposed by calling its Dispose method. The caller of
11837f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * this function should not otherwise delete or modify the resource. Neither
11847f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * should the underlying buffer be deallocated or modified except through the
11857f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * destructor of the external string resource.
1186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11878defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewExternal(
11888defd9ff6930b4e24729971a61cf7469daf119beSteve Block      ExternalAsciiStringResource* resource);
1189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an external string resource with this string by transforming it
1192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in place so that existing references to this string in the JavaScript heap
1193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * will use the external string resource. The external string resource's
1194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * character contents needs to be equivalent to this string.
1195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string has been changed to be an external string.
11967f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * The string is not modified if the operation fails. See NewExternal for
11977f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * information on the lifetime of the resource.
1198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11998defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
1200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this string can be made external.
1203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12048defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool CanMakeExternal();
1205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates an undetectable string from the supplied ascii or utf-8 data.*/
12078defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewUndetectable(const char* data,
12088defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                                int length = -1);
1209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates an undetectable string from the supplied utf-16 data.*/
12118defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
12128defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                                int length = -1);
1213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Converts an object to a utf8-encoded character array.  Useful if
1216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * you want to print the object.  If conversion to a string fails
1217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * (eg. due to an exception in the toString() method of the object)
1218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * then the length() method returns 0 and the * operator returns
1219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * NULL.
1220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Utf8Value {
1222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit Utf8Value(Handle<v8::Value> obj);
1224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~Utf8Value();
1225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* operator*() { return str_; }
1226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const char* operator*() const { return str_; }
1227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* str_;
1230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Utf8Value(const Utf8Value&);
1234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const Utf8Value&);
1235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Converts an object to an ascii string.
1239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Useful if you want to print the object.
1240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If conversion to a string fails (eg. due to an exception in the toString()
1241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * method of the object) then the length() method returns 0 and the * operator
1242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * returns NULL.
1243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT AsciiValue {
1245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit AsciiValue(Handle<v8::Value> obj);
1247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~AsciiValue();
1248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* operator*() { return str_; }
1249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const char* operator*() const { return str_; }
1250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* str_;
1253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    AsciiValue(const AsciiValue&);
1257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const AsciiValue&);
1258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Converts an object to a two-byte string.
1262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If conversion to a string fails (eg. due to an exception in the toString()
1263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * method of the object) then the length() method returns 0 and the * operator
1264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * returns NULL.
1265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Value {
1267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit Value(Handle<v8::Value> obj);
1269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~Value();
1270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint16_t* operator*() { return str_; }
1271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const uint16_t* operator*() const { return str_; }
1272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint16_t* str_;
1275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Value(const Value&);
1279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const Value&);
1280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
12813ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
12838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const;
12848defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript number value (ECMA-262, 4.3.20)
1290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
12918defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Number : public Primitive {
1292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
12938defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double Value() const;
12948defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Number> New(double value);
1295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Number* Cast(v8::Value* obj);
1296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
12978defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Number();
1298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void CheckCast(v8::Value* obj);
1299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a signed integer.
1304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13058defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Integer : public Number {
1306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13078defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Integer> New(int32_t value);
13088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value);
13098defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int64_t Value() const;
1310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Integer* Cast(v8::Value* obj);
1311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13128defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Integer();
13138defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit signed integer.
1319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13208defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Int32 : public Integer {
1321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int32_t Value() const;
1323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13248defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Int32();
1325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit unsigned integer.
1330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13318defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Uint32 : public Integer {
1332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13338defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Value() const;
1334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13358defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Uint32();
1336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An instance of the built-in Date constructor (ECMA-262, 15.9).
1341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13428defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Date : public Value {
1343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13448defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Value> New(double time);
1345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A specialization of Value::NumberValue that is more efficient
1348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * because we know the structure of this object.
1349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
13508defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double NumberValue() const;
1351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Date* Cast(v8::Value* obj);
1353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13548defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1358f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch/**
1359f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
1360f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch */
1361f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdochclass RegExp : public Value {
1362f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch public:
1363f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1364f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Regular expression flag bits. They can be or'ed to enable a set
1365f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * of flags.
1366f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1367f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  enum Flags {
1368f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kNone = 0,
1369f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kGlobal = 1,
1370f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kIgnoreCase = 2,
1371f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kMultiline = 4
1372f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  };
1373f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1374f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1375f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Creates a regular expression from the given pattern string and
1376f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * the flags bit field. May throw a JavaScript exception as
1377f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * described in ECMA-262, 15.10.4.1.
1378f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   *
1379f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * For example,
1380f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   *   RegExp::New(v8::String::New("foo"),
1381f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   *               static_cast<RegExp::Flags>(kGlobal | kMultiline))
1382f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * is equivalent to evaluating "/foo/gm".
1383f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1384f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT static Local<RegExp> New(Handle<String> pattern,
1385f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch                                    Flags flags);
1386f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1387f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1388f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Returns the value of the source property: a string representing
1389f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * the regular expression.
1390f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1391f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT Local<String> GetSource() const;
1392f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1393f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1394f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Returns the flags bit field.
1395f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1396f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT Flags GetFlags() const;
1397f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1398f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  static inline RegExp* Cast(v8::Value* obj);
1399f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1400f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch private:
1401f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
1402f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch};
1403f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1404f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum PropertyAttribute {
1406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  None       = 0,
1407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ReadOnly   = 1 << 0,
1408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DontEnum   = 1 << 1,
1409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DontDelete = 1 << 2
1410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockenum ExternalArrayType {
14133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalByteArray = 1,
14143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedByteArray,
14153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalShortArray,
14163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedShortArray,
14173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalIntArray,
14183ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedIntArray,
14193ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalFloatArray
14203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
14213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1423f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Accessor[Getter|Setter] are used as callback functions when
1424f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * setting|getting a particular property. See Object and ObjectTemplate's
1425f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * method SetAccessor.
1426f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */
1427f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef Handle<Value> (*AccessorGetter)(Local<String> property,
1428f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                                        const AccessorInfo& info);
1429f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1430f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1431f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef void (*AccessorSetter)(Local<String> property,
1432f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                               Local<Value> value,
1433f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                               const AccessorInfo& info);
1434f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1435f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1436f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/**
1437f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Access control specifications.
1438f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke *
1439f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Some accessors should be accessible across contexts.  These
1440f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors have an explicit access control parameter which specifies
1441f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * the kind of cross-context access that should be allowed.
1442f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke *
1443f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Additionally, for security, accessors can prohibit overwriting by
1444f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors defined in JavaScript.  For objects that have such
1445f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors either locally or in their prototype chain it is not
1446f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * possible to overwrite the accessor by using __defineGetter__ or
1447f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * __defineSetter__ from JavaScript code.
1448f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */
1449f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeenum AccessControl {
1450f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  DEFAULT               = 0,
1451f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  ALL_CAN_READ          = 1,
1452f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  ALL_CAN_WRITE         = 1 << 1,
1453f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  PROHIBITS_OVERWRITING = 1 << 2
1454f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke};
1455f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1456f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1457f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/**
1458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript object (ECMA-262, 4.3.3)
1459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
14608defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Object : public Value {
1461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
14628defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Set(Handle<Value> key,
14638defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    Handle<Value> value,
14648defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    PropertyAttribute attribs = None);
1465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Set(uint32_t index,
14678defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    Handle<Value> value);
14686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets a local property on this object bypassing interceptors and
1470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // overriding accessors or read-only properties.
1471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
1472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Note that if the object has an interceptor the property will be set
1473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // locally, but since the interceptor takes precedence the local property
1474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // will only be returned if the interceptor doesn't return a value.
1475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
1476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Note also that this only works for named properties.
14778defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool ForceSet(Handle<Value> key,
14788defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         Handle<Value> value,
14798defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         PropertyAttribute attribs = None);
1480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Get(Handle<Value> key);
1482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Get(uint32_t index);
14846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // TODO(1245389): Replace the type-specific versions of these
1486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // functions with generic ones that accept a Handle<Value> key.
14878defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Has(Handle<String> key);
1488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14898defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Delete(Handle<String> key);
1490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Delete a property on this object bypassing interceptors and
1492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ignoring dont-delete attributes.
14938defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool ForceDelete(Handle<Value> key);
1494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14958defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Has(uint32_t index);
1496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14978defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Delete(uint32_t index);
1498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14998defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetAccessor(Handle<String> name,
15008defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessorGetter getter,
15018defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessorSetter setter = 0,
15028defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            Handle<Value> data = Handle<Value>(),
15038defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessControl settings = DEFAULT,
15048defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            PropertyAttribute attribute = None);
1505f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns an array containing the names of the enumerable properties
1508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * of this object, including properties from prototype objects.  The
1509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * array returned by this method contains the same values as would
1510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be enumerated by a for-in statement over this object.
1511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15128defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Array> GetPropertyNames();
1513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the prototype object.  This does not skip objects marked to
1516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be skipped by __proto__ and it does not consult the security
1517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler.
1518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15198defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetPrototype();
1520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1522402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Set the prototype object.  This does not skip objects marked to
1523402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * be skipped by __proto__ and it does not consult the security
1524402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * handler.
1525402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
15268defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetPrototype(Handle<Value> prototype);
1527402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
1528402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
1529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Finds an instance of the given function template in the prototype
1530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * chain.
1531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15328defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> FindInstanceInPrototypeChain(
15338defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<FunctionTemplate> tmpl);
1534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Call builtin Object.prototype.toString on this object.
1537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This is different from Value::ToString() that may call
1538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * user-defined toString function. This one does not.
1539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15408defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ObjectProtoToString();
1541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15428a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  /**
15438a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang   * Returns the name of the function invoked as a constructor for this object.
15448a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang   */
15458a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  V8EXPORT Local<String> GetConstructorName();
15468a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
1547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets the number of internal fields for this Object. */
15488defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int InternalFieldCount();
1549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets the value in an internal field. */
1550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> GetInternalField(int index);
1551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Sets the value in an internal field. */
15528defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetInternalField(int index, Handle<Value> value);
1553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets a native pointer from an internal field. */
1555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void* GetPointerFromInternalField(int index);
15563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Sets a native pointer in an internal field. */
15588defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetPointerInInternalField(int index, void* value);
1559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Testers for local properties.
15618defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealNamedProperty(Handle<String> key);
15628defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealIndexedProperty(uint32_t index);
15638defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key);
1564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If result.IsEmpty() no real property was located in the prototype chain.
1567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means interceptors in the prototype chain are not called.
1568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15698defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain(
15708defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<String> key);
1571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If result.IsEmpty() no real property was located on the object or
1574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in the prototype chain.
1575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means interceptors in the prototype chain are not called.
1576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15778defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key);
1578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Tests for a named lookup interceptor.*/
15808defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasNamedLookupInterceptor();
1581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Tests for an index lookup interceptor.*/
15838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasIndexedLookupInterceptor();
1584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Turns on access check on the object if the object is an instance of
1587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a template that has access check callbacks. If an object has no
1588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * access check info, the object cannot be accessed by anyone.
1589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15908defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void TurnOnAccessCheck();
1591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the identity hash for this object. The current implemenation uses
1594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a hidden property on the object to store the identity hash.
1595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
1596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The return value will never be 0. Also, it is not guaranteed to be
1597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * unique.
1598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15998defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int GetIdentityHash();
1600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Access hidden properties on JavaScript objects. These properties are
1603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * hidden from the executing JavaScript and only accessible through the V8
1604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * C++ API. Hidden properties introduced by V8 internally (for example the
1605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * identity hash) are prefixed with "v8::".
1606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16078defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value);
16088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetHiddenValue(Handle<String> key);
16098defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool DeleteHiddenValue(Handle<String> key);
16103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this is an instance of an api function (one
1613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * created from a function created from a function template) and has
1614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been modified since it was created.  Note that this method is
1615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * conservative and may return true for objects that haven't actually
1616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been modified.
1617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16188defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsDirty();
1619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clone this object with a fast but shallow copy.  Values will point
1622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to the same values as the original object.
1623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16248defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> Clone();
1625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the backing store of the indexed properties to be managed by the
1628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * embedding layer. Access to the indexed properties will follow the rules
1629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * spelled out in CanvasPixelArray.
1630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Note: The embedding program still owns the data and needs to ensure that
1631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *       the backing store is preserved while V8 has a reference.
1632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16338defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
16349dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  bool HasIndexedPropertiesInPixelData();
16359dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  uint8_t* GetIndexedPropertiesPixelData();
16369dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  int GetIndexedPropertiesPixelDataLength();
1637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
16383ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
16393ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Set the backing store of the indexed properties to be managed by the
16403ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * embedding layer. Access to the indexed properties will follow the rules
16413ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * spelled out for the CanvasArray subtypes in the WebGL specification.
16423ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Note: The embedding program still owns the data and needs to ensure that
16433ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   *       the backing store is preserved while V8 has a reference.
16443ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
16458defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetIndexedPropertiesToExternalArrayData(
16468defd9ff6930b4e24729971a61cf7469daf119beSteve Block      void* data,
16478defd9ff6930b4e24729971a61cf7469daf119beSteve Block      ExternalArrayType array_type,
16488defd9ff6930b4e24729971a61cf7469daf119beSteve Block      int number_of_elements);
16499dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  bool HasIndexedPropertiesInExternalArrayData();
16509dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  void* GetIndexedPropertiesExternalArrayData();
16519dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
16529dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  int GetIndexedPropertiesExternalArrayDataLength();
16533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
16548defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Object> New();
1655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Object* Cast(Value* obj);
1656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
16578defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Object();
16588defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(Value* obj);
16598defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> CheckedGetInternalField(int index);
16608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void* SlowGetPointerFromInternalField(int index);
1661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If quick access to the internal field is possible this method
16643ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * returns the value.  Otherwise an empty handle is returned.
1665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> UncheckedGetInternalField(int index);
1667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An instance of the built-in array constructor (ECMA-262, 15.4.2).
1672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
16738defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Array : public Object {
1674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
16758defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Length() const;
1676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clones an element at index |index|.  Returns an empty
1679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handle if cloning fails (for any reason).
1680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> CloneElementAt(uint32_t index);
1682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
16838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Array> New(int length = 0);
1684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Array* Cast(Value* obj);
1685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
16868defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Array();
1687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void CheckCast(Value* obj);
1688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript function object (ECMA-262, 15.3).
1693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
16948defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Function : public Object {
1695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
16968defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> NewInstance() const;
16978defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
16988defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Call(Handle<Object> recv,
16998defd9ff6930b4e24729971a61cf7469daf119beSteve Block                             int argc,
17008defd9ff6930b4e24729971a61cf7469daf119beSteve Block                             Handle<Value> argv[]);
17018defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetName(Handle<String> name);
17028defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Handle<Value> GetName() const;
1703402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
1704402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
1705402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Returns zero based line number of function body and
1706402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * kLineOffsetNotFound if no information available.
1707402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
17088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int GetScriptLineNumber() const;
17098defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT ScriptOrigin GetScriptOrigin() const;
1710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Function* Cast(Value* obj);
17118defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static const int kLineOffsetNotFound;
1712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
17138defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Function();
17148defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(Value* obj);
1715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value that wraps a C++ void*.  This type of value is
1720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * mainly used to associate C++ data structures with JavaScript
1721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects.
1722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Wrap function V8 will return the most optimal Value object wrapping the
1724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * C++ void*. The type of the value is not guaranteed to be an External object
1725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and no assumptions about its type should be made. To access the wrapped
1726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * value Unwrap should be used, all other operations on that object will lead
1727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to unpredictable results.
1728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
17298defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass External : public Value {
1730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
17318defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Value> Wrap(void* data);
1732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void* Unwrap(Handle<Value> obj);
1733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
17348defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<External> New(void* value);
1735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline External* Cast(Value* obj);
17368defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void* Value() const;
1737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
17388defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT External();
17398defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void* QuickUnwrap(Handle<v8::Value> obj);
17418defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
1742a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- T e m p l a t e s ---
1746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of object and function templates.
1750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Template : public Data {
1752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Adds a property to each instance created by this template.*/
1754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Set(Handle<String> name, Handle<Data> value,
1755a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block           PropertyAttribute attributes = None);
1756a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Set(const char* name, Handle<Data> value);
1757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Template();
1759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
1761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class FunctionTemplate;
1762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The argument information given to function call callbacks.  This
1767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * class provides access to information about the context of the call,
1768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * including the receiver, the number and values of arguments, and
1769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the holder of the function.
1770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
17718defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Arguments {
1772a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int Length() const;
1774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> operator[](int i) const;
1775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Function> Callee() const;
1776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> This() const;
1777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> Holder() const;
1778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsConstructCall() const;
1779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> Data() const;
1780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
17813e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  static const int kDataIndex = 0;
17823e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  static const int kCalleeIndex = -1;
17833e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  static const int kHolderIndex = -2;
17843e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu
1785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
17863e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  inline Arguments(internal::Object** implicit_args,
17873e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                   internal::Object** values,
17883e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                   int length,
17893e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                   bool is_construct_call);
17903e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  internal::Object** implicit_args_;
17913e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  internal::Object** values_;
1792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int length_;
17933e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  bool is_construct_call_;
1794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The information passed to an accessor callback about the context
1799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * of the property access.
1800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT AccessorInfo {
1802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline AccessorInfo(internal::Object** args)
1804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : args_(args) { }
1805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> Data() const;
1806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> This() const;
1807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> Holder() const;
1808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** args_;
1810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*InvocationCallback)(const Arguments& args);
1814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * NamedProperty[Getter|Setter] are used as interceptors on object.
1817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ObjectTemplate::SetNamedPropertyHandler.
1818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
1820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             const AccessorInfo& info);
1821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request.
1825a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle.
1826a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1827a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
1828a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             Local<Value> value,
1829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             const AccessorInfo& info);
1830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request.
18339dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * The result is an integer encoding property attributes (like v8::None,
18349dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * v8::DontEnum, etc.)
1835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
18367f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochtypedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
18377f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch                                              const AccessorInfo& info);
1838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request.
1842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false
1843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise.
1844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
1846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                const AccessorInfo& info);
1847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the names of the properties the named
1850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property getter intercepts.
1851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
1853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value of the property if the getter intercepts the
1857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * request.  Otherwise, returns an empty handle.
1858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
1860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               const AccessorInfo& info);
1861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request.
1865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle.
1866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
1868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               Local<Value> value,
1869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               const AccessorInfo& info);
1870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request.
1874756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick * The result is an integer encoding property attributes.
1875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1876756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merricktypedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
1877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                const AccessorInfo& info);
1878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request.
1881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false
1882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise.
1883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
1885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                  const AccessorInfo& info);
1886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the indices of the properties the
1889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * indexed property getter intercepts.
1890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
1892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Access type specification.
1896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum AccessType {
1898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_GET,
1899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_SET,
1900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_HAS,
1901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_DELETE,
1902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_KEYS
1903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the named
1908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given key on the host object.
1909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*NamedSecurityCallback)(Local<Object> host,
1911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      Local<Value> key,
1912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      AccessType type,
1913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      Local<Value> data);
1914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the indexed
1918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given index on the host object.
1919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*IndexedSecurityCallback)(Local<Object> host,
1921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        uint32_t index,
1922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        AccessType type,
1923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        Local<Value> data);
1924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate is used to create functions at runtime. There
1928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * can only be one function created from a FunctionTemplate in a
1929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * context.  The lifetime of the created function is equal to the
1930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * lifetime of the context.  So in case the embedder needs to create
1931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * temporary functions that can be collected using Scripts is
1932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * preferred.
1933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have properties, these properties are added to the
1935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function object when it is created.
1936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate has a corresponding instance template which is
1938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * used to create object instances when the function is used as a
1939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor. Properties added to the instance template are added to
1940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * each object instance.
1941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have a prototype template. The prototype template
1943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is used to create the prototype object of the function.
1944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The following example shows how to use a FunctionTemplate:
1946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
1948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
1949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    t->Set("func_property", v8::Number::New(1));
1950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
1952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
1953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    proto_t->Set("proto_const", v8::Number::New(2));
1954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
1956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
1957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
1958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->Set("instance_property", Number::New(3));
1959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Function> function = t->GetFunction();
1961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Object> instance = function->NewInstance();
1962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
1963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let's use "function" as the JS variable name of the function object
1965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and "instance" for the instance object created above.  The function
1966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and the instance will have the following properties:
1967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
1969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   func_property in function == true;
1970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.func_property == 1;
1971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.prototype.proto_method() invokes 'InvokeCallback'
1973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.prototype.proto_const == 2;
1974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance instanceof function == true;
1976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance.instance_accessor calls 'InstanceAccessorCallback'
1977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance.instance_property == 3;
1978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
1979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can inherit from another one by calling the
1981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate::Inherit method.  The following graph illustrates
1982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the semantics of inheritance:
1983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
1985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   FunctionTemplate Parent  -> Parent() . prototype -> { }
1986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     ^                                                  ^
1987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     | Inherit(Parent)                                  | .__proto__
1988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     |                                                  |
1989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   FunctionTemplate Child   -> Child()  . prototype -> { }
1990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
1991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
1993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * object of the Child() function has __proto__ pointing to the
1994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Parent() function's prototype object. An instance of the Child
1995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function has all properties on Parent's instance templates.
1996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let Parent be the FunctionTemplate initialized in the previous
1998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * section and create a Child FunctionTemplate by:
1999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<FunctionTemplate> parent = t;
2002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<FunctionTemplate> child = FunctionTemplate::New();
2003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child->Inherit(parent);
2004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<Function> child_function = child->GetFunction();
2006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<Object> child_instance = child_function->NewInstance();
2007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Child function and Child instance will have the following
2010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * properties:
2011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_func.prototype.__proto__ == function.prototype;
2014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_instance.instance_accessor calls 'InstanceAccessorCallback'
2015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_instance.instance_property == 3;
2016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT FunctionTemplate : public Template {
2019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a function template.*/
2021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<FunctionTemplate> New(
2022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      InvocationCallback callback = 0,
2023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Value> data = Handle<Value>(),
2024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Signature> signature = Handle<Signature>());
2025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the unique function instance in the current execution context.*/
2026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Function> GetFunction();
2027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the call-handler callback for a FunctionTemplate.  This
2030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback is called whenever the function created from this
2031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * FunctionTemplate is called.
2032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCallHandler(InvocationCallback callback,
2034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                      Handle<Value> data = Handle<Value>());
2035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Get the InstanceTemplate. */
2037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<ObjectTemplate> InstanceTemplate();
2038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Causes the function template to inherit from a parent function template.*/
2040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Inherit(Handle<FunctionTemplate> parent);
2041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A PrototypeTemplate is the template used to create the prototype object
2044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * of the function created by this template.
2045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<ObjectTemplate> PrototypeTemplate();
2047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the class name of the FunctionTemplate.  This is used for
2051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * printing objects created with the function created from the
2052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * FunctionTemplate as its constructor.
2053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetClassName(Handle<String> name);
2055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Determines whether the __proto__ accessor ignores instances of
2058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the function template.  If instances of the function template are
2059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ignored, __proto__ skips all instances and instead returns the
2060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * next object in the prototype chain.
2061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Call with a value of true to make the __proto__ accessor ignore
2063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * instances of the function template.  Call with a value of false
2064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to make the __proto__ accessor not ignore instances of the
2065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function template.  By default, instances of a function template
2066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * are not ignored.
2067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetHiddenPrototype(bool value);
2069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the given object is an instance of this function
2072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * template.
2073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasInstance(Handle<Value> object);
2075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  FunctionTemplate();
2078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void AddInstancePropertyAccessor(Handle<String> name,
2079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessorGetter getter,
2080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessorSetter setter,
2081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   Handle<Value> data,
2082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessControl settings,
2083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   PropertyAttribute attributes);
2084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
2085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertySetter setter,
2086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyQuery query,
2087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyDeleter remover,
2088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyEnumerator enumerator,
20899dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen                                       Handle<Value> data);
2090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
2091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertySetter setter,
2092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyQuery query,
2093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyDeleter remover,
2094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyEnumerator enumerator,
2095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         Handle<Value> data);
2096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
2097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        Handle<Value> data);
2098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Context;
2100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
2101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An ObjectTemplate is used to create objects at runtime.
2106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Properties added to an ObjectTemplate are added to each object
2108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * created from the ObjectTemplate.
2109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ObjectTemplate : public Template {
2111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates an ObjectTemplate. */
2113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<ObjectTemplate> New();
2114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a new instance of this template.*/
2116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Object> NewInstance();
2117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets an accessor on the object template.
2120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever the property with the given name is accessed on objects
2122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * created from this ObjectTemplate the getter and setter callbacks
2123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * are called instead of getting and setting the property directly
2124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * on the JavaScript object.
2125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param name The name of the property for which an accessor is added.
2127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting the property.
2128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting the property.
2129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the getter and setter
2130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   callbacks whenever they are invoked.
2131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param settings Access control settings for the accessor. This is a bit
2132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   field consisting of one of more of
2133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
2134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   The default is to not allow cross-context access.
2135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   ALL_CAN_READ means that all cross-context reads are allowed.
2136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   ALL_CAN_WRITE means that all cross-context writes are allowed.
2137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
2138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   cross-context access.
2139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param attribute The attributes of the property for which an accessor
2140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   is added.
2141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetAccessor(Handle<String> name,
2143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessorGetter getter,
2144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessorSetter setter = 0,
2145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   Handle<Value> data = Handle<Value>(),
2146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessControl settings = DEFAULT,
2147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   PropertyAttribute attribute = None);
2148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets a named property handler on the object template.
2151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever a named property is accessed on objects created from
2153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this object template, the provided callback is invoked instead of
2154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * accessing the property directly on the JavaScript object.
2155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting a property.
2157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting a property.
21589dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen   * \param query The callback to invoke to check if a property is present,
21599dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen   *   and if present, get its attributes.
2160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param deleter The callback to invoke when deleting a property.
2161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param enumerator The callback to invoke to enumerate all the named
2162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   properties of an object.
2163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the callbacks
2164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   whenever they are invoked.
2165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNamedPropertyHandler(NamedPropertyGetter getter,
2167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertySetter setter = 0,
2168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyQuery query = 0,
2169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyDeleter deleter = 0,
2170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyEnumerator enumerator = 0,
21719dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen                               Handle<Value> data = Handle<Value>());
2172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets an indexed property handler on the object template.
2175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever an indexed property is accessed on objects created from
2177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this object template, the provided callback is invoked instead of
2178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * accessing the property directly on the JavaScript object.
2179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting a property.
2181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting a property.
2182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param query The callback to invoke to check is an object has a property.
2183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param deleter The callback to invoke when deleting a property.
2184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param enumerator The callback to invoke to enumerate all the indexed
2185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   properties of an object.
2186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the callbacks
2187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   whenever they are invoked.
2188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
2190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertySetter setter = 0,
2191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyQuery query = 0,
2192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyDeleter deleter = 0,
2193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyEnumerator enumerator = 0,
2194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 Handle<Value> data = Handle<Value>());
2195756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
2196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the callback to be used when calling instances created from
2198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template as a function.  If no callback is set, instances
2199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * behave like normal JavaScript objects that cannot be called as a
2200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function.
2201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCallAsFunctionHandler(InvocationCallback callback,
2203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                Handle<Value> data = Handle<Value>());
2204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Mark object instances of the template as undetectable.
2207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * In many ways, undetectable objects behave as though they are not
2209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * there.  They behave like 'undefined' in conditionals and when
2210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * printed.  However, properties can be accessed and called as on
2211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * normal objects.
2212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void MarkAsUndetectable();
2214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets access check callbacks on the object template.
2217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When accessing properties on instances of this object template,
2219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the access check callback will be called to determine whether or
2220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * not to allow cross-context access to the properties.
2221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The last parameter specifies whether access checks are turned
2222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * on by default on instances. If access checks are off by default,
2223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * they can be turned on on individual instances by calling
2224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Object::TurnOnAccessCheck().
2225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
2227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               IndexedSecurityCallback indexed_handler,
2228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               Handle<Value> data = Handle<Value>(),
2229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               bool turned_on_by_default = true);
2230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Gets the number of internal fields for objects generated from
2233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template.
2234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int InternalFieldCount();
2236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the number of internal fields for objects generated from
2239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template.
2240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetInternalFieldCount(int value);
2242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ObjectTemplate();
2245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
2246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class FunctionTemplate;
2247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A Signature specifies which receivers and arguments a function can
2252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * legally be called with.
2253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Signature : public Data {
2255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Signature> New(Handle<FunctionTemplate> receiver =
2257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  Handle<FunctionTemplate>(),
2258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              int argc = 0,
2259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              Handle<FunctionTemplate> argv[] = 0);
2260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Signature();
2262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A utility for determining the type of objects based on the template
2267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * they were constructed from.
2268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TypeSwitch : public Data {
2270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
2272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
2273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int match(Handle<Value> value);
2274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  TypeSwitch();
2276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- E x t e n s i o n s ---
2280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
2284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Extension {  // NOLINT
2286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Extension(const char* name,
2288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            const char* source = 0,
2289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            int dep_count = 0,
2290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            const char** deps = 0);
2291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~Extension() { }
2292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual v8::Handle<v8::FunctionTemplate>
2293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      GetNativeFunction(v8::Handle<v8::String> name) {
2294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return v8::Handle<v8::FunctionTemplate>();
2295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* name() { return name_; }
2298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* source() { return source_; }
2299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int dependency_count() { return dep_count_; }
2300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** dependencies() { return deps_; }
2301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_auto_enable(bool value) { auto_enable_ = value; }
2302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool auto_enable() { return auto_enable_; }
2303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* name_;
2306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* source_;
2307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int dep_count_;
2308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** deps_;
2309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool auto_enable_;
2310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Disallow copying and assigning.
2312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Extension(const Extension&);
2313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const Extension&);
2314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid V8EXPORT RegisterExtension(Extension* extension);
2318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
2322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT DeclareExtension {
2324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline DeclareExtension(Extension* extension) {
2326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    RegisterExtension(extension);
2327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- S t a t i c s ---
2332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Undefined();
2335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Null();
2336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT True();
2337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT False();
2338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A set of constraints that specifies the limits of the runtime's memory use.
2342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * You must set the heap size before initializing the VM - the size cannot be
2343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * adjusted after the VM is initialized.
2344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you are using threads then you should hold the V8::Locker lock while
2346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * setting the stack limit and you must set a non-default stack limit separately
2347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for each thread.
2348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ResourceConstraints {
2350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ResourceConstraints();
2352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_young_space_size() const { return max_young_space_size_; }
2353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_max_young_space_size(int value) { max_young_space_size_ = value; }
2354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_old_space_size() const { return max_old_space_size_; }
2355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_max_old_space_size(int value) { max_old_space_size_ = value; }
235690bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  int max_executable_size() { return max_executable_size_; }
235790bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  void set_max_executable_size(int value) { max_executable_size_ = value; }
2358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t* stack_limit() const { return stack_limit_; }
2359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets an address beyond which the VM's stack may not grow.
2360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
2361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_young_space_size_;
2363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_old_space_size_;
236490bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  int max_executable_size_;
2365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t* stack_limit_;
2366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
236925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenbool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints);
2370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- E x c e p t i o n s ---
2373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FatalErrorCallback)(const char* location, const char* message);
2376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
2379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Schedules an exception to be thrown when returning to JavaScript.  When an
2383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * exception has been scheduled it is illegal to invoke any JavaScript
2384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operation; the caller must return immediately and only after the exception
2385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * has been handled does it become legal to invoke JavaScript operations.
2386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> V8EXPORT ThrowException(Handle<Value> exception);
2388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Create new error objects by calling the corresponding error object
2391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor with the message.
2392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Exception {
2394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> RangeError(Handle<String> message);
2396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> ReferenceError(Handle<String> message);
2397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> SyntaxError(Handle<String> message);
2398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> TypeError(Handle<String> message);
2399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> Error(Handle<String> message);
2400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- C o u n t e r s  C a l l b a c k s ---
2404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int* (*CounterLookupCallback)(const char* name);
2406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void* (*CreateHistogramCallback)(const char* name,
2408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         int min,
2409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         int max,
2410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         size_t buckets);
2411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
2413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
24149ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick// --- M e m o r y  A l l o c a t i o n   C a l l b a c k ---
24159ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  enum ObjectSpace {
24169ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceNewSpace = 1 << 0,
24179ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceOldPointerSpace = 1 << 1,
24189ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceOldDataSpace = 1 << 2,
24199ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceCodeSpace = 1 << 3,
24209ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceMapSpace = 1 << 4,
24219ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceLoSpace = 1 << 5,
24229ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
24239ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
24249ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick      kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
24259ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick      kObjectSpaceLoSpace
24269ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  };
24279ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
24289ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  enum AllocationAction {
24299ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionAllocate = 1 << 0,
24309ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionFree = 1 << 1,
24319ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
24329ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  };
24339ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
24349ac36c9faca11611ada13b4054edbaa0738661d0Iain Merricktypedef void (*MemoryAllocationCallback)(ObjectSpace space,
24359ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                         AllocationAction action,
24369ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                         int size);
24379ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
2438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- F a i l e d A c c e s s C h e c k C a l l b a c k ---
2439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FailedAccessCheckCallback)(Local<Object> target,
2440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          AccessType type,
2441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          Local<Value> data);
2442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- G a r b a g e C o l l e c t i o n  C a l l b a c k s
2444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
24466ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Applications can register callback functions which will be called
24476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * before and after a garbage collection.  Allocations are not
24486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * allowed in the callback functions, you therefore cannot manipulate
2449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects (set or delete properties for example) since it is possible
2450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * such operations will result in the allocation of objects.
2451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
24526ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCType {
24536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeScavenge = 1 << 0,
24546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeMarkSweepCompact = 1 << 1,
24556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
24566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
24576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
24586ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCCallbackFlags {
24596ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kNoGCCallbackFlags = 0,
24606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCCallbackFlagCompacted = 1 << 0
24616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
24626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
24636ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
24646ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
24656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
2466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*GCCallback)();
2467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Profiler modules.
2471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * In V8, profiler consists of several modules: CPU profiler, and different
2473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * kinds of heap profiling. Each can be turned on / off independently.
2474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * When PROFILER_MODULE_HEAP_SNAPSHOT flag is passed to ResumeProfilerEx,
2475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * modules are enabled only temporarily for making a snapshot of the heap.
2476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum ProfilerModules {
2478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_NONE            = 0,
2479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_CPU             = 1,
2480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_HEAP_STATS      = 1 << 1,
2481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2,
2482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_HEAP_SNAPSHOT   = 1 << 16
2483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
24873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Collection of V8 heap information.
24883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block *
24893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Instances of this class can be passed to v8::V8::HeapStatistics to
24903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * get heap statistics from V8.
24913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block */
24923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass V8EXPORT HeapStatistics {
24933ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
24943ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  HeapStatistics();
24953ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t total_heap_size() { return total_heap_size_; }
249690bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  size_t total_heap_size_executable() { return total_heap_size_executable_; }
24973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t used_heap_size() { return used_heap_size_; }
24983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
24993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
25003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void set_total_heap_size(size_t size) { total_heap_size_ = size; }
250190bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  void set_total_heap_size_executable(size_t size) {
250290bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner    total_heap_size_executable_ = size;
250390bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  }
25043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void set_used_heap_size(size_t size) { used_heap_size_ = size; }
25053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t total_heap_size_;
250790bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  size_t total_heap_size_executable_;
25083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t used_heap_size_;
25093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  friend class V8;
25113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
25123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block/**
2515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Container class for static utility functions.
2516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT V8 {
2518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Set the callback to invoke in case of fatal errors. */
2520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFatalErrorHandler(FatalErrorCallback that);
2521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Ignore out-of-memory exceptions.
2524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 running out of memory is treated as a fatal error by default.
2526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means that the fatal error handler is called and that V8 is
2527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * terminated.
2528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * IgnoreOutOfMemoryException can be used to not treat a
2530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * out-of-memory situation as a fatal error.  This way, the contexts
2531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that did not cause the out of memory problem might be able to
2532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * continue execution.
2533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void IgnoreOutOfMemoryException();
2535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Check if V8 is dead and therefore unusable.  This is the case after
2538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * fatal errors such as out-of-memory situations.
2539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsDead();
2541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Adds a message listener.
2544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The same message listener can be added more than once and it that
2546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * case it will be called more than once for each message.
2547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool AddMessageListener(MessageCallback that,
2549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 Handle<Value> data = Handle<Value>());
2550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Remove all message listeners from the specified callback function.
2553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void RemoveMessageListeners(MessageCallback that);
2555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
25573bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * Tells V8 to capture current stack trace when uncaught exception occurs
25583bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * and report it to the message listeners. The option is off by default.
25593bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   */
25603bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  static void SetCaptureStackTraceForUncaughtExceptions(
25613bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      bool capture,
25623bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      int frame_limit = 10,
25633bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      StackTrace::StackTraceOptions options = StackTrace::kOverview);
25643bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
25653bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  /**
2566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets V8 flags from a string.
2567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFlagsFromString(const char* str, int length);
2569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets V8 flags from the command line.
2572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFlagsFromCommandLine(int* argc,
2574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      char** argv,
2575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      bool remove_flags);
2576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Get the version string. */
2578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const char* GetVersion();
2579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to provide a mechanism for recording
2582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * statistics counters.
2583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetCounterFunction(CounterLookupCallback);
2585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to provide a mechanism for recording
2588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * histograms. The CreateHistogram function returns a
2589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * histogram which will later be passed to the AddHistogramSample
2590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function.
2591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetCreateHistogramFunction(CreateHistogramCallback);
2593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
2594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the computation of a sliding window of states. The sliding
2597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * window information is recorded in statistics counters.
2598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void EnableSlidingStateWindow();
2600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Callback function for reporting failed access checks.*/
2602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
2603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to receive a notification before a
26066ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
26076ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * callback function, you therefore cannot manipulate objects (set
26086ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * or delete properties for example) since it is possible such
26096ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * operations will result in the allocation of objects. It is possible
26106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * to specify the GCType filter for your callback. But it is not possible to
26116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * register the same callback function two times with different
26126ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * GCType filters.
26136ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26146ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void AddGCPrologueCallback(
26156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
26166ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26176ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * This function removes callback which was installed by
26196ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * AddGCPrologueCallback function.
26206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void RemoveGCPrologueCallback(GCPrologueCallback callback);
26226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26246ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The function is deprecated. Please use AddGCPrologueCallback instead.
26256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Enables the host application to receive a notification before a
26266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
2627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback function, you therefore cannot manipulate objects (set
2628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * or delete properties for example) since it is possible such
2629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations will result in the allocation of objects.
2630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetGlobalGCPrologueCallback(GCCallback);
2632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to receive a notification after a
26356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
26366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * callback function, you therefore cannot manipulate objects (set
26376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * or delete properties for example) since it is possible such
26386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * operations will result in the allocation of objects. It is possible
26396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * to specify the GCType filter for your callback. But it is not possible to
26406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * register the same callback function two times with different
26416ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * GCType filters.
26426ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26436ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void AddGCEpilogueCallback(
26446ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
26456ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26466ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * This function removes callback which was installed by
26486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * AddGCEpilogueCallback function.
26496ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26506ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
26516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The function is deprecated. Please use AddGCEpilogueCallback instead.
26546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Enables the host application to receive a notification after a
2655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * major garbage collection.  Allocations are not allowed in the
2656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback function, you therefore cannot manipulate objects (set
2657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * or delete properties for example) since it is possible such
2658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations will result in the allocation of objects.
2659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetGlobalGCEpilogueCallback(GCCallback);
2661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
26639ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * Enables the host application to provide a mechanism to be notified
26649ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * and perform custom logging when V8 Allocates Executable Memory.
26659ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   */
26669ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
26679ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                          ObjectSpace space,
26689ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                          AllocationAction action);
26699ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26709ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  /**
26719ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * This function removes callback which was installed by
26729ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * AddMemoryAllocationCallback function.
26739ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   */
26749ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
26759ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26769ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  /**
2677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Allows the host application to group objects together. If one
2678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * object in the group is alive, all objects in the group are alive.
2679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * After each garbage collection, object groups are removed. It is
2680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * intended to be used in the before-garbage-collection callback
2681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function, for instance to simulate DOM tree connections among JS
2682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * wrapper objects.
2683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void AddObjectGroup(Persistent<Value>* objects, size_t length);
2685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Initializes from snapshot if possible. Otherwise, attempts to
2688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * initialize from scratch.  This function is called implicitly if
2689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * you use the API without calling it first.
2690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool Initialize();
2692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Adjusts the amount of registered external memory.  Used to give
2695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 an indication of the amount of externally allocated memory
2696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that is kept alive by JavaScript objects.  V8 uses this to decide
2697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * when to perform global garbage collections.  Registering
2698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * externally allocated memory will trigger global garbage
2699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * collections more often than otherwise in an attempt to garbage
2700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * collect the JavaScript objects keeping the externally allocated
2701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * memory alive.
2702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param change_in_bytes the change in externally allocated memory
2704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   that is kept alive by JavaScript objects.
2705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \returns the adjusted value.
2706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
2708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Suspends recording of tick samples in the profiler.
2711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When the V8 profiling mode is enabled (usually via command line
2712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * switches) this function suspends recording of tick samples.
2713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Profiling ticks are discarded until ResumeProfiler() is called.
2714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See also the --prof and --prof_auto command line switches to
2716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enable V8 profiling.
2717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void PauseProfiler();
2719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Resumes recording of tick samples in the profiler.
2722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See also PauseProfiler().
2723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ResumeProfiler();
2725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Return whether profiler is currently paused.
2728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsProfilerPaused();
2730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2732402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Resumes specified profiler modules. Can be called several times to
2733402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * mark the opening of a profiler events block with the given tag.
2734402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
2735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CPU)".
2736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ProfilerModules enum.
2737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param flags Flags specifying profiler modules.
2739402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param tag Profile tag.
2740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2741402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static void ResumeProfilerEx(int flags, int tag = 0);
2742a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2744402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Pauses specified profiler modules. Each call to "PauseProfilerEx" closes
2745402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * a block of profiler events opened by a call to "ResumeProfilerEx" with the
2746402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * same tag value. There is no need for blocks to be properly nested.
2747402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * The profiler is paused when the last opened block is closed.
2748402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
2749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)".
2750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ProfilerModules enum.
2751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param flags Flags specifying profiler modules.
2753402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param tag Profile tag.
2754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2755402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static void PauseProfilerEx(int flags, int tag = 0);
2756a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns active (resumed) profiler modules.
2759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ProfilerModules enum.
2760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \returns active profiler modules.
2762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int GetActiveProfilerModules();
2764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If logging is performed into a memory buffer (via --logfile=*), allows to
2767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * retrieve previously written messages. This can be used for retrieving
2768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * profiler log data in the application. This function is thread-safe.
2769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Caller provides a destination buffer that must exist during GetLogLines
2771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * call. Only whole log lines are copied into the buffer.
2772a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param from_pos specified a point in a buffer to read from, 0 is the
2774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   beginning of a buffer. It is assumed that caller updates its current
2775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   position using returned size value from the previous call.
2776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param dest_buf destination buffer for log data.
2777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param max_size size of the destination buffer.
2778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \returns actual size of log data copied into buffer.
2779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int GetLogLines(int from_pos, char* dest_buf, int max_size);
2781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2782a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
27836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The minimum allowed size for a log lines buffer.  If the size of
27846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * the buffer given will not be enough to hold a line of the maximum
27856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * length, an attempt to find a log line end in GetLogLines will
27866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * fail, and an empty result will be returned.
27876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
27886ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kMinimumSizeForLogLinesBuffer = 2048;
27896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
27906ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
2791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Retrieve the V8 thread id of the calling thread.
2792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The thread id for a thread should only be retrieved after the V8
2794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * lock has been acquired with a Locker object with that thread.
2795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int GetCurrentThreadId();
2797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Forcefully terminate execution of a JavaScript thread.  This can
2800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be used to terminate long-running scripts.
2801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TerminateExecution should only be called when then V8 lock has
2803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been acquired with a Locker object.  Therefore, in order to be
2804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * able to terminate long-running threads, preemption must be
2805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enabled to allow the user of TerminateExecution to acquire the
2806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * lock.
2807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The termination is achieved by throwing an exception that is
2809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * uncatchable by JavaScript exception handlers.  Termination
2810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exceptions act as if they were caught by a C++ TryCatch exception
2811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handlers.  If forceful termination is used, any C++ TryCatch
2812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exception handler that catches an exception should check if that
2813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exception is a termination exception and immediately return if
2814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that is the case.  Returning immediately in that case will
2815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * continue the propagation of the termination exception if needed.
2816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The thread id passed to TerminateExecution must have been
2818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * obtained by calling GetCurrentThreadId on the thread in question.
2819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param thread_id The thread id of the thread to terminate.
2821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void TerminateExecution(int thread_id);
2823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2825a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Forcefully terminate the current thread of JavaScript execution.
2826a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2827a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This method can be used by any thread even if that thread has not
2828a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * acquired the V8 lock with a Locker object.
2829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void TerminateExecution();
2831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
28336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Is V8 terminating JavaScript execution.
28346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *
28356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Returns true if JavaScript execution is currently terminating
28366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * because of a call to TerminateExecution.  In that case there are
28376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * still JavaScript frames on the stack and the termination
28386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * exception is still active.
28396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
28406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static bool IsExecutionTerminating();
28416ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
28426ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
2843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Releases any resources used by v8 and stops any utility threads
2844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that may be running.  Note that disposing v8 is permanent, it
2845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * cannot be reinitialized.
2846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * It should generally not be necessary to dispose v8 before exiting
2848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a process, this should happen automatically.  It is only necessary
2849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to use if the process needs the resources taken up by v8.
2850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool Dispose();
2852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
28543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Get statistics about the heap memory usage.
28553ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
28563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static void GetHeapStatistics(HeapStatistics* heap_statistics);
2857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Optional notification that the embedder is idle.
2860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 uses the notification to reduce memory footprint.
2861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This call can be used repeatedly if the embedder remains idle.
2862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the embedder should stop calling IdleNotification
2863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * until real work has been done.  This indicates that V8 has done
2864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * as much cleanup as it will be able to do.
2865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
28663ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static bool IdleNotification();
2867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Optional notification that the system is running low on memory.
2870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 uses these notifications to attempt to free memory.
2871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void LowMemoryNotification();
2873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
28756ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Optional notification that a context has been disposed. V8 uses
28766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * these notifications to guide the GC heuristic. Returns the number
28776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * of context disposals - including this one - since the last time
28786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * V8 had a chance to clean up.
28796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
28806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static int ContextDisposedNotification();
28816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
2882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8();
2884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static internal::Object** GlobalizeReference(internal::Object** handle);
2886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void DisposeGlobal(internal::Object** global_handle);
2887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void MakeWeak(internal::Object** global_handle,
2888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       void* data,
2889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       WeakReferenceCallback);
2890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ClearWeak(internal::Object** global_handle);
2891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsGlobalNearDeath(internal::Object** global_handle);
2892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsGlobalWeak(internal::Object** global_handle);
2893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Handle;
2895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Local;
2896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Persistent;
2897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Context;
2898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An external exception handler.
2903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TryCatch {
2905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new try/catch block and registers it with v8.
2909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  TryCatch();
2911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Unregisters and deletes this try/catch block.
2914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~TryCatch();
2916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if an exception has been caught by this try/catch block.
2919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasCaught() const;
2921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * For certain types of exceptions, it makes no sense to continue
2924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * execution.
2925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Currently, the only type of exception that can be caught by a
2927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TryCatch handler and for which it does not make sense to continue
2928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is termination exception.  Such exceptions are thrown when the
2929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TerminateExecution methods are called to terminate a long-running
2930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * script.
2931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If CanContinue returns false, the correct action is to perform
2933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * any C++ cleanup needed and then return.
2934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool CanContinue() const;
2936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2938d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * Throws the exception caught by this TryCatch in a way that avoids
2939d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * it being caught again by this same TryCatch.  As with ThrowException
2940d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * it is illegal to execute any JavaScript operations after calling
2941d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * ReThrow; the caller must return immediately to where the exception
2942d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * is caught.
2943d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   */
2944d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  Handle<Value> ReThrow();
2945d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
2946d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /**
2947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the exception caught by this try/catch block.  If no exception has
2948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been caught an empty handle is returned.
2949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The returned handle is valid until this TryCatch block has been destroyed.
2951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Exception() const;
2953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the .stack property of the thrown object.  If no .stack
2956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * property is present an empty handle is returned.
2957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> StackTrace() const;
2959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the message associated with this exception.  If there is
2962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * no message associated an empty handle is returned.
2963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The returned handle is valid until this TryCatch block has been
2965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * destroyed.
2966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<v8::Message> Message() const;
2968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clears any exceptions that may have been caught by this try/catch block.
2971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * After this method has been called, HasCaught() will return false.
2972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * It is not necessary to clear a try/catch block before using it again; if
2974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * another exception is thrown the previously caught exception will just be
2975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * overwritten.  However, it is often a good idea since it makes it easier
2976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to determine which operation threw a given exception.
2977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Reset();
2979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set verbosity of the external exception handler.
2982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * By default, exceptions that are caught by an external exception
2984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler are not reported.  Call SetVerbose with true on an
2985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * external exception handler to have exceptions caught by the
2986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler reported as if they were not caught.
2987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetVerbose(bool value);
2989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set whether or not this TryCatch should capture a Message object
2992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * which holds source information about where the exception
2993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * occurred.  True by default.
2994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCaptureMessage(bool value);
2996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2997d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block private:
2998d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void* next_;
2999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* exception_;
3000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* message_;
3001d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool is_verbose_ : 1;
3002d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool can_continue_ : 1;
3003d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool capture_message_ : 1;
3004d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool rethrow_ : 1;
3005d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3006d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  friend class v8::internal::Top;
3007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- C o n t e x t ---
3011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
3015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ExtensionConfiguration {
3017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ExtensionConfiguration(int name_count, const char* names[])
3019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : name_count_(name_count), names_(names) { }
3020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
3022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int name_count_;
3023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** names_;
3024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A sandboxed execution context with its own set of built-in objects
3029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and functions.
3030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Context {
3032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the global object of the context. */
3034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Object> Global();
3035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Detaches the global object from its context before
3038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the global object can be reused to create a new context.
3039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void DetachGlobal();
3041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
304274b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu  /**
304374b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * Reattaches a global object to a context.  This can be used to
304474b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * restore the connection between a global object and a context
304574b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * after DetachGlobal has been called.
304674b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *
304774b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * \param global_object The global object to reattach to the
304874b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   context.  For this to work, the global object must be the global
304974b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   object that was associated with this context before a call to
305074b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   DetachGlobal.
305174b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   */
305274b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu  void ReattachGlobal(Handle<Object> global_object);
305374b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu
3054f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /** Creates a new context.
3055f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
3056f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns a persistent handle to the newly allocated context. This
3057f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * persistent handle has to be disposed when the context is no
3058f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * longer used so the context can be garbage collected.
3059f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
3060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Persistent<Context> New(
30613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu      ExtensionConfiguration* extensions = NULL,
3062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
3063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Value> global_object = Handle<Value>());
3064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the last entered context. */
3066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetEntered();
3067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the context that is on the top of the stack. */
3069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetCurrent();
3070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the context of the calling JavaScript code.  That is the
3073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context of the top-most JavaScript frame.  If there are no
3074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * JavaScript frames an empty handle is returned.
3075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetCalling();
3077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the security token for the context.  To access an object in
3080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * another context, the security tokens must match.
3081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetSecurityToken(Handle<Value> token);
3083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Restores the security token to the default value. */
3085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void UseDefaultSecurityToken();
3086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the security token of this context.*/
3088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetSecurityToken();
3089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enter this context.  After entering a context, all code compiled
3092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * and run is compiled and run in this context.  If another context
3093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is already entered, this old context is saved so it can be
3094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * restored when the new context is exited.
3095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Enter();
3097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Exit this context.  Exiting the current context restores the
3100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context that was in place when entering the current context.
3101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Exit();
3103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns true if the context has experienced an out of memory situation. */
3105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasOutOfMemoryException();
3106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns true if V8 has a current context. */
3108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool InContext();
3109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an additional data object with the context. This is mainly used
3112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * with the debugger to provide additional information on the context through
3113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the debugger API.
3114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3115d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void SetData(Handle<String> data);
3116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> GetData();
3117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Stack-allocated class which sets the execution context for all
3120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations executed within a local scope.
3121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
31228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  class Scope {
3123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
3124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline Scope(Handle<Context> context) : context_(context) {
3125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      context_->Enter();
3126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
3127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline ~Scope() { context_->Exit(); }
3128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
3129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Handle<Context> context_;
3130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
3131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Value;
3134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Script;
3135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Object;
3136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Function;
3137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Multiple threads in V8 are allowed, but only one thread at a time
3142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is allowed to use V8.  The definition of 'using V8' includes
3143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * accessing handles or holding onto object pointers obtained from V8
3144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles.  It is up to the user of V8 to ensure (perhaps with
3145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * locking) that this constraint is not violated.
3146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you wish to start using V8 in a thread you can do this by constructing
3148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a v8::Locker object.  After the code using V8 has completed for the
3149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * current thread you can call the destructor.  This can be combined
3150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * with C++ scope-based construction as follows:
3151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ...
3154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   v8::Locker locker;
3156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // Code using V8 goes here.
3158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here
3160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you wish to stop using V8 in a thread A you can do this by either
3163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * by destroying the v8::Locker object as above or by constructing a
3164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Unlocker object:
3165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   v8::Unlocker unlocker;
3169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // Code not using V8 goes here while V8 can run in another thread.
3171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here.
3173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Unlocker object is intended for use in a long-running callback
3176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * from V8, where you want to release the V8 lock for other threads to
3177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * use.
3178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The v8::Locker is a recursive lock.  That is, you can lock more than
3180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * once in a given thread.  This can be useful if you have code that can
3181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be called either from code that holds the lock or from code that does
3182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * not.  The Unlocker is not recursive so you can not have several
3183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Unlockers on the stack at once, and you can not use an Unlocker in a
3184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * thread that is not inside a Locker's scope.
3185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An unlocker will unlock several lockers if it has to and reinstate
3187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the correct depth of locking on its destruction. eg.:
3188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 not locked.
3191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   v8::Locker locker;
3193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // V8 locked.
3194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   {
3195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     v8::Locker another_locker;
3196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     // V8 still locked (2 levels).
3197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     {
3198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *       v8::Unlocker unlocker;
3199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *       // V8 not locked.
3200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     }
3201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     // V8 locked again (2 levels).
3202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   }
3203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // V8 still locked (1 level).
3204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * }
3205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 Now no longer locked.
3206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Unlocker {
3209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Unlocker();
3211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~Unlocker();
3212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Locker {
3216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Locker();
3218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~Locker();
3219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Start preemption.
3222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When preemption is started, a timer is fired every n milli seconds
3224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that will switch between multiple threads that are in contention
3225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * for the V8 lock.
3226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void StartPreemption(int every_n_ms);
3228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Stop preemption.
3231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void StopPreemption();
3233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns whether or not the locker is locked by the current thread.
3236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsLocked();
3238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns whether v8::Locker is being used by this V8 instance.
3241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsActive() { return active_; }
3243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool has_lock_;
3246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool top_level_;
3247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool active_;
3249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Disallow copying and assigning.
3251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Locker(const Locker&);
3252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const Locker&);
3253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
32560d5e116f6aee03185f237311a943491bb079a768Kristian Monsen/**
32570d5e116f6aee03185f237311a943491bb079a768Kristian Monsen * An interface for exporting data from V8, using "push" model.
32580d5e116f6aee03185f237311a943491bb079a768Kristian Monsen */
32593e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhuclass V8EXPORT OutputStream {  // NOLINT
32603e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu public:
32610d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  enum OutputEncoding {
32620d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kAscii = 0  // 7-bit ASCII.
32630d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  };
32640d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  enum WriteResult {
32650d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kContinue = 0,
32660d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kAbort = 1
32670d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  };
32680d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual ~OutputStream() {}
32690d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Notify about the end of stream. */
32700d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual void EndOfStream() = 0;
32710d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Get preferred output chunk size. Called only once. */
32720d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual int GetChunkSize() { return 1024; }
32730d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Get preferred output encoding. Called only once. */
32740d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual OutputEncoding GetOutputEncoding() { return kAscii; }
32750d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /**
32760d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * Writes the next chunk of snapshot data into the stream. Writing
32770d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * can be stopped by returning kAbort as function result. EndOfStream
32780d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * will not be called in case writing was aborted.
32790d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   */
32800d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
32810d5e116f6aee03185f237311a943491bb079a768Kristian Monsen};
32820d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
32830d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
3284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- I m p l e m e n t a t i o n ---
3286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
3289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
32908a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangstatic const int kApiPointerSize = sizeof(void*);  // NOLINT
32918a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangstatic const int kApiIntSize = sizeof(int);  // NOLINT
3292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for HeapObject.
3294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTag = 1;
3295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTagSize = 2;
3296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
3297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for Smi.
3299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTag = 0;
3300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTagSize = 1;
3301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
3302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
33033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <size_t ptr_size> struct SmiConstants;
33043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 32-bit systems.
33063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <> struct SmiConstants<4> {
33073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiShiftSize = 0;
33083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiValueSize = 31;
33093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int SmiToInt(internal::Object* value) {
33103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    int shift_bits = kSmiTagSize + kSmiShiftSize;
33113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // Throw away top 32 bits and shift down (requires >> to be sign extending).
33123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
33133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
33153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 64-bit systems.
33173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <> struct SmiConstants<8> {
33183ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiShiftSize = 31;
33193ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiValueSize = 32;
33203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int SmiToInt(internal::Object* value) {
33213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    int shift_bits = kSmiTagSize + kSmiShiftSize;
33223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // Shift down and throw away top 32 bits.
33233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
33243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33253ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
33263ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33278a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangconst int kSmiShiftSize = SmiConstants<kApiPointerSize>::kSmiShiftSize;
33288a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wangconst int kSmiValueSize = SmiConstants<kApiPointerSize>::kSmiValueSize;
3329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3330d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <size_t ptr_size> struct InternalConstants;
3331d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3332d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 32-bit systems.
3333d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<4> {
33348a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kStringResourceOffset = 3 * kApiPointerSize;
3335d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block};
3336d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3337d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 64-bit systems.
3338d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<8> {
33398a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kStringResourceOffset = 3 * kApiPointerSize;
3340d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block};
3341d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This class exports constants and functionality from within v8 that
3344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is necessary to implement inline functions in the v8 api.  Don't
3345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * depend on functions and constants defined here.
3346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Internals {
3348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // These values match non-compiler-dependent values defined within
3351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the implementation of v8.
3352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeapObjectMapOffset = 0;
33538a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kMapInstanceTypeOffset = kApiPointerSize + kApiIntSize;
3354d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kStringResourceOffset =
33558a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang      InternalConstants<kApiPointerSize>::kStringResourceOffset;
3356d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
33578a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kProxyProxyOffset = kApiPointerSize;
33588a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
3359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFullStringRepresentationMask = 0x07;
33607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kExternalTwoByteRepresentationTag = 0x02;
3361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
33629dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kJSObjectType = 0x9f;
33639dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kFirstNonstringType = 0x80;
33649dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kProxyType = 0x85;
3365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool HasHeapObjectTag(internal::Object* value) {
3367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
3368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            kHeapObjectTag);
3369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool HasSmiTag(internal::Object* value) {
3372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
3373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline int SmiValue(internal::Object* value) {
33768a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang    return SmiConstants<kApiPointerSize>::SmiToInt(value);
33773ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33783ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33793ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int GetInstanceType(internal::Object* obj) {
33803ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    typedef internal::Object O;
33813ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
33823ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
33833ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33843ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33853ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline void* GetExternalPointer(internal::Object* obj) {
33863ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    if (HasSmiTag(obj)) {
33873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block      return obj;
33883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    } else if (GetInstanceType(obj) == kProxyType) {
33893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block      return ReadField<void*>(obj, kProxyProxyOffset);
33903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    } else {
33913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block      return NULL;
33923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    }
3393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool IsExternalTwoByteString(int instance_type) {
3396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int representation = (instance_type & kFullStringRepresentationMask);
3397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return representation == kExternalTwoByteRepresentationTag;
3398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <typename T>
3401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline T ReadField(Object* ptr, int offset) {
3402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
3403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return *reinterpret_cast<T*>(addr);
3404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
34073e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu}  // namespace internal
3408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<T>::Handle() : val_(0) { }
3412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T>::Local() : Handle<T>() { }
3416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> Local<T>::New(Handle<T> that) {
3420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (that.IsEmpty()) return Local<T>();
3421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** p = reinterpret_cast<internal::Object**>(*that);
3422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
3423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T> Persistent<T>::New(Handle<T> that) {
3428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (that.IsEmpty()) return Persistent<T>();
3429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** p = reinterpret_cast<internal::Object**>(*that);
3430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
3431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsNearDeath() const {
3436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return false;
3437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
3438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsWeak() const {
3443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return false;
3444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
3445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::Dispose() {
3450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return;
3451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
3452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T>::Persistent() : Handle<T>() { }
3457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
3460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
3461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block               parameters,
3462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block               callback);
3463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::ClearWeak() {
3467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
3468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
34708defd9ff6930b4e24729971a61cf7469daf119beSteve Block
34713e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui ZhuArguments::Arguments(internal::Object** implicit_args,
34723e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                     internal::Object** values, int length,
34733e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                     bool is_construct_call)
34743e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu    : implicit_args_(implicit_args),
34753e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      values_(values),
34763e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      length_(length),
34773e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      is_construct_call_(is_construct_call) { }
34788defd9ff6930b4e24729971a61cf7469daf119beSteve Block
34798defd9ff6930b4e24729971a61cf7469daf119beSteve Block
3480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::operator[](int i) const {
3481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
3482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
3483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Function> Arguments::Callee() const {
34873e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  return Local<Function>(reinterpret_cast<Function*>(
34883e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      &implicit_args_[kCalleeIndex]));
3489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::This() const {
3493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
3494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::Holder() const {
34983e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  return Local<Object>(reinterpret_cast<Object*>(
34993e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      &implicit_args_[kHolderIndex]));
3500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::Data() const {
35043e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
3505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Arguments::IsConstructCall() const {
3509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return is_construct_call_;
3510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockint Arguments::Length() const {
3514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return length_;
3515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> HandleScope::Close(Handle<T> value) {
3520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** before = reinterpret_cast<internal::Object**>(*value);
3521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** after = RawClose(before);
3522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<T>(reinterpret_cast<T*>(after));
3523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> ScriptOrigin::ResourceName() const {
3526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_name_;
3527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceLineOffset() const {
3531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_line_offset_;
3532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceColumnOffset() const {
3536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_column_offset_;
3537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> Boolean::New(bool value) {
3541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return value ? True() : False();
3542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Template::Set(const char* name, v8::Handle<Data> value) {
3546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Set(v8::String::New(name), value);
3547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::GetInternalField(int index) {
3551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_ENABLE_CHECKS
3552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> quick_result = UncheckedGetInternalField(index);
3553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (!quick_result.IsEmpty()) return quick_result;
3554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return CheckedGetInternalField(index);
3556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::UncheckedGetInternalField(int index) {
3560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
3562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(this);
35633ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::GetInstanceType(obj) == I::kJSObjectType) {
3564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If the object is a plain JSObject, which is the common case,
3565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // we know where to find the internal fields and can return the
3566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // value directly.
35678a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang    int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
3568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    O* value = I::ReadField<O*>(obj, offset);
3569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    O** result = HandleScope::CreateHandle(value);
3570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<Value>(reinterpret_cast<Value*>(result));
3571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  } else {
3572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<Value>();
3573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::Unwrap(Handle<v8::Value> obj) {
3578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return FullUnwrap(obj);
3580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
3581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return QuickUnwrap(obj);
3582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::QuickUnwrap(Handle<v8::Value> wrapper) {
3587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
35893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return internal::Internals::GetExternalPointer(obj);
3590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* Object::GetPointerFromInternalField(int index) {
35943ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  typedef internal::Object O;
35953ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  typedef internal::Internals I;
35963ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
35973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  O* obj = *reinterpret_cast<O**>(this);
35983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
35993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::GetInstanceType(obj) == I::kJSObjectType) {
36003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // If the object is a plain JSObject, which is the common case,
36013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // we know where to find the internal fields and can return the
36023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // value directly.
36038a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang    int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
36043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    O* value = I::ReadField<O*>(obj, offset);
36053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return I::GetExternalPointer(value);
36063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
36073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
36083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return SlowGetPointerFromInternalField(index);
3609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString* String::Cast(v8::Value* value) {
3613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<String*>(value);
3617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString::ExternalStringResource* String::GetExternalStringResource() const {
3621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
3623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
3624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  String::ExternalStringResource* result;
36253ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
3626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
3627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    result = reinterpret_cast<String::ExternalStringResource*>(value);
3628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  } else {
3629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    result = NULL;
3630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  VerifyExternalStringResource(result);
3633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return result;
3635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::IsString() const {
3639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return FullIsString();
3641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
3642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return QuickIsString();
3643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::QuickIsString() const {
3647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
3649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
3650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (!I::HasHeapObjectTag(obj)) return false;
36513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
3652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockNumber* Number::Cast(v8::Value* value) {
3656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Number*>(value);
3660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockInteger* Integer::Cast(v8::Value* value) {
3664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Integer*>(value);
3668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDate* Date::Cast(v8::Value* value) {
3672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Date*>(value);
3676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3679f87a203d89e1bbb6708282e0b64dbd13d59b723dBen MurdochRegExp* RegExp::Cast(v8::Value* value) {
3680f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch#ifdef V8_ENABLE_CHECKS
3681f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  CheckCast(value);
3682f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch#endif
3683f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  return static_cast<RegExp*>(value);
3684f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch}
3685f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
3686f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
3687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockObject* Object::Cast(v8::Value* value) {
3688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Object*>(value);
3692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockArray* Array::Cast(v8::Value* value) {
3696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Array*>(value);
3700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockFunction* Function::Cast(v8::Value* value) {
3704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Function*>(value);
3708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockExternal* External::Cast(v8::Value* value) {
3712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<External*>(value);
3716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> AccessorInfo::Data() const {
37206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
3721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::This() const {
3725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
3726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::Holder() const {
3730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
3731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example shell.cc
3736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A simple shell that takes a list of expressions on the
3737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * command-line and executes them.
3738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3741a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3742a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example process.cc
3743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}  // namespace v8
3747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef V8EXPORT
3750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef TYPE_CHECK
3751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // V8_H_
3754