1257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// Copyright 2011 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;
833fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochclass StringObject;
84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Value;
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Utils;
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Number;
873fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochclass NumberObject;
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Object;
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Array;
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Int32;
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Uint32;
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass External;
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Primitive;
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Boolean;
953fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochclass BooleanObject;
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Integer;
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Function;
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Date;
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ImplementationUtilities;
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Signature;
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Handle;
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Local;
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Persistent;
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass FunctionTemplate;
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ObjectTemplate;
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Data;
107f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeclass AccessorInfo;
10825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackTrace;
10925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackFrame;
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Arguments;
114d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blockclass Object;
1157f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochclass Heap;
11644f0eee88ff00398ff7f715fab053374d808c90dSteve Blockclass HeapObject;
11744f0eee88ff00398ff7f715fab053374d808c90dSteve Blockclass Isolate;
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
121257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Weak Handles ---
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A weak reference callback function.
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
12750ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * This callback should either explicitly invoke Dispose on |object| if
12850ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak.
12950ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen *
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param object the weak global object to be reclaimed by the garbage collector
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param parameter the value passed in when making the weak global object
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*WeakReferenceCallback)(Persistent<Value> object,
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      void* parameter);
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
137257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Handles ---
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
13950ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen#define TYPE_CHECK(T, S)                                       \
14050ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen  while (false) {                                              \
14150ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen    *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference managed by the v8 garbage collector.
146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * All objects returned from v8 have to be tracked by the garbage
148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * collector so that it knows that the objects are still alive.  Also,
149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * because the garbage collector may move objects, it is unsafe to
150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * point directly to an object.  Instead, all objects are stored in
151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles which are known by the garbage collector and updated
152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * whenever an object moves.  Handles should always be passed by value
153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * (except in cases like out-parameters) and they should never be
154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated on the heap.
155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * There are two types of handles: local and persistent handles.
157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local handles are light-weight and transient and typically used in
158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * local operations.  They are managed by HandleScopes.  Persistent
159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles can be used when storing objects across several independent
160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operations and have to be explicitly deallocated when they're no
161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * longer used.
162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * It is safe to extract the object stored in the handle by
164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * dereferencing the handle (for instance, to extract the Object* from
165257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * a Handle<Object>); the value will still be governed by a handle
166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * behind the scenes and the same rules apply to these values as to
167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * their handles.
168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1698defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Handle {
170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates an empty handle.
173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
17469a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  inline Handle() : val_(0) {}
175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new handle for the specified value.
178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
17969a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  inline explicit Handle(T* val) : val_(val) {}
180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a handle for the contents of the specified handle.  This
183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * constructor allows you to pass handles as arguments by value and
184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to assign between handles.  However, if you try to assign between
185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * incompatible handles, for instance from a Handle<String> to a
186257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Handle<Number> it will cause a compile-time error.  Assigning
187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * between compatible handles, for instance assigning a
188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Handle<String> to a variable declared as Handle<Value>, is legal
189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * because String is a subclass of Value.
190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Handle(Handle<S> that)
192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : val_(reinterpret_cast<T*>(*that)) {
193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the handle is empty.
203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2048defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline bool IsEmpty() const { return val_ == 0; }
205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the handle to be empty. IsEmpty() will then return true.
208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
20969a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  inline void Clear() { val_ = 0; }
21069a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch
21169a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  inline T* operator->() const { return val_; }
21269a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch
21369a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  inline T* operator*() const { return val_; }
214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Checks whether two handles are the same.
217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if both are empty, or if the objects
218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to which they refer are identical.
219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The handles' references are not checked.
220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2218defd9ff6930b4e24729971a61cf7469daf119beSteve Block  template <class S> inline bool operator==(Handle<S> that) const {
222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** a = reinterpret_cast<internal::Object**>(**this);
223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** b = reinterpret_cast<internal::Object**>(*that);
224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (a == 0) return b == 0;
225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (b == 0) return false;
226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return *a == *b;
227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Checks whether two handles are different.
231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if only one of the handles is empty, or if
232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the objects to which they refer are different.
233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The handles' references are not checked.
234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2358defd9ff6930b4e24729971a61cf7469daf119beSteve Block  template <class S> inline bool operator!=(Handle<S> that) const {
236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return !operator==(that);
237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Handle<T> Cast(Handle<S> that) {
240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Handle<T>();
244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Handle<T>(T::Cast(*that));
246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Handle<S> As() {
2496ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Handle<S>::Cast(*this);
2506ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
2516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  T* val_;
254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A light-weight stack-allocated object handle.  All operations
259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that return objects from within v8 return them in local handles.  They
260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are created within HandleScopes, and all local handles allocated within a
261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope are destroyed when the handle scope is destroyed.  Hence it
262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is not necessary to explicitly deallocate local handles.
263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2648defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Local : public Handle<T> {
265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local();
267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Local(Local<S> that)
268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(reinterpret_cast<T*>(*that)) {
269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Local(S* that) : Handle<T>(that) { }
277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Local<T> Cast(Local<S> that) {
278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Local<T>();
282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<T>(T::Cast(*that));
284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Local<S> As() {
2876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Local<S>::Cast(*this);
2886ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
2896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Create a local handle for the content of another handle.
291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *  The referee is kept alive by the local handle even when
292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *  the original handle is destroyed/disposed.
293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline static Local<T> New(Handle<T> that);
295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference that is independent of any handle scope.  Where
300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a Local handle only lives as long as the HandleScope in which it was
301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated, a Persistent handle remains valid until it is explicitly
302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * disposed.
303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A persistent handle contains a reference to a storage cell within
305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the v8 engine which holds an object value and which is updated by
306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the garbage collector whenever the object is moved.  A new storage
307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * cell can be created using Persistent::New and existing handles can
308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be disposed using Persistent::Dispose.  Since persistent handles
309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are passed by value you may have many persistent handle objects
310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that point to the same storage cell.  For instance, if you pass a
311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * persistent handle as an argument to a function you will not get two
312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * different storage cells but rather two references to the same
313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * storage cell.
314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3158defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Persistent : public Handle<T> {
316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates an empty persistent handle that doesn't point to any
319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * storage cell.
320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Persistent();
322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a persistent handle for the same storage cell as the
325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * specified handle.  This constructor allows you to pass persistent
326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handles as arguments by value and to assign between persistent
327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handles.  However, attempting to assign between incompatible
328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * persistent handles, for instance from a Persistent<String> to a
329257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Persistent<Number> will cause a compile-time error.  Assigning
330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * between compatible persistent handles, for instance assigning a
331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Persistent<String> to a variable declared as Persistent<Value>,
332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is allowed as String is a subclass of Value.
333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Persistent(Persistent<S> that)
335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(reinterpret_cast<T*>(*that)) {
336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Persistent(S* that) : Handle<T>(that) { }
345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * "Casts" a plain handle which is known to be a persistent handle
348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to a persistent handle.
349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> explicit inline Persistent(Handle<S> that)
351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(*that) { }
352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Persistent<T>();
358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Persistent<T>(T::Cast(*that));
360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Persistent<S> As() {
3636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Persistent<S>::Cast(*this);
3646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
3656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new persistent handle for an existing local or
368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * persistent handle.
369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline static Persistent<T> New(Handle<T> that);
371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Releases the storage cell referenced by this persistent handle.
374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Does not remove the reference to the cell from any handles.
375257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * This handle's reference, and any other references to the storage
376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * cell remain and IsEmpty will still return false.
377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Dispose();
379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Make the reference to this object weak.  When only weak handles
382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * refer to the object, the garbage collector will perform a
383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback to the given V8::WeakReferenceCallback function, passing
384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * it the object reference and the given parameters.
385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Clears the weak reference to this object.*/
389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ClearWeak();
390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
392257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Marks the reference to this object independent. Garbage collector
393257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * is free to ignore any object groups containing this object.
394257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Weak callback for an independent handle should not
395257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * assume that it will be preceded by a global GC prologue callback
396257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * or followed by a global GC epilogue callback.
397257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
398257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  inline void MarkIndependent();
399257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
400257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *Checks if the handle holds the only reference to an object.
402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsNearDeath() const;
404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the handle's reference is weak.
407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsWeak() const;
409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
41044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
41144f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Assigns a wrapper class ID to the handle. See RetainedObjectInfo
41244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * interface description in v8-profiler.h for details.
41344f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
41444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void SetWrapperClassId(uint16_t class_id);
41544f0eee88ff00398ff7f715fab053374d808c90dSteve Block
416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /**
423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A stack-allocated class that governs a number of local handles.
424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After a handle scope has been created, all local handles will be
425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated within that handle scope until either the handle scope is
426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * deleted or another handle scope is created.  If there is already a
427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope and a new one is created, all allocations will take
428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * place in the new handle scope until it is deleted.  After that,
429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * new handles will again be allocated in the original handle scope.
430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After the handle scope of a local handle has been deleted the
432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * garbage collector will no longer track the object stored in the
433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle and may deallocate it.  The behavior of accessing a handle
434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for which the handle scope has been deleted is undefined.
435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT HandleScope {
437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  HandleScope();
439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~HandleScope();
441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Closes the handle scope and returns the value as a handle in the
444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * previous scope, which is the new current scope after the call.
445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> Local<T> Close(Handle<T> value);
447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Counts the number of allocated handles.
450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int NumberOfHandles();
452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new handle with the given value.
455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static internal::Object** CreateHandle(internal::Object* value);
45744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Faster version, uses HeapObject to obtain the current Isolate.
45844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static internal::Object** CreateHandle(internal::HeapObject* value);
459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Make it impossible to create heap-allocated or illegal handle
462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // scopes by disallowing certain operations.
463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  HandleScope(const HandleScope&);
464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const HandleScope&);
465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* operator new(size_t size);
466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator delete(void*, size_t);
467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
468d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // This Data class is accessible internally as HandleScopeData through a
469d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // typedef in the ImplementationUtilities class.
470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Data {
471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** next;
473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** limit;
4745913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    int level;
475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline void Initialize() {
476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      next = limit = NULL;
4775913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      level = 0;
478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
4803e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu
4815913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  void Leave();
482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
48344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  internal::Isolate* isolate_;
4845913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  internal::Object** prev_next_;
4855913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  internal::Object** prev_limit_;
486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Allow for the active closing of HandleScopes which allows to pass a handle
488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // from the HandleScope being closed to the next top most HandleScope.
489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_closed_;
490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** RawClose(internal::Object** value);
491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
496257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Special objects ---
497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of values and API object templates.
501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Data {
503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Data();
505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Pre-compilation data that can be associated with a script.  This
510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data can be calculated for a script in advance of actually
511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * compiling it, and can be stored between compilations.  When script
512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data is given to the compile method compilation will be faster.
513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ScriptData {  // NOLINT
515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~ScriptData() { }
5177f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
518f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
519f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Pre-compiles the specified script (context-independent).
520f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
521f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param input Pointer to UTF-8 script source code.
522f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param length Length of UTF-8 script source code.
523f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static ScriptData* PreCompile(const char* input, int length);
525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
526f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
5277f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * Pre-compiles the specified script (context-independent).
5287f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   *
5297f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * NOTE: Pre-compilation using this method cannot happen on another thread
5307f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * without using Lockers.
5317f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   *
5327f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * \param source Script source code.
5337f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   */
5347f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static ScriptData* PreCompile(Handle<String> source);
5357f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
5367f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  /**
537f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Load previous pre-compilation data.
538f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
539f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param data Pointer to data returned by a call to Data() of a previous
540f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *   ScriptData. Ownership is not transferred.
541f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param length Length of data.
542f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
543f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  static ScriptData* New(const char* data, int length);
544f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
545f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
546f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns the length of Data().
547f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual int Length() = 0;
549f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
550f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
551f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns a serialized representation of this ScriptData that can later be
552f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * passed to New(). NOTE: Serialized data is platform-dependent.
553f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
554f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  virtual const char* Data() = 0;
555f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
556f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
557f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns true if the source code could not be parsed.
558f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
559e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  virtual bool HasError() = 0;
560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The origin, within a file, of a script.
565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
5668defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass ScriptOrigin {
567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5688defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline ScriptOrigin(
5698defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Value> resource_name,
5708defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Integer> resource_line_offset = Handle<Integer>(),
5718defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Integer> resource_column_offset = Handle<Integer>())
572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : resource_name_(resource_name),
573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        resource_line_offset_(resource_line_offset),
574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        resource_column_offset_(resource_column_offset) { }
575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Value> ResourceName() const;
576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Integer> ResourceLineOffset() const;
577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Integer> ResourceColumnOffset() const;
578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> resource_name_;
580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Integer> resource_line_offset_;
581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Integer> resource_column_offset_;
582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A compiled JavaScript script.
587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Script {
589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
590402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
591402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script (context-independent).
592402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
593402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
5946ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param origin Script origin, owned by caller, no references are kept
595402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when New() returns
596402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
597402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   using pre_data speeds compilation if it's done multiple times.
598402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   Owned by caller, no references are kept when New() returns.
599402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
6006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *   this has same effect as calling SetData(), but allows data to be
601402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   available to compile event handlers.
602402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object (context independent; when run it
603402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   will use the currently entered context).
604402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
605402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static Local<Script> New(Handle<String> source,
606402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           ScriptOrigin* origin = NULL,
607402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           ScriptData* pre_data = NULL,
608402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           Handle<String> script_data = Handle<String>());
609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
610402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
611402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script using the specified file name
612402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * object (typically a string) as the script's origin.
613402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
614402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
6156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param file_name file name object (typically a string) to be used
616402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   as the script's origin.
617402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object (context independent; when run it
618402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   will use the currently entered context).
619402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
620402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static Local<Script> New(Handle<String> source,
621402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           Handle<Value> file_name);
622402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
623402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
624402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script (bound to current context).
625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
626402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
6276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param origin Script origin, owned by caller, no references are kept
628402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when Compile() returns
629402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
630402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   using pre_data speeds compilation if it's done multiple times.
631402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   Owned by caller, no references are kept when Compile() returns.
632402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
633402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   this has same effect as calling SetData(), but makes data available
634402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   earlier (i.e. to compile event handlers).
635402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object, bound to the context that was active
636402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when this function was called.  When run it will always use this
637402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   context.
638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Script> Compile(Handle<String> source,
640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               ScriptOrigin* origin = NULL,
641402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               ScriptData* pre_data = NULL,
642402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<String> script_data = Handle<String>());
643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Compiles the specified script using the specified file name
646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * object (typically a string) as the script's origin.
647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
648402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
649402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param file_name File name to use as script's origin
650402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
651402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   this has same effect as calling SetData(), but makes data available
652402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   earlier (i.e. to compile event handlers).
653402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object, bound to the context that was active
654402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when this function was called.  When run it will always use this
655402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   context.
656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Script> Compile(Handle<String> source,
658402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<Value> file_name,
659402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<String> script_data = Handle<String>());
660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Runs the script returning the resulting value.  If the script is
663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context independent (created using ::New) it will be run in the
664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * currently entered context.  If it is context specific (created
665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * using ::Compile) it will be run in the context in which it was
666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * compiled.
667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Run();
669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the script id value.
672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Id();
674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an additional data object with the script. This is mainly used
677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * with the debugger as this data object is only available through the
678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * debugger API.
679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
680d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void SetData(Handle<String> data);
681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An error message.
686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Message {
688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<String> Get() const;
690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<String> GetSourceLine() const;
691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the resource name for the script from where the function causing
694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error originates.
695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetScriptResourceName() const;
697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the resource data for the script from where the function causing
700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error originates.
701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetScriptData() const;
703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
7053bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * Exception stack trace. By default stack traces are not captured for
7063bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
7073bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * to change this option.
7083bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   */
7093bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  Handle<StackTrace> GetStackTrace() const;
7103bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
7113bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  /**
712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number, 1-based, of the line where the error occurred.
713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetLineNumber() const;
715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the script of the first character where
718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetStartPosition() const;
721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the script of the last character where
724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetEndPosition() const;
727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the line of the first character where
730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetStartColumn() const;
733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the line of the last character where
736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetEndColumn() const;
739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // TODO(1245381): Print to a string instead of on a FILE.
741a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void PrintCurrentStackTrace(FILE* out);
74225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
74325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kNoLineNumberInfo = 0;
74425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kNoColumnInfo = 0;
74525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen};
74625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
74725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
74825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/**
74925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Representation of a JavaScript stack trace. The information collected is a
75025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * snapshot of the execution stack and the information remains valid after
75125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * execution continues.
75225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */
75325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackTrace {
75425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public:
75525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
75625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Flags that determine what information is placed captured for each
75725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * StackFrame when grabbing the current stack trace.
75825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
75925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  enum StackTraceOptions {
76025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kLineNumber = 1,
76125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kColumnOffset = 1 << 1 | kLineNumber,
76225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kScriptName = 1 << 2,
76325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kFunctionName = 1 << 3,
76425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kIsEval = 1 << 4,
76525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kIsConstructor = 1 << 5,
766f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kScriptNameOrSourceURL = 1 << 6,
76725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
768f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
76925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  };
77025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
77125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
77225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns a StackFrame at a particular index.
77325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
77425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<StackFrame> GetFrame(uint32_t index) const;
77525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
77625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
77725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the number of StackFrames.
77825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
77925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetFrameCount() const;
78025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
78125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
78225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns StackTrace as a v8::Array that contains StackFrame objects.
78325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
78425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<Array> AsArray();
78525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
78625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
787257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Grab a snapshot of the current JavaScript execution stack.
78825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   *
78925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * \param frame_limit The maximum number of stack frames we want to capture.
79025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * \param options Enumerates the set of things we will capture for each
79125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   *   StackFrame.
79225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
79325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static Local<StackTrace> CurrentStackTrace(
79425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen      int frame_limit,
79525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen      StackTraceOptions options = kOverview);
79625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen};
79725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
79825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
79925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/**
80025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * A single JavaScript stack frame.
80125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */
80225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackFrame {
80325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public:
80425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
80525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the number, 1-based, of the line for the associate function call.
80625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * This method will return Message::kNoLineNumberInfo if it is unable to
80725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * retrieve the line number, or if kLineNumber was not passed as an option
80825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * when capturing the StackTrace.
80925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
81025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetLineNumber() const;
81125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
81225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
81325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the 1-based column offset on the line for the associated function
81425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * call.
81525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * This method will return Message::kNoColumnInfo if it is unable to retrieve
81625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * the column number, or if kColumnOffset was not passed as an option when
81725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * capturing the StackTrace.
81825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
81925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetColumn() const;
82025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
82125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
82225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the name of the resource that contains the script for the
82325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * function for this StackFrame.
82425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
82525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<String> GetScriptName() const;
82625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
82725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
828f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Returns the name of the resource that contains the script for the
829f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * function for this StackFrame or sourceURL value if the script name
830f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * is undefined and its source ends with //@ sourceURL=... string.
831f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
832f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  Local<String> GetScriptNameOrSourceURL() const;
833f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
834f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
83525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the name of the function associated with this stack frame.
83625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
83725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<String> GetFunctionName() const;
83825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
83925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
84025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns whether or not the associated function is compiled via a call to
84125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * eval().
84225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
84325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  bool IsEval() const;
84425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
84525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
846257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Returns whether or not the associated function is called as a
84725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * constructor via "new".
84825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
84925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  bool IsConstructor() const;
850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
853257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Value ---
854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of all JavaScript values and objects.
858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
8598defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Value : public Data {
860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is the undefined value.  See ECMA-262
863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 4.3.10.
864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8658defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsUndefined() const;
866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is the null value.  See ECMA-262
869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 4.3.11.
870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8718defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsNull() const;
872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   /**
874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is true.
875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8768defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsTrue() const;
877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is false.
880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsFalse() const;
882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an instance of the String type.
885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ECMA-262 8.4.
886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsString() const;
888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a function.
891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8928defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsFunction() const;
893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an array.
896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8978defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsArray() const;
898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an object.
901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9028defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsObject() const;
903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is boolean.
906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9078defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsBoolean() const;
908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a number.
911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9128defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsNumber() const;
913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is external.
916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9178defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternal() const;
918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a 32-bit signed integer.
921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsInt32() const;
923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
9256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Returns true if this value is a 32-bit unsigned integer.
9266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
9278defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsUint32() const;
9286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
9296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a Date.
931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9328defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsDate() const;
933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
934756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  /**
9353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Returns true if this value is a Boolean object.
9363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
9373fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT bool IsBooleanObject() const;
9383fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
9393fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
9403fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Returns true if this value is a Number object.
9413fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
9423fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT bool IsNumberObject() const;
9433fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
9443fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
9453fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Returns true if this value is a String object.
9463fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
9473fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT bool IsStringObject() const;
9483fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
9493fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
9503fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Returns true if this value is a NativeError.
9513fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
9523fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT bool IsNativeError() const;
9533fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
9543fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
955756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   * Returns true if this value is a RegExp.
956756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   */
957756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V8EXPORT bool IsRegExp() const;
958756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
9598defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Boolean> ToBoolean() const;
9608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Number> ToNumber() const;
9618defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ToString() const;
9628defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ToDetailString() const;
9638defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> ToObject() const;
9648defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Integer> ToInteger() const;
9658defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Uint32> ToUint32() const;
9668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Int32> ToInt32() const;
967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Attempts to convert a string to an array index.
970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns an empty handle if the conversion fails.
971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9728defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Uint32> ToArrayIndex() const;
973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
9748defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool BooleanValue() const;
9758defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double NumberValue() const;
9768defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int64_t IntegerValue() const;
9778defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Uint32Value() const;
9788defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int32_t Int32Value() const;
979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** JS == */
9818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Equals(Handle<Value> that) const;
9828defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool StrictEquals(Handle<Value> that) const;
9833ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool QuickIsString() const;
9868defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool FullIsString() const;
987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of primitive values.  See ECMA-262 4.3.2.
992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
9938defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Primitive : public Value { };
994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A primitive boolean value (ECMA-262, 4.3.14).  Either the true
998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * or false value.
999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
10008defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Boolean : public Primitive {
1001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
10028defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Value() const;
1003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Handle<Boolean> New(bool value);
1004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript string value (ECMA-262, 4.3.17).
1009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
10108defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass String : public Primitive {
1011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number of characters in this string.
1014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10158defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Length() const;
1016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number of bytes in the UTF-8 encoded
1019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * representation of this string.
1020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10218defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Utf8Length() const;
1022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
10243ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * A fast conservative check for non-ASCII characters.  May
10253ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * return true even for ASCII strings, but if it returns
10263ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * false you can be sure that all characters are in the range
10273ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * 0-127.
10283ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
10293ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  V8EXPORT bool MayContainNonAscii() const;
10303ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
10313ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
1032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Write the contents of the string to an external buffer.
1033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If no arguments are given, expects the buffer to be large
1034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enough to hold the entire string and NULL terminator. Copies
1035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the contents of the string and the NULL terminator into the
1036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer.
1037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
1038b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
1039b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   * before the end of the buffer.
1040b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   *
1041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Copies up to length characters into the output buffer.
1042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Only null-terminates if there is enough space in the buffer.
1043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
1044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param buffer The buffer into which the string will be copied.
1045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param start The starting position within the string at which
1046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * copying begins.
1047b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   * \param length The number of characters to copy from the string.  For
1048b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   *    WriteUtf8 the number of bytes in the buffer.
10496ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param nchars_ref The number of characters written, can be NULL.
105069a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch   * \param options Various options that might affect performance of this or
10516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *    subsequent operations.
1052b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   * \return The number of characters copied to the buffer excluding the null
1053b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   *    terminator.  For WriteUtf8: The number of bytes copied to the buffer
105469a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch   *    including the null terminator (if written).
1055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
105669a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  enum WriteOptions {
105769a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch    NO_OPTIONS = 0,
105869a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch    HINT_MANY_WRITES_EXPECTED = 1,
105969a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch    NO_NULL_TERMINATION = 2
10606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  };
10616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1062589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch  // 16-bit character codes.
10638defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Write(uint16_t* buffer,
10648defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     int start = 0,
10658defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     int length = -1,
1066589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch                     int options = NO_OPTIONS) const;
1067589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch  // ASCII characters.
10688defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int WriteAscii(char* buffer,
10698defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          int start = 0,
10708defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          int length = -1,
1071589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch                          int options = NO_OPTIONS) const;
1072589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch  // UTF-8 encoded characters.
10738defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int WriteUtf8(char* buffer,
10748defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         int length = -1,
10758defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         int* nchars_ref = NULL,
1076589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch                         int options = NO_OPTIONS) const;
1077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A zero length string.
1080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static v8::Local<v8::String> Empty();
1082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string is external
1085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10868defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternal() const;
1087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1089589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * Returns true if the string is both external and ASCII
1090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10918defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternalAscii() const;
1092e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
10933e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  class V8EXPORT ExternalStringResourceBase {  // NOLINT
1094e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   public:
1095e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    virtual ~ExternalStringResourceBase() {}
10967f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1097e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   protected:
1098e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    ExternalStringResourceBase() {}
10997f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
11007f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
11017f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * Internally V8 will call this Dispose method when the external string
11027f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * resource is no longer needed. The default implementation will use the
11037f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * delete operator. This method can be overridden in subclasses to
11047f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * control how allocated external string resources are disposed.
11057f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
11067f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    virtual void Dispose() { delete this; }
11077f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1108e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   private:
1109e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    // Disallow copying and assigning.
1110e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    ExternalStringResourceBase(const ExternalStringResourceBase&);
1111e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    void operator=(const ExternalStringResourceBase&);
11127f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
11137f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    friend class v8::internal::Heap;
1114e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  };
1115e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
1116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * An ExternalStringResource is a wrapper around a two-byte string
1118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer that resides outside V8's heap. Implement an
1119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ExternalStringResource to manage the life cycle of the underlying
1120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer.  Note that the string data must be immutable.
1121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1122e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  class V8EXPORT ExternalStringResource
1123e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      : public ExternalStringResourceBase {
1124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
1126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Override the destructor to manage the life cycle of the underlying
1127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * buffer.
1128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
1129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~ExternalStringResource() {}
11307f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
11317f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
11327f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * The string data from the underlying buffer.
11337f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
1134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual const uint16_t* data() const = 0;
11357f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
11367f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
11377f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * The length of the string. That is, the number of two-byte characters.
11387f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
1139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual size_t length() const = 0;
11407f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   protected:
1142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalStringResource() {}
1143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1146589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * An ExternalAsciiStringResource is a wrapper around an ASCII
1147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * string buffer that resides outside V8's heap. Implement an
1148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ExternalAsciiStringResource to manage the life cycle of the
1149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * underlying buffer.  Note that the string data must be immutable
1150589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * and that the data must be strict (7-bit) ASCII, not Latin-1 or
1151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * UTF-8, which would require special treatment internally in the
1152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * engine and, in the case of UTF-8, do not allow efficient indexing.
1153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Use String::New or convert to 16 bit data for non-ASCII.
1154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1156e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  class V8EXPORT ExternalAsciiStringResource
1157e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      : public ExternalStringResourceBase {
1158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
1160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Override the destructor to manage the life cycle of the underlying
1161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * buffer.
1162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
1163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~ExternalAsciiStringResource() {}
1164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /** The string data from the underlying buffer.*/
1165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual const char* data() const = 0;
1166589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch    /** The number of ASCII characters in the string.*/
1167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual size_t length() const = 0;
1168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   protected:
1169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalAsciiStringResource() {}
1170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the ExternalStringResource for an external string.  Returns
1174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * NULL if IsExternal() doesn't return true.
1175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline ExternalStringResource* GetExternalStringResource() const;
1177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1179589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * Get the ExternalAsciiStringResource for an external ASCII string.
1180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns NULL if IsExternalAscii() doesn't return true.
1181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11823ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource()
11833ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch      const;
1184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline String* Cast(v8::Value* obj);
1186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1188589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * Allocates a new string from either UTF-8 encoded or ASCII data.
1189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The second parameter 'length' gives the buffer length.
1190589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * If the data is UTF-8 encoded, the caller must
1191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be careful to supply the length parameter.
1192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If it is not given, the function calls
1193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 'strlen' to determine the buffer length, it might be
1194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * wrong if 'data' contains a null character.
1195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11968defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> New(const char* data, int length = -1);
1197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1198589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch  /** Allocates a new string from 16-bit character codes.*/
11998defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> New(const uint16_t* data, int length = -1);
1200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a symbol. Returns one if it exists already.*/
12028defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1);
1203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
12053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Creates a new string by concatenating the left and the right strings
12063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * passed in as parameters.
12073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
12088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> Concat(Handle<String> left,
12093ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch                                       Handle<String> right);
12103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
12113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
1212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new external string using the data defined in the given
12137f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource. When the external string is no longer live on V8's heap the
12147f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource will be disposed by calling its Dispose method. The caller of
12157f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * this function should not otherwise delete or modify the resource. Neither
12167f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * should the underlying buffer be deallocated or modified except through the
12177f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * destructor of the external string resource.
1218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12198defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource);
1220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an external string resource with this string by transforming it
1223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in place so that existing references to this string in the JavaScript heap
1224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * will use the external string resource. The external string resource's
1225257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * character contents need to be equivalent to this string.
1226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string has been changed to be an external string.
12277f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * The string is not modified if the operation fails. See NewExternal for
12287f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * information on the lifetime of the resource.
1229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12308defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool MakeExternal(ExternalStringResource* resource);
1231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1233589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * Creates a new external string using the ASCII data defined in the given
12347f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource. When the external string is no longer live on V8's heap the
12357f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource will be disposed by calling its Dispose method. The caller of
12367f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * this function should not otherwise delete or modify the resource. Neither
12377f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * should the underlying buffer be deallocated or modified except through the
12387f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * destructor of the external string resource.
1239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12408defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewExternal(
12418defd9ff6930b4e24729971a61cf7469daf119beSteve Block      ExternalAsciiStringResource* resource);
1242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an external string resource with this string by transforming it
1245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in place so that existing references to this string in the JavaScript heap
1246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * will use the external string resource. The external string resource's
1247257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * character contents need to be equivalent to this string.
1248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string has been changed to be an external string.
12497f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * The string is not modified if the operation fails. See NewExternal for
12507f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * information on the lifetime of the resource.
1251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12528defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
1253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this string can be made external.
1256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12578defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool CanMakeExternal();
1258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1259589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch  /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/
12608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewUndetectable(const char* data,
12618defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                                int length = -1);
1262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1263589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch  /** Creates an undetectable string from the supplied 16-bit character codes.*/
12648defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
12658defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                                int length = -1);
1266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1268589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * Converts an object to a UTF-8-encoded character array.  Useful if
1269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * you want to print the object.  If conversion to a string fails
1270589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * (e.g. due to an exception in the toString() method of the object)
1271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * then the length() method returns 0 and the * operator returns
1272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * NULL.
1273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Utf8Value {
1275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit Utf8Value(Handle<v8::Value> obj);
1277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~Utf8Value();
1278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* operator*() { return str_; }
1279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const char* operator*() const { return str_; }
1280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* str_;
1283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Utf8Value(const Utf8Value&);
1287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const Utf8Value&);
1288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1291589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * Converts an object to an ASCII string.
1292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Useful if you want to print the object.
1293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If conversion to a string fails (eg. due to an exception in the toString()
1294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * method of the object) then the length() method returns 0 and the * operator
1295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * returns NULL.
1296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT AsciiValue {
1298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit AsciiValue(Handle<v8::Value> obj);
1300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~AsciiValue();
1301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* operator*() { return str_; }
1302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const char* operator*() const { return str_; }
1303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* str_;
1306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    AsciiValue(const AsciiValue&);
1310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const AsciiValue&);
1311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Converts an object to a two-byte string.
1315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If conversion to a string fails (eg. due to an exception in the toString()
1316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * method of the object) then the length() method returns 0 and the * operator
1317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * returns NULL.
1318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Value {
1320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit Value(Handle<v8::Value> obj);
1322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~Value();
1323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint16_t* operator*() { return str_; }
1324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const uint16_t* operator*() const { return str_; }
1325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint16_t* str_;
1328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Value(const Value&);
1332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const Value&);
1333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
13343ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13368defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const;
13378defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript number value (ECMA-262, 4.3.20)
1343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13448defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Number : public Primitive {
1345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13468defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double Value() const;
13478defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Number> New(double value);
1348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Number* Cast(v8::Value* obj);
1349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13508defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Number();
135169a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
1352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a signed integer.
1357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13588defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Integer : public Number {
1359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Integer> New(int32_t value);
13618defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value);
13628defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int64_t Value() const;
1363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Integer* Cast(v8::Value* obj);
1364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13658defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Integer();
13668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit signed integer.
1372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13738defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Int32 : public Integer {
1374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13758defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int32_t Value() const;
1376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13778defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Int32();
1378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit unsigned integer.
1383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13848defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Uint32 : public Integer {
1385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13868defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Value() const;
1387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13888defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Uint32();
1389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum PropertyAttribute {
1393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  None       = 0,
1394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ReadOnly   = 1 << 0,
1395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DontEnum   = 1 << 1,
1396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DontDelete = 1 << 2
1397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
13993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockenum ExternalArrayType {
14003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalByteArray = 1,
14013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedByteArray,
14023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalShortArray,
14033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedShortArray,
14043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalIntArray,
14053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedIntArray,
140644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  kExternalFloatArray,
1407257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  kExternalDoubleArray,
140844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  kExternalPixelArray
14093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
14103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1412f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Accessor[Getter|Setter] are used as callback functions when
1413f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * setting|getting a particular property. See Object and ObjectTemplate's
1414f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * method SetAccessor.
1415f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */
1416f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef Handle<Value> (*AccessorGetter)(Local<String> property,
1417f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                                        const AccessorInfo& info);
1418f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1419f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1420f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef void (*AccessorSetter)(Local<String> property,
1421f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                               Local<Value> value,
1422f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                               const AccessorInfo& info);
1423f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1424f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1425f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/**
1426f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Access control specifications.
1427f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke *
1428f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Some accessors should be accessible across contexts.  These
1429f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors have an explicit access control parameter which specifies
1430f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * the kind of cross-context access that should be allowed.
1431f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke *
1432f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Additionally, for security, accessors can prohibit overwriting by
1433f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors defined in JavaScript.  For objects that have such
1434f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors either locally or in their prototype chain it is not
1435f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * possible to overwrite the accessor by using __defineGetter__ or
1436f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * __defineSetter__ from JavaScript code.
1437f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */
1438f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeenum AccessControl {
1439f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  DEFAULT               = 0,
1440f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  ALL_CAN_READ          = 1,
1441f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  ALL_CAN_WRITE         = 1 << 1,
1442f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  PROHIBITS_OVERWRITING = 1 << 2
1443f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke};
1444f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1445f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1446f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/**
1447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript object (ECMA-262, 4.3.3)
1448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
14498defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Object : public Value {
1450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
14518defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Set(Handle<Value> key,
14528defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    Handle<Value> value,
14538defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    PropertyAttribute attribs = None);
1454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14558defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Set(uint32_t index,
14568defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    Handle<Value> value);
14576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets a local property on this object bypassing interceptors and
1459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // overriding accessors or read-only properties.
1460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
1461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Note that if the object has an interceptor the property will be set
1462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // locally, but since the interceptor takes precedence the local property
1463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // will only be returned if the interceptor doesn't return a value.
1464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
1465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Note also that this only works for named properties.
14668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool ForceSet(Handle<Value> key,
14678defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         Handle<Value> value,
14688defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         PropertyAttribute attribs = None);
1469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14708defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Get(Handle<Value> key);
1471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14728defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Get(uint32_t index);
14736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
14743fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
14753fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Gets the property attributes of a property which can be None or
14763fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * any combination of ReadOnly, DontEnum and DontDelete. Returns
14773fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * None when the property doesn't exist.
14783fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
14793fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT PropertyAttribute GetPropertyAttributes(Handle<Value> key);
14803fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
1481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // TODO(1245389): Replace the type-specific versions of these
1482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // functions with generic ones that accept a Handle<Value> key.
14838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Has(Handle<String> key);
1484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14858defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Delete(Handle<String> key);
1486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Delete a property on this object bypassing interceptors and
1488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ignoring dont-delete attributes.
14898defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool ForceDelete(Handle<Value> key);
1490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14918defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Has(uint32_t index);
1492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14938defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Delete(uint32_t index);
1494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14958defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetAccessor(Handle<String> name,
14968defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessorGetter getter,
14978defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessorSetter setter = 0,
14988defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            Handle<Value> data = Handle<Value>(),
14998defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessControl settings = DEFAULT,
15008defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            PropertyAttribute attribute = None);
1501f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns an array containing the names of the enumerable properties
1504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * of this object, including properties from prototype objects.  The
1505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * array returned by this method contains the same values as would
1506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be enumerated by a for-in statement over this object.
1507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Array> GetPropertyNames();
1509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
15113fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * This function has the same functionality as GetPropertyNames but
15123fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * the returned array doesn't contain the names of properties from
15133fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * prototype objects.
15143fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
15153fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT Local<Array> GetOwnPropertyNames();
15163fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
15173fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
1518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the prototype object.  This does not skip objects marked to
1519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be skipped by __proto__ and it does not consult the security
1520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler.
1521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetPrototype();
1523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1525402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Set the prototype object.  This does not skip objects marked to
1526402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * be skipped by __proto__ and it does not consult the security
1527402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * handler.
1528402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
15298defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetPrototype(Handle<Value> prototype);
1530402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
1531402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
1532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Finds an instance of the given function template in the prototype
1533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * chain.
1534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15358defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> FindInstanceInPrototypeChain(
15368defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<FunctionTemplate> tmpl);
1537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Call builtin Object.prototype.toString on this object.
1540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This is different from Value::ToString() that may call
1541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * user-defined toString function. This one does not.
1542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15438defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ObjectProtoToString();
1544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15458a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  /**
15468a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang   * Returns the name of the function invoked as a constructor for this object.
15478a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang   */
15488a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  V8EXPORT Local<String> GetConstructorName();
15498a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang
1550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets the number of internal fields for this Object. */
15518defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int InternalFieldCount();
1552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets the value in an internal field. */
1553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> GetInternalField(int index);
1554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Sets the value in an internal field. */
15558defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetInternalField(int index, Handle<Value> value);
1556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets a native pointer from an internal field. */
1558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void* GetPointerFromInternalField(int index);
15593ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Sets a native pointer in an internal field. */
15618defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetPointerInInternalField(int index, void* value);
1562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Testers for local properties.
1564257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT bool HasOwnProperty(Handle<String> key);
15658defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealNamedProperty(Handle<String> key);
15668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealIndexedProperty(uint32_t index);
15678defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key);
1568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If result.IsEmpty() no real property was located in the prototype chain.
1571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means interceptors in the prototype chain are not called.
1572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15738defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain(
15748defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<String> key);
1575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If result.IsEmpty() no real property was located on the object or
1578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in the prototype chain.
1579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means interceptors in the prototype chain are not called.
1580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key);
1582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Tests for a named lookup interceptor.*/
15848defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasNamedLookupInterceptor();
1585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Tests for an index lookup interceptor.*/
15878defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasIndexedLookupInterceptor();
1588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Turns on access check on the object if the object is an instance of
1591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a template that has access check callbacks. If an object has no
1592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * access check info, the object cannot be accessed by anyone.
1593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15948defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void TurnOnAccessCheck();
1595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1597257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Returns the identity hash for this object. The current implementation
1598257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * uses a hidden property on the object to store the identity hash.
1599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
1600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The return value will never be 0. Also, it is not guaranteed to be
1601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * unique.
1602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16038defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int GetIdentityHash();
1604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Access hidden properties on JavaScript objects. These properties are
1607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * hidden from the executing JavaScript and only accessible through the V8
1608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * C++ API. Hidden properties introduced by V8 internally (for example the
1609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * identity hash) are prefixed with "v8::".
1610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16118defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value);
16128defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetHiddenValue(Handle<String> key);
16138defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool DeleteHiddenValue(Handle<String> key);
16143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this is an instance of an api function (one
1617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * created from a function created from a function template) and has
1618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been modified since it was created.  Note that this method is
1619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * conservative and may return true for objects that haven't actually
1620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been modified.
1621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsDirty();
1623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clone this object with a fast but shallow copy.  Values will point
1626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to the same values as the original object.
1627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16288defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> Clone();
1629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
16318b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch   * Returns the context in which the object was created.
16328b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch   */
16338b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  V8EXPORT Local<Context> CreationContext();
16348b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch
16358b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  /**
1636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the backing store of the indexed properties to be managed by the
1637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * embedding layer. Access to the indexed properties will follow the rules
1638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * spelled out in CanvasPixelArray.
1639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Note: The embedding program still owns the data and needs to ensure that
1640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *       the backing store is preserved while V8 has a reference.
1641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16428defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
16439fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  V8EXPORT bool HasIndexedPropertiesInPixelData();
16449fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  V8EXPORT uint8_t* GetIndexedPropertiesPixelData();
16459fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  V8EXPORT int GetIndexedPropertiesPixelDataLength();
1646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
16473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
16483ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Set the backing store of the indexed properties to be managed by the
16493ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * embedding layer. Access to the indexed properties will follow the rules
16503ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * spelled out for the CanvasArray subtypes in the WebGL specification.
16513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Note: The embedding program still owns the data and needs to ensure that
16523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   *       the backing store is preserved while V8 has a reference.
16533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
16548defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetIndexedPropertiesToExternalArrayData(
16558defd9ff6930b4e24729971a61cf7469daf119beSteve Block      void* data,
16568defd9ff6930b4e24729971a61cf7469daf119beSteve Block      ExternalArrayType array_type,
16578defd9ff6930b4e24729971a61cf7469daf119beSteve Block      int number_of_elements);
16589fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  V8EXPORT bool HasIndexedPropertiesInExternalArrayData();
16599fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  V8EXPORT void* GetIndexedPropertiesExternalArrayData();
16609fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
16619fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  V8EXPORT int GetIndexedPropertiesExternalArrayDataLength();
16623ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1663257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1664257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Checks whether a callback is set by the
1665257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * ObjectTemplate::SetCallAsFunctionHandler method.
1666257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * When an Object is callable this method returns true.
1667257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1668257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT bool IsCallable();
1669257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1670257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1671589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch   * Call an Object as a function if a callback is set by the
1672257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * ObjectTemplate::SetCallAsFunctionHandler method.
1673257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1674257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv,
1675257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch                                       int argc,
1676257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch                                       Handle<Value> argv[]);
1677257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1678257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1679257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Call an Object as a constructor if a callback is set by the
1680257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * ObjectTemplate::SetCallAsFunctionHandler method.
1681257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Note: This method behaves like the Function::NewInstance method.
1682257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1683257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT Local<Value> CallAsConstructor(int argc,
1684257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch                                          Handle<Value> argv[]);
1685257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
16868defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Object> New();
1687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Object* Cast(Value* obj);
16883fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
1689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
16908defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Object();
16918defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(Value* obj);
16928defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> CheckedGetInternalField(int index);
16938defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void* SlowGetPointerFromInternalField(int index);
1694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If quick access to the internal field is possible this method
16973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * returns the value.  Otherwise an empty handle is returned.
1698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> UncheckedGetInternalField(int index);
1700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An instance of the built-in array constructor (ECMA-262, 15.4.2).
1705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
17068defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Array : public Object {
1707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
17088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Length() const;
1709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clones an element at index |index|.  Returns an empty
1712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handle if cloning fails (for any reason).
1713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
17148defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> CloneElementAt(uint32_t index);
1715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
171644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
171744f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Creates a JavaScript array with the given length. If the length
171844f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * is negative the returned array will have length 0.
171944f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
17208defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Array> New(int length = 0);
172144f0eee88ff00398ff7f715fab053374d808c90dSteve Block
1722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Array* Cast(Value* obj);
1723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
17248defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Array();
172569a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  V8EXPORT static void CheckCast(Value* obj);
1726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript function object (ECMA-262, 15.3).
1731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
17328defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Function : public Object {
1733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
17348defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> NewInstance() const;
17358defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
17368defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Call(Handle<Object> recv,
17378defd9ff6930b4e24729971a61cf7469daf119beSteve Block                             int argc,
17388defd9ff6930b4e24729971a61cf7469daf119beSteve Block                             Handle<Value> argv[]);
17398defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetName(Handle<String> name);
17408defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Handle<Value> GetName() const;
1741402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
1742402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
17433ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Name inferred from variable or property assignment of this function.
17443ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Used to facilitate debugging and profiling of JavaScript code written
17453ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * in an OO style, where many functions are anonymous but are assigned
17463ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * to object properties.
17473ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
17483ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  V8EXPORT Handle<Value> GetInferredName() const;
17493ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
17503ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
1751402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Returns zero based line number of function body and
1752402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * kLineOffsetNotFound if no information available.
1753402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
17548defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int GetScriptLineNumber() const;
17553ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
17563ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Returns zero based column number of function body and
17573ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * kLineOffsetNotFound if no information available.
17583ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
17593ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  V8EXPORT int GetScriptColumnNumber() const;
17603ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  V8EXPORT Handle<Value> GetScriptId() const;
17618defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT ScriptOrigin GetScriptOrigin() const;
1762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Function* Cast(Value* obj);
17638defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static const int kLineOffsetNotFound;
17643ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
1765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
17668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Function();
17678defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(Value* obj);
1768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1772257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * An instance of the built-in Date constructor (ECMA-262, 15.9).
1773257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch */
1774257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdochclass Date : public Object {
1775257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch public:
1776257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT static Local<Value> New(double time);
1777257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1778257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1779257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * A specialization of Value::NumberValue that is more efficient
1780257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * because we know the structure of this object.
1781257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1782257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT double NumberValue() const;
1783257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1784257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static inline Date* Cast(v8::Value* obj);
1785257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1786257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1787257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Notification that the embedder has changed the time zone,
1788257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * daylight savings time, or other date / time configuration
1789257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * parameters.  V8 keeps a cache of various values used for
1790257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * date / time computation.  This notification will reset
1791257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * those cached values for the current context so that date /
1792257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * time configuration changes would be reflected in the Date
1793257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * object.
1794257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *
1795257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * This API should not be called more than needed as it will
1796257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * negatively impact the performance of date operations.
1797257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1798257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT static void DateTimeConfigurationChangeNotification();
1799257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1800257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch private:
1801257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
1802257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch};
1803257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1804257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1805257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch/**
18063fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * A Number object (ECMA-262, 4.3.21).
18073fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch */
18083fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochclass NumberObject : public Object {
18093fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch public:
18103fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT static Local<Value> New(double value);
18113fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18123fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
18133fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Returns the Number held by the object.
18143fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
18153fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT double NumberValue() const;
18163fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18173fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  static inline NumberObject* Cast(v8::Value* obj);
18183fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18193fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch private:
18203fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
18213fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch};
18223fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18233fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18243fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch/**
18253fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * A Boolean object (ECMA-262, 4.3.15).
18263fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch */
18273fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochclass BooleanObject : public Object {
18283fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch public:
18293fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT static Local<Value> New(bool value);
18303fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18313fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
18323fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Returns the Boolean held by the object.
18333fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
18343fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT bool BooleanValue() const;
18353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  static inline BooleanObject* Cast(v8::Value* obj);
18373fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18383fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch private:
18393fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
18403fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch};
18413fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18423fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18433fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch/**
18443fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * A String object (ECMA-262, 4.3.18).
18453fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch */
18463fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochclass StringObject : public Object {
18473fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch public:
18483fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT static Local<Value> New(Handle<String> value);
18493fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18503fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
18513fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Returns the String held by the object.
18523fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
18533fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT Local<String> StringValue() const;
18543fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18553fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  static inline StringObject* Cast(v8::Value* obj);
18563fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18573fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch private:
18583fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
18593fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch};
18603fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18613fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
18623fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch/**
1863257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
1864257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch */
1865257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdochclass RegExp : public Object {
1866257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch public:
1867257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1868257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Regular expression flag bits. They can be or'ed to enable a set
1869257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * of flags.
1870257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1871257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  enum Flags {
1872257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    kNone = 0,
1873257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    kGlobal = 1,
1874257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    kIgnoreCase = 2,
1875257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    kMultiline = 4
1876257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  };
1877257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1878257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1879257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Creates a regular expression from the given pattern string and
1880257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * the flags bit field. May throw a JavaScript exception as
1881257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * described in ECMA-262, 15.10.4.1.
1882257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *
1883257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * For example,
1884257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   RegExp::New(v8::String::New("foo"),
1885257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *               static_cast<RegExp::Flags>(kGlobal | kMultiline))
1886257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * is equivalent to evaluating "/foo/gm".
1887257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1888257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT static Local<RegExp> New(Handle<String> pattern,
1889257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch                                    Flags flags);
1890257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1891257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1892257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Returns the value of the source property: a string representing
1893257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * the regular expression.
1894257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1895257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT Local<String> GetSource() const;
1896257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1897257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
1898257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Returns the flags bit field.
1899257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
1900257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT Flags GetFlags() const;
1901257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1902257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static inline RegExp* Cast(v8::Value* obj);
1903257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1904257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch private:
1905257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
1906257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch};
1907257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1908257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
1909257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch/**
1910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value that wraps a C++ void*.  This type of value is
1911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * mainly used to associate C++ data structures with JavaScript
1912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects.
1913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Wrap function V8 will return the most optimal Value object wrapping the
1915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * C++ void*. The type of the value is not guaranteed to be an External object
1916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and no assumptions about its type should be made. To access the wrapped
1917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * value Unwrap should be used, all other operations on that object will lead
1918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to unpredictable results.
1919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
19208defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass External : public Value {
1921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
19228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Value> Wrap(void* data);
1923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void* Unwrap(Handle<Value> obj);
1924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
19258defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<External> New(void* value);
1926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline External* Cast(Value* obj);
19278defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void* Value() const;
1928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
19298defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT External();
19308defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void* QuickUnwrap(Handle<v8::Value> obj);
19328defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
1933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1936257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Templates ---
1937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of object and function templates.
1941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Template : public Data {
1943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Adds a property to each instance created by this template.*/
1945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Set(Handle<String> name, Handle<Data> value,
1946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block           PropertyAttribute attributes = None);
1947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Set(const char* name, Handle<Data> value);
1948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Template();
1950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
1952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class FunctionTemplate;
1953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The argument information given to function call callbacks.  This
1958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * class provides access to information about the context of the call,
1959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * including the receiver, the number and values of arguments, and
1960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the holder of the function.
1961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
19628defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Arguments {
1963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int Length() const;
1965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> operator[](int i) const;
1966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Function> Callee() const;
1967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> This() const;
1968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> Holder() const;
1969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsConstructCall() const;
1970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> Data() const;
1971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
19723e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  static const int kDataIndex = 0;
19733e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  static const int kCalleeIndex = -1;
19743e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  static const int kHolderIndex = -2;
19753e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu
1976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
19773e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  inline Arguments(internal::Object** implicit_args,
19783e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                   internal::Object** values,
19793e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                   int length,
19803e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                   bool is_construct_call);
19813e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  internal::Object** implicit_args_;
19823e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  internal::Object** values_;
1983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int length_;
19843e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  bool is_construct_call_;
1985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The information passed to an accessor callback about the context
1990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * of the property access.
1991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT AccessorInfo {
1993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline AccessorInfo(internal::Object** args)
1995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : args_(args) { }
1996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> Data() const;
1997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> This() const;
1998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> Holder() const;
1999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** args_;
2001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*InvocationCallback)(const Arguments& args);
2005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * NamedProperty[Getter|Setter] are used as interceptors on object.
2008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ObjectTemplate::SetNamedPropertyHandler.
2009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
2011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             const AccessorInfo& info);
2012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request.
2016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle.
2017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
2019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             Local<Value> value,
2020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             const AccessorInfo& info);
2021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request.
20249dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * The result is an integer encoding property attributes (like v8::None,
20259dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * v8::DontEnum, etc.)
2026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
20277f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochtypedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
20287f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch                                              const AccessorInfo& info);
2029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request.
2033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false
2034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise.
2035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
2037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                const AccessorInfo& info);
2038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the names of the properties the named
2041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property getter intercepts.
2042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
2044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value of the property if the getter intercepts the
2048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * request.  Otherwise, returns an empty handle.
2049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
2051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               const AccessorInfo& info);
2052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request.
2056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle.
2057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
2059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               Local<Value> value,
2060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               const AccessorInfo& info);
2061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request.
2065756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick * The result is an integer encoding property attributes.
2066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2067756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merricktypedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
2068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                const AccessorInfo& info);
2069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request.
2072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false
2073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise.
2074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
2076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                  const AccessorInfo& info);
2077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the indices of the properties the
2080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * indexed property getter intercepts.
2081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
2083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Access type specification.
2087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum AccessType {
2089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_GET,
2090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_SET,
2091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_HAS,
2092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_DELETE,
2093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_KEYS
2094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the named
2099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given key on the host object.
2100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*NamedSecurityCallback)(Local<Object> host,
2102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      Local<Value> key,
2103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      AccessType type,
2104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      Local<Value> data);
2105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the indexed
2109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given index on the host object.
2110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*IndexedSecurityCallback)(Local<Object> host,
2112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        uint32_t index,
2113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        AccessType type,
2114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        Local<Value> data);
2115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate is used to create functions at runtime. There
2119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * can only be one function created from a FunctionTemplate in a
2120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * context.  The lifetime of the created function is equal to the
2121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * lifetime of the context.  So in case the embedder needs to create
2122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * temporary functions that can be collected using Scripts is
2123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * preferred.
2124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have properties, these properties are added to the
2126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function object when it is created.
2127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate has a corresponding instance template which is
2129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * used to create object instances when the function is used as a
2130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor. Properties added to the instance template are added to
2131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * each object instance.
2132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have a prototype template. The prototype template
2134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is used to create the prototype object of the function.
2135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The following example shows how to use a FunctionTemplate:
2137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
2140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    t->Set("func_property", v8::Number::New(1));
2141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
2143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
2144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    proto_t->Set("proto_const", v8::Number::New(2));
2145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
2147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
2148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
2149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->Set("instance_property", Number::New(3));
2150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Function> function = t->GetFunction();
2152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Object> instance = function->NewInstance();
2153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let's use "function" as the JS variable name of the function object
2156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and "instance" for the instance object created above.  The function
2157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and the instance will have the following properties:
2158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   func_property in function == true;
2161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.func_property == 1;
2162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.prototype.proto_method() invokes 'InvokeCallback'
2164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.prototype.proto_const == 2;
2165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance instanceof function == true;
2167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance.instance_accessor calls 'InstanceAccessorCallback'
2168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance.instance_property == 3;
2169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can inherit from another one by calling the
2172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate::Inherit method.  The following graph illustrates
2173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the semantics of inheritance:
2174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   FunctionTemplate Parent  -> Parent() . prototype -> { }
2177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     ^                                                  ^
2178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     | Inherit(Parent)                                  | .__proto__
2179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     |                                                  |
2180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   FunctionTemplate Child   -> Child()  . prototype -> { }
2181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
2184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * object of the Child() function has __proto__ pointing to the
2185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Parent() function's prototype object. An instance of the Child
2186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function has all properties on Parent's instance templates.
2187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let Parent be the FunctionTemplate initialized in the previous
2189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * section and create a Child FunctionTemplate by:
2190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<FunctionTemplate> parent = t;
2193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<FunctionTemplate> child = FunctionTemplate::New();
2194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child->Inherit(parent);
2195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<Function> child_function = child->GetFunction();
2197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<Object> child_instance = child_function->NewInstance();
2198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Child function and Child instance will have the following
2201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * properties:
2202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_func.prototype.__proto__ == function.prototype;
2205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_instance.instance_accessor calls 'InstanceAccessorCallback'
2206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_instance.instance_property == 3;
2207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT FunctionTemplate : public Template {
2210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a function template.*/
2212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<FunctionTemplate> New(
2213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      InvocationCallback callback = 0,
2214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Value> data = Handle<Value>(),
2215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Signature> signature = Handle<Signature>());
2216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the unique function instance in the current execution context.*/
2217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Function> GetFunction();
2218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the call-handler callback for a FunctionTemplate.  This
2221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback is called whenever the function created from this
2222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * FunctionTemplate is called.
2223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCallHandler(InvocationCallback callback,
2225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                      Handle<Value> data = Handle<Value>());
2226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Get the InstanceTemplate. */
2228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<ObjectTemplate> InstanceTemplate();
2229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Causes the function template to inherit from a parent function template.*/
2231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Inherit(Handle<FunctionTemplate> parent);
2232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A PrototypeTemplate is the template used to create the prototype object
2235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * of the function created by this template.
2236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<ObjectTemplate> PrototypeTemplate();
2238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the class name of the FunctionTemplate.  This is used for
2242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * printing objects created with the function created from the
2243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * FunctionTemplate as its constructor.
2244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetClassName(Handle<String> name);
2246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Determines whether the __proto__ accessor ignores instances of
2249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the function template.  If instances of the function template are
2250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ignored, __proto__ skips all instances and instead returns the
2251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * next object in the prototype chain.
2252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Call with a value of true to make the __proto__ accessor ignore
2254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * instances of the function template.  Call with a value of false
2255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to make the __proto__ accessor not ignore instances of the
2256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function template.  By default, instances of a function template
2257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * are not ignored.
2258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetHiddenPrototype(bool value);
2260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
226269a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch   * Sets the ReadOnly flag in the attributes of the 'prototype' property
226369a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch   * of functions created from this FunctionTemplate to true.
22643fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
226569a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  void ReadOnlyPrototype();
22663fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
22673fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
2268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the given object is an instance of this function
2269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * template.
2270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasInstance(Handle<Value> object);
2272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  FunctionTemplate();
2275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void AddInstancePropertyAccessor(Handle<String> name,
2276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessorGetter getter,
2277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessorSetter setter,
2278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   Handle<Value> data,
2279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessControl settings,
2280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   PropertyAttribute attributes);
2281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
2282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertySetter setter,
2283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyQuery query,
2284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyDeleter remover,
2285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyEnumerator enumerator,
22869dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen                                       Handle<Value> data);
2287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
2288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertySetter setter,
2289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyQuery query,
2290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyDeleter remover,
2291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyEnumerator enumerator,
2292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         Handle<Value> data);
2293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
2294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        Handle<Value> data);
2295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Context;
2297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
2298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An ObjectTemplate is used to create objects at runtime.
2303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Properties added to an ObjectTemplate are added to each object
2305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * created from the ObjectTemplate.
2306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ObjectTemplate : public Template {
2308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates an ObjectTemplate. */
2310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<ObjectTemplate> New();
2311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a new instance of this template.*/
2313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Object> NewInstance();
2314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets an accessor on the object template.
2317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever the property with the given name is accessed on objects
2319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * created from this ObjectTemplate the getter and setter callbacks
2320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * are called instead of getting and setting the property directly
2321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * on the JavaScript object.
2322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param name The name of the property for which an accessor is added.
2324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting the property.
2325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting the property.
2326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the getter and setter
2327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   callbacks whenever they are invoked.
2328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param settings Access control settings for the accessor. This is a bit
2329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   field consisting of one of more of
2330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
2331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   The default is to not allow cross-context access.
2332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   ALL_CAN_READ means that all cross-context reads are allowed.
2333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   ALL_CAN_WRITE means that all cross-context writes are allowed.
2334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
2335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   cross-context access.
2336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param attribute The attributes of the property for which an accessor
2337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   is added.
2338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetAccessor(Handle<String> name,
2340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessorGetter getter,
2341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessorSetter setter = 0,
2342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   Handle<Value> data = Handle<Value>(),
2343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessControl settings = DEFAULT,
2344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   PropertyAttribute attribute = None);
2345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets a named property handler on the object template.
2348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever a named property is accessed on objects created from
2350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this object template, the provided callback is invoked instead of
2351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * accessing the property directly on the JavaScript object.
2352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting a property.
2354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting a property.
23559dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen   * \param query The callback to invoke to check if a property is present,
23569dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen   *   and if present, get its attributes.
2357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param deleter The callback to invoke when deleting a property.
2358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param enumerator The callback to invoke to enumerate all the named
2359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   properties of an object.
2360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the callbacks
2361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   whenever they are invoked.
2362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNamedPropertyHandler(NamedPropertyGetter getter,
2364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertySetter setter = 0,
2365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyQuery query = 0,
2366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyDeleter deleter = 0,
2367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyEnumerator enumerator = 0,
23689dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen                               Handle<Value> data = Handle<Value>());
2369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets an indexed property handler on the object template.
2372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever an indexed property is accessed on objects created from
2374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this object template, the provided callback is invoked instead of
2375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * accessing the property directly on the JavaScript object.
2376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting a property.
2378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting a property.
2379257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * \param query The callback to invoke to check if an object has a property.
2380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param deleter The callback to invoke when deleting a property.
2381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param enumerator The callback to invoke to enumerate all the indexed
2382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   properties of an object.
2383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the callbacks
2384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   whenever they are invoked.
2385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
2387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertySetter setter = 0,
2388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyQuery query = 0,
2389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyDeleter deleter = 0,
2390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyEnumerator enumerator = 0,
2391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 Handle<Value> data = Handle<Value>());
2392756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
2393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the callback to be used when calling instances created from
2395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template as a function.  If no callback is set, instances
2396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * behave like normal JavaScript objects that cannot be called as a
2397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function.
2398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCallAsFunctionHandler(InvocationCallback callback,
2400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                Handle<Value> data = Handle<Value>());
2401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Mark object instances of the template as undetectable.
2404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * In many ways, undetectable objects behave as though they are not
2406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * there.  They behave like 'undefined' in conditionals and when
2407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * printed.  However, properties can be accessed and called as on
2408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * normal objects.
2409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void MarkAsUndetectable();
2411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets access check callbacks on the object template.
2414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When accessing properties on instances of this object template,
2416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the access check callback will be called to determine whether or
2417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * not to allow cross-context access to the properties.
2418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The last parameter specifies whether access checks are turned
2419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * on by default on instances. If access checks are off by default,
2420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * they can be turned on on individual instances by calling
2421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Object::TurnOnAccessCheck().
2422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
2424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               IndexedSecurityCallback indexed_handler,
2425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               Handle<Value> data = Handle<Value>(),
2426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               bool turned_on_by_default = true);
2427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Gets the number of internal fields for objects generated from
2430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template.
2431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int InternalFieldCount();
2433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the number of internal fields for objects generated from
2436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template.
2437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetInternalFieldCount(int value);
2439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ObjectTemplate();
2442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
2443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class FunctionTemplate;
2444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A Signature specifies which receivers and arguments a function can
2449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * legally be called with.
2450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Signature : public Data {
2452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Signature> New(Handle<FunctionTemplate> receiver =
2454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  Handle<FunctionTemplate>(),
2455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              int argc = 0,
2456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              Handle<FunctionTemplate> argv[] = 0);
2457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Signature();
2459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A utility for determining the type of objects based on the template
2464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * they were constructed from.
2465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TypeSwitch : public Data {
2467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
2469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
2470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int match(Handle<Value> value);
2471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  TypeSwitch();
2473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2476257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Extensions ---
2477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
24783ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochclass V8EXPORT ExternalAsciiStringResourceImpl
24793ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch    : public String::ExternalAsciiStringResource {
24803ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch public:
24813ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  ExternalAsciiStringResourceImpl() : data_(0), length_(0) {}
24823ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  ExternalAsciiStringResourceImpl(const char* data, size_t length)
24833ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch      : data_(data), length_(length) {}
24843ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  const char* data() const { return data_; }
24853ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  size_t length() const { return length_; }
24863ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
24873ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch private:
24883ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  const char* data_;
24893ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  size_t length_;
24903ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch};
2491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
2494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Extension {  // NOLINT
2496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
24973ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  // Note that the strings passed into this constructor must live as long
24983ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  // as the Extension itself.
2499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Extension(const char* name,
2500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            const char* source = 0,
2501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            int dep_count = 0,
25023ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch            const char** deps = 0,
25033ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch            int source_length = -1);
2504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~Extension() { }
2505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual v8::Handle<v8::FunctionTemplate>
2506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      GetNativeFunction(v8::Handle<v8::String> name) {
2507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return v8::Handle<v8::FunctionTemplate>();
2508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
25103ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  const char* name() const { return name_; }
25113ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  size_t source_length() const { return source_length_; }
25123ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  const String::ExternalAsciiStringResource* source() const {
25133ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch    return &source_; }
2514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int dependency_count() { return dep_count_; }
2515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** dependencies() { return deps_; }
2516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_auto_enable(bool value) { auto_enable_ = value; }
2517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool auto_enable() { return auto_enable_; }
2518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* name_;
25213ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  size_t source_length_;  // expected to initialize before source_
25223ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  ExternalAsciiStringResourceImpl source_;
2523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int dep_count_;
2524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** deps_;
2525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool auto_enable_;
2526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Disallow copying and assigning.
2528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Extension(const Extension&);
2529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const Extension&);
2530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid V8EXPORT RegisterExtension(Extension* extension);
2534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
2538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT DeclareExtension {
2540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline DeclareExtension(Extension* extension) {
2542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    RegisterExtension(extension);
2543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2547257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Statics ---
2548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Undefined();
2551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Null();
2552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT True();
2553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT False();
2554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A set of constraints that specifies the limits of the runtime's memory use.
2558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * You must set the heap size before initializing the VM - the size cannot be
2559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * adjusted after the VM is initialized.
2560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you are using threads then you should hold the V8::Locker lock while
2562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * setting the stack limit and you must set a non-default stack limit separately
2563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for each thread.
2564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ResourceConstraints {
2566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ResourceConstraints();
2568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_young_space_size() const { return max_young_space_size_; }
2569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_max_young_space_size(int value) { max_young_space_size_ = value; }
2570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_old_space_size() const { return max_old_space_size_; }
2571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_max_old_space_size(int value) { max_old_space_size_ = value; }
257290bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  int max_executable_size() { return max_executable_size_; }
257390bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  void set_max_executable_size(int value) { max_executable_size_ = value; }
2574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t* stack_limit() const { return stack_limit_; }
2575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets an address beyond which the VM's stack may not grow.
2576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
2577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_young_space_size_;
2579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_old_space_size_;
258090bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  int max_executable_size_;
2581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t* stack_limit_;
2582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
258525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenbool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints);
2586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2588257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Exceptions ---
2589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FatalErrorCallback)(const char* location, const char* message);
2592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
2595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Schedules an exception to be thrown when returning to JavaScript.  When an
2599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * exception has been scheduled it is illegal to invoke any JavaScript
2600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operation; the caller must return immediately and only after the exception
2601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * has been handled does it become legal to invoke JavaScript operations.
2602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> V8EXPORT ThrowException(Handle<Value> exception);
2604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Create new error objects by calling the corresponding error object
2607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor with the message.
2608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Exception {
2610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> RangeError(Handle<String> message);
2612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> ReferenceError(Handle<String> message);
2613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> SyntaxError(Handle<String> message);
2614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> TypeError(Handle<String> message);
2615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> Error(Handle<String> message);
2616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2619257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Counters Callbacks ---
2620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int* (*CounterLookupCallback)(const char* name);
2622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void* (*CreateHistogramCallback)(const char* name,
2624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         int min,
2625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         int max,
2626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         size_t buckets);
2627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
2629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2630257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Memory Allocation Callback ---
26319ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  enum ObjectSpace {
26329ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceNewSpace = 1 << 0,
26339ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceOldPointerSpace = 1 << 1,
26349ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceOldDataSpace = 1 << 2,
26359ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceCodeSpace = 1 << 3,
26369ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceMapSpace = 1 << 4,
26379ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceLoSpace = 1 << 5,
26389ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26399ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
26409ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick      kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
26419ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick      kObjectSpaceLoSpace
26429ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  };
26439ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26449ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  enum AllocationAction {
26459ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionAllocate = 1 << 0,
26469ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionFree = 1 << 1,
26479ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
26489ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  };
26499ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26509ac36c9faca11611ada13b4054edbaa0738661d0Iain Merricktypedef void (*MemoryAllocationCallback)(ObjectSpace space,
26519ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                         AllocationAction action,
26529ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                         int size);
26539ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26543ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// --- Leave Script Callback ---
26553ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochtypedef void (*CallCompletedCallback)();
26563ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
2657257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Failed Access Check Callback ---
2658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FailedAccessCheckCallback)(Local<Object> target,
2659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          AccessType type,
2660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          Local<Value> data);
2661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2662257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- AllowCodeGenerationFromStrings callbacks ---
2663257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
2664257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch/**
2665257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * Callback to check if code generation from strings is allowed. See
2666257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * Context::AllowCodeGenerationFromStrings.
2667257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch */
2668257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdochtypedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
2669257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
2670257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Garbage Collection Callbacks ---
2671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
26736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Applications can register callback functions which will be called
26746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * before and after a garbage collection.  Allocations are not
26756ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * allowed in the callback functions, you therefore cannot manipulate
2676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects (set or delete properties for example) since it is possible
2677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * such operations will result in the allocation of objects.
2678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
26796ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCType {
26806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeScavenge = 1 << 0,
26816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeMarkSweepCompact = 1 << 1,
26826ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
26836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
26846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26856ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCCallbackFlags {
26866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kNoGCCallbackFlags = 0,
26876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCCallbackFlagCompacted = 1 << 0
26886ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
26896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26906ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
26916ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
26926ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
2693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*GCCallback)();
2694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
26973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Collection of V8 heap information.
26983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block *
26993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Instances of this class can be passed to v8::V8::HeapStatistics to
27003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * get heap statistics from V8.
27013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block */
27023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass V8EXPORT HeapStatistics {
27033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
27043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  HeapStatistics();
27053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t total_heap_size() { return total_heap_size_; }
270690bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  size_t total_heap_size_executable() { return total_heap_size_executable_; }
27073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t used_heap_size() { return used_heap_size_; }
2708b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  size_t heap_size_limit() { return heap_size_limit_; }
27093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
27103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
27113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void set_total_heap_size(size_t size) { total_heap_size_ = size; }
271290bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  void set_total_heap_size_executable(size_t size) {
271390bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner    total_heap_size_executable_ = size;
271490bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  }
27153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void set_used_heap_size(size_t size) { used_heap_size_ = size; }
2716b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  void set_heap_size_limit(size_t size) { heap_size_limit_ = size; }
27173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
27183ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t total_heap_size_;
271990bac256d9f48d4ee52d0e08bf0e5cad57b3c51cRussell Brenner  size_t total_heap_size_executable_;
27203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t used_heap_size_;
2721b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  size_t heap_size_limit_;
27223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
27233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  friend class V8;
27243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
27253ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
27263ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
272744f0eee88ff00398ff7f715fab053374d808c90dSteve Blockclass RetainedObjectInfo;
272844f0eee88ff00398ff7f715fab053374d808c90dSteve Block
272944f0eee88ff00398ff7f715fab053374d808c90dSteve Block/**
273044f0eee88ff00398ff7f715fab053374d808c90dSteve Block * Isolate represents an isolated instance of the V8 engine.  V8
273144f0eee88ff00398ff7f715fab053374d808c90dSteve Block * isolates have completely separate states.  Objects from one isolate
273244f0eee88ff00398ff7f715fab053374d808c90dSteve Block * must not be used in other isolates.  When V8 is initialized a
273344f0eee88ff00398ff7f715fab053374d808c90dSteve Block * default isolate is implicitly created and entered.  The embedder
273444f0eee88ff00398ff7f715fab053374d808c90dSteve Block * can create additional isolates and use them in parallel in multiple
273544f0eee88ff00398ff7f715fab053374d808c90dSteve Block * threads.  An isolate can be entered by at most one thread at any
27363ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * given time.  The Locker/Unlocker API must be used to synchronize.
273744f0eee88ff00398ff7f715fab053374d808c90dSteve Block */
273844f0eee88ff00398ff7f715fab053374d808c90dSteve Blockclass V8EXPORT Isolate {
273944f0eee88ff00398ff7f715fab053374d808c90dSteve Block public:
274044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
274144f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Stack-allocated class which sets the isolate for all operations
274244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * executed within a local scope.
274344f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
274444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  class V8EXPORT Scope {
274544f0eee88ff00398ff7f715fab053374d808c90dSteve Block   public:
274644f0eee88ff00398ff7f715fab053374d808c90dSteve Block    explicit Scope(Isolate* isolate) : isolate_(isolate) {
274744f0eee88ff00398ff7f715fab053374d808c90dSteve Block      isolate->Enter();
274844f0eee88ff00398ff7f715fab053374d808c90dSteve Block    }
274944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
275044f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ~Scope() { isolate_->Exit(); }
275144f0eee88ff00398ff7f715fab053374d808c90dSteve Block
275244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   private:
275344f0eee88ff00398ff7f715fab053374d808c90dSteve Block    Isolate* const isolate_;
275444f0eee88ff00398ff7f715fab053374d808c90dSteve Block
275544f0eee88ff00398ff7f715fab053374d808c90dSteve Block    // Prevent copying of Scope objects.
275644f0eee88ff00398ff7f715fab053374d808c90dSteve Block    Scope(const Scope&);
275744f0eee88ff00398ff7f715fab053374d808c90dSteve Block    Scope& operator=(const Scope&);
275844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  };
275944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
276044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
276144f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Creates a new isolate.  Does not change the currently entered
276244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * isolate.
276344f0eee88ff00398ff7f715fab053374d808c90dSteve Block   *
276444f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * When an isolate is no longer used its resources should be freed
276544f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * by calling Dispose().  Using the delete operator is not allowed.
276644f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
276744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static Isolate* New();
276844f0eee88ff00398ff7f715fab053374d808c90dSteve Block
276944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
277044f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Returns the entered isolate for the current thread or NULL in
277144f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * case there is no current isolate.
277244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
277344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static Isolate* GetCurrent();
277444f0eee88ff00398ff7f715fab053374d808c90dSteve Block
277544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
277644f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Methods below this point require holding a lock (using Locker) in
277744f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * a multi-threaded environment.
277844f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
277944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
278044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
278144f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Sets this isolate as the entered one for the current thread.
278244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Saves the previously entered one (if any), so that it can be
278344f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * restored when exiting.  Re-entering an isolate is allowed.
278444f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
278544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void Enter();
278644f0eee88ff00398ff7f715fab053374d808c90dSteve Block
278744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
278844f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Exits this isolate by restoring the previously entered one in the
278944f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * current thread.  The isolate may still stay the same, if it was
279044f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * entered more than once.
279144f0eee88ff00398ff7f715fab053374d808c90dSteve Block   *
279244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Requires: this == Isolate::GetCurrent().
279344f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
279444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void Exit();
279544f0eee88ff00398ff7f715fab053374d808c90dSteve Block
279644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
279744f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Disposes the isolate.  The isolate must not be entered by any
279844f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * thread to be disposable.
279944f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
280044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void Dispose();
280144f0eee88ff00398ff7f715fab053374d808c90dSteve Block
2802257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
2803257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Associate embedder-specific data with the isolate
2804257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
2805257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  void SetData(void* data);
2806257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
2807257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
2808257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Retrive embedder-specific data from the isolate.
2809257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Returns NULL if SetData has never been called.
2810257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
2811257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  void* GetData();
2812257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
281344f0eee88ff00398ff7f715fab053374d808c90dSteve Block private:
281444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  Isolate();
281544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  Isolate(const Isolate&);
281644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  ~Isolate();
281744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  Isolate& operator=(const Isolate&);
281844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void* operator new(size_t size);
281944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void operator delete(void*, size_t);
282044f0eee88ff00398ff7f715fab053374d808c90dSteve Block};
282144f0eee88ff00398ff7f715fab053374d808c90dSteve Block
282244f0eee88ff00398ff7f715fab053374d808c90dSteve Block
2823257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdochclass StartupData {
2824257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch public:
2825257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  enum CompressionAlgorithm {
2826257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    kUncompressed,
2827257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    kBZip2
2828257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  };
2829257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
2830257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  const char* data;
2831257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  int compressed_size;
2832257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  int raw_size;
2833257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch};
2834257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
28353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
28363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch/**
28373fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * A helper class for driving V8 startup data decompression.  It is based on
28383fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * "CompressedStartupData" API functions from the V8 class.  It isn't mandatory
28393fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * for an embedder to use this class, instead, API functions can be used
28403fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * directly.
28413fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch *
28423fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * For an example of the class usage, see the "shell.cc" sample application.
28433fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch */
28443fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochclass V8EXPORT StartupDataDecompressor {  // NOLINT
28453fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch public:
28463fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  StartupDataDecompressor();
28473fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  virtual ~StartupDataDecompressor();
28483fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  int Decompress();
28493fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
28503fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch protected:
28513fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  virtual int DecompressData(char* raw_data,
28523fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch                             int* raw_data_size,
28533fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch                             const char* compressed_data,
28543fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch                             int compressed_data_size) = 0;
28553fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
28563fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch private:
28573fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  char** raw_data;
28583fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch};
28593fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
28603fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
28613fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch/**
28623fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * EntropySource is used as a callback function when v8 needs a source
28633fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch * of entropy.
28643fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch */
28653fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochtypedef bool (*EntropySource)(unsigned char* buffer, size_t length);
28663fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
28673ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
28683ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch/**
28693ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * ReturnAddressLocationResolver is used as a callback function when v8 is
28703ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * resolving the location of a return address on the stack. Profilers that
28713ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * change the return address on the stack can use this to resolve the stack
28723ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * location to whereever the profiler stashed the original return address.
28733ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * When invoked, return_addr_location will point to a location on stack where
28743ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * a machine return address resides, this function should return either the
28753ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * same pointer, or a pointer to the profiler's copy of the original return
28763ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * address.
28773ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch */
28783ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochtypedef uintptr_t (*ReturnAddressLocationResolver)(
28793ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch    uintptr_t return_addr_location);
28803ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
28813ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
28823ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch/**
28833ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * Interface for iterating though all external resources in the heap.
28843ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch */
28853ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochclass V8EXPORT ExternalResourceVisitor {  // NOLINT
28863ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch public:
28873ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  virtual ~ExternalResourceVisitor() {}
28883ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  virtual void VisitExternalString(Handle<String> string) {}
28893ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch};
28903ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
28913ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
28923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block/**
2893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Container class for static utility functions.
2894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT V8 {
2896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Set the callback to invoke in case of fatal errors. */
2898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFatalErrorHandler(FatalErrorCallback that);
2899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2901257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Set the callback to invoke to check if code generation from
2902257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * strings should be allowed.
2903257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
2904257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static void SetAllowCodeGenerationFromStringsCallback(
2905257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch      AllowCodeGenerationFromStringsCallback that);
2906257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
2907257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
2908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Ignore out-of-memory exceptions.
2909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 running out of memory is treated as a fatal error by default.
2911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means that the fatal error handler is called and that V8 is
2912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * terminated.
2913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2914257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * IgnoreOutOfMemoryException can be used to not treat an
2915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * out-of-memory situation as a fatal error.  This way, the contexts
2916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that did not cause the out of memory problem might be able to
2917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * continue execution.
2918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void IgnoreOutOfMemoryException();
2920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Check if V8 is dead and therefore unusable.  This is the case after
2923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * fatal errors such as out-of-memory situations.
2924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsDead();
2926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2928257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * The following 4 functions are to be used when V8 is built with
2929257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * the 'compress_startup_data' flag enabled. In this case, the
2930257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * embedder must decompress startup data prior to initializing V8.
2931257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *
2932257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * This is how interaction with V8 should look like:
2933257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
2934257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   v8::StartupData* compressed_data =
2935257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *     new v8::StartupData[compressed_data_count];
2936257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   v8::V8::GetCompressedStartupData(compressed_data);
2937257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   ... decompress data (compressed_data can be updated in-place) ...
2938257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   v8::V8::SetDecompressedStartupData(compressed_data);
2939257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   ... now V8 can be initialized
2940257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *   ... make sure the decompressed data stays valid until V8 shutdown
29413fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   *
29423fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * A helper class StartupDataDecompressor is provided. It implements
29433fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * the protocol of the interaction described above, and can be used in
29443fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * most cases instead of calling these API functions directly.
2945257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
2946257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
2947257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static int GetCompressedStartupDataCount();
2948257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static void GetCompressedStartupData(StartupData* compressed_data);
2949257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static void SetDecompressedStartupData(StartupData* decompressed_data);
2950257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
2951257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
2952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Adds a message listener.
2953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2954257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * The same message listener can be added more than once and in that
2955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * case it will be called more than once for each message.
2956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool AddMessageListener(MessageCallback that,
2958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 Handle<Value> data = Handle<Value>());
2959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Remove all message listeners from the specified callback function.
2962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void RemoveMessageListeners(MessageCallback that);
2964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
29663bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * Tells V8 to capture current stack trace when uncaught exception occurs
29673bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * and report it to the message listeners. The option is off by default.
29683bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   */
29693bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  static void SetCaptureStackTraceForUncaughtExceptions(
29703bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      bool capture,
29713bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      int frame_limit = 10,
29723bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      StackTrace::StackTraceOptions options = StackTrace::kOverview);
29733bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
29743bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  /**
2975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets V8 flags from a string.
2976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFlagsFromString(const char* str, int length);
2978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets V8 flags from the command line.
2981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFlagsFromCommandLine(int* argc,
2983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      char** argv,
2984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      bool remove_flags);
2985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Get the version string. */
2987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const char* GetVersion();
2988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to provide a mechanism for recording
2991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * statistics counters.
2992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetCounterFunction(CounterLookupCallback);
2994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to provide a mechanism for recording
2997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * histograms. The CreateHistogram function returns a
2998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * histogram which will later be passed to the AddHistogramSample
2999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function.
3000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetCreateHistogramFunction(CreateHistogramCallback);
3002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
3003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the computation of a sliding window of states. The sliding
3006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * window information is recorded in statistics counters.
3007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void EnableSlidingStateWindow();
3009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Callback function for reporting failed access checks.*/
3011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
3012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to receive a notification before a
30156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
30166ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * callback function, you therefore cannot manipulate objects (set
30176ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * or delete properties for example) since it is possible such
30186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * operations will result in the allocation of objects. It is possible
30196ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * to specify the GCType filter for your callback. But it is not possible to
30206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * register the same callback function two times with different
30216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * GCType filters.
30226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
30236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void AddGCPrologueCallback(
30246ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
30256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
30266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
30276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * This function removes callback which was installed by
30286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * AddGCPrologueCallback function.
30296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
30306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void RemoveGCPrologueCallback(GCPrologueCallback callback);
30316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
30326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
30336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The function is deprecated. Please use AddGCPrologueCallback instead.
30346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Enables the host application to receive a notification before a
30356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
3036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback function, you therefore cannot manipulate objects (set
3037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * or delete properties for example) since it is possible such
3038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations will result in the allocation of objects.
3039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetGlobalGCPrologueCallback(GCCallback);
3041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to receive a notification after a
30446ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
30456ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * callback function, you therefore cannot manipulate objects (set
30466ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * or delete properties for example) since it is possible such
30476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * operations will result in the allocation of objects. It is possible
30486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * to specify the GCType filter for your callback. But it is not possible to
30496ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * register the same callback function two times with different
30506ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * GCType filters.
30516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
30526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void AddGCEpilogueCallback(
30536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
30546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
30556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
30566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * This function removes callback which was installed by
30576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * AddGCEpilogueCallback function.
30586ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
30596ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
30606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
30616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
30626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The function is deprecated. Please use AddGCEpilogueCallback instead.
30636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Enables the host application to receive a notification after a
3064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * major garbage collection.  Allocations are not allowed in the
3065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback function, you therefore cannot manipulate objects (set
3066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * or delete properties for example) since it is possible such
3067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations will result in the allocation of objects.
3068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetGlobalGCEpilogueCallback(GCCallback);
3070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
30729ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * Enables the host application to provide a mechanism to be notified
30739ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * and perform custom logging when V8 Allocates Executable Memory.
30749ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   */
30759ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
30769ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                          ObjectSpace space,
30779ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                          AllocationAction action);
30789ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
30799ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  /**
30803ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Removes callback that was installed by AddMemoryAllocationCallback.
30819ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   */
30829ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
30839ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
30849ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  /**
30853ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Adds a callback to notify the host application when a script finished
30863ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * running.  If a script re-enters the runtime during executing, the
30873ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * CallCompletedCallback is only invoked when the outer-most script
30883ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * execution ends.  Executing scripts inside the callback do not trigger
30893ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * further callbacks.
30903ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
30913ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  static void AddCallCompletedCallback(CallCompletedCallback callback);
30923ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
30933ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
30943ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Removes callback that was installed by AddCallCompletedCallback.
30953ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
30963ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  static void RemoveCallCompletedCallback(CallCompletedCallback callback);
30973ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
30983ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
3099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Allows the host application to group objects together. If one
3100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * object in the group is alive, all objects in the group are alive.
3101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * After each garbage collection, object groups are removed. It is
3102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * intended to be used in the before-garbage-collection callback
3103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function, for instance to simulate DOM tree connections among JS
3104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * wrapper objects.
310544f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * See v8-profiler.h for RetainedObjectInfo interface description.
310644f0eee88ff00398ff7f715fab053374d808c90dSteve Block   */
310744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static void AddObjectGroup(Persistent<Value>* objects,
310844f0eee88ff00398ff7f715fab053374d808c90dSteve Block                             size_t length,
310944f0eee88ff00398ff7f715fab053374d808c90dSteve Block                             RetainedObjectInfo* info = NULL);
311044f0eee88ff00398ff7f715fab053374d808c90dSteve Block
311144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  /**
311244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Allows the host application to declare implicit references between
311344f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * the objects: if |parent| is alive, all |children| are alive too.
311444f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * After each garbage collection, all implicit references
311544f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * are removed.  It is intended to be used in the before-garbage-collection
311644f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * callback function.
3117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
311844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static void AddImplicitReferences(Persistent<Object> parent,
311944f0eee88ff00398ff7f715fab053374d808c90dSteve Block                                    Persistent<Value>* children,
312044f0eee88ff00398ff7f715fab053374d808c90dSteve Block                                    size_t length);
3121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Initializes from snapshot if possible. Otherwise, attempts to
3124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * initialize from scratch.  This function is called implicitly if
3125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * you use the API without calling it first.
3126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool Initialize();
3128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
31303fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * Allows the host application to provide a callback which can be used
31313fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * as a source of entropy for random number generators.
31323fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   */
31333fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  static void SetEntropySource(EntropySource source);
31343fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
31353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  /**
31363ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Allows the host application to provide a callback that allows v8 to
31373ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * cooperate with a profiler that rewrites return addresses on stack.
31383ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
31393ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  static void SetReturnAddressLocationResolver(
31403ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch      ReturnAddressLocationResolver return_address_resolver);
31413ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
31423ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
3143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Adjusts the amount of registered external memory.  Used to give
3144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 an indication of the amount of externally allocated memory
3145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that is kept alive by JavaScript objects.  V8 uses this to decide
3146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * when to perform global garbage collections.  Registering
3147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * externally allocated memory will trigger global garbage
3148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * collections more often than otherwise in an attempt to garbage
3149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * collect the JavaScript objects keeping the externally allocated
3150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * memory alive.
3151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param change_in_bytes the change in externally allocated memory
3153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   that is kept alive by JavaScript objects.
3154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \returns the adjusted value.
3155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
3157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Suspends recording of tick samples in the profiler.
3160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When the V8 profiling mode is enabled (usually via command line
3161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * switches) this function suspends recording of tick samples.
3162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Profiling ticks are discarded until ResumeProfiler() is called.
3163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See also the --prof and --prof_auto command line switches to
3165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enable V8 profiling.
3166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void PauseProfiler();
3168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Resumes recording of tick samples in the profiler.
3171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See also PauseProfiler().
3172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ResumeProfiler();
3174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Return whether profiler is currently paused.
3177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsProfilerPaused();
3179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Retrieve the V8 thread id of the calling thread.
3182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The thread id for a thread should only be retrieved after the V8
3184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * lock has been acquired with a Locker object with that thread.
3185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int GetCurrentThreadId();
3187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Forcefully terminate execution of a JavaScript thread.  This can
3190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be used to terminate long-running scripts.
3191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TerminateExecution should only be called when then V8 lock has
3193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been acquired with a Locker object.  Therefore, in order to be
3194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * able to terminate long-running threads, preemption must be
3195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enabled to allow the user of TerminateExecution to acquire the
3196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * lock.
3197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The termination is achieved by throwing an exception that is
3199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * uncatchable by JavaScript exception handlers.  Termination
3200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exceptions act as if they were caught by a C++ TryCatch exception
3201257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * handler.  If forceful termination is used, any C++ TryCatch
3202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exception handler that catches an exception should check if that
3203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exception is a termination exception and immediately return if
3204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that is the case.  Returning immediately in that case will
3205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * continue the propagation of the termination exception if needed.
3206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The thread id passed to TerminateExecution must have been
3208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * obtained by calling GetCurrentThreadId on the thread in question.
3209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param thread_id The thread id of the thread to terminate.
3211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void TerminateExecution(int thread_id);
3213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
321544f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * Forcefully terminate the current thread of JavaScript execution
321644f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * in the given isolate. If no isolate is provided, the default
321744f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * isolate is used.
3218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This method can be used by any thread even if that thread has not
3220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * acquired the V8 lock with a Locker object.
322144f0eee88ff00398ff7f715fab053374d808c90dSteve Block   *
322244f0eee88ff00398ff7f715fab053374d808c90dSteve Block   * \param isolate The isolate in which to terminate the current JS execution.
3223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
322444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static void TerminateExecution(Isolate* isolate = NULL);
3225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
32276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Is V8 terminating JavaScript execution.
32286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *
32296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Returns true if JavaScript execution is currently terminating
32306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * because of a call to TerminateExecution.  In that case there are
32316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * still JavaScript frames on the stack and the termination
32326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * exception is still active.
32333fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   *
32343fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch   * \param isolate The isolate in which to check.
32356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
32363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  static bool IsExecutionTerminating(Isolate* isolate = NULL);
32376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
32386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
3239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Releases any resources used by v8 and stops any utility threads
3240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that may be running.  Note that disposing v8 is permanent, it
3241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * cannot be reinitialized.
3242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * It should generally not be necessary to dispose v8 before exiting
3244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a process, this should happen automatically.  It is only necessary
3245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to use if the process needs the resources taken up by v8.
3246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool Dispose();
3248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
32493ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
32503ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Get statistics about the heap memory usage.
32513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
32523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static void GetHeapStatistics(HeapStatistics* heap_statistics);
3253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
32553ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Iterates through all external resources referenced from current isolate
32563ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * heap. This method is not expected to be used except for debugging purposes
32573ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * and may be quite slow.
32583ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
32593ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  static void VisitExternalResources(ExternalResourceVisitor* visitor);
32603ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
32613ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
3262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Optional notification that the embedder is idle.
3263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 uses the notification to reduce memory footprint.
3264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This call can be used repeatedly if the embedder remains idle.
3265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the embedder should stop calling IdleNotification
3266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * until real work has been done.  This indicates that V8 has done
3267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * as much cleanup as it will be able to do.
32683ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   *
32693ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * The hint argument specifies the amount of work to be done in the function
32703ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * on scale from 1 to 1000. There is no guarantee that the actual work will
32713ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * match the hint.
3272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
32733ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  static bool IdleNotification(int hint = 1000);
3274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Optional notification that the system is running low on memory.
3277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 uses these notifications to attempt to free memory.
3278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void LowMemoryNotification();
3280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
32816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
32826ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Optional notification that a context has been disposed. V8 uses
32836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * these notifications to guide the GC heuristic. Returns the number
32846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * of context disposals - including this one - since the last time
32856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * V8 had a chance to clean up.
32866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
32876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static int ContextDisposedNotification();
32886ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
3289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8();
3291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static internal::Object** GlobalizeReference(internal::Object** handle);
3293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void DisposeGlobal(internal::Object** global_handle);
3294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void MakeWeak(internal::Object** global_handle,
3295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       void* data,
3296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       WeakReferenceCallback);
3297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ClearWeak(internal::Object** global_handle);
3298257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static void MarkIndependent(internal::Object** global_handle);
3299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsGlobalNearDeath(internal::Object** global_handle);
3300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsGlobalWeak(internal::Object** global_handle);
330144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static void SetWrapperClassId(internal::Object** global_handle,
330244f0eee88ff00398ff7f715fab053374d808c90dSteve Block                                uint16_t class_id);
3303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Handle;
3305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Local;
3306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Persistent;
3307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Context;
3308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An external exception handler.
3313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TryCatch {
3315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new try/catch block and registers it with v8.
3318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  TryCatch();
3320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Unregisters and deletes this try/catch block.
3323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~TryCatch();
3325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if an exception has been caught by this try/catch block.
3328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasCaught() const;
3330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * For certain types of exceptions, it makes no sense to continue
3333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * execution.
3334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Currently, the only type of exception that can be caught by a
3336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TryCatch handler and for which it does not make sense to continue
3337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is termination exception.  Such exceptions are thrown when the
3338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TerminateExecution methods are called to terminate a long-running
3339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * script.
3340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If CanContinue returns false, the correct action is to perform
3342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * any C++ cleanup needed and then return.
3343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool CanContinue() const;
3345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3347d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * Throws the exception caught by this TryCatch in a way that avoids
3348d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * it being caught again by this same TryCatch.  As with ThrowException
3349d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * it is illegal to execute any JavaScript operations after calling
3350d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * ReThrow; the caller must return immediately to where the exception
3351d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * is caught.
3352d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   */
3353d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  Handle<Value> ReThrow();
3354d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3355d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /**
3356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the exception caught by this try/catch block.  If no exception has
3357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been caught an empty handle is returned.
3358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The returned handle is valid until this TryCatch block has been destroyed.
3360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Exception() const;
3362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the .stack property of the thrown object.  If no .stack
3365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * property is present an empty handle is returned.
3366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> StackTrace() const;
3368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the message associated with this exception.  If there is
3371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * no message associated an empty handle is returned.
3372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The returned handle is valid until this TryCatch block has been
3374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * destroyed.
3375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<v8::Message> Message() const;
3377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clears any exceptions that may have been caught by this try/catch block.
3380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * After this method has been called, HasCaught() will return false.
3381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * It is not necessary to clear a try/catch block before using it again; if
3383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * another exception is thrown the previously caught exception will just be
3384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * overwritten.  However, it is often a good idea since it makes it easier
3385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to determine which operation threw a given exception.
3386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Reset();
3388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set verbosity of the external exception handler.
3391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * By default, exceptions that are caught by an external exception
3393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler are not reported.  Call SetVerbose with true on an
3394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * external exception handler to have exceptions caught by the
3395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler reported as if they were not caught.
3396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetVerbose(bool value);
3398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set whether or not this TryCatch should capture a Message object
3401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * which holds source information about where the exception
3402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * occurred.  True by default.
3403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCaptureMessage(bool value);
3405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3406d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block private:
34073fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  v8::internal::Isolate* isolate_;
3408d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void* next_;
3409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* exception_;
3410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* message_;
3411d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool is_verbose_ : 1;
3412d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool can_continue_ : 1;
3413d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool capture_message_ : 1;
3414d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool rethrow_ : 1;
3415d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
341644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  friend class v8::internal::Isolate;
3417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3420257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Context ---
3421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
3425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ExtensionConfiguration {
3427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ExtensionConfiguration(int name_count, const char* names[])
3429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : name_count_(name_count), names_(names) { }
3430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
3432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int name_count_;
3433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** names_;
3434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A sandboxed execution context with its own set of built-in objects
3439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and functions.
3440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Context {
3442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
34431e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  /**
34441e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * Returns the global proxy object or global object itself for
34451e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * detached contexts.
34461e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   *
34471e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * Global proxy object is a thin wrapper whose prototype points to
34481e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * actual context's global object with the properties like Object, etc.
34491e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * This is done that way for security reasons (for more details see
34501e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * https://wiki.mozilla.org/Gecko:SplitWindow).
34511e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   *
34521e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * Please note that changes to global proxy object prototype most probably
34531e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * would break VM---v8 expects only global object as a prototype of
34541e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * global proxy object.
34551e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   *
34561e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * If DetachGlobal() has been invoked, Global() would return actual global
34571e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   * object until global is reattached with ReattachGlobal().
34581e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block   */
3459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Object> Global();
3460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Detaches the global object from its context before
3463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the global object can be reused to create a new context.
3464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void DetachGlobal();
3466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
346774b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu  /**
346874b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * Reattaches a global object to a context.  This can be used to
346974b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * restore the connection between a global object and a context
347074b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * after DetachGlobal has been called.
347174b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *
347274b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * \param global_object The global object to reattach to the
347374b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   context.  For this to work, the global object must be the global
347474b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   object that was associated with this context before a call to
347574b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   DetachGlobal.
347674b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   */
347774b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu  void ReattachGlobal(Handle<Object> global_object);
347874b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu
3479f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /** Creates a new context.
3480f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
3481f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns a persistent handle to the newly allocated context. This
3482f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * persistent handle has to be disposed when the context is no
3483f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * longer used so the context can be garbage collected.
34849fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   *
34859fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * \param extensions An optional extension configuration containing
34869fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * the extensions to be installed in the newly created context.
34879fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   *
34889fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * \param global_template An optional object template from which the
34899fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * global object for the newly created context will be created.
34909fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   *
34919fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * \param global_object An optional global object to be reused for
34929fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * the newly created context. This global object must have been
34939fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * created by a previous call to Context::New with the same global
34949fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * template. The state of the global object will be completely reset
34959fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block   * and only object identify will remain.
3496f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
3497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Persistent<Context> New(
34983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu      ExtensionConfiguration* extensions = NULL,
3499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
3500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Value> global_object = Handle<Value>());
3501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the last entered context. */
3503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetEntered();
3504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the context that is on the top of the stack. */
3506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetCurrent();
3507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the context of the calling JavaScript code.  That is the
3510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context of the top-most JavaScript frame.  If there are no
3511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * JavaScript frames an empty handle is returned.
3512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetCalling();
3514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the security token for the context.  To access an object in
3517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * another context, the security tokens must match.
3518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetSecurityToken(Handle<Value> token);
3520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Restores the security token to the default value. */
3522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void UseDefaultSecurityToken();
3523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the security token of this context.*/
3525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetSecurityToken();
3526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enter this context.  After entering a context, all code compiled
3529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * and run is compiled and run in this context.  If another context
3530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is already entered, this old context is saved so it can be
3531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * restored when the new context is exited.
3532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Enter();
3534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Exit this context.  Exiting the current context restores the
3537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context that was in place when entering the current context.
3538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Exit();
3540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns true if the context has experienced an out of memory situation. */
3542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasOutOfMemoryException();
3543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns true if V8 has a current context. */
3545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool InContext();
3546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an additional data object with the context. This is mainly used
3549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * with the debugger to provide additional information on the context through
3550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the debugger API.
3551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3552d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void SetData(Handle<String> data);
3553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> GetData();
3554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3556257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Control whether code generation from strings is allowed. Calling
3557257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * this method with false will disable 'eval' and the 'Function'
3558257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * constructor for code running in this context. If 'eval' or the
3559257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * 'Function' constructor are used an exception will be thrown.
3560257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   *
3561257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * If code generation from strings is not allowed the
3562257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * V8::AllowCodeGenerationFromStrings callback will be invoked if
3563257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * set before blocking the call to 'eval' or the 'Function'
3564257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * constructor. If that callback returns true, the call will be
3565257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * allowed, otherwise an exception will be thrown. If no callback is
3566257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * set an exception will be thrown.
3567257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
3568257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  void AllowCodeGenerationFromStrings(bool allow);
3569257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
3570257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
35713ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Returns true if code generation from strings is allowed for the context.
35723ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * For more details see AllowCodeGenerationFromStrings(bool) documentation.
35733ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   */
35743ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  bool IsCodeGenerationFromStringsAllowed();
35753ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch
35763ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  /**
3577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Stack-allocated class which sets the execution context for all
3578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations executed within a local scope.
3579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
35808defd9ff6930b4e24729971a61cf7469daf119beSteve Block  class Scope {
3581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
35828b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch    explicit inline Scope(Handle<Context> context) : context_(context) {
3583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      context_->Enter();
3584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
3585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline ~Scope() { context_->Exit(); }
3586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
3587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Handle<Context> context_;
3588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
3589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Value;
3592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Script;
3593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Object;
3594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Function;
3595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Multiple threads in V8 are allowed, but only one thread at a time
360044f0eee88ff00398ff7f715fab053374d808c90dSteve Block * is allowed to use any given V8 isolate. See Isolate class
360144f0eee88ff00398ff7f715fab053374d808c90dSteve Block * comments. The definition of 'using V8 isolate' includes
360244f0eee88ff00398ff7f715fab053374d808c90dSteve Block * accessing handles or holding onto object pointers obtained
360344f0eee88ff00398ff7f715fab053374d808c90dSteve Block * from V8 handles while in the particular V8 isolate.  It is up
360444f0eee88ff00398ff7f715fab053374d808c90dSteve Block * to the user of V8 to ensure (perhaps with locking) that this
36053ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * constraint is not violated.  In addition to any other synchronization
36063ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * mechanism that may be used, the v8::Locker and v8::Unlocker classes
36073ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * must be used to signal thead switches to V8.
360844f0eee88ff00398ff7f715fab053374d808c90dSteve Block *
3609257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * v8::Locker is a scoped lock object. While it's
3610257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * active (i.e. between its construction and destruction) the current thread is
36113ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * allowed to use the locked isolate. V8 guarantees that an isolate can be
36123ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * locked by at most one thread at any time. In other words, the scope of a
36133ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch * v8::Locker is a critical section.
3614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3615257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * Sample usage:
3616257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch* \code
3617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ...
3618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3619257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *   v8::Locker locker(isolate);
3620257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *   v8::Isolate::Scope isolate_scope(isolate);
3621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3622257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *   // Code using V8 and isolate goes here.
3623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here
3625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3627257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * If you wish to stop using V8 in a thread A you can do this either
3628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * by destroying the v8::Locker object as above or by constructing a
3629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Unlocker object:
3630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3633257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *   isolate->Exit();
3634257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *   v8::Unlocker unlocker(isolate);
3635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // Code not using V8 goes here while V8 can run in another thread.
3637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here.
3639257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch * isolate->Enter();
3640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Unlocker object is intended for use in a long-running callback
3643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * from V8, where you want to release the V8 lock for other threads to
3644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * use.
3645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The v8::Locker is a recursive lock.  That is, you can lock more than
3647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * once in a given thread.  This can be useful if you have code that can
3648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be called either from code that holds the lock or from code that does
3649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * not.  The Unlocker is not recursive so you can not have several
3650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Unlockers on the stack at once, and you can not use an Unlocker in a
3651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * thread that is not inside a Locker's scope.
3652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An unlocker will unlock several lockers if it has to and reinstate
3654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the correct depth of locking on its destruction. eg.:
3655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 not locked.
3658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3659257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *   v8::Locker locker(isolate);
3660257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *   Isolate::Scope isolate_scope(isolate);
3661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // V8 locked.
3662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   {
3663257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *     v8::Locker another_locker(isolate);
3664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     // V8 still locked (2 levels).
3665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     {
3666257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *       isolate->Exit();
3667257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *       v8::Unlocker unlocker(isolate);
3668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *       // V8 not locked.
3669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     }
3670257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *     isolate->Enter();
3671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     // V8 locked again (2 levels).
3672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   }
3673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // V8 still locked (1 level).
3674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * }
3675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 Now no longer locked.
3676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3677257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch *
3678589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch *
3679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Unlocker {
3681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3682257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
3683257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Initialize Unlocker for a given Isolate. NULL means default isolate.
3684257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
3685257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  explicit Unlocker(Isolate* isolate = NULL);
3686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~Unlocker();
3687257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch private:
3688257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  internal::Isolate* isolate_;
3689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Locker {
3693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3694257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  /**
3695257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * Initialize Locker for a given Isolate. NULL means default isolate.
3696257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   */
3697257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  explicit Locker(Isolate* isolate = NULL);
3698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~Locker();
3699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Start preemption.
3702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3703257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch   * When preemption is started, a timer is fired every n milliseconds
3704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that will switch between multiple threads that are in contention
3705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * for the V8 lock.
3706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void StartPreemption(int every_n_ms);
3708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Stop preemption.
3711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void StopPreemption();
3713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
37153ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * Returns whether or not the locker for a given isolate, or default isolate
37163ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch   * if NULL is given, is locked by the current thread.
3717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3718257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static bool IsLocked(Isolate* isolate = NULL);
3719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns whether v8::Locker is being used by this V8 instance.
3722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
372369a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch  static bool IsActive();
3724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool has_lock_;
3727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool top_level_;
3728257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  internal::Isolate* isolate_;
3729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool active_;
3731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Disallow copying and assigning.
3733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Locker(const Locker&);
3734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const Locker&);
3735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
37380d5e116f6aee03185f237311a943491bb079a768Kristian Monsen/**
37390d5e116f6aee03185f237311a943491bb079a768Kristian Monsen * An interface for exporting data from V8, using "push" model.
37400d5e116f6aee03185f237311a943491bb079a768Kristian Monsen */
37413e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhuclass V8EXPORT OutputStream {  // NOLINT
37423e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu public:
37430d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  enum OutputEncoding {
37440d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kAscii = 0  // 7-bit ASCII.
37450d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  };
37460d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  enum WriteResult {
37470d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kContinue = 0,
37480d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kAbort = 1
37490d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  };
37500d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual ~OutputStream() {}
37510d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Notify about the end of stream. */
37520d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual void EndOfStream() = 0;
37530d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Get preferred output chunk size. Called only once. */
37540d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual int GetChunkSize() { return 1024; }
37550d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Get preferred output encoding. Called only once. */
37560d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual OutputEncoding GetOutputEncoding() { return kAscii; }
37570d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /**
37580d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * Writes the next chunk of snapshot data into the stream. Writing
37590d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * can be stopped by returning kAbort as function result. EndOfStream
37600d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * will not be called in case writing was aborted.
37610d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   */
37620d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
37630d5e116f6aee03185f237311a943491bb079a768Kristian Monsen};
37640d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
37650d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
3766b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch/**
3767b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch * An interface for reporting progress and controlling long-running
3768b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch * activities.
3769b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch */
3770b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochclass V8EXPORT ActivityControl {  // NOLINT
3771b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch public:
3772b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  enum ControlOption {
3773b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    kContinue = 0,
3774b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    kAbort = 1
3775b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  };
3776b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  virtual ~ActivityControl() {}
3777b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  /**
3778b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   * Notify about current progress. The activity can be stopped by
3779b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   * returning kAbort as the callback result.
3780b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch   */
3781b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  virtual ControlOption ReportProgressValue(int done, int total) = 0;
3782b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch};
3783b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3785257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch// --- Implementation ---
3786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3787a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
3789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
37903ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochconst int kApiPointerSize = sizeof(void*);  // NOLINT
37913ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochconst int kApiIntSize = sizeof(int);  // NOLINT
3792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for HeapObject.
3794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTag = 1;
3795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTagSize = 2;
3796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
3797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for Smi.
3799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTag = 0;
3800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTagSize = 1;
3801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
3802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3803b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochtemplate <size_t ptr_size> struct SmiTagging;
38043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
38053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 32-bit systems.
3806b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochtemplate <> struct SmiTagging<4> {
38073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiShiftSize = 0;
38083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiValueSize = 31;
38093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int SmiToInt(internal::Object* value) {
38103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    int shift_bits = kSmiTagSize + kSmiShiftSize;
38113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // Throw away top 32 bits and shift down (requires >> to be sign extending).
38123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
38133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
3814b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
3815b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi
3816b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  // with a plain reinterpret_cast.
38171e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const uintptr_t kEncodablePointerMask = 0x1;
3818b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  static const int kPointerToSmiShift = 0;
38193ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
38203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
38213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 64-bit systems.
3822b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochtemplate <> struct SmiTagging<8> {
38233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiShiftSize = 31;
38243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiValueSize = 32;
38253ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int SmiToInt(internal::Object* value) {
38263ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    int shift_bits = kSmiTagSize + kSmiShiftSize;
38273ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // Shift down and throw away top 32 bits.
38283ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
38293ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
3830b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
3831b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  // To maximize the range of pointers that can be encoded
3832b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  // in the available 32 bits, we require them to be 8 bytes aligned.
3833b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  // This gives 2 ^ (32 + 3) = 32G address space covered.
3834b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  // It might be not enough to cover stack allocated objects on some platforms.
3835b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  static const int kPointerAlignment = 3;
3836b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
38371e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const uintptr_t kEncodablePointerMask =
38381e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block      ~(uintptr_t(0xffffffff) << kPointerAlignment);
3839b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
3840b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  static const int kPointerToSmiShift =
3841b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      kSmiTagSize + kSmiShiftSize - kPointerAlignment;
38423ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
38433ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3844b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochtypedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
3845b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochconst int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
3846b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochconst int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
38471e0659c275bb392c045087af4f6b0d7565cb3d77Steve Blockconst uintptr_t kEncodablePointerMask =
3848b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch    PlatformSmiTagging::kEncodablePointerMask;
3849b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochconst int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;
3850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3851d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <size_t ptr_size> struct InternalConstants;
3852d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3853d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 32-bit systems.
3854d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<4> {
38558a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kStringResourceOffset = 3 * kApiPointerSize;
3856d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block};
3857d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3858d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 64-bit systems.
3859d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<8> {
38608a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kStringResourceOffset = 3 * kApiPointerSize;
3861d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block};
3862d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This class exports constants and functionality from within v8 that
3865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is necessary to implement inline functions in the v8 api.  Don't
3866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * depend on functions and constants defined here.
3867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Internals {
3869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // These values match non-compiler-dependent values defined within
3871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the implementation of v8.
3872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeapObjectMapOffset = 0;
387344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
3874d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kStringResourceOffset =
38758a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang      InternalConstants<kApiPointerSize>::kStringResourceOffset;
3876d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3877257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static const int kForeignAddressOffset = kApiPointerSize;
38788a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
3879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFullStringRepresentationMask = 0x07;
38807f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kExternalTwoByteRepresentationTag = 0x02;
3881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
38823ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  static const int kJSObjectType = 0xaa;
38839dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kFirstNonstringType = 0x80;
3884257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  static const int kForeignType = 0x85;
3885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool HasHeapObjectTag(internal::Object* value) {
3887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
3888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            kHeapObjectTag);
3889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool HasSmiTag(internal::Object* value) {
3892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
3893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline int SmiValue(internal::Object* value) {
3896b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch    return PlatformSmiTagging::SmiToInt(value);
38973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
38983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
38993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int GetInstanceType(internal::Object* obj) {
39003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    typedef internal::Object O;
39013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
39023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
39033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
39043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3905b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  static inline void* GetExternalPointerFromSmi(internal::Object* value) {
39061e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block    const uintptr_t address = reinterpret_cast<uintptr_t>(value);
3907b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch    return reinterpret_cast<void*>(address >> kPointerToSmiShift);
3908b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  }
3909b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
39103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline void* GetExternalPointer(internal::Object* obj) {
39113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    if (HasSmiTag(obj)) {
3912b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      return GetExternalPointerFromSmi(obj);
3913257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    } else if (GetInstanceType(obj) == kForeignType) {
3914257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch      return ReadField<void*>(obj, kForeignAddressOffset);
39153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    } else {
39163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block      return NULL;
39173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    }
3918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool IsExternalTwoByteString(int instance_type) {
3921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int representation = (instance_type & kFullStringRepresentationMask);
3922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return representation == kExternalTwoByteRepresentationTag;
3923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <typename T>
3926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline T ReadField(Object* ptr, int offset) {
3927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
3928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return *reinterpret_cast<T*>(addr);
3929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
393044f0eee88ff00398ff7f715fab053374d808c90dSteve Block
393144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool CanCastToHeapObject(void* o) { return false; }
393244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool CanCastToHeapObject(Context* o) { return true; }
393344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool CanCastToHeapObject(String* o) { return true; }
393444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool CanCastToHeapObject(Object* o) { return true; }
393544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool CanCastToHeapObject(Message* o) { return true; }
393644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool CanCastToHeapObject(StackTrace* o) { return true; }
393744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool CanCastToHeapObject(StackFrame* o) { return true; }
3938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
39403e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu}  // namespace internal
3941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T>::Local() : Handle<T>() { }
3945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> Local<T>::New(Handle<T> that) {
3949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (that.IsEmpty()) return Local<T>();
395044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  T* that_ptr = *that;
395144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
395244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  if (internal::Internals::CanCastToHeapObject(that_ptr)) {
395344f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
395444f0eee88ff00398ff7f715fab053374d808c90dSteve Block        reinterpret_cast<internal::HeapObject*>(*p))));
395544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  }
3956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
3957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T> Persistent<T>::New(Handle<T> that) {
3962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (that.IsEmpty()) return Persistent<T>();
3963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** p = reinterpret_cast<internal::Object**>(*that);
3964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
3965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsNearDeath() const {
3970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return false;
3971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
3972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsWeak() const {
3977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return false;
3978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
3979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::Dispose() {
3984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return;
3985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
3986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T>::Persistent() : Handle<T>() { }
3991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
3994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
3995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block               parameters,
3996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block               callback);
3997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
4000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::ClearWeak() {
4001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
4002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
400444f0eee88ff00398ff7f715fab053374d808c90dSteve Blocktemplate <class T>
4005257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdochvoid Persistent<T>::MarkIndependent() {
4006257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this));
4007257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch}
4008257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
4009257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdochtemplate <class T>
401044f0eee88ff00398ff7f715fab053374d808c90dSteve Blockvoid Persistent<T>::SetWrapperClassId(uint16_t class_id) {
401144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id);
401244f0eee88ff00398ff7f715fab053374d808c90dSteve Block}
40138defd9ff6930b4e24729971a61cf7469daf119beSteve Block
40143e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui ZhuArguments::Arguments(internal::Object** implicit_args,
40153e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                     internal::Object** values, int length,
40163e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu                     bool is_construct_call)
40173e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu    : implicit_args_(implicit_args),
40183e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      values_(values),
40193e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      length_(length),
40203e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      is_construct_call_(is_construct_call) { }
40218defd9ff6930b4e24729971a61cf7469daf119beSteve Block
40228defd9ff6930b4e24729971a61cf7469daf119beSteve Block
4023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::operator[](int i) const {
4024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
4025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
4026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Function> Arguments::Callee() const {
40303e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  return Local<Function>(reinterpret_cast<Function*>(
40313e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      &implicit_args_[kCalleeIndex]));
4032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::This() const {
4036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
4037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::Holder() const {
40413e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  return Local<Object>(reinterpret_cast<Object*>(
40423e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu      &implicit_args_[kHolderIndex]));
4043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::Data() const {
40473e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu  return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
4048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Arguments::IsConstructCall() const {
4052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return is_construct_call_;
4053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockint Arguments::Length() const {
4057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return length_;
4058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
4062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> HandleScope::Close(Handle<T> value) {
4063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** before = reinterpret_cast<internal::Object**>(*value);
4064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** after = RawClose(before);
4065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<T>(reinterpret_cast<T*>(after));
4066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> ScriptOrigin::ResourceName() const {
4069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_name_;
4070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceLineOffset() const {
4074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_line_offset_;
4075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceColumnOffset() const {
4079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_column_offset_;
4080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> Boolean::New(bool value) {
4084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return value ? True() : False();
4085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Template::Set(const char* name, v8::Handle<Data> value) {
4089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Set(v8::String::New(name), value);
4090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::GetInternalField(int index) {
4094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_ENABLE_CHECKS
4095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> quick_result = UncheckedGetInternalField(index);
4096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (!quick_result.IsEmpty()) return quick_result;
4097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return CheckedGetInternalField(index);
4099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::UncheckedGetInternalField(int index) {
4103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
4104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
4105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(this);
41063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::GetInstanceType(obj) == I::kJSObjectType) {
4107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If the object is a plain JSObject, which is the common case,
4108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // we know where to find the internal fields and can return the
4109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // value directly.
41108a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang    int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
4111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    O* value = I::ReadField<O*>(obj, offset);
4112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    O** result = HandleScope::CreateHandle(value);
4113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<Value>(reinterpret_cast<Value*>(result));
4114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  } else {
4115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<Value>();
4116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
4117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::Unwrap(Handle<v8::Value> obj) {
4121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return FullUnwrap(obj);
4123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
4124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return QuickUnwrap(obj);
4125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::QuickUnwrap(Handle<v8::Value> wrapper) {
4130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
4131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
41323ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return internal::Internals::GetExternalPointer(obj);
4133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* Object::GetPointerFromInternalField(int index) {
41373ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  typedef internal::Object O;
41383ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  typedef internal::Internals I;
41393ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
41403ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  O* obj = *reinterpret_cast<O**>(this);
41413ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
41423ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::GetInstanceType(obj) == I::kJSObjectType) {
41433ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // If the object is a plain JSObject, which is the common case,
41443ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // we know where to find the internal fields and can return the
41453ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // value directly.
41468a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang    int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
41473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    O* value = I::ReadField<O*>(obj, offset);
41483ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return I::GetExternalPointer(value);
41493ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
41503ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
41513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return SlowGetPointerFromInternalField(index);
4152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString* String::Cast(v8::Value* value) {
4156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<String*>(value);
4160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString::ExternalStringResource* String::GetExternalStringResource() const {
4164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
4165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
4166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  String::ExternalStringResource* result;
41683ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
4169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    result = reinterpret_cast<String::ExternalStringResource*>(value);
4171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  } else {
4172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    result = NULL;
4173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
4174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  VerifyExternalStringResource(result);
4176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return result;
4178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::IsString() const {
4182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return FullIsString();
4184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
4185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return QuickIsString();
4186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::QuickIsString() const {
4190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
4191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
4192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (!I::HasHeapObjectTag(obj)) return false;
41943ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
4195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockNumber* Number::Cast(v8::Value* value) {
4199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Number*>(value);
4203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockInteger* Integer::Cast(v8::Value* value) {
4207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Integer*>(value);
4211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDate* Date::Cast(v8::Value* value) {
4215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Date*>(value);
4219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
42223fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochStringObject* StringObject::Cast(v8::Value* value) {
42233fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#ifdef V8_ENABLE_CHECKS
42243fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  CheckCast(value);
42253fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#endif
42263fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  return static_cast<StringObject*>(value);
42273fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch}
42283fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
42293fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
42303fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochNumberObject* NumberObject::Cast(v8::Value* value) {
42313fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#ifdef V8_ENABLE_CHECKS
42323fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  CheckCast(value);
42333fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#endif
42343fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  return static_cast<NumberObject*>(value);
42353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch}
42363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
42373fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
42383fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochBooleanObject* BooleanObject::Cast(v8::Value* value) {
42393fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#ifdef V8_ENABLE_CHECKS
42403fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  CheckCast(value);
42413fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch#endif
42423fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch  return static_cast<BooleanObject*>(value);
42433fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch}
42443fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
42453fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch
4246f87a203d89e1bbb6708282e0b64dbd13d59b723dBen MurdochRegExp* RegExp::Cast(v8::Value* value) {
4247f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch#ifdef V8_ENABLE_CHECKS
4248f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  CheckCast(value);
4249f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch#endif
4250f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  return static_cast<RegExp*>(value);
4251f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch}
4252f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
4253f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
4254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockObject* Object::Cast(v8::Value* value) {
4255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Object*>(value);
4259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockArray* Array::Cast(v8::Value* value) {
4263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Array*>(value);
4267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockFunction* Function::Cast(v8::Value* value) {
4271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Function*>(value);
4275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockExternal* External::Cast(v8::Value* value) {
4279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
4280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
4281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<External*>(value);
4283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> AccessorInfo::Data() const {
42876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
4288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::This() const {
4292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
4293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::Holder() const {
4297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
4298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
4299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
4302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example shell.cc
4303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A simple shell that takes a list of expressions on the
4304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * command-line and executes them.
4305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
4306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
4309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example process.cc
4310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
4311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}  // namespace v8
4314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef V8EXPORT
4317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef TYPE_CHECK
4318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // V8_H_
4321