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