v8.h revision 5913587db4c6bab03d97bfe44b06289fd6d7270d
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
41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include <stdio.h>
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef _WIN32
44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// When compiling on MinGW stdint.h is available.
45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef __MINGW32__
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include <stdint.h>
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else  // __MINGW32__
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef signed char int8_t;
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned char uint8_t;
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef short int16_t;  // NOLINT
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned short uint16_t;  // NOLINT
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int int32_t;
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned int uint32_t;
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef __int64 int64_t;
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned __int64 uint64_t;
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// intptr_t and friends are defined in crtdefs.h through stdio.h.
57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // __MINGW32__
58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Windows DLL export/import. When building the V8 DLL the
60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// BUILDING_V8_SHARED needs to be defined. When building a program which uses
61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// static library or building a program which uses the V8 static library neither
63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  build configuration to ensure that at most one of these is set
67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef BUILDING_V8_SHARED
70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __declspec(dllexport)
71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#elif USING_V8_SHARED
72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __declspec(dllimport)
73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT
75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // BUILDING_V8_SHARED
76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else  // _WIN32
78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include <stdint.h>
80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Linux shared library export. There is no need to distinguish
82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// between building or using the V8 shared library, but we should not
83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// export symbols when we are building a static library.
84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __attribute__ ((visibility("default")))
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else  // defined(__GNUC__) && (__GNUC__ >= 4)
87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // defined(__GNUC__) && (__GNUC__ >= 4)
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // _WIN32
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The v8 JavaScript engine.
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 {
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Context;
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass String;
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Value;
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Utils;
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Number;
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Object;
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Array;
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Int32;
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Uint32;
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass External;
107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Primitive;
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Boolean;
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Integer;
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Function;
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Date;
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ImplementationUtilities;
113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Signature;
114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Handle;
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Local;
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Persistent;
117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass FunctionTemplate;
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ObjectTemplate;
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Data;
120f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeclass AccessorInfo;
12125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackTrace;
12225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackFrame;
123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Arguments;
127d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blockclass Object;
1287f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochclass Heap;
129d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blockclass Top;
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- W e a k  H a n d l e s
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A weak reference callback function.
139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
14050ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * This callback should either explicitly invoke Dispose on |object| if
14150ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak.
14250ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen *
143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param object the weak global object to be reclaimed by the garbage collector
144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param parameter the value passed in when making the weak global object
145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*WeakReferenceCallback)(Persistent<Value> object,
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      void* parameter);
148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- H a n d l e s ---
151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15250ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen#define TYPE_CHECK(T, S)                                       \
15350ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen  while (false) {                                              \
15450ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen    *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference managed by the v8 garbage collector.
159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * All objects returned from v8 have to be tracked by the garbage
161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * collector so that it knows that the objects are still alive.  Also,
162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * because the garbage collector may move objects, it is unsafe to
163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * point directly to an object.  Instead, all objects are stored in
164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles which are known by the garbage collector and updated
165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * whenever an object moves.  Handles should always be passed by value
166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * (except in cases like out-parameters) and they should never be
167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated on the heap.
168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * There are two types of handles: local and persistent handles.
170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local handles are light-weight and transient and typically used in
171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * local operations.  They are managed by HandleScopes.  Persistent
172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles can be used when storing objects across several independent
173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operations and have to be explicitly deallocated when they're no
174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * longer used.
175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * It is safe to extract the object stored in the handle by
177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * dereferencing the handle (for instance, to extract the Object* from
178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * an Handle<Object>); the value will still be governed by a handle
179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * behind the scenes and the same rules apply to these values as to
180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * their handles.
181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1828defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Handle {
183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates an empty handle.
187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle();
189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new handle for the specified value.
192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1938defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline explicit Handle(T* val) : val_(val) { }
194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a handle for the contents of the specified handle.  This
197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * constructor allows you to pass handles as arguments by value and
198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to assign between handles.  However, if you try to assign between
199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * incompatible handles, for instance from a Handle<String> to a
200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Handle<Number> it will cause a compiletime error.  Assigning
201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * between compatible handles, for instance assigning a
202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Handle<String> to a variable declared as Handle<Value>, is legal
203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * because String is a subclass of Value.
204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Handle(Handle<S> that)
206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : val_(reinterpret_cast<T*>(*that)) {
207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the handle is empty.
217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2188defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline bool IsEmpty() const { return val_ == 0; }
219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2208defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline T* operator->() const { return val_; }
221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline T* operator*() const { return val_; }
223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the handle to be empty. IsEmpty() will then return true.
226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2278defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline void Clear() { this->val_ = 0; }
228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Checks whether two handles are the same.
231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if both are empty, or if the objects
232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to which they refer are identical.
233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The handles' references are not checked.
234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2358defd9ff6930b4e24729971a61cf7469daf119beSteve Block  template <class S> inline bool operator==(Handle<S> that) const {
236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** a = reinterpret_cast<internal::Object**>(**this);
237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** b = reinterpret_cast<internal::Object**>(*that);
238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (a == 0) return b == 0;
239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (b == 0) return false;
240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return *a == *b;
241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Checks whether two handles are different.
245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if only one of the handles is empty, or if
246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the objects to which they refer are different.
247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The handles' references are not checked.
248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2498defd9ff6930b4e24729971a61cf7469daf119beSteve Block  template <class S> inline bool operator!=(Handle<S> that) const {
250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return !operator==(that);
251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Handle<T> Cast(Handle<S> that) {
254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Handle<T>();
258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Handle<T>(T::Cast(*that));
260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Handle<S> As() {
2636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Handle<S>::Cast(*this);
2646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
2656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  T* val_;
268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A light-weight stack-allocated object handle.  All operations
273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that return objects from within v8 return them in local handles.  They
274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are created within HandleScopes, and all local handles allocated within a
275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope are destroyed when the handle scope is destroyed.  Hence it
276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is not necessary to explicitly deallocate local handles.
277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2788defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Local : public Handle<T> {
279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local();
281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Local(Local<S> that)
282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(reinterpret_cast<T*>(*that)) {
283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Local(S* that) : Handle<T>(that) { }
291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Local<T> Cast(Local<S> that) {
292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Local<T>();
296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<T>(T::Cast(*that));
298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Local<S> As() {
3016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Local<S>::Cast(*this);
3026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
3036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Create a local handle for the content of another handle.
305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *  The referee is kept alive by the local handle even when
306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *  the original handle is destroyed/disposed.
307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline static Local<T> New(Handle<T> that);
309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference that is independent of any handle scope.  Where
314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a Local handle only lives as long as the HandleScope in which it was
315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated, a Persistent handle remains valid until it is explicitly
316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * disposed.
317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A persistent handle contains a reference to a storage cell within
319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the v8 engine which holds an object value and which is updated by
320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the garbage collector whenever the object is moved.  A new storage
321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * cell can be created using Persistent::New and existing handles can
322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be disposed using Persistent::Dispose.  Since persistent handles
323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are passed by value you may have many persistent handle objects
324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that point to the same storage cell.  For instance, if you pass a
325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * persistent handle as an argument to a function you will not get two
326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * different storage cells but rather two references to the same
327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * storage cell.
328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3298defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Persistent : public Handle<T> {
330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates an empty persistent handle that doesn't point to any
334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * storage cell.
335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Persistent();
337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a persistent handle for the same storage cell as the
340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * specified handle.  This constructor allows you to pass persistent
341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handles as arguments by value and to assign between persistent
342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handles.  However, attempting to assign between incompatible
343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * persistent handles, for instance from a Persistent<String> to a
344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Persistent<Number> will cause a compiletime error.  Assigning
345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * between compatible persistent handles, for instance assigning a
346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Persistent<String> to a variable declared as Persistent<Value>,
347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is allowed as String is a subclass of Value.
348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Persistent(Persistent<S> that)
350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(reinterpret_cast<T*>(*that)) {
351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * This check fails when trying to convert between incompatible
353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * handles. For example, converting from a Handle<String> to a
354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Handle<Number>.
355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_CHECK(T, S);
357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> inline Persistent(S* that) : Handle<T>(that) { }
360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * "Casts" a plain handle which is known to be a persistent handle
363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to a persistent handle.
364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> explicit inline Persistent(Handle<S> that)
366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : Handle<T>(*that) { }
367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If we're going to perform the type check then we have to check
371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // that the handle isn't empty before doing the checked cast.
372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (that.IsEmpty()) return Persistent<T>();
373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Persistent<T>(T::Cast(*that));
375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  template <class S> inline Persistent<S> As() {
3786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return Persistent<S>::Cast(*this);
3796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
3806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new persistent handle for an existing local or
383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * persistent handle.
384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline static Persistent<T> New(Handle<T> that);
386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Releases the storage cell referenced by this persistent handle.
389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Does not remove the reference to the cell from any handles.
390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This handle's reference, and any any other references to the storage
391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * cell remain and IsEmpty will still return false.
392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Dispose();
394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Make the reference to this object weak.  When only weak handles
397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * refer to the object, the garbage collector will perform a
398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback to the given V8::WeakReferenceCallback function, passing
399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * it the object reference and the given parameters.
400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Clears the weak reference to this object.*/
404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ClearWeak();
405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *Checks if the handle holds the only reference to an object.
408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsNearDeath() const;
410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the handle's reference is weak.
413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsWeak() const;
415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /**
423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A stack-allocated class that governs a number of local handles.
424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After a handle scope has been created, all local handles will be
425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated within that handle scope until either the handle scope is
426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * deleted or another handle scope is created.  If there is already a
427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope and a new one is created, all allocations will take
428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * place in the new handle scope until it is deleted.  After that,
429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * new handles will again be allocated in the original handle scope.
430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After the handle scope of a local handle has been deleted the
432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * garbage collector will no longer track the object stored in the
433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle and may deallocate it.  The behavior of accessing a handle
434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for which the handle scope has been deleted is undefined.
435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT HandleScope {
437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  HandleScope();
439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~HandleScope();
441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Closes the handle scope and returns the value as a handle in the
444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * previous scope, which is the new current scope after the call.
445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> Local<T> Close(Handle<T> value);
447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Counts the number of allocated handles.
450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int NumberOfHandles();
452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new handle with the given value.
455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static internal::Object** CreateHandle(internal::Object* value);
457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Make it impossible to create heap-allocated or illegal handle
460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // scopes by disallowing certain operations.
461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  HandleScope(const HandleScope&);
462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const HandleScope&);
463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* operator new(size_t size);
464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator delete(void*, size_t);
465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
466d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // This Data class is accessible internally as HandleScopeData through a
467d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // typedef in the ImplementationUtilities class.
468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Data {
469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** next;
471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    internal::Object** limit;
4725913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    int level;
4735913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline void Initialize() {
475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      next = limit = NULL;
4765913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      level = 0;
477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
4795913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
4805913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  void Leave();
481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4825913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
4835913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  internal::Object** prev_next_;
4845913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  internal::Object** prev_limit_;
485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Allow for the active closing of HandleScopes which allows to pass a handle
487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // from the HandleScope being closed to the next top most HandleScope.
488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_closed_;
489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** RawClose(internal::Object** value);
490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- S p e c i a l   o b j e c t s ---
496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of values and API object templates.
500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Data {
502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Data();
504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Pre-compilation data that can be associated with a script.  This
509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data can be calculated for a script in advance of actually
510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * compiling it, and can be stored between compilations.  When script
511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data is given to the compile method compilation will be faster.
512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ScriptData {  // NOLINT
514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~ScriptData() { }
5167f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
517f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
518f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Pre-compiles the specified script (context-independent).
519f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
520f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param input Pointer to UTF-8 script source code.
521f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param length Length of UTF-8 script source code.
522f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static ScriptData* PreCompile(const char* input, int length);
524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
525f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
5267f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * Pre-compiles the specified script (context-independent).
5277f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   *
5287f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * NOTE: Pre-compilation using this method cannot happen on another thread
5297f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * without using Lockers.
5307f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   *
5317f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * \param source Script source code.
5327f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   */
5337f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static ScriptData* PreCompile(Handle<String> source);
5347f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
5357f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  /**
536f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Load previous pre-compilation data.
537f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
538f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param data Pointer to data returned by a call to Data() of a previous
539f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *   ScriptData. Ownership is not transferred.
540f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * \param length Length of data.
541f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
542f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  static ScriptData* New(const char* data, int length);
543f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
544f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
545f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns the length of Data().
546f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual int Length() = 0;
548f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
549f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
550f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns a serialized representation of this ScriptData that can later be
551f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * passed to New(). NOTE: Serialized data is platform-dependent.
552f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
553f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  virtual const char* Data() = 0;
554f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
555f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /**
556f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns true if the source code could not be parsed.
557f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
558e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  virtual bool HasError() = 0;
559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The origin, within a file, of a script.
564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
5658defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass ScriptOrigin {
566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5678defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline ScriptOrigin(
5688defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Value> resource_name,
5698defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Integer> resource_line_offset = Handle<Integer>(),
5708defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<Integer> resource_column_offset = Handle<Integer>())
571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : resource_name_(resource_name),
572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        resource_line_offset_(resource_line_offset),
573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        resource_column_offset_(resource_column_offset) { }
574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Value> ResourceName() const;
575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Integer> ResourceLineOffset() const;
576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Handle<Integer> ResourceColumnOffset() const;
577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> resource_name_;
579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Integer> resource_line_offset_;
580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Integer> resource_column_offset_;
581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A compiled JavaScript script.
586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Script {
588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
590402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
591402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script (context-independent).
592402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
593402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
5946ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param origin Script origin, owned by caller, no references are kept
595402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when New() returns
596402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
597402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   using pre_data speeds compilation if it's done multiple times.
598402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   Owned by caller, no references are kept when New() returns.
599402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
6006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *   this has same effect as calling SetData(), but allows data to be
601402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   available to compile event handlers.
602402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object (context independent; when run it
603402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   will use the currently entered context).
604402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
605402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static Local<Script> New(Handle<String> source,
606402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           ScriptOrigin* origin = NULL,
607402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           ScriptData* pre_data = NULL,
608402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           Handle<String> script_data = Handle<String>());
609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
610402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
611402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script using the specified file name
612402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * object (typically a string) as the script's origin.
613402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
614402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
6156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param file_name file name object (typically a string) to be used
616402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   as the script's origin.
617402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object (context independent; when run it
618402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   will use the currently entered context).
619402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
620402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static Local<Script> New(Handle<String> source,
621402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                           Handle<Value> file_name);
622402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
623402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
624402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Compiles the specified script (bound to current context).
625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
626402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
6276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param origin Script origin, owned by caller, no references are kept
628402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when Compile() returns
629402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
630402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   using pre_data speeds compilation if it's done multiple times.
631402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   Owned by caller, no references are kept when Compile() returns.
632402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
633402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   this has same effect as calling SetData(), but makes data available
634402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   earlier (i.e. to compile event handlers).
635402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object, bound to the context that was active
636402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when this function was called.  When run it will always use this
637402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   context.
638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Script> Compile(Handle<String> source,
640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               ScriptOrigin* origin = NULL,
641402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               ScriptData* pre_data = NULL,
642402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<String> script_data = Handle<String>());
643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Compiles the specified script using the specified file name
646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * object (typically a string) as the script's origin.
647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
648402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param source Script source code.
649402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param file_name File name to use as script's origin
650402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param script_data Arbitrary data associated with script. Using
651402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   this has same effect as calling SetData(), but makes data available
652402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   earlier (i.e. to compile event handlers).
653402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \return Compiled script object, bound to the context that was active
654402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   when this function was called.  When run it will always use this
655402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *   context.
656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Script> Compile(Handle<String> source,
658402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<Value> file_name,
659402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu                               Handle<String> script_data = Handle<String>());
660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Runs the script returning the resulting value.  If the script is
663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context independent (created using ::New) it will be run in the
664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * currently entered context.  If it is context specific (created
665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * using ::Compile) it will be run in the context in which it was
666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * compiled.
667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Run();
669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the script id value.
672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Id();
674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an additional data object with the script. This is mainly used
677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * with the debugger as this data object is only available through the
678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * debugger API.
679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
680d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void SetData(Handle<String> data);
681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An error message.
686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Message {
688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<String> Get() const;
690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<String> GetSourceLine() const;
691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the resource name for the script from where the function causing
694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error originates.
695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetScriptResourceName() const;
697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the resource data for the script from where the function causing
700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error originates.
701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetScriptData() const;
703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
7053bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * Exception stack trace. By default stack traces are not captured for
7063bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
7073bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * to change this option.
7083bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   */
7093bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  Handle<StackTrace> GetStackTrace() const;
7103bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
7113bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  /**
712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number, 1-based, of the line where the error occurred.
713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetLineNumber() const;
715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the script of the first character where
718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetStartPosition() const;
721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the script of the last character where
724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetEndPosition() const;
727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the line of the first character where
730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetStartColumn() const;
733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the index within the line of the last character where
736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the error occurred.
737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetEndColumn() const;
739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // TODO(1245381): Print to a string instead of on a FILE.
741a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void PrintCurrentStackTrace(FILE* out);
74225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
74325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kNoLineNumberInfo = 0;
74425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kNoColumnInfo = 0;
74525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen};
74625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
74725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
74825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/**
74925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Representation of a JavaScript stack trace. The information collected is a
75025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * snapshot of the execution stack and the information remains valid after
75125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * execution continues.
75225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */
75325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackTrace {
75425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public:
75525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
75625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Flags that determine what information is placed captured for each
75725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * StackFrame when grabbing the current stack trace.
75825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
75925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  enum StackTraceOptions {
76025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kLineNumber = 1,
76125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kColumnOffset = 1 << 1 | kLineNumber,
76225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kScriptName = 1 << 2,
76325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kFunctionName = 1 << 3,
76425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kIsEval = 1 << 4,
76525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kIsConstructor = 1 << 5,
766f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kScriptNameOrSourceURL = 1 << 6,
76725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen    kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
768f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
76925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  };
77025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
77125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
77225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns a StackFrame at a particular index.
77325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
77425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<StackFrame> GetFrame(uint32_t index) const;
77525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
77625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
77725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the number of StackFrames.
77825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
77925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetFrameCount() const;
78025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
78125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
78225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns StackTrace as a v8::Array that contains StackFrame objects.
78325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
78425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<Array> AsArray();
78525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
78625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
78725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Grab a snapshot of the the current JavaScript execution stack.
78825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   *
78925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * \param frame_limit The maximum number of stack frames we want to capture.
79025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * \param options Enumerates the set of things we will capture for each
79125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   *   StackFrame.
79225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
79325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static Local<StackTrace> CurrentStackTrace(
79425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen      int frame_limit,
79525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen      StackTraceOptions options = kOverview);
79625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen};
79725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
79825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
79925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/**
80025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * A single JavaScript stack frame.
80125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */
80225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackFrame {
80325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public:
80425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
80525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the number, 1-based, of the line for the associate function call.
80625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * This method will return Message::kNoLineNumberInfo if it is unable to
80725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * retrieve the line number, or if kLineNumber was not passed as an option
80825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * when capturing the StackTrace.
80925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
81025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetLineNumber() const;
81125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
81225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
81325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the 1-based column offset on the line for the associated function
81425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * call.
81525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * This method will return Message::kNoColumnInfo if it is unable to retrieve
81625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * the column number, or if kColumnOffset was not passed as an option when
81725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * capturing the StackTrace.
81825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
81925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  int GetColumn() const;
82025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
82125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
82225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the name of the resource that contains the script for the
82325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * function for this StackFrame.
82425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
82525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<String> GetScriptName() const;
82625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
82725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
828f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Returns the name of the resource that contains the script for the
829f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * function for this StackFrame or sourceURL value if the script name
830f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * is undefined and its source ends with //@ sourceURL=... string.
831f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
832f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  Local<String> GetScriptNameOrSourceURL() const;
833f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
834f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
83525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns the name of the function associated with this stack frame.
83625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
83725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  Local<String> GetFunctionName() const;
83825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
83925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
84025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns whether or not the associated function is compiled via a call to
84125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * eval().
84225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
84325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  bool IsEval() const;
84425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
84525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  /**
84625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * Returns whther or not the associated function is called as a
84725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   * constructor via "new".
84825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen   */
84925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  bool IsConstructor() const;
850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- V a l u e ---
854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of all JavaScript values and objects.
858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
8598defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Value : public Data {
860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is the undefined value.  See ECMA-262
864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 4.3.10.
865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsUndefined() const;
867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is the null value.  See ECMA-262
870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 4.3.11.
871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8728defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsNull() const;
873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   /**
875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is true.
876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8778defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsTrue() const;
878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is false.
881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8828defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsFalse() const;
883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an instance of the String type.
886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ECMA-262 8.4.
887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsString() const;
889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a function.
892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8938defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsFunction() const;
894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an array.
897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
8988defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsArray() const;
899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is an object.
902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9038defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsObject() const;
904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is boolean.
907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsBoolean() const;
909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a number.
912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9138defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsNumber() const;
914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is external.
917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9188defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternal() const;
919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a 32-bit signed integer.
922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9238defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsInt32() const;
924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
9266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Returns true if this value is a 32-bit unsigned integer.
9276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
9288defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsUint32() const;
9296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
9306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this value is a Date.
932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9338defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsDate() const;
934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
935756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  /**
936756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   * Returns true if this value is a RegExp.
937756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   */
938756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V8EXPORT bool IsRegExp() const;
939756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
9408defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Boolean> ToBoolean() const;
9418defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Number> ToNumber() const;
9428defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ToString() const;
9438defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ToDetailString() const;
9448defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> ToObject() const;
9458defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Integer> ToInteger() const;
9468defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Uint32> ToUint32() const;
9478defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Int32> ToInt32() const;
948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Attempts to convert a string to an array index.
951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns an empty handle if the conversion fails.
952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9538defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Uint32> ToArrayIndex() const;
954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
9558defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool BooleanValue() const;
9568defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double NumberValue() const;
9578defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int64_t IntegerValue() const;
9588defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Uint32Value() const;
9598defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int32_t Int32Value() const;
960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** JS == */
9628defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Equals(Handle<Value> that) const;
9638defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool StrictEquals(Handle<Value> that) const;
9643ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool QuickIsString() const;
9678defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool FullIsString() const;
968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of primitive values.  See ECMA-262 4.3.2.
973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
9748defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Primitive : public Value { };
975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A primitive boolean value (ECMA-262, 4.3.14).  Either the true
979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * or false value.
980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
9818defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Boolean : public Primitive {
982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
9838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Value() const;
984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Handle<Boolean> New(bool value);
985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript string value (ECMA-262, 4.3.17).
990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
9918defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass String : public Primitive {
992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number of characters in this string.
996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
9978defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Length() const;
998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the number of bytes in the UTF-8 encoded
1001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * representation of this string.
1002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10038defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Utf8Length() const;
1004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Write the contents of the string to an external buffer.
1007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If no arguments are given, expects the buffer to be large
1008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enough to hold the entire string and NULL terminator. Copies
1009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the contents of the string and the NULL terminator into the
1010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer.
1011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
1012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Copies up to length characters into the output buffer.
1013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Only null-terminates if there is enough space in the buffer.
1014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
1015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param buffer The buffer into which the string will be copied.
1016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param start The starting position within the string at which
1017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * copying begins.
1018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param length The number of bytes to copy from the string.
10196ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param nchars_ref The number of characters written, can be NULL.
10206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \param hints Various hints that might affect performance of this or
10216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *    subsequent operations.
10226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * \return The number of bytes copied to the buffer
1023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * excluding the NULL terminator.
1024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  enum WriteHints {
10266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    NO_HINTS = 0,
10276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    HINT_MANY_WRITES_EXPECTED = 1
10286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  };
10296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
10308defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int Write(uint16_t* buffer,
10318defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     int start = 0,
10328defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     int length = -1,
10338defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     WriteHints hints = NO_HINTS) const;  // UTF-16
10348defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int WriteAscii(char* buffer,
10358defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          int start = 0,
10368defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          int length = -1,
10378defd9ff6930b4e24729971a61cf7469daf119beSteve Block                          WriteHints hints = NO_HINTS) const;  // ASCII
10388defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int WriteUtf8(char* buffer,
10398defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         int length = -1,
10408defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         int* nchars_ref = NULL,
10418defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         WriteHints hints = NO_HINTS) const;  // UTF-8
1042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A zero length string.
1045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10468defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static v8::Local<v8::String> Empty();
1047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string is external
1050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10518defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternal() const;
1052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string is both external and ascii
1055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
10568defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsExternalAscii() const;
1057e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
1058e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  class V8EXPORT ExternalStringResourceBase {
1059e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   public:
1060e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    virtual ~ExternalStringResourceBase() {}
10617f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1062e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   protected:
1063e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    ExternalStringResourceBase() {}
10647f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
10657f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
10667f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * Internally V8 will call this Dispose method when the external string
10677f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * resource is no longer needed. The default implementation will use the
10687f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * delete operator. This method can be overridden in subclasses to
10697f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * control how allocated external string resources are disposed.
10707f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
10717f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    virtual void Dispose() { delete this; }
10727f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1073e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke   private:
1074e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    // Disallow copying and assigning.
1075e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    ExternalStringResourceBase(const ExternalStringResourceBase&);
1076e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    void operator=(const ExternalStringResourceBase&);
10777f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
10787f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    friend class v8::internal::Heap;
1079e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  };
1080e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
1081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * An ExternalStringResource is a wrapper around a two-byte string
1083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer that resides outside V8's heap. Implement an
1084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ExternalStringResource to manage the life cycle of the underlying
1085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * buffer.  Note that the string data must be immutable.
1086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1087e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  class V8EXPORT ExternalStringResource
1088e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      : public ExternalStringResourceBase {
1089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
1091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Override the destructor to manage the life cycle of the underlying
1092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * buffer.
1093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
1094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~ExternalStringResource() {}
10957f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
10967f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
10977f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * The string data from the underlying buffer.
10987f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
1099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual const uint16_t* data() const = 0;
11007f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
11017f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    /**
11027f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     * The length of the string. That is, the number of two-byte characters.
11037f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch     */
1104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual size_t length() const = 0;
11057f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
1106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   protected:
1107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalStringResource() {}
1108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * An ExternalAsciiStringResource is a wrapper around an ascii
1112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * string buffer that resides outside V8's heap. Implement an
1113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ExternalAsciiStringResource to manage the life cycle of the
1114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * underlying buffer.  Note that the string data must be immutable
1115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * and that the data must be strict 7-bit ASCII, not Latin1 or
1116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * UTF-8, which would require special treatment internally in the
1117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * engine and, in the case of UTF-8, do not allow efficient indexing.
1118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Use String::New or convert to 16 bit data for non-ASCII.
1119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1121e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  class V8EXPORT ExternalAsciiStringResource
1122e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      : public ExternalStringResourceBase {
1123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /**
1125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * Override the destructor to manage the life cycle of the underlying
1126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     * buffer.
1127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block     */
1128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual ~ExternalAsciiStringResource() {}
1129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /** The string data from the underlying buffer.*/
1130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual const char* data() const = 0;
1131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    /** The number of ascii characters in the string.*/
1132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    virtual size_t length() const = 0;
1133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   protected:
1134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalAsciiStringResource() {}
1135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the ExternalStringResource for an external string.  Returns
1139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * NULL if IsExternal() doesn't return true.
1140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline ExternalStringResource* GetExternalStringResource() const;
1142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the ExternalAsciiStringResource for an external ascii string.
1145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns NULL if IsExternalAscii() doesn't return true.
1146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11478defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
1148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline String* Cast(v8::Value* obj);
1150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Allocates a new string from either utf-8 encoded or ascii data.
1153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The second parameter 'length' gives the buffer length.
1154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If the data is utf-8 encoded, the caller must
1155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be careful to supply the length parameter.
1156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If it is not given, the function calls
1157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * 'strlen' to determine the buffer length, it might be
1158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * wrong if 'data' contains a null character.
1159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> New(const char* data, int length = -1);
1161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Allocates a new string from utf16 data.*/
11638defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> New(const uint16_t* data, int length = -1);
1164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a symbol. Returns one if it exists already.*/
11668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1);
1167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
11693ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Creates a new string by concatenating the left and the right strings
11703ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * passed in as parameters.
11713ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
11728defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> Concat(Handle<String> left,
11738defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                       Handle<String>right);
11743ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
11753ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
1176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new external string using the data defined in the given
11777f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource. When the external string is no longer live on V8's heap the
11787f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource will be disposed by calling its Dispose method. The caller of
11797f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * this function should not otherwise delete or modify the resource. Neither
11807f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * should the underlying buffer be deallocated or modified except through the
11817f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * destructor of the external string resource.
1182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource);
1184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an external string resource with this string by transforming it
1187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in place so that existing references to this string in the JavaScript heap
1188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * will use the external string resource. The external string resource's
1189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * character contents needs to be equivalent to this string.
1190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string has been changed to be an external string.
11917f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * The string is not modified if the operation fails. See NewExternal for
11927f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * information on the lifetime of the resource.
1193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
11948defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool MakeExternal(ExternalStringResource* resource);
1195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new external string using the ascii data defined in the given
11987f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource. When the external string is no longer live on V8's heap the
11997f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * resource will be disposed by calling its Dispose method. The caller of
12007f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * this function should not otherwise delete or modify the resource. Neither
12017f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * should the underlying buffer be deallocated or modified except through the
12027f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * destructor of the external string resource.
1203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12048defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewExternal(
12058defd9ff6930b4e24729971a61cf7469daf119beSteve Block      ExternalAsciiStringResource* resource);
1206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an external string resource with this string by transforming it
1209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in place so that existing references to this string in the JavaScript heap
1210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * will use the external string resource. The external string resource's
1211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * character contents needs to be equivalent to this string.
1212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the string has been changed to be an external string.
12137f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * The string is not modified if the operation fails. See NewExternal for
12147f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch   * information on the lifetime of the resource.
1215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12168defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
1217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this string can be made external.
1220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
12218defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool CanMakeExternal();
1222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates an undetectable string from the supplied ascii or utf-8 data.*/
12248defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewUndetectable(const char* data,
12258defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                                int length = -1);
1226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates an undetectable string from the supplied utf-16 data.*/
12288defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
12298defd9ff6930b4e24729971a61cf7469daf119beSteve Block                                                int length = -1);
1230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Converts an object to a utf8-encoded character array.  Useful if
1233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * you want to print the object.  If conversion to a string fails
1234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * (eg. due to an exception in the toString() method of the object)
1235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * then the length() method returns 0 and the * operator returns
1236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * NULL.
1237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Utf8Value {
1239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit Utf8Value(Handle<v8::Value> obj);
1241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~Utf8Value();
1242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* operator*() { return str_; }
1243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const char* operator*() const { return str_; }
1244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* str_;
1247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Utf8Value(const Utf8Value&);
1251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const Utf8Value&);
1252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Converts an object to an ascii string.
1256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Useful if you want to print the object.
1257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If conversion to a string fails (eg. due to an exception in the toString()
1258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * method of the object) then the length() method returns 0 and the * operator
1259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * returns NULL.
1260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT AsciiValue {
1262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit AsciiValue(Handle<v8::Value> obj);
1264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~AsciiValue();
1265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* operator*() { return str_; }
1266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const char* operator*() const { return str_; }
1267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    char* str_;
1270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    AsciiValue(const AsciiValue&);
1274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const AsciiValue&);
1275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Converts an object to a two-byte string.
1279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If conversion to a string fails (eg. due to an exception in the toString()
1280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * method of the object) then the length() method returns 0 and the * operator
1281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * returns NULL.
1282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class V8EXPORT Value {
1284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit Value(Handle<v8::Value> obj);
1286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ~Value();
1287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint16_t* operator*() { return str_; }
1288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    const uint16_t* operator*() const { return str_; }
1289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length() const { return length_; }
1290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
1291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint16_t* str_;
1292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int length_;
1293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Disallow copying and assigning.
1295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Value(const Value&);
1296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void operator=(const Value&);
1297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
12983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13008defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const;
13018defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript number value (ECMA-262, 4.3.20)
1307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13088defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Number : public Primitive {
1309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13108defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double Value() const;
13118defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Number> New(double value);
1312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Number* Cast(v8::Value* obj);
1313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13148defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Number();
1315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void CheckCast(v8::Value* obj);
1316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a signed integer.
1321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13228defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Integer : public Number {
1323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13248defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Integer> New(int32_t value);
13258defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value);
13268defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int64_t Value() const;
1327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Integer* Cast(v8::Value* obj);
1328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13298defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Integer();
13308defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit signed integer.
1336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13378defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Int32 : public Integer {
1338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13398defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int32_t Value() const;
1340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13418defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Int32();
1342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit unsigned integer.
1347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13488defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Uint32 : public Integer {
1349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13508defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Value() const;
1351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13528defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Uint32();
1353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An instance of the built-in Date constructor (ECMA-262, 15.9).
1358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
13598defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Date : public Value {
1360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
13618defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Value> New(double time);
1362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A specialization of Value::NumberValue that is more efficient
1365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * because we know the structure of this object.
1366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
13678defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT double NumberValue() const;
1368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Date* Cast(v8::Value* obj);
1370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
13718defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1375f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch/**
1376f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
1377f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch */
1378f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdochclass RegExp : public Value {
1379f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch public:
1380f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1381f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Regular expression flag bits. They can be or'ed to enable a set
1382f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * of flags.
1383f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1384f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  enum Flags {
1385f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kNone = 0,
1386f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kGlobal = 1,
1387f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kIgnoreCase = 2,
1388f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch    kMultiline = 4
1389f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  };
1390f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1391f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1392f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Creates a regular expression from the given pattern string and
1393f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * the flags bit field. May throw a JavaScript exception as
1394f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * described in ECMA-262, 15.10.4.1.
1395f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   *
1396f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * For example,
1397f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   *   RegExp::New(v8::String::New("foo"),
1398f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   *               static_cast<RegExp::Flags>(kGlobal | kMultiline))
1399f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * is equivalent to evaluating "/foo/gm".
1400f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1401f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT static Local<RegExp> New(Handle<String> pattern,
1402f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch                                    Flags flags);
1403f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1404f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1405f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Returns the value of the source property: a string representing
1406f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * the regular expression.
1407f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1408f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT Local<String> GetSource() const;
1409f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1410f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  /**
1411f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   * Returns the flags bit field.
1412f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch   */
1413f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT Flags GetFlags() const;
1414f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1415f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  static inline RegExp* Cast(v8::Value* obj);
1416f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1417f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch private:
1418f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  V8EXPORT static void CheckCast(v8::Value* obj);
1419f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch};
1420f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1421f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
1422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum PropertyAttribute {
1423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  None       = 0,
1424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ReadOnly   = 1 << 0,
1425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DontEnum   = 1 << 1,
1426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DontDelete = 1 << 2
1427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14293ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockenum ExternalArrayType {
14303ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalByteArray = 1,
14313ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedByteArray,
14323ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalShortArray,
14333ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedShortArray,
14343ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalIntArray,
14353ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalUnsignedIntArray,
14363ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  kExternalFloatArray
14373ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
14383ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1440f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Accessor[Getter|Setter] are used as callback functions when
1441f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * setting|getting a particular property. See Object and ObjectTemplate's
1442f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * method SetAccessor.
1443f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */
1444f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef Handle<Value> (*AccessorGetter)(Local<String> property,
1445f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                                        const AccessorInfo& info);
1446f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1447f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1448f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef void (*AccessorSetter)(Local<String> property,
1449f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                               Local<Value> value,
1450f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke                               const AccessorInfo& info);
1451f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1452f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1453f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/**
1454f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Access control specifications.
1455f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke *
1456f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Some accessors should be accessible across contexts.  These
1457f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors have an explicit access control parameter which specifies
1458f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * the kind of cross-context access that should be allowed.
1459f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke *
1460f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Additionally, for security, accessors can prohibit overwriting by
1461f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors defined in JavaScript.  For objects that have such
1462f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors either locally or in their prototype chain it is not
1463f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * possible to overwrite the accessor by using __defineGetter__ or
1464f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * __defineSetter__ from JavaScript code.
1465f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */
1466f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeenum AccessControl {
1467f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  DEFAULT               = 0,
1468f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  ALL_CAN_READ          = 1,
1469f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  ALL_CAN_WRITE         = 1 << 1,
1470f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  PROHIBITS_OVERWRITING = 1 << 2
1471f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke};
1472f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1473f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1474f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/**
1475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript object (ECMA-262, 4.3.3)
1476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
14778defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Object : public Value {
1478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
14798defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Set(Handle<Value> key,
14808defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    Handle<Value> value,
14818defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    PropertyAttribute attribs = None);
1482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14838defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Set(uint32_t index,
14848defd9ff6930b4e24729971a61cf7469daf119beSteve Block                    Handle<Value> value);
14856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets a local property on this object bypassing interceptors and
1487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // overriding accessors or read-only properties.
1488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
1489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Note that if the object has an interceptor the property will be set
1490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // locally, but since the interceptor takes precedence the local property
1491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // will only be returned if the interceptor doesn't return a value.
1492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
1493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Note also that this only works for named properties.
14948defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool ForceSet(Handle<Value> key,
14958defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         Handle<Value> value,
14968defd9ff6930b4e24729971a61cf7469daf119beSteve Block                         PropertyAttribute attribs = None);
1497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14988defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Get(Handle<Value> key);
1499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15008defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Get(uint32_t index);
15016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // TODO(1245389): Replace the type-specific versions of these
1503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // functions with generic ones that accept a Handle<Value> key.
15048defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Has(Handle<String> key);
1505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15068defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Delete(Handle<String> key);
1507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Delete a property on this object bypassing interceptors and
1509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ignoring dont-delete attributes.
15108defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool ForceDelete(Handle<Value> key);
1511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15128defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Has(uint32_t index);
1513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15148defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool Delete(uint32_t index);
1515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15168defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetAccessor(Handle<String> name,
15178defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessorGetter getter,
15188defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessorSetter setter = 0,
15198defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            Handle<Value> data = Handle<Value>(),
15208defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            AccessControl settings = DEFAULT,
15218defd9ff6930b4e24729971a61cf7469daf119beSteve Block                            PropertyAttribute attribute = None);
1522f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns an array containing the names of the enumerable properties
1525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * of this object, including properties from prototype objects.  The
1526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * array returned by this method contains the same values as would
1527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be enumerated by a for-in statement over this object.
1528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15298defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Array> GetPropertyNames();
1530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Get the prototype object.  This does not skip objects marked to
1533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be skipped by __proto__ and it does not consult the security
1534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler.
1535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15368defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetPrototype();
1537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1539402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Set the prototype object.  This does not skip objects marked to
1540402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * be skipped by __proto__ and it does not consult the security
1541402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * handler.
1542402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
15438defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetPrototype(Handle<Value> prototype);
1544402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
1545402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
1546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Finds an instance of the given function template in the prototype
1547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * chain.
1548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15498defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> FindInstanceInPrototypeChain(
15508defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<FunctionTemplate> tmpl);
1551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Call builtin Object.prototype.toString on this object.
1554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This is different from Value::ToString() that may call
1555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * user-defined toString function. This one does not.
1556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15578defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<String> ObjectProtoToString();
1558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets the number of internal fields for this Object. */
15608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int InternalFieldCount();
1561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets the value in an internal field. */
1562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> GetInternalField(int index);
1563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Sets the value in an internal field. */
15648defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetInternalField(int index, Handle<Value> value);
1565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Gets a native pointer from an internal field. */
1567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void* GetPointerFromInternalField(int index);
15683ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Sets a native pointer in an internal field. */
15708defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetPointerInInternalField(int index, void* value);
1571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Testers for local properties.
15738defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealNamedProperty(Handle<String> key);
15748defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealIndexedProperty(uint32_t index);
15758defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key);
1576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If result.IsEmpty() no real property was located in the prototype chain.
1579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means interceptors in the prototype chain are not called.
1580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15818defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain(
15828defd9ff6930b4e24729971a61cf7469daf119beSteve Block      Handle<String> key);
1583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If result.IsEmpty() no real property was located on the object or
1586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * in the prototype chain.
1587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means interceptors in the prototype chain are not called.
1588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
15898defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key);
1590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Tests for a named lookup interceptor.*/
15928defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasNamedLookupInterceptor();
1593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Tests for an index lookup interceptor.*/
15958defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool HasIndexedLookupInterceptor();
1596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Turns on access check on the object if the object is an instance of
1599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a template that has access check callbacks. If an object has no
1600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * access check info, the object cannot be accessed by anyone.
1601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16028defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void TurnOnAccessCheck();
1603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the identity hash for this object. The current implemenation uses
1606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a hidden property on the object to store the identity hash.
1607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
1608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The return value will never be 0. Also, it is not guaranteed to be
1609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * unique.
1610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16118defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int GetIdentityHash();
1612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Access hidden properties on JavaScript objects. These properties are
1615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * hidden from the executing JavaScript and only accessible through the V8
1616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * C++ API. Hidden properties introduced by V8 internally (for example the
1617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * identity hash) are prefixed with "v8::".
1618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16198defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value);
16208defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> GetHiddenValue(Handle<String> key);
16218defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool DeleteHiddenValue(Handle<String> key);
16223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
1623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if this is an instance of an api function (one
1625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * created from a function created from a function template) and has
1626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been modified since it was created.  Note that this method is
1627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * conservative and may return true for objects that haven't actually
1628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been modified.
1629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16308defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT bool IsDirty();
1631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clone this object with a fast but shallow copy.  Values will point
1634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to the same values as the original object.
1635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16368defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> Clone();
1637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the backing store of the indexed properties to be managed by the
1640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * embedding layer. Access to the indexed properties will follow the rules
1641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * spelled out in CanvasPixelArray.
1642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Note: The embedding program still owns the data and needs to ensure that
1643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *       the backing store is preserved while V8 has a reference.
1644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16458defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
16469dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  bool HasIndexedPropertiesInPixelData();
16479dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  uint8_t* GetIndexedPropertiesPixelData();
16489dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  int GetIndexedPropertiesPixelDataLength();
1649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
16503ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
16513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Set the backing store of the indexed properties to be managed by the
16523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * embedding layer. Access to the indexed properties will follow the rules
16533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * spelled out for the CanvasArray subtypes in the WebGL specification.
16543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Note: The embedding program still owns the data and needs to ensure that
16553ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   *       the backing store is preserved while V8 has a reference.
16563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
16578defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetIndexedPropertiesToExternalArrayData(
16588defd9ff6930b4e24729971a61cf7469daf119beSteve Block      void* data,
16598defd9ff6930b4e24729971a61cf7469daf119beSteve Block      ExternalArrayType array_type,
16608defd9ff6930b4e24729971a61cf7469daf119beSteve Block      int number_of_elements);
16619dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  bool HasIndexedPropertiesInExternalArrayData();
16629dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  void* GetIndexedPropertiesExternalArrayData();
16639dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
16649dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  int GetIndexedPropertiesExternalArrayDataLength();
16653ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
16668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Object> New();
1667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Object* Cast(Value* obj);
1668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
16698defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Object();
16708defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(Value* obj);
16718defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> CheckedGetInternalField(int index);
16728defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void* SlowGetPointerFromInternalField(int index);
1673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If quick access to the internal field is possible this method
16763ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * returns the value.  Otherwise an empty handle is returned.
1677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
1678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> UncheckedGetInternalField(int index);
1679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An instance of the built-in array constructor (ECMA-262, 15.4.2).
1684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
16858defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Array : public Object {
1686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
16878defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT uint32_t Length() const;
1688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
1690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clones an element at index |index|.  Returns an empty
1691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handle if cloning fails (for any reason).
1692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
16938defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> CloneElementAt(uint32_t index);
1694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
16958defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Array> New(int length = 0);
1696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Array* Cast(Value* obj);
1697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
16988defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Array();
1699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void CheckCast(Value* obj);
1700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript function object (ECMA-262, 15.3).
1705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
17068defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Function : public Object {
1707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
17088defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> NewInstance() const;
17098defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
17108defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Local<Value> Call(Handle<Object> recv,
17118defd9ff6930b4e24729971a61cf7469daf119beSteve Block                             int argc,
17128defd9ff6930b4e24729971a61cf7469daf119beSteve Block                             Handle<Value> argv[]);
17138defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void SetName(Handle<String> name);
17148defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Handle<Value> GetName() const;
1715402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
1716402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  /**
1717402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Returns zero based line number of function body and
1718402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * kLineOffsetNotFound if no information available.
1719402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   */
17208defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT int GetScriptLineNumber() const;
17218defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT ScriptOrigin GetScriptOrigin() const;
1722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Function* Cast(Value* obj);
17238defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static const int kLineOffsetNotFound;
1724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
17258defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT Function();
17268defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(Value* obj);
1727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value that wraps a C++ void*.  This type of value is
1732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * mainly used to associate C++ data structures with JavaScript
1733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects.
1734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Wrap function V8 will return the most optimal Value object wrapping the
1736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * C++ void*. The type of the value is not guaranteed to be an External object
1737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and no assumptions about its type should be made. To access the wrapped
1738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * value Unwrap should be used, all other operations on that object will lead
1739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to unpredictable results.
1740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
17418defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass External : public Value {
1742a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
17438defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<Value> Wrap(void* data);
1744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void* Unwrap(Handle<Value> obj);
1745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
17468defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static Local<External> New(void* value);
1747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline External* Cast(Value* obj);
17488defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT void* Value() const;
1749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
17508defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT External();
17518defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void CheckCast(v8::Value* obj);
1752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void* QuickUnwrap(Handle<v8::Value> obj);
17538defd9ff6930b4e24729971a61cf7469daf119beSteve Block  V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
1754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1755a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1756a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- T e m p l a t e s ---
1758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of object and function templates.
1762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Template : public Data {
1764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Adds a property to each instance created by this template.*/
1766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Set(Handle<String> name, Handle<Data> value,
1767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block           PropertyAttribute attributes = None);
1768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Set(const char* name, Handle<Data> value);
1769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Template();
1771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1772a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
1773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class FunctionTemplate;
1774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The argument information given to function call callbacks.  This
1779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * class provides access to information about the context of the call,
1780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * including the receiver, the number and values of arguments, and
1781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the holder of the function.
1782a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
17838defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Arguments {
1784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int Length() const;
1786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> operator[](int i) const;
1787a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Function> Callee() const;
1788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> This() const;
1789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> Holder() const;
1790a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsConstructCall() const;
1791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> Data() const;
1792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
1794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Arguments(Local<Value> data,
1795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   Local<Object> holder,
1796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   Local<Function> callee,
1797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   bool is_construct_call,
1798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   void** values, int length);
1799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> data_;
1800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Object> holder_;
1801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Function> callee_;
1802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_construct_call_;
1803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void** values_;
1804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int length_;
1805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The information passed to an accessor callback about the context
1810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * of the property access.
1811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT AccessorInfo {
1813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline AccessorInfo(internal::Object** args)
1815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : args_(args) { }
1816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Value> Data() const;
1817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> This() const;
1818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Local<Object> Holder() const;
1819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** args_;
1821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*InvocationCallback)(const Arguments& args);
1825a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1826a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1827a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * NamedProperty[Getter|Setter] are used as interceptors on object.
1828a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ObjectTemplate::SetNamedPropertyHandler.
1829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
1831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             const AccessorInfo& info);
1832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request.
1836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle.
1837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
1839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             Local<Value> value,
1840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                             const AccessorInfo& info);
1841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request.
18449dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * The result is an integer encoding property attributes (like v8::None,
18459dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * v8::DontEnum, etc.)
1846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
18477f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochtypedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
18487f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch                                              const AccessorInfo& info);
1849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request.
1853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false
1854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise.
1855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
1857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                const AccessorInfo& info);
1858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the names of the properties the named
1861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property getter intercepts.
1862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
1864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value of the property if the getter intercepts the
1868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * request.  Otherwise, returns an empty handle.
1869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
1871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               const AccessorInfo& info);
1872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request.
1876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle.
1877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
1879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               Local<Value> value,
1880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               const AccessorInfo& info);
1881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request.
1885756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick * The result is an integer encoding property attributes.
1886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1887756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merricktypedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
1888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                const AccessorInfo& info);
1889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request.
1892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false
1893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise.
1894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
1896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                  const AccessorInfo& info);
1897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the indices of the properties the
1900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * indexed property getter intercepts.
1901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
1903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Access type specification.
1907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum AccessType {
1909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_GET,
1910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_SET,
1911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_HAS,
1912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_DELETE,
1913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_KEYS
1914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the named
1919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given key on the host object.
1920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*NamedSecurityCallback)(Local<Object> host,
1922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      Local<Value> key,
1923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      AccessType type,
1924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      Local<Value> data);
1925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the indexed
1929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given index on the host object.
1930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
1931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*IndexedSecurityCallback)(Local<Object> host,
1932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        uint32_t index,
1933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        AccessType type,
1934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        Local<Value> data);
1935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
1938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate is used to create functions at runtime. There
1939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * can only be one function created from a FunctionTemplate in a
1940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * context.  The lifetime of the created function is equal to the
1941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * lifetime of the context.  So in case the embedder needs to create
1942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * temporary functions that can be collected using Scripts is
1943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * preferred.
1944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have properties, these properties are added to the
1946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function object when it is created.
1947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate has a corresponding instance template which is
1949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * used to create object instances when the function is used as a
1950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor. Properties added to the instance template are added to
1951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * each object instance.
1952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have a prototype template. The prototype template
1954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is used to create the prototype object of the function.
1955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The following example shows how to use a FunctionTemplate:
1957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
1959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
1960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    t->Set("func_property", v8::Number::New(1));
1961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
1963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
1964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    proto_t->Set("proto_const", v8::Number::New(2));
1965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
1967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
1968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
1969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    instance_t->Set("instance_property", Number::New(3));
1970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Function> function = t->GetFunction();
1972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *    v8::Local<v8::Object> instance = function->NewInstance();
1973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
1974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let's use "function" as the JS variable name of the function object
1976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and "instance" for the instance object created above.  The function
1977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and the instance will have the following properties:
1978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
1980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   func_property in function == true;
1981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.func_property == 1;
1982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.prototype.proto_method() invokes 'InvokeCallback'
1984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   function.prototype.proto_const == 2;
1985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance instanceof function == true;
1987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance.instance_accessor calls 'InstanceAccessorCallback'
1988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   instance.instance_property == 3;
1989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
1990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can inherit from another one by calling the
1992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate::Inherit method.  The following graph illustrates
1993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the semantics of inheritance:
1994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
1995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
1996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   FunctionTemplate Parent  -> Parent() . prototype -> { }
1997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     ^                                                  ^
1998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     | Inherit(Parent)                                  | .__proto__
1999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     |                                                  |
2000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   FunctionTemplate Child   -> Child()  . prototype -> { }
2001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
2004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * object of the Child() function has __proto__ pointing to the
2005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Parent() function's prototype object. An instance of the Child
2006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function has all properties on Parent's instance templates.
2007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let Parent be the FunctionTemplate initialized in the previous
2009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * section and create a Child FunctionTemplate by:
2010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<FunctionTemplate> parent = t;
2013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<FunctionTemplate> child = FunctionTemplate::New();
2014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child->Inherit(parent);
2015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<Function> child_function = child->GetFunction();
2017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   Local<Object> child_instance = child_function->NewInstance();
2018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Child function and Child instance will have the following
2021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * properties:
2022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
2024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_func.prototype.__proto__ == function.prototype;
2025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_instance.instance_accessor calls 'InstanceAccessorCallback'
2026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   child_instance.instance_property == 3;
2027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
2028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT FunctionTemplate : public Template {
2030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a function template.*/
2032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<FunctionTemplate> New(
2033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      InvocationCallback callback = 0,
2034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Value> data = Handle<Value>(),
2035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Signature> signature = Handle<Signature>());
2036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the unique function instance in the current execution context.*/
2037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Function> GetFunction();
2038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the call-handler callback for a FunctionTemplate.  This
2041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback is called whenever the function created from this
2042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * FunctionTemplate is called.
2043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCallHandler(InvocationCallback callback,
2045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                      Handle<Value> data = Handle<Value>());
2046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Get the InstanceTemplate. */
2048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<ObjectTemplate> InstanceTemplate();
2049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Causes the function template to inherit from a parent function template.*/
2051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Inherit(Handle<FunctionTemplate> parent);
2052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * A PrototypeTemplate is the template used to create the prototype object
2055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * of the function created by this template.
2056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<ObjectTemplate> PrototypeTemplate();
2058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set the class name of the FunctionTemplate.  This is used for
2062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * printing objects created with the function created from the
2063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * FunctionTemplate as its constructor.
2064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetClassName(Handle<String> name);
2066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Determines whether the __proto__ accessor ignores instances of
2069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the function template.  If instances of the function template are
2070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * ignored, __proto__ skips all instances and instead returns the
2071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * next object in the prototype chain.
2072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Call with a value of true to make the __proto__ accessor ignore
2074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * instances of the function template.  Call with a value of false
2075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to make the __proto__ accessor not ignore instances of the
2076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function template.  By default, instances of a function template
2077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * are not ignored.
2078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetHiddenPrototype(bool value);
2080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the given object is an instance of this function
2083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * template.
2084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasInstance(Handle<Value> object);
2086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  FunctionTemplate();
2089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void AddInstancePropertyAccessor(Handle<String> name,
2090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessorGetter getter,
2091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessorSetter setter,
2092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   Handle<Value> data,
2093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   AccessControl settings,
2094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                   PropertyAttribute attributes);
2095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
2096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertySetter setter,
2097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyQuery query,
2098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyDeleter remover,
2099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       NamedPropertyEnumerator enumerator,
21009dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen                                       Handle<Value> data);
2101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
2102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertySetter setter,
2103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyQuery query,
2104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyDeleter remover,
2105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         IndexedPropertyEnumerator enumerator,
2106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         Handle<Value> data);
2107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
2108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        Handle<Value> data);
2109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Context;
2111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ObjectTemplate;
2112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An ObjectTemplate is used to create objects at runtime.
2117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Properties added to an ObjectTemplate are added to each object
2119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * created from the ObjectTemplate.
2120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ObjectTemplate : public Template {
2122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates an ObjectTemplate. */
2124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<ObjectTemplate> New();
2125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Creates a new instance of this template.*/
2127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Object> NewInstance();
2128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets an accessor on the object template.
2131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever the property with the given name is accessed on objects
2133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * created from this ObjectTemplate the getter and setter callbacks
2134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * are called instead of getting and setting the property directly
2135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * on the JavaScript object.
2136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param name The name of the property for which an accessor is added.
2138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting the property.
2139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting the property.
2140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the getter and setter
2141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   callbacks whenever they are invoked.
2142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param settings Access control settings for the accessor. This is a bit
2143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   field consisting of one of more of
2144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
2145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   The default is to not allow cross-context access.
2146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   ALL_CAN_READ means that all cross-context reads are allowed.
2147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   ALL_CAN_WRITE means that all cross-context writes are allowed.
2148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
2149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   cross-context access.
2150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param attribute The attributes of the property for which an accessor
2151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   is added.
2152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetAccessor(Handle<String> name,
2154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessorGetter getter,
2155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessorSetter setter = 0,
2156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   Handle<Value> data = Handle<Value>(),
2157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   AccessControl settings = DEFAULT,
2158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                   PropertyAttribute attribute = None);
2159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets a named property handler on the object template.
2162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever a named property is accessed on objects created from
2164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this object template, the provided callback is invoked instead of
2165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * accessing the property directly on the JavaScript object.
2166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting a property.
2168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting a property.
21699dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen   * \param query The callback to invoke to check if a property is present,
21709dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen   *   and if present, get its attributes.
2171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param deleter The callback to invoke when deleting a property.
2172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param enumerator The callback to invoke to enumerate all the named
2173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   properties of an object.
2174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the callbacks
2175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   whenever they are invoked.
2176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNamedPropertyHandler(NamedPropertyGetter getter,
2178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertySetter setter = 0,
2179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyQuery query = 0,
2180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyDeleter deleter = 0,
2181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               NamedPropertyEnumerator enumerator = 0,
21829dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen                               Handle<Value> data = Handle<Value>());
2183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets an indexed property handler on the object template.
2186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Whenever an indexed property is accessed on objects created from
2188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this object template, the provided callback is invoked instead of
2189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * accessing the property directly on the JavaScript object.
2190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param getter The callback to invoke when getting a property.
2192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param setter The callback to invoke when setting a property.
2193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param query The callback to invoke to check is an object has a property.
2194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param deleter The callback to invoke when deleting a property.
2195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param enumerator The callback to invoke to enumerate all the indexed
2196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   properties of an object.
2197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param data A piece of data that will be passed to the callbacks
2198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   whenever they are invoked.
2199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
2201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertySetter setter = 0,
2202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyQuery query = 0,
2203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyDeleter deleter = 0,
2204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 IndexedPropertyEnumerator enumerator = 0,
2205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 Handle<Value> data = Handle<Value>());
2206756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
2207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the callback to be used when calling instances created from
2209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template as a function.  If no callback is set, instances
2210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * behave like normal JavaScript objects that cannot be called as a
2211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function.
2212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCallAsFunctionHandler(InvocationCallback callback,
2214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                Handle<Value> data = Handle<Value>());
2215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Mark object instances of the template as undetectable.
2218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * In many ways, undetectable objects behave as though they are not
2220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * there.  They behave like 'undefined' in conditionals and when
2221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * printed.  However, properties can be accessed and called as on
2222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * normal objects.
2223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void MarkAsUndetectable();
2225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets access check callbacks on the object template.
2228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When accessing properties on instances of this object template,
2230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the access check callback will be called to determine whether or
2231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * not to allow cross-context access to the properties.
2232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The last parameter specifies whether access checks are turned
2233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * on by default on instances. If access checks are off by default,
2234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * they can be turned on on individual instances by calling
2235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Object::TurnOnAccessCheck().
2236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
2238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               IndexedSecurityCallback indexed_handler,
2239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               Handle<Value> data = Handle<Value>(),
2240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               bool turned_on_by_default = true);
2241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Gets the number of internal fields for objects generated from
2244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template.
2245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int InternalFieldCount();
2247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the number of internal fields for objects generated from
2250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * this template.
2251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetInternalFieldCount(int value);
2253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ObjectTemplate();
2256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
2257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class FunctionTemplate;
2258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A Signature specifies which receivers and arguments a function can
2263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * legally be called with.
2264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Signature : public Data {
2266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Signature> New(Handle<FunctionTemplate> receiver =
2268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  Handle<FunctionTemplate>(),
2269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              int argc = 0,
2270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              Handle<FunctionTemplate> argv[] = 0);
2271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Signature();
2273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A utility for determining the type of objects based on the template
2278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * they were constructed from.
2279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TypeSwitch : public Data {
2281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
2283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
2284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int match(Handle<Value> value);
2285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  TypeSwitch();
2287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- E x t e n s i o n s ---
2291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
2295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Extension {  // NOLINT
2297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Extension(const char* name,
2299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            const char* source = 0,
2300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            int dep_count = 0,
2301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            const char** deps = 0);
2302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~Extension() { }
2303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual v8::Handle<v8::FunctionTemplate>
2304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      GetNativeFunction(v8::Handle<v8::String> name) {
2305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return v8::Handle<v8::FunctionTemplate>();
2306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* name() { return name_; }
2309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* source() { return source_; }
2310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int dependency_count() { return dep_count_; }
2311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** dependencies() { return deps_; }
2312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_auto_enable(bool value) { auto_enable_ = value; }
2313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool auto_enable() { return auto_enable_; }
2314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* name_;
2317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* source_;
2318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int dep_count_;
2319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** deps_;
2320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool auto_enable_;
2321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Disallow copying and assigning.
2323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Extension(const Extension&);
2324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const Extension&);
2325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid V8EXPORT RegisterExtension(Extension* extension);
2329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
2333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT DeclareExtension {
2335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline DeclareExtension(Extension* extension) {
2337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    RegisterExtension(extension);
2338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- S t a t i c s ---
2343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Undefined();
2346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Null();
2347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT True();
2348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT False();
2349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A set of constraints that specifies the limits of the runtime's memory use.
2353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * You must set the heap size before initializing the VM - the size cannot be
2354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * adjusted after the VM is initialized.
2355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you are using threads then you should hold the V8::Locker lock while
2357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * setting the stack limit and you must set a non-default stack limit separately
2358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for each thread.
2359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ResourceConstraints {
2361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ResourceConstraints();
2363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_young_space_size() const { return max_young_space_size_; }
2364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_max_young_space_size(int value) { max_young_space_size_ = value; }
2365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_old_space_size() const { return max_old_space_size_; }
2366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_max_old_space_size(int value) { max_old_space_size_ = value; }
2367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t* stack_limit() const { return stack_limit_; }
2368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets an address beyond which the VM's stack may not grow.
2369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
2370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_young_space_size_;
2372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int max_old_space_size_;
2373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t* stack_limit_;
2374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
237725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenbool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints);
2378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- E x c e p t i o n s ---
2381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FatalErrorCallback)(const char* location, const char* message);
2384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
2387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Schedules an exception to be thrown when returning to JavaScript.  When an
2391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * exception has been scheduled it is illegal to invoke any JavaScript
2392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operation; the caller must return immediately and only after the exception
2393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * has been handled does it become legal to invoke JavaScript operations.
2394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> V8EXPORT ThrowException(Handle<Value> exception);
2396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Create new error objects by calling the corresponding error object
2399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor with the message.
2400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Exception {
2402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> RangeError(Handle<String> message);
2404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> ReferenceError(Handle<String> message);
2405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> SyntaxError(Handle<String> message);
2406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> TypeError(Handle<String> message);
2407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Value> Error(Handle<String> message);
2408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- C o u n t e r s  C a l l b a c k s ---
2412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int* (*CounterLookupCallback)(const char* name);
2414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void* (*CreateHistogramCallback)(const char* name,
2416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         int min,
2417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         int max,
2418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                         size_t buckets);
2419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
2421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
24229ac36c9faca11611ada13b4054edbaa0738661d0Iain 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 ---
24239ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  enum ObjectSpace {
24249ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceNewSpace = 1 << 0,
24259ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceOldPointerSpace = 1 << 1,
24269ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceOldDataSpace = 1 << 2,
24279ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceCodeSpace = 1 << 3,
24289ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceMapSpace = 1 << 4,
24299ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceLoSpace = 1 << 5,
24309ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
24319ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
24329ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick      kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
24339ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick      kObjectSpaceLoSpace
24349ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  };
24359ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
24369ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  enum AllocationAction {
24379ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionAllocate = 1 << 0,
24389ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionFree = 1 << 1,
24399ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick    kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
24409ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  };
24419ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
24429ac36c9faca11611ada13b4054edbaa0738661d0Iain Merricktypedef void (*MemoryAllocationCallback)(ObjectSpace space,
24439ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                         AllocationAction action,
24449ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                         int size);
24459ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
2446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve 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 ---
2447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FailedAccessCheckCallback)(Local<Object> target,
2448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          AccessType type,
2449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          Local<Value> data);
2450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve 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
2452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
24546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Applications can register callback functions which will be called
24556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * before and after a garbage collection.  Allocations are not
24566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * allowed in the callback functions, you therefore cannot manipulate
2457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects (set or delete properties for example) since it is possible
2458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * such operations will result in the allocation of objects.
2459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
24606ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCType {
24616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeScavenge = 1 << 0,
24626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeMarkSweepCompact = 1 << 1,
24636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
24646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
24656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
24666ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCCallbackFlags {
24676ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kNoGCCallbackFlags = 0,
24686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  kGCCallbackFlagCompacted = 1 << 0
24696ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
24706ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
24716ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
24726ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
24736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
2474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*GCCallback)();
2475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Profiler modules.
2479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
2480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * In V8, profiler consists of several modules: CPU profiler, and different
2481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * kinds of heap profiling. Each can be turned on / off independently.
2482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * When PROFILER_MODULE_HEAP_SNAPSHOT flag is passed to ResumeProfilerEx,
2483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * modules are enabled only temporarily for making a snapshot of the heap.
2484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum ProfilerModules {
2486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_NONE            = 0,
2487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_CPU             = 1,
2488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_HEAP_STATS      = 1 << 1,
2489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2,
2490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROFILER_MODULE_HEAP_SNAPSHOT   = 1 << 16
2491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
24953ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Collection of V8 heap information.
24963ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block *
24973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Instances of this class can be passed to v8::V8::HeapStatistics to
24983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * get heap statistics from V8.
24993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block */
25003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass V8EXPORT HeapStatistics {
25013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
25023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  HeapStatistics();
25033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t total_heap_size() { return total_heap_size_; }
25043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t used_heap_size() { return used_heap_size_; }
25053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
25073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void set_total_heap_size(size_t size) { total_heap_size_ = size; }
25083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void set_used_heap_size(size_t size) { used_heap_size_ = size; }
25093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t total_heap_size_;
25113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  size_t used_heap_size_;
25123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  friend class V8;
25143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
25153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
25173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block/**
2518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Container class for static utility functions.
2519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT V8 {
2521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Set the callback to invoke in case of fatal errors. */
2523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFatalErrorHandler(FatalErrorCallback that);
2524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Ignore out-of-memory exceptions.
2527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 running out of memory is treated as a fatal error by default.
2529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This means that the fatal error handler is called and that V8 is
2530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * terminated.
2531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * IgnoreOutOfMemoryException can be used to not treat a
2533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * out-of-memory situation as a fatal error.  This way, the contexts
2534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that did not cause the out of memory problem might be able to
2535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * continue execution.
2536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void IgnoreOutOfMemoryException();
2538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Check if V8 is dead and therefore unusable.  This is the case after
2541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * fatal errors such as out-of-memory situations.
2542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsDead();
2544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Adds a message listener.
2547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The same message listener can be added more than once and it that
2549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * case it will be called more than once for each message.
2550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool AddMessageListener(MessageCallback that,
2552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                 Handle<Value> data = Handle<Value>());
2553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Remove all message listeners from the specified callback function.
2556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void RemoveMessageListeners(MessageCallback that);
2558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
25603bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * Tells V8 to capture current stack trace when uncaught exception occurs
25613bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   * and report it to the message listeners. The option is off by default.
25623bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch   */
25633bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  static void SetCaptureStackTraceForUncaughtExceptions(
25643bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      bool capture,
25653bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      int frame_limit = 10,
25663bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch      StackTrace::StackTraceOptions options = StackTrace::kOverview);
25673bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
25683bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  /**
2569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets V8 flags from a string.
2570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFlagsFromString(const char* str, int length);
2572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets V8 flags from the command line.
2575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFlagsFromCommandLine(int* argc,
2577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      char** argv,
2578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                      bool remove_flags);
2579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Get the version string. */
2581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const char* GetVersion();
2582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to provide a mechanism for recording
2585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * statistics counters.
2586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetCounterFunction(CounterLookupCallback);
2588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to provide a mechanism for recording
2591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * histograms. The CreateHistogram function returns a
2592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * histogram which will later be passed to the AddHistogramSample
2593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function.
2594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetCreateHistogramFunction(CreateHistogramCallback);
2596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
2597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the computation of a sliding window of states. The sliding
2600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * window information is recorded in statistics counters.
2601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void EnableSlidingStateWindow();
2603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Callback function for reporting failed access checks.*/
2605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
2606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to receive a notification before a
26096ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
26106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * callback function, you therefore cannot manipulate objects (set
26116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * or delete properties for example) since it is possible such
26126ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * operations will result in the allocation of objects. It is possible
26136ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * to specify the GCType filter for your callback. But it is not possible to
26146ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * register the same callback function two times with different
26156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * GCType filters.
26166ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26176ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void AddGCPrologueCallback(
26186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
26196ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * This function removes callback which was installed by
26226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * AddGCPrologueCallback function.
26236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26246ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void RemoveGCPrologueCallback(GCPrologueCallback callback);
26256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The function is deprecated. Please use AddGCPrologueCallback instead.
26286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Enables the host application to receive a notification before a
26296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
2630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback function, you therefore cannot manipulate objects (set
2631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * or delete properties for example) since it is possible such
2632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations will result in the allocation of objects.
2633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetGlobalGCPrologueCallback(GCCallback);
2635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enables the host application to receive a notification after a
26386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * garbage collection.  Allocations are not allowed in the
26396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * callback function, you therefore cannot manipulate objects (set
26406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * or delete properties for example) since it is possible such
26416ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * operations will result in the allocation of objects. It is possible
26426ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * to specify the GCType filter for your callback. But it is not possible to
26436ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * register the same callback function two times with different
26446ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * GCType filters.
26456ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26466ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void AddGCEpilogueCallback(
26476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
26486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26496ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26506ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * This function removes callback which was installed by
26516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * AddGCEpilogueCallback function.
26526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
26536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
26546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
26556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
26566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The function is deprecated. Please use AddGCEpilogueCallback instead.
26576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Enables the host application to receive a notification after a
2658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * major garbage collection.  Allocations are not allowed in the
2659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * callback function, you therefore cannot manipulate objects (set
2660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * or delete properties for example) since it is possible such
2661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations will result in the allocation of objects.
2662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetGlobalGCEpilogueCallback(GCCallback);
2664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
26669ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * Enables the host application to provide a mechanism to be notified
26679ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * and perform custom logging when V8 Allocates Executable Memory.
26689ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   */
26699ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
26709ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                          ObjectSpace space,
26719ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick                                          AllocationAction action);
26729ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26739ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  /**
26749ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * This function removes callback which was installed by
26759ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   * AddMemoryAllocationCallback function.
26769ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick   */
26779ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
26789ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick
26799ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  /**
2680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Allows the host application to group objects together. If one
2681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * object in the group is alive, all objects in the group are alive.
2682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * After each garbage collection, object groups are removed. It is
2683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * intended to be used in the before-garbage-collection callback
2684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * function, for instance to simulate DOM tree connections among JS
2685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * wrapper objects.
2686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void AddObjectGroup(Persistent<Value>* objects, size_t length);
2688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Initializes from snapshot if possible. Otherwise, attempts to
2691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * initialize from scratch.  This function is called implicitly if
2692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * you use the API without calling it first.
2693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool Initialize();
2695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Adjusts the amount of registered external memory.  Used to give
2698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 an indication of the amount of externally allocated memory
2699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that is kept alive by JavaScript objects.  V8 uses this to decide
2700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * when to perform global garbage collections.  Registering
2701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * externally allocated memory will trigger global garbage
2702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * collections more often than otherwise in an attempt to garbage
2703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * collect the JavaScript objects keeping the externally allocated
2704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * memory alive.
2705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param change_in_bytes the change in externally allocated memory
2707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   that is kept alive by JavaScript objects.
2708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \returns the adjusted value.
2709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
2711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Suspends recording of tick samples in the profiler.
2714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When the V8 profiling mode is enabled (usually via command line
2715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * switches) this function suspends recording of tick samples.
2716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Profiling ticks are discarded until ResumeProfiler() is called.
2717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See also the --prof and --prof_auto command line switches to
2719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enable V8 profiling.
2720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void PauseProfiler();
2722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Resumes recording of tick samples in the profiler.
2725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See also PauseProfiler().
2726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ResumeProfiler();
2728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Return whether profiler is currently paused.
2731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsProfilerPaused();
2733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2735402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Resumes specified profiler modules. Can be called several times to
2736402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * mark the opening of a profiler events block with the given tag.
2737402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
2738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CPU)".
2739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ProfilerModules enum.
2740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2741a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param flags Flags specifying profiler modules.
2742402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param tag Profile tag.
2743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2744402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static void ResumeProfilerEx(int flags, int tag = 0);
2745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2747402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * Pauses specified profiler modules. Each call to "PauseProfilerEx" closes
2748402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * a block of profiler events opened by a call to "ResumeProfilerEx" with the
2749402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * same tag value. There is no need for blocks to be properly nested.
2750402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * The profiler is paused when the last opened block is closed.
2751402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   *
2752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)".
2753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ProfilerModules enum.
2754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2755a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param flags Flags specifying profiler modules.
2756402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu   * \param tag Profile tag.
2757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2758402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  static void PauseProfilerEx(int flags, int tag = 0);
2759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns active (resumed) profiler modules.
2762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * See ProfilerModules enum.
2763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \returns active profiler modules.
2765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int GetActiveProfilerModules();
2767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If logging is performed into a memory buffer (via --logfile=*), allows to
2770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * retrieve previously written messages. This can be used for retrieving
2771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * profiler log data in the application. This function is thread-safe.
2772a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Caller provides a destination buffer that must exist during GetLogLines
2774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * call. Only whole log lines are copied into the buffer.
2775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param from_pos specified a point in a buffer to read from, 0 is the
2777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   beginning of a buffer. It is assumed that caller updates its current
2778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *   position using returned size value from the previous call.
2779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param dest_buf destination buffer for log data.
2780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param max_size size of the destination buffer.
2781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \returns actual size of log data copied into buffer.
2782a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2783a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int GetLogLines(int from_pos, char* dest_buf, int max_size);
2784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
27866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * The minimum allowed size for a log lines buffer.  If the size of
27876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * the buffer given will not be enough to hold a line of the maximum
27886ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * length, an attempt to find a log line end in GetLogLines will
27896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * fail, and an empty result will be returned.
27906ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
27916ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kMinimumSizeForLogLinesBuffer = 2048;
27926ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
27936ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
2794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Retrieve the V8 thread id of the calling thread.
2795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The thread id for a thread should only be retrieved after the V8
2797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * lock has been acquired with a Locker object with that thread.
2798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int GetCurrentThreadId();
2800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Forcefully terminate execution of a JavaScript thread.  This can
2803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * be used to terminate long-running scripts.
2804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TerminateExecution should only be called when then V8 lock has
2806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been acquired with a Locker object.  Therefore, in order to be
2807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * able to terminate long-running threads, preemption must be
2808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * enabled to allow the user of TerminateExecution to acquire the
2809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * lock.
2810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The termination is achieved by throwing an exception that is
2812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * uncatchable by JavaScript exception handlers.  Termination
2813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exceptions act as if they were caught by a C++ TryCatch exception
2814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handlers.  If forceful termination is used, any C++ TryCatch
2815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exception handler that catches an exception should check if that
2816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * exception is a termination exception and immediately return if
2817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that is the case.  Returning immediately in that case will
2818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * continue the propagation of the termination exception if needed.
2819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The thread id passed to TerminateExecution must have been
2821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * obtained by calling GetCurrentThreadId on the thread in question.
2822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * \param thread_id The thread id of the thread to terminate.
2824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2825a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void TerminateExecution(int thread_id);
2826a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2827a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2828a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Forcefully terminate the current thread of JavaScript execution.
2829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This method can be used by any thread even if that thread has not
2831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * acquired the V8 lock with a Locker object.
2832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void TerminateExecution();
2834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
28366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Is V8 terminating JavaScript execution.
28376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   *
28386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Returns true if JavaScript execution is currently terminating
28396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * because of a call to TerminateExecution.  In that case there are
28406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * still JavaScript frames on the stack and the termination
28416ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * exception is still active.
28426ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
28436ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static bool IsExecutionTerminating();
28446ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
28456ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
2846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Releases any resources used by v8 and stops any utility threads
2847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that may be running.  Note that disposing v8 is permanent, it
2848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * cannot be reinitialized.
2849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * It should generally not be necessary to dispose v8 before exiting
2851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * a process, this should happen automatically.  It is only necessary
2852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to use if the process needs the resources taken up by v8.
2853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool Dispose();
2855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  /**
28573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   * Get statistics about the heap memory usage.
28583ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block   */
28593ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static void GetHeapStatistics(HeapStatistics* heap_statistics);
2860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Optional notification that the embedder is idle.
2863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 uses the notification to reduce memory footprint.
2864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * This call can be used repeatedly if the embedder remains idle.
2865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if the embedder should stop calling IdleNotification
2866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * until real work has been done.  This indicates that V8 has done
2867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * as much cleanup as it will be able to do.
2868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
28693ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static bool IdleNotification();
2870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Optional notification that the system is running low on memory.
2873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * V8 uses these notifications to attempt to free memory.
2874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void LowMemoryNotification();
2876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  /**
28786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * Optional notification that a context has been disposed. V8 uses
28796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * these notifications to guide the GC heuristic. Returns the number
28806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * of context disposals - including this one - since the last time
28816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   * V8 had a chance to clean up.
28826ded16be15dd865a9b21ea304d5273c8be299c87Steve Block   */
28836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static int ContextDisposedNotification();
28846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
2885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8();
2887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static internal::Object** GlobalizeReference(internal::Object** handle);
2889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void DisposeGlobal(internal::Object** global_handle);
2890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void MakeWeak(internal::Object** global_handle,
2891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       void* data,
2892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       WeakReferenceCallback);
2893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ClearWeak(internal::Object** global_handle);
2894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsGlobalNearDeath(internal::Object** global_handle);
2895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsGlobalWeak(internal::Object** global_handle);
2896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Handle;
2898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Local;
2899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <class T> friend class Persistent;
2900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Context;
2901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
2905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An external exception handler.
2906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
2907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TryCatch {
2908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Creates a new try/catch block and registers it with v8.
2912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  TryCatch();
2914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Unregisters and deletes this try/catch block.
2917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~TryCatch();
2919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns true if an exception has been caught by this try/catch block.
2922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasCaught() const;
2924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * For certain types of exceptions, it makes no sense to continue
2927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * execution.
2928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Currently, the only type of exception that can be caught by a
2930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TryCatch handler and for which it does not make sense to continue
2931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is termination exception.  Such exceptions are thrown when the
2932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * TerminateExecution methods are called to terminate a long-running
2933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * script.
2934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * If CanContinue returns false, the correct action is to perform
2936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * any C++ cleanup needed and then return.
2937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool CanContinue() const;
2939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2941d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * Throws the exception caught by this TryCatch in a way that avoids
2942d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * it being caught again by this same TryCatch.  As with ThrowException
2943d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * it is illegal to execute any JavaScript operations after calling
2944d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * ReThrow; the caller must return immediately to where the exception
2945d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   * is caught.
2946d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block   */
2947d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  Handle<Value> ReThrow();
2948d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
2949d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /**
2950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the exception caught by this try/catch block.  If no exception has
2951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * been caught an empty handle is returned.
2952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The returned handle is valid until this TryCatch block has been destroyed.
2954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> Exception() const;
2956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the .stack property of the thrown object.  If no .stack
2959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * property is present an empty handle is returned.
2960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> StackTrace() const;
2962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the message associated with this exception.  If there is
2965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * no message associated an empty handle is returned.
2966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * The returned handle is valid until this TryCatch block has been
2968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * destroyed.
2969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<v8::Message> Message() const;
2971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Clears any exceptions that may have been caught by this try/catch block.
2974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * After this method has been called, HasCaught() will return false.
2975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * It is not necessary to clear a try/catch block before using it again; if
2977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * another exception is thrown the previously caught exception will just be
2978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * overwritten.  However, it is often a good idea since it makes it easier
2979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * to determine which operation threw a given exception.
2980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Reset();
2982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set verbosity of the external exception handler.
2985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
2986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * By default, exceptions that are caught by an external exception
2987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler are not reported.  Call SetVerbose with true on an
2988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * external exception handler to have exceptions caught by the
2989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * handler reported as if they were not caught.
2990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetVerbose(bool value);
2992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
2994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Set whether or not this TryCatch should capture a Message object
2995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * which holds source information about where the exception
2996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * occurred.  True by default.
2997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
2998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCaptureMessage(bool value);
2999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3000d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block private:
3001d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void* next_;
3002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* exception_;
3003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void* message_;
3004d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool is_verbose_ : 1;
3005d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool can_continue_ : 1;
3006d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool capture_message_ : 1;
3007d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool rethrow_ : 1;
3008d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3009d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  friend class v8::internal::Top;
3010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- C o n t e x t ---
3014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore
3018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ExtensionConfiguration {
3020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ExtensionConfiguration(int name_count, const char* names[])
3022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : name_count_(name_count), names_(names) { }
3023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class ImplementationUtilities;
3025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int name_count_;
3026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char** names_;
3027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A sandboxed execution context with its own set of built-in objects
3032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and functions.
3033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Context {
3035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the global object of the context. */
3037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Object> Global();
3038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Detaches the global object from its context before
3041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the global object can be reused to create a new context.
3042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void DetachGlobal();
3044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
304574b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu  /**
304674b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * Reattaches a global object to a context.  This can be used to
304774b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * restore the connection between a global object and a context
304874b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * after DetachGlobal has been called.
304974b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *
305074b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   * \param global_object The global object to reattach to the
305174b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   context.  For this to work, the global object must be the global
305274b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   object that was associated with this context before a call to
305374b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   *   DetachGlobal.
305474b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu   */
305574b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu  void ReattachGlobal(Handle<Object> global_object);
305674b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu
3057f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  /** Creates a new context.
3058f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   *
3059f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * Returns a persistent handle to the newly allocated context. This
3060f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * persistent handle has to be disposed when the context is no
3061f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   * longer used so the context can be garbage collected.
3062f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke   */
3063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Persistent<Context> New(
30643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu      ExtensionConfiguration* extensions = NULL,
3065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
3066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Handle<Value> global_object = Handle<Value>());
3067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the last entered context. */
3069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetEntered();
3070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the context that is on the top of the stack. */
3072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetCurrent();
3073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns the context of the calling JavaScript code.  That is the
3076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context of the top-most JavaScript frame.  If there are no
3077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * JavaScript frames an empty handle is returned.
3078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Local<Context> GetCalling();
3080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Sets the security token for the context.  To access an object in
3083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * another context, the security tokens must match.
3084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetSecurityToken(Handle<Value> token);
3086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Restores the security token to the default value. */
3088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void UseDefaultSecurityToken();
3089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns the security token of this context.*/
3091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Handle<Value> GetSecurityToken();
3092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Enter this context.  After entering a context, all code compiled
3095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * and run is compiled and run in this context.  If another context
3096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * is already entered, this old context is saved so it can be
3097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * restored when the new context is exited.
3098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Enter();
3100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Exit this context.  Exiting the current context restores the
3103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * context that was in place when entering the current context.
3104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Exit();
3106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns true if the context has experienced an out of memory situation. */
3108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasOutOfMemoryException();
3109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /** Returns true if V8 has a current context. */
3111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool InContext();
3112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Associate an additional data object with the context. This is mainly used
3115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * with the debugger to provide additional information on the context through
3116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * the debugger API.
3117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3118d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void SetData(Handle<String> data);
3119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> GetData();
3120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Stack-allocated class which sets the execution context for all
3123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * operations executed within a local scope.
3124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
31258defd9ff6930b4e24729971a61cf7469daf119beSteve Block  class Scope {
3126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
3127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline Scope(Handle<Context> context) : context_(context) {
3128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      context_->Enter();
3129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
3130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    inline ~Scope() { context_->Exit(); }
3131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
3132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Handle<Context> context_;
3133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
3134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Value;
3137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Script;
3138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Object;
3139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class Function;
3140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Multiple threads in V8 are allowed, but only one thread at a time
3145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is allowed to use V8.  The definition of 'using V8' includes
3146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * accessing handles or holding onto object pointers obtained from V8
3147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles.  It is up to the user of V8 to ensure (perhaps with
3148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * locking) that this constraint is not violated.
3149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you wish to start using V8 in a thread you can do this by constructing
3151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a v8::Locker object.  After the code using V8 has completed for the
3152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * current thread you can call the destructor.  This can be combined
3153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * with C++ scope-based construction as follows:
3154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ...
3157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   v8::Locker locker;
3159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // Code using V8 goes here.
3161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here
3163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you wish to stop using V8 in a thread A you can do this by either
3166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * by destroying the v8::Locker object as above or by constructing a
3167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Unlocker object:
3168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   v8::Unlocker unlocker;
3172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // Code not using V8 goes here while V8 can run in another thread.
3174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   ...
3175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here.
3176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Unlocker object is intended for use in a long-running callback
3179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * from V8, where you want to release the V8 lock for other threads to
3180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * use.
3181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The v8::Locker is a recursive lock.  That is, you can lock more than
3183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * once in a given thread.  This can be useful if you have code that can
3184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be called either from code that holds the lock or from code that does
3185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * not.  The Unlocker is not recursive so you can not have several
3186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Unlockers on the stack at once, and you can not use an Unlocker in a
3187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * thread that is not inside a Locker's scope.
3188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An unlocker will unlock several lockers if it has to and reinstate
3190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the correct depth of locking on its destruction. eg.:
3191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *
3192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code
3193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 not locked.
3194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * {
3195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   v8::Locker locker;
3196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // V8 locked.
3197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   {
3198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     v8::Locker another_locker;
3199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     // V8 still locked (2 levels).
3200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     {
3201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *       v8::Unlocker unlocker;
3202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *       // V8 not locked.
3203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     }
3204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *     // V8 locked again (2 levels).
3205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   }
3206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *   // V8 still locked (1 level).
3207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * }
3208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 Now no longer locked.
3209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode
3210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Unlocker {
3212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Unlocker();
3214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~Unlocker();
3215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Locker {
3219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Locker();
3221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ~Locker();
3222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Start preemption.
3225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   *
3226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * When preemption is started, a timer is fired every n milli seconds
3227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * that will switch between multiple threads that are in contention
3228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * for the V8 lock.
3229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void StartPreemption(int every_n_ms);
3231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Stop preemption.
3234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void StopPreemption();
3236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns whether or not the locker is locked by the current thread.
3239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsLocked();
3241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  /**
3243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   * Returns whether v8::Locker is being used by this V8 instance.
3244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   */
3245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool IsActive() { return active_; }
3246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool has_lock_;
3249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool top_level_;
3250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool active_;
3252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Disallow copying and assigning.
3254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Locker(const Locker&);
3255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void operator=(const Locker&);
3256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
32590d5e116f6aee03185f237311a943491bb079a768Kristian Monsen/**
32600d5e116f6aee03185f237311a943491bb079a768Kristian Monsen * An interface for exporting data from V8, using "push" model.
32610d5e116f6aee03185f237311a943491bb079a768Kristian Monsen */
32620d5e116f6aee03185f237311a943491bb079a768Kristian Monsenclass V8EXPORT OutputStream {
32630d5e116f6aee03185f237311a943491bb079a768Kristian Monsenpublic:
32640d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  enum OutputEncoding {
32650d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kAscii = 0  // 7-bit ASCII.
32660d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  };
32670d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  enum WriteResult {
32680d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kContinue = 0,
32690d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    kAbort = 1
32700d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  };
32710d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual ~OutputStream() {}
32720d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Notify about the end of stream. */
32730d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual void EndOfStream() = 0;
32740d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Get preferred output chunk size. Called only once. */
32750d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual int GetChunkSize() { return 1024; }
32760d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /** Get preferred output encoding. Called only once. */
32770d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual OutputEncoding GetOutputEncoding() { return kAscii; }
32780d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  /**
32790d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * Writes the next chunk of snapshot data into the stream. Writing
32800d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * can be stopped by returning kAbort as function result. EndOfStream
32810d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   * will not be called in case writing was aborted.
32820d5e116f6aee03185f237311a943491bb079a768Kristian Monsen   */
32830d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
32840d5e116f6aee03185f237311a943491bb079a768Kristian Monsen};
32850d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
32860d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
3287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- I m p l e m e n t a t i o n ---
3289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
3292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for HeapObject.
3295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTag = 1;
3296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTagSize = 2;
3297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
3298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for Smi.
3300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTag = 0;
3301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTagSize = 1;
3302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
3303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
33043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <size_t ptr_size> struct SmiConstants;
33053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 32-bit systems.
33073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <> struct SmiConstants<4> {
33083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiShiftSize = 0;
33093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiValueSize = 31;
33103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int SmiToInt(internal::Object* value) {
33113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    int shift_bits = kSmiTagSize + kSmiShiftSize;
33123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // Throw away top 32 bits and shift down (requires >> to be sign extending).
33133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
33143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
33163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 64-bit systems.
33183ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <> struct SmiConstants<8> {
33193ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiShiftSize = 31;
33203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kSmiValueSize = 32;
33213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int SmiToInt(internal::Object* value) {
33223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    int shift_bits = kSmiTagSize + kSmiShiftSize;
33233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // Shift down and throw away top 32 bits.
33243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
33253ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33263ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
33273ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33283ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockconst int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize;
33293ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockconst int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize;
3330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3331d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <size_t ptr_size> struct InternalConstants;
3332d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3333d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 32-bit systems.
3334d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<4> {
3335d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kStringResourceOffset = 3 * sizeof(void*);
3336d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block};
3337d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3338d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 64-bit systems.
3339d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<8> {
33406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kStringResourceOffset = 3 * sizeof(void*);
3341d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block};
3342d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This class exports constants and functionality from within v8 that
3345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is necessary to implement inline functions in the v8 api.  Don't
3346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * depend on functions and constants defined here.
3347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Internals {
3349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // These values match non-compiler-dependent values defined within
3352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the implementation of v8.
3353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeapObjectMapOffset = 0;
3354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int);
3355d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kStringResourceOffset =
3356d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block      InternalConstants<sizeof(void*)>::kStringResourceOffset;
3357d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
3358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kProxyProxyOffset = sizeof(void*);
3359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kJSObjectHeaderSize = 3 * sizeof(void*);
3360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFullStringRepresentationMask = 0x07;
33617f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kExternalTwoByteRepresentationTag = 0x02;
3362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
33639dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kJSObjectType = 0x9f;
33649dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kFirstNonstringType = 0x80;
33659dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kProxyType = 0x85;
3366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool HasHeapObjectTag(internal::Object* value) {
3368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
3369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            kHeapObjectTag);
3370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool HasSmiTag(internal::Object* value) {
3373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
3374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline int SmiValue(internal::Object* value) {
33773ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return SmiConstants<sizeof(void*)>::SmiToInt(value);
33783ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33793ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33803ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline int GetInstanceType(internal::Object* obj) {
33813ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    typedef internal::Object O;
33823ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
33833ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
33843ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
33853ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
33863ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline void* GetExternalPointer(internal::Object* obj) {
33873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    if (HasSmiTag(obj)) {
33883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block      return obj;
33893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    } else if (GetInstanceType(obj) == kProxyType) {
33903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block      return ReadField<void*>(obj, kProxyProxyOffset);
33913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    } else {
33923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block      return NULL;
33933ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    }
3394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool IsExternalTwoByteString(int instance_type) {
3397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int representation = (instance_type & kFullStringRepresentationMask);
3398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return representation == kExternalTwoByteRepresentationTag;
3399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <typename T>
3402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline T ReadField(Object* ptr, int offset) {
3403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
3404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return *reinterpret_cast<T*>(addr);
3405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<T>::Handle() : val_(0) { }
3414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T>::Local() : Handle<T>() { }
3418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> Local<T>::New(Handle<T> that) {
3422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (that.IsEmpty()) return Local<T>();
3423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** p = reinterpret_cast<internal::Object**>(*that);
3424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
3425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T> Persistent<T>::New(Handle<T> that) {
3430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (that.IsEmpty()) return Persistent<T>();
3431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** p = reinterpret_cast<internal::Object**>(*that);
3432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
3433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsNearDeath() const {
3438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return false;
3439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
3440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsWeak() const {
3445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return false;
3446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
3447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::Dispose() {
3452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (this->IsEmpty()) return;
3453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
3454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T>::Persistent() : Handle<T>() { }
3459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
3462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
3463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block               parameters,
3464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block               callback);
3465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::ClearWeak() {
3469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
3470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
34728defd9ff6930b4e24729971a61cf7469daf119beSteve Block
34738defd9ff6930b4e24729971a61cf7469daf119beSteve BlockArguments::Arguments(v8::Local<v8::Value> data,
34748defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     v8::Local<v8::Object> holder,
34758defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     v8::Local<v8::Function> callee,
34768defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     bool is_construct_call,
34778defd9ff6930b4e24729971a61cf7469daf119beSteve Block                     void** values, int length)
34788defd9ff6930b4e24729971a61cf7469daf119beSteve Block    : data_(data), holder_(holder), callee_(callee),
34798defd9ff6930b4e24729971a61cf7469daf119beSteve Block      is_construct_call_(is_construct_call),
34808defd9ff6930b4e24729971a61cf7469daf119beSteve Block      values_(values), length_(length) { }
34818defd9ff6930b4e24729971a61cf7469daf119beSteve Block
34828defd9ff6930b4e24729971a61cf7469daf119beSteve Block
3483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::operator[](int i) const {
3484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
3485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
3486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Function> Arguments::Callee() const {
3490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return callee_;
3491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::This() const {
3495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
3496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::Holder() const {
3500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return holder_;
3501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::Data() const {
3505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return data_;
3506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Arguments::IsConstructCall() const {
3510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return is_construct_call_;
3511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockint Arguments::Length() const {
3515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return length_;
3516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T>
3520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> HandleScope::Close(Handle<T> value) {
3521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** before = reinterpret_cast<internal::Object**>(*value);
3522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  internal::Object** after = RawClose(before);
3523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<T>(reinterpret_cast<T*>(after));
3524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> ScriptOrigin::ResourceName() const {
3527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_name_;
3528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceLineOffset() const {
3532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_line_offset_;
3533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceColumnOffset() const {
3537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return resource_column_offset_;
3538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> Boolean::New(bool value) {
3542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return value ? True() : False();
3543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Template::Set(const char* name, v8::Handle<Data> value) {
3547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Set(v8::String::New(name), value);
3548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::GetInternalField(int index) {
3552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_ENABLE_CHECKS
3553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Local<Value> quick_result = UncheckedGetInternalField(index);
3554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (!quick_result.IsEmpty()) return quick_result;
3555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return CheckedGetInternalField(index);
3557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::UncheckedGetInternalField(int index) {
3561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
3563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(this);
35643ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::GetInstanceType(obj) == I::kJSObjectType) {
3565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If the object is a plain JSObject, which is the common case,
3566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // we know where to find the internal fields and can return the
3567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // value directly.
3568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index);
3569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    O* value = I::ReadField<O*>(obj, offset);
3570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    O** result = HandleScope::CreateHandle(value);
3571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<Value>(reinterpret_cast<Value*>(result));
3572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  } else {
3573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Local<Value>();
3574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::Unwrap(Handle<v8::Value> obj) {
3579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return FullUnwrap(obj);
3581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
3582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return QuickUnwrap(obj);
3583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::QuickUnwrap(Handle<v8::Value> wrapper) {
3588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
35903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return internal::Internals::GetExternalPointer(obj);
3591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* Object::GetPointerFromInternalField(int index) {
35953ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  typedef internal::Object O;
35963ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  typedef internal::Internals I;
35973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
35983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  O* obj = *reinterpret_cast<O**>(this);
35993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
36003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::GetInstanceType(obj) == I::kJSObjectType) {
36013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // If the object is a plain JSObject, which is the common case,
36023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // we know where to find the internal fields and can return the
36033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    // value directly.
36043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index);
36053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    O* value = I::ReadField<O*>(obj, offset);
36063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    return I::GetExternalPointer(value);
36073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  }
36083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
36093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return SlowGetPointerFromInternalField(index);
3610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString* String::Cast(v8::Value* value) {
3614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<String*>(value);
3618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString::ExternalStringResource* String::GetExternalStringResource() const {
3622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
3624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
3625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  String::ExternalStringResource* result;
36263ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
3627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
3628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    result = reinterpret_cast<String::ExternalStringResource*>(value);
3629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  } else {
3630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    result = NULL;
3631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  VerifyExternalStringResource(result);
3634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return result;
3636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::IsString() const {
3640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return FullIsString();
3642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
3643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return QuickIsString();
3644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::QuickIsString() const {
3648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Object O;
3649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef internal::Internals I;
3650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
3651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (!I::HasHeapObjectTag(obj)) return false;
36523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
3653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockNumber* Number::Cast(v8::Value* value) {
3657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Number*>(value);
3661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockInteger* Integer::Cast(v8::Value* value) {
3665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Integer*>(value);
3669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDate* Date::Cast(v8::Value* value) {
3673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Date*>(value);
3677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3680f87a203d89e1bbb6708282e0b64dbd13d59b723dBen MurdochRegExp* RegExp::Cast(v8::Value* value) {
3681f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch#ifdef V8_ENABLE_CHECKS
3682f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  CheckCast(value);
3683f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch#endif
3684f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  return static_cast<RegExp*>(value);
3685f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch}
3686f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
3687f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
3688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockObject* Object::Cast(v8::Value* value) {
3689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Object*>(value);
3693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockArray* Array::Cast(v8::Value* value) {
3697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Array*>(value);
3701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockFunction* Function::Cast(v8::Value* value) {
3705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<Function*>(value);
3709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockExternal* External::Cast(v8::Value* value) {
3713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS
3714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CheckCast(value);
3715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return static_cast<External*>(value);
3717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> AccessorInfo::Data() const {
37216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
3722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::This() const {
3726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
3727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::Holder() const {
3731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
3732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
3733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example shell.cc
3737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A simple shell that takes a list of expressions on the
3738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * command-line and executes them.
3739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3741a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3742a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/**
3743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example process.cc
3744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */
3745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}  // namespace v8
3748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef V8EXPORT
3751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef TYPE_CHECK
3752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // V8_H_
3755