My favorites | Sign in
v8
Project Home Downloads Wiki Issues Source Code Search
Checkout   Browse   Changes  
Changes to /branches/bleeding_edge/include/v8.h
r12640 vs. r12668 Compare: vs.  Format:
Revision r12668
Go to: 
Project members, sign in to write a code review
/branches/bleeding_edge/include/v8.h   r12640 /branches/bleeding_edge/include/v8.h   r12668
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 /** \mainpage V8 API Reference Guide 28 /** \mainpage V8 API Reference Guide
29 * 29 *
30 * V8 is Google's open source JavaScript engine. 30 * V8 is Google's open source JavaScript engine.
31 * 31 *
32 * This set of documents provides reference material generated from the 32 * This set of documents provides reference material generated from the
33 * V8 header file, include/v8.h. 33 * V8 header file, include/v8.h.
34 * 34 *
35 * For other documentation see http://code.google.com/apis/v8/ 35 * For other documentation see http://code.google.com/apis/v8/
36 */ 36 */
37 37
38 #ifndef V8_H_ 38 #ifndef V8_H_
39 #define V8_H_ 39 #define V8_H_
40 40
41 #include "v8stdint.h" 41 #include "v8stdint.h"
42 42
43 #ifdef _WIN32 43 #ifdef _WIN32
44 44
45 // Setup for Windows DLL export/import. When building the V8 DLL the 45 // Setup for Windows DLL export/import. When building the V8 DLL the
46 // BUILDING_V8_SHARED needs to be defined. When building a program which uses 46 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
47 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 47 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
48 // static library or building a program which uses the V8 static library neither 48 // static library or building a program which uses the V8 static library neither
49 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. 49 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
50 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) 50 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
51 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ 51 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
52 build configuration to ensure that at most one of these is set 52 build configuration to ensure that at most one of these is set
53 #endif 53 #endif
54 54
55 #ifdef BUILDING_V8_SHARED 55 #ifdef BUILDING_V8_SHARED
56 #define V8EXPORT __declspec(dllexport) 56 #define V8EXPORT __declspec(dllexport)
57 #elif USING_V8_SHARED 57 #elif USING_V8_SHARED
58 #define V8EXPORT __declspec(dllimport) 58 #define V8EXPORT __declspec(dllimport)
59 #else 59 #else
60 #define V8EXPORT 60 #define V8EXPORT
61 #endif // BUILDING_V8_SHARED 61 #endif // BUILDING_V8_SHARED
62 62
63 #else // _WIN32 63 #else // _WIN32
64 64
65 // Setup for Linux shared library export. 65 // Setup for Linux shared library export.
66 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ 66 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
67 (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED) 67 (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
68 #ifdef BUILDING_V8_SHARED 68 #ifdef BUILDING_V8_SHARED
69 #define V8EXPORT __attribute__ ((visibility("default"))) 69 #define V8EXPORT __attribute__ ((visibility("default")))
70 #else 70 #else
71 #define V8EXPORT 71 #define V8EXPORT
72 #endif 72 #endif
73 #else 73 #else
74 #define V8EXPORT 74 #define V8EXPORT
75 #endif 75 #endif
76 76
77 #endif // _WIN32 77 #endif // _WIN32
78 78
79 /** 79 /**
80 * The v8 JavaScript engine. 80 * The v8 JavaScript engine.
81 */ 81 */
82 namespace v8 { 82 namespace v8 {
83 83
84 class Context; 84 class Context;
85 class String; 85 class String;
86 class StringObject; 86 class StringObject;
87 class Value; 87 class Value;
88 class Utils; 88 class Utils;
89 class Number; 89 class Number;
90 class NumberObject; 90 class NumberObject;
91 class Object; 91 class Object;
92 class Array; 92 class Array;
93 class Int32; 93 class Int32;
94 class Uint32; 94 class Uint32;
95 class External; 95 class External;
96 class Primitive; 96 class Primitive;
97 class Boolean; 97 class Boolean;
98 class BooleanObject; 98 class BooleanObject;
99 class Integer; 99 class Integer;
100 class Function; 100 class Function;
101 class Date; 101 class Date;
102 class ImplementationUtilities; 102 class ImplementationUtilities;
103 class Signature; 103 class Signature;
104 class AccessorSignature; 104 class AccessorSignature;
105 template <class T> class Handle; 105 template <class T> class Handle;
106 template <class T> class Local; 106 template <class T> class Local;
107 template <class T> class Persistent; 107 template <class T> class Persistent;
108 class FunctionTemplate; 108 class FunctionTemplate;
109 class ObjectTemplate; 109 class ObjectTemplate;
110 class Data; 110 class Data;
111 class AccessorInfo; 111 class AccessorInfo;
112 class StackTrace; 112 class StackTrace;
113 class StackFrame; 113 class StackFrame;
114 class Isolate; 114 class Isolate;
115 115
116 namespace internal { 116 namespace internal {
117 117
118 class Arguments; 118 class Arguments;
119 class Object; 119 class Object;
120 class Heap; 120 class Heap;
121 class HeapObject; 121 class HeapObject;
122 class Isolate; 122 class Isolate;
123 } 123 }
124 124
125 125
126 // --- Weak Handles --- 126 // --- Weak Handles ---
127 127
128 128
129 /** 129 /**
130 * A weak reference callback function. 130 * A weak reference callback function.
131 * 131 *
132 * This callback should either explicitly invoke Dispose on |object| if 132 * This callback should either explicitly invoke Dispose on |object| if
133 * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. 133 * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak.
134 * 134 *
135 * \param object the weak global object to be reclaimed by the garbage collector 135 * \param object the weak global object to be reclaimed by the garbage collector
136 * \param parameter the value passed in when making the weak global object 136 * \param parameter the value passed in when making the weak global object
137 */ 137 */
138 typedef void (*WeakReferenceCallback)(Persistent<Value> object, 138 typedef void (*WeakReferenceCallback)(Persistent<Value> object,
139 void* parameter); 139 void* parameter);
140 140
141 141
142 // --- Handles --- 142 // --- Handles ---
143 143
144 #define TYPE_CHECK(T, S) \ 144 #define TYPE_CHECK(T, S) \
145 while (false) { \ 145 while (false) { \
146 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ 146 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
147 } 147 }
148 148
149 /** 149 /**
150 * An object reference managed by the v8 garbage collector. 150 * An object reference managed by the v8 garbage collector.
151 * 151 *
152 * All objects returned from v8 have to be tracked by the garbage 152 * All objects returned from v8 have to be tracked by the garbage
153 * collector so that it knows that the objects are still alive. Also, 153 * collector so that it knows that the objects are still alive. Also,
154 * because the garbage collector may move objects, it is unsafe to 154 * because the garbage collector may move objects, it is unsafe to
155 * point directly to an object. Instead, all objects are stored in 155 * point directly to an object. Instead, all objects are stored in
156 * handles which are known by the garbage collector and updated 156 * handles which are known by the garbage collector and updated
157 * whenever an object moves. Handles should always be passed by value 157 * whenever an object moves. Handles should always be passed by value
158 * (except in cases like out-parameters) and they should never be 158 * (except in cases like out-parameters) and they should never be
159 * allocated on the heap. 159 * allocated on the heap.
160 * 160 *
161 * There are two types of handles: local and persistent handles. 161 * There are two types of handles: local and persistent handles.
162 * Local handles are light-weight and transient and typically used in 162 * Local handles are light-weight and transient and typically used in
163 * local operations. They are managed by HandleScopes. Persistent 163 * local operations. They are managed by HandleScopes. Persistent
164 * handles can be used when storing objects across several independent 164 * handles can be used when storing objects across several independent
165 * operations and have to be explicitly deallocated when they're no 165 * operations and have to be explicitly deallocated when they're no
166 * longer used. 166 * longer used.
167 * 167 *
168 * It is safe to extract the object stored in the handle by 168 * It is safe to extract the object stored in the handle by
169 * dereferencing the handle (for instance, to extract the Object* from 169 * dereferencing the handle (for instance, to extract the Object* from
170 * a Handle<Object>); the value will still be governed by a handle 170 * a Handle<Object>); the value will still be governed by a handle
171 * behind the scenes and the same rules apply to these values as to 171 * behind the scenes and the same rules apply to these values as to
172 * their handles. 172 * their handles.
173 */ 173 */
174 template <class T> class Handle { 174 template <class T> class Handle {
175 public: 175 public:
176 /** 176 /**
177 * Creates an empty handle. 177 * Creates an empty handle.
178 */ 178 */
179 inline Handle() : val_(0) {} 179 inline Handle() : val_(0) {}
180 180
181 /** 181 /**
182 * Creates a new handle for the specified value. 182 * Creates a new handle for the specified value.
183 */ 183 */
184 inline explicit Handle(T* val) : val_(val) {} 184 inline explicit Handle(T* val) : val_(val) {}
185 185
186 /** 186 /**
187 * Creates a handle for the contents of the specified handle. This 187 * Creates a handle for the contents of the specified handle. This
188 * constructor allows you to pass handles as arguments by value and 188 * constructor allows you to pass handles as arguments by value and
189 * to assign between handles. However, if you try to assign between 189 * to assign between handles. However, if you try to assign between
190 * incompatible handles, for instance from a Handle<String> to a 190 * incompatible handles, for instance from a Handle<String> to a
191 * Handle<Number> it will cause a compile-time error. Assigning 191 * Handle<Number> it will cause a compile-time error. Assigning
192 * between compatible handles, for instance assigning a 192 * between compatible handles, for instance assigning a
193 * Handle<String> to a variable declared as Handle<Value>, is legal 193 * Handle<String> to a variable declared as Handle<Value>, is legal
194 * because String is a subclass of Value. 194 * because String is a subclass of Value.
195 */ 195 */
196 template <class S> inline Handle(Handle<S> that) 196 template <class S> inline Handle(Handle<S> that)
197 : val_(reinterpret_cast<T*>(*that)) { 197 : val_(reinterpret_cast<T*>(*that)) {
198 /** 198 /**
199 * This check fails when trying to convert between incompatible 199 * This check fails when trying to convert between incompatible
200 * handles. For example, converting from a Handle<String> to a 200 * handles. For example, converting from a Handle<String> to a
201 * Handle<Number>. 201 * Handle<Number>.
202 */ 202 */
203 TYPE_CHECK(T, S); 203 TYPE_CHECK(T, S);
204 } 204 }
205 205
206 /** 206 /**
207 * Returns true if the handle is empty. 207 * Returns true if the handle is empty.
208 */ 208 */
209 inline bool IsEmpty() const { return val_ == 0; } 209 inline bool IsEmpty() const { return val_ == 0; }
210 210
211 /** 211 /**
212 * Sets the handle to be empty. IsEmpty() will then return true. 212 * Sets the handle to be empty. IsEmpty() will then return true.
213 */ 213 */
214 inline void Clear() { val_ = 0; } 214 inline void Clear() { val_ = 0; }
215 215
216 inline T* operator->() const { return val_; } 216 inline T* operator->() const { return val_; }
217 217
218 inline T* operator*() const { return val_; } 218 inline T* operator*() const { return val_; }
219 219
220 /** 220 /**
221 * Checks whether two handles are the same. 221 * Checks whether two handles are the same.
222 * Returns true if both are empty, or if the objects 222 * Returns true if both are empty, or if the objects
223 * to which they refer are identical. 223 * to which they refer are identical.
224 * The handles' references are not checked. 224 * The handles' references are not checked.
225 */ 225 */
226 template <class S> inline bool operator==(Handle<S> that) const { 226 template <class S> inline bool operator==(Handle<S> that) const {
227 internal::Object** a = reinterpret_cast<internal::Object**>(**this); 227 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
228 internal::Object** b = reinterpret_cast<internal::Object**>(*that); 228 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
229 if (a == 0) return b == 0; 229 if (a == 0) return b == 0;
230 if (b == 0) return false; 230 if (b == 0) return false;
231 return *a == *b; 231 return *a == *b;
232 } 232 }
233 233
234 /** 234 /**
235 * Checks whether two handles are different. 235 * Checks whether two handles are different.
236 * Returns true if only one of the handles is empty, or if 236 * Returns true if only one of the handles is empty, or if
237 * the objects to which they refer are different. 237 * the objects to which they refer are different.
238 * The handles' references are not checked. 238 * The handles' references are not checked.
239 */ 239 */
240 template <class S> inline bool operator!=(Handle<S> that) const { 240 template <class S> inline bool operator!=(Handle<S> that) const {
241 return !operator==(that); 241 return !operator==(that);
242 } 242 }
243 243
244 template <class S> static inline Handle<T> Cast(Handle<S> that) { 244 template <class S> static inline Handle<T> Cast(Handle<S> that) {
245 #ifdef V8_ENABLE_CHECKS 245 #ifdef V8_ENABLE_CHECKS
246 // If we're going to perform the type check then we have to check 246 // If we're going to perform the type check then we have to check
247 // that the handle isn't empty before doing the checked cast. 247 // that the handle isn't empty before doing the checked cast.
248 if (that.IsEmpty()) return Handle<T>(); 248 if (that.IsEmpty()) return Handle<T>();
249 #endif 249 #endif
250 return Handle<T>(T::Cast(*that)); 250 return Handle<T>(T::Cast(*that));
251 } 251 }
252 252
253 template <class S> inline Handle<S> As() { 253 template <class S> inline Handle<S> As() {
254 return Handle<S>::Cast(*this); 254 return Handle<S>::Cast(*this);
255 } 255 }
256 256
257 private: 257 private:
258 T* val_; 258 T* val_;
259 }; 259 };
260 260
261 261
262 /** 262 /**
263 * A light-weight stack-allocated object handle. All operations 263 * A light-weight stack-allocated object handle. All operations
264 * that return objects from within v8 return them in local handles. They 264 * that return objects from within v8 return them in local handles. They
265 * are created within HandleScopes, and all local handles allocated within a 265 * are created within HandleScopes, and all local handles allocated within a
266 * handle scope are destroyed when the handle scope is destroyed. Hence it 266 * handle scope are destroyed when the handle scope is destroyed. Hence it
267 * is not necessary to explicitly deallocate local handles. 267 * is not necessary to explicitly deallocate local handles.
268 */ 268 */
269 template <class T> class Local : public Handle<T> { 269 template <class T> class Local : public Handle<T> {
270 public: 270 public:
271 inline Local(); 271 inline Local();
272 template <class S> inline Local(Local<S> that) 272 template <class S> inline Local(Local<S> that)
273 : Handle<T>(reinterpret_cast<T*>(*that)) { 273 : Handle<T>(reinterpret_cast<T*>(*that)) {
274 /** 274 /**
275 * This check fails when trying to convert between incompatible 275 * This check fails when trying to convert between incompatible
276 * handles. For example, converting from a Handle<String> to a 276 * handles. For example, converting from a Handle<String> to a
277 * Handle<Number>. 277 * Handle<Number>.
278 */ 278 */
279 TYPE_CHECK(T, S); 279 TYPE_CHECK(T, S);
280 } 280 }
281 template <class S> inline Local(S* that) : Handle<T>(that) { } 281 template <class S> inline Local(S* that) : Handle<T>(that) { }
282 template <class S> static inline Local<T> Cast(Local<S> that) { 282 template <class S> static inline Local<T> Cast(Local<S> that) {
283 #ifdef V8_ENABLE_CHECKS 283 #ifdef V8_ENABLE_CHECKS
284 // If we're going to perform the type check then we have to check 284 // If we're going to perform the type check then we have to check
285 // that the handle isn't empty before doing the checked cast. 285 // that the handle isn't empty before doing the checked cast.
286 if (that.IsEmpty()) return Local<T>(); 286 if (that.IsEmpty()) return Local<T>();
287 #endif 287 #endif
288 return Local<T>(T::Cast(*that)); 288 return Local<T>(T::Cast(*that));
289 } 289 }
290 290
291 template <class S> inline Local<S> As() { 291 template <class S> inline Local<S> As() {
292 return Local<S>::Cast(*this); 292 return Local<S>::Cast(*this);
293 } 293 }
294 294
295 /** Create a local handle for the content of another handle. 295 /** Create a local handle for the content of another handle.
296 * The referee is kept alive by the local handle even when 296 * The referee is kept alive by the local handle even when
297 * the original handle is destroyed/disposed. 297 * the original handle is destroyed/disposed.
298 */ 298 */
299 inline static Local<T> New(Handle<T> that); 299 inline static Local<T> New(Handle<T> that);
300 }; 300 };
301 301
302 302
303 /** 303 /**
304 * An object reference that is independent of any handle scope. Where 304 * An object reference that is independent of any handle scope. Where
305 * a Local handle only lives as long as the HandleScope in which it was 305 * a Local handle only lives as long as the HandleScope in which it was
306 * allocated, a Persistent handle remains valid until it is explicitly 306 * allocated, a Persistent handle remains valid until it is explicitly
307 * disposed. 307 * disposed.
308 * 308 *
309 * A persistent handle contains a reference to a storage cell within 309 * A persistent handle contains a reference to a storage cell within
310 * the v8 engine which holds an object value and which is updated by 310 * the v8 engine which holds an object value and which is updated by
311 * the garbage collector whenever the object is moved. A new storage 311 * the garbage collector whenever the object is moved. A new storage
312 * cell can be created using Persistent::New and existing handles can 312 * cell can be created using Persistent::New and existing handles can
313 * be disposed using Persistent::Dispose. Since persistent handles 313 * be disposed using Persistent::Dispose. Since persistent handles
314 * are passed by value you may have many persistent handle objects 314 * are passed by value you may have many persistent handle objects
315 * that point to the same storage cell. For instance, if you pass a 315 * that point to the same storage cell. For instance, if you pass a
316 * persistent handle as an argument to a function you will not get two 316 * persistent handle as an argument to a function you will not get two
317 * different storage cells but rather two references to the same 317 * different storage cells but rather two references to the same
318 * storage cell. 318 * storage cell.
319 */ 319 */
320 template <class T> class Persistent : public Handle<T> { 320 template <class T> class Persistent : public Handle<T> {
321 public: 321 public:
322 /** 322 /**
323 * Creates an empty persistent handle that doesn't point to any 323 * Creates an empty persistent handle that doesn't point to any
324 * storage cell. 324 * storage cell.
325 */ 325 */
326 inline Persistent(); 326 inline Persistent();
327 327
328 /** 328 /**
329 * Creates a persistent handle for the same storage cell as the 329 * Creates a persistent handle for the same storage cell as the
330 * specified handle. This constructor allows you to pass persistent 330 * specified handle. This constructor allows you to pass persistent
331 * handles as arguments by value and to assign between persistent 331 * handles as arguments by value and to assign between persistent
332 * handles. However, attempting to assign between incompatible 332 * handles. However, attempting to assign between incompatible
333 * persistent handles, for instance from a Persistent<String> to a 333 * persistent handles, for instance from a Persistent<String> to a
334 * Persistent<Number> will cause a compile-time error. Assigning 334 * Persistent<Number> will cause a compile-time error. Assigning
335 * between compatible persistent handles, for instance assigning a 335 * between compatible persistent handles, for instance assigning a
336 * Persistent<String> to a variable declared as Persistent<Value>, 336 * Persistent<String> to a variable declared as Persistent<Value>,
337 * is allowed as String is a subclass of Value. 337 * is allowed as String is a subclass of Value.
338 */ 338 */
339 template <class S> inline Persistent(Persistent<S> that) 339 template <class S> inline Persistent(Persistent<S> that)
340 : Handle<T>(reinterpret_cast<T*>(*that)) { 340 : Handle<T>(reinterpret_cast<T*>(*that)) {
341 /** 341 /**
342 * This check fails when trying to convert between incompatible 342 * This check fails when trying to convert between incompatible
343 * handles. For example, converting from a Handle<String> to a 343 * handles. For example, converting from a Handle<String> to a
344 * Handle<Number>. 344 * Handle<Number>.
345 */ 345 */
346 TYPE_CHECK(T, S); 346 TYPE_CHECK(T, S);
347 } 347 }
348 348
349 template <class S> inline Persistent(S* that) : Handle<T>(that) { } 349 template <class S> inline Persistent(S* that) : Handle<T>(that) { }
350 350
351 /** 351 /**
352 * "Casts" a plain handle which is known to be a persistent handle 352 * "Casts" a plain handle which is known to be a persistent handle
353 * to a persistent handle. 353 * to a persistent handle.
354 */ 354 */
355 template <class S> explicit inline Persistent(Handle<S> that) 355 template <class S> explicit inline Persistent(Handle<S> that)
356 : Handle<T>(*that) { } 356 : Handle<T>(*that) { }
357 357
358 template <class S> static inline Persistent<T> Cast(Persistent<S> that) { 358 template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
359 #ifdef V8_ENABLE_CHECKS 359 #ifdef V8_ENABLE_CHECKS
360 // If we're going to perform the type check then we have to check 360 // If we're going to perform the type check then we have to check
361 // that the handle isn't empty before doing the checked cast. 361 // that the handle isn't empty before doing the checked cast.
362 if (that.IsEmpty()) return Persistent<T>(); 362 if (that.IsEmpty()) return Persistent<T>();
363 #endif 363 #endif
364 return Persistent<T>(T::Cast(*that)); 364 return Persistent<T>(T::Cast(*that));
365 } 365 }
366 366
367 template <class S> inline Persistent<S> As() { 367 template <class S> inline Persistent<S> As() {
368 return Persistent<S>::Cast(*this); 368 return Persistent<S>::Cast(*this);
369 } 369 }
370 370
371 /** 371 /**
372 * Creates a new persistent handle for an existing local or 372 * Creates a new persistent handle for an existing local or
373 * persistent handle. 373 * persistent handle.
374 */ 374 */
375 inline static Persistent<T> New(Handle<T> that); 375 inline static Persistent<T> New(Handle<T> that);
376 376
377 /** 377 /**
378 * Releases the storage cell referenced by this persistent handle. 378 * Releases the storage cell referenced by this persistent handle.
379 * Does not remove the reference to the cell from any handles. 379 * Does not remove the reference to the cell from any handles.
380 * This handle's reference, and any other references to the storage 380 * This handle's reference, and any other references to the storage
381 * cell remain and IsEmpty will still return false. 381 * cell remain and IsEmpty will still return false.
382 */ 382 */
383 inline void Dispose(); 383 inline void Dispose();
384 384
385 /** 385 /**
386 * Make the reference to this object weak. When only weak handles 386 * Make the reference to this object weak. When only weak handles
387 * refer to the object, the garbage collector will perform a 387 * refer to the object, the garbage collector will perform a
388 * callback to the given V8::WeakReferenceCallback function, passing 388 * callback to the given V8::WeakReferenceCallback function, passing
389 * it the object reference and the given parameters. 389 * it the object reference and the given parameters.
390 */ 390 */
391 inline void MakeWeak(void* parameters, WeakReferenceCallback callback); 391 inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
392 392
393 /** Clears the weak reference to this object.*/ 393 /** Clears the weak reference to this object.*/
394 inline void ClearWeak(); 394 inline void ClearWeak();
395 395
396 /** 396 /**
397 * Marks the reference to this object independent. Garbage collector 397 * Marks the reference to this object independent. Garbage collector
398 * is free to ignore any object groups containing this object. 398 * is free to ignore any object groups containing this object.
399 * Weak callback for an independent handle should not 399 * Weak callback for an independent handle should not
400 * assume that it will be preceded by a global GC prologue callback 400 * assume that it will be preceded by a global GC prologue callback
401 * or followed by a global GC epilogue callback. 401 * or followed by a global GC epilogue callback.
402 */ 402 */
403 inline void MarkIndependent(); 403 inline void MarkIndependent();
404 404
405 /** 405 /**
406 *Checks if the handle holds the only reference to an object. 406 *Checks if the handle holds the only reference to an object.
407 */ 407 */
408 inline bool IsNearDeath() const; 408 inline bool IsNearDeath() const;
409 409
410 /** 410 /**
411 * Returns true if the handle's reference is weak. 411 * Returns true if the handle's reference is weak.
412 */ 412 */
413 inline bool IsWeak() const; 413 inline bool IsWeak() const;
414 414
415 /** 415 /**
416 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo 416 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo
417 * interface description in v8-profiler.h for details. 417 * interface description in v8-profiler.h for details.
418 */ 418 */
419 inline void SetWrapperClassId(uint16_t class_id); 419 inline void SetWrapperClassId(uint16_t class_id);
420 420
421 private: 421 private:
422 friend class ImplementationUtilities; 422 friend class ImplementationUtilities;
423 friend class ObjectTemplate; 423 friend class ObjectTemplate;
424 }; 424 };
425 425
426 426
427 /** 427 /**
428 * A stack-allocated class that governs a number of local handles. 428 * A stack-allocated class that governs a number of local handles.
429 * After a handle scope has been created, all local handles will be 429 * After a handle scope has been created, all local handles will be
430 * allocated within that handle scope until either the handle scope is 430 * allocated within that handle scope until either the handle scope is
431 * deleted or another handle scope is created. If there is already a 431 * deleted or another handle scope is created. If there is already a
432 * handle scope and a new one is created, all allocations will take 432 * handle scope and a new one is created, all allocations will take
433 * place in the new handle scope until it is deleted. After that, 433 * place in the new handle scope until it is deleted. After that,
434 * new handles will again be allocated in the original handle scope. 434 * new handles will again be allocated in the original handle scope.
435 * 435 *
436 * After the handle scope of a local handle has been deleted the 436 * After the handle scope of a local handle has been deleted the
437 * garbage collector will no longer track the object stored in the 437 * garbage collector will no longer track the object stored in the
438 * handle and may deallocate it. The behavior of accessing a handle 438 * handle and may deallocate it. The behavior of accessing a handle
439 * for which the handle scope has been deleted is undefined. 439 * for which the handle scope has been deleted is undefined.
440 */ 440 */
441 class V8EXPORT HandleScope { 441 class V8EXPORT HandleScope {
442 public: 442 public:
443 HandleScope(); 443 HandleScope();
444 444
445 ~HandleScope(); 445 ~HandleScope();
446 446
447 /** 447 /**
448 * Closes the handle scope and returns the value as a handle in the 448 * Closes the handle scope and returns the value as a handle in the
449 * previous scope, which is the new current scope after the call. 449 * previous scope, which is the new current scope after the call.
450 */ 450 */
451 template <class T> Local<T> Close(Handle<T> value); 451 template <class T> Local<T> Close(Handle<T> value);
452 452
453 /** 453 /**
454 * Counts the number of allocated handles. 454 * Counts the number of allocated handles.
455 */ 455 */
456 static int NumberOfHandles(); 456 static int NumberOfHandles();
457 457
458 /** 458 /**
459 * Creates a new handle with the given value. 459 * Creates a new handle with the given value.
460 */ 460 */
461 static internal::Object** CreateHandle(internal::Object* value); 461 static internal::Object** CreateHandle(internal::Object* value);
462 // Faster version, uses HeapObject to obtain the current Isolate. 462 // Faster version, uses HeapObject to obtain the current Isolate.
463 static internal::Object** CreateHandle(internal::HeapObject* value); 463 static internal::Object** CreateHandle(internal::HeapObject* value);
464 464
465 private: 465 private:
466 // Make it impossible to create heap-allocated or illegal handle 466 // Make it impossible to create heap-allocated or illegal handle
467 // scopes by disallowing certain operations. 467 // scopes by disallowing certain operations.
468 HandleScope(const HandleScope&); 468 HandleScope(const HandleScope&);
469 void operator=(const HandleScope&); 469 void operator=(const HandleScope&);
470 void* operator new(size_t size); 470 void* operator new(size_t size);
471 void operator delete(void*, size_t); 471 void operator delete(void*, size_t);
472 472
473 // This Data class is accessible internally as HandleScopeData through a 473 // This Data class is accessible internally as HandleScopeData through a
474 // typedef in the ImplementationUtilities class. 474 // typedef in the ImplementationUtilities class.
475 class V8EXPORT Data { 475 class V8EXPORT Data {
476 public: 476 public:
477 internal::Object** next; 477 internal::Object** next;
478 internal::Object** limit; 478 internal::Object** limit;
479 int level; 479 int level;
480 inline void Initialize() { 480 inline void Initialize() {
481 next = limit = NULL; 481 next = limit = NULL;
482 level = 0; 482 level = 0;
483 } 483 }
484 }; 484 };
485 485
486 void Leave(); 486 void Leave();
487 487
488 internal::Isolate* isolate_; 488 internal::Isolate* isolate_;
489 internal::Object** prev_next_; 489 internal::Object** prev_next_;
490 internal::Object** prev_limit_; 490 internal::Object** prev_limit_;
491 491
492 // Allow for the active closing of HandleScopes which allows to pass a handle 492 // Allow for the active closing of HandleScopes which allows to pass a handle
493 // from the HandleScope being closed to the next top most HandleScope. 493 // from the HandleScope being closed to the next top most HandleScope.
494 bool is_closed_; 494 bool is_closed_;
495 internal::Object** RawClose(internal::Object** value); 495 internal::Object** RawClose(internal::Object** value);
496 496
497 friend class ImplementationUtilities; 497 friend class ImplementationUtilities;
498 }; 498 };
499 499
500 500
501 // --- Special objects --- 501 // --- Special objects ---
502 502
503 503
504 /** 504 /**
505 * The superclass of values and API object templates. 505 * The superclass of values and API object templates.
506 */ 506 */
507 class V8EXPORT Data { 507 class V8EXPORT Data {
508 private: 508 private:
509 Data(); 509 Data();
510 }; 510 };
511 511
512 512
513 /** 513 /**
514 * Pre-compilation data that can be associated with a script. This 514 * Pre-compilation data that can be associated with a script. This
515 * data can be calculated for a script in advance of actually 515 * data can be calculated for a script in advance of actually
516 * compiling it, and can be stored between compilations. When script 516 * compiling it, and can be stored between compilations. When script
517 * data is given to the compile method compilation will be faster. 517 * data is given to the compile method compilation will be faster.
518 */ 518 */
519 class V8EXPORT ScriptData { // NOLINT 519 class V8EXPORT ScriptData { // NOLINT
520 public: 520 public:
521 virtual ~ScriptData() { } 521 virtual ~ScriptData() { }
522 522
523 /** 523 /**
524 * Pre-compiles the specified script (context-independent). 524 * Pre-compiles the specified script (context-independent).
525 * 525 *
526 * \param input Pointer to UTF-8 script source code. 526 * \param input Pointer to UTF-8 script source code.
527 * \param length Length of UTF-8 script source code. 527 * \param length Length of UTF-8 script source code.
528 */ 528 */
529 static ScriptData* PreCompile(const char* input, int length); 529 static ScriptData* PreCompile(const char* input, int length);
530 530
531 /** 531 /**
532 * Pre-compiles the specified script (context-independent). 532 * Pre-compiles the specified script (context-independent).
533 * 533 *
534 * NOTE: Pre-compilation using this method cannot happen on another thread 534 * NOTE: Pre-compilation using this method cannot happen on another thread
535 * without using Lockers. 535 * without using Lockers.
536 * 536 *
537 * \param source Script source code. 537 * \param source Script source code.
538 */ 538 */
539 static ScriptData* PreCompile(Handle<String> source); 539 static ScriptData* PreCompile(Handle<String> source);
540 540
541 /** 541 /**
542 * Load previous pre-compilation data. 542 * Load previous pre-compilation data.
543 * 543 *
544 * \param data Pointer to data returned by a call to Data() of a previous 544 * \param data Pointer to data returned by a call to Data() of a previous
545 * ScriptData. Ownership is not transferred. 545 * ScriptData. Ownership is not transferred.
546 * \param length Length of data. 546 * \param length Length of data.
547 */ 547 */
548 static ScriptData* New(const char* data, int length); 548 static ScriptData* New(const char* data, int length);
549 549
550 /** 550 /**
551 * Returns the length of Data(). 551 * Returns the length of Data().
552 */ 552 */
553 virtual int Length() = 0; 553 virtual int Length() = 0;
554 554
555 /** 555 /**
556 * Returns a serialized representation of this ScriptData that can later be 556 * Returns a serialized representation of this ScriptData that can later be
557 * passed to New(). NOTE: Serialized data is platform-dependent. 557 * passed to New(). NOTE: Serialized data is platform-dependent.
558 */ 558 */
559 virtual const char* Data() = 0; 559 virtual const char* Data() = 0;
560 560
561 /** 561 /**
562 * Returns true if the source code could not be parsed. 562 * Returns true if the source code could not be parsed.
563 */ 563 */
564 virtual bool HasError() = 0; 564 virtual bool HasError() = 0;
565 }; 565 };
566 566
567 567
568 /** 568 /**
569 * The origin, within a file, of a script. 569 * The origin, within a file, of a script.
570 */ 570 */
571 class ScriptOrigin { 571 class ScriptOrigin {
572 public: 572 public:
573 inline ScriptOrigin( 573 inline ScriptOrigin(
574 Handle<Value> resource_name, 574 Handle<Value> resource_name,
575 Handle<Integer> resource_line_offset = Handle<Integer>(), 575 Handle<Integer> resource_line_offset = Handle<Integer>(),
576 Handle<Integer> resource_column_offset = Handle<Integer>()) 576 Handle<Integer> resource_column_offset = Handle<Integer>())
577 : resource_name_(resource_name), 577 : resource_name_(resource_name),
578 resource_line_offset_(resource_line_offset), 578 resource_line_offset_(resource_line_offset),
579 resource_column_offset_(resource_column_offset) { } 579 resource_column_offset_(resource_column_offset) { }
580 inline Handle<Value> ResourceName() const; 580 inline Handle<Value> ResourceName() const;
581 inline Handle<Integer> ResourceLineOffset() const; 581 inline Handle<Integer> ResourceLineOffset() const;
582 inline Handle<Integer> ResourceColumnOffset() const; 582 inline Handle<Integer> ResourceColumnOffset() const;
583 private: 583 private:
584 Handle<Value> resource_name_; 584 Handle<Value> resource_name_;
585 Handle<Integer> resource_line_offset_; 585 Handle<Integer> resource_line_offset_;
586 Handle<Integer> resource_column_offset_; 586 Handle<Integer> resource_column_offset_;
587 }; 587 };
588 588
589 589
590 /** 590 /**
591 * A compiled JavaScript script. 591 * A compiled JavaScript script.
592 */ 592 */
593 class V8EXPORT Script { 593 class V8EXPORT Script {
594 public: 594 public:
595 /** 595 /**
596 * Compiles the specified script (context-independent). 596 * Compiles the specified script (context-independent).
597 * 597 *
598 * \param source Script source code. 598 * \param source Script source code.
599 * \param origin Script origin, owned by caller, no references are kept 599 * \param origin Script origin, owned by caller, no references are kept
600 * when New() returns 600 * when New() returns
601 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() 601 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
602 * using pre_data speeds compilation if it's done multiple times. 602 * using pre_data speeds compilation if it's done multiple times.
603 * Owned by caller, no references are kept when New() returns. 603 * Owned by caller, no references are kept when New() returns.
604 * \param script_data Arbitrary data associated with script. Using 604 * \param script_data Arbitrary data associated with script. Using
605 * this has same effect as calling SetData(), but allows data to be 605 * this has same effect as calling SetData(), but allows data to be
606 * available to compile event handlers. 606 * available to compile event handlers.
607 * \return Compiled script object (context independent; when run it 607 * \return Compiled script object (context independent; when run it
608 * will use the currently entered context). 608 * will use the currently entered context).
609 */ 609 */
610 static Local<Script> New(Handle<String> source, 610 static Local<Script> New(Handle<String> source,
611 ScriptOrigin* origin = NULL, 611 ScriptOrigin* origin = NULL,
612 ScriptData* pre_data = NULL, 612 ScriptData* pre_data = NULL,
613 Handle<String> script_data = Handle<String>()); 613 Handle<String> script_data = Handle<String>());
614 614
615 /** 615 /**
616 * Compiles the specified script using the specified file name 616 * Compiles the specified script using the specified file name
617 * object (typically a string) as the script's origin. 617 * object (typically a string) as the script's origin.
618 * 618 *
619 * \param source Script source code. 619 * \param source Script source code.
620 * \param file_name file name object (typically a string) to be used 620 * \param file_name file name object (typically a string) to be used
621 * as the script's origin. 621 * as the script's origin.
622 * \return Compiled script object (context independent; when run it 622 * \return Compiled script object (context independent; when run it
623 * will use the currently entered context). 623 * will use the currently entered context).
624 */ 624 */
625 static Local<Script> New(Handle<String> source, 625 static Local<Script> New(Handle<String> source,
626 Handle<Value> file_name); 626 Handle<Value> file_name);
627 627
628 /** 628 /**
629 * Compiles the specified script (bound to current context). 629 * Compiles the specified script (bound to current context).
630 * 630 *
631 * \param source Script source code. 631 * \param source Script source code.
632 * \param origin Script origin, owned by caller, no references are kept 632 * \param origin Script origin, owned by caller, no references are kept
633 * when Compile() returns 633 * when Compile() returns
634 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() 634 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
635 * using pre_data speeds compilation if it's done multiple times. 635 * using pre_data speeds compilation if it's done multiple times.
636 * Owned by caller, no references are kept when Compile() returns. 636 * Owned by caller, no references are kept when Compile() returns.
637 * \param script_data Arbitrary data associated with script. Using 637 * \param script_data Arbitrary data associated with script. Using
638 * this has same effect as calling SetData(), but makes data available 638 * this has same effect as calling SetData(), but makes data available
639 * earlier (i.e. to compile event handlers). 639 * earlier (i.e. to compile event handlers).
640 * \return Compiled script object, bound to the context that was active 640 * \return Compiled script object, bound to the context that was active
641 * when this function was called. When run it will always use this 641 * when this function was called. When run it will always use this
642 * context. 642 * context.
643 */ 643 */
644 static Local<Script> Compile(Handle<String> source, 644 static Local<Script> Compile(Handle<String> source,
645 ScriptOrigin* origin = NULL, 645 ScriptOrigin* origin = NULL,
646 ScriptData* pre_data = NULL, 646 ScriptData* pre_data = NULL,
647 Handle<String> script_data = Handle<String>()); 647 Handle<String> script_data = Handle<String>());
648 648
649 /** 649 /**
650 * Compiles the specified script using the specified file name 650 * Compiles the specified script using the specified file name
651 * object (typically a string) as the script's origin. 651 * object (typically a string) as the script's origin.
652 * 652 *
653 * \param source Script source code. 653 * \param source Script source code.
654 * \param file_name File name to use as script's origin 654 * \param file_name File name to use as script's origin
655 * \param script_data Arbitrary data associated with script. Using 655 * \param script_data Arbitrary data associated with script. Using
656 * this has same effect as calling SetData(), but makes data available 656 * this has same effect as calling SetData(), but makes data available
657 * earlier (i.e. to compile event handlers). 657 * earlier (i.e. to compile event handlers).
658 * \return Compiled script object, bound to the context that was active 658 * \return Compiled script object, bound to the context that was active
659 * when this function was called. When run it will always use this 659 * when this function was called. When run it will always use this
660 * context. 660 * context.
661 */ 661 */
662 static Local<Script> Compile(Handle<String> source, 662 static Local<Script> Compile(Handle<String> source,
663 Handle<Value> file_name, 663 Handle<Value> file_name,
664 Handle<String> script_data = Handle<String>()); 664 Handle<String> script_data = Handle<String>());
665 665
666 /** 666 /**
667 * Runs the script returning the resulting value. If the script is 667 * Runs the script returning the resulting value. If the script is
668 * context independent (created using ::New) it will be run in the 668 * context independent (created using ::New) it will be run in the
669 * currently entered context. If it is context specific (created 669 * currently entered context. If it is context specific (created
670 * using ::Compile) it will be run in the context in which it was 670 * using ::Compile) it will be run in the context in which it was
671 * compiled. 671 * compiled.
672 */ 672 */
673 Local<Value> Run(); 673 Local<Value> Run();
674 674
675 /** 675 /**
676 * Returns the script id value. 676 * Returns the script id value.
677 */ 677 */
678 Local<Value> Id(); 678 Local<Value> Id();
679 679
680 /** 680 /**
681 * Associate an additional data object with the script. This is mainly used 681 * Associate an additional data object with the script. This is mainly used
682 * with the debugger as this data object is only available through the 682 * with the debugger as this data object is only available through the
683 * debugger API. 683 * debugger API.
684 */ 684 */
685 void SetData(Handle<String> data); 685 void SetData(Handle<String> data);
686 }; 686 };
687 687
688 688
689 /** 689 /**
690 * An error message. 690 * An error message.
691 */ 691 */
692 class V8EXPORT Message { 692 class V8EXPORT Message {
693 public: 693 public:
694 Local<String> Get() const; 694 Local<String> Get() const;
695 Local<String> GetSourceLine() const; 695 Local<String> GetSourceLine() const;
696 696
697 /** 697 /**
698 * Returns the resource name for the script from where the function causing 698 * Returns the resource name for the script from where the function causing
699 * the error originates. 699 * the error originates.
700 */ 700 */
701 Handle<Value> GetScriptResourceName() const; 701 Handle<Value> GetScriptResourceName() const;
702 702
703 /** 703 /**
704 * Returns the resource data for the script from where the function causing 704 * Returns the resource data for the script from where the function causing
705 * the error originates. 705 * the error originates.
706 */ 706 */
707 Handle<Value> GetScriptData() const; 707 Handle<Value> GetScriptData() const;
708 708
709 /** 709 /**
710 * Exception stack trace. By default stack traces are not captured for 710 * Exception stack trace. By default stack traces are not captured for
711 * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows 711 * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
712 * to change this option. 712 * to change this option.
713 */ 713 */
714 Handle<StackTrace> GetStackTrace() const; 714 Handle<StackTrace> GetStackTrace() const;
715 715
716 /** 716 /**
717 * Returns the number, 1-based, of the line where the error occurred. 717 * Returns the number, 1-based, of the line where the error occurred.
718 */ 718 */
719 int GetLineNumber() const; 719 int GetLineNumber() const;
720 720
721 /** 721 /**
722 * Returns the index within the script of the first character where 722 * Returns the index within the script of the first character where
723 * the error occurred. 723 * the error occurred.
724 */ 724 */
725 int GetStartPosition() const; 725 int GetStartPosition() const;
726 726
727 /** 727 /**
728 * Returns the index within the script of the last character where 728 * Returns the index within the script of the last character where
729 * the error occurred. 729 * the error occurred.
730 */ 730 */
731 int GetEndPosition() const; 731 int GetEndPosition() const;
732 732
733 /** 733 /**
734 * Returns the index within the line of the first character where 734 * Returns the index within the line of the first character where
735 * the error occurred. 735 * the error occurred.
736 */ 736 */
737 int GetStartColumn() const; 737 int GetStartColumn() const;
738 738
739 /** 739 /**
740 * Returns the index within the line of the last character where 740 * Returns the index within the line of the last character where
741 * the error occurred. 741 * the error occurred.
742 */ 742 */
743 int GetEndColumn() const; 743 int GetEndColumn() const;
744 744
745 // TODO(1245381): Print to a string instead of on a FILE. 745 // TODO(1245381): Print to a string instead of on a FILE.
746 static void PrintCurrentStackTrace(FILE* out); 746 static void PrintCurrentStackTrace(FILE* out);
747 747
748 static const int kNoLineNumberInfo = 0; 748 static const int kNoLineNumberInfo = 0;
749 static const int kNoColumnInfo = 0; 749 static const int kNoColumnInfo = 0;
750 }; 750 };
751 751
752 752
753 /** 753 /**
754 * Representation of a JavaScript stack trace. The information collected is a 754 * Representation of a JavaScript stack trace. The information collected is a
755 * snapshot of the execution stack and the information remains valid after 755 * snapshot of the execution stack and the information remains valid after
756 * execution continues. 756 * execution continues.
757 */ 757 */
758 class V8EXPORT StackTrace { 758 class V8EXPORT StackTrace {
759 public: 759 public:
760 /** 760 /**
761 * Flags that determine what information is placed captured for each 761 * Flags that determine what information is placed captured for each
762 * StackFrame when grabbing the current stack trace. 762 * StackFrame when grabbing the current stack trace.
763 */ 763 */
764 enum StackTraceOptions { 764 enum StackTraceOptions {
765 kLineNumber = 1, 765 kLineNumber = 1,
766 kColumnOffset = 1 << 1 | kLineNumber, 766 kColumnOffset = 1 << 1 | kLineNumber,
767 kScriptName = 1 << 2, 767 kScriptName = 1 << 2,
768 kFunctionName = 1 << 3, 768 kFunctionName = 1 << 3,
769 kIsEval = 1 << 4, 769 kIsEval = 1 << 4,
770 kIsConstructor = 1 << 5, 770 kIsConstructor = 1 << 5,
771 kScriptNameOrSourceURL = 1 << 6, 771 kScriptNameOrSourceURL = 1 << 6,
772 kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, 772 kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
773 kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL 773 kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
774 }; 774 };
775 775
776 /** 776 /**
777 * Returns a StackFrame at a particular index. 777 * Returns a StackFrame at a particular index.
778 */ 778 */
779 Local<StackFrame> GetFrame(uint32_t index) const; 779 Local<StackFrame> GetFrame(uint32_t index) const;
780 780
781 /** 781 /**
782 * Returns the number of StackFrames. 782 * Returns the number of StackFrames.
783 */ 783 */
784 int GetFrameCount() const; 784 int GetFrameCount() const;
785 785
786 /** 786 /**
787 * Returns StackTrace as a v8::Array that contains StackFrame objects. 787 * Returns StackTrace as a v8::Array that contains StackFrame objects.
788 */ 788 */
789 Local<Array> AsArray(); 789 Local<Array> AsArray();
790 790
791 /** 791 /**
792 * Grab a snapshot of the current JavaScript execution stack. 792 * Grab a snapshot of the current JavaScript execution stack.
793 * 793 *
794 * \param frame_limit The maximum number of stack frames we want to capture. 794 * \param frame_limit The maximum number of stack frames we want to capture.
795 * \param options Enumerates the set of things we will capture for each 795 * \param options Enumerates the set of things we will capture for each
796 * StackFrame. 796 * StackFrame.
797 */ 797 */
798 static Local<StackTrace> CurrentStackTrace( 798 static Local<StackTrace> CurrentStackTrace(
799 int frame_limit, 799 int frame_limit,
800 StackTraceOptions options = kOverview); 800 StackTraceOptions options = kOverview);
801 }; 801 };
802 802
803 803
804 /** 804 /**
805 * A single JavaScript stack frame. 805 * A single JavaScript stack frame.
806 */ 806 */
807 class V8EXPORT StackFrame { 807 class V8EXPORT StackFrame {
808 public: 808 public:
809 /** 809 /**
810 * Returns the number, 1-based, of the line for the associate function call. 810 * Returns the number, 1-based, of the line for the associate function call.
811 * This method will return Message::kNoLineNumberInfo if it is unable to 811 * This method will return Message::kNoLineNumberInfo if it is unable to
812 * retrieve the line number, or if kLineNumber was not passed as an option 812 * retrieve the line number, or if kLineNumber was not passed as an option
813 * when capturing the StackTrace. 813 * when capturing the StackTrace.
814 */ 814 */
815 int GetLineNumber() const; 815 int GetLineNumber() const;
816 816
817 /** 817 /**
818 * Returns the 1-based column offset on the line for the associated function 818 * Returns the 1-based column offset on the line for the associated function
819 * call. 819 * call.
820 * This method will return Message::kNoColumnInfo if it is unable to retrieve 820 * This method will return Message::kNoColumnInfo if it is unable to retrieve
821 * the column number, or if kColumnOffset was not passed as an option when 821 * the column number, or if kColumnOffset was not passed as an option when
822 * capturing the StackTrace. 822 * capturing the StackTrace.
823 */ 823 */
824 int GetColumn() const; 824 int GetColumn() const;
825 825
826 /** 826 /**
827 * Returns the name of the resource that contains the script for the 827 * Returns the name of the resource that contains the script for the
828 * function for this StackFrame. 828 * function for this StackFrame.
829 */ 829 */
830 Local<String> GetScriptName() const; 830 Local<String> GetScriptName() const;
831 831
832 /** 832 /**
833 * Returns the name of the resource that contains the script for the 833 * Returns the name of the resource that contains the script for the
834 * function for this StackFrame or sourceURL value if the script name 834 * function for this StackFrame or sourceURL value if the script name
835 * is undefined and its source ends with //@ sourceURL=... string. 835 * is undefined and its source ends with //@ sourceURL=... string.
836 */ 836 */
837 Local<String> GetScriptNameOrSourceURL() const; 837 Local<String> GetScriptNameOrSourceURL() const;
838 838
839 /** 839 /**
840 * Returns the name of the function associated with this stack frame. 840 * Returns the name of the function associated with this stack frame.
841 */ 841 */
842 Local<String> GetFunctionName() const; 842 Local<String> GetFunctionName() const;
843 843
844 /** 844 /**
845 * Returns whether or not the associated function is compiled via a call to 845 * Returns whether or not the associated function is compiled via a call to
846 * eval(). 846 * eval().
847 */ 847 */
848 bool IsEval() const; 848 bool IsEval() const;
849 849
850 /** 850 /**
851 * Returns whether or not the associated function is called as a 851 * Returns whether or not the associated function is called as a
852 * constructor via "new". 852 * constructor via "new".
853 */ 853 */
854 bool IsConstructor() const; 854 bool IsConstructor() const;
855 }; 855 };
856 856
857 857
858 // --- Value --- 858 // --- Value ---
859 859
860 860
861 /** 861 /**
862 * The superclass of all JavaScript values and objects. 862 * The superclass of all JavaScript values and objects.
863 */ 863 */
864 class Value : public Data { 864 class Value : public Data {
865 public: 865 public:
866 /** 866 /**
867 * Returns true if this value is the undefined value. See ECMA-262 867 * Returns true if this value is the undefined value. See ECMA-262
868 * 4.3.10. 868 * 4.3.10.
869 */ 869 */
870 inline bool IsUndefined() const; 870 inline bool IsUndefined() const;
871 871
872 /** 872 /**
873 * Returns true if this value is the null value. See ECMA-262 873 * Returns true if this value is the null value. See ECMA-262
874 * 4.3.11. 874 * 4.3.11.
875 */ 875 */
876 inline bool IsNull() const; 876 inline bool IsNull() const;
877 877
878 /** 878 /**
879 * Returns true if this value is true. 879 * Returns true if this value is true.
880 */ 880 */
881 V8EXPORT bool IsTrue() const; 881 V8EXPORT bool IsTrue() const;
882 882
883 /** 883 /**
884 * Returns true if this value is false. 884 * Returns true if this value is false.
885 */ 885 */
886 V8EXPORT bool IsFalse() const; 886 V8EXPORT bool IsFalse() const;
887 887
888 /** 888 /**
889 * Returns true if this value is an instance of the String type. 889 * Returns true if this value is an instance of the String type.
890 * See ECMA-262 8.4. 890 * See ECMA-262 8.4.
891 */ 891 */
892 inline bool IsString() const; 892 inline bool IsString() const;
893 893
894 /** 894 /**
895 * Returns true if this value is a function. 895 * Returns true if this value is a function.
896 */ 896 */
897 V8EXPORT bool IsFunction() const; 897 V8EXPORT bool IsFunction() const;
898 898
899 /** 899 /**
900 * Returns true if this value is an array. 900 * Returns true if this value is an array.
901 */ 901 */
902 V8EXPORT bool IsArray() const; 902 V8EXPORT bool IsArray() const;
903 903
904 /** 904 /**
905 * Returns true if this value is an object. 905 * Returns true if this value is an object.
906 */ 906 */
907 V8EXPORT bool IsObject() const; 907 V8EXPORT bool IsObject() const;
908 908
909 /** 909 /**
910 * Returns true if this value is boolean. 910 * Returns true if this value is boolean.
911 */ 911 */
912 V8EXPORT bool IsBoolean() const; 912 V8EXPORT bool IsBoolean() const;
913 913
914 /** 914 /**
915 * Returns true if this value is a number. 915 * Returns true if this value is a number.
916 */ 916 */
917 V8EXPORT bool IsNumber() const; 917 V8EXPORT bool IsNumber() const;
918 918
919 /** 919 /**
920 * Returns true if this value is external. 920 * Returns true if this value is external.
921 */ 921 */
922 V8EXPORT bool IsExternal() const; 922 V8EXPORT bool IsExternal() const;
923 923
924 /** 924 /**
925 * Returns true if this value is a 32-bit signed integer. 925 * Returns true if this value is a 32-bit signed integer.
926 */ 926 */
927 V8EXPORT bool IsInt32() const; 927 V8EXPORT bool IsInt32() const;
928 928
929 /** 929 /**
930 * Returns true if this value is a 32-bit unsigned integer. 930 * Returns true if this value is a 32-bit unsigned integer.
931 */ 931 */
932 V8EXPORT bool IsUint32() const; 932 V8EXPORT bool IsUint32() const;
933 933
934 /** 934 /**
935 * Returns true if this value is a Date. 935 * Returns true if this value is a Date.
936 */ 936 */
937 V8EXPORT bool IsDate() const; 937 V8EXPORT bool IsDate() const;
938 938
939 /** 939 /**
940 * Returns true if this value is a Boolean object. 940 * Returns true if this value is a Boolean object.
941 */ 941 */
942 V8EXPORT bool IsBooleanObject() const; 942 V8EXPORT bool IsBooleanObject() const;
943 943
944 /** 944 /**
945 * Returns true if this value is a Number object. 945 * Returns true if this value is a Number object.
946 */ 946 */
947 V8EXPORT bool IsNumberObject() const; 947 V8EXPORT bool IsNumberObject() const;
948 948
949 /** 949 /**
950 * Returns true if this value is a String object. 950 * Returns true if this value is a String object.
951 */ 951 */
952 V8EXPORT bool IsStringObject() const; 952 V8EXPORT bool IsStringObject() const;
953 953
954 /** 954 /**
955 * Returns true if this value is a NativeError. 955 * Returns true if this value is a NativeError.
956 */ 956 */
957 V8EXPORT bool IsNativeError() const; 957 V8EXPORT bool IsNativeError() const;
958 958
959 /** 959 /**
960 * Returns true if this value is a RegExp. 960 * Returns true if this value is a RegExp.
961 */ 961 */
962 V8EXPORT bool IsRegExp() const; 962 V8EXPORT bool IsRegExp() const;
963 963
964 V8EXPORT Local<Boolean> ToBoolean() const; 964 V8EXPORT Local<Boolean> ToBoolean() const;
965 V8EXPORT Local<Number> ToNumber() const; 965 V8EXPORT Local<Number> ToNumber() const;
966 V8EXPORT Local<String> ToString() const; 966 V8EXPORT Local<String> ToString() const;
967 V8EXPORT Local<String> ToDetailString() const; 967 V8EXPORT Local<String> ToDetailString() const;
968 V8EXPORT Local<Object> ToObject() const; 968 V8EXPORT Local<Object> ToObject() const;
969 V8EXPORT Local<Integer> ToInteger() const; 969 V8EXPORT Local<Integer> ToInteger() const;
970 V8EXPORT Local<Uint32> ToUint32() const; 970 V8EXPORT Local<Uint32> ToUint32() const;
971 V8EXPORT Local<Int32> ToInt32() const; 971 V8EXPORT Local<Int32> ToInt32() const;
972 972
973 /** 973 /**
974 * Attempts to convert a string to an array index. 974 * Attempts to convert a string to an array index.
975 * Returns an empty handle if the conversion fails. 975 * Returns an empty handle if the conversion fails.
976 */ 976 */
977 V8EXPORT Local<Uint32> ToArrayIndex() const; 977 V8EXPORT Local<Uint32> ToArrayIndex() const;
978 978
979 V8EXPORT bool BooleanValue() const; 979 V8EXPORT bool BooleanValue() const;
980 V8EXPORT double NumberValue() const; 980 V8EXPORT double NumberValue() const;
981 V8EXPORT int64_t IntegerValue() const; 981 V8EXPORT int64_t IntegerValue() const;
982 V8EXPORT uint32_t Uint32Value() const; 982 V8EXPORT uint32_t Uint32Value() const;
983 V8EXPORT int32_t Int32Value() const; 983 V8EXPORT int32_t Int32Value() const;
984 984
985 /** JS == */ 985 /** JS == */
986 V8EXPORT bool Equals(Handle<Value> that) const; 986 V8EXPORT bool Equals(Handle<Value> that) const;
987 V8EXPORT bool StrictEquals(Handle<Value> that) const; 987 V8EXPORT bool StrictEquals(Handle<Value> that) const;
988 988
989 private: 989 private:
990 inline bool QuickIsUndefined() const; 990 inline bool QuickIsUndefined() const;
991 inline bool QuickIsNull() const; 991 inline bool QuickIsNull() const;
992 inline bool QuickIsString() const; 992 inline bool QuickIsString() const;
993 V8EXPORT bool FullIsUndefined() const; 993 V8EXPORT bool FullIsUndefined() const;
994 V8EXPORT bool FullIsNull() const; 994 V8EXPORT bool FullIsNull() const;
995 V8EXPORT bool FullIsString() const; 995 V8EXPORT bool FullIsString() const;
996 }; 996 };
997 997
998 998
999 /** 999 /**
1000 * The superclass of primitive values. See ECMA-262 4.3.2. 1000 * The superclass of primitive values. See ECMA-262 4.3.2.
1001 */ 1001 */
1002 class Primitive : public Value { }; 1002 class Primitive : public Value { };
1003 1003
1004 1004
1005 /** 1005 /**
1006 * A primitive boolean value (ECMA-262, 4.3.14). Either the true 1006 * A primitive boolean value (ECMA-262, 4.3.14). Either the true
1007 * or false value. 1007 * or false value.
1008 */ 1008 */
1009 class Boolean : public Primitive { 1009 class Boolean : public Primitive {
1010 public: 1010 public:
1011 V8EXPORT bool Value() const; 1011 V8EXPORT bool Value() const;
1012 static inline Handle<Boolean> New(bool value); 1012 static inline Handle<Boolean> New(bool value);
1013 }; 1013 };
1014 1014
1015 1015
1016 /** 1016 /**
1017 * A JavaScript string value (ECMA-262, 4.3.17). 1017 * A JavaScript string value (ECMA-262, 4.3.17).
1018 */ 1018 */
1019 class String : public Primitive { 1019 class String : public Primitive {
1020 public: 1020 public:
1021 enum Encoding { 1021 enum Encoding {
1022 UNKNOWN_ENCODING = 0x1, 1022 UNKNOWN_ENCODING = 0x1,
1023 TWO_BYTE_ENCODING = 0x0, 1023 TWO_BYTE_ENCODING = 0x0,
1024 ASCII_ENCODING = 0x4 1024 ASCII_ENCODING = 0x4
1025 }; 1025 };
1026 /** 1026 /**
1027 * Returns the number of characters in this string. 1027 * Returns the number of characters in this string.
1028 */ 1028 */
1029 V8EXPORT int Length() const; 1029 V8EXPORT int Length() const;
1030 1030
1031 /** 1031 /**
1032 * Returns the number of bytes in the UTF-8 encoded 1032 * Returns the number of bytes in the UTF-8 encoded
1033 * representation of this string. 1033 * representation of this string.
1034 */ 1034 */
1035 V8EXPORT int Utf8Length() const; 1035 V8EXPORT int Utf8Length() const;
1036 1036
1037 /** 1037 /**
1038 * A fast conservative check for non-ASCII characters. May 1038 * A fast conservative check for non-ASCII characters. May
1039 * return true even for ASCII strings, but if it returns 1039 * return true even for ASCII strings, but if it returns
1040 * false you can be sure that all characters are in the range 1040 * false you can be sure that all characters are in the range
1041 * 0-127. 1041 * 0-127.
1042 */ 1042 */
1043 V8EXPORT bool MayContainNonAscii() const; 1043 V8EXPORT bool MayContainNonAscii() const;
1044 1044
1045 /** 1045 /**
1046 * Write the contents of the string to an external buffer. 1046 * Write the contents of the string to an external buffer.
1047 * If no arguments are given, expects the buffer to be large 1047 * If no arguments are given, expects the buffer to be large
1048 * enough to hold the entire string and NULL terminator. Copies 1048 * enough to hold the entire string and NULL terminator. Copies
1049 * the contents of the string and the NULL terminator into the 1049 * the contents of the string and the NULL terminator into the
1050 * buffer. 1050 * buffer.
1051 * 1051 *
1052 * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop 1052 * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
1053 * before the end of the buffer. 1053 * before the end of the buffer.
1054 * 1054 *
1055 * Copies up to length characters into the output buffer. 1055 * Copies up to length characters into the output buffer.
1056 * Only null-terminates if there is enough space in the buffer. 1056 * Only null-terminates if there is enough space in the buffer.
1057 * 1057 *
1058 * \param buffer The buffer into which the string will be copied. 1058 * \param buffer The buffer into which the string will be copied.
1059 * \param start The starting position within the string at which 1059 * \param start The starting position within the string at which
1060 * copying begins. 1060 * copying begins.
1061 * \param length The number of characters to copy from the string. For 1061 * \param length The number of characters to copy from the string. For
1062 * WriteUtf8 the number of bytes in the buffer. 1062 * WriteUtf8 the number of bytes in the buffer.
1063 * \param nchars_ref The number of characters written, can be NULL. 1063 * \param nchars_ref The number of characters written, can be NULL.
1064 * \param options Various options that might affect performance of this or 1064 * \param options Various options that might affect performance of this or
1065 * subsequent operations. 1065 * subsequent operations.
1066 * \return The number of characters copied to the buffer excluding the null 1066 * \return The number of characters copied to the buffer excluding the null
1067 * terminator. For WriteUtf8: The number of bytes copied to the buffer 1067 * terminator. For WriteUtf8: The number of bytes copied to the buffer
1068 * including the null terminator (if written). 1068 * including the null terminator (if written).
1069 */ 1069 */
1070 enum WriteOptions { 1070 enum WriteOptions {
1071 NO_OPTIONS = 0, 1071 NO_OPTIONS = 0,
1072 HINT_MANY_WRITES_EXPECTED = 1, 1072 HINT_MANY_WRITES_EXPECTED = 1,
1073 NO_NULL_TERMINATION = 2, 1073 NO_NULL_TERMINATION = 2,
1074 PRESERVE_ASCII_NULL = 4 1074 PRESERVE_ASCII_NULL = 4
1075 }; 1075 };
1076 1076
1077 // 16-bit character codes. 1077 // 16-bit character codes.
1078 V8EXPORT int Write(uint16_t* buffer, 1078 V8EXPORT int Write(uint16_t* buffer,
1079 int start = 0, 1079 int start = 0,
1080 int length = -1, 1080 int length = -1,
1081 int options = NO_OPTIONS) const; 1081 int options = NO_OPTIONS) const;
1082 // ASCII characters. 1082 // ASCII characters.
1083 V8EXPORT int WriteAscii(char* buffer, 1083 V8EXPORT int WriteAscii(char* buffer,
1084 int start = 0, 1084 int start = 0,
1085 int length = -1, 1085 int length = -1,
1086 int options = NO_OPTIONS) const; 1086 int options = NO_OPTIONS) const;
1087 // UTF-8 encoded characters. 1087 // UTF-8 encoded characters.
1088 V8EXPORT int WriteUtf8(char* buffer, 1088 V8EXPORT int WriteUtf8(char* buffer,
1089 int length = -1, 1089 int length = -1,
1090 int* nchars_ref = NULL, 1090 int* nchars_ref = NULL,
1091 int options = NO_OPTIONS) const; 1091 int options = NO_OPTIONS) const;
1092 1092
1093 /** 1093 /**
1094 * A zero length string. 1094 * A zero length string.
1095 */ 1095 */
1096 V8EXPORT static v8::Local<v8::String> Empty(); 1096 V8EXPORT static v8::Local<v8::String> Empty();
1097 inline static v8::Local<v8::String> Empty(Isolate* isolate); 1097 inline static v8::Local<v8::String> Empty(Isolate* isolate);
1098 1098
1099 /** 1099 /**
1100 * Returns true if the string is external 1100 * Returns true if the string is external
1101 */ 1101 */
1102 V8EXPORT bool IsExternal() const; 1102 V8EXPORT bool IsExternal() const;
1103 1103
1104 /** 1104 /**
1105 * Returns true if the string is both external and ASCII 1105 * Returns true if the string is both external and ASCII
1106 */ 1106 */
1107 V8EXPORT bool IsExternalAscii() const; 1107 V8EXPORT bool IsExternalAscii() const;
1108 1108
1109 class V8EXPORT ExternalStringResourceBase { // NOLINT 1109 class V8EXPORT ExternalStringResourceBase { // NOLINT
1110 public: 1110 public:
1111 virtual ~ExternalStringResourceBase() {} 1111 virtual ~ExternalStringResourceBase() {}
1112 1112
1113 protected: 1113 protected:
1114 ExternalStringResourceBase() {} 1114 ExternalStringResourceBase() {}
1115 1115
1116 /** 1116 /**
1117 * Internally V8 will call this Dispose method when the external string 1117 * Internally V8 will call this Dispose method when the external string
1118 * resource is no longer needed. The default implementation will use the 1118 * resource is no longer needed. The default implementation will use the
1119 * delete operator. This method can be overridden in subclasses to 1119 * delete operator. This method can be overridden in subclasses to
1120 * control how allocated external string resources are disposed. 1120 * control how allocated external string resources are disposed.
1121 */ 1121 */
1122 virtual void Dispose() { delete this; } 1122 virtual void Dispose() { delete this; }
1123 1123
1124 private: 1124 private:
1125 // Disallow copying and assigning. 1125 // Disallow copying and assigning.
1126 ExternalStringResourceBase(const ExternalStringResourceBase&); 1126 ExternalStringResourceBase(const ExternalStringResourceBase&);
1127 void operator=(const ExternalStringResourceBase&); 1127 void operator=(const ExternalStringResourceBase&);
1128 1128
1129 friend class v8::internal::Heap; 1129 friend class v8::internal::Heap;
1130 }; 1130 };
1131 1131
1132 /** 1132 /**
1133 * An ExternalStringResource is a wrapper around a two-byte string 1133 * An ExternalStringResource is a wrapper around a two-byte string
1134 * buffer that resides outside V8's heap. Implement an 1134 * buffer that resides outside V8's heap. Implement an
1135 * ExternalStringResource to manage the life cycle of the underlying 1135 * ExternalStringResource to manage the life cycle of the underlying
1136 * buffer. Note that the string data must be immutable. 1136 * buffer. Note that the string data must be immutable.
1137 */ 1137 */
1138 class V8EXPORT ExternalStringResource 1138 class V8EXPORT ExternalStringResource
1139 : public ExternalStringResourceBase { 1139 : public ExternalStringResourceBase {
1140 public: 1140 public:
1141 /** 1141 /**
1142 * Override the destructor to manage the life cycle of the underlying 1142 * Override the destructor to manage the life cycle of the underlying
1143 * buffer. 1143 * buffer.
1144 */ 1144 */
1145 virtual ~ExternalStringResource() {} 1145 virtual ~ExternalStringResource() {}
1146 1146
1147 /** 1147 /**
1148 * The string data from the underlying buffer. 1148 * The string data from the underlying buffer.
1149 */ 1149 */
1150 virtual const uint16_t* data() const = 0; 1150 virtual const uint16_t* data() const = 0;
1151 1151
1152 /** 1152 /**
1153 * The length of the string. That is, the number of two-byte characters. 1153 * The length of the string. That is, the number of two-byte characters.
1154 */ 1154 */
1155 virtual size_t length() const = 0; 1155 virtual size_t length() const = 0;
1156 1156
1157 protected: 1157 protected:
1158 ExternalStringResource() {} 1158 ExternalStringResource() {}
1159 }; 1159 };
1160 1160
1161 /** 1161 /**
1162 * An ExternalAsciiStringResource is a wrapper around an ASCII 1162 * An ExternalAsciiStringResource is a wrapper around an ASCII
1163 * string buffer that resides outside V8's heap. Implement an 1163 * string buffer that resides outside V8's heap. Implement an
1164 * ExternalAsciiStringResource to manage the life cycle of the 1164 * ExternalAsciiStringResource to manage the life cycle of the
1165 * underlying buffer. Note that the string data must be immutable 1165 * underlying buffer. Note that the string data must be immutable
1166 * and that the data must be strict (7-bit) ASCII, not Latin-1 or 1166 * and that the data must be strict (7-bit) ASCII, not Latin-1 or
1167 * UTF-8, which would require special treatment internally in the 1167 * UTF-8, which would require special treatment internally in the
1168 * engine and, in the case of UTF-8, do not allow efficient indexing. 1168 * engine and, in the case of UTF-8, do not allow efficient indexing.
1169 * Use String::New or convert to 16 bit data for non-ASCII. 1169 * Use String::New or convert to 16 bit data for non-ASCII.
1170 */ 1170 */
1171 1171
1172 class V8EXPORT ExternalAsciiStringResource 1172 class V8EXPORT ExternalAsciiStringResource
1173 : public ExternalStringResourceBase { 1173 : public ExternalStringResourceBase {
1174 public: 1174 public:
1175 /** 1175 /**
1176 * Override the destructor to manage the life cycle of the underlying 1176 * Override the destructor to manage the life cycle of the underlying
1177 * buffer. 1177 * buffer.
1178 */ 1178 */
1179 virtual ~ExternalAsciiStringResource() {} 1179 virtual ~ExternalAsciiStringResource() {}
1180 /** The string data from the underlying buffer.*/ 1180 /** The string data from the underlying buffer.*/
1181 virtual const char* data() const = 0; 1181 virtual const char* data() const = 0;
1182 /** The number of ASCII characters in the string.*/ 1182 /** The number of ASCII characters in the string.*/
1183 virtual size_t length() const = 0; 1183 virtual size_t length() const = 0;
1184 protected: 1184 protected:
1185 ExternalAsciiStringResource() {} 1185 ExternalAsciiStringResource() {}
1186 }; 1186 };
1187 1187
1188 /** 1188 /**
1189 * If the string is an external string, return the ExternalStringResourceBase 1189 * If the string is an external string, return the ExternalStringResourceBase
1190 * regardless of the encoding, otherwise return NULL. The encoding of the 1190 * regardless of the encoding, otherwise return NULL. The encoding of the
1191 * string is returned in encoding_out. 1191 * string is returned in encoding_out.
1192 */ 1192 */
1193 inline ExternalStringResourceBase* GetExternalStringResourceBase( 1193 inline ExternalStringResourceBase* GetExternalStringResourceBase(
1194 Encoding* encoding_out) const; 1194 Encoding* encoding_out) const;
1195 1195
1196 /** 1196 /**
1197 * Get the ExternalStringResource for an external string. Returns 1197 * Get the ExternalStringResource for an external string. Returns
1198 * NULL if IsExternal() doesn't return true. 1198 * NULL if IsExternal() doesn't return true.
1199 */ 1199 */
1200 inline ExternalStringResource* GetExternalStringResource() const; 1200 inline ExternalStringResource* GetExternalStringResource() const;
1201 1201
1202 /** 1202 /**
1203 * Get the ExternalAsciiStringResource for an external ASCII string. 1203 * Get the ExternalAsciiStringResource for an external ASCII string.
1204 * Returns NULL if IsExternalAscii() doesn't return true. 1204 * Returns NULL if IsExternalAscii() doesn't return true.
1205 */ 1205 */
1206 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() 1206 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource()
1207 const; 1207 const;
1208 1208
1209 static inline String* Cast(v8::Value* obj); 1209 static inline String* Cast(v8::Value* obj);
1210 1210
1211 /** 1211 /**
1212 * Allocates a new string from either UTF-8 encoded or ASCII data. 1212 * Allocates a new string from either UTF-8 encoded or ASCII data.
1213 * The second parameter 'length' gives the buffer length. 1213 * The second parameter 'length' gives the buffer length.
1214 * If the data is UTF-8 encoded, the caller must 1214 * If the data is UTF-8 encoded, the caller must
1215 * be careful to supply the length parameter. 1215 * be careful to supply the length parameter.
1216 * If it is not given, the function calls 1216 * If it is not given, the function calls
1217 * 'strlen' to determine the buffer length, it might be 1217 * 'strlen' to determine the buffer length, it might be
1218 * wrong if 'data' contains a null character. 1218 * wrong if 'data' contains a null character.
1219 */ 1219 */
1220 V8EXPORT static Local<String> New(const char* data, int length = -1); 1220 V8EXPORT static Local<String> New(const char* data, int length = -1);
1221 1221
1222 /** Allocates a new string from 16-bit character codes.*/ 1222 /** Allocates a new string from 16-bit character codes.*/
1223 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1); 1223 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1);
1224 1224
1225 /** Creates a symbol. Returns one if it exists already.*/ 1225 /** Creates a symbol. Returns one if it exists already.*/
1226 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1); 1226 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1);
1227 1227
1228 /** 1228 /**
1229 * Creates a new string by concatenating the left and the right strings 1229 * Creates a new string by concatenating the left and the right strings
1230 * passed in as parameters. 1230 * passed in as parameters.
1231 */ 1231 */
1232 V8EXPORT static Local<String> Concat(Handle<String> left, 1232 V8EXPORT static Local<String> Concat(Handle<String> left,
1233 Handle<String> right); 1233 Handle<String> right);
1234 1234
1235 /** 1235 /**
1236 * Creates a new external string using the data defined in the given 1236 * Creates a new external string using the data defined in the given
1237 * resource. When the external string is no longer live on V8's heap the 1237 * resource. When the external string is no longer live on V8's heap the
1238 * resource will be disposed by calling its Dispose method. The caller of 1238 * resource will be disposed by calling its Dispose method. The caller of
1239 * this function should not otherwise delete or modify the resource. Neither 1239 * this function should not otherwise delete or modify the resource. Neither
1240 * should the underlying buffer be deallocated or modified except through the 1240 * should the underlying buffer be deallocated or modified except through the
1241 * destructor of the external string resource. 1241 * destructor of the external string resource.
1242 */ 1242 */
1243 V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); 1243 V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource);
1244 1244
1245 /** 1245 /**
1246 * Associate an external string resource with this string by transforming it 1246 * Associate an external string resource with this string by transforming it
1247 * in place so that existing references to this string in the JavaScript heap 1247 * in place so that existing references to this string in the JavaScript heap
1248 * will use the external string resource. The external string resource's 1248 * will use the external string resource. The external string resource's
1249 * character contents need to be equivalent to this string. 1249 * character contents need to be equivalent to this string.
1250 * Returns true if the string has been changed to be an external string. 1250 * Returns true if the string has been changed to be an external string.
1251 * The string is not modified if the operation fails. See NewExternal for 1251 * The string is not modified if the operation fails. See NewExternal for
1252 * information on the lifetime of the resource. 1252 * information on the lifetime of the resource.
1253 */ 1253 */
1254 V8EXPORT bool MakeExternal(ExternalStringResource* resource); 1254 V8EXPORT bool MakeExternal(ExternalStringResource* resource);
1255 1255
1256 /** 1256 /**
1257 * Creates a new external string using the ASCII data defined in the given 1257 * Creates a new external string using the ASCII data defined in the given
1258 * resource. When the external string is no longer live on V8's heap the 1258 * resource. When the external string is no longer live on V8's heap the
1259 * resource will be disposed by calling its Dispose method. The caller of 1259 * resource will be disposed by calling its Dispose method. The caller of
1260 * this function should not otherwise delete or modify the resource. Neither 1260 * this function should not otherwise delete or modify the resource. Neither
1261 * should the underlying buffer be deallocated or modified except through the 1261 * should the underlying buffer be deallocated or modified except through the
1262 * destructor of the external string resource. 1262 * destructor of the external string resource.
1263 */ V8EXPORT static Local<String> NewExternal( 1263 */ V8EXPORT static Local<String> NewExternal(
1264 ExternalAsciiStringResource* resource); 1264 ExternalAsciiStringResource* resource);
1265 1265
1266 /** 1266 /**
1267 * Associate an external string resource with this string by transforming it 1267 * Associate an external string resource with this string by transforming it
1268 * in place so that existing references to this string in the JavaScript heap 1268 * in place so that existing references to this string in the JavaScript heap
1269 * will use the external string resource. The external string resource's 1269 * will use the external string resource. The external string resource's
1270 * character contents need to be equivalent to this string. 1270 * character contents need to be equivalent to this string.
1271 * Returns true if the string has been changed to be an external string. 1271 * Returns true if the string has been changed to be an external string.
1272 * The string is not modified if the operation fails. See NewExternal for 1272 * The string is not modified if the operation fails. See NewExternal for
1273 * information on the lifetime of the resource. 1273 * information on the lifetime of the resource.
1274 */ 1274 */
1275 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); 1275 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
1276 1276
1277 /** 1277 /**
1278 * Returns true if this string can be made external. 1278 * Returns true if this string can be made external.
1279 */ 1279 */
1280 V8EXPORT bool CanMakeExternal(); 1280 V8EXPORT bool CanMakeExternal();
1281 1281
1282 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ 1282 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/
1283 V8EXPORT static Local<String> NewUndetectable(const char* data, 1283 V8EXPORT static Local<String> NewUndetectable(const char* data,
1284 int length = -1); 1284 int length = -1);
1285 1285
1286 /** Creates an undetectable string from the supplied 16-bit character codes.*/ 1286 /** Creates an undetectable string from the supplied 16-bit character codes.*/
1287 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, 1287 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
1288 int length = -1); 1288 int length = -1);
1289 1289
1290 /** 1290 /**
1291 * Converts an object to a UTF-8-encoded character array. Useful if 1291 * Converts an object to a UTF-8-encoded character array. Useful if
1292 * you want to print the object. If conversion to a string fails 1292 * you want to print the object. If conversion to a string fails
1293 * (e.g. due to an exception in the toString() method of the object) 1293 * (e.g. due to an exception in the toString() method of the object)
1294 * then the length() method returns 0 and the * operator returns 1294 * then the length() method returns 0 and the * operator returns
1295 * NULL. 1295 * NULL.
1296 */ 1296 */
1297 class V8EXPORT Utf8Value { 1297 class V8EXPORT Utf8Value {
1298 public: 1298 public:
1299 explicit Utf8Value(Handle<v8::Value> obj); 1299 explicit Utf8Value(Handle<v8::Value> obj);
1300 ~Utf8Value(); 1300 ~Utf8Value();
1301 char* operator*() { return str_; } 1301 char* operator*() { return str_; }
1302 const char* operator*() const { return str_; } 1302 const char* operator*() const { return str_; }
1303 int length() const { return length_; } 1303 int length() const { return length_; }
1304 private: 1304 private:
1305 char* str_; 1305 char* str_;
1306 int length_; 1306 int length_;
1307 1307
1308 // Disallow copying and assigning. 1308 // Disallow copying and assigning.
1309 Utf8Value(const Utf8Value&); 1309 Utf8Value(const Utf8Value&);
1310 void operator=(const Utf8Value&); 1310 void operator=(const Utf8Value&);
1311 }; 1311 };
1312 1312
1313 /** 1313 /**
1314 * Converts an object to an ASCII string. 1314 * Converts an object to an ASCII string.
1315 * Useful if you want to print the object. 1315 * Useful if you want to print the object.
1316 * If conversion to a string fails (eg. due to an exception in the toString() 1316 * If conversion to a string fails (eg. due to an exception in the toString()
1317 * method of the object) then the length() method returns 0 and the * operator 1317 * method of the object) then the length() method returns 0 and the * operator
1318 * returns NULL. 1318 * returns NULL.
1319 */ 1319 */
1320 class V8EXPORT AsciiValue { 1320 class V8EXPORT AsciiValue {
1321 public: 1321 public:
1322 explicit AsciiValue(Handle<v8::Value> obj); 1322 explicit AsciiValue(Handle<v8::Value> obj);
1323 ~AsciiValue(); 1323 ~AsciiValue();
1324 char* operator*() { return str_; } 1324 char* operator*() { return str_; }
1325 const char* operator*() const { return str_; } 1325 const char* operator*() const { return str_; }
1326 int length() const { return length_; } 1326 int length() const { return length_; }
1327 private: 1327 private:
1328 char* str_; 1328 char* str_;
1329 int length_; 1329 int length_;
1330 1330
1331 // Disallow copying and assigning. 1331 // Disallow copying and assigning.
1332 AsciiValue(const AsciiValue&); 1332 AsciiValue(const AsciiValue&);
1333 void operator=(const AsciiValue&); 1333 void operator=(const AsciiValue&);
1334 }; 1334 };
1335 1335
1336 /** 1336 /**
1337 * Converts an object to a two-byte string. 1337 * Converts an object to a two-byte string.
1338 * If conversion to a string fails (eg. due to an exception in the toString() 1338 * If conversion to a string fails (eg. due to an exception in the toString()
1339 * method of the object) then the length() method returns 0 and the * operator 1339 * method of the object) then the length() method returns 0 and the * operator
1340 * returns NULL. 1340 * returns NULL.
1341 */ 1341 */
1342 class V8EXPORT Value { 1342 class V8EXPORT Value {
1343 public: 1343 public:
1344 explicit Value(Handle<v8::Value> obj); 1344 explicit Value(Handle<v8::Value> obj);
1345 ~Value(); 1345 ~Value();
1346 uint16_t* operator*() { return str_; } 1346 uint16_t* operator*() { return str_; }
1347 const uint16_t* operator*() const { return str_; } 1347 const uint16_t* operator*() const { return str_; }
1348 int length() const { return length_; } 1348 int length() const { return length_; }
1349 private: 1349 private:
1350 uint16_t* str_; 1350 uint16_t* str_;
1351 int length_; 1351 int length_;
1352 1352
1353 // Disallow copying and assigning. 1353 // Disallow copying and assigning.
1354 Value(const Value&); 1354 Value(const Value&);
1355 void operator=(const Value&); 1355 void operator=(const Value&);
1356 }; 1356 };
1357 1357
1358 private: 1358 private:
1359 V8EXPORT void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, 1359 V8EXPORT void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
1360 Encoding encoding) const; 1360 Encoding encoding) const;
1361 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; 1361 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const;
1362 V8EXPORT static void CheckCast(v8::Value* obj); 1362 V8EXPORT static void CheckCast(v8::Value* obj);
1363 }; 1363 };
1364 1364
1365 1365
1366 /** 1366 /**
1367 * A JavaScript number value (ECMA-262, 4.3.20) 1367 * A JavaScript number value (ECMA-262, 4.3.20)
1368 */ 1368 */
1369 class Number : public Primitive { 1369 class Number : public Primitive {
1370 public: 1370 public:
1371 V8EXPORT double Value() const; 1371 V8EXPORT double Value() const;
1372 V8EXPORT static Local<Number> New(double value); 1372 V8EXPORT static Local<Number> New(double value);
1373 static inline Number* Cast(v8::Value* obj); 1373 static inline Number* Cast(v8::Value* obj);
1374 private: 1374 private:
1375 V8EXPORT Number(); 1375 V8EXPORT Number();
1376 V8EXPORT static void CheckCast(v8::Value* obj); 1376 V8EXPORT static void CheckCast(v8::Value* obj);
1377 }; 1377 };
1378 1378
1379 1379
1380 /** 1380 /**
1381 * A JavaScript value representing a signed integer. 1381 * A JavaScript value representing a signed integer.
1382 */ 1382 */
1383 class Integer : public Number { 1383 class Integer : public Number {
1384 public: 1384 public:
1385 V8EXPORT static Local<Integer> New(int32_t value); 1385 V8EXPORT static Local<Integer> New(int32_t value);
1386 V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value); 1386 V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value);
1387 V8EXPORT int64_t Value() const; 1387 V8EXPORT int64_t Value() const;
1388 static inline Integer* Cast(v8::Value* obj); 1388 static inline Integer* Cast(v8::Value* obj);
1389 private: 1389 private:
1390 V8EXPORT Integer(); 1390 V8EXPORT Integer();
1391 V8EXPORT static void CheckCast(v8::Value* obj); 1391 V8EXPORT static void CheckCast(v8::Value* obj);
1392 }; 1392 };
1393 1393
1394 1394
1395 /** 1395 /**
1396 * A JavaScript value representing a 32-bit signed integer. 1396 * A JavaScript value representing a 32-bit signed integer.
1397 */ 1397 */
1398 class Int32 : public Integer { 1398 class Int32 : public Integer {
1399 public: 1399 public:
1400 V8EXPORT int32_t Value() const; 1400 V8EXPORT int32_t Value() const;
1401 private: 1401 private:
1402 V8EXPORT Int32(); 1402 V8EXPORT Int32();
1403 }; 1403 };
1404 1404
1405 1405
1406 /** 1406 /**
1407 * A JavaScript value representing a 32-bit unsigned integer. 1407 * A JavaScript value representing a 32-bit unsigned integer.
1408 */ 1408 */
1409 class Uint32 : public Integer { 1409 class Uint32 : public Integer {
1410 public: 1410 public:
1411 V8EXPORT uint32_t Value() const; 1411 V8EXPORT uint32_t Value() const;
1412 private: 1412 private:
1413 V8EXPORT Uint32(); 1413 V8EXPORT Uint32();
1414 }; 1414 };
1415 1415
1416 1416
1417 enum PropertyAttribute { 1417 enum PropertyAttribute {
1418 None = 0, 1418 None = 0,
1419 ReadOnly = 1 << 0, 1419 ReadOnly = 1 << 0,
1420 DontEnum = 1 << 1, 1420 DontEnum = 1 << 1,
1421 DontDelete = 1 << 2 1421 DontDelete = 1 << 2
1422 }; 1422 };
1423 1423
1424 enum ExternalArrayType { 1424 enum ExternalArrayType {
1425 kExternalByteArray = 1, 1425 kExternalByteArray = 1,
1426 kExternalUnsignedByteArray, 1426 kExternalUnsignedByteArray,
1427 kExternalShortArray, 1427 kExternalShortArray,
1428 kExternalUnsignedShortArray, 1428 kExternalUnsignedShortArray,
1429 kExternalIntArray, 1429 kExternalIntArray,
1430 kExternalUnsignedIntArray, 1430 kExternalUnsignedIntArray,
1431 kExternalFloatArray, 1431 kExternalFloatArray,
1432 kExternalDoubleArray, 1432 kExternalDoubleArray,
1433 kExternalPixelArray 1433 kExternalPixelArray
1434 }; 1434 };
1435 1435
1436 /** 1436 /**
1437 * Accessor[Getter|Setter] are used as callback functions when 1437 * Accessor[Getter|Setter] are used as callback functions when
1438 * setting|getting a particular property. See Object and ObjectTemplate's 1438 * setting|getting a particular property. See Object and ObjectTemplate's
1439 * method SetAccessor. 1439 * method SetAccessor.
1440 */ 1440 */
1441 typedef Handle<Value> (*AccessorGetter)(Local<String> property, 1441 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
1442 const AccessorInfo& info); 1442 const AccessorInfo& info);
1443 1443
1444 1444
1445 typedef void (*AccessorSetter)(Local<String> property, 1445 typedef void (*AccessorSetter)(Local<String> property,
1446 Local<Value> value, 1446 Local<Value> value,
1447 const AccessorInfo& info); 1447 const AccessorInfo& info);
1448 1448
1449 1449
1450 /** 1450 /**
1451 * Access control specifications. 1451 * Access control specifications.
1452 * 1452 *
1453 * Some accessors should be accessible across contexts. These 1453 * Some accessors should be accessible across contexts. These
1454 * accessors have an explicit access control parameter which specifies 1454 * accessors have an explicit access control parameter which specifies
1455 * the kind of cross-context access that should be allowed. 1455 * the kind of cross-context access that should be allowed.
1456 * 1456 *
1457 * Additionally, for security, accessors can prohibit overwriting by 1457 * Additionally, for security, accessors can prohibit overwriting by
1458 * accessors defined in JavaScript. For objects that have such 1458 * accessors defined in JavaScript. For objects that have such
1459 * accessors either locally or in their prototype chain it is not 1459 * accessors either locally or in their prototype chain it is not
1460 * possible to overwrite the accessor by using __defineGetter__ or 1460 * possible to overwrite the accessor by using __defineGetter__ or
1461 * __defineSetter__ from JavaScript code. 1461 * __defineSetter__ from JavaScript code.
1462 */ 1462 */
1463 enum AccessControl { 1463 enum AccessControl {
1464 DEFAULT = 0, 1464 DEFAULT = 0,
1465 ALL_CAN_READ = 1, 1465 ALL_CAN_READ = 1,
1466 ALL_CAN_WRITE = 1 << 1, 1466 ALL_CAN_WRITE = 1 << 1,
1467 PROHIBITS_OVERWRITING = 1 << 2 1467 PROHIBITS_OVERWRITING = 1 << 2
1468 }; 1468 };
1469 1469
1470 1470
1471 /** 1471 /**
1472 * A JavaScript object (ECMA-262, 4.3.3) 1472 * A JavaScript object (ECMA-262, 4.3.3)
1473 */ 1473 */
1474 class Object : public Value { 1474 class Object : public Value {
1475 public: 1475 public:
1476 V8EXPORT bool Set(Handle<Value> key, 1476 V8EXPORT bool Set(Handle<Value> key,
1477 Handle<Value> value, 1477 Handle<Value> value,
1478 PropertyAttribute attribs = None); 1478 PropertyAttribute attribs = None);
1479 1479
1480 V8EXPORT bool Set(uint32_t index, 1480 V8EXPORT bool Set(uint32_t index,
1481 Handle<Value> value); 1481 Handle<Value> value);
1482 1482
1483 // Sets a local property on this object bypassing interceptors and 1483 // Sets a local property on this object bypassing interceptors and
1484 // overriding accessors or read-only properties. 1484 // overriding accessors or read-only properties.
1485 // 1485 //
1486 // Note that if the object has an interceptor the property will be set 1486 // Note that if the object has an interceptor the property will be set
1487 // locally, but since the interceptor takes precedence the local property 1487 // locally, but since the interceptor takes precedence the local property
1488 // will only be returned if the interceptor doesn't return a value. 1488 // will only be returned if the interceptor doesn't return a value.
1489 // 1489 //
1490 // Note also that this only works for named properties. 1490 // Note also that this only works for named properties.
1491 V8EXPORT bool ForceSet(Handle<Value> key, 1491 V8EXPORT bool ForceSet(Handle<Value> key,
1492 Handle<Value> value, 1492 Handle<Value> value,
1493 PropertyAttribute attribs = None); 1493 PropertyAttribute attribs = None);
1494 1494
1495 V8EXPORT Local<Value> Get(Handle<Value> key); 1495 V8EXPORT Local<Value> Get(Handle<Value> key);
1496 1496
1497 V8EXPORT Local<Value> Get(uint32_t index); 1497 V8EXPORT Local<Value> Get(uint32_t index);
1498 1498
1499 /** 1499 /**
1500 * Gets the property attributes of a property which can be None or 1500 * Gets the property attributes of a property which can be None or
1501 * any combination of ReadOnly, DontEnum and DontDelete. Returns 1501 * any combination of ReadOnly, DontEnum and DontDelete. Returns
1502 * None when the property doesn't exist. 1502 * None when the property doesn't exist.
1503 */ 1503 */
1504 V8EXPORT PropertyAttribute GetPropertyAttributes(Handle<Value> key); 1504 V8EXPORT PropertyAttribute GetPropertyAttributes(Handle<Value> key);
1505 1505
1506 // TODO(1245389): Replace the type-specific versions of these 1506 // TODO(1245389): Replace the type-specific versions of these
1507 // functions with generic ones that accept a Handle<Value> key. 1507 // functions with generic ones that accept a Handle<Value> key.
1508 V8EXPORT bool Has(Handle<String> key); 1508 V8EXPORT bool Has(Handle<String> key);
1509 1509
1510 V8EXPORT bool Delete(Handle<String> key); 1510 V8EXPORT bool Delete(Handle<String> key);
1511 1511
1512 // Delete a property on this object bypassing interceptors and 1512 // Delete a property on this object bypassing interceptors and
1513 // ignoring dont-delete attributes. 1513 // ignoring dont-delete attributes.
1514 V8EXPORT bool ForceDelete(Handle<Value> key); 1514 V8EXPORT bool ForceDelete(Handle<Value> key);
1515 1515
1516 V8EXPORT bool Has(uint32_t index); 1516 V8EXPORT bool Has(uint32_t index);
1517 1517
1518 V8EXPORT bool Delete(uint32_t index); 1518 V8EXPORT bool Delete(uint32_t index);
1519 1519
1520 V8EXPORT bool SetAccessor(Handle<String> name, 1520 V8EXPORT bool SetAccessor(Handle<String> name,
1521 AccessorGetter getter, 1521 AccessorGetter getter,
1522 AccessorSetter setter = 0, 1522 AccessorSetter setter = 0,
1523 Handle<Value> data = Handle<Value>(), 1523 Handle<Value> data = Handle<Value>(),
1524 AccessControl settings = DEFAULT, 1524 AccessControl settings = DEFAULT,
1525 PropertyAttribute attribute = None); 1525 PropertyAttribute attribute = None);
1526 1526
1527 /** 1527 /**
1528 * Returns an array containing the names of the enumerable properties 1528 * Returns an array containing the names of the enumerable properties
1529 * of this object, including properties from prototype objects. The 1529 * of this object, including properties from prototype objects. The
1530 * array returned by this method contains the same values as would 1530 * array returned by this method contains the same values as would
1531 * be enumerated by a for-in statement over this object. 1531 * be enumerated by a for-in statement over this object.
1532 */ 1532 */
1533 V8EXPORT Local<Array> GetPropertyNames(); 1533 V8EXPORT Local<Array> GetPropertyNames();
1534 1534
1535 /** 1535 /**
1536 * This function has the same functionality as GetPropertyNames but 1536 * This function has the same functionality as GetPropertyNames but
1537 * the returned array doesn't contain the names of properties from 1537 * the returned array doesn't contain the names of properties from
1538 * prototype objects. 1538 * prototype objects.
1539 */ 1539 */
1540 V8EXPORT Local<Array> GetOwnPropertyNames(); 1540 V8EXPORT Local<Array> GetOwnPropertyNames();
1541 1541
1542 /** 1542 /**
1543 * Get the prototype object. This does not skip objects marked to 1543 * Get the prototype object. This does not skip objects marked to
1544 * be skipped by __proto__ and it does not consult the security 1544 * be skipped by __proto__ and it does not consult the security
1545 * handler. 1545 * handler.
1546 */ 1546 */
1547 V8EXPORT Local<Value> GetPrototype(); 1547 V8EXPORT Local<Value> GetPrototype();
1548 1548
1549 /** 1549 /**
1550 * Set the prototype object. This does not skip objects marked to 1550 * Set the prototype object. This does not skip objects marked to
1551 * be skipped by __proto__ and it does not consult the security 1551 * be skipped by __proto__ and it does not consult the security
1552 * handler. 1552 * handler.
1553 */ 1553 */
1554 V8EXPORT bool SetPrototype(Handle<Value> prototype); 1554 V8EXPORT bool SetPrototype(Handle<Value> prototype);
1555 1555
1556 /** 1556 /**
1557 * Finds an instance of the given function template in the prototype 1557 * Finds an instance of the given function template in the prototype
1558 * chain. 1558 * chain.
1559 */ 1559 */
1560 V8EXPORT Local<Object> FindInstanceInPrototypeChain( 1560 V8EXPORT Local<Object> FindInstanceInPrototypeChain(
1561 Handle<FunctionTemplate> tmpl); 1561 Handle<FunctionTemplate> tmpl);
1562 1562
1563 /** 1563 /**
1564 * Call builtin Object.prototype.toString on this object. 1564 * Call builtin Object.prototype.toString on this object.
1565 * This is different from Value::ToString() that may call 1565 * This is different from Value::ToString() that may call
1566 * user-defined toString function. This one does not. 1566 * user-defined toString function. This one does not.
1567 */ 1567 */
1568 V8EXPORT Local<String> ObjectProtoToString(); 1568 V8EXPORT Local<String> ObjectProtoToString();
1569 1569
1570 /** 1570 /**
1571 * Returns the function invoked as a constructor for this object. 1571 * Returns the function invoked as a constructor for this object.
1572 * May be the null value. 1572 * May be the null value.
1573 */ 1573 */
1574 V8EXPORT Local<Value> GetConstructor(); 1574 V8EXPORT Local<Value> GetConstructor();
1575 1575
1576 /** 1576 /**
1577 * Returns the name of the function invoked as a constructor for this object. 1577 * Returns the name of the function invoked as a constructor for this object.
1578 */ 1578 */
1579 V8EXPORT Local<String> GetConstructorName(); 1579 V8EXPORT Local<String> GetConstructorName();
1580 1580
1581 /** Gets the number of internal fields for this Object. */ 1581 /** Gets the number of internal fields for this Object. */
1582 V8EXPORT int InternalFieldCount(); 1582 V8EXPORT int InternalFieldCount();
1583 /** Gets the value in an internal field. */ 1583 /** Gets the value in an internal field. */
1584 inline Local<Value> GetInternalField(int index); 1584 inline Local<Value> GetInternalField(int index);
1585 /** Sets the value in an internal field. */ 1585 /** Sets the value in an internal field. */
1586 V8EXPORT void SetInternalField(int index, Handle<Value> value); 1586 V8EXPORT void SetInternalField(int index, Handle<Value> value);
1587 1587
1588 /** Gets a native pointer from an internal field. */ 1588 /** Gets a native pointer from an internal field. */
1589 inline void* GetPointerFromInternalField(int index); 1589 inline void* GetPointerFromInternalField(int index);
1590 1590
1591 /** Sets a native pointer in an internal field. */ 1591 /** Sets a native pointer in an internal field. */
1592 V8EXPORT void SetPointerInInternalField(int index, void* value); 1592 V8EXPORT void SetPointerInInternalField(int index, void* value);
1593 1593
1594 // Testers for local properties. 1594 // Testers for local properties.
1595 V8EXPORT bool HasOwnProperty(Handle<String> key); 1595 V8EXPORT bool HasOwnProperty(Handle<String> key);
1596 V8EXPORT bool HasRealNamedProperty(Handle<String> key); 1596 V8EXPORT bool HasRealNamedProperty(Handle<String> key);
1597 V8EXPORT bool HasRealIndexedProperty(uint32_t index); 1597 V8EXPORT bool HasRealIndexedProperty(uint32_t index);
1598 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); 1598 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key);
1599 1599
1600 /** 1600 /**
1601 * If result.IsEmpty() no real property was located in the prototype chain. 1601 * If result.IsEmpty() no real property was located in the prototype chain.
1602 * This means interceptors in the prototype chain are not called. 1602 * This means interceptors in the prototype chain are not called.
1603 */ 1603 */
1604 V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain( 1604 V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain(
1605 Handle<String> key); 1605 Handle<String> key);
1606 1606
1607 /** 1607 /**
1608 * If result.IsEmpty() no real property was located on the object or 1608 * If result.IsEmpty() no real property was located on the object or
1609 * in the prototype chain. 1609 * in the prototype chain.
1610 * This means interceptors in the prototype chain are not called. 1610 * This means interceptors in the prototype chain are not called.
1611 */ 1611 */
1612 V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key); 1612 V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key);
1613 1613
1614 /** Tests for a named lookup interceptor.*/ 1614 /** Tests for a named lookup interceptor.*/
1615 V8EXPORT bool HasNamedLookupInterceptor(); 1615 V8EXPORT bool HasNamedLookupInterceptor();
1616 1616
1617 /** Tests for an index lookup interceptor.*/ 1617 /** Tests for an index lookup interceptor.*/
1618 V8EXPORT bool HasIndexedLookupInterceptor(); 1618 V8EXPORT bool HasIndexedLookupInterceptor();
1619 1619
1620 /** 1620 /**
1621 * Turns on access check on the object if the object is an instance of 1621 * Turns on access check on the object if the object is an instance of
1622 * a template that has access check callbacks. If an object has no 1622 * a template that has access check callbacks. If an object has no
1623 * access check info, the object cannot be accessed by anyone. 1623 * access check info, the object cannot be accessed by anyone.
1624 */ 1624 */
1625 V8EXPORT void TurnOnAccessCheck(); 1625 V8EXPORT void TurnOnAccessCheck();
1626 1626
1627 /** 1627 /**
1628 * Returns the identity hash for this object. The current implementation 1628 * Returns the identity hash for this object. The current implementation
1629 * uses a hidden property on the object to store the identity hash. 1629 * uses a hidden property on the object to store the identity hash.
1630 * 1630 *
1631 * The return value will never be 0. Also, it is not guaranteed to be 1631 * The return value will never be 0. Also, it is not guaranteed to be
1632 * unique. 1632 * unique.
1633 */ 1633 */
1634 V8EXPORT int GetIdentityHash(); 1634 V8EXPORT int GetIdentityHash();
1635 1635
1636 /** 1636 /**
1637 * Access hidden properties on JavaScript objects. These properties are 1637 * Access hidden properties on JavaScript objects. These properties are
1638 * hidden from the executing JavaScript and only accessible through the V8 1638 * hidden from the executing JavaScript and only accessible through the V8
1639 * C++ API. Hidden properties introduced by V8 internally (for example the 1639 * C++ API. Hidden properties introduced by V8 internally (for example the
1640 * identity hash) are prefixed with "v8::". 1640 * identity hash) are prefixed with "v8::".
1641 */ 1641 */
1642 V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value); 1642 V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value);
1643 V8EXPORT Local<Value> GetHiddenValue(Handle<String> key); 1643 V8EXPORT Local<Value> GetHiddenValue(Handle<String> key);
1644 V8EXPORT bool DeleteHiddenValue(Handle<String> key); 1644 V8EXPORT bool DeleteHiddenValue(Handle<String> key);
1645 1645
1646 /** 1646 /**
1647 * Returns true if this is an instance of an api function (one 1647 * Returns true if this is an instance of an api function (one
1648 * created from a function created from a function template) and has 1648 * created from a function created from a function template) and has
1649 * been modified since it was created. Note that this method is 1649 * been modified since it was created. Note that this method is
1650 * conservative and may return true for objects that haven't actually 1650 * conservative and may return true for objects that haven't actually
1651 * been modified. 1651 * been modified.
1652 */ 1652 */
1653 V8EXPORT bool IsDirty(); 1653 V8EXPORT bool IsDirty();
1654 1654
1655 /** 1655 /**
1656 * Clone this object with a fast but shallow copy. Values will point 1656 * Clone this object with a fast but shallow copy. Values will point
1657 * to the same values as the original object. 1657 * to the same values as the original object.
1658 */ 1658 */
1659 V8EXPORT Local<Object> Clone(); 1659 V8EXPORT Local<Object> Clone();
1660 1660
1661 /** 1661 /**
1662 * Returns the context in which the object was created. 1662 * Returns the context in which the object was created.
1663 */ 1663 */
1664 V8EXPORT Local<Context> CreationContext(); 1664 V8EXPORT Local<Context> CreationContext();
1665 1665
1666 /** 1666 /**
1667 * Set the backing store of the indexed properties to be managed by the 1667 * Set the backing store of the indexed properties to be managed by the
1668 * embedding layer. Access to the indexed properties will follow the rules 1668 * embedding layer. Access to the indexed properties will follow the rules
1669 * spelled out in CanvasPixelArray. 1669 * spelled out in CanvasPixelArray.
1670 * Note: The embedding program still owns the data and needs to ensure that 1670 * Note: The embedding program still owns the data and needs to ensure that
1671 * the backing store is preserved while V8 has a reference. 1671 * the backing store is preserved while V8 has a reference.
1672 */ 1672 */
1673 V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length); 1673 V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
1674 V8EXPORT bool HasIndexedPropertiesInPixelData(); 1674 V8EXPORT bool HasIndexedPropertiesInPixelData();
1675 V8EXPORT uint8_t* GetIndexedPropertiesPixelData(); 1675 V8EXPORT uint8_t* GetIndexedPropertiesPixelData();
1676 V8EXPORT int GetIndexedPropertiesPixelDataLength(); 1676 V8EXPORT int GetIndexedPropertiesPixelDataLength();
1677 1677
1678 /** 1678 /**
1679 * Set the backing store of the indexed properties to be managed by the 1679 * Set the backing store of the indexed properties to be managed by the
1680 * embedding layer. Access to the indexed properties will follow the rules 1680 * embedding layer. Access to the indexed properties will follow the rules
1681 * spelled out for the CanvasArray subtypes in the WebGL specification. 1681 * spelled out for the CanvasArray subtypes in the WebGL specification.
1682 * Note: The embedding program still owns the data and needs to ensure that 1682 * Note: The embedding program still owns the data and needs to ensure that
1683 * the backing store is preserved while V8 has a reference. 1683 * the backing store is preserved while V8 has a reference.
1684 */ 1684 */
1685 V8EXPORT void SetIndexedPropertiesToExternalArrayData( 1685 V8EXPORT void SetIndexedPropertiesToExternalArrayData(
1686 void* data, 1686 void* data,
1687 ExternalArrayType array_type, 1687 ExternalArrayType array_type,
1688 int number_of_elements); 1688 int number_of_elements);
1689 V8EXPORT bool HasIndexedPropertiesInExternalArrayData(); 1689 V8EXPORT bool HasIndexedPropertiesInExternalArrayData();
1690 V8EXPORT void* GetIndexedPropertiesExternalArrayData(); 1690 V8EXPORT void* GetIndexedPropertiesExternalArrayData();
1691 V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); 1691 V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
1692 V8EXPORT int GetIndexedPropertiesExternalArrayDataLength(); 1692 V8EXPORT int GetIndexedPropertiesExternalArrayDataLength();
1693 1693
1694 /** 1694 /**
1695 * Checks whether a callback is set by the 1695 * Checks whether a callback is set by the
1696 * ObjectTemplate::SetCallAsFunctionHandler method. 1696 * ObjectTemplate::SetCallAsFunctionHandler method.
1697 * When an Object is callable this method returns true. 1697 * When an Object is callable this method returns true.
1698 */ 1698 */
1699 V8EXPORT bool IsCallable(); 1699 V8EXPORT bool IsCallable();
1700 1700
1701 /** 1701 /**
1702 * Call an Object as a function if a callback is set by the 1702 * Call an Object as a function if a callback is set by the
1703 * ObjectTemplate::SetCallAsFunctionHandler method. 1703 * ObjectTemplate::SetCallAsFunctionHandler method.
1704 */ 1704 */
1705 V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv, 1705 V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv,
1706 int argc, 1706 int argc,
1707 Handle<Value> argv[]); 1707 Handle<Value> argv[]);
1708 1708
1709 /** 1709 /**
1710 * Call an Object as a constructor if a callback is set by the 1710 * Call an Object as a constructor if a callback is set by the
1711 * ObjectTemplate::SetCallAsFunctionHandler method. 1711 * ObjectTemplate::SetCallAsFunctionHandler method.
1712 * Note: This method behaves like the Function::NewInstance method. 1712 * Note: This method behaves like the Function::NewInstance method.
1713 */ 1713 */
1714 V8EXPORT Local<Value> CallAsConstructor(int argc, 1714 V8EXPORT Local<Value> CallAsConstructor(int argc,
1715 Handle<Value> argv[]); 1715 Handle<Value> argv[]);
1716 1716
1717 V8EXPORT static Local<Object> New(); 1717 V8EXPORT static Local<Object> New();
1718 static inline Object* Cast(Value* obj); 1718 static inline Object* Cast(Value* obj);
1719 1719
1720 private: 1720 private:
1721 V8EXPORT Object(); 1721 V8EXPORT Object();
1722 V8EXPORT static void CheckCast(Value* obj); 1722 V8EXPORT static void CheckCast(Value* obj);
1723 V8EXPORT Local<Value> CheckedGetInternalField(int index); 1723 V8EXPORT Local<Value> CheckedGetInternalField(int index);
1724 V8EXPORT void* SlowGetPointerFromInternalField(int index); 1724 V8EXPORT void* SlowGetPointerFromInternalField(int index);
1725 1725
1726 /** 1726 /**
1727 * If quick access to the internal field is possible this method 1727 * If quick access to the internal field is possible this method
1728 * returns the value. Otherwise an empty handle is returned. 1728 * returns the value. Otherwise an empty handle is returned.
1729 */ 1729 */
1730 inline Local<Value> UncheckedGetInternalField(int index); 1730 inline Local<Value> UncheckedGetInternalField(int index);
1731 }; 1731 };
1732 1732
1733 1733
1734 /** 1734 /**
1735 * An instance of the built-in array constructor (ECMA-262, 15.4.2). 1735 * An instance of the built-in array constructor (ECMA-262, 15.4.2).
1736 */ 1736 */
1737 class Array : public Object { 1737 class Array : public Object {
1738 public: 1738 public:
1739 V8EXPORT uint32_t Length() const; 1739 V8EXPORT uint32_t Length() const;
1740 1740
1741 /** 1741 /**
1742 * Clones an element at index |index|. Returns an empty 1742 * Clones an element at index |index|. Returns an empty
1743 * handle if cloning fails (for any reason). 1743 * handle if cloning fails (for any reason).
1744 */ 1744 */
1745 V8EXPORT Local<Object> CloneElementAt(uint32_t index); 1745 V8EXPORT Local<Object> CloneElementAt(uint32_t index);
1746 1746
1747 /** 1747 /**
1748 * Creates a JavaScript array with the given length. If the length 1748 * Creates a JavaScript array with the given length. If the length
1749 * is negative the returned array will have length 0. 1749 * is negative the returned array will have length 0.
1750 */ 1750 */
1751 V8EXPORT static Local<Array> New(int length = 0); 1751 V8EXPORT static Local<Array> New(int length = 0);
1752 1752
1753 static inline Array* Cast(Value* obj); 1753 static inline Array* Cast(Value* obj);
1754 private: 1754 private:
1755 V8EXPORT Array(); 1755 V8EXPORT Array();
1756 V8EXPORT static void CheckCast(Value* obj); 1756 V8EXPORT static void CheckCast(Value* obj);
1757 }; 1757 };
1758 1758
1759 1759
1760 /** 1760 /**
1761 * A JavaScript function object (ECMA-262, 15.3). 1761 * A JavaScript function object (ECMA-262, 15.3).
1762 */ 1762 */
1763 class Function : public Object { 1763 class Function : public Object {
1764 public: 1764 public:
1765 V8EXPORT Local<Object> NewInstance() const; 1765 V8EXPORT Local<Object> NewInstance() const;
1766 V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; 1766 V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
1767 V8EXPORT Local<Value> Call(Handle<Object> recv, 1767 V8EXPORT Local<Value> Call(Handle<Object> recv,
1768 int argc, 1768 int argc,
1769 Handle<Value> argv[]); 1769 Handle<Value> argv[]);
1770 V8EXPORT void SetName(Handle<String> name); 1770 V8EXPORT void SetName(Handle<String> name);
1771 V8EXPORT Handle<Value> GetName() const; 1771 V8EXPORT Handle<Value> GetName() const;
1772 1772
1773 /** 1773 /**
1774 * Name inferred from variable or property assignment of this function. 1774 * Name inferred from variable or property assignment of this function.
1775 * Used to facilitate debugging and profiling of JavaScript code written 1775 * Used to facilitate debugging and profiling of JavaScript code written
1776 * in an OO style, where many functions are anonymous but are assigned 1776 * in an OO style, where many functions are anonymous but are assigned
1777 * to object properties. 1777 * to object properties.
1778 */ 1778 */
1779 V8EXPORT Handle<Value> GetInferredName() const; 1779 V8EXPORT Handle<Value> GetInferredName() const;
1780 1780
1781 /** 1781 /**
1782 * Returns zero based line number of function body and 1782 * Returns zero based line number of function body and
1783 * kLineOffsetNotFound if no information available. 1783 * kLineOffsetNotFound if no information available.
1784 */ 1784 */
1785 V8EXPORT int GetScriptLineNumber() const; 1785 V8EXPORT int GetScriptLineNumber() const;
1786 /** 1786 /**
1787 * Returns zero based column number of function body and 1787 * Returns zero based column number of function body and
1788 * kLineOffsetNotFound if no information available. 1788 * kLineOffsetNotFound if no information available.
1789 */ 1789 */
1790 V8EXPORT int GetScriptColumnNumber() const; 1790 V8EXPORT int GetScriptColumnNumber() const;
1791 V8EXPORT Handle<Value> GetScriptId() const; 1791 V8EXPORT Handle<Value> GetScriptId() const;
1792 V8EXPORT ScriptOrigin GetScriptOrigin() const; 1792 V8EXPORT ScriptOrigin GetScriptOrigin() const;
1793 static inline Function* Cast(Value* obj); 1793 static inline Function* Cast(Value* obj);
1794 V8EXPORT static const int kLineOffsetNotFound; 1794 V8EXPORT static const int kLineOffsetNotFound;
1795 1795
1796 private: 1796 private:
1797 V8EXPORT Function(); 1797 V8EXPORT Function();
1798 V8EXPORT static void CheckCast(Value* obj); 1798 V8EXPORT static void CheckCast(Value* obj);
1799 }; 1799 };
1800 1800
1801 1801
1802 /** 1802 /**
1803 * An instance of the built-in Date constructor (ECMA-262, 15.9). 1803 * An instance of the built-in Date constructor (ECMA-262, 15.9).
1804 */ 1804 */
1805 class Date : public Object { 1805 class Date : public Object {
1806 public: 1806 public:
1807 V8EXPORT static Local<Value> New(double time); 1807 V8EXPORT static Local<Value> New(double time);
1808 1808
1809 /** 1809 /**
1810 * A specialization of Value::NumberValue that is more efficient 1810 * A specialization of Value::NumberValue that is more efficient
1811 * because we know the structure of this object. 1811 * because we know the structure of this object.
1812 */ 1812 */
1813 V8EXPORT double NumberValue() const; 1813 V8EXPORT double NumberValue() const;
1814 1814
1815 static inline Date* Cast(v8::Value* obj); 1815 static inline Date* Cast(v8::Value* obj);
1816 1816
1817 /** 1817 /**
1818 * Notification that the embedder has changed the time zone, 1818 * Notification that the embedder has changed the time zone,
1819 * daylight savings time, or other date / time configuration 1819 * daylight savings time, or other date / time configuration
1820 * parameters. V8 keeps a cache of various values used for 1820 * parameters. V8 keeps a cache of various values used for
1821 * date / time computation. This notification will reset 1821 * date / time computation. This notification will reset
1822 * those cached values for the current context so that date / 1822 * those cached values for the current context so that date /
1823 * time configuration changes would be reflected in the Date 1823 * time configuration changes would be reflected in the Date
1824 * object. 1824 * object.
1825 * 1825 *
1826 * This API should not be called more than needed as it will 1826 * This API should not be called more than needed as it will
1827 * negatively impact the performance of date operations. 1827 * negatively impact the performance of date operations.
1828 */ 1828 */
1829 V8EXPORT static void DateTimeConfigurationChangeNotification(); 1829 V8EXPORT static void DateTimeConfigurationChangeNotification();
1830 1830
1831 private: 1831 private:
1832 V8EXPORT static void CheckCast(v8::Value* obj); 1832 V8EXPORT static void CheckCast(v8::Value* obj);
1833 }; 1833 };
1834 1834
1835 1835
1836 /** 1836 /**
1837 * A Number object (ECMA-262, 4.3.21). 1837 * A Number object (ECMA-262, 4.3.21).
1838 */ 1838 */
1839 class NumberObject : public Object { 1839 class NumberObject : public Object {
1840 public: 1840 public:
1841 V8EXPORT static Local<Value> New(double value); 1841 V8EXPORT static Local<Value> New(double value);
1842 1842
1843 /** 1843 /**
1844 * Returns the Number held by the object. 1844 * Returns the Number held by the object.
1845 */ 1845 */
1846 V8EXPORT double NumberValue() const; 1846 V8EXPORT double NumberValue() const;
1847 1847
1848 static inline NumberObject* Cast(v8::Value* obj); 1848 static inline NumberObject* Cast(v8::Value* obj);
1849 1849
1850 private: 1850 private:
1851 V8EXPORT static void CheckCast(v8::Value* obj); 1851 V8EXPORT static void CheckCast(v8::Value* obj);
1852 }; 1852 };
1853 1853
1854 1854
1855 /** 1855 /**
1856 * A Boolean object (ECMA-262, 4.3.15). 1856 * A Boolean object (ECMA-262, 4.3.15).
1857 */ 1857 */
1858 class BooleanObject : public Object { 1858 class BooleanObject : public Object {
1859 public: 1859 public:
1860 V8EXPORT static Local<Value> New(bool value); 1860 V8EXPORT static Local<Value> New(bool value);
1861 1861
1862 /** 1862 /**
1863 * Returns the Boolean held by the object. 1863 * Returns the Boolean held by the object.
1864 */ 1864 */
1865 V8EXPORT bool BooleanValue() const; 1865 V8EXPORT bool BooleanValue() const;
1866 1866
1867 static inline BooleanObject* Cast(v8::Value* obj); 1867 static inline BooleanObject* Cast(v8::Value* obj);
1868 1868
1869 private: 1869 private:
1870 V8EXPORT static void CheckCast(v8::Value* obj); 1870 V8EXPORT static void CheckCast(v8::Value* obj);
1871 }; 1871 };
1872 1872
1873 1873
1874 /** 1874 /**
1875 * A String object (ECMA-262, 4.3.18). 1875 * A String object (ECMA-262, 4.3.18).
1876 */ 1876 */
1877 class StringObject : public Object { 1877 class StringObject : public Object {
1878 public: 1878 public:
1879 V8EXPORT static Local<Value> New(Handle<String> value); 1879 V8EXPORT static Local<Value> New(Handle<String> value);
1880 1880
1881 /** 1881 /**
1882 * Returns the String held by the object. 1882 * Returns the String held by the object.
1883 */ 1883 */
1884 V8EXPORT Local<String> StringValue() const; 1884 V8EXPORT Local<String> StringValue() const;
1885 1885
1886 static inline StringObject* Cast(v8::Value* obj); 1886 static inline StringObject* Cast(v8::Value* obj);
1887 1887
1888 private: 1888 private:
1889 V8EXPORT static void CheckCast(v8::Value* obj); 1889 V8EXPORT static void CheckCast(v8::Value* obj);
1890 }; 1890 };
1891 1891
1892 1892
1893 /** 1893 /**
1894 * An instance of the built-in RegExp constructor (ECMA-262, 15.10). 1894 * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
1895 */ 1895 */
1896 class RegExp : public Object { 1896 class RegExp : public Object {
1897 public: 1897 public:
1898 /** 1898 /**
1899 * Regular expression flag bits. They can be or'ed to enable a set 1899 * Regular expression flag bits. They can be or'ed to enable a set
1900 * of flags. 1900 * of flags.
1901 */ 1901 */
1902 enum Flags { 1902 enum Flags {
1903 kNone = 0, 1903 kNone = 0,
1904 kGlobal = 1, 1904 kGlobal = 1,
1905 kIgnoreCase = 2, 1905 kIgnoreCase = 2,
1906 kMultiline = 4 1906 kMultiline = 4
1907 }; 1907 };
1908 1908
1909 /** 1909 /**
1910 * Creates a regular expression from the given pattern string and 1910 * Creates a regular expression from the given pattern string and
1911 * the flags bit field. May throw a JavaScript exception as 1911 * the flags bit field. May throw a JavaScript exception as
1912 * described in ECMA-262, 15.10.4.1. 1912 * described in ECMA-262, 15.10.4.1.
1913 * 1913 *
1914 * For example, 1914 * For example,
1915 * RegExp::New(v8::String::New("foo"), 1915 * RegExp::New(v8::String::New("foo"),
1916 * static_cast<RegExp::Flags>(kGlobal | kMultiline)) 1916 * static_cast<RegExp::Flags>(kGlobal | kMultiline))
1917 * is equivalent to evaluating "/foo/gm". 1917 * is equivalent to evaluating "/foo/gm".
1918 */ 1918 */
1919 V8EXPORT static Local<RegExp> New(Handle<String> pattern, 1919 V8EXPORT static Local<RegExp> New(Handle<String> pattern,
1920 Flags flags); 1920 Flags flags);
1921 1921
1922 /** 1922 /**
1923 * Returns the value of the source property: a string representing 1923 * Returns the value of the source property: a string representing
1924 * the regular expression. 1924 * the regular expression.
1925 */ 1925 */
1926 V8EXPORT Local<String> GetSource() const; 1926 V8EXPORT Local<String> GetSource() const;
1927 1927
1928 /** 1928 /**
1929 * Returns the flags bit field. 1929 * Returns the flags bit field.
1930 */ 1930 */
1931 V8EXPORT Flags GetFlags() const; 1931 V8EXPORT Flags GetFlags() const;
1932 1932
1933 static inline RegExp* Cast(v8::Value* obj); 1933 static inline RegExp* Cast(v8::Value* obj);
1934 1934
1935 private: 1935 private:
1936 V8EXPORT static void CheckCast(v8::Value* obj); 1936 V8EXPORT static void CheckCast(v8::Value* obj);
1937 }; 1937 };
1938 1938
1939 1939
1940 /** 1940 /**
1941 * A JavaScript value that wraps a C++ void*. This type of value is 1941 * A JavaScript value that wraps a C++ void*. This type of value is
1942 * mainly used to associate C++ data structures with JavaScript 1942 * mainly used to associate C++ data structures with JavaScript
1943 * objects. 1943 * objects.
1944 * 1944 *
1945 * The Wrap function V8 will return the most optimal Value object wrapping the 1945 * The Wrap function V8 will return the most optimal Value object wrapping the
1946 * C++ void*. The type of the value is not guaranteed to be an External object 1946 * C++ void*. The type of the value is not guaranteed to be an External object
1947 * and no assumptions about its type should be made. To access the wrapped 1947 * and no assumptions about its type should be made. To access the wrapped
1948 * value Unwrap should be used, all other operations on that object will lead 1948 * value Unwrap should be used, all other operations on that object will lead
1949 * to unpredictable results. 1949 * to unpredictable results.
1950 */ 1950 */
1951 class External : public Value { 1951 class External : public Value {
1952 public: 1952 public:
1953 V8EXPORT static Local<Value> Wrap(void* data); 1953 V8EXPORT static Local<Value> Wrap(void* data);
1954 static inline void* Unwrap(Handle<Value> obj); 1954 static inline void* Unwrap(Handle<Value> obj);
1955 1955
1956 V8EXPORT static Local<External> New(void* value); 1956 V8EXPORT static Local<External> New(void* value);
1957 static inline External* Cast(Value* obj); 1957 static inline External* Cast(Value* obj);
1958 V8EXPORT void* Value() const; 1958 V8EXPORT void* Value() const;
1959 private: 1959 private:
1960 V8EXPORT External(); 1960 V8EXPORT External();
1961 V8EXPORT static void CheckCast(v8::Value* obj); 1961 V8EXPORT static void CheckCast(v8::Value* obj);
1962 static inline void* QuickUnwrap(Handle<v8::Value> obj); 1962 static inline void* QuickUnwrap(Handle<v8::Value> obj);
1963 V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj); 1963 V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
1964 }; 1964 };
1965 1965
1966 1966
1967 // --- Templates --- 1967 // --- Templates ---
1968 1968
1969 1969
1970 /** 1970 /**
1971 * The superclass of object and function templates. 1971 * The superclass of object and function templates.
1972 */ 1972 */
1973 class V8EXPORT Template : public Data { 1973 class V8EXPORT Template : public Data {
1974 public: 1974 public:
1975 /** Adds a property to each instance created by this template.*/ 1975 /** Adds a property to each instance created by this template.*/
1976 void Set(Handle<String> name, Handle<Data> value, 1976 void Set(Handle<String> name, Handle<Data> value,
1977 PropertyAttribute attributes = None); 1977 PropertyAttribute attributes = None);
1978 inline void Set(const char* name, Handle<Data> value); 1978 inline void Set(const char* name, Handle<Data> value);
1979 private: 1979 private:
1980 Template(); 1980 Template();
1981 1981
1982 friend class ObjectTemplate; 1982 friend class ObjectTemplate;
1983 friend class FunctionTemplate; 1983 friend class FunctionTemplate;
1984 }; 1984 };
1985 1985
1986 1986
1987 /** 1987 /**
1988 * The argument information given to function call callbacks. This 1988 * The argument information given to function call callbacks. This
1989 * class provides access to information about the context of the call, 1989 * class provides access to information about the context of the call,
1990 * including the receiver, the number and values of arguments, and 1990 * including the receiver, the number and values of arguments, and
1991 * the holder of the function. 1991 * the holder of the function.
1992 */ 1992 */
1993 class Arguments { 1993 class Arguments {
1994 public: 1994 public:
1995 inline int Length() const; 1995 inline int Length() const;
1996 inline Local<Value> operator[](int i) const; 1996 inline Local<Value> operator[](int i) const;
1997 inline Local<Function> Callee() const; 1997 inline Local<Function> Callee() const;
1998 inline Local<Object> This() const; 1998 inline Local<Object> This() const;
1999 inline Local<Object> Holder() const; 1999 inline Local<Object> Holder() const;
2000 inline bool IsConstructCall() const; 2000 inline bool IsConstructCall() const;
2001 inline Local<Value> Data() const; 2001 inline Local<Value> Data() const;
2002 inline Isolate* GetIsolate() const; 2002 inline Isolate* GetIsolate() const;
2003 2003
2004 private: 2004 private:
2005 static const int kIsolateIndex = 0; 2005 static const int kIsolateIndex = 0;
2006 static const int kDataIndex = -1; 2006 static const int kDataIndex = -1;
2007 static const int kCalleeIndex = -2; 2007 static const int kCalleeIndex = -2;
2008 static const int kHolderIndex = -3; 2008 static const int kHolderIndex = -3;
2009 2009
2010 friend class ImplementationUtilities; 2010 friend class ImplementationUtilities;
2011 inline Arguments(internal::Object** implicit_args, 2011 inline Arguments(internal::Object** implicit_args,
2012 internal::Object** values, 2012 internal::Object** values,
2013 int length, 2013 int length,
2014 bool is_construct_call); 2014 bool is_construct_call);
2015 internal::Object** implicit_args_; 2015 internal::Object** implicit_args_;
2016 internal::Object** values_; 2016 internal::Object** values_;
2017 int length_; 2017 int length_;
2018 bool is_construct_call_; 2018 bool is_construct_call_;
2019 }; 2019 };
2020 2020
2021 2021
2022 /** 2022 /**
2023 * The information passed to an accessor callback about the context 2023 * The information passed to an accessor callback about the context
2024 * of the property access. 2024 * of the property access.
2025 */ 2025 */
2026 class V8EXPORT AccessorInfo { 2026 class V8EXPORT AccessorInfo {
2027 public: 2027 public:
2028 inline AccessorInfo(internal::Object** args) 2028 inline AccessorInfo(internal::Object** args)
2029 : args_(args) { } 2029 : args_(args) { }
2030 inline Isolate* GetIsolate() const; 2030 inline Isolate* GetIsolate() const;
2031 inline Local<Value> Data() const; 2031 inline Local<Value> Data() const;
2032 inline Local<Object> This() const; 2032 inline Local<Object> This() const;
2033 inline Local<Object> Holder() const; 2033 inline Local<Object> Holder() const;
2034 2034
2035 private: 2035 private:
2036 internal::Object** args_; 2036 internal::Object** args_;
2037 }; 2037 };
2038 2038
2039 2039
2040 typedef Handle<Value> (*InvocationCallback)(const Arguments& args); 2040 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
2041 2041
2042 /** 2042 /**
2043 * NamedProperty[Getter|Setter] are used as interceptors on object. 2043 * NamedProperty[Getter|Setter] are used as interceptors on object.
2044 * See ObjectTemplate::SetNamedPropertyHandler. 2044 * See ObjectTemplate::SetNamedPropertyHandler.
2045 */ 2045 */
2046 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, 2046 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
2047 const AccessorInfo& info); 2047 const AccessorInfo& info);
2048 2048
2049 2049
2050 /** 2050 /**
2051 * Returns the value if the setter intercepts the request. 2051 * Returns the value if the setter intercepts the request.
2052 * Otherwise, returns an empty handle. 2052 * Otherwise, returns an empty handle.
2053 */ 2053 */
2054 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, 2054 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
2055 Local<Value> value, 2055 Local<Value> value,
2056 const AccessorInfo& info); 2056 const AccessorInfo& info);
2057 2057
2058 /** 2058 /**
2059 * Returns a non-empty handle if the interceptor intercepts the request. 2059 * Returns a non-empty handle if the interceptor intercepts the request.
2060 * The result is an integer encoding property attributes (like v8::None, 2060 * The result is an integer encoding property attributes (like v8::None,
2061 * v8::DontEnum, etc.) 2061 * v8::DontEnum, etc.)
2062 */ 2062 */
2063 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, 2063 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
2064 const AccessorInfo& info); 2064 const AccessorInfo& info);
2065 2065
2066 2066
2067 /** 2067 /**
2068 * Returns a non-empty handle if the deleter intercepts the request. 2068 * Returns a non-empty handle if the deleter intercepts the request.
2069 * The return value is true if the property could be deleted and false 2069 * The return value is true if the property could be deleted and false
2070 * otherwise. 2070 * otherwise.
2071 */ 2071 */
2072 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, 2072 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
2073 const AccessorInfo& info); 2073 const AccessorInfo& info);
2074 2074
2075 /** 2075 /**
2076 * Returns an array containing the names of the properties the named 2076 * Returns an array containing the names of the properties the named
2077 * property getter intercepts. 2077 * property getter intercepts.
2078 */ 2078 */
2079 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); 2079 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
2080 2080
2081 2081
2082 /** 2082 /**
2083 * Returns the value of the property if the getter intercepts the 2083 * Returns the value of the property if the getter intercepts the
2084 * request. Otherwise, returns an empty handle. 2084 * request. Otherwise, returns an empty handle.
2085 */ 2085 */
2086 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, 2086 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
2087 const AccessorInfo& info); 2087 const AccessorInfo& info);
2088 2088
2089 2089
2090 /** 2090 /**
2091 * Returns the value if the setter intercepts the request. 2091 * Returns the value if the setter intercepts the request.
2092 * Otherwise, returns an empty handle. 2092 * Otherwise, returns an empty handle.
2093 */ 2093 */
2094 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, 2094 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
2095 Local<Value> value, 2095 Local<Value> value,
2096 const AccessorInfo& info); 2096 const AccessorInfo& info);
2097 2097
2098 2098
2099 /** 2099 /**
2100 * Returns a non-empty handle if the interceptor intercepts the request. 2100 * Returns a non-empty handle if the interceptor intercepts the request.
2101 * The result is an integer encoding property attributes. 2101 * The result is an integer encoding property attributes.
2102 */ 2102 */
2103 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, 2103 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
2104 const AccessorInfo& info); 2104 const AccessorInfo& info);
2105 2105
2106 /** 2106 /**
2107 * Returns a non-empty handle if the deleter intercepts the request. 2107 * Returns a non-empty handle if the deleter intercepts the request.
2108 * The return value is true if the property could be deleted and false 2108 * The return value is true if the property could be deleted and false
2109 * otherwise. 2109 * otherwise.
2110 */ 2110 */
2111 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, 2111 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
2112 const AccessorInfo& info); 2112 const AccessorInfo& info);
2113 2113
2114 /** 2114 /**
2115 * Returns an array containing the indices of the properties the 2115 * Returns an array containing the indices of the properties the
2116 * indexed property getter intercepts. 2116 * indexed property getter intercepts.
2117 */ 2117 */
2118 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); 2118 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
2119 2119
2120 2120
2121 /** 2121 /**
2122 * Access type specification. 2122 * Access type specification.
2123 */ 2123 */
2124 enum AccessType { 2124 enum AccessType {
2125 ACCESS_GET, 2125 ACCESS_GET,
2126 ACCESS_SET, 2126 ACCESS_SET,
2127 ACCESS_HAS, 2127 ACCESS_HAS,
2128 ACCESS_DELETE, 2128 ACCESS_DELETE,
2129 ACCESS_KEYS 2129 ACCESS_KEYS
2130 }; 2130 };
2131 2131
2132 2132
2133 /** 2133 /**
2134 * Returns true if cross-context access should be allowed to the named 2134 * Returns true if cross-context access should be allowed to the named
2135 * property with the given key on the host object. 2135 * property with the given key on the host object.
2136 */ 2136 */
2137 typedef bool (*NamedSecurityCallback)(Local<Object> host, 2137 typedef bool (*NamedSecurityCallback)(Local<Object> host,
2138 Local<Value> key, 2138 Local<Value> key,
2139 AccessType type, 2139 AccessType type,
2140 Local<Value> data); 2140 Local<Value> data);
2141 2141
2142 2142
2143 /** 2143 /**
2144 * Returns true if cross-context access should be allowed to the indexed 2144 * Returns true if cross-context access should be allowed to the indexed
2145 * property with the given index on the host object. 2145 * property with the given index on the host object.
2146 */ 2146 */
2147 typedef bool (*IndexedSecurityCallback)(Local<Object> host, 2147 typedef bool (*IndexedSecurityCallback)(Local<Object> host,
2148 uint32_t index, 2148 uint32_t index,
2149 AccessType type, 2149 AccessType type,
2150 Local<Value> data); 2150 Local<Value> data);
2151 2151
2152 2152
2153 /** 2153 /**
2154 * A FunctionTemplate is used to create functions at runtime. There 2154 * A FunctionTemplate is used to create functions at runtime. There
2155 * can only be one function created from a FunctionTemplate in a 2155 * can only be one function created from a FunctionTemplate in a
2156 * context. The lifetime of the created function is equal to the 2156 * context. The lifetime of the created function is equal to the
2157 * lifetime of the context. So in case the embedder needs to create 2157 * lifetime of the context. So in case the embedder needs to create
2158 * temporary functions that can be collected using Scripts is 2158 * temporary functions that can be collected using Scripts is
2159 * preferred. 2159 * preferred.
2160 * 2160 *
2161 * A FunctionTemplate can have properties, these properties are added to the 2161 * A FunctionTemplate can have properties, these properties are added to the
2162 * function object when it is created. 2162 * function object when it is created.
2163 * 2163 *
2164 * A FunctionTemplate has a corresponding instance template which is 2164 * A FunctionTemplate has a corresponding instance template which is
2165 * used to create object instances when the function is used as a 2165 * used to create object instances when the function is used as a
2166 * constructor. Properties added to the instance template are added to 2166 * constructor. Properties added to the instance template are added to
2167 * each object instance. 2167 * each object instance.
2168 * 2168 *
2169 * A FunctionTemplate can have a prototype template. The prototype template 2169 * A FunctionTemplate can have a prototype template. The prototype template
2170 * is used to create the prototype object of the function. 2170 * is used to create the prototype object of the function.
2171 * 2171 *
2172 * The following example shows how to use a FunctionTemplate: 2172 * The following example shows how to use a FunctionTemplate:
2173 * 2173 *
2174 * \code 2174 * \code
2175 * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 2175 * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
2176 * t->Set("func_property", v8::Number::New(1)); 2176 * t->Set("func_property", v8::Number::New(1));
2177 * 2177 *
2178 * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); 2178 * v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
2179 * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); 2179 * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
2180 * proto_t->Set("proto_const", v8::Number::New(2)); 2180 * proto_t->Set("proto_const", v8::Number::New(2));
2181 * 2181 *
2182 * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); 2182 * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
2183 * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); 2183 * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
2184 * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); 2184 * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
2185 * instance_t->Set("instance_property", Number::New(3)); 2185 * instance_t->Set("instance_property", Number::New(3));
2186 * 2186 *
2187 * v8::Local<v8::Function> function = t->GetFunction(); 2187 * v8::Local<v8::Function> function = t->GetFunction();
2188 * v8::Local<v8::Object> instance = function->NewInstance(); 2188 * v8::Local<v8::Object> instance = function->NewInstance();
2189 * \endcode 2189 * \endcode
2190 * 2190 *
2191 * Let's use "function" as the JS variable name of the function object 2191 * Let's use "function" as the JS variable name of the function object
2192 * and "instance" for the instance object created above. The function 2192 * and "instance" for the instance object created above. The function
2193 * and the instance will have the following properties: 2193 * and the instance will have the following properties:
2194 * 2194 *
2195 * \code 2195 * \code
2196 * func_property in function == true; 2196 * func_property in function == true;
2197 * function.func_property == 1; 2197 * function.func_property == 1;
2198 * 2198 *
2199 * function.prototype.proto_method() invokes 'InvokeCallback' 2199 * function.prototype.proto_method() invokes 'InvokeCallback'
2200 * function.prototype.proto_const == 2; 2200 * function.prototype.proto_const == 2;
2201 * 2201 *
2202 * instance instanceof function == true; 2202 * instance instanceof function == true;
2203 * instance.instance_accessor calls 'InstanceAccessorCallback' 2203 * instance.instance_accessor calls 'InstanceAccessorCallback'
2204 * instance.instance_property == 3; 2204 * instance.instance_property == 3;
2205 * \endcode 2205 * \endcode
2206 * 2206 *
2207 * A FunctionTemplate can inherit from another one by calling the 2207 * A FunctionTemplate can inherit from another one by calling the
2208 * FunctionTemplate::Inherit method. The following graph illustrates 2208 * FunctionTemplate::Inherit method. The following graph illustrates
2209 * the semantics of inheritance: 2209 * the semantics of inheritance:
2210 * 2210 *
2211 * \code 2211 * \code
2212 * FunctionTemplate Parent -> Parent() . prototype -> { } 2212 * FunctionTemplate Parent -> Parent() . prototype -> { }
2213 * ^ ^ 2213 * ^ ^
2214 * | Inherit(Parent) | .__proto__ 2214 * | Inherit(Parent) | .__proto__
2215 * | | 2215 * | |
2216 * FunctionTemplate Child -> Child() . prototype -> { } 2216 * FunctionTemplate Child -> Child() . prototype -> { }
2217 * \endcode 2217 * \endcode
2218 * 2218 *
2219 * A FunctionTemplate 'Child' inherits from 'Parent', the prototype 2219 * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
2220 * object of the Child() function has __proto__ pointing to the 2220 * object of the Child() function has __proto__ pointing to the
2221 * Parent() function's prototype object. An instance of the Child 2221 * Parent() function's prototype object. An instance of the Child
2222 * function has all properties on Parent's instance templates. 2222 * function has all properties on Parent's instance templates.
2223 * 2223 *
2224 * Let Parent be the FunctionTemplate initialized in the previous 2224 * Let Parent be the FunctionTemplate initialized in the previous
2225 * section and create a Child FunctionTemplate by: 2225 * section and create a Child FunctionTemplate by:
2226 * 2226 *
2227 * \code 2227 * \code
2228 * Local<FunctionTemplate> parent = t; 2228 * Local<FunctionTemplate> parent = t;
2229 * Local<FunctionTemplate> child = FunctionTemplate::New(); 2229 * Local<FunctionTemplate> child = FunctionTemplate::New();
2230 * child->Inherit(parent); 2230 * child->Inherit(parent);
2231 * 2231 *
2232 * Local<Function> child_function = child->GetFunction(); 2232 * Local<Function> child_function = child->GetFunction();
2233 * Local<Object> child_instance = child_function->NewInstance(); 2233 * Local<Object> child_instance = child_function->NewInstance();
2234 * \endcode 2234 * \endcode
2235 * 2235 *
2236 * The Child function and Child instance will have the following 2236 * The Child function and Child instance will have the following
2237 * properties: 2237 * properties:
2238 * 2238 *
2239 * \code 2239 * \code
2240 * child_func.prototype.__proto__ == function.prototype; 2240 * child_func.prototype.__proto__ == function.prototype;
2241 * child_instance.instance_accessor calls 'InstanceAccessorCallback' 2241 * child_instance.instance_accessor calls 'InstanceAccessorCallback'
2242 * child_instance.instance_property == 3; 2242 * child_instance.instance_property == 3;
2243 * \endcode 2243 * \endcode
2244 */ 2244 */
2245 class V8EXPORT FunctionTemplate : public Template { 2245 class V8EXPORT FunctionTemplate : public Template {
2246 public: 2246 public:
2247 /** Creates a function template.*/ 2247 /** Creates a function template.*/
2248 static Local<FunctionTemplate> New( 2248 static Local<FunctionTemplate> New(
2249 InvocationCallback callback = 0, 2249 InvocationCallback callback = 0,
2250 Handle<Value> data = Handle<Value>(), 2250 Handle<Value> data = Handle<Value>(),
2251 Handle<Signature> signature = Handle<Signature>()); 2251 Handle<Signature> signature = Handle<Signature>());
2252 /** Returns the unique function instance in the current execution context.*/ 2252 /** Returns the unique function instance in the current execution context.*/
2253 Local<Function> GetFunction(); 2253 Local<Function> GetFunction();
2254 2254
2255 /** 2255 /**
2256 * Set the call-handler callback for a FunctionTemplate. This 2256 * Set the call-handler callback for a FunctionTemplate. This
2257 * callback is called whenever the function created from this 2257 * callback is called whenever the function created from this
2258 * FunctionTemplate is called. 2258 * FunctionTemplate is called.
2259 */ 2259 */
2260 void SetCallHandler(InvocationCallback callback, 2260 void SetCallHandler(InvocationCallback callback,
2261 Handle<Value> data = Handle<Value>()); 2261 Handle<Value> data = Handle<Value>());
2262 2262
2263 /** Get the InstanceTemplate. */ 2263 /** Get the InstanceTemplate. */
2264 Local<ObjectTemplate> InstanceTemplate(); 2264 Local<ObjectTemplate> InstanceTemplate();
2265 2265
2266 /** Causes the function template to inherit from a parent function template.*/ 2266 /** Causes the function template to inherit from a parent function template.*/
2267 void Inherit(Handle<FunctionTemplate> parent); 2267 void Inherit(Handle<FunctionTemplate> parent);
2268 2268
2269 /** 2269 /**
2270 * A PrototypeTemplate is the template used to create the prototype object 2270 * A PrototypeTemplate is the template used to create the prototype object
2271 * of the function created by this template. 2271 * of the function created by this template.
2272 */ 2272 */
2273 Local<ObjectTemplate> PrototypeTemplate(); 2273 Local<ObjectTemplate> PrototypeTemplate();
2274 2274
2275 2275
2276 /** 2276 /**
2277 * Set the class name of the FunctionTemplate. This is used for 2277 * Set the class name of the FunctionTemplate. This is used for
2278 * printing objects created with the function created from the 2278 * printing objects created with the function created from the
2279 * FunctionTemplate as its constructor. 2279 * FunctionTemplate as its constructor.
2280 */ 2280 */
2281 void SetClassName(Handle<String> name); 2281 void SetClassName(Handle<String> name);
2282 2282
2283 /** 2283 /**
2284 * Determines whether the __proto__ accessor ignores instances of 2284 * Determines whether the __proto__ accessor ignores instances of
2285 * the function template. If instances of the function template are 2285 * the function template. If instances of the function template are
2286 * ignored, __proto__ skips all instances and instead returns the 2286 * ignored, __proto__ skips all instances and instead returns the
2287 * next object in the prototype chain. 2287 * next object in the prototype chain.
2288 * 2288 *
2289 * Call with a value of true to make the __proto__ accessor ignore 2289 * Call with a value of true to make the __proto__ accessor ignore
2290 * instances of the function template. Call with a value of false 2290 * instances of the function template. Call with a value of false
2291 * to make the __proto__ accessor not ignore instances of the 2291 * to make the __proto__ accessor not ignore instances of the
2292 * function template. By default, instances of a function template 2292 * function template. By default, instances of a function template
2293 * are not ignored. 2293 * are not ignored.
2294 */ 2294 */
2295 void SetHiddenPrototype(bool value); 2295 void SetHiddenPrototype(bool value);
2296 2296
2297 /** 2297 /**
2298 * Sets the ReadOnly flag in the attributes of the 'prototype' property 2298 * Sets the ReadOnly flag in the attributes of the 'prototype' property
2299 * of functions created from this FunctionTemplate to true. 2299 * of functions created from this FunctionTemplate to true.
2300 */ 2300 */
2301 void ReadOnlyPrototype(); 2301 void ReadOnlyPrototype();
2302 2302
2303 /** 2303 /**
2304 * Returns true if the given object is an instance of this function 2304 * Returns true if the given object is an instance of this function
2305 * template. 2305 * template.
2306 */ 2306 */
2307 bool HasInstance(Handle<Value> object); 2307 bool HasInstance(Handle<Value> object);
2308 2308
2309 private: 2309 private:
2310 FunctionTemplate(); 2310 FunctionTemplate();
2311 void AddInstancePropertyAccessor(Handle<String> name, 2311 void AddInstancePropertyAccessor(Handle<String> name,
2312 AccessorGetter getter, 2312 AccessorGetter getter,
2313 AccessorSetter setter, 2313 AccessorSetter setter,
2314 Handle<Value> data, 2314 Handle<Value> data,
2315 AccessControl settings, 2315 AccessControl settings,
2316 PropertyAttribute attributes, 2316 PropertyAttribute attributes,
2317 Handle<AccessorSignature> signature); 2317 Handle<AccessorSignature> signature);
2318 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, 2318 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
2319 NamedPropertySetter setter, 2319 NamedPropertySetter setter,
2320 NamedPropertyQuery query, 2320 NamedPropertyQuery query,
2321 NamedPropertyDeleter remover, 2321 NamedPropertyDeleter remover,
2322 NamedPropertyEnumerator enumerator, 2322 NamedPropertyEnumerator enumerator,
2323 Handle<Value> data); 2323 Handle<Value> data);
2324 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, 2324 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
2325 IndexedPropertySetter setter, 2325 IndexedPropertySetter setter,
2326 IndexedPropertyQuery query, 2326 IndexedPropertyQuery query,
2327 IndexedPropertyDeleter remover, 2327 IndexedPropertyDeleter remover,
2328 IndexedPropertyEnumerator enumerator, 2328 IndexedPropertyEnumerator enumerator,
2329 Handle<Value> data); 2329 Handle<Value> data);
2330 void SetInstanceCallAsFunctionHandler(InvocationCallback callback, 2330 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
2331 Handle<Value> data); 2331 Handle<Value> data);
2332 2332
2333 friend class Context; 2333 friend class Context;
2334 friend class ObjectTemplate; 2334 friend class ObjectTemplate;
2335 }; 2335 };
2336 2336
2337 2337
2338 /** 2338 /**
2339 * An ObjectTemplate is used to create objects at runtime. 2339 * An ObjectTemplate is used to create objects at runtime.
2340 * 2340 *
2341 * Properties added to an ObjectTemplate are added to each object 2341 * Properties added to an ObjectTemplate are added to each object
2342 * created from the ObjectTemplate. 2342 * created from the ObjectTemplate.
2343 */ 2343 */
2344 class V8EXPORT ObjectTemplate : public Template { 2344 class V8EXPORT ObjectTemplate : public Template {
2345 public: 2345 public:
2346 /** Creates an ObjectTemplate. */ 2346 /** Creates an ObjectTemplate. */
2347 static Local<ObjectTemplate> New(); 2347 static Local<ObjectTemplate> New();
2348 2348
2349 /** Creates a new instance of this template.*/ 2349 /** Creates a new instance of this template.*/
2350 Local<Object> NewInstance(); 2350 Local<Object> NewInstance();
2351 2351
2352 /** 2352 /**
2353 * Sets an accessor on the object template. 2353 * Sets an accessor on the object template.
2354 * 2354 *
2355 * Whenever the property with the given name is accessed on objects 2355 * Whenever the property with the given name is accessed on objects
2356 * created from this ObjectTemplate the getter and setter callbacks 2356 * created from this ObjectTemplate the getter and setter callbacks
2357 * are called instead of getting and setting the property directly 2357 * are called instead of getting and setting the property directly
2358 * on the JavaScript object. 2358 * on the JavaScript object.
2359 * 2359 *
2360 * \param name The name of the property for which an accessor is added. 2360 * \param name The name of the property for which an accessor is added.
2361 * \param getter The callback to invoke when getting the property. 2361 * \param getter The callback to invoke when getting the property.
2362 * \param setter The callback to invoke when setting the property. 2362 * \param setter The callback to invoke when setting the property.
2363 * \param data A piece of data that will be passed to the getter and setter 2363 * \param data A piece of data that will be passed to the getter and setter
2364 * callbacks whenever they are invoked. 2364 * callbacks whenever they are invoked.
2365 * \param settings Access control settings for the accessor. This is a bit 2365 * \param settings Access control settings for the accessor. This is a bit
2366 * field consisting of one of more of 2366 * field consisting of one of more of
2367 * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. 2367 * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
2368 * The default is to not allow cross-context access. 2368 * The default is to not allow cross-context access.
2369 * ALL_CAN_READ means that all cross-context reads are allowed. 2369 * ALL_CAN_READ means that all cross-context reads are allowed.
2370 * ALL_CAN_WRITE means that all cross-context writes are allowed. 2370 * ALL_CAN_WRITE means that all cross-context writes are allowed.
2371 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all 2371 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
2372 * cross-context access. 2372 * cross-context access.
2373 * \param attribute The attributes of the property for which an accessor 2373 * \param attribute The attributes of the property for which an accessor
2374 * is added. 2374 * is added.
2375 * \param signature The signature describes valid receivers for the accessor 2375 * \param signature The signature describes valid receivers for the accessor
2376 * and is used to perform implicit instance checks against them. If the 2376 * and is used to perform implicit instance checks against them. If the
2377 * receiver is incompatible (i.e. is not an instance of the constructor as 2377 * receiver is incompatible (i.e. is not an instance of the constructor as
2378 * defined by FunctionTemplate::HasInstance()), an implicit TypeError is 2378 * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
2379 * thrown and no callback is invoked. 2379 * thrown and no callback is invoked.
2380 */ 2380 */
2381 void SetAccessor(Handle<String> name, 2381 void SetAccessor(Handle<String> name,
2382 AccessorGetter getter, 2382 AccessorGetter getter,
2383 AccessorSetter setter = 0, 2383 AccessorSetter setter = 0,
2384 Handle<Value> data = Handle<Value>(), 2384 Handle<Value> data = Handle<Value>(),
2385 AccessControl settings = DEFAULT, 2385 AccessControl settings = DEFAULT,
2386 PropertyAttribute attribute = None, 2386 PropertyAttribute attribute = None,
2387 Handle<AccessorSignature> signature = 2387 Handle<AccessorSignature> signature =
2388 Handle<AccessorSignature>()); 2388 Handle<AccessorSignature>());
2389 2389
2390 /** 2390 /**
2391 * Sets a named property handler on the object template. 2391 * Sets a named property handler on the object template.
2392 * 2392 *
2393 * Whenever a named property is accessed on objects created from 2393 * Whenever a named property is accessed on objects created from
2394 * this object template, the provided callback is invoked instead of 2394 * this object template, the provided callback is invoked instead of
2395 * accessing the property directly on the JavaScript object. 2395 * accessing the property directly on the JavaScript object.
2396 * 2396 *
2397 * \param getter The callback to invoke when getting a property. 2397 * \param getter The callback to invoke when getting a property.
2398 * \param setter The callback to invoke when setting a property. 2398 * \param setter The callback to invoke when setting a property.
2399 * \param query The callback to invoke to check if a property is present, 2399 * \param query The callback to invoke to check if a property is present,
2400 * and if present, get its attributes. 2400 * and if present, get its attributes.
2401 * \param deleter The callback to invoke when deleting a property. 2401 * \param deleter The callback to invoke when deleting a property.
2402 * \param enumerator The callback to invoke to enumerate all the named 2402 * \param enumerator The callback to invoke to enumerate all the named
2403 * properties of an object. 2403 * properties of an object.
2404 * \param data A piece of data that will be passed to the callbacks 2404 * \param data A piece of data that will be passed to the callbacks
2405 * whenever they are invoked. 2405 * whenever they are invoked.
2406 */ 2406 */
2407 void SetNamedPropertyHandler(NamedPropertyGetter getter, 2407 void SetNamedPropertyHandler(NamedPropertyGetter getter,
2408 NamedPropertySetter setter = 0, 2408 NamedPropertySetter setter = 0,
2409 NamedPropertyQuery query = 0, 2409 NamedPropertyQuery query = 0,
2410 NamedPropertyDeleter deleter = 0, 2410 NamedPropertyDeleter deleter = 0,
2411 NamedPropertyEnumerator enumerator = 0, 2411 NamedPropertyEnumerator enumerator = 0,
2412 Handle<Value> data = Handle<Value>()); 2412 Handle<Value> data = Handle<Value>());
2413 2413
2414 /** 2414 /**
2415 * Sets an indexed property handler on the object template. 2415 * Sets an indexed property handler on the object template.
2416 * 2416 *
2417 * Whenever an indexed property is accessed on objects created from 2417 * Whenever an indexed property is accessed on objects created from
2418 * this object template, the provided callback is invoked instead of 2418 * this object template, the provided callback is invoked instead of
2419 * accessing the property directly on the JavaScript object. 2419 * accessing the property directly on the JavaScript object.
2420 * 2420 *
2421 * \param getter The callback to invoke when getting a property. 2421 * \param getter The callback to invoke when getting a property.
2422 * \param setter The callback to invoke when setting a property. 2422 * \param setter The callback to invoke when setting a property.
2423 * \param query The callback to invoke to check if an object has a property. 2423 * \param query The callback to invoke to check if an object has a property.
2424 * \param deleter The callback to invoke when deleting a property. 2424 * \param deleter The callback to invoke when deleting a property.
2425 * \param enumerator The callback to invoke to enumerate all the indexed 2425 * \param enumerator The callback to invoke to enumerate all the indexed
2426 * properties of an object. 2426 * properties of an object.
2427 * \param data A piece of data that will be passed to the callbacks 2427 * \param data A piece of data that will be passed to the callbacks
2428 * whenever they are invoked. 2428 * whenever they are invoked.
2429 */ 2429 */
2430 void SetIndexedPropertyHandler(IndexedPropertyGetter getter, 2430 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
2431 IndexedPropertySetter setter = 0, 2431 IndexedPropertySetter setter = 0,
2432 IndexedPropertyQuery query = 0, 2432 IndexedPropertyQuery query = 0,
2433 IndexedPropertyDeleter deleter = 0, 2433 IndexedPropertyDeleter deleter = 0,
2434 IndexedPropertyEnumerator enumerator = 0, 2434 IndexedPropertyEnumerator enumerator = 0,
2435 Handle<Value> data = Handle<Value>()); 2435 Handle<Value> data = Handle<Value>());
2436 2436
2437 /** 2437 /**
2438 * Sets the callback to be used when calling instances created from 2438 * Sets the callback to be used when calling instances created from
2439 * this template as a function. If no callback is set, instances 2439 * this template as a function. If no callback is set, instances
2440 * behave like normal JavaScript objects that cannot be called as a 2440 * behave like normal JavaScript objects that cannot be called as a
2441 * function. 2441 * function.
2442 */ 2442 */
2443 void SetCallAsFunctionHandler(InvocationCallback callback, 2443 void SetCallAsFunctionHandler(InvocationCallback callback,
2444 Handle<Value> data = Handle<Value>()); 2444 Handle<Value> data = Handle<Value>());
2445 2445
2446 /** 2446 /**
2447 * Mark object instances of the template as undetectable. 2447 * Mark object instances of the template as undetectable.
2448 * 2448 *
2449 * In many ways, undetectable objects behave as though they are not 2449 * In many ways, undetectable objects behave as though they are not
2450 * there. They behave like 'undefined' in conditionals and when 2450 * there. They behave like 'undefined' in conditionals and when
2451 * printed. However, properties can be accessed and called as on 2451 * printed. However, properties can be accessed and called as on
2452 * normal objects. 2452 * normal objects.
2453 */ 2453 */
2454 void MarkAsUndetectable(); 2454 void MarkAsUndetectable();
2455 2455
2456 /** 2456 /**
2457 * Sets access check callbacks on the object template. 2457 * Sets access check callbacks on the object template.
2458 * 2458 *
2459 * When accessing properties on instances of this object template, 2459 * When accessing properties on instances of this object template,
2460 * the access check callback will be called to determine whether or 2460 * the access check callback will be called to determine whether or
2461 * not to allow cross-context access to the properties. 2461 * not to allow cross-context access to the properties.
2462 * The last parameter specifies whether access checks are turned 2462 * The last parameter specifies whether access checks are turned
2463 * on by default on instances. If access checks are off by default, 2463 * on by default on instances. If access checks are off by default,
2464 * they can be turned on on individual instances by calling 2464 * they can be turned on on individual instances by calling
2465 * Object::TurnOnAccessCheck(). 2465 * Object::TurnOnAccessCheck().
2466 */ 2466 */
2467 void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, 2467 void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
2468 IndexedSecurityCallback indexed_handler, 2468 IndexedSecurityCallback indexed_handler,
2469 Handle<Value> data = Handle<Value>(), 2469 Handle<Value> data = Handle<Value>(),
2470 bool turned_on_by_default = true); 2470 bool turned_on_by_default = true);
2471 2471
2472 /** 2472 /**
2473 * Gets the number of internal fields for objects generated from 2473 * Gets the number of internal fields for objects generated from
2474 * this template. 2474 * this template.
2475 */ 2475 */
2476 int InternalFieldCount(); 2476 int InternalFieldCount();
2477 2477
2478 /** 2478 /**
2479 * Sets the number of internal fields for objects generated from 2479 * Sets the number of internal fields for objects generated from
2480 * this template. 2480 * this template.
2481 */ 2481 */
2482 void SetInternalFieldCount(int value); 2482 void SetInternalFieldCount(int value);
2483 2483
2484 private: 2484 private:
2485 ObjectTemplate(); 2485 ObjectTemplate();
2486 static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); 2486 static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
2487 friend class FunctionTemplate; 2487 friend class FunctionTemplate;
2488 }; 2488 };
2489 2489
2490 2490
2491 /** 2491 /**
2492 * A Signature specifies which receivers and arguments are valid 2492 * A Signature specifies which receivers and arguments are valid
2493 * parameters to a function. 2493 * parameters to a function.
2494 */ 2494 */
2495 class V8EXPORT Signature : public Data { 2495 class V8EXPORT Signature : public Data {
2496 public: 2496 public:
2497 static Local<Signature> New(Handle<FunctionTemplate> receiver = 2497 static Local<Signature> New(Handle<FunctionTemplate> receiver =
2498 Handle<FunctionTemplate>(), 2498 Handle<FunctionTemplate>(),
2499 int argc = 0, 2499 int argc = 0,
2500 Handle<FunctionTemplate> argv[] = 0); 2500 Handle<FunctionTemplate> argv[] = 0);
2501 private: 2501 private:
2502 Signature(); 2502 Signature();
2503 }; 2503 };
2504 2504
2505 2505
2506 /** 2506 /**
2507 * An AccessorSignature specifies which receivers are valid parameters 2507 * An AccessorSignature specifies which receivers are valid parameters
2508 * to an accessor callback. 2508 * to an accessor callback.
2509 */ 2509 */
2510 class V8EXPORT AccessorSignature : public Data { 2510 class V8EXPORT AccessorSignature : public Data {
2511 public: 2511 public:
2512 static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = 2512 static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver =
2513 Handle<FunctionTemplate>()); 2513 Handle<FunctionTemplate>());
2514 private: 2514 private:
2515 AccessorSignature(); 2515 AccessorSignature();
2516 }; 2516 };
2517 2517
2518 2518
2519 /** 2519 /**
2520 * A utility for determining the type of objects based on the template 2520 * A utility for determining the type of objects based on the template
2521 * they were constructed from. 2521 * they were constructed from.
2522 */ 2522 */
2523 class V8EXPORT TypeSwitch : public Data { 2523 class V8EXPORT TypeSwitch : public Data {
2524 public: 2524 public:
2525 static Local<TypeSwitch> New(Handle<FunctionTemplate> type); 2525 static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
2526 static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); 2526 static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
2527 int match(Handle<Value> value); 2527 int match(Handle<Value> value);
2528 private: 2528 private:
2529 TypeSwitch(); 2529 TypeSwitch();
2530 }; 2530 };
2531 2531
2532 2532
2533 // --- Extensions --- 2533 // --- Extensions ---
2534 2534
2535 class V8EXPORT ExternalAsciiStringResourceImpl 2535 class V8EXPORT ExternalAsciiStringResourceImpl
2536 : public String::ExternalAsciiStringResource { 2536 : public String::ExternalAsciiStringResource {
2537 public: 2537 public:
2538 ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} 2538 ExternalAsciiStringResourceImpl() : data_(0), length_(0) {}
2539 ExternalAsciiStringResourceImpl(const char* data, size_t length) 2539 ExternalAsciiStringResourceImpl(const char* data, size_t length)
2540 : data_(data), length_(length) {} 2540 : data_(data), length_(length) {}
2541 const char* data() const { return data_; } 2541 const char* data() const { return data_; }
2542 size_t length() const { return length_; } 2542 size_t length() const { return length_; }
2543 2543
2544 private: 2544 private:
2545 const char* data_; 2545 const char* data_;
2546 size_t length_; 2546 size_t length_;
2547 }; 2547 };
2548 2548
2549 /** 2549 /**
2550 * Ignore 2550 * Ignore
2551 */ 2551 */
2552 class V8EXPORT Extension { // NOLINT 2552 class V8EXPORT Extension { // NOLINT
2553 public: 2553 public:
2554 // Note that the strings passed into this constructor must live as long 2554 // Note that the strings passed into this constructor must live as long
2555 // as the Extension itself. 2555 // as the Extension itself.
2556 Extension(const char* name, 2556 Extension(const char* name,
2557 const char* source = 0, 2557 const char* source = 0,
2558 int dep_count = 0, 2558 int dep_count = 0,
2559 const char** deps = 0, 2559 const char** deps = 0,
2560 int source_length = -1); 2560 int source_length = -1);
2561 virtual ~Extension() { } 2561 virtual ~Extension() { }
2562 virtual v8::Handle<v8::FunctionTemplate> 2562 virtual v8::Handle<v8::FunctionTemplate>
2563 GetNativeFunction(v8::Handle<v8::String> name) { 2563 GetNativeFunction(v8::Handle<v8::String> name) {
2564 return v8::Handle<v8::FunctionTemplate>(); 2564 return v8::Handle<v8::FunctionTemplate>();
2565 } 2565 }
2566 2566
2567 const char* name() const { return name_; } 2567 const char* name() const { return name_; }
2568 size_t source_length() const { return source_length_; } 2568 size_t source_length() const { return source_length_; }
2569 const String::ExternalAsciiStringResource* source() const { 2569 const String::ExternalAsciiStringResource* source() const {
2570 return &source_; } 2570 return &source_; }
2571 int dependency_count() { return dep_count_; } 2571 int dependency_count() { return dep_count_; }
2572 const char** dependencies() { return deps_; } 2572 const char** dependencies() { return deps_; }
2573 void set_auto_enable(bool value) { auto_enable_ = value; } 2573 void set_auto_enable(bool value) { auto_enable_ = value; }
2574 bool auto_enable() { return auto_enable_; } 2574 bool auto_enable() { return auto_enable_; }
2575 2575
2576 private: 2576 private:
2577 const char* name_; 2577 const char* name_;
2578 size_t source_length_; // expected to initialize before source_ 2578 size_t source_length_; // expected to initialize before source_
2579 ExternalAsciiStringResourceImpl source_; 2579 ExternalAsciiStringResourceImpl source_;
2580 int dep_count_; 2580 int dep_count_;
2581 const char** deps_; 2581 const char** deps_;
2582 bool auto_enable_; 2582 bool auto_enable_;
2583 2583
2584 // Disallow copying and assigning. 2584 // Disallow copying and assigning.
2585 Extension(const Extension&); 2585 Extension(const Extension&);
2586 void operator=(const Extension&); 2586 void operator=(const Extension&);
2587 }; 2587 };
2588 2588
2589 2589
2590 void V8EXPORT RegisterExtension(Extension* extension); 2590 void V8EXPORT RegisterExtension(Extension* extension);
2591 2591
2592 2592
2593 /** 2593 /**
2594 * Ignore 2594 * Ignore
2595 */ 2595 */
2596 class V8EXPORT DeclareExtension { 2596 class V8EXPORT DeclareExtension {
2597 public: 2597 public:
2598 inline DeclareExtension(Extension* extension) { 2598 inline DeclareExtension(Extension* extension) {
2599 RegisterExtension(extension); 2599 RegisterExtension(extension);
2600 } 2600 }
2601 }; 2601 };
2602 2602
2603 2603
2604 // --- Statics --- 2604 // --- Statics ---
2605 2605
2606 2606
2607 Handle<Primitive> V8EXPORT Undefined(); 2607 Handle<Primitive> V8EXPORT Undefined();
2608 Handle<Primitive> V8EXPORT Null(); 2608 Handle<Primitive> V8EXPORT Null();
2609 Handle<Boolean> V8EXPORT True(); 2609 Handle<Boolean> V8EXPORT True();
2610 Handle<Boolean> V8EXPORT False(); 2610 Handle<Boolean> V8EXPORT False();
2611 2611
2612 inline Handle<Primitive> Undefined(Isolate* isolate); 2612 inline Handle<Primitive> Undefined(Isolate* isolate);
2613 inline Handle<Primitive> Null(Isolate* isolate); 2613 inline Handle<Primitive> Null(Isolate* isolate);
2614 inline Handle<Boolean> True(Isolate* isolate); 2614 inline Handle<Boolean> True(Isolate* isolate);
2615 inline Handle<Boolean> False(Isolate* isolate); 2615 inline Handle<Boolean> False(Isolate* isolate);
2616 2616
2617 2617
2618 /** 2618 /**
2619 * A set of constraints that specifies the limits of the runtime's memory use. 2619 * A set of constraints that specifies the limits of the runtime's memory use.
2620 * You must set the heap size before initializing the VM - the size cannot be 2620 * You must set the heap size before initializing the VM - the size cannot be
2621 * adjusted after the VM is initialized. 2621 * adjusted after the VM is initialized.
2622 * 2622 *
2623 * If you are using threads then you should hold the V8::Locker lock while 2623 * If you are using threads then you should hold the V8::Locker lock while
2624 * setting the stack limit and you must set a non-default stack limit separately 2624 * setting the stack limit and you must set a non-default stack limit separately
2625 * for each thread. 2625 * for each thread.
2626 */ 2626 */
2627 class V8EXPORT ResourceConstraints { 2627 class V8EXPORT ResourceConstraints {
2628 public: 2628 public:
2629 ResourceConstraints(); 2629 ResourceConstraints();
2630 int max_young_space_size() const { return max_young_space_size_; } 2630 int max_young_space_size() const { return max_young_space_size_; }
2631 void set_max_young_space_size(int value) { max_young_space_size_ = value; } 2631 void set_max_young_space_size(int value) { max_young_space_size_ = value; }
2632 int max_old_space_size() const { return max_old_space_size_; } 2632 int max_old_space_size() const { return max_old_space_size_; }
2633 void set_max_old_space_size(int value) { max_old_space_size_ = value; } 2633 void set_max_old_space_size(int value) { max_old_space_size_ = value; }
2634 int max_executable_size() { return max_executable_size_; } 2634 int max_executable_size() { return max_executable_size_; }
2635 void set_max_executable_size(int value) { max_executable_size_ = value; } 2635 void set_max_executable_size(int value) { max_executable_size_ = value; }
2636 uint32_t* stack_limit() const { return stack_limit_; } 2636 uint32_t* stack_limit() const { return stack_limit_; }
2637 // Sets an address beyond which the VM's stack may not grow. 2637 // Sets an address beyond which the VM's stack may not grow.
2638 void set_stack_limit(uint32_t* value) { stack_limit_ = value; } 2638 void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
2639 private: 2639 private:
2640 int max_young_space_size_; 2640 int max_young_space_size_;
2641 int max_old_space_size_; 2641 int max_old_space_size_;
2642 int max_executable_size_; 2642 int max_executable_size_;
2643 uint32_t* stack_limit_; 2643 uint32_t* stack_limit_;
2644 }; 2644 };
2645 2645
2646 2646
2647 bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); 2647 bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints);
2648 2648
2649 2649
2650 // --- Exceptions --- 2650 // --- Exceptions ---
2651 2651
2652 2652
2653 typedef void (*FatalErrorCallback)(const char* location, const char* message); 2653 typedef void (*FatalErrorCallback)(const char* location, const char* message);
2654 2654
2655 2655
2656 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data); 2656 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
2657 2657
2658 2658
2659 /** 2659 /**
2660 * Schedules an exception to be thrown when returning to JavaScript. When an 2660 * Schedules an exception to be thrown when returning to JavaScript. When an
2661 * exception has been scheduled it is illegal to invoke any JavaScript 2661 * exception has been scheduled it is illegal to invoke any JavaScript
2662 * operation; the caller must return immediately and only after the exception 2662 * operation; the caller must return immediately and only after the exception
2663 * has been handled does it become legal to invoke JavaScript operations. 2663 * has been handled does it become legal to invoke JavaScript operations.
2664 */ 2664 */
2665 Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); 2665 Handle<Value> V8EXPORT ThrowException(Handle<Value> exception);
2666 2666
2667 /** 2667 /**
2668 * Create new error objects by calling the corresponding error object 2668 * Create new error objects by calling the corresponding error object
2669 * constructor with the message. 2669 * constructor with the message.
2670 */ 2670 */
2671 class V8EXPORT Exception { 2671 class V8EXPORT Exception {
2672 public: 2672 public:
2673 static Local<Value> RangeError(Handle<String> message); 2673 static Local<Value> RangeError(Handle<String> message);
2674 static Local<Value> ReferenceError(Handle<String> message); 2674 static Local<Value> ReferenceError(Handle<String> message);
2675 static Local<Value> SyntaxError(Handle<String> message); 2675 static Local<Value> SyntaxError(Handle<String> message);
2676 static Local<Value> TypeError(Handle<String> message); 2676 static Local<Value> TypeError(Handle<String> message);
2677 static Local<Value> Error(Handle<String> message); 2677 static Local<Value> Error(Handle<String> message);
2678 }; 2678 };
2679 2679
2680 2680
2681 // --- Counters Callbacks --- 2681 // --- Counters Callbacks ---
2682 2682
2683 typedef int* (*CounterLookupCallback)(const char* name); 2683 typedef int* (*CounterLookupCallback)(const char* name);
2684 2684
2685 typedef void* (*CreateHistogramCallback)(const char* name, 2685 typedef void* (*CreateHistogramCallback)(const char* name,
2686 int min, 2686 int min,
2687 int max, 2687 int max,
2688 size_t buckets); 2688 size_t buckets);
2689 2689
2690 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); 2690 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
2691 2691
2692 // --- Memory Allocation Callback --- 2692 // --- Memory Allocation Callback ---
2693 enum ObjectSpace { 2693 enum ObjectSpace {
2694 kObjectSpaceNewSpace = 1 << 0, 2694 kObjectSpaceNewSpace = 1 << 0,
2695 kObjectSpaceOldPointerSpace = 1 << 1, 2695 kObjectSpaceOldPointerSpace = 1 << 1,
2696 kObjectSpaceOldDataSpace = 1 << 2, 2696 kObjectSpaceOldDataSpace = 1 << 2,
2697 kObjectSpaceCodeSpace = 1 << 3, 2697 kObjectSpaceCodeSpace = 1 << 3,
2698 kObjectSpaceMapSpace = 1 << 4, 2698 kObjectSpaceMapSpace = 1 << 4,
2699 kObjectSpaceLoSpace = 1 << 5, 2699 kObjectSpaceLoSpace = 1 << 5,
2700 2700
2701 kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | 2701 kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
2702 kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | 2702 kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
2703 kObjectSpaceLoSpace 2703 kObjectSpaceLoSpace
2704 }; 2704 };
2705 2705
2706 enum AllocationAction { 2706 enum AllocationAction {
2707 kAllocationActionAllocate = 1 << 0, 2707 kAllocationActionAllocate = 1 << 0,
2708 kAllocationActionFree = 1 << 1, 2708 kAllocationActionFree = 1 << 1,
2709 kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree 2709 kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
2710 }; 2710 };
2711 2711
2712 typedef void (*MemoryAllocationCallback)(ObjectSpace space, 2712 typedef void (*MemoryAllocationCallback)(ObjectSpace space,
2713 AllocationAction action, 2713 AllocationAction action,
2714 int size); 2714 int size);
2715 2715
2716 // --- Leave Script Callback --- 2716 // --- Leave Script Callback ---
2717 typedef void (*CallCompletedCallback)(); 2717 typedef void (*CallCompletedCallback)();
2718 2718
2719 // --- Failed Access Check Callback --- 2719 // --- Failed Access Check Callback ---
2720 typedef void (*FailedAccessCheckCallback)(Local<Object> target, 2720 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
2721 AccessType type, 2721 AccessType type,
2722 Local<Value> data); 2722 Local<Value> data);
2723 2723
2724 // --- AllowCodeGenerationFromStrings callbacks --- 2724 // --- AllowCodeGenerationFromStrings callbacks ---
2725 2725
2726 /** 2726 /**
2727 * Callback to check if code generation from strings is allowed. See 2727 * Callback to check if code generation from strings is allowed. See
2728 * Context::AllowCodeGenerationFromStrings. 2728 * Context::AllowCodeGenerationFromStrings.
2729 */ 2729 */
2730 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); 2730 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
2731 2731
2732 // --- Garbage Collection Callbacks --- 2732 // --- Garbage Collection Callbacks ---
2733 2733
2734 /** 2734 /**
2735 * Applications can register callback functions which will be called 2735 * Applications can register callback functions which will be called
2736 * before and after a garbage collection. Allocations are not 2736 * before and after a garbage collection. Allocations are not
2737 * allowed in the callback functions, you therefore cannot manipulate 2737 * allowed in the callback functions, you therefore cannot manipulate
2738 * objects (set or delete properties for example) since it is possible 2738 * objects (set or delete properties for example) since it is possible
2739 * such operations will result in the allocation of objects. 2739 * such operations will result in the allocation of objects.
2740 */ 2740 */
2741 enum GCType { 2741 enum GCType {
2742 kGCTypeScavenge = 1 << 0, 2742 kGCTypeScavenge = 1 << 0,
2743 kGCTypeMarkSweepCompact = 1 << 1, 2743 kGCTypeMarkSweepCompact = 1 << 1,
2744 kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact 2744 kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
2745 }; 2745 };
2746 2746
2747 enum GCCallbackFlags { 2747 enum GCCallbackFlags {
2748 kNoGCCallbackFlags = 0, 2748 kNoGCCallbackFlags = 0,
2749 kGCCallbackFlagCompacted = 1 << 0 2749 kGCCallbackFlagCompacted = 1 << 0
2750 }; 2750 };
2751 2751
2752 typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); 2752 typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
2753 typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); 2753 typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
2754 2754
2755 typedef void (*GCCallback)(); 2755 typedef void (*GCCallback)();
2756 2756
2757 2757
2758 /** 2758 /**
2759 * Collection of V8 heap information. 2759 * Collection of V8 heap information.
2760 * 2760 *
2761 * Instances of this class can be passed to v8::V8::HeapStatistics to 2761 * Instances of this class can be passed to v8::V8::HeapStatistics to
2762 * get heap statistics from V8. 2762 * get heap statistics from V8.
2763 */ 2763 */
2764 class V8EXPORT HeapStatistics { 2764 class V8EXPORT HeapStatistics {
2765 public: 2765 public:
2766 HeapStatistics(); 2766 HeapStatistics();
2767 size_t total_heap_size() { return total_heap_size_; } 2767 size_t total_heap_size() { return total_heap_size_; }
2768 size_t total_heap_size_executable() { return total_heap_size_executable_; } 2768 size_t total_heap_size_executable() { return total_heap_size_executable_; }
2769 size_t used_heap_size() { return used_heap_size_; } 2769 size_t used_heap_size() { return used_heap_size_; }
2770 size_t heap_size_limit() { return heap_size_limit_; } 2770 size_t heap_size_limit() { return heap_size_limit_; }
2771 2771
2772 private: 2772 private:
2773 void set_total_heap_size(size_t size) { total_heap_size_ = size; } 2773 void set_total_heap_size(size_t size) { total_heap_size_ = size; }
2774 void set_total_heap_size_executable(size_t size) { 2774 void set_total_heap_size_executable(size_t size) {
2775 total_heap_size_executable_ = size; 2775 total_heap_size_executable_ = size;
2776 } 2776 }
2777 void set_used_heap_size(size_t size) { used_heap_size_ = size; } 2777 void set_used_heap_size(size_t size) { used_heap_size_ = size; }
2778 void set_heap_size_limit(size_t size) { heap_size_limit_ = size; } 2778 void set_heap_size_limit(size_t size) { heap_size_limit_ = size; }
2779 2779
2780 size_t total_heap_size_; 2780 size_t total_heap_size_;
2781 size_t total_heap_size_executable_; 2781 size_t total_heap_size_executable_;
2782 size_t used_heap_size_; 2782 size_t used_heap_size_;
2783 size_t heap_size_limit_; 2783 size_t heap_size_limit_;
2784 2784
2785 friend class V8; 2785 friend class V8;
2786 }; 2786 };
2787 2787
2788 2788
2789 class RetainedObjectInfo; 2789 class RetainedObjectInfo;
2790 2790
2791 /** 2791 /**
2792 * Isolate represents an isolated instance of the V8 engine. V8 2792 * Isolate represents an isolated instance of the V8 engine. V8
2793 * isolates have completely separate states. Objects from one isolate 2793 * isolates have completely separate states. Objects from one isolate
2794 * must not be used in other isolates. When V8 is initialized a 2794 * must not be used in other isolates. When V8 is initialized a
2795 * default isolate is implicitly created and entered. The embedder 2795 * default isolate is implicitly created and entered. The embedder
2796 * can create additional isolates and use them in parallel in multiple 2796 * can create additional isolates and use them in parallel in multiple
2797 * threads. An isolate can be entered by at most one thread at any 2797 * threads. An isolate can be entered by at most one thread at any
2798 * given time. The Locker/Unlocker API must be used to synchronize. 2798 * given time. The Locker/Unlocker API must be used to synchronize.
2799 */ 2799 */
2800 class V8EXPORT Isolate { 2800 class V8EXPORT Isolate {
2801 public: 2801 public:
2802 /** 2802 /**
2803 * Stack-allocated class which sets the isolate for all operations 2803 * Stack-allocated class which sets the isolate for all operations
2804 * executed within a local scope. 2804 * executed within a local scope.
2805 */ 2805 */
2806 class V8EXPORT Scope { 2806 class V8EXPORT Scope {
2807 public: 2807 public:
2808 explicit Scope(Isolate* isolate) : isolate_(isolate) { 2808 explicit Scope(Isolate* isolate) : isolate_(isolate) {
2809 isolate->Enter(); 2809 isolate->Enter();
2810 } 2810 }
2811 2811
2812 ~Scope() { isolate_->Exit(); } 2812 ~Scope() { isolate_->Exit(); }
2813 2813
2814 private: 2814 private:
2815 Isolate* const isolate_; 2815 Isolate* const isolate_;
2816 2816
2817 // Prevent copying of Scope objects. 2817 // Prevent copying of Scope objects.
2818 Scope(const Scope&); 2818 Scope(const Scope&);
2819 Scope& operator=(const Scope&); 2819 Scope& operator=(const Scope&);
2820 }; 2820 };
2821 2821
2822 /** 2822 /**
2823 * Creates a new isolate. Does not change the currently entered 2823 * Creates a new isolate. Does not change the currently entered
2824 * isolate. 2824 * isolate.
2825 * 2825 *
2826 * When an isolate is no longer used its resources should be freed 2826 * When an isolate is no longer used its resources should be freed
2827 * by calling Dispose(). Using the delete operator is not allowed. 2827 * by calling Dispose(). Using the delete operator is not allowed.
2828 */ 2828 */
2829 static Isolate* New(); 2829 static Isolate* New();
2830 2830
2831 /** 2831 /**
2832 * Returns the entered isolate for the current thread or NULL in 2832 * Returns the entered isolate for the current thread or NULL in
2833 * case there is no current isolate. 2833 * case there is no current isolate.
2834 */ 2834 */
2835 static Isolate* GetCurrent(); 2835 static Isolate* GetCurrent();
2836 2836
2837 /** 2837 /**
2838 * Methods below this point require holding a lock (using Locker) in 2838 * Methods below this point require holding a lock (using Locker) in
2839 * a multi-threaded environment. 2839 * a multi-threaded environment.
2840 */ 2840 */
2841 2841
2842 /** 2842 /**
2843 * Sets this isolate as the entered one for the current thread. 2843 * Sets this isolate as the entered one for the current thread.
2844 * Saves the previously entered one (if any), so that it can be 2844 * Saves the previously entered one (if any), so that it can be
2845 * restored when exiting. Re-entering an isolate is allowed. 2845 * restored when exiting. Re-entering an isolate is allowed.
2846 */ 2846 */
2847 void Enter(); 2847 void Enter();
2848 2848
2849 /** 2849 /**
2850 * Exits this isolate by restoring the previously entered one in the 2850 * Exits this isolate by restoring the previously entered one in the
2851 * current thread. The isolate may still stay the same, if it was 2851 * current thread. The isolate may still stay the same, if it was
2852 * entered more than once. 2852 * entered more than once.
2853 * 2853 *
2854 * Requires: this == Isolate::GetCurrent(). 2854 * Requires: this == Isolate::GetCurrent().
2855 */ 2855 */
2856 void Exit(); 2856 void Exit();
2857 2857
2858 /** 2858 /**
2859 * Disposes the isolate. The isolate must not be entered by any 2859 * Disposes the isolate. The isolate must not be entered by any
2860 * thread to be disposable. 2860 * thread to be disposable.
2861 */ 2861 */
2862 void Dispose(); 2862 void Dispose();
2863 2863
2864 /** 2864 /**
2865 * Associate embedder-specific data with the isolate 2865 * Associate embedder-specific data with the isolate
2866 */ 2866 */
2867 inline void SetData(void* data); 2867 inline void SetData(void* data);
2868 2868
2869 /** 2869 /**
2870 * Retrieve embedder-specific data from the isolate. 2870 * Retrieve embedder-specific data from the isolate.
2871 * Returns NULL if SetData has never been called. 2871 * Returns NULL if SetData has never been called.
2872 */ 2872 */
2873 inline void* GetData(); 2873 inline void* GetData();
2874 2874
2875 private: 2875 private:
2876 Isolate(); 2876 Isolate();
2877 Isolate(const Isolate&); 2877 Isolate(const Isolate&);
2878 ~Isolate(); 2878 ~Isolate();
2879 Isolate& operator=(const Isolate&); 2879 Isolate& operator=(const Isolate&);
2880 void* operator new(size_t size); 2880 void* operator new(size_t size);
2881 void operator delete(void*, size_t); 2881 void operator delete(void*, size_t);
2882 }; 2882 };
2883 2883
2884 2884
2885 class StartupData { 2885 class StartupData {
2886 public: 2886 public:
2887 enum CompressionAlgorithm { 2887 enum CompressionAlgorithm {
2888 kUncompressed, 2888 kUncompressed,
2889 kBZip2 2889 kBZip2
2890 }; 2890 };
2891 2891
2892 const char* data; 2892 const char* data;
2893 int compressed_size; 2893 int compressed_size;
2894 int raw_size; 2894 int raw_size;
2895 }; 2895 };
2896 2896
2897 2897
2898 /** 2898 /**
2899 * A helper class for driving V8 startup data decompression. It is based on 2899 * A helper class for driving V8 startup data decompression. It is based on
2900 * "CompressedStartupData" API functions from the V8 class. It isn't mandatory 2900 * "CompressedStartupData" API functions from the V8 class. It isn't mandatory
2901 * for an embedder to use this class, instead, API functions can be used 2901 * for an embedder to use this class, instead, API functions can be used
2902 * directly. 2902 * directly.
2903 * 2903 *
2904 * For an example of the class usage, see the "shell.cc" sample application. 2904 * For an example of the class usage, see the "shell.cc" sample application.
2905 */ 2905 */
2906 class V8EXPORT StartupDataDecompressor { // NOLINT 2906 class V8EXPORT StartupDataDecompressor { // NOLINT
2907 public: 2907 public:
2908 StartupDataDecompressor(); 2908 StartupDataDecompressor();
2909 virtual ~StartupDataDecompressor(); 2909 virtual ~StartupDataDecompressor();
2910 int Decompress(); 2910 int Decompress();
2911 2911
2912 protected: 2912 protected:
2913 virtual int DecompressData(char* raw_data, 2913 virtual int DecompressData(char* raw_data,
2914 int* raw_data_size, 2914 int* raw_data_size,
2915 const char* compressed_data, 2915 const char* compressed_data,
2916 int compressed_data_size) = 0; 2916 int compressed_data_size) = 0;
2917 2917
2918 private: 2918 private:
2919 char** raw_data; 2919 char** raw_data;
2920 }; 2920 };
2921 2921
2922 2922
2923 /** 2923 /**
2924 * EntropySource is used as a callback function when v8 needs a source 2924 * EntropySource is used as a callback function when v8 needs a source
2925 * of entropy. 2925 * of entropy.
2926 */ 2926 */
2927 typedef bool (*EntropySource)(unsigned char* buffer, size_t length); 2927 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
2928 2928
2929 2929
2930 /** 2930 /**
2931 * ReturnAddressLocationResolver is used as a callback function when v8 is 2931 * ReturnAddressLocationResolver is used as a callback function when v8 is
2932 * resolving the location of a return address on the stack. Profilers that 2932 * resolving the location of a return address on the stack. Profilers that
2933 * change the return address on the stack can use this to resolve the stack 2933 * change the return address on the stack can use this to resolve the stack
2934 * location to whereever the profiler stashed the original return address. 2934 * location to whereever the profiler stashed the original return address.
2935 * 2935 *
2936 * \param return_addr_location points to a location on stack where a machine 2936 * \param return_addr_location points to a location on stack where a machine
2937 * return address resides. 2937 * return address resides.
2938 * \returns either return_addr_location, or else a pointer to the profiler's 2938 * \returns either return_addr_location, or else a pointer to the profiler's
2939 * copy of the original return address. 2939 * copy of the original return address.
2940 * 2940 *
2941 * \note the resolver function must not cause garbage collection. 2941 * \note the resolver function must not cause garbage collection.
2942 */ 2942 */
2943 typedef uintptr_t (*ReturnAddressLocationResolver)( 2943 typedef uintptr_t (*ReturnAddressLocationResolver)(
2944 uintptr_t return_addr_location); 2944 uintptr_t return_addr_location);
2945 2945
2946 2946
2947 /** 2947 /**
2948 * FunctionEntryHook is the type of the profile entry hook called at entry to 2948 * FunctionEntryHook is the type of the profile entry hook called at entry to
2949 * any generated function when function-level profiling is enabled. 2949 * any generated function when function-level profiling is enabled.
2950 * 2950 *
2951 * \param function the address of the function that's being entered. 2951 * \param function the address of the function that's being entered.
2952 * \param return_addr_location points to a location on stack where the machine 2952 * \param return_addr_location points to a location on stack where the machine
2953 * return address resides. This can be used to identify the caller of 2953 * return address resides. This can be used to identify the caller of
2954 * \p function, and/or modified to divert execution when \p function exits. 2954 * \p function, and/or modified to divert execution when \p function exits.
2955 * 2955 *
2956 * \note the entry hook must not cause garbage collection. 2956 * \note the entry hook must not cause garbage collection.
2957 */ 2957 */
2958 typedef void (*FunctionEntryHook)(uintptr_t function, 2958 typedef void (*FunctionEntryHook)(uintptr_t function,
2959 uintptr_t return_addr_location); 2959 uintptr_t return_addr_location);
2960 2960
2961 2961
2962 /** 2962 /**
2963 * A JIT code event is issued each time code is added, moved or removed. 2963 * A JIT code event is issued each time code is added, moved or removed.
2964 * 2964 *
2965 * \note removal events are not currently issued. 2965 * \note removal events are not currently issued.
2966 */ 2966 */
2967 struct JitCodeEvent { 2967 struct JitCodeEvent {
2968 enum EventType { 2968 enum EventType {
2969 CODE_ADDED, 2969 CODE_ADDED,
2970 CODE_MOVED, 2970 CODE_MOVED,
2971 CODE_REMOVED 2971 CODE_REMOVED
2972 }; 2972 };
2973 2973
2974 // Type of event. 2974 // Type of event.
2975 EventType type; 2975 EventType type;
2976 // Start of the instructions. 2976 // Start of the instructions.
2977 void* code_start; 2977 void* code_start;
2978 // Size of the instructions. 2978 // Size of the instructions.
2979 size_t code_len; 2979 size_t code_len;
2980 2980
2981 union { 2981 union {
2982 // Only valid for CODE_ADDED. 2982 // Only valid for CODE_ADDED.
2983 struct { 2983 struct {
2984 // Name of the object associated with the code, note that the string is 2984 // Name of the object associated with the code, note that the string is
2985 // not zero-terminated. 2985 // not zero-terminated.
2986 const char* str; 2986 const char* str;
2987 // Number of chars in str. 2987 // Number of chars in str.
2988 size_t len; 2988 size_t len;
2989 } name; 2989 } name;
2990 // New location of instructions. Only valid for CODE_MOVED. 2990 // New location of instructions. Only valid for CODE_MOVED.
2991 void* new_code_start; 2991 void* new_code_start;
2992 }; 2992 };
2993 }; 2993 };
2994 2994
2995 /** 2995 /**
2996 * Option flags passed to the SetJitCodeEventHandler function. 2996 * Option flags passed to the SetJitCodeEventHandler function.
2997 */ 2997 */
2998 enum JitCodeEventOptions { 2998 enum JitCodeEventOptions {
2999 kJitCodeEventDefault = 0, 2999 kJitCodeEventDefault = 0,
3000 // Generate callbacks for already existent code. 3000 // Generate callbacks for already existent code.
3001 kJitCodeEventEnumExisting = 1 3001 kJitCodeEventEnumExisting = 1
3002 }; 3002 };
3003 3003
3004 3004
3005 /** 3005 /**
3006 * Callback function passed to SetJitCodeEventHandler. 3006 * Callback function passed to SetJitCodeEventHandler.
3007 * 3007 *
3008 * \param event code add, move or removal event. 3008 * \param event code add, move or removal event.
3009 */ 3009 */
3010 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); 3010 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
3011 3011
3012 3012
3013 /** 3013 /**
3014 * Interface for iterating though all external resources in the heap. 3014 * Interface for iterating though all external resources in the heap.
3015 */ 3015 */
3016 class V8EXPORT ExternalResourceVisitor { // NOLINT 3016 class V8EXPORT ExternalResourceVisitor { // NOLINT
3017 public: 3017 public:
3018 virtual ~ExternalResourceVisitor() {} 3018 virtual ~ExternalResourceVisitor() {}
3019 virtual void VisitExternalString(Handle<String> string) {} 3019 virtual void VisitExternalString(Handle<String> string) {}
3020 }; 3020 };
3021 3021
3022 3022
3023 /** 3023 /**
3024 * Container class for static utility functions. 3024 * Container class for static utility functions.
3025 */ 3025 */
3026 class V8EXPORT V8 { 3026 class V8EXPORT V8 {
3027 public: 3027 public:
3028 /** Set the callback to invoke in case of fatal errors. */ 3028 /** Set the callback to invoke in case of fatal errors. */
3029 static void SetFatalErrorHandler(FatalErrorCallback that); 3029 static void SetFatalErrorHandler(FatalErrorCallback that);
3030 3030
3031 /** 3031 /**
3032 * Set the callback to invoke to check if code generation from 3032 * Set the callback to invoke to check if code generation from
3033 * strings should be allowed. 3033 * strings should be allowed.
3034 */ 3034 */
3035 static void SetAllowCodeGenerationFromStringsCallback( 3035 static void SetAllowCodeGenerationFromStringsCallback(
3036 AllowCodeGenerationFromStringsCallback that); 3036 AllowCodeGenerationFromStringsCallback that);
3037 3037
3038 /** 3038 /**
3039 * Ignore out-of-memory exceptions. 3039 * Ignore out-of-memory exceptions.
3040 * 3040 *
3041 * V8 running out of memory is treated as a fatal error by default. 3041 * V8 running out of memory is treated as a fatal error by default.
3042 * This means that the fatal error handler is called and that V8 is 3042 * This means that the fatal error handler is called and that V8 is
3043 * terminated. 3043 * terminated.
3044 * 3044 *
3045 * IgnoreOutOfMemoryException can be used to not treat an 3045 * IgnoreOutOfMemoryException can be used to not treat an
3046 * out-of-memory situation as a fatal error. This way, the contexts 3046 * out-of-memory situation as a fatal error. This way, the contexts
3047 * that did not cause the out of memory problem might be able to 3047 * that did not cause the out of memory problem might be able to
3048 * continue execution. 3048 * continue execution.
3049 */ 3049 */
3050 static void IgnoreOutOfMemoryException(); 3050 static void IgnoreOutOfMemoryException();
3051 3051
3052 /** 3052 /**
3053 * Check if V8 is dead and therefore unusable. This is the case after 3053 * Check if V8 is dead and therefore unusable. This is the case after
3054 * fatal errors such as out-of-memory situations. 3054 * fatal errors such as out-of-memory situations.
3055 */ 3055 */
3056 static bool IsDead(); 3056 static bool IsDead();
3057 3057
3058 /** 3058 /**
3059 * The following 4 functions are to be used when V8 is built with 3059 * The following 4 functions are to be used when V8 is built with
3060 * the 'compress_startup_data' flag enabled. In this case, the 3060 * the 'compress_startup_data' flag enabled. In this case, the
3061 * embedder must decompress startup data prior to initializing V8. 3061 * embedder must decompress startup data prior to initializing V8.
3062 * 3062 *
3063 * This is how interaction with V8 should look like: 3063 * This is how interaction with V8 should look like:
3064 * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); 3064 * int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
3065 * v8::StartupData* compressed_data = 3065 * v8::StartupData* compressed_data =
3066 * new v8::StartupData[compressed_data_count]; 3066 * new v8::StartupData[compressed_data_count];
3067 * v8::V8::GetCompressedStartupData(compressed_data); 3067 * v8::V8::GetCompressedStartupData(compressed_data);
3068 * ... decompress data (compressed_data can be updated in-place) ... 3068 * ... decompress data (compressed_data can be updated in-place) ...
3069 * v8::V8::SetDecompressedStartupData(compressed_data); 3069 * v8::V8::SetDecompressedStartupData(compressed_data);
3070 * ... now V8 can be initialized 3070 * ... now V8 can be initialized
3071 * ... make sure the decompressed data stays valid until V8 shutdown 3071 * ... make sure the decompressed data stays valid until V8 shutdown
3072 * 3072 *
3073 * A helper class StartupDataDecompressor is provided. It implements 3073 * A helper class StartupDataDecompressor is provided. It implements
3074 * the protocol of the interaction described above, and can be used in 3074 * the protocol of the interaction described above, and can be used in
3075 * most cases instead of calling these API functions directly. 3075 * most cases instead of calling these API functions directly.
3076 */ 3076 */
3077 static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); 3077 static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
3078 static int GetCompressedStartupDataCount(); 3078 static int GetCompressedStartupDataCount();
3079 static void GetCompressedStartupData(StartupData* compressed_data); 3079 static void GetCompressedStartupData(StartupData* compressed_data);
3080 static void SetDecompressedStartupData(StartupData* decompressed_data); 3080 static void SetDecompressedStartupData(StartupData* decompressed_data);
3081 3081
3082 /** 3082 /**
3083 * Adds a message listener. 3083 * Adds a message listener.
3084 * 3084 *
3085 * The same message listener can be added more than once and in that 3085 * The same message listener can be added more than once and in that
3086 * case it will be called more than once for each message. 3086 * case it will be called more than once for each message.
3087 */ 3087 */
3088 static bool AddMessageListener(MessageCallback that, 3088 static bool AddMessageListener(MessageCallback that,
3089 Handle<Value> data = Handle<Value>()); 3089 Handle<Value> data = Handle<Value>());
3090 3090
3091 /** 3091 /**
3092 * Remove all message listeners from the specified callback function. 3092 * Remove all message listeners from the specified callback function.
3093 */ 3093 */
3094 static void RemoveMessageListeners(MessageCallback that); 3094 static void RemoveMessageListeners(MessageCallback that);
3095 3095
3096 /** 3096 /**
3097 * Tells V8 to capture current stack trace when uncaught exception occurs 3097 * Tells V8 to capture current stack trace when uncaught exception occurs
3098 * and report it to the message listeners. The option is off by default. 3098 * and report it to the message listeners. The option is off by default.
3099 */ 3099 */
3100 static void SetCaptureStackTraceForUncaughtExceptions( 3100 static void SetCaptureStackTraceForUncaughtExceptions(
3101 bool capture, 3101 bool capture,
3102 int frame_limit = 10, 3102 int frame_limit = 10,
3103 StackTrace::StackTraceOptions options = StackTrace::kOverview); 3103 StackTrace::StackTraceOptions options = StackTrace::kOverview);
3104 3104
3105 /** 3105 /**
3106 * Sets V8 flags from a string. 3106 * Sets V8 flags from a string.
3107 */ 3107 */
3108 static void SetFlagsFromString(const char* str, int length); 3108 static void SetFlagsFromString(const char* str, int length);
3109 3109
3110 /** 3110 /**
3111 * Sets V8 flags from the command line. 3111 * Sets V8 flags from the command line.
3112 */ 3112 */
3113 static void SetFlagsFromCommandLine(int* argc, 3113 static void SetFlagsFromCommandLine(int* argc,
3114 char** argv, 3114 char** argv,
3115 bool remove_flags); 3115 bool remove_flags);
3116 3116
3117 /** Get the version string. */ 3117 /** Get the version string. */
3118 static const char* GetVersion(); 3118 static const char* GetVersion();
3119 3119
3120 /** 3120 /**
3121 * Enables the host application to provide a mechanism for recording 3121 * Enables the host application to provide a mechanism for recording
3122 * statistics counters. 3122 * statistics counters.
3123 */ 3123 */
3124 static void SetCounterFunction(CounterLookupCallback); 3124 static void SetCounterFunction(CounterLookupCallback);
3125 3125
3126 /** 3126 /**
3127 * Enables the host application to provide a mechanism for recording 3127 * Enables the host application to provide a mechanism for recording
3128 * histograms. The CreateHistogram function returns a 3128 * histograms. The CreateHistogram function returns a
3129 * histogram which will later be passed to the AddHistogramSample 3129 * histogram which will later be passed to the AddHistogramSample
3130 * function. 3130 * function.
3131 */ 3131 */
3132 static void SetCreateHistogramFunction(CreateHistogramCallback); 3132 static void SetCreateHistogramFunction(CreateHistogramCallback);
3133 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); 3133 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
3134 3134
3135 /** 3135 /**
3136 * Enables the computation of a sliding window of states. The sliding 3136 * Enables the computation of a sliding window of states. The sliding
3137 * window information is recorded in statistics counters. 3137 * window information is recorded in statistics counters.
3138 */ 3138 */
3139 static void EnableSlidingStateWindow(); 3139 static void EnableSlidingStateWindow();
3140 3140
3141 /** Callback function for reporting failed access checks.*/ 3141 /** Callback function for reporting failed access checks.*/
3142 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); 3142 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
3143 3143
3144 /** 3144 /**
3145 * Enables the host application to receive a notification before a 3145 * Enables the host application to receive a notification before a
3146 * garbage collection. Allocations are not allowed in the 3146 * garbage collection. Allocations are not allowed in the
3147 * callback function, you therefore cannot manipulate objects (set 3147 * callback function, you therefore cannot manipulate objects (set
3148 * or delete properties for example) since it is possible such 3148 * or delete properties for example) since it is possible such
3149 * operations will result in the allocation of objects. It is possible 3149 * operations will result in the allocation of objects. It is possible
3150 * to specify the GCType filter for your callback. But it is not possible to 3150 * to specify the GCType filter for your callback. But it is not possible to
3151 * register the same callback function two times with different 3151 * register the same callback function two times with different
3152 * GCType filters. 3152 * GCType filters.
3153 */ 3153 */
3154 static void AddGCPrologueCallback( 3154 static void AddGCPrologueCallback(
3155 GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); 3155 GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
3156 3156
3157 /** 3157 /**
3158 * This function removes callback which was installed by 3158 * This function removes callback which was installed by
3159 * AddGCPrologueCallback function. 3159 * AddGCPrologueCallback function.
3160 */ 3160 */
3161 static void RemoveGCPrologueCallback(GCPrologueCallback callback); 3161 static void RemoveGCPrologueCallback(GCPrologueCallback callback);
3162 3162
3163 /** 3163 /**
3164 * The function is deprecated. Please use AddGCPrologueCallback instead. 3164 * The function is deprecated. Please use AddGCPrologueCallback instead.
3165 * Enables the host application to receive a notification before a 3165 * Enables the host application to receive a notification before a
3166 * garbage collection. Allocations are not allowed in the 3166 * garbage collection. Allocations are not allowed in the
3167 * callback function, you therefore cannot manipulate objects (set 3167 * callback function, you therefore cannot manipulate objects (set
3168 * or delete properties for example) since it is possible such 3168 * or delete properties for example) since it is possible such
3169 * operations will result in the allocation of objects. 3169 * operations will result in the allocation of objects.
3170 */ 3170 */
3171 static void SetGlobalGCPrologueCallback(GCCallback); 3171 static void SetGlobalGCPrologueCallback(GCCallback);
3172 3172
3173 /** 3173 /**
3174 * Enables the host application to receive a notification after a 3174 * Enables the host application to receive a notification after a
3175 * garbage collection. Allocations are not allowed in the 3175 * garbage collection. Allocations are not allowed in the
3176 * callback function, you therefore cannot manipulate objects (set 3176 * callback function, you therefore cannot manipulate objects (set
3177 * or delete properties for example) since it is possible such 3177 * or delete properties for example) since it is possible such
3178 * operations will result in the allocation of objects. It is possible 3178 * operations will result in the allocation of objects. It is possible
3179 * to specify the GCType filter for your callback. But it is not possible to 3179 * to specify the GCType filter for your callback. But it is not possible to
3180 * register the same callback function two times with different 3180 * register the same callback function two times with different
3181 * GCType filters. 3181 * GCType filters.
3182 */ 3182 */
3183 static void AddGCEpilogueCallback( 3183 static void AddGCEpilogueCallback(
3184 GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); 3184 GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
3185 3185
3186 /** 3186 /**
3187 * This function removes callback which was installed by 3187 * This function removes callback which was installed by
3188 * AddGCEpilogueCallback function. 3188 * AddGCEpilogueCallback function.
3189 */ 3189 */
3190 static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); 3190 static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
3191 3191
3192 /** 3192 /**
3193 * The function is deprecated. Please use AddGCEpilogueCallback instead. 3193 * The function is deprecated. Please use AddGCEpilogueCallback instead.
3194 * Enables the host application to receive a notification after a 3194 * Enables the host application to receive a notification after a
3195 * major garbage collection. Allocations are not allowed in the 3195 * major garbage collection. Allocations are not allowed in the
3196 * callback function, you therefore cannot manipulate objects (set 3196 * callback function, you therefore cannot manipulate objects (set
3197 * or delete properties for example) since it is possible such 3197 * or delete properties for example) since it is possible such
3198 * operations will result in the allocation of objects. 3198 * operations will result in the allocation of objects.
3199 */ 3199 */
3200 static void SetGlobalGCEpilogueCallback(GCCallback); 3200 static void SetGlobalGCEpilogueCallback(GCCallback);
3201 3201
3202 /** 3202 /**
3203 * Enables the host application to provide a mechanism to be notified 3203 * Enables the host application to provide a mechanism to be notified
3204 * and perform custom logging when V8 Allocates Executable Memory. 3204 * and perform custom logging when V8 Allocates Executable Memory.
3205 */ 3205 */
3206 static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, 3206 static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
3207 ObjectSpace space, 3207 ObjectSpace space,
3208 AllocationAction action); 3208 AllocationAction action);
3209 3209
3210 /** 3210 /**
3211 * Removes callback that was installed by AddMemoryAllocationCallback. 3211 * Removes callback that was installed by AddMemoryAllocationCallback.
3212 */ 3212 */
3213 static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); 3213 static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
3214 3214
3215 /** 3215 /**
3216 * Adds a callback to notify the host application when a script finished 3216 * Adds a callback to notify the host application when a script finished
3217 * running. If a script re-enters the runtime during executing, the 3217 * running. If a script re-enters the runtime during executing, the
3218 * CallCompletedCallback is only invoked when the outer-most script 3218 * CallCompletedCallback is only invoked when the outer-most script
3219 * execution ends. Executing scripts inside the callback do not trigger 3219 * execution ends. Executing scripts inside the callback do not trigger
3220 * further callbacks. 3220 * further callbacks.
3221 */ 3221 */
3222 static void AddCallCompletedCallback(CallCompletedCallback callback); 3222 static void AddCallCompletedCallback(CallCompletedCallback callback);
3223 3223
3224 /** 3224 /**
3225 * Removes callback that was installed by AddCallCompletedCallback. 3225 * Removes callback that was installed by AddCallCompletedCallback.
3226 */ 3226 */
3227 static void RemoveCallCompletedCallback(CallCompletedCallback callback); 3227 static void RemoveCallCompletedCallback(CallCompletedCallback callback);
3228 3228
3229 /** 3229 /**
3230 * Allows the host application to group objects together. If one 3230 * Allows the host application to group objects together. If one
3231 * object in the group is alive, all objects in the group are alive. 3231 * object in the group is alive, all objects in the group are alive.
3232 * After each garbage collection, object groups are removed. It is 3232 * After each garbage collection, object groups are removed. It is
3233 * intended to be used in the before-garbage-collection callback 3233 * intended to be used in the before-garbage-collection callback
3234 * function, for instance to simulate DOM tree connections among JS 3234 * function, for instance to simulate DOM tree connections among JS
3235 * wrapper objects. 3235 * wrapper objects.
3236 * See v8-profiler.h for RetainedObjectInfo interface description. 3236 * See v8-profiler.h for RetainedObjectInfo interface description.
3237 */ 3237 */
3238 static void AddObjectGroup(Persistent<Value>* objects, 3238 static void AddObjectGroup(Persistent<Value>* objects,
3239 size_t length, 3239 size_t length,
3240 RetainedObjectInfo* info = NULL); 3240 RetainedObjectInfo* info = NULL);
3241 3241
3242 /** 3242 /**
3243 * Allows the host application to declare implicit references between 3243 * Allows the host application to declare implicit references between
3244 * the objects: if |parent| is alive, all |children| are alive too. 3244 * the objects: if |parent| is alive, all |children| are alive too.
3245 * After each garbage collection, all implicit references 3245 * After each garbage collection, all implicit references
3246 * are removed. It is intended to be used in the before-garbage-collection 3246 * are removed. It is intended to be used in the before-garbage-collection
3247 * callback function. 3247 * callback function.
3248 */ 3248 */
3249 static void AddImplicitReferences(Persistent<Object> parent, 3249 static void AddImplicitReferences(Persistent<Object> parent,
3250 Persistent<Value>* children, 3250 Persistent<Value>* children,
3251 size_t length); 3251 size_t length);
3252 3252
3253 /** 3253 /**
3254 * Initializes from snapshot if possible. Otherwise, attempts to 3254 * Initializes from snapshot if possible. Otherwise, attempts to
3255 * initialize from scratch. This function is called implicitly if 3255 * initialize from scratch. This function is called implicitly if
3256 * you use the API without calling it first. 3256 * you use the API without calling it first.
3257 */ 3257 */
3258 static bool Initialize(); 3258 static bool Initialize();
3259 3259
3260 /** 3260 /**
3261 * Allows the host application to provide a callback which can be used 3261 * Allows the host application to provide a callback which can be used
3262 * as a source of entropy for random number generators. 3262 * as a source of entropy for random number generators.
3263 */ 3263 */
3264 static void SetEntropySource(EntropySource source); 3264 static void SetEntropySource(EntropySource source);
3265 3265
3266 /** 3266 /**
3267 * Allows the host application to provide a callback that allows v8 to 3267 * Allows the host application to provide a callback that allows v8 to
3268 * cooperate with a profiler that rewrites return addresses on stack. 3268 * cooperate with a profiler that rewrites return addresses on stack.
3269 */ 3269 */
3270 static void SetReturnAddressLocationResolver( 3270 static void SetReturnAddressLocationResolver(
3271 ReturnAddressLocationResolver return_address_resolver); 3271 ReturnAddressLocationResolver return_address_resolver);
3272 3272
3273 /** 3273 /**
3274 * Allows the host application to provide the address of a function that's 3274 * Allows the host application to provide the address of a function that's
3275 * invoked on entry to every V8-generated function. 3275 * invoked on entry to every V8-generated function.
3276 * Note that \p entry_hook is invoked at the very start of each 3276 * Note that \p entry_hook is invoked at the very start of each
3277 * generated function. 3277 * generated function.
3278 * 3278 *
3279 * \param entry_hook a function that will be invoked on entry to every 3279 * \param entry_hook a function that will be invoked on entry to every
3280 * V8-generated function. 3280 * V8-generated function.
3281 * \returns true on success on supported platforms, false on failure. 3281 * \returns true on success on supported platforms, false on failure.
3282 * \note Setting a new entry hook function when one is already active will 3282 * \note Setting a new entry hook function when one is already active will
3283 * fail. 3283 * fail.
3284 */ 3284 */
3285 static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); 3285 static bool SetFunctionEntryHook(FunctionEntryHook entry_hook);
3286 3286
3287 /** 3287 /**
3288 * Allows the host application to provide the address of a function that is 3288 * Allows the host application to provide the address of a function that is
3289 * notified each time code is added, moved or removed. 3289 * notified each time code is added, moved or removed.
3290 * 3290 *
3291 * \param options options for the JIT code event handler. 3291 * \param options options for the JIT code event handler.
3292 * \param event_handler the JIT code event handler, which will be invoked 3292 * \param event_handler the JIT code event handler, which will be invoked
3293 * each time code is added, moved or removed. 3293 * each time code is added, moved or removed.
3294 * \note \p event_handler won't get notified of existent code. 3294 * \note \p event_handler won't get notified of existent code.
3295 * \note since code removal notifications are not currently issued, the 3295 * \note since code removal notifications are not currently issued, the
3296 * \p event_handler may get notifications of code that overlaps earlier 3296 * \p event_handler may get notifications of code that overlaps earlier
3297 * code notifications. This happens when code areas are reused, and the 3297 * code notifications. This happens when code areas are reused, and the
3298 * earlier overlapping code areas should therefore be discarded. 3298 * earlier overlapping code areas should therefore be discarded.
3299 * \note the events passed to \p event_handler and the strings they point to 3299 * \note the events passed to \p event_handler and the strings they point to
3300 * are not guaranteed to live past each call. The \p event_handler must 3300 * are not guaranteed to live past each call. The \p event_handler must
3301 * copy strings and other parameters it needs to keep around. 3301 * copy strings and other parameters it needs to keep around.
3302 * \note the set of events declared in JitCodeEvent::EventType is expected to 3302 * \note the set of events declared in JitCodeEvent::EventType is expected to
3303 * grow over time, and the JitCodeEvent structure is expected to accrue 3303 * grow over time, and the JitCodeEvent structure is expected to accrue
3304 * new members. The \p event_handler function must ignore event codes 3304 * new members. The \p event_handler function must ignore event codes
3305 * it does not recognize to maintain future compatibility. 3305 * it does not recognize to maintain future compatibility.
3306 */ 3306 */
3307 static void SetJitCodeEventHandler(JitCodeEventOptions options, 3307 static void SetJitCodeEventHandler(JitCodeEventOptions options,
3308 JitCodeEventHandler event_handler); 3308 JitCodeEventHandler event_handler);
3309 3309
3310 /** 3310 /**
3311 * Adjusts the amount of registered external memory. Used to give 3311 * Adjusts the amount of registered external memory. Used to give
3312 * V8 an indication of the amount of externally allocated memory 3312 * V8 an indication of the amount of externally allocated memory
3313 * that is kept alive by JavaScript objects. V8 uses this to decide 3313 * that is kept alive by JavaScript objects. V8 uses this to decide
3314 * when to perform global garbage collections. Registering 3314 * when to perform global garbage collections. Registering
3315 * externally allocated memory will trigger global garbage 3315 * externally allocated memory will trigger global garbage
3316 * collections more often than otherwise in an attempt to garbage 3316 * collections more often than otherwise in an attempt to garbage
3317 * collect the JavaScript objects keeping the externally allocated 3317 * collect the JavaScript objects keeping the externally allocated
3318 * memory alive. 3318 * memory alive.
3319 * 3319 *
3320 * \param change_in_bytes the change in externally allocated memory 3320 * \param change_in_bytes the change in externally allocated memory
3321 * that is kept alive by JavaScript objects. 3321 * that is kept alive by JavaScript objects.
3322 * \returns the adjusted value. 3322 * \returns the adjusted value.
3323 */ 3323 */
3324 static intptr_t AdjustAmountOfExternalAllocatedMemory( 3324 static intptr_t AdjustAmountOfExternalAllocatedMemory(
3325 intptr_t change_in_bytes); 3325 intptr_t change_in_bytes);
3326 3326
3327 /** 3327 /**
3328 * Suspends recording of tick samples in the profiler. 3328 * Suspends recording of tick samples in the profiler.
3329 * When the V8 profiling mode is enabled (usually via command line 3329 * When the V8 profiling mode is enabled (usually via command line
3330 * switches) this function suspends recording of tick samples. 3330 * switches) this function suspends recording of tick samples.
3331 * Profiling ticks are discarded until ResumeProfiler() is called. 3331 * Profiling ticks are discarded until ResumeProfiler() is called.
3332 * 3332 *
3333 * See also the --prof and --prof_auto command line switches to 3333 * See also the --prof and --prof_auto command line switches to
3334 * enable V8 profiling. 3334 * enable V8 profiling.
3335 */ 3335 */
3336 static void PauseProfiler(); 3336 static void PauseProfiler();
3337 3337
3338 /** 3338 /**
3339 * Resumes recording of tick samples in the profiler. 3339 * Resumes recording of tick samples in the profiler.
3340 * See also PauseProfiler(). 3340 * See also PauseProfiler().
3341 */ 3341 */
3342 static void ResumeProfiler(); 3342 static void ResumeProfiler();
3343 3343
3344 /** 3344 /**
3345 * Return whether profiler is currently paused. 3345 * Return whether profiler is currently paused.
3346 */ 3346 */
3347 static bool IsProfilerPaused(); 3347 static bool IsProfilerPaused();
3348 3348
3349 /** 3349 /**
3350 * Retrieve the V8 thread id of the calling thread. 3350 * Retrieve the V8 thread id of the calling thread.
3351 * 3351 *
3352 * The thread id for a thread should only be retrieved after the V8 3352 * The thread id for a thread should only be retrieved after the V8
3353 * lock has been acquired with a Locker object with that thread. 3353 * lock has been acquired with a Locker object with that thread.
3354 */ 3354 */
3355 static int GetCurrentThreadId(); 3355 static int GetCurrentThreadId();
3356 3356
3357 /** 3357 /**
3358 * Forcefully terminate execution of a JavaScript thread. This can 3358 * Forcefully terminate execution of a JavaScript thread. This can
3359 * be used to terminate long-running scripts. 3359 * be used to terminate long-running scripts.
3360 * 3360 *
3361 * TerminateExecution should only be called when then V8 lock has 3361 * TerminateExecution should only be called when then V8 lock has
3362 * been acquired with a Locker object. Therefore, in order to be 3362 * been acquired with a Locker object. Therefore, in order to be
3363 * able to terminate long-running threads, preemption must be 3363 * able to terminate long-running threads, preemption must be
3364 * enabled to allow the user of TerminateExecution to acquire the 3364 * enabled to allow the user of TerminateExecution to acquire the
3365 * lock. 3365 * lock.
3366 * 3366 *
3367 * The termination is achieved by throwing an exception that is 3367 * The termination is achieved by throwing an exception that is
3368 * uncatchable by JavaScript exception handlers. Termination 3368 * uncatchable by JavaScript exception handlers. Termination
3369 * exceptions act as if they were caught by a C++ TryCatch exception 3369 * exceptions act as if they were caught by a C++ TryCatch exception
3370 * handler. If forceful termination is used, any C++ TryCatch 3370 * handler. If forceful termination is used, any C++ TryCatch
3371 * exception handler that catches an exception should check if that 3371 * exception handler that catches an exception should check if that
3372 * exception is a termination exception and immediately return if 3372 * exception is a termination exception and immediately return if
3373 * that is the case. Returning immediately in that case will 3373 * that is the case. Returning immediately in that case will
3374 * continue the propagation of the termination exception if needed. 3374 * continue the propagation of the termination exception if needed.
3375 * 3375 *
3376 * The thread id passed to TerminateExecution must have been 3376 * The thread id passed to TerminateExecution must have been
3377 * obtained by calling GetCurrentThreadId on the thread in question. 3377 * obtained by calling GetCurrentThreadId on the thread in question.
3378 * 3378 *
3379 * \param thread_id The thread id of the thread to terminate. 3379 * \param thread_id The thread id of the thread to terminate.
3380 */ 3380 */
3381 static void TerminateExecution(int thread_id); 3381 static void TerminateExecution(int thread_id);
3382 3382
3383 /** 3383 /**
3384 * Forcefully terminate the current thread of JavaScript execution 3384 * Forcefully terminate the current thread of JavaScript execution
3385 * in the given isolate. If no isolate is provided, the default 3385 * in the given isolate. If no isolate is provided, the default
3386 * isolate is used. 3386 * isolate is used.
3387 * 3387 *
3388 * This method can be used by any thread even if that thread has not 3388 * This method can be used by any thread even if that thread has not
3389 * acquired the V8 lock with a Locker object. 3389 * acquired the V8 lock with a Locker object.
3390 * 3390 *
3391 * \param isolate The isolate in which to terminate the current JS execution. 3391 * \param isolate The isolate in which to terminate the current JS execution.
3392 */ 3392 */
3393 static void TerminateExecution(Isolate* isolate = NULL); 3393 static void TerminateExecution(Isolate* isolate = NULL);
3394 3394
3395 /** 3395 /**
3396 * Is V8 terminating JavaScript execution. 3396 * Is V8 terminating JavaScript execution.
3397 * 3397 *
3398 * Returns true if JavaScript execution is currently terminating 3398 * Returns true if JavaScript execution is currently terminating
3399 * because of a call to TerminateExecution. In that case there are 3399 * because of a call to TerminateExecution. In that case there are
3400 * still JavaScript frames on the stack and the termination 3400 * still JavaScript frames on the stack and the termination
3401 * exception is still active. 3401 * exception is still active.
3402 * 3402 *
3403 * \param isolate The isolate in which to check. 3403 * \param isolate The isolate in which to check.
3404 */ 3404 */
3405 static bool IsExecutionTerminating(Isolate* isolate = NULL); 3405 static bool IsExecutionTerminating(Isolate* isolate = NULL);
3406 3406
3407 /** 3407 /**
3408 * Releases any resources used by v8 and stops any utility threads 3408 * Releases any resources used by v8 and stops any utility threads
3409 * that may be running. Note that disposing v8 is permanent, it 3409 * that may be running. Note that disposing v8 is permanent, it
3410 * cannot be reinitialized. 3410 * cannot be reinitialized.
3411 * 3411 *
3412 * It should generally not be necessary to dispose v8 before exiting 3412 * It should generally not be necessary to dispose v8 before exiting
3413 * a process, this should happen automatically. It is only necessary 3413 * a process, this should happen automatically. It is only necessary
3414 * to use if the process needs the resources taken up by v8. 3414 * to use if the process needs the resources taken up by v8.
3415 */ 3415 */
3416 static bool Dispose(); 3416 static bool Dispose();
3417 3417
3418 /** 3418 /**
3419 * Get statistics about the heap memory usage. 3419 * Get statistics about the heap memory usage.
3420 */ 3420 */
3421 static void GetHeapStatistics(HeapStatistics* heap_statistics); 3421 static void GetHeapStatistics(HeapStatistics* heap_statistics);
3422 3422
3423 /** 3423 /**
3424 * Iterates through all external resources referenced from current isolate 3424 * Iterates through all external resources referenced from current isolate
3425 * heap. This method is not expected to be used except for debugging purposes 3425 * heap. This method is not expected to be used except for debugging purposes
3426 * and may be quite slow. 3426 * and may be quite slow.
3427 */ 3427 */
3428 static void VisitExternalResources(ExternalResourceVisitor* visitor); 3428 static void VisitExternalResources(ExternalResourceVisitor* visitor);
3429 3429
3430 /** 3430 /**
3431 * Optional notification that the embedder is idle. 3431 * Optional notification that the embedder is idle.
3432 * V8 uses the notification to reduce memory footprint. 3432 * V8 uses the notification to reduce memory footprint.
3433 * This call can be used repeatedly if the embedder remains idle. 3433 * This call can be used repeatedly if the embedder remains idle.
3434 * Returns true if the embedder should stop calling IdleNotification 3434 * Returns true if the embedder should stop calling IdleNotification
3435 * until real work has been done. This indicates that V8 has done 3435 * until real work has been done. This indicates that V8 has done
3436 * as much cleanup as it will be able to do. 3436 * as much cleanup as it will be able to do.
3437 * 3437 *
3438 * The hint argument specifies the amount of work to be done in the function 3438 * The hint argument specifies the amount of work to be done in the function
3439 * on scale from 1 to 1000. There is no guarantee that the actual work will 3439 * on scale from 1 to 1000. There is no guarantee that the actual work will
3440 * match the hint. 3440 * match the hint.
3441 */ 3441 */
3442 static bool IdleNotification(int hint = 1000); 3442 static bool IdleNotification(int hint = 1000);
3443 3443
3444 /** 3444 /**
3445 * Optional notification that the system is running low on memory. 3445 * Optional notification that the system is running low on memory.
3446 * V8 uses these notifications to attempt to free memory. 3446 * V8 uses these notifications to attempt to free memory.
3447 */ 3447 */
3448 static void LowMemoryNotification(); 3448 static void LowMemoryNotification();
3449 3449
3450 /** 3450 /**
3451 * Optional notification that a context has been disposed. V8 uses 3451 * Optional notification that a context has been disposed. V8 uses
3452 * these notifications to guide the GC heuristic. Returns the number 3452 * these notifications to guide the GC heuristic. Returns the number
3453 * of context disposals - including this one - since the last time 3453 * of context disposals - including this one - since the last time
3454 * V8 had a chance to clean up. 3454 * V8 had a chance to clean up.
3455 */ 3455 */
3456 static int ContextDisposedNotification(); 3456 static int ContextDisposedNotification();
3457 3457
3458 private: 3458 private:
3459 V8(); 3459 V8();
3460 3460
3461 static internal::Object** GlobalizeReference(internal::Object** handle); 3461 static internal::Object** GlobalizeReference(internal::Object** handle);
3462 static void DisposeGlobal(internal::Object** global_handle); 3462 static void DisposeGlobal(internal::Object** global_handle);
3463 static void MakeWeak(internal::Object** global_handle, 3463 static void MakeWeak(internal::Object** global_handle,
3464 void* data, 3464 void* data,
3465 WeakReferenceCallback); 3465 WeakReferenceCallback);
3466 static void ClearWeak(internal::Object** global_handle); 3466 static void ClearWeak(internal::Object** global_handle);
3467 static void MarkIndependent(internal::Object** global_handle); 3467 static void MarkIndependent(internal::Object** global_handle);
3468 static bool IsGlobalNearDeath(internal::Object** global_handle); 3468 static bool IsGlobalNearDeath(internal::Object** global_handle);
3469 static bool IsGlobalWeak(internal::Object** global_handle); 3469 static bool IsGlobalWeak(internal::Object** global_handle);
3470 static void SetWrapperClassId(internal::Object** global_handle, 3470 static void SetWrapperClassId(internal::Object** global_handle,
3471 uint16_t class_id); 3471 uint16_t class_id);
3472 3472
3473 template <class T> friend class Handle; 3473 template <class T> friend class Handle;
3474 template <class T> friend class Local; 3474 template <class T> friend class Local;
3475 template <class T> friend class Persistent; 3475 template <class T> friend class Persistent;
3476 friend class Context; 3476 friend class Context;
3477 }; 3477 };
3478 3478
3479 3479
3480 /** 3480 /**
3481 * An external exception handler. 3481 * An external exception handler.
3482 */ 3482 */
3483 class V8EXPORT TryCatch { 3483 class V8EXPORT TryCatch {
3484 public: 3484 public:
3485 /** 3485 /**
3486 * Creates a new try/catch block and registers it with v8. 3486 * Creates a new try/catch block and registers it with v8.
3487 */ 3487 */
3488 TryCatch(); 3488 TryCatch();
3489 3489
3490 /** 3490 /**
3491 * Unregisters and deletes this try/catch block. 3491 * Unregisters and deletes this try/catch block.
3492 */ 3492 */
3493 ~TryCatch(); 3493 ~TryCatch();
3494 3494
3495 /** 3495 /**
3496 * Returns true if an exception has been caught by this try/catch block. 3496 * Returns true if an exception has been caught by this try/catch block.
3497 */ 3497 */
3498 bool HasCaught() const; 3498 bool HasCaught() const;
3499 3499
3500 /** 3500 /**
3501 * For certain types of exceptions, it makes no sense to continue 3501 * For certain types of exceptions, it makes no sense to continue
3502 * execution. 3502 * execution.
3503 * 3503 *
3504 * Currently, the only type of exception that can be caught by a 3504 * Currently, the only type of exception that can be caught by a
3505 * TryCatch handler and for which it does not make sense to continue 3505 * TryCatch handler and for which it does not make sense to continue
3506 * is termination exception. Such exceptions are thrown when the 3506 * is termination exception. Such exceptions are thrown when the
3507 * TerminateExecution methods are called to terminate a long-running 3507 * TerminateExecution methods are called to terminate a long-running
3508 * script. 3508 * script.
3509 * 3509 *
3510 * If CanContinue returns false, the correct action is to perform 3510 * If CanContinue returns false, the correct action is to perform
3511 * any C++ cleanup needed and then return. 3511 * any C++ cleanup needed and then return.
3512 */ 3512 */
3513 bool CanContinue() const; 3513 bool CanContinue() const;
3514 3514
3515 /** 3515 /**
3516 * Throws the exception caught by this TryCatch in a way that avoids 3516 * Throws the exception caught by this TryCatch in a way that avoids
3517 * it being caught again by this same TryCatch. As with ThrowException 3517 * it being caught again by this same TryCatch. As with ThrowException
3518 * it is illegal to execute any JavaScript operations after calling 3518 * it is illegal to execute any JavaScript operations after calling
3519 * ReThrow; the caller must return immediately to where the exception 3519 * ReThrow; the caller must return immediately to where the exception
3520 * is caught. 3520 * is caught.
3521 */ 3521 */
3522 Handle<Value> ReThrow(); 3522 Handle<Value> ReThrow();
3523 3523
3524 /** 3524 /**
3525 * Returns the exception caught by this try/catch block. If no exception has 3525 * Returns the exception caught by this try/catch block. If no exception has
3526 * been caught an empty handle is returned. 3526 * been caught an empty handle is returned.
3527 * 3527 *
3528 * The returned handle is valid until this TryCatch block has been destroyed. 3528 * The returned handle is valid until this TryCatch block has been destroyed.
3529 */ 3529 */
3530 Local<Value> Exception() const; 3530 Local<Value> Exception() const;
3531 3531
3532 /** 3532 /**
3533 * Returns the .stack property of the thrown object. If no .stack 3533 * Returns the .stack property of the thrown object. If no .stack
3534 * property is present an empty handle is returned. 3534 * property is present an empty handle is returned.
3535 */ 3535 */
3536 Local<Value> StackTrace() const; 3536 Local<Value> StackTrace() const;
3537 3537
3538 /** 3538 /**
3539 * Returns the message associated with this exception. If there is 3539 * Returns the message associated with this exception. If there is
3540 * no message associated an empty handle is returned. 3540 * no message associated an empty handle is returned.
3541 * 3541 *
3542 * The returned handle is valid until this TryCatch block has been 3542 * The returned handle is valid until this TryCatch block has been
3543 * destroyed. 3543 * destroyed.
3544 */ 3544 */
3545 Local<v8::Message> Message() const; 3545 Local<v8::Message> Message() const;
3546 3546
3547 /** 3547 /**
3548 * Clears any exceptions that may have been caught by this try/catch block. 3548 * Clears any exceptions that may have been caught by this try/catch block.
3549 * After this method has been called, HasCaught() will return false. 3549 * After this method has been called, HasCaught() will return false.
3550 * 3550 *
3551 * It is not necessary to clear a try/catch block before using it again; if 3551 * It is not necessary to clear a try/catch block before using it again; if
3552 * another exception is thrown the previously caught exception will just be 3552 * another exception is thrown the previously caught exception will just be
3553 * overwritten. However, it is often a good idea since it makes it easier 3553 * overwritten. However, it is often a good idea since it makes it easier
3554 * to determine which operation threw a given exception. 3554 * to determine which operation threw a given exception.
3555 */ 3555 */
3556 void Reset(); 3556 void Reset();
3557 3557
3558 /** 3558 /**
3559 * Set verbosity of the external exception handler. 3559 * Set verbosity of the external exception handler.
3560 * 3560 *
3561 * By default, exceptions that are caught by an external exception 3561 * By default, exceptions that are caught by an external exception
3562 * handler are not reported. Call SetVerbose with true on an 3562 * handler are not reported. Call SetVerbose with true on an
3563 * external exception handler to have exceptions caught by the 3563 * external exception handler to have exceptions caught by the
3564 * handler reported as if they were not caught. 3564 * handler reported as if they were not caught.
3565 */ 3565 */
3566 void SetVerbose(bool value); 3566 void SetVerbose(bool value);
3567 3567
3568 /** 3568 /**
3569 * Set whether or not this TryCatch should capture a Message object 3569 * Set whether or not this TryCatch should capture a Message object
3570 * which holds source information about where the exception 3570 * which holds source information about where the exception
3571 * occurred. True by default. 3571 * occurred. True by default.
3572 */ 3572 */
3573 void SetCaptureMessage(bool value); 3573 void SetCaptureMessage(bool value);
3574 3574
3575 private: 3575 private:
3576 v8::internal::Isolate* isolate_; 3576 v8::internal::Isolate* isolate_;
3577 void* next_; 3577 void* next_;
3578 void* exception_; 3578 void* exception_;
3579 void* message_; 3579 void* message_;
3580 bool is_verbose_ : 1; 3580 bool is_verbose_ : 1;
3581 bool can_continue_ : 1; 3581 bool can_continue_ : 1;
3582 bool capture_message_ : 1; 3582 bool capture_message_ : 1;
3583 bool rethrow_ : 1; 3583 bool rethrow_ : 1;
3584 3584
3585 friend class v8::internal::Isolate; 3585 friend class v8::internal::Isolate;
3586 }; 3586 };
3587 3587
3588 3588
3589 // --- Context --- 3589 // --- Context ---
3590 3590
3591 3591
3592 /** 3592 /**
3593 * Ignore 3593 * Ignore
3594 */ 3594 */
3595 class V8EXPORT ExtensionConfiguration { 3595 class V8EXPORT ExtensionConfiguration {
3596 public: 3596 public:
3597 ExtensionConfiguration(int name_count, const char* names[]) 3597 ExtensionConfiguration(int name_count, const char* names[])
3598 : name_count_(name_count), names_(names) { } 3598 : name_count_(name_count), names_(names) { }
3599 private: 3599 private:
3600 friend class ImplementationUtilities; 3600 friend class ImplementationUtilities;
3601 int name_count_; 3601 int name_count_;
3602 const char** names_; 3602 const char** names_;
3603 }; 3603 };
3604 3604
3605 3605
3606 /** 3606 /**
3607 * A sandboxed execution context with its own set of built-in objects 3607 * A sandboxed execution context with its own set of built-in objects
3608 * and functions. 3608 * and functions.
3609 */ 3609 */
3610 class V8EXPORT Context { 3610 class V8EXPORT Context {
3611 public: 3611 public:
3612 /** 3612 /**
3613 * Returns the global proxy object or global object itself for 3613 * Returns the global proxy object or global object itself for
3614 * detached contexts. 3614 * detached contexts.
3615 * 3615 *
3616 * Global proxy object is a thin wrapper whose prototype points to 3616 * Global proxy object is a thin wrapper whose prototype points to
3617 * actual context's global object with the properties like Object, etc. 3617 * actual context's global object with the properties like Object, etc.
3618 * This is done that way for security reasons (for more details see 3618 * This is done that way for security reasons (for more details see
3619 * https://wiki.mozilla.org/Gecko:SplitWindow). 3619 * https://wiki.mozilla.org/Gecko:SplitWindow).
3620 * 3620 *
3621 * Please note that changes to global proxy object prototype most probably 3621 * Please note that changes to global proxy object prototype most probably
3622 * would break VM---v8 expects only global object as a prototype of 3622 * would break VM---v8 expects only global object as a prototype of
3623 * global proxy object. 3623 * global proxy object.
3624 * 3624 *
3625 * If DetachGlobal() has been invoked, Global() would return actual global 3625 * If DetachGlobal() has been invoked, Global() would return actual global
3626 * object until global is reattached with ReattachGlobal(). 3626 * object until global is reattached with ReattachGlobal().
3627 */ 3627 */
3628 Local<Object> Global(); 3628 Local<Object> Global();
3629 3629
3630 /** 3630 /**
3631 * Detaches the global object from its context before 3631 * Detaches the global object from its context before
3632 * the global object can be reused to create a new context. 3632 * the global object can be reused to create a new context.
3633 */ 3633 */
3634 void DetachGlobal(); 3634 void DetachGlobal();
3635 3635
3636 /** 3636 /**
3637 * Reattaches a global object to a context. This can be used to 3637 * Reattaches a global object to a context. This can be used to
3638 * restore the connection between a global object and a context 3638 * restore the connection between a global object and a context
3639 * after DetachGlobal has been called. 3639 * after DetachGlobal has been called.
3640 * 3640 *
3641 * \param global_object The global object to reattach to the 3641 * \param global_object The global object to reattach to the
3642 * context. For this to work, the global object must be the global 3642 * context. For this to work, the global object must be the global
3643 * object that was associated with this context before a call to 3643 * object that was associated with this context before a call to
3644 * DetachGlobal. 3644 * DetachGlobal.
3645 */ 3645 */
3646 void ReattachGlobal(Handle<Object> global_object); 3646 void ReattachGlobal(Handle<Object> global_object);
3647 3647
3648 /** Creates a new context. 3648 /** Creates a new context.
3649 * 3649 *
3650 * Returns a persistent handle to the newly allocated context. This 3650 * Returns a persistent handle to the newly allocated context. This
3651 * persistent handle has to be disposed when the context is no 3651 * persistent handle has to be disposed when the context is no
3652 * longer used so the context can be garbage collected. 3652 * longer used so the context can be garbage collected.
3653 * 3653 *
3654 * \param extensions An optional extension configuration containing 3654 * \param extensions An optional extension configuration containing
3655 * the extensions to be installed in the newly created context. 3655 * the extensions to be installed in the newly created context.
3656 * 3656 *
3657 * \param global_template An optional object template from which the 3657 * \param global_template An optional object template from which the
3658 * global object for the newly created context will be created. 3658 * global object for the newly created context will be created.
3659 * 3659 *
3660 * \param global_object An optional global object to be reused for 3660 * \param global_object An optional global object to be reused for
3661 * the newly created context. This global object must have been 3661 * the newly created context. This global object must have been
3662 * created by a previous call to Context::New with the same global 3662 * created by a previous call to Context::New with the same global
3663 * template. The state of the global object will be completely reset 3663 * template. The state of the global object will be completely reset
3664 * and only object identify will remain. 3664 * and only object identify will remain.
3665 */ 3665 */
3666 static Persistent<Context> New( 3666 static Persistent<Context> New(
3667 ExtensionConfiguration* extensions = NULL, 3667 ExtensionConfiguration* extensions = NULL,
3668 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), 3668 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
3669 Handle<Value> global_object = Handle<Value>()); 3669 Handle<Value> global_object = Handle<Value>());
3670 3670
3671 /** Returns the last entered context. */ 3671 /** Returns the last entered context. */
3672 static Local<Context> GetEntered(); 3672 static Local<Context> GetEntered();
3673 3673
3674 /** Returns the context that is on the top of the stack. */ 3674 /** Returns the context that is on the top of the stack. */
3675 static Local<Context> GetCurrent(); 3675 static Local<Context> GetCurrent();
3676 3676
3677 /** 3677 /**
3678 * Returns the context of the calling JavaScript code. That is the 3678 * Returns the context of the calling JavaScript code. That is the
3679 * context of the top-most JavaScript frame. If there are no 3679 * context of the top-most JavaScript frame. If there are no
3680 * JavaScript frames an empty handle is returned. 3680 * JavaScript frames an empty handle is returned.
3681 */ 3681 */
3682 static Local<Context> GetCalling(); 3682 static Local<Context> GetCalling();
3683 3683
3684 /** 3684 /**
3685 * Sets the security token for the context. To access an object in 3685 * Sets the security token for the context. To access an object in
3686 * another context, the security tokens must match. 3686 * another context, the security tokens must match.
3687 */ 3687 */
3688 void SetSecurityToken(Handle<Value> token); 3688 void SetSecurityToken(Handle<Value> token);
3689 3689
3690 /** Restores the security token to the default value. */ 3690 /** Restores the security token to the default value. */
3691 void UseDefaultSecurityToken(); 3691 void UseDefaultSecurityToken();
3692 3692
3693 /** Returns the security token of this context.*/ 3693 /** Returns the security token of this context.*/
3694 Handle<Value> GetSecurityToken(); 3694 Handle<Value> GetSecurityToken();
3695 3695
3696 /** 3696 /**
3697 * Enter this context. After entering a context, all code compiled 3697 * Enter this context. After entering a context, all code compiled
3698 * and run is compiled and run in this context. If another context 3698 * and run is compiled and run in this context. If another context
3699 * is already entered, this old context is saved so it can be 3699 * is already entered, this old context is saved so it can be
3700 * restored when the new context is exited. 3700 * restored when the new context is exited.
3701 */ 3701 */
3702 void Enter(); 3702 void Enter();
3703 3703
3704 /** 3704 /**
3705 * Exit this context. Exiting the current context restores the 3705 * Exit this context. Exiting the current context restores the
3706 * context that was in place when entering the current context. 3706 * context that was in place when entering the current context.
3707 */ 3707 */
3708 void Exit(); 3708 void Exit();
3709 3709
3710 /** Returns true if the context has experienced an out of memory situation. */ 3710 /** Returns true if the context has experienced an out of memory situation. */
3711 bool HasOutOfMemoryException(); 3711 bool HasOutOfMemoryException();
3712 3712
3713 /** Returns true if V8 has a current context. */ 3713 /** Returns true if V8 has a current context. */
3714 static bool InContext(); 3714 static bool InContext();
3715 3715
3716 /** 3716 /**
3717 * Associate an additional data object with the context. This is mainly used 3717 * Associate an additional data object with the context. This is mainly used
3718 * with the debugger to provide additional information on the context through 3718 * with the debugger to provide additional information on the context through
3719 * the debugger API. 3719 * the debugger API.
3720 */ 3720 */
3721 void SetData(Handle<Value> data); 3721 void SetData(Handle<Value> data);
3722 Local<Value> GetData(); 3722 Local<Value> GetData();
3723 3723
3724 /** 3724 /**
3725 * Control whether code generation from strings is allowed. Calling 3725 * Control whether code generation from strings is allowed. Calling
3726 * this method with false will disable 'eval' and the 'Function' 3726 * this method with false will disable 'eval' and the 'Function'
3727 * constructor for code running in this context. If 'eval' or the 3727 * constructor for code running in this context. If 'eval' or the
3728 * 'Function' constructor are used an exception will be thrown. 3728 * 'Function' constructor are used an exception will be thrown.
3729 * 3729 *
3730 * If code generation from strings is not allowed the 3730 * If code generation from strings is not allowed the
3731 * V8::AllowCodeGenerationFromStrings callback will be invoked if 3731 * V8::AllowCodeGenerationFromStrings callback will be invoked if
3732 * set before blocking the call to 'eval' or the 'Function' 3732 * set before blocking the call to 'eval' or the 'Function'
3733 * constructor. If that callback returns true, the call will be 3733 * constructor. If that callback returns true, the call will be
3734 * allowed, otherwise an exception will be thrown. If no callback is 3734 * allowed, otherwise an exception will be thrown. If no callback is
3735 * set an exception will be thrown. 3735 * set an exception will be thrown.
3736 */ 3736 */
3737 void AllowCodeGenerationFromStrings(bool allow); 3737 void AllowCodeGenerationFromStrings(bool allow);
3738 3738
3739 /** 3739 /**
3740 * Returns true if code generation from strings is allowed for the context. 3740 * Returns true if code generation from strings is allowed for the context.
3741 * For more details see AllowCodeGenerationFromStrings(bool) documentation. 3741 * For more details see AllowCodeGenerationFromStrings(bool) documentation.
3742 */ 3742 */
3743 bool IsCodeGenerationFromStringsAllowed(); 3743 bool IsCodeGenerationFromStringsAllowed();
3744 3744
3745 /** 3745 /**
3746 * Sets the error description for the exception that is thrown when 3746 * Sets the error description for the exception that is thrown when
3747 * code generation from strings is not allowed and 'eval' or the 'Function' 3747 * code generation from strings is not allowed and 'eval' or the 'Function'
3748 * constructor are called. 3748 * constructor are called.
3749 */ 3749 */
3750 void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); 3750 void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message);
3751 3751
3752 /** 3752 /**
3753 * Stack-allocated class which sets the execution context for all 3753 * Stack-allocated class which sets the execution context for all
3754 * operations executed within a local scope. 3754 * operations executed within a local scope.
3755 */ 3755 */
3756 class Scope { 3756 class Scope {
3757 public: 3757 public:
3758 explicit inline Scope(Handle<Context> context) : context_(context) { 3758 explicit inline Scope(Handle<Context> context) : context_(context) {
3759 context_->Enter(); 3759 context_->Enter();
3760 } 3760 }
3761 inline ~Scope() { context_->Exit(); } 3761 inline ~Scope() { context_->Exit(); }
3762 private: 3762 private:
3763 Handle<Context> context_; 3763 Handle<Context> context_;
3764 }; 3764 };
3765 3765
3766 private: 3766 private:
3767 friend class Value; 3767 friend class Value;
3768 friend class Script; 3768 friend class Script;
3769 friend class Object; 3769 friend class Object;
3770 friend class Function; 3770 friend class Function;
3771 }; 3771 };
3772 3772
3773 3773
3774 /** 3774 /**
3775 * Multiple threads in V8 are allowed, but only one thread at a time 3775 * Multiple threads in V8 are allowed, but only one thread at a time
3776 * is allowed to use any given V8 isolate. See Isolate class 3776 * is allowed to use any given V8 isolate. See Isolate class
3777 * comments. The definition of 'using V8 isolate' includes 3777 * comments. The definition of 'using V8 isolate' includes
3778 * accessing handles or holding onto object pointers obtained 3778 * accessing handles or holding onto object pointers obtained
3779 * from V8 handles while in the particular V8 isolate. It is up 3779 * from V8 handles while in the particular V8 isolate. It is up
3780 * to the user of V8 to ensure (perhaps with locking) that this 3780 * to the user of V8 to ensure (perhaps with locking) that this
3781 * constraint is not violated. In addition to any other synchronization 3781 * constraint is not violated. In addition to any other synchronization
3782 * mechanism that may be used, the v8::Locker and v8::Unlocker classes 3782 * mechanism that may be used, the v8::Locker and v8::Unlocker classes
3783 * must be used to signal thead switches to V8. 3783 * must be used to signal thead switches to V8.
3784 * 3784 *
3785 * v8::Locker is a scoped lock object. While it's 3785 * v8::Locker is a scoped lock object. While it's
3786 * active (i.e. between its construction and destruction) the current thread is 3786 * active (i.e. between its construction and destruction) the current thread is
3787 * allowed to use the locked isolate. V8 guarantees that an isolate can be 3787 * allowed to use the locked isolate. V8 guarantees that an isolate can be
3788 * locked by at most one thread at any time. In other words, the scope of a 3788 * locked by at most one thread at any time. In other words, the scope of a
3789 * v8::Locker is a critical section. 3789 * v8::Locker is a critical section.
3790 * 3790 *
3791 * Sample usage: 3791 * Sample usage:
3792 * \code 3792 * \code
3793 * ... 3793 * ...
3794 * { 3794 * {
3795 * v8::Locker locker(isolate); 3795 * v8::Locker locker(isolate);
3796 * v8::Isolate::Scope isolate_scope(isolate); 3796 * v8::Isolate::Scope isolate_scope(isolate);
3797 * ... 3797 * ...
3798 * // Code using V8 and isolate goes here. 3798 * // Code using V8 and isolate goes here.
3799 * ... 3799 * ...
3800 * } // Destructor called here 3800 * } // Destructor called here
3801 * \endcode 3801 * \endcode
3802 * 3802 *
3803 * If you wish to stop using V8 in a thread A you can do this either 3803 * If you wish to stop using V8 in a thread A you can do this either
3804 * by destroying the v8::Locker object as above or by constructing a 3804 * by destroying the v8::Locker object as above or by constructing a
3805 * v8::Unlocker object: 3805 * v8::Unlocker object:
3806 * 3806 *
3807 * \code 3807 * \code
3808 * { 3808 * {
3809 * isolate->Exit(); 3809 * isolate->Exit();
3810 * v8::Unlocker unlocker(isolate); 3810 * v8::Unlocker unlocker(isolate);
3811 * ... 3811 * ...
3812 * // Code not using V8 goes here while V8 can run in another thread. 3812 * // Code not using V8 goes here while V8 can run in another thread.
3813 * ... 3813 * ...
3814 * } // Destructor called here. 3814 * } // Destructor called here.
3815 * isolate->Enter(); 3815 * isolate->Enter();
3816 * \endcode 3816 * \endcode
3817 * 3817 *
3818 * The Unlocker object is intended for use in a long-running callback 3818 * The Unlocker object is intended for use in a long-running callback
3819 * from V8, where you want to release the V8 lock for other threads to 3819 * from V8, where you want to release the V8 lock for other threads to
3820 * use. 3820 * use.
3821 * 3821 *
3822 * The v8::Locker is a recursive lock. That is, you can lock more than 3822 * The v8::Locker is a recursive lock. That is, you can lock more than
3823 * once in a given thread. This can be useful if you have code that can 3823 * once in a given thread. This can be useful if you have code that can
3824 * be called either from code that holds the lock or from code that does 3824 * be called either from code that holds the lock or from code that does
3825 * not. The Unlocker is not recursive so you can not have several 3825 * not. The Unlocker is not recursive so you can not have several
3826 * Unlockers on the stack at once, and you can not use an Unlocker in a 3826 * Unlockers on the stack at once, and you can not use an Unlocker in a
3827 * thread that is not inside a Locker's scope. 3827 * thread that is not inside a Locker's scope.
3828 * 3828 *
3829 * An unlocker will unlock several lockers if it has to and reinstate 3829 * An unlocker will unlock several lockers if it has to and reinstate
3830 * the correct depth of locking on its destruction. eg.: 3830 * the correct depth of locking on its destruction. eg.:
3831 * 3831 *
3832 * \code 3832 * \code
3833 * // V8 not locked. 3833 * // V8 not locked.
3834 * { 3834 * {
3835 * v8::Locker locker(isolate); 3835 * v8::Locker locker(isolate);
3836 * Isolate::Scope isolate_scope(isolate); 3836 * Isolate::Scope isolate_scope(isolate);
3837 * // V8 locked. 3837 * // V8 locked.
3838 * { 3838 * {
3839 * v8::Locker another_locker(isolate); 3839 * v8::Locker another_locker(isolate);
3840 * // V8 still locked (2 levels). 3840 * // V8 still locked (2 levels).
3841 * { 3841 * {
3842 * isolate->Exit(); 3842 * isolate->Exit();
3843 * v8::Unlocker unlocker(isolate); 3843 * v8::Unlocker unlocker(isolate);
3844 * // V8 not locked. 3844 * // V8 not locked.
3845 * } 3845 * }
3846 * isolate->Enter(); 3846 * isolate->Enter();
3847 * // V8 locked again (2 levels). 3847 * // V8 locked again (2 levels).
3848 * } 3848 * }
3849 * // V8 still locked (1 level). 3849 * // V8 still locked (1 level).
3850 * } 3850 * }
3851 * // V8 Now no longer locked. 3851 * // V8 Now no longer locked.
3852 * \endcode 3852 * \endcode
3853 * 3853 *
3854 * 3854 *
3855 */ 3855 */
3856 class V8EXPORT Unlocker { 3856 class V8EXPORT Unlocker {
3857 public: 3857 public:
3858 /** 3858 /**
3859 * Initialize Unlocker for a given Isolate. NULL means default isolate. 3859 * Initialize Unlocker for a given Isolate. NULL means default isolate.
3860 */ 3860 */
3861 explicit Unlocker(Isolate* isolate = NULL); 3861 explicit Unlocker(Isolate* isolate = NULL);
3862 ~Unlocker(); 3862 ~Unlocker();
3863 private: 3863 private:
3864 internal::Isolate* isolate_; 3864 internal::Isolate* isolate_;
3865 }; 3865 };
3866 3866
3867 3867
3868 class V8EXPORT Locker { 3868 class V8EXPORT Locker {
3869 public: 3869 public:
3870 /** 3870 /**
3871 * Initialize Locker for a given Isolate. NULL means default isolate. 3871 * Initialize Locker for a given Isolate. NULL means default isolate.
3872 */ 3872 */
3873 explicit Locker(Isolate* isolate = NULL); 3873 explicit Locker(Isolate* isolate = NULL);
3874 ~Locker(); 3874 ~Locker();
3875 3875
3876 /** 3876 /**
3877 * Start preemption. 3877 * Start preemption.
3878 * 3878 *
3879 * When preemption is started, a timer is fired every n milliseconds 3879 * When preemption is started, a timer is fired every n milliseconds
3880 * that will switch between multiple threads that are in contention 3880 * that will switch between multiple threads that are in contention
3881 * for the V8 lock. 3881 * for the V8 lock.
3882 */ 3882 */
3883 static void StartPreemption(int every_n_ms); 3883 static void StartPreemption(int every_n_ms);
3884 3884
3885 /** 3885 /**
3886 * Stop preemption. 3886 * Stop preemption.
3887 */ 3887 */
3888 static void StopPreemption(); 3888 static void StopPreemption();
3889 3889
3890 /** 3890 /**
3891 * Returns whether or not the locker for a given isolate, or default isolate 3891 * Returns whether or not the locker for a given isolate, or default isolate
3892 * if NULL is given, is locked by the current thread. 3892 * if NULL is given, is locked by the current thread.
3893 */ 3893 */
3894 static bool IsLocked(Isolate* isolate = NULL); 3894 static bool IsLocked(Isolate* isolate = NULL);
3895 3895
3896 /** 3896 /**
3897 * Returns whether v8::Locker is being used by this V8 instance. 3897 * Returns whether v8::Locker is being used by this V8 instance.
3898 */ 3898 */
3899 static bool IsActive(); 3899 static bool IsActive();
3900 3900
3901 private: 3901 private:
3902 bool has_lock_; 3902 bool has_lock_;
3903 bool top_level_; 3903 bool top_level_;
3904 internal::Isolate* isolate_; 3904 internal::Isolate* isolate_;
3905 3905
3906 static bool active_; 3906 static bool active_;
3907 3907
3908 // Disallow copying and assigning. 3908 // Disallow copying and assigning.
3909 Locker(const Locker&); 3909 Locker(const Locker&);
3910 void operator=(const Locker&); 3910 void operator=(const Locker&);
3911 }; 3911 };
3912 3912
3913 3913
3914 /** 3914 /**
3915 * A struct for exporting HeapStats data from V8, using "push" model. 3915 * A struct for exporting HeapStats data from V8, using "push" model.
3916 */ 3916 */
3917 struct HeapStatsUpdate; 3917 struct HeapStatsUpdate;
3918 3918
3919 3919
3920 /** 3920 /**
3921 * An interface for exporting data from V8, using "push" model. 3921 * An interface for exporting data from V8, using "push" model.
3922 */ 3922 */
3923 class V8EXPORT OutputStream { // NOLINT 3923 class V8EXPORT OutputStream { // NOLINT
3924 public: 3924 public:
3925 enum OutputEncoding { 3925 enum OutputEncoding {
3926 kAscii = 0 // 7-bit ASCII. 3926 kAscii = 0 // 7-bit ASCII.
3927 }; 3927 };
3928 enum WriteResult { 3928 enum WriteResult {
3929 kContinue = 0, 3929 kContinue = 0,
3930 kAbort = 1 3930 kAbort = 1
3931 }; 3931 };
3932 virtual ~OutputStream() {} 3932 virtual ~OutputStream() {}
3933 /** Notify about the end of stream. */ 3933 /** Notify about the end of stream. */
3934 virtual void EndOfStream() = 0; 3934 virtual void EndOfStream() = 0;
3935 /** Get preferred output chunk size. Called only once. */ 3935 /** Get preferred output chunk size. Called only once. */
3936 virtual int GetChunkSize() { return 1024; } 3936 virtual int GetChunkSize() { return 1024; }
3937 /** Get preferred output encoding. Called only once. */ 3937 /** Get preferred output encoding. Called only once. */
3938 virtual OutputEncoding GetOutputEncoding() { return kAscii; } 3938 virtual OutputEncoding GetOutputEncoding() { return kAscii; }
3939 /** 3939 /**
3940 * Writes the next chunk of snapshot data into the stream. Writing 3940 * Writes the next chunk of snapshot data into the stream. Writing
3941 * can be stopped by returning kAbort as function result. EndOfStream 3941 * can be stopped by returning kAbort as function result. EndOfStream
3942 * will not be called in case writing was aborted. 3942 * will not be called in case writing was aborted.
3943 */ 3943 */
3944 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; 3944 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
3945 /** 3945 /**
3946 * Writes the next chunk of heap stats data into the stream. Writing 3946 * Writes the next chunk of heap stats data into the stream. Writing
3947 * can be stopped by returning kAbort as function result. EndOfStream 3947 * can be stopped by returning kAbort as function result. EndOfStream
3948 * will not be called in case writing was aborted. 3948 * will not be called in case writing was aborted.
3949 */ 3949 */
3950 virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { 3950 virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
3951 return kAbort; 3951 return kAbort;
3952 }; 3952 };
3953 }; 3953 };
3954 3954
3955 3955
3956 /** 3956 /**
3957 * An interface for reporting progress and controlling long-running 3957 * An interface for reporting progress and controlling long-running
3958 * activities. 3958 * activities.
3959 */ 3959 */
3960 class V8EXPORT ActivityControl { // NOLINT 3960 class V8EXPORT ActivityControl { // NOLINT
3961 public: 3961 public:
3962 enum ControlOption { 3962 enum ControlOption {
3963 kContinue = 0, 3963 kContinue = 0,
3964 kAbort = 1 3964 kAbort = 1
3965 }; 3965 };
3966 virtual ~ActivityControl() {} 3966 virtual ~ActivityControl() {}
3967 /** 3967 /**
3968 * Notify about current progress. The activity can be stopped by 3968 * Notify about current progress. The activity can be stopped by
3969 * returning kAbort as the callback result. 3969 * returning kAbort as the callback result.
3970 */ 3970 */
3971 virtual ControlOption ReportProgressValue(int done, int total) = 0; 3971 virtual ControlOption ReportProgressValue(int done, int total) = 0;
3972 }; 3972 };
3973 3973
3974 3974
3975 // --- Implementation --- 3975 // --- Implementation ---
3976 3976
3977 3977
3978 namespace internal { 3978 namespace internal {
3979 3979
3980 const int kApiPointerSize = sizeof(void*); // NOLINT 3980 const int kApiPointerSize = sizeof(void*); // NOLINT
3981 const int kApiIntSize = sizeof(int); // NOLINT 3981 const int kApiIntSize = sizeof(int); // NOLINT
3982 3982
3983 // Tag information for HeapObject. 3983 // Tag information for HeapObject.
3984 const int kHeapObjectTag = 1; 3984 const int kHeapObjectTag = 1;
3985 const int kHeapObjectTagSize = 2; 3985 const int kHeapObjectTagSize = 2;
3986 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; 3986 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
3987 3987
3988 // Tag information for Smi. 3988 // Tag information for Smi.
3989 const int kSmiTag = 0; 3989 const int kSmiTag = 0;
3990 const int kSmiTagSize = 1; 3990 const int kSmiTagSize = 1;
3991 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; 3991 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
3992 3992
3993 template <size_t ptr_size> struct SmiTagging; 3993 template <size_t ptr_size> struct SmiTagging;
3994 3994
3995 // Smi constants for 32-bit systems. 3995 // Smi constants for 32-bit systems.
3996 template <> struct SmiTagging<4> { 3996 template <> struct SmiTagging<4> {
3997 static const int kSmiShiftSize = 0; 3997 static const int kSmiShiftSize = 0;
3998 static const int kSmiValueSize = 31; 3998 static const int kSmiValueSize = 31;
3999 static inline int SmiToInt(internal::Object* value) { 3999 static inline int SmiToInt(internal::Object* value) {
4000 int shift_bits = kSmiTagSize + kSmiShiftSize; 4000 int shift_bits = kSmiTagSize + kSmiShiftSize;
4001 // Throw away top 32 bits and shift down (requires >> to be sign extending). 4001 // Throw away top 32 bits and shift down (requires >> to be sign extending).
4002 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; 4002 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
4003 } 4003 }
4004 4004
4005 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi 4005 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi
4006 // with a plain reinterpret_cast. 4006 // with a plain reinterpret_cast.
4007 static const uintptr_t kEncodablePointerMask = 0x1; 4007 static const uintptr_t kEncodablePointerMask = 0x1;
4008 static const int kPointerToSmiShift = 0; 4008 static const int kPointerToSmiShift = 0;
4009 }; 4009 };
4010 4010
4011 // Smi constants for 64-bit systems. 4011 // Smi constants for 64-bit systems.
4012 template <> struct SmiTagging<8> { 4012 template <> struct SmiTagging<8> {
4013 static const int kSmiShiftSize = 31; 4013 static const int kSmiShiftSize = 31;
4014 static const int kSmiValueSize = 32; 4014 static const int kSmiValueSize = 32;
4015 static inline int SmiToInt(internal::Object* value) { 4015 static inline int SmiToInt(internal::Object* value) {
4016 int shift_bits = kSmiTagSize + kSmiShiftSize; 4016 int shift_bits = kSmiTagSize + kSmiShiftSize;
4017 // Shift down and throw away top 32 bits. 4017 // Shift down and throw away top 32 bits.
4018 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); 4018 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
4019 } 4019 }
4020 4020
4021 // To maximize the range of pointers that can be encoded 4021 // To maximize the range of pointers that can be encoded
4022 // in the available 32 bits, we require them to be 8 bytes aligned. 4022 // in the available 32 bits, we require them to be 8 bytes aligned.
4023 // This gives 2 ^ (32 + 3) = 32G address space covered. 4023 // This gives 2 ^ (32 + 3) = 32G address space covered.
4024 // It might be not enough to cover stack allocated objects on some platforms. 4024 // It might be not enough to cover stack allocated objects on some platforms.
4025 static const int kPointerAlignment = 3; 4025 static const int kPointerAlignment = 3;
4026 4026
4027 static const uintptr_t kEncodablePointerMask = 4027 static const uintptr_t kEncodablePointerMask =
4028 ~(uintptr_t(0xffffffff) << kPointerAlignment); 4028 ~(uintptr_t(0xffffffff) << kPointerAlignment);
4029 4029
4030 static const int kPointerToSmiShift = 4030 static const int kPointerToSmiShift =
4031 kSmiTagSize + kSmiShiftSize - kPointerAlignment; 4031 kSmiTagSize + kSmiShiftSize - kPointerAlignment;
4032 }; 4032 };
4033 4033
4034 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; 4034 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
4035 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; 4035 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
4036 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; 4036 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
4037 const uintptr_t kEncodablePointerMask = 4037 const uintptr_t kEncodablePointerMask =
4038 PlatformSmiTagging::kEncodablePointerMask; 4038 PlatformSmiTagging::kEncodablePointerMask;
4039 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; 4039 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;
4040 4040
4041 /** 4041 /**
4042 * This class exports constants and functionality from within v8 that 4042 * This class exports constants and functionality from within v8 that
4043 * is necessary to implement inline functions in the v8 api. Don't 4043 * is necessary to implement inline functions in the v8 api. Don't
4044 * depend on functions and constants defined here. 4044 * depend on functions and constants defined here.
4045 */ 4045 */
4046 class Internals { 4046 class Internals {
4047 public: 4047 public:
4048 // These values match non-compiler-dependent values defined within 4048 // These values match non-compiler-dependent values defined within
4049 // the implementation of v8. 4049 // the implementation of v8.
4050 static const int kHeapObjectMapOffset = 0; 4050 static const int kHeapObjectMapOffset = 0;
4051 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; 4051 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
4052 static const int kStringResourceOffset = 3 * kApiPointerSize; 4052 static const int kStringResourceOffset = 3 * kApiPointerSize;
4053 4053
4054 static const int kOddballKindOffset = 3 * kApiPointerSize; 4054 static const int kOddballKindOffset = 3 * kApiPointerSize;
4055 static const int kForeignAddressOffset = kApiPointerSize; 4055 static const int kForeignAddressOffset = kApiPointerSize;
4056 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 4056 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
4057 static const int kFullStringRepresentationMask = 0x07; 4057 static const int kFullStringRepresentationMask = 0x07;
4058 static const int kStringEncodingMask = 0x4; 4058 static const int kStringEncodingMask = 0x4;
4059 static const int kExternalTwoByteRepresentationTag = 0x02; 4059 static const int kExternalTwoByteRepresentationTag = 0x02;
4060 static const int kExternalAsciiRepresentationTag = 0x06; 4060 static const int kExternalAsciiRepresentationTag = 0x06;
4061 4061
4062 static const int kIsolateStateOffset = 0; 4062 static const int kIsolateStateOffset = 0;
4063 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; 4063 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
4064 static const int kIsolateRootsOffset = 3 * kApiPointerSize; 4064 static const int kIsolateRootsOffset = 3 * kApiPointerSize;
4065 static const int kUndefinedValueRootIndex = 5; 4065 static const int kUndefinedValueRootIndex = 5;
4066 static const int kNullValueRootIndex = 7; 4066 static const int kNullValueRootIndex = 7;
4067 static const int kTrueValueRootIndex = 8; 4067 static const int kTrueValueRootIndex = 8;
4068 static const int kFalseValueRootIndex = 9; 4068 static const int kFalseValueRootIndex = 9;
4069 static const int kEmptySymbolRootIndex = 116; 4069 static const int kEmptySymbolRootIndex = 117;
4070 4070
4071 static const int kJSObjectType = 0xaa; 4071 static const int kJSObjectType = 0xaa;
4072 static const int kFirstNonstringType = 0x80; 4072 static const int kFirstNonstringType = 0x80;
4073 static const int kOddballType = 0x82; 4073 static const int kOddballType = 0x82;
4074 static const int kForeignType = 0x85; 4074 static const int kForeignType = 0x85;
4075 4075
4076 static const int kUndefinedOddballKind = 5; 4076 static const int kUndefinedOddballKind = 5;
4077 static const int kNullOddballKind = 3; 4077 static const int kNullOddballKind = 3;
4078 4078
4079 static inline bool HasHeapObjectTag(internal::Object* value) { 4079 static inline bool HasHeapObjectTag(internal::Object* value) {
4080 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == 4080 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
4081 kHeapObjectTag); 4081 kHeapObjectTag);
4082 } 4082 }
4083 4083
4084 static inline bool HasSmiTag(internal::Object* value) { 4084 static inline bool HasSmiTag(internal::Object* value) {
4085 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); 4085 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
4086 } 4086 }
4087 4087
4088 static inline int SmiValue(internal::Object* value) { 4088 static inline int SmiValue(internal::Object* value) {
4089 return PlatformSmiTagging::SmiToInt(value); 4089 return PlatformSmiTagging::SmiToInt(value);
4090 } 4090 }
4091 4091
4092 static inline int GetInstanceType(internal::Object* obj) { 4092 static inline int GetInstanceType(internal::Object* obj) {
4093 typedef internal::Object O; 4093 typedef internal::Object O;
4094 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); 4094 O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
4095 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); 4095 return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
4096 } 4096 }
4097 4097
4098 static inline int GetOddballKind(internal::Object* obj) { 4098 static inline int GetOddballKind(internal::Object* obj) {
4099 typedef internal::Object O; 4099 typedef internal::Object O;
4100 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); 4100 return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
4101 } 4101 }
4102 4102
4103 static inline void* GetExternalPointerFromSmi(internal::Object* value) { 4103 static inline void* GetExternalPointerFromSmi(internal::Object* value) {
4104 const uintptr_t address = reinterpret_cast<uintptr_t>(value); 4104 const uintptr_t address = reinterpret_cast<uintptr_t>(value);
4105 return reinterpret_cast<void*>(address >> kPointerToSmiShift); 4105 return reinterpret_cast<void*>(address >> kPointerToSmiShift);
4106 } 4106 }
4107 4107
4108 static inline void* GetExternalPointer(internal::Object* obj) { 4108 static inline void* GetExternalPointer(internal::Object* obj) {
4109 if (HasSmiTag(obj)) { 4109 if (HasSmiTag(obj)) {
4110 return GetExternalPointerFromSmi(obj); 4110 return GetExternalPointerFromSmi(obj);
4111 } else if (GetInstanceType(obj) == kForeignType) { 4111 } else if (GetInstanceType(obj) == kForeignType) {
4112 return ReadField<void*>(obj, kForeignAddressOffset); 4112 return ReadField<void*>(obj, kForeignAddressOffset);
4113 } else { 4113 } else {
4114 return NULL; 4114 return NULL;
4115 } 4115 }
4116 } 4116 }
4117 4117
4118 static inline bool IsExternalTwoByteString(int instance_type) { 4118 static inline bool IsExternalTwoByteString(int instance_type) {
4119 int representation = (instance_type & kFullStringRepresentationMask); 4119 int representation = (instance_type & kFullStringRepresentationMask);
4120 return representation == kExternalTwoByteRepresentationTag; 4120 return representation == kExternalTwoByteRepresentationTag;
4121 } 4121 }
4122 4122
4123 static inline bool IsInitialized(v8::Isolate* isolate) { 4123 static inline bool IsInitialized(v8::Isolate* isolate) {
4124 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; 4124 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
4125 return *reinterpret_cast<int*>(addr) == 1; 4125 return *reinterpret_cast<int*>(addr) == 1;
4126 } 4126 }
4127 4127
4128 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { 4128 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) {
4129 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 4129 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4130 kIsolateEmbedderDataOffset; 4130 kIsolateEmbedderDataOffset;
4131 *reinterpret_cast<void**>(addr) = data; 4131 *reinterpret_cast<void**>(addr) = data;
4132 } 4132 }
4133 4133
4134 static inline void* GetEmbedderData(v8::Isolate* isolate) { 4134 static inline void* GetEmbedderData(v8::Isolate* isolate) {
4135 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 4135 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4136 kIsolateEmbedderDataOffset; 4136 kIsolateEmbedderDataOffset;
4137 return *reinterpret_cast<void**>(addr); 4137 return *reinterpret_cast<void**>(addr);
4138 } 4138 }
4139 4139
4140 static inline internal::Object** GetRoot(v8::Isolate* isolate, int index) { 4140 static inline internal::Object** GetRoot(v8::Isolate* isolate, int index) {
4141 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; 4141 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
4142 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); 4142 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
4143 } 4143 }
4144 4144
4145 template <typename T> 4145 template <typename T>
4146 static inline T ReadField(Object* ptr, int offset) { 4146 static inline T ReadField(Object* ptr, int offset) {
4147 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; 4147 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
4148 return *reinterpret_cast<T*>(addr); 4148 return *reinterpret_cast<T*>(addr);
4149 } 4149 }
4150 4150
4151 static inline bool CanCastToHeapObject(void* o) { return false; } 4151 static inline bool CanCastToHeapObject(void* o) { return false; }
4152 static inline bool CanCastToHeapObject(Context* o) { return true; } 4152 static inline bool CanCastToHeapObject(Context* o) { return true; }
4153 static inline bool CanCastToHeapObject(String* o) { return true; } 4153 static inline bool CanCastToHeapObject(String* o) { return true; }
4154 static inline bool CanCastToHeapObject(Object* o) { return true; } 4154 static inline bool CanCastToHeapObject(Object* o) { return true; }
4155 static inline bool CanCastToHeapObject(Message* o) { return true; } 4155 static inline bool CanCastToHeapObject(Message* o) { return true; }
4156 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } 4156 static inline bool CanCastToHeapObject(StackTrace* o) { return true; }
4157 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } 4157 static inline bool CanCastToHeapObject(StackFrame* o) { return true; }
4158 }; 4158 };
4159 4159
4160 } // namespace internal 4160 } // namespace internal
4161 4161
4162 4162
4163 template <class T> 4163 template <class T>
4164 Local<T>::Local() : Handle<T>() { } 4164 Local<T>::Local() : Handle<T>() { }
4165 4165
4166 4166
4167 template <class T> 4167 template <class T>
4168 Local<T> Local<T>::New(Handle<T> that) { 4168 Local<T> Local<T>::New(Handle<T> that) {
4169 if (that.IsEmpty()) return Local<T>(); 4169 if (that.IsEmpty()) return Local<T>();
4170 T* that_ptr = *that; 4170 T* that_ptr = *that;
4171 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); 4171 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
4172 if (internal::Internals::CanCastToHeapObject(that_ptr)) { 4172 if (internal::Internals::CanCastToHeapObject(that_ptr)) {
4173 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( 4173 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
4174 reinterpret_cast<internal::HeapObject*>(*p)))); 4174 reinterpret_cast<internal::HeapObject*>(*p))));
4175 } 4175 }
4176 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); 4176 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
4177 } 4177 }
4178 4178
4179 4179
4180 template <class T> 4180 template <class T>
4181 Persistent<T> Persistent<T>::New(Handle<T> that) { 4181 Persistent<T> Persistent<T>::New(Handle<T> that) {
4182 if (that.IsEmpty()) return Persistent<T>(); 4182 if (that.IsEmpty()) return Persistent<T>();
4183 internal::Object** p = reinterpret_cast<internal::Object**>(*that); 4183 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
4184 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); 4184 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
4185 } 4185 }
4186 4186
4187 4187
4188 template <class T> 4188 template <class T>
4189 bool Persistent<T>::IsNearDeath() const { 4189 bool Persistent<T>::IsNearDeath() const {
4190 if (this->IsEmpty()) return false; 4190 if (this->IsEmpty()) return false;
4191 return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this)); 4191 return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
4192 } 4192 }
4193 4193
4194 4194
4195 template <class T> 4195 template <class T>
4196 bool Persistent<T>::IsWeak() const { 4196 bool Persistent<T>::IsWeak() const {
4197 if (this->IsEmpty()) return false; 4197 if (this->IsEmpty()) return false;
4198 return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this)); 4198 return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
4199 } 4199 }
4200 4200
4201 4201
4202 template <class T> 4202 template <class T>
4203 void Persistent<T>::Dispose() { 4203 void Persistent<T>::Dispose() {
4204 if (this->IsEmpty()) return; 4204 if (this->IsEmpty()) return;
4205 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this)); 4205 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
4206 } 4206 }
4207 4207
4208 4208
4209 template <class T> 4209 template <class T>
4210 Persistent<T>::Persistent() : Handle<T>() { } 4210 Persistent<T>::Persistent() : Handle<T>() { }
4211 4211
4212 template <class T> 4212 template <class T>
4213 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { 4213 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
4214 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), 4214 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
4215 parameters, 4215 parameters,
4216 callback); 4216 callback);
4217 } 4217 }
4218 4218
4219 template <class T> 4219 template <class T>
4220 void Persistent<T>::ClearWeak() { 4220 void Persistent<T>::ClearWeak() {
4221 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); 4221 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
4222 } 4222 }
4223 4223
4224 template <class T> 4224 template <class T>
4225 void Persistent<T>::MarkIndependent() { 4225 void Persistent<T>::MarkIndependent() {
4226 V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this)); 4226 V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this));
4227 } 4227 }
4228 4228
4229 template <class T> 4229 template <class T>
4230 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { 4230 void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
4231 V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id); 4231 V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id);
4232 } 4232 }
4233 4233
4234 Arguments::Arguments(internal::Object** implicit_args, 4234 Arguments::Arguments(internal::Object** implicit_args,
4235 internal::Object** values, int length, 4235 internal::Object** values, int length,
4236 bool is_construct_call) 4236 bool is_construct_call)
4237 : implicit_args_(implicit_args), 4237 : implicit_args_(implicit_args),
4238 values_(values), 4238 values_(values),
4239 length_(length), 4239 length_(length),
4240 is_construct_call_(is_construct_call) { } 4240 is_construct_call_(is_construct_call) { }
4241 4241
4242 4242
4243 Local<Value> Arguments::operator[](int i) const { 4243 Local<Value> Arguments::operator[](int i) const {
4244 if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); 4244 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
4245 return Local<Value>(reinterpret_cast<Value*>(values_ - i)); 4245 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
4246 } 4246 }
4247 4247
4248 4248
4249 Local<Function> Arguments::Callee() const { 4249 Local<Function> Arguments::Callee() const {
4250 return Local<Function>(reinterpret_cast<Function*>( 4250 return Local<Function>(reinterpret_cast<Function*>(
4251 &implicit_args_[kCalleeIndex])); 4251 &implicit_args_[kCalleeIndex]));
4252 } 4252 }
4253 4253
4254 4254
4255 Local<Object> Arguments::This() const { 4255 Local<Object> Arguments::This() const {
4256 return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); 4256 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
4257 } 4257 }
4258 4258
4259 4259
4260 Local<Object> Arguments::Holder() const { 4260 Local<Object> Arguments::Holder() const {
4261 return Local<Object>(reinterpret_cast<Object*>( 4261 return Local<Object>(reinterpret_cast<Object*>(
4262 &implicit_args_[kHolderIndex])); 4262 &implicit_args_[kHolderIndex]));
4263 } 4263 }
4264 4264
4265 4265
4266 Local<Value> Arguments::Data() const { 4266 Local<Value> Arguments::Data() const {
4267 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); 4267 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
4268 } 4268 }
4269 4269
4270 4270
4271 Isolate* Arguments::GetIsolate() const { 4271 Isolate* Arguments::GetIsolate() const {
4272 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); 4272 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
4273 } 4273 }
4274 4274
4275 4275
4276 bool Arguments::IsConstructCall() const { 4276 bool Arguments::IsConstructCall() const {
4277 return is_construct_call_; 4277 return is_construct_call_;
4278 } 4278 }
4279 4279
4280 4280
4281 int Arguments::Length() const { 4281 int Arguments::Length() const {
4282 return length_; 4282 return length_;
4283 } 4283 }
4284 4284
4285 4285
4286 template <class T> 4286 template <class T>
4287 Local<T> HandleScope::Close(Handle<T> value) { 4287 Local<T> HandleScope::Close(Handle<T> value) {
4288 internal::Object** before = reinterpret_cast<internal::Object**>(*value); 4288 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
4289 internal::Object** after = RawClose(before); 4289 internal::Object** after = RawClose(before);
4290 return Local<T>(reinterpret_cast<T*>(after)); 4290 return Local<T>(reinterpret_cast<T*>(after));
4291 } 4291 }
4292 4292
4293 Handle<Value> ScriptOrigin::ResourceName() const { 4293 Handle<Value> ScriptOrigin::ResourceName() const {
4294 return resource_name_; 4294 return resource_name_;
4295 } 4295 }
4296 4296
4297 4297
4298 Handle<Integer> ScriptOrigin::ResourceLineOffset() const { 4298 Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
4299 return resource_line_offset_; 4299 return resource_line_offset_;
4300 } 4300 }
4301 4301
4302 4302
4303 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { 4303 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
4304 return resource_column_offset_; 4304 return resource_column_offset_;
4305 } 4305 }
4306 4306
4307 4307
4308 Handle<Boolean> Boolean::New(bool value) { 4308 Handle<Boolean> Boolean::New(bool value) {
4309 return value ? True() : False(); 4309 return value ? True() : False();
4310 } 4310 }
4311 4311
4312 4312
4313 void Template::Set(const char* name, v8::Handle<Data> value) { 4313 void Template::Set(const char* name, v8::Handle<Data> value) {
4314 Set(v8::String::New(name), value); 4314 Set(v8::String::New(name), value);
4315 } 4315 }
4316 4316
4317 4317
4318 Local<Value> Object::GetInternalField(int index) { 4318 Local<Value> Object::GetInternalField(int index) {
4319 #ifndef V8_ENABLE_CHECKS 4319 #ifndef V8_ENABLE_CHECKS
4320 Local<Value> quick_result = UncheckedGetInternalField(index); 4320 Local<Value> quick_result = UncheckedGetInternalField(index);
4321 if (!quick_result.IsEmpty()) return quick_result; 4321 if (!quick_result.IsEmpty()) return quick_result;
4322 #endif 4322 #endif
4323 return CheckedGetInternalField(index); 4323 return CheckedGetInternalField(index);
4324 } 4324 }
4325 4325
4326 4326
4327 Local<Value> Object::UncheckedGetInternalField(int index) { 4327 Local<Value> Object::UncheckedGetInternalField(int index) {
4328 typedef internal::Object O; 4328 typedef internal::Object O;
4329 typedef internal::Internals I; 4329 typedef internal::Internals I;
4330 O* obj = *reinterpret_cast<O**>(this); 4330 O* obj = *reinterpret_cast<O**>(this);
4331 if (I::GetInstanceType(obj) == I::kJSObjectType) { 4331 if (I::GetInstanceType(obj) == I::kJSObjectType) {
4332 // If the object is a plain JSObject, which is the common case, 4332 // If the object is a plain JSObject, which is the common case,
4333 // we know where to find the internal fields and can return the 4333 // we know where to find the internal fields and can return the
4334 // value directly. 4334 // value directly.
4335 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); 4335 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
4336 O* value = I::ReadField<O*>(obj, offset); 4336 O* value = I::ReadField<O*>(obj, offset);
4337 O** result = HandleScope::CreateHandle(value); 4337 O** result = HandleScope::CreateHandle(value);
4338 return Local<Value>(reinterpret_cast<Value*>(result)); 4338 return Local<Value>(reinterpret_cast<Value*>(result));
4339 } else { 4339 } else {
4340 return Local<Value>(); 4340 return Local<Value>();
4341 } 4341 }
4342 } 4342 }
4343 4343
4344 4344
4345 void* External::Unwrap(Handle<v8::Value> obj) { 4345 void* External::Unwrap(Handle<v8::Value> obj) {
4346 #ifdef V8_ENABLE_CHECKS 4346 #ifdef V8_ENABLE_CHECKS
4347 return FullUnwrap(obj); 4347 return FullUnwrap(obj);
4348 #else 4348 #else
4349 return QuickUnwrap(obj); 4349 return QuickUnwrap(obj);
4350 #endif 4350 #endif
4351 } 4351 }
4352 4352
4353 4353
4354 void* External::QuickUnwrap(Handle<v8::Value> wrapper) { 4354 void* External::QuickUnwrap(Handle<v8::Value> wrapper) {
4355 typedef internal::Object O; 4355 typedef internal::Object O;
4356 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); 4356 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
4357 return internal::Internals::GetExternalPointer(obj); 4357 return internal::Internals::GetExternalPointer(obj);
4358 } 4358 }
4359 4359
4360 4360
4361 void* Object::GetPointerFromInternalField(int index) { 4361 void* Object::GetPointerFromInternalField(int index) {
4362 typedef internal::Object O; 4362 typedef internal::Object O;
4363 typedef internal::Internals I; 4363 typedef internal::Internals I;
4364 4364
4365 O* obj = *reinterpret_cast<O**>(this); 4365 O* obj = *reinterpret_cast<O**>(this);
4366 4366
4367 if (I::GetInstanceType(obj) == I::kJSObjectType) { 4367 if (I::GetInstanceType(obj) == I::kJSObjectType) {
4368 // If the object is a plain JSObject, which is the common case, 4368 // If the object is a plain JSObject, which is the common case,
4369 // we know where to find the internal fields and can return the 4369 // we know where to find the internal fields and can return the
4370 // value directly. 4370 // value directly.
4371 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); 4371 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
4372 O* value = I::ReadField<O*>(obj, offset); 4372 O* value = I::ReadField<O*>(obj, offset);
4373 return I::GetExternalPointer(value); 4373 return I::GetExternalPointer(value);
4374 } 4374 }
4375 4375
4376 return SlowGetPointerFromInternalField(index); 4376 return SlowGetPointerFromInternalField(index);
4377 } 4377 }
4378 4378
4379 4379
4380 String* String::Cast(v8::Value* value) { 4380 String* String::Cast(v8::Value* value) {
4381 #ifdef V8_ENABLE_CHECKS 4381 #ifdef V8_ENABLE_CHECKS
4382 CheckCast(value); 4382 CheckCast(value);
4383 #endif 4383 #endif
4384 return static_cast<String*>(value); 4384 return static_cast<String*>(value);
4385 } 4385 }
4386 4386
4387 4387
4388 Local<String> String::Empty(Isolate* isolate) { 4388 Local<String> String::Empty(Isolate* isolate) {
4389 typedef internal::Object* S; 4389 typedef internal::Object* S;
4390 typedef internal::Internals I; 4390 typedef internal::Internals I;
4391 if (!I::IsInitialized(isolate)) return Empty(); 4391 if (!I::IsInitialized(isolate)) return Empty();
4392 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex); 4392 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex);
4393 return Local<String>(reinterpret_cast<String*>(slot)); 4393 return Local<String>(reinterpret_cast<String*>(slot));
4394 } 4394 }
4395 4395
4396 4396
4397 String::ExternalStringResource* String::GetExternalStringResource() const { 4397 String::ExternalStringResource* String::GetExternalStringResource() const {
4398 typedef internal::Object O; 4398 typedef internal::Object O;
4399 typedef internal::Internals I; 4399 typedef internal::Internals I;
4400 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); 4400 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4401 String::ExternalStringResource* result; 4401 String::ExternalStringResource* result;
4402 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { 4402 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
4403 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); 4403 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4404 result = reinterpret_cast<String::ExternalStringResource*>(value); 4404 result = reinterpret_cast<String::ExternalStringResource*>(value);
4405 } else { 4405 } else {
4406 result = NULL; 4406 result = NULL;
4407 } 4407 }
4408 #ifdef V8_ENABLE_CHECKS 4408 #ifdef V8_ENABLE_CHECKS
4409 VerifyExternalStringResource(result); 4409 VerifyExternalStringResource(result);
4410 #endif 4410 #endif
4411 return result; 4411 return result;
4412 } 4412 }
4413 4413
4414 4414
4415 String::ExternalStringResourceBase* String::GetExternalStringResourceBase( 4415 String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
4416 String::Encoding* encoding_out) const { 4416 String::Encoding* encoding_out) const {
4417 typedef internal::Object O; 4417 typedef internal::Object O;
4418 typedef internal::Internals I; 4418 typedef internal::Internals I;
4419 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); 4419 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4420 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; 4420 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
4421 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); 4421 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
4422 ExternalStringResourceBase* resource = NULL; 4422 ExternalStringResourceBase* resource = NULL;
4423 if (type == I::kExternalAsciiRepresentationTag || 4423 if (type == I::kExternalAsciiRepresentationTag ||
4424 type == I::kExternalTwoByteRepresentationTag) { 4424 type == I::kExternalTwoByteRepresentationTag) {
4425 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); 4425 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4426 resource = static_cast<ExternalStringResourceBase*>(value); 4426 resource = static_cast<ExternalStringResourceBase*>(value);
4427 } 4427 }
4428 #ifdef V8_ENABLE_CHECKS 4428 #ifdef V8_ENABLE_CHECKS
4429 VerifyExternalStringResourceBase(resource, *encoding_out); 4429 VerifyExternalStringResourceBase(resource, *encoding_out);
4430 #endif 4430 #endif
4431 return resource; 4431 return resource;
4432 } 4432 }
4433 4433
4434 4434
4435 bool Value::IsUndefined() const { 4435 bool Value::IsUndefined() const {
4436 #ifdef V8_ENABLE_CHECKS 4436 #ifdef V8_ENABLE_CHECKS
4437 return FullIsUndefined(); 4437 return FullIsUndefined();
4438 #else 4438 #else
4439 return QuickIsUndefined(); 4439 return QuickIsUndefined();
4440 #endif 4440 #endif
4441 } 4441 }
4442 4442
4443 bool Value::QuickIsUndefined() const { 4443 bool Value::QuickIsUndefined() const {
4444 typedef internal::Object O; 4444 typedef internal::Object O;
4445 typedef internal::Internals I; 4445 typedef internal::Internals I;
4446 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); 4446 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4447 if (!I::HasHeapObjectTag(obj)) return false; 4447 if (!I::HasHeapObjectTag(obj)) return false;
4448 if (I::GetInstanceType(obj) != I::kOddballType) return false; 4448 if (I::GetInstanceType(obj) != I::kOddballType) return false;
4449 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); 4449 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
4450 } 4450 }
4451 4451
4452 4452
4453 bool Value::IsNull() const { 4453 bool Value::IsNull() const {
4454 #ifdef V8_ENABLE_CHECKS 4454 #ifdef V8_ENABLE_CHECKS
4455 return FullIsNull(); 4455 return FullIsNull();
4456 #else 4456 #else
4457 return QuickIsNull(); 4457 return QuickIsNull();
4458 #endif 4458 #endif
4459 } 4459 }
4460 4460
4461 bool Value::QuickIsNull() const { 4461 bool Value::QuickIsNull() const {
4462 typedef internal::Object O; 4462 typedef internal::Object O;
4463 typedef internal::Internals I; 4463 typedef internal::Internals I;
4464 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); 4464 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4465 if (!I::HasHeapObjectTag(obj)) return false; 4465 if (!I::HasHeapObjectTag(obj)) return false;
4466 if (I::GetInstanceType(obj) != I::kOddballType) return false; 4466 if (I::GetInstanceType(obj) != I::kOddballType) return false;
4467 return (I::GetOddballKind(obj) == I::kNullOddballKind); 4467 return (I::GetOddballKind(obj) == I::kNullOddballKind);
4468 } 4468 }
4469 4469
4470 4470
4471 bool Value::IsString() const { 4471 bool Value::IsString() const {
4472 #ifdef V8_ENABLE_CHECKS 4472 #ifdef V8_ENABLE_CHECKS
4473 return FullIsString(); 4473 return FullIsString();
4474 #else 4474 #else
4475 return QuickIsString(); 4475 return QuickIsString();
4476 #endif 4476 #endif
4477 } 4477 }
4478 4478
4479 bool Value::QuickIsString() const { 4479 bool Value::QuickIsString() const {
4480 typedef internal::Object O; 4480 typedef internal::Object O;
4481 typedef internal::Internals I; 4481 typedef internal::Internals I;
4482 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); 4482 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4483 if (!I::HasHeapObjectTag(obj)) return false; 4483 if (!I::HasHeapObjectTag(obj)) return false;
4484 return (I::GetInstanceType(obj) < I::kFirstNonstringType); 4484 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
4485 } 4485 }
4486 4486
4487 4487
4488 Number* Number::Cast(v8::Value* value) { 4488 Number* Number::Cast(v8::Value* value) {
4489 #ifdef V8_ENABLE_CHECKS 4489 #ifdef V8_ENABLE_CHECKS
4490 CheckCast(value); 4490 CheckCast(value);
4491 #endif 4491 #endif
4492 return static_cast<Number*>(value); 4492 return static_cast<Number*>(value);
4493 } 4493 }
4494 4494
4495 4495
4496 Integer* Integer::Cast(v8::Value* value) { 4496 Integer* Integer::Cast(v8::Value* value) {
4497 #ifdef V8_ENABLE_CHECKS 4497 #ifdef V8_ENABLE_CHECKS
4498 CheckCast(value); 4498 CheckCast(value);
4499 #endif 4499 #endif
4500 return static_cast<Integer*>(value); 4500 return static_cast<Integer*>(value);
4501 } 4501 }
4502 4502
4503 4503
4504 Date* Date::Cast(v8::Value* value) { 4504 Date* Date::Cast(v8::Value* value) {
4505 #ifdef V8_ENABLE_CHECKS 4505 #ifdef V8_ENABLE_CHECKS
4506 CheckCast(value); 4506 CheckCast(value);
4507 #endif 4507 #endif
4508 return static_cast<Date*>(value); 4508 return static_cast<Date*>(value);
4509 } 4509 }
4510 4510
4511 4511
4512 StringObject* StringObject::Cast(v8::Value* value) { 4512 StringObject* StringObject::Cast(v8::Value* value) {
4513 #ifdef V8_ENABLE_CHECKS 4513 #ifdef V8_ENABLE_CHECKS
4514 CheckCast(value); 4514 CheckCast(value);
4515 #endif 4515 #endif
4516 return static_cast<StringObject*>(value); 4516 return static_cast<StringObject*>(value);
4517 } 4517 }
4518 4518
4519 4519
4520 NumberObject* NumberObject::Cast(v8::Value* value) { 4520 NumberObject* NumberObject::Cast(v8::Value* value) {
4521 #ifdef V8_ENABLE_CHECKS 4521 #ifdef V8_ENABLE_CHECKS
4522 CheckCast(value); 4522 CheckCast(value);
4523 #endif 4523 #endif
4524 return static_cast<NumberObject*>(value); 4524 return static_cast<NumberObject*>(value);
4525 } 4525 }
4526 4526
4527 4527
4528 BooleanObject* BooleanObject::Cast(v8::Value* value) { 4528 BooleanObject* BooleanObject::Cast(v8::Value* value) {
4529 #ifdef V8_ENABLE_CHECKS 4529 #ifdef V8_ENABLE_CHECKS
4530 CheckCast(value); 4530 CheckCast(value);
4531 #endif 4531 #endif
4532 return static_cast<BooleanObject*>(value); 4532 return static_cast<BooleanObject*>(value);
4533 } 4533 }
4534 4534
4535 4535
4536 RegExp* RegExp::Cast(v8::Value* value) { 4536 RegExp* RegExp::Cast(v8::Value* value) {
4537 #ifdef V8_ENABLE_CHECKS 4537 #ifdef V8_ENABLE_CHECKS
4538 CheckCast(value); 4538 CheckCast(value);
4539 #endif 4539 #endif
4540 return static_cast<RegExp*>(value); 4540 return static_cast<RegExp*>(value);
4541 } 4541 }
4542 4542
4543 4543
4544 Object* Object::Cast(v8::Value* value) { 4544 Object* Object::Cast(v8::Value* value) {
4545 #ifdef V8_ENABLE_CHECKS 4545 #ifdef V8_ENABLE_CHECKS
4546 CheckCast(value); 4546 CheckCast(value);
4547 #endif 4547 #endif
4548 return static_cast<Object*>(value); 4548 return static_cast<Object*>(value);
4549 } 4549 }
4550 4550
4551 4551
4552 Array* Array::Cast(v8::Value* value) { 4552 Array* Array::Cast(v8::Value* value) {
4553 #ifdef V8_ENABLE_CHECKS 4553 #ifdef V8_ENABLE_CHECKS
4554 CheckCast(value); 4554 CheckCast(value);
4555 #endif 4555 #endif
4556 return static_cast<Array*>(value); 4556 return static_cast<Array*>(value);
4557 } 4557 }
4558 4558
4559 4559
4560 Function* Function::Cast(v8::Value* value) { 4560 Function* Function::Cast(v8::Value* value) {
4561 #ifdef V8_ENABLE_CHECKS 4561 #ifdef V8_ENABLE_CHECKS
4562 CheckCast(value); 4562 CheckCast(value);
4563 #endif 4563 #endif
4564 return static_cast<Function*>(value); 4564 return static_cast<Function*>(value);
4565 } 4565 }
4566 4566
4567 4567
4568 External* External::Cast(v8::Value* value) { 4568 External* External::Cast(v8::Value* value) {
4569 #ifdef V8_ENABLE_CHECKS 4569 #ifdef V8_ENABLE_CHECKS
4570 CheckCast(value); 4570 CheckCast(value);
4571 #endif 4571 #endif
4572 return static_cast<External*>(value); 4572 return static_cast<External*>(value);
4573 } 4573 }
4574 4574
4575 4575
4576 Isolate* AccessorInfo::GetIsolate() const { 4576 Isolate* AccessorInfo::GetIsolate() const {
4577 return *reinterpret_cast<Isolate**>(&args_[-3]); 4577 return *reinterpret_cast<Isolate**>(&args_[-3]);
4578 } 4578 }
4579 4579
4580 4580
4581 Local<Value> AccessorInfo::Data() const { 4581 Local<Value> AccessorInfo::Data() const {
4582 return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); 4582 return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
4583 } 4583 }
4584 4584
4585 4585
4586 Local<Object> AccessorInfo::This() const { 4586 Local<Object> AccessorInfo::This() const {
4587 return Local<Object>(reinterpret_cast<Object*>(&args_[0])); 4587 return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
4588 } 4588 }
4589 4589
4590 4590
4591 Local<Object> AccessorInfo::Holder() const { 4591 Local<Object> AccessorInfo::Holder() const {
4592 return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); 4592 return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
4593 } 4593 }
4594 4594
4595 4595
4596 Handle<Primitive> Undefined(Isolate* isolate) { 4596 Handle<Primitive> Undefined(Isolate* isolate) {
4597 typedef internal::Object* S; 4597 typedef internal::Object* S;
4598 typedef internal::Internals I; 4598 typedef internal::Internals I;
4599 if (!I::IsInitialized(isolate)) return Undefined(); 4599 if (!I::IsInitialized(isolate)) return Undefined();
4600 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); 4600 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
4601 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); 4601 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
4602 } 4602 }
4603 4603
4604 4604
4605 Handle<Primitive> Null(Isolate* isolate) { 4605 Handle<Primitive> Null(Isolate* isolate) {
4606 typedef internal::Object* S; 4606 typedef internal::Object* S;
4607 typedef internal::Internals I; 4607 typedef internal::Internals I;
4608 if (!I::IsInitialized(isolate)) return Null(); 4608 if (!I::IsInitialized(isolate)) return Null();
4609 S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); 4609 S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
4610 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); 4610 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
4611 } 4611 }
4612 4612
4613 4613
4614 Handle<Boolean> True(Isolate* isolate) { 4614 Handle<Boolean> True(Isolate* isolate) {
4615 typedef internal::Object* S; 4615 typedef internal::Object* S;
4616 typedef internal::Internals I; 4616 typedef internal::Internals I;
4617 if (!I::IsInitialized(isolate)) return True(); 4617 if (!I::IsInitialized(isolate)) return True();
4618 S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); 4618 S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
4619 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); 4619 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
4620 } 4620 }
4621 4621
4622 4622
4623 Handle<Boolean> False(Isolate* isolate) { 4623 Handle<Boolean> False(Isolate* isolate) {
4624 typedef internal::Object* S; 4624 typedef internal::Object* S;
4625 typedef internal::Internals I; 4625 typedef internal::Internals I;
4626 if (!I::IsInitialized(isolate)) return False(); 4626 if (!I::IsInitialized(isolate)) return False();
4627 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); 4627 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
4628 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); 4628 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
4629 } 4629 }
4630 4630
4631 4631
4632 void Isolate::SetData(void* data) { 4632 void Isolate::SetData(void* data) {
4633 typedef internal::Internals I; 4633 typedef internal::Internals I;
4634 I::SetEmbedderData(this, data); 4634 I::SetEmbedderData(this, data);
4635 } 4635 }
4636 4636
4637 4637
4638 void* Isolate::GetData() { 4638 void* Isolate::GetData() {
4639 typedef internal::Internals I; 4639 typedef internal::Internals I;
4640 return I::GetEmbedderData(this); 4640 return I::GetEmbedderData(this);
4641 } 4641 }
4642 4642
4643 4643
4644 /** 4644 /**
4645 * \example shell.cc 4645 * \example shell.cc
4646 * A simple shell that takes a list of expressions on the 4646 * A simple shell that takes a list of expressions on the
4647 * command-line and executes them. 4647 * command-line and executes them.
4648 */ 4648 */
4649 4649
4650 4650
4651 /** 4651 /**
4652 * \example process.cc 4652 * \example process.cc
4653 */ 4653 */
4654 4654
4655 4655
4656 } // namespace v8 4656 } // namespace v8
4657 4657
4658 4658
4659 #undef V8EXPORT 4659 #undef V8EXPORT
4660 #undef TYPE_CHECK 4660 #undef TYPE_CHECK
4661 4661
4662 4662
4663 #endif // V8_H_ 4663 #endif // V8_H_
Powered by Google Project Hosting