blob: 882eeddf153c1896e8c19a5c336c2f68b3e708b7 [file] [log] [blame]
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001// Copyright 2007-2009 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
v8.team.kasperl727e9952008-09-02 14:56:44 +000028/** \mainpage V8 API Reference Guide
ager@chromium.org9258b6b2008-09-11 09:11:10 +000029 *
30 * V8 is Google's open source JavaScript engine.
v8.team.kasperl727e9952008-09-02 14:56:44 +000031 *
32 * This set of documents provides reference material generated from the
33 * V8 header file, include/v8.h.
34 *
35 * For other documentation see http://code.google.com/apis/v8/
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036 */
v8.team.kasperl727e9952008-09-02 14:56:44 +000037
ager@chromium.org9258b6b2008-09-11 09:11:10 +000038#ifndef V8_H_
39#define V8_H_
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000040
41#include <stdio.h>
42
43#ifdef _WIN32
kasperl@chromium.org71affb52009-05-26 05:44:31 +000044// When compiling on MinGW stdint.h is available.
45#ifdef __MINGW32__
46#include <stdint.h>
47#else // __MINGW32__
ager@chromium.org5ec48922009-05-05 07:25:34 +000048typedef signed char int8_t;
49typedef unsigned char uint8_t;
50typedef short int16_t; // NOLINT
51typedef unsigned short uint16_t; // NOLINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000052typedef int int32_t;
53typedef unsigned int uint32_t;
ager@chromium.org5ec48922009-05-05 07:25:34 +000054typedef __int64 int64_t;
55typedef unsigned __int64 uint64_t;
kasperl@chromium.org71affb52009-05-26 05:44:31 +000056// intptr_t and friends are defined in crtdefs.h through stdio.h.
57#endif // __MINGW32__
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000058
59// Setup for Windows DLL export/import. When building the V8 DLL the
60// BUILDING_V8_SHARED needs to be defined. When building a program which uses
61// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
62// static library or building a program which uses the V8 static library neither
63// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000064// The reason for having both V8EXPORT and V8EXPORT_INLINE is that classes which
65// have their code inside this header file need to have __declspec(dllexport)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000066// when building the DLL but cannot have __declspec(dllimport) when building
67// a program which uses the DLL.
68#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
69#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
70 build configuration to ensure that at most one of these is set
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000071#endif
72
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000073#ifdef BUILDING_V8_SHARED
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000074#define V8EXPORT __declspec(dllexport)
75#define V8EXPORT_INLINE __declspec(dllexport)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000076#elif USING_V8_SHARED
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000077#define V8EXPORT __declspec(dllimport)
78#define V8EXPORT_INLINE
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000079#else
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000080#define V8EXPORT
81#define V8EXPORT_INLINE
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000082#endif // BUILDING_V8_SHARED
83
84#else // _WIN32
ager@chromium.org9085a012009-05-11 19:22:57 +000085
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000086#include <stdint.h>
87
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +000088// Setup for Linux shared library export. There is no need to distinguish
89// between building or using the V8 shared library, but we should not
90// export symbols when we are building a static library.
91#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000092#define V8EXPORT __attribute__ ((visibility("default")))
93#define V8EXPORT_INLINE __attribute__ ((visibility("default")))
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000094#else // defined(__GNUC__) && (__GNUC__ >= 4)
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000095#define V8EXPORT
96#define V8EXPORT_INLINE
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000097#endif // defined(__GNUC__) && (__GNUC__ >= 4)
98
99#endif // _WIN32
100
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000101/**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000102 * The v8 JavaScript engine.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000103 */
104namespace v8 {
105
106class Context;
107class String;
108class Value;
109class Utils;
110class Number;
111class Object;
112class Array;
113class Int32;
114class Uint32;
115class External;
116class Primitive;
117class Boolean;
118class Integer;
119class Function;
120class Date;
121class ImplementationUtilities;
122class Signature;
123template <class T> class Handle;
124template <class T> class Local;
125template <class T> class Persistent;
126class FunctionTemplate;
127class ObjectTemplate;
128class Data;
129
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000130namespace internal {
131
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000132class Arguments;
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000133class Object;
134class Top;
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000135
136}
137
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000138
139// --- W e a k H a n d l e s
140
141
142/**
143 * A weak reference callback function.
144 *
145 * \param object the weak global object to be reclaimed by the garbage collector
146 * \param parameter the value passed in when making the weak global object
147 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000148typedef void (*WeakReferenceCallback)(Persistent<Value> object,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000149 void* parameter);
150
151
152// --- H a n d l e s ---
153
154#define TYPE_CHECK(T, S) \
155 while (false) { \
156 *(static_cast<T**>(0)) = static_cast<S*>(0); \
157 }
158
159/**
160 * An object reference managed by the v8 garbage collector.
161 *
162 * All objects returned from v8 have to be tracked by the garbage
163 * collector so that it knows that the objects are still alive. Also,
164 * because the garbage collector may move objects, it is unsafe to
165 * point directly to an object. Instead, all objects are stored in
166 * handles which are known by the garbage collector and updated
167 * whenever an object moves. Handles should always be passed by value
168 * (except in cases like out-parameters) and they should never be
169 * allocated on the heap.
170 *
171 * There are two types of handles: local and persistent handles.
172 * Local handles are light-weight and transient and typically used in
173 * local operations. They are managed by HandleScopes. Persistent
174 * handles can be used when storing objects across several independent
175 * operations and have to be explicitly deallocated when they're no
176 * longer used.
177 *
178 * It is safe to extract the object stored in the handle by
179 * dereferencing the handle (for instance, to extract the Object* from
180 * an Handle<Object>); the value will still be governed by a handle
181 * behind the scenes and the same rules apply to these values as to
182 * their handles.
183 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000184template <class T> class V8EXPORT_INLINE Handle {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185 public:
186
187 /**
188 * Creates an empty handle.
189 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000190 inline Handle();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000191
192 /**
193 * Creates a new handle for the specified value.
194 */
195 explicit Handle(T* val) : val_(val) { }
196
197 /**
198 * Creates a handle for the contents of the specified handle. This
199 * constructor allows you to pass handles as arguments by value and
v8.team.kasperl727e9952008-09-02 14:56:44 +0000200 * to assign between handles. However, if you try to assign between
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000201 * incompatible handles, for instance from a Handle<String> to a
202 * Handle<Number> it will cause a compiletime error. Assigning
203 * between compatible handles, for instance assigning a
204 * Handle<String> to a variable declared as Handle<Value>, is legal
205 * because String is a subclass of Value.
206 */
207 template <class S> inline Handle(Handle<S> that)
208 : val_(reinterpret_cast<T*>(*that)) {
209 /**
210 * This check fails when trying to convert between incompatible
211 * handles. For example, converting from a Handle<String> to a
212 * Handle<Number>.
213 */
214 TYPE_CHECK(T, S);
215 }
216
217 /**
218 * Returns true if the handle is empty.
219 */
ager@chromium.org32912102009-01-16 10:38:43 +0000220 bool IsEmpty() const { return val_ == 0; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000221
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000222 T* operator->() const { return val_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000223
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000224 T* operator*() const { return val_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000225
226 /**
227 * Sets the handle to be empty. IsEmpty() will then return true.
228 */
229 void Clear() { this->val_ = 0; }
230
231 /**
232 * Checks whether two handles are the same.
233 * Returns true if both are empty, or if the objects
234 * to which they refer are identical.
235 * The handles' references are not checked.
236 */
ager@chromium.org32912102009-01-16 10:38:43 +0000237 template <class S> bool operator==(Handle<S> that) const {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000238 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
239 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000240 if (a == 0) return b == 0;
241 if (b == 0) return false;
242 return *a == *b;
243 }
244
245 /**
246 * Checks whether two handles are different.
247 * Returns true if only one of the handles is empty, or if
248 * the objects to which they refer are different.
249 * The handles' references are not checked.
250 */
ager@chromium.org32912102009-01-16 10:38:43 +0000251 template <class S> bool operator!=(Handle<S> that) const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000252 return !operator==(that);
253 }
254
255 template <class S> static inline Handle<T> Cast(Handle<S> that) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000256#ifdef V8_ENABLE_CHECKS
257 // If we're going to perform the type check then we have to check
258 // that the handle isn't empty before doing the checked cast.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000259 if (that.IsEmpty()) return Handle<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000260#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000261 return Handle<T>(T::Cast(*that));
262 }
263
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000264 template <class S> inline Handle<S> As() {
265 return Handle<S>::Cast(*this);
266 }
267
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000268 private:
269 T* val_;
270};
271
272
273/**
274 * A light-weight stack-allocated object handle. All operations
275 * that return objects from within v8 return them in local handles. They
276 * are created within HandleScopes, and all local handles allocated within a
277 * handle scope are destroyed when the handle scope is destroyed. Hence it
278 * is not necessary to explicitly deallocate local handles.
279 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000280template <class T> class V8EXPORT_INLINE Local : public Handle<T> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000281 public:
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000282 inline Local();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000283 template <class S> inline Local(Local<S> that)
284 : Handle<T>(reinterpret_cast<T*>(*that)) {
285 /**
286 * This check fails when trying to convert between incompatible
287 * handles. For example, converting from a Handle<String> to a
288 * Handle<Number>.
289 */
290 TYPE_CHECK(T, S);
291 }
292 template <class S> inline Local(S* that) : Handle<T>(that) { }
293 template <class S> static inline Local<T> Cast(Local<S> that) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000294#ifdef V8_ENABLE_CHECKS
295 // If we're going to perform the type check then we have to check
296 // that the handle isn't empty before doing the checked cast.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000297 if (that.IsEmpty()) return Local<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000298#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000299 return Local<T>(T::Cast(*that));
300 }
301
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000302 template <class S> inline Local<S> As() {
303 return Local<S>::Cast(*this);
304 }
305
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000306 /** Create a local handle for the content of another handle.
307 * The referee is kept alive by the local handle even when
308 * the original handle is destroyed/disposed.
309 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000310 inline static Local<T> New(Handle<T> that);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000311};
312
313
314/**
315 * An object reference that is independent of any handle scope. Where
v8.team.kasperl727e9952008-09-02 14:56:44 +0000316 * a Local handle only lives as long as the HandleScope in which it was
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000317 * allocated, a Persistent handle remains valid until it is explicitly
318 * disposed.
319 *
320 * A persistent handle contains a reference to a storage cell within
321 * the v8 engine which holds an object value and which is updated by
322 * the garbage collector whenever the object is moved. A new storage
323 * cell can be created using Persistent::New and existing handles can
324 * be disposed using Persistent::Dispose. Since persistent handles
325 * are passed by value you may have many persistent handle objects
326 * that point to the same storage cell. For instance, if you pass a
327 * persistent handle as an argument to a function you will not get two
328 * different storage cells but rather two references to the same
329 * storage cell.
330 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000331template <class T> class V8EXPORT_INLINE Persistent : public Handle<T> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000332 public:
333
334 /**
335 * Creates an empty persistent handle that doesn't point to any
336 * storage cell.
337 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000338 inline Persistent();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000339
340 /**
341 * Creates a persistent handle for the same storage cell as the
342 * specified handle. This constructor allows you to pass persistent
343 * handles as arguments by value and to assign between persistent
v8.team.kasperl727e9952008-09-02 14:56:44 +0000344 * handles. However, attempting to assign between incompatible
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000345 * persistent handles, for instance from a Persistent<String> to a
v8.team.kasperl727e9952008-09-02 14:56:44 +0000346 * Persistent<Number> will cause a compiletime error. Assigning
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000347 * between compatible persistent handles, for instance assigning a
348 * Persistent<String> to a variable declared as Persistent<Value>,
v8.team.kasperl727e9952008-09-02 14:56:44 +0000349 * is allowed as String is a subclass of Value.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000350 */
351 template <class S> inline Persistent(Persistent<S> that)
352 : Handle<T>(reinterpret_cast<T*>(*that)) {
353 /**
354 * This check fails when trying to convert between incompatible
355 * handles. For example, converting from a Handle<String> to a
356 * Handle<Number>.
357 */
358 TYPE_CHECK(T, S);
359 }
360
361 template <class S> inline Persistent(S* that) : Handle<T>(that) { }
362
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000363 /**
364 * "Casts" a plain handle which is known to be a persistent handle
365 * to a persistent handle.
366 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000367 template <class S> explicit inline Persistent(Handle<S> that)
368 : Handle<T>(*that) { }
369
370 template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000371#ifdef V8_ENABLE_CHECKS
372 // If we're going to perform the type check then we have to check
373 // that the handle isn't empty before doing the checked cast.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000374 if (that.IsEmpty()) return Persistent<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000375#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000376 return Persistent<T>(T::Cast(*that));
377 }
378
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000379 template <class S> inline Persistent<S> As() {
380 return Persistent<S>::Cast(*this);
381 }
382
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000383 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000384 * Creates a new persistent handle for an existing local or
385 * persistent handle.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000386 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000387 inline static Persistent<T> New(Handle<T> that);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000388
389 /**
390 * Releases the storage cell referenced by this persistent handle.
391 * Does not remove the reference to the cell from any handles.
392 * This handle's reference, and any any other references to the storage
393 * cell remain and IsEmpty will still return false.
394 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000395 inline void Dispose();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000396
397 /**
398 * Make the reference to this object weak. When only weak handles
399 * refer to the object, the garbage collector will perform a
400 * callback to the given V8::WeakReferenceCallback function, passing
401 * it the object reference and the given parameters.
402 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000403 inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000404
405 /** Clears the weak reference to this object.*/
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000406 inline void ClearWeak();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000407
408 /**
409 *Checks if the handle holds the only reference to an object.
410 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000411 inline bool IsNearDeath() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000412
413 /**
414 * Returns true if the handle's reference is weak.
415 */
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000416 inline bool IsWeak() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000417
418 private:
419 friend class ImplementationUtilities;
420 friend class ObjectTemplate;
421};
422
423
v8.team.kasperl727e9952008-09-02 14:56:44 +0000424 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000425 * A stack-allocated class that governs a number of local handles.
426 * After a handle scope has been created, all local handles will be
427 * allocated within that handle scope until either the handle scope is
428 * deleted or another handle scope is created. If there is already a
429 * handle scope and a new one is created, all allocations will take
v8.team.kasperl727e9952008-09-02 14:56:44 +0000430 * place in the new handle scope until it is deleted. After that,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000431 * new handles will again be allocated in the original handle scope.
432 *
433 * After the handle scope of a local handle has been deleted the
434 * garbage collector will no longer track the object stored in the
435 * handle and may deallocate it. The behavior of accessing a handle
436 * for which the handle scope has been deleted is undefined.
437 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000438class V8EXPORT HandleScope {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000439 public:
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000440 HandleScope();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000441
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000442 ~HandleScope();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000443
444 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000445 * Closes the handle scope and returns the value as a handle in the
446 * previous scope, which is the new current scope after the call.
447 */
448 template <class T> Local<T> Close(Handle<T> value);
449
450 /**
451 * Counts the number of allocated handles.
452 */
453 static int NumberOfHandles();
454
455 /**
456 * Creates a new handle with the given value.
457 */
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000458 static internal::Object** CreateHandle(internal::Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000459
460 private:
461 // Make it impossible to create heap-allocated or illegal handle
462 // scopes by disallowing certain operations.
463 HandleScope(const HandleScope&);
464 void operator=(const HandleScope&);
465 void* operator new(size_t size);
466 void operator delete(void*, size_t);
467
ager@chromium.org3811b432009-10-28 14:53:37 +0000468 // This Data class is accessible internally as HandleScopeData through a
469 // typedef in the ImplementationUtilities class.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000470 class V8EXPORT Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000471 public:
472 int extensions;
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000473 internal::Object** next;
474 internal::Object** limit;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000475 inline void Initialize() {
476 extensions = -1;
477 next = limit = NULL;
478 }
479 };
480
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000481 Data previous_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000482
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000483 // Allow for the active closing of HandleScopes which allows to pass a handle
484 // from the HandleScope being closed to the next top most HandleScope.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000485 bool is_closed_;
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000486 internal::Object** RawClose(internal::Object** value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000487
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000488 friend class ImplementationUtilities;
489};
490
491
492// --- S p e c i a l o b j e c t s ---
493
494
495/**
496 * The superclass of values and API object templates.
497 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000498class V8EXPORT Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000499 private:
500 Data();
501};
502
503
504/**
505 * Pre-compilation data that can be associated with a script. This
506 * data can be calculated for a script in advance of actually
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000507 * compiling it, and can be stored between compilations. When script
v8.team.kasperl727e9952008-09-02 14:56:44 +0000508 * data is given to the compile method compilation will be faster.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000509 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000510class V8EXPORT ScriptData { // NOLINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000511 public:
512 virtual ~ScriptData() { }
513 static ScriptData* PreCompile(const char* input, int length);
514 static ScriptData* New(unsigned* data, int length);
515
516 virtual int Length() = 0;
517 virtual unsigned* Data() = 0;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000518 virtual bool HasError() = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000519};
520
521
522/**
523 * The origin, within a file, of a script.
524 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000525class V8EXPORT ScriptOrigin {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000526 public:
mads.s.agercbaa0602008-08-14 13:41:48 +0000527 ScriptOrigin(Handle<Value> resource_name,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000528 Handle<Integer> resource_line_offset = Handle<Integer>(),
529 Handle<Integer> resource_column_offset = Handle<Integer>())
530 : resource_name_(resource_name),
531 resource_line_offset_(resource_line_offset),
532 resource_column_offset_(resource_column_offset) { }
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000533 inline Handle<Value> ResourceName() const;
534 inline Handle<Integer> ResourceLineOffset() const;
535 inline Handle<Integer> ResourceColumnOffset() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000536 private:
mads.s.agercbaa0602008-08-14 13:41:48 +0000537 Handle<Value> resource_name_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000538 Handle<Integer> resource_line_offset_;
539 Handle<Integer> resource_column_offset_;
540};
541
542
543/**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000544 * A compiled JavaScript script.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000545 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000546class V8EXPORT Script {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000547 public:
548
549 /**
ager@chromium.org5c838252010-02-19 08:53:10 +0000550 * Compiles the specified script (context-independent).
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000551 *
ager@chromium.org5c838252010-02-19 08:53:10 +0000552 * \param source Script source code.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000553 * \param origin Script origin, owned by caller, no references are kept
ager@chromium.org5c838252010-02-19 08:53:10 +0000554 * when New() returns
555 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
556 * using pre_data speeds compilation if it's done multiple times.
557 * Owned by caller, no references are kept when New() returns.
558 * \param script_data Arbitrary data associated with script. Using
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000559 * this has same effect as calling SetData(), but allows data to be
ager@chromium.org5c838252010-02-19 08:53:10 +0000560 * available to compile event handlers.
561 * \return Compiled script object (context independent; when run it
562 * will use the currently entered context).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000563 */
ager@chromium.org5c838252010-02-19 08:53:10 +0000564 static Local<Script> New(Handle<String> source,
565 ScriptOrigin* origin = NULL,
566 ScriptData* pre_data = NULL,
567 Handle<String> script_data = Handle<String>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000568
mads.s.agercbaa0602008-08-14 13:41:48 +0000569 /**
570 * Compiles the specified script using the specified file name
571 * object (typically a string) as the script's origin.
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000572 *
ager@chromium.org5c838252010-02-19 08:53:10 +0000573 * \param source Script source code.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000574 * \param file_name file name object (typically a string) to be used
ager@chromium.org5c838252010-02-19 08:53:10 +0000575 * as the script's origin.
576 * \return Compiled script object (context independent; when run it
577 * will use the currently entered context).
578 */
579 static Local<Script> New(Handle<String> source,
580 Handle<Value> file_name);
581
582 /**
583 * Compiles the specified script (bound to current context).
584 *
585 * \param source Script source code.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000586 * \param origin Script origin, owned by caller, no references are kept
ager@chromium.org5c838252010-02-19 08:53:10 +0000587 * when Compile() returns
588 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
589 * using pre_data speeds compilation if it's done multiple times.
590 * Owned by caller, no references are kept when Compile() returns.
591 * \param script_data Arbitrary data associated with script. Using
592 * this has same effect as calling SetData(), but makes data available
593 * earlier (i.e. to compile event handlers).
594 * \return Compiled script object, bound to the context that was active
595 * when this function was called. When run it will always use this
596 * context.
mads.s.agercbaa0602008-08-14 13:41:48 +0000597 */
598 static Local<Script> Compile(Handle<String> source,
ager@chromium.org5c838252010-02-19 08:53:10 +0000599 ScriptOrigin* origin = NULL,
600 ScriptData* pre_data = NULL,
601 Handle<String> script_data = Handle<String>());
602
603 /**
604 * Compiles the specified script using the specified file name
605 * object (typically a string) as the script's origin.
606 *
607 * \param source Script source code.
608 * \param file_name File name to use as script's origin
609 * \param script_data Arbitrary data associated with script. Using
610 * this has same effect as calling SetData(), but makes data available
611 * earlier (i.e. to compile event handlers).
612 * \return Compiled script object, bound to the context that was active
613 * when this function was called. When run it will always use this
614 * context.
615 */
616 static Local<Script> Compile(Handle<String> source,
617 Handle<Value> file_name,
618 Handle<String> script_data = Handle<String>());
mads.s.agercbaa0602008-08-14 13:41:48 +0000619
v8.team.kasperl727e9952008-09-02 14:56:44 +0000620 /**
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000621 * Runs the script returning the resulting value. If the script is
622 * context independent (created using ::New) it will be run in the
623 * currently entered context. If it is context specific (created
624 * using ::Compile) it will be run in the context in which it was
625 * compiled.
v8.team.kasperl727e9952008-09-02 14:56:44 +0000626 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000627 Local<Value> Run();
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000628
629 /**
630 * Returns the script id value.
631 */
632 Local<Value> Id();
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000633
634 /**
635 * Associate an additional data object with the script. This is mainly used
636 * with the debugger as this data object is only available through the
637 * debugger API.
638 */
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +0000639 void SetData(Handle<String> data);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000640};
641
642
643/**
644 * An error message.
645 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000646class V8EXPORT Message {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000647 public:
ager@chromium.org32912102009-01-16 10:38:43 +0000648 Local<String> Get() const;
649 Local<String> GetSourceLine() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000650
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000651 /**
652 * Returns the resource name for the script from where the function causing
653 * the error originates.
654 */
ager@chromium.org32912102009-01-16 10:38:43 +0000655 Handle<Value> GetScriptResourceName() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000656
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000657 /**
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000658 * Returns the resource data for the script from where the function causing
659 * the error originates.
660 */
661 Handle<Value> GetScriptData() const;
662
663 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000664 * Returns the number, 1-based, of the line where the error occurred.
665 */
ager@chromium.org32912102009-01-16 10:38:43 +0000666 int GetLineNumber() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000667
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000668 /**
669 * Returns the index within the script of the first character where
670 * the error occurred.
671 */
ager@chromium.org32912102009-01-16 10:38:43 +0000672 int GetStartPosition() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000673
674 /**
675 * Returns the index within the script of the last character where
676 * the error occurred.
677 */
ager@chromium.org32912102009-01-16 10:38:43 +0000678 int GetEndPosition() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000679
680 /**
681 * Returns the index within the line of the first character where
682 * the error occurred.
683 */
ager@chromium.org32912102009-01-16 10:38:43 +0000684 int GetStartColumn() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000685
686 /**
687 * Returns the index within the line of the last character where
688 * the error occurred.
689 */
ager@chromium.org32912102009-01-16 10:38:43 +0000690 int GetEndColumn() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000691
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000692 // TODO(1245381): Print to a string instead of on a FILE.
693 static void PrintCurrentStackTrace(FILE* out);
694};
695
696
697// --- V a l u e ---
698
699
700/**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000701 * The superclass of all JavaScript values and objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000702 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000703class V8EXPORT Value : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000704 public:
705
706 /**
707 * Returns true if this value is the undefined value. See ECMA-262
708 * 4.3.10.
709 */
ager@chromium.org32912102009-01-16 10:38:43 +0000710 bool IsUndefined() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000711
712 /**
713 * Returns true if this value is the null value. See ECMA-262
714 * 4.3.11.
715 */
ager@chromium.org32912102009-01-16 10:38:43 +0000716 bool IsNull() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000717
718 /**
719 * Returns true if this value is true.
720 */
ager@chromium.org32912102009-01-16 10:38:43 +0000721 bool IsTrue() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000722
723 /**
724 * Returns true if this value is false.
725 */
ager@chromium.org32912102009-01-16 10:38:43 +0000726 bool IsFalse() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000727
728 /**
729 * Returns true if this value is an instance of the String type.
730 * See ECMA-262 8.4.
731 */
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000732 inline bool IsString() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000733
734 /**
735 * Returns true if this value is a function.
736 */
ager@chromium.org32912102009-01-16 10:38:43 +0000737 bool IsFunction() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000738
739 /**
740 * Returns true if this value is an array.
741 */
ager@chromium.org32912102009-01-16 10:38:43 +0000742 bool IsArray() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000743
v8.team.kasperl727e9952008-09-02 14:56:44 +0000744 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000745 * Returns true if this value is an object.
746 */
ager@chromium.org32912102009-01-16 10:38:43 +0000747 bool IsObject() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000748
v8.team.kasperl727e9952008-09-02 14:56:44 +0000749 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000750 * Returns true if this value is boolean.
751 */
ager@chromium.org32912102009-01-16 10:38:43 +0000752 bool IsBoolean() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000753
v8.team.kasperl727e9952008-09-02 14:56:44 +0000754 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000755 * Returns true if this value is a number.
756 */
ager@chromium.org32912102009-01-16 10:38:43 +0000757 bool IsNumber() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000758
v8.team.kasperl727e9952008-09-02 14:56:44 +0000759 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000760 * Returns true if this value is external.
761 */
ager@chromium.org32912102009-01-16 10:38:43 +0000762 bool IsExternal() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000763
v8.team.kasperl727e9952008-09-02 14:56:44 +0000764 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000765 * Returns true if this value is a 32-bit signed integer.
766 */
ager@chromium.org32912102009-01-16 10:38:43 +0000767 bool IsInt32() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000768
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000769 /**
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000770 * Returns true if this value is a 32-bit signed integer.
771 */
772 bool IsUint32() const;
773
774 /**
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000775 * Returns true if this value is a Date.
776 */
ager@chromium.org32912102009-01-16 10:38:43 +0000777 bool IsDate() const;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000778
ager@chromium.org32912102009-01-16 10:38:43 +0000779 Local<Boolean> ToBoolean() const;
780 Local<Number> ToNumber() const;
781 Local<String> ToString() const;
782 Local<String> ToDetailString() const;
783 Local<Object> ToObject() const;
784 Local<Integer> ToInteger() const;
785 Local<Uint32> ToUint32() const;
786 Local<Int32> ToInt32() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000787
788 /**
789 * Attempts to convert a string to an array index.
790 * Returns an empty handle if the conversion fails.
791 */
ager@chromium.org32912102009-01-16 10:38:43 +0000792 Local<Uint32> ToArrayIndex() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000793
ager@chromium.org32912102009-01-16 10:38:43 +0000794 bool BooleanValue() const;
795 double NumberValue() const;
796 int64_t IntegerValue() const;
797 uint32_t Uint32Value() const;
798 int32_t Int32Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000799
800 /** JS == */
ager@chromium.org32912102009-01-16 10:38:43 +0000801 bool Equals(Handle<Value> that) const;
802 bool StrictEquals(Handle<Value> that) const;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000803
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000804 private:
805 inline bool QuickIsString() const;
806 bool FullIsString() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000807};
808
809
810/**
811 * The superclass of primitive values. See ECMA-262 4.3.2.
812 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000813class V8EXPORT Primitive : public Value { };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000814
815
816/**
817 * A primitive boolean value (ECMA-262, 4.3.14). Either the true
818 * or false value.
819 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000820class V8EXPORT Boolean : public Primitive {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000821 public:
ager@chromium.org32912102009-01-16 10:38:43 +0000822 bool Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000823 static inline Handle<Boolean> New(bool value);
824};
825
826
827/**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000828 * A JavaScript string value (ECMA-262, 4.3.17).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000829 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000830class V8EXPORT String : public Primitive {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000831 public:
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000832
833 /**
834 * Returns the number of characters in this string.
835 */
ager@chromium.org32912102009-01-16 10:38:43 +0000836 int Length() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000837
v8.team.kasperl727e9952008-09-02 14:56:44 +0000838 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000839 * Returns the number of bytes in the UTF-8 encoded
840 * representation of this string.
841 */
ager@chromium.org32912102009-01-16 10:38:43 +0000842 int Utf8Length() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000843
844 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000845 * Write the contents of the string to an external buffer.
846 * If no arguments are given, expects the buffer to be large
847 * enough to hold the entire string and NULL terminator. Copies
848 * the contents of the string and the NULL terminator into the
849 * buffer.
850 *
851 * Copies up to length characters into the output buffer.
852 * Only null-terminates if there is enough space in the buffer.
853 *
854 * \param buffer The buffer into which the string will be copied.
855 * \param start The starting position within the string at which
856 * copying begins.
857 * \param length The number of bytes to copy from the string.
858 * \return The number of characters copied to the buffer
859 * excluding the NULL terminator.
860 */
ager@chromium.org32912102009-01-16 10:38:43 +0000861 int Write(uint16_t* buffer, int start = 0, int length = -1) const; // UTF-16
862 int WriteAscii(char* buffer, int start = 0, int length = -1) const; // ASCII
863 int WriteUtf8(char* buffer, int length = -1) const; // UTF-8
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000864
v8.team.kasperl727e9952008-09-02 14:56:44 +0000865 /**
ager@chromium.org563b8dc2009-03-20 14:23:52 +0000866 * A zero length string.
867 */
868 static v8::Local<v8::String> Empty();
869
870 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000871 * Returns true if the string is external
872 */
ager@chromium.org32912102009-01-16 10:38:43 +0000873 bool IsExternal() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000874
v8.team.kasperl727e9952008-09-02 14:56:44 +0000875 /**
876 * Returns true if the string is both external and ascii
877 */
ager@chromium.org32912102009-01-16 10:38:43 +0000878 bool IsExternalAscii() const;
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000879
880 class V8EXPORT ExternalStringResourceBase {
881 public:
882 virtual ~ExternalStringResourceBase() {}
883 protected:
884 ExternalStringResourceBase() {}
885 private:
886 // Disallow copying and assigning.
887 ExternalStringResourceBase(const ExternalStringResourceBase&);
888 void operator=(const ExternalStringResourceBase&);
889 };
890
v8.team.kasperl727e9952008-09-02 14:56:44 +0000891 /**
892 * An ExternalStringResource is a wrapper around a two-byte string
893 * buffer that resides outside V8's heap. Implement an
894 * ExternalStringResource to manage the life cycle of the underlying
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000895 * buffer. Note that the string data must be immutable.
v8.team.kasperl727e9952008-09-02 14:56:44 +0000896 */
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000897 class V8EXPORT ExternalStringResource
898 : public ExternalStringResourceBase {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000899 public:
900 /**
901 * Override the destructor to manage the life cycle of the underlying
902 * buffer.
903 */
904 virtual ~ExternalStringResource() {}
905 /** The string data from the underlying buffer.*/
906 virtual const uint16_t* data() const = 0;
907 /** The length of the string. That is, the number of two-byte characters.*/
908 virtual size_t length() const = 0;
909 protected:
910 ExternalStringResource() {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000911 };
912
913 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000914 * An ExternalAsciiStringResource is a wrapper around an ascii
915 * string buffer that resides outside V8's heap. Implement an
916 * ExternalAsciiStringResource to manage the life cycle of the
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000917 * underlying buffer. Note that the string data must be immutable
918 * and that the data must be strict 7-bit ASCII, not Latin1 or
919 * UTF-8, which would require special treatment internally in the
920 * engine and, in the case of UTF-8, do not allow efficient indexing.
921 * Use String::New or convert to 16 bit data for non-ASCII.
v8.team.kasperl727e9952008-09-02 14:56:44 +0000922 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000923
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000924 class V8EXPORT ExternalAsciiStringResource
925 : public ExternalStringResourceBase {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000926 public:
927 /**
928 * Override the destructor to manage the life cycle of the underlying
929 * buffer.
930 */
931 virtual ~ExternalAsciiStringResource() {}
932 /** The string data from the underlying buffer.*/
933 virtual const char* data() const = 0;
934 /** The number of ascii characters in the string.*/
935 virtual size_t length() const = 0;
936 protected:
937 ExternalAsciiStringResource() {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000938 };
939
940 /**
ager@chromium.org9085a012009-05-11 19:22:57 +0000941 * Get the ExternalStringResource for an external string. Returns
942 * NULL if IsExternal() doesn't return true.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000943 */
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000944 inline ExternalStringResource* GetExternalStringResource() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000945
946 /**
947 * Get the ExternalAsciiStringResource for an external ascii string.
ager@chromium.org9085a012009-05-11 19:22:57 +0000948 * Returns NULL if IsExternalAscii() doesn't return true.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000949 */
ager@chromium.org32912102009-01-16 10:38:43 +0000950 ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000951
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000952 static inline String* Cast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000953
954 /**
955 * Allocates a new string from either utf-8 encoded or ascii data.
956 * The second parameter 'length' gives the buffer length.
957 * If the data is utf-8 encoded, the caller must
958 * be careful to supply the length parameter.
959 * If it is not given, the function calls
960 * 'strlen' to determine the buffer length, it might be
kasper.lund7276f142008-07-30 08:49:36 +0000961 * wrong if 'data' contains a null character.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000962 */
963 static Local<String> New(const char* data, int length = -1);
964
965 /** Allocates a new string from utf16 data.*/
966 static Local<String> New(const uint16_t* data, int length = -1);
967
968 /** Creates a symbol. Returns one if it exists already.*/
969 static Local<String> NewSymbol(const char* data, int length = -1);
970
v8.team.kasperl727e9952008-09-02 14:56:44 +0000971 /**
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000972 * Creates a new string by concatenating the left and the right strings
973 * passed in as parameters.
974 */
975 static Local<String> Concat(Handle<String> left, Handle<String>right);
976
977 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000978 * Creates a new external string using the data defined in the given
979 * resource. The resource is deleted when the external string is no
980 * longer live on V8's heap. The caller of this function should not
981 * delete or modify the resource. Neither should the underlying buffer be
982 * deallocated or modified except through the destructor of the
983 * external string resource.
984 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000985 static Local<String> NewExternal(ExternalStringResource* resource);
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000986
ager@chromium.org6f10e412009-02-13 10:11:16 +0000987 /**
988 * Associate an external string resource with this string by transforming it
989 * in place so that existing references to this string in the JavaScript heap
990 * will use the external string resource. The external string resource's
991 * character contents needs to be equivalent to this string.
992 * Returns true if the string has been changed to be an external string.
993 * The string is not modified if the operation fails.
994 */
995 bool MakeExternal(ExternalStringResource* resource);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000996
v8.team.kasperl727e9952008-09-02 14:56:44 +0000997 /**
998 * Creates a new external string using the ascii data defined in the given
999 * resource. The resource is deleted when the external string is no
1000 * longer live on V8's heap. The caller of this function should not
1001 * delete or modify the resource. Neither should the underlying buffer be
1002 * deallocated or modified except through the destructor of the
1003 * external string resource.
1004 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001005 static Local<String> NewExternal(ExternalAsciiStringResource* resource);
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001006
ager@chromium.org6f10e412009-02-13 10:11:16 +00001007 /**
1008 * Associate an external string resource with this string by transforming it
1009 * in place so that existing references to this string in the JavaScript heap
1010 * will use the external string resource. The external string resource's
1011 * character contents needs to be equivalent to this string.
1012 * Returns true if the string has been changed to be an external string.
1013 * The string is not modified if the operation fails.
1014 */
1015 bool MakeExternal(ExternalAsciiStringResource* resource);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001016
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +00001017 /**
1018 * Returns true if this string can be made external.
1019 */
1020 bool CanMakeExternal();
1021
kasper.lund7276f142008-07-30 08:49:36 +00001022 /** Creates an undetectable string from the supplied ascii or utf-8 data.*/
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001023 static Local<String> NewUndetectable(const char* data, int length = -1);
1024
kasper.lund7276f142008-07-30 08:49:36 +00001025 /** Creates an undetectable string from the supplied utf-16 data.*/
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001026 static Local<String> NewUndetectable(const uint16_t* data, int length = -1);
1027
1028 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001029 * Converts an object to a utf8-encoded character array. Useful if
ager@chromium.org71daaf62009-04-01 07:22:49 +00001030 * you want to print the object. If conversion to a string fails
1031 * (eg. due to an exception in the toString() method of the object)
1032 * then the length() method returns 0 and the * operator returns
1033 * NULL.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001034 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001035 class V8EXPORT Utf8Value {
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001036 public:
1037 explicit Utf8Value(Handle<v8::Value> obj);
1038 ~Utf8Value();
ager@chromium.orga1645e22009-09-09 19:27:10 +00001039 char* operator*() { return str_; }
1040 const char* operator*() const { return str_; }
1041 int length() const { return length_; }
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001042 private:
1043 char* str_;
1044 int length_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001045
1046 // Disallow copying and assigning.
1047 Utf8Value(const Utf8Value&);
1048 void operator=(const Utf8Value&);
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001049 };
1050
1051 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001052 * Converts an object to an ascii string.
1053 * Useful if you want to print the object.
ager@chromium.org71daaf62009-04-01 07:22:49 +00001054 * If conversion to a string fails (eg. due to an exception in the toString()
1055 * method of the object) then the length() method returns 0 and the * operator
1056 * returns NULL.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001057 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001058 class V8EXPORT AsciiValue {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001059 public:
1060 explicit AsciiValue(Handle<v8::Value> obj);
1061 ~AsciiValue();
ager@chromium.orga1645e22009-09-09 19:27:10 +00001062 char* operator*() { return str_; }
1063 const char* operator*() const { return str_; }
1064 int length() const { return length_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001065 private:
1066 char* str_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001067 int length_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001068
1069 // Disallow copying and assigning.
1070 AsciiValue(const AsciiValue&);
1071 void operator=(const AsciiValue&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001072 };
1073
1074 /**
1075 * Converts an object to a two-byte string.
ager@chromium.org71daaf62009-04-01 07:22:49 +00001076 * If conversion to a string fails (eg. due to an exception in the toString()
1077 * method of the object) then the length() method returns 0 and the * operator
1078 * returns NULL.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001079 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001080 class V8EXPORT Value {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001081 public:
1082 explicit Value(Handle<v8::Value> obj);
1083 ~Value();
ager@chromium.orga1645e22009-09-09 19:27:10 +00001084 uint16_t* operator*() { return str_; }
1085 const uint16_t* operator*() const { return str_; }
1086 int length() const { return length_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001087 private:
1088 uint16_t* str_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001089 int length_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001090
1091 // Disallow copying and assigning.
1092 Value(const Value&);
1093 void operator=(const Value&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001094 };
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001095
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001096 private:
1097 void VerifyExternalStringResource(ExternalStringResource* val) const;
1098 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001099};
1100
1101
1102/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001103 * A JavaScript number value (ECMA-262, 4.3.20)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001104 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001105class V8EXPORT Number : public Primitive {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001106 public:
ager@chromium.org32912102009-01-16 10:38:43 +00001107 double Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001108 static Local<Number> New(double value);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001109 static inline Number* Cast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001110 private:
1111 Number();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001112 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001113};
1114
1115
1116/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001117 * A JavaScript value representing a signed integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001118 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001119class V8EXPORT Integer : public Number {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001120 public:
1121 static Local<Integer> New(int32_t value);
ager@chromium.org3811b432009-10-28 14:53:37 +00001122 static Local<Integer> NewFromUnsigned(uint32_t value);
ager@chromium.org32912102009-01-16 10:38:43 +00001123 int64_t Value() const;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001124 static inline Integer* Cast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001125 private:
1126 Integer();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001127 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001128};
1129
1130
1131/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001132 * A JavaScript value representing a 32-bit signed integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001133 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001134class V8EXPORT Int32 : public Integer {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001135 public:
ager@chromium.org32912102009-01-16 10:38:43 +00001136 int32_t Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001137 private:
1138 Int32();
1139};
1140
1141
1142/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001143 * A JavaScript value representing a 32-bit unsigned integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001144 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001145class V8EXPORT Uint32 : public Integer {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001146 public:
ager@chromium.org32912102009-01-16 10:38:43 +00001147 uint32_t Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001148 private:
1149 Uint32();
1150};
1151
1152
1153/**
1154 * An instance of the built-in Date constructor (ECMA-262, 15.9).
1155 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001156class V8EXPORT Date : public Value {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001157 public:
1158 static Local<Value> New(double time);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001159
1160 /**
1161 * A specialization of Value::NumberValue that is more efficient
1162 * because we know the structure of this object.
1163 */
ager@chromium.org32912102009-01-16 10:38:43 +00001164 double NumberValue() const;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001165
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001166 static inline Date* Cast(v8::Value* obj);
1167 private:
1168 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001169};
1170
1171
1172enum PropertyAttribute {
1173 None = 0,
1174 ReadOnly = 1 << 0,
1175 DontEnum = 1 << 1,
1176 DontDelete = 1 << 2
1177};
1178
ager@chromium.org3811b432009-10-28 14:53:37 +00001179enum ExternalArrayType {
1180 kExternalByteArray = 1,
1181 kExternalUnsignedByteArray,
1182 kExternalShortArray,
1183 kExternalUnsignedShortArray,
1184 kExternalIntArray,
1185 kExternalUnsignedIntArray,
1186 kExternalFloatArray
1187};
1188
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001189/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001190 * A JavaScript object (ECMA-262, 4.3.3)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001191 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001192class V8EXPORT Object : public Value {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001193 public:
1194 bool Set(Handle<Value> key,
1195 Handle<Value> value,
1196 PropertyAttribute attribs = None);
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001197
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001198 bool Set(uint32_t index,
1199 Handle<Value> value);
1200
ager@chromium.orge2902be2009-06-08 12:21:35 +00001201 // Sets a local property on this object bypassing interceptors and
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001202 // overriding accessors or read-only properties.
1203 //
1204 // Note that if the object has an interceptor the property will be set
1205 // locally, but since the interceptor takes precedence the local property
1206 // will only be returned if the interceptor doesn't return a value.
1207 //
1208 // Note also that this only works for named properties.
1209 bool ForceSet(Handle<Value> key,
1210 Handle<Value> value,
1211 PropertyAttribute attribs = None);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001212
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001213 Local<Value> Get(Handle<Value> key);
1214
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001215 Local<Value> Get(uint32_t index);
1216
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001217 // TODO(1245389): Replace the type-specific versions of these
1218 // functions with generic ones that accept a Handle<Value> key.
1219 bool Has(Handle<String> key);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001220
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001221 bool Delete(Handle<String> key);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001222
1223 // Delete a property on this object bypassing interceptors and
1224 // ignoring dont-delete attributes.
1225 bool ForceDelete(Handle<Value> key);
1226
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001227 bool Has(uint32_t index);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001228
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001229 bool Delete(uint32_t index);
1230
1231 /**
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001232 * Returns an array containing the names of the enumerable properties
1233 * of this object, including properties from prototype objects. The
1234 * array returned by this method contains the same values as would
1235 * be enumerated by a for-in statement over this object.
1236 */
1237 Local<Array> GetPropertyNames();
1238
1239 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001240 * Get the prototype object. This does not skip objects marked to
1241 * be skipped by __proto__ and it does not consult the security
1242 * handler.
1243 */
1244 Local<Value> GetPrototype();
1245
1246 /**
ager@chromium.org5c838252010-02-19 08:53:10 +00001247 * Set the prototype object. This does not skip objects marked to
1248 * be skipped by __proto__ and it does not consult the security
1249 * handler.
1250 */
1251 bool SetPrototype(Handle<Value> prototype);
1252
1253 /**
sgjesse@chromium.org900d3b72009-08-07 11:24:25 +00001254 * Finds an instance of the given function template in the prototype
1255 * chain.
1256 */
1257 Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl);
1258
1259 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001260 * Call builtin Object.prototype.toString on this object.
1261 * This is different from Value::ToString() that may call
1262 * user-defined toString function. This one does not.
1263 */
1264 Local<String> ObjectProtoToString();
1265
kasper.lund212ac232008-07-16 07:07:30 +00001266 /** Gets the number of internal fields for this Object. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001267 int InternalFieldCount();
kasper.lund212ac232008-07-16 07:07:30 +00001268 /** Gets the value in an internal field. */
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001269 inline Local<Value> GetInternalField(int index);
kasper.lund212ac232008-07-16 07:07:30 +00001270 /** Sets the value in an internal field. */
1271 void SetInternalField(int index, Handle<Value> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001272
kasperl@chromium.orge959c182009-07-27 08:59:04 +00001273 /** Gets a native pointer from an internal field. */
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001274 inline void* GetPointerFromInternalField(int index);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001275
kasperl@chromium.orge959c182009-07-27 08:59:04 +00001276 /** Sets a native pointer in an internal field. */
1277 void SetPointerInInternalField(int index, void* value);
1278
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001279 // Testers for local properties.
1280 bool HasRealNamedProperty(Handle<String> key);
1281 bool HasRealIndexedProperty(uint32_t index);
1282 bool HasRealNamedCallbackProperty(Handle<String> key);
1283
1284 /**
1285 * If result.IsEmpty() no real property was located in the prototype chain.
1286 * This means interceptors in the prototype chain are not called.
1287 */
sgjesse@chromium.org98aff2f2009-09-30 08:27:10 +00001288 Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
1289
1290 /**
1291 * If result.IsEmpty() no real property was located on the object or
1292 * in the prototype chain.
1293 * This means interceptors in the prototype chain are not called.
1294 */
1295 Local<Value> GetRealNamedProperty(Handle<String> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001296
1297 /** Tests for a named lookup interceptor.*/
1298 bool HasNamedLookupInterceptor();
1299
kasper.lund212ac232008-07-16 07:07:30 +00001300 /** Tests for an index lookup interceptor.*/
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001301 bool HasIndexedLookupInterceptor();
1302
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001303 /**
1304 * Turns on access check on the object if the object is an instance of
1305 * a template that has access check callbacks. If an object has no
1306 * access check info, the object cannot be accessed by anyone.
1307 */
1308 void TurnOnAccessCheck();
ager@chromium.org41826e72009-03-30 13:30:57 +00001309
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001310 /**
1311 * Returns the identity hash for this object. The current implemenation uses
ager@chromium.org9085a012009-05-11 19:22:57 +00001312 * a hidden property on the object to store the identity hash.
ager@chromium.org5ec48922009-05-05 07:25:34 +00001313 *
ager@chromium.org9085a012009-05-11 19:22:57 +00001314 * The return value will never be 0. Also, it is not guaranteed to be
ager@chromium.org5ec48922009-05-05 07:25:34 +00001315 * unique.
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001316 */
1317 int GetIdentityHash();
ager@chromium.org41826e72009-03-30 13:30:57 +00001318
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001319 /**
1320 * Access hidden properties on JavaScript objects. These properties are
1321 * hidden from the executing JavaScript and only accessible through the V8
1322 * C++ API. Hidden properties introduced by V8 internally (for example the
1323 * identity hash) are prefixed with "v8::".
1324 */
1325 bool SetHiddenValue(Handle<String> key, Handle<Value> value);
1326 Local<Value> GetHiddenValue(Handle<String> key);
1327 bool DeleteHiddenValue(Handle<String> key);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001328
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001329 /**
1330 * Returns true if this is an instance of an api function (one
1331 * created from a function created from a function template) and has
1332 * been modified since it was created. Note that this method is
1333 * conservative and may return true for objects that haven't actually
1334 * been modified.
1335 */
1336 bool IsDirty();
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001337
1338 /**
1339 * Clone this object with a fast but shallow copy. Values will point
1340 * to the same values as the original object.
1341 */
1342 Local<Object> Clone();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001343
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001344 /**
1345 * Set the backing store of the indexed properties to be managed by the
1346 * embedding layer. Access to the indexed properties will follow the rules
1347 * spelled out in CanvasPixelArray.
1348 * Note: The embedding program still owns the data and needs to ensure that
1349 * the backing store is preserved while V8 has a reference.
1350 */
1351 void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
1352
ager@chromium.org3811b432009-10-28 14:53:37 +00001353 /**
1354 * Set the backing store of the indexed properties to be managed by the
1355 * embedding layer. Access to the indexed properties will follow the rules
1356 * spelled out for the CanvasArray subtypes in the WebGL specification.
1357 * Note: The embedding program still owns the data and needs to ensure that
1358 * the backing store is preserved while V8 has a reference.
1359 */
1360 void SetIndexedPropertiesToExternalArrayData(void* data,
1361 ExternalArrayType array_type,
1362 int number_of_elements);
1363
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001364 static Local<Object> New();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001365 static inline Object* Cast(Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001366 private:
1367 Object();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001368 static void CheckCast(Value* obj);
1369 Local<Value> CheckedGetInternalField(int index);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001370 void* SlowGetPointerFromInternalField(int index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001371
1372 /**
1373 * If quick access to the internal field is possible this method
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001374 * returns the value. Otherwise an empty handle is returned.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001375 */
1376 inline Local<Value> UncheckedGetInternalField(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001377};
1378
1379
1380/**
1381 * An instance of the built-in array constructor (ECMA-262, 15.4.2).
1382 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001383class V8EXPORT Array : public Object {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001384 public:
ager@chromium.org32912102009-01-16 10:38:43 +00001385 uint32_t Length() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001386
ager@chromium.org3e875802009-06-29 08:26:34 +00001387 /**
1388 * Clones an element at index |index|. Returns an empty
1389 * handle if cloning fails (for any reason).
1390 */
1391 Local<Object> CloneElementAt(uint32_t index);
1392
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001393 static Local<Array> New(int length = 0);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001394 static inline Array* Cast(Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001395 private:
1396 Array();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001397 static void CheckCast(Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001398};
1399
1400
1401/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001402 * A JavaScript function object (ECMA-262, 15.3).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001403 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001404class V8EXPORT Function : public Object {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001405 public:
ager@chromium.org32912102009-01-16 10:38:43 +00001406 Local<Object> NewInstance() const;
1407 Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001408 Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]);
1409 void SetName(Handle<String> name);
ager@chromium.org32912102009-01-16 10:38:43 +00001410 Handle<Value> GetName() const;
ager@chromium.org5c838252010-02-19 08:53:10 +00001411
1412 /**
1413 * Returns zero based line number of function body and
1414 * kLineOffsetNotFound if no information available.
1415 */
1416 int GetScriptLineNumber() const;
1417 ScriptOrigin GetScriptOrigin() const;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001418 static inline Function* Cast(Value* obj);
ager@chromium.org5c838252010-02-19 08:53:10 +00001419 static const int kLineOffsetNotFound;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001420 private:
1421 Function();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001422 static void CheckCast(Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001423};
1424
1425
1426/**
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001427 * A JavaScript value that wraps a C++ void*. This type of value is
1428 * mainly used to associate C++ data structures with JavaScript
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001429 * objects.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001430 *
1431 * The Wrap function V8 will return the most optimal Value object wrapping the
1432 * C++ void*. The type of the value is not guaranteed to be an External object
1433 * and no assumptions about its type should be made. To access the wrapped
1434 * value Unwrap should be used, all other operations on that object will lead
1435 * to unpredictable results.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001436 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001437class V8EXPORT External : public Value {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001438 public:
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001439 static Local<Value> Wrap(void* data);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001440 static inline void* Unwrap(Handle<Value> obj);
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001441
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001442 static Local<External> New(void* value);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001443 static inline External* Cast(Value* obj);
ager@chromium.org32912102009-01-16 10:38:43 +00001444 void* Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001445 private:
1446 External();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001447 static void CheckCast(v8::Value* obj);
1448 static inline void* QuickUnwrap(Handle<v8::Value> obj);
1449 static void* FullUnwrap(Handle<v8::Value> obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001450};
1451
1452
1453// --- T e m p l a t e s ---
1454
1455
1456/**
1457 * The superclass of object and function templates.
1458 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001459class V8EXPORT Template : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001460 public:
1461 /** Adds a property to each instance created by this template.*/
1462 void Set(Handle<String> name, Handle<Data> value,
1463 PropertyAttribute attributes = None);
1464 inline void Set(const char* name, Handle<Data> value);
1465 private:
1466 Template();
1467
1468 friend class ObjectTemplate;
1469 friend class FunctionTemplate;
1470};
1471
1472
1473/**
1474 * The argument information given to function call callbacks. This
v8.team.kasperl727e9952008-09-02 14:56:44 +00001475 * class provides access to information about the context of the call,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001476 * including the receiver, the number and values of arguments, and
1477 * the holder of the function.
1478 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001479class V8EXPORT Arguments {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001480 public:
1481 inline int Length() const;
1482 inline Local<Value> operator[](int i) const;
1483 inline Local<Function> Callee() const;
1484 inline Local<Object> This() const;
1485 inline Local<Object> Holder() const;
1486 inline bool IsConstructCall() const;
1487 inline Local<Value> Data() const;
1488 private:
1489 Arguments();
1490 friend class ImplementationUtilities;
1491 inline Arguments(Local<Value> data,
1492 Local<Object> holder,
1493 Local<Function> callee,
1494 bool is_construct_call,
1495 void** values, int length);
1496 Local<Value> data_;
1497 Local<Object> holder_;
1498 Local<Function> callee_;
1499 bool is_construct_call_;
1500 void** values_;
1501 int length_;
1502};
1503
1504
1505/**
1506 * The information passed to an accessor callback about the context
1507 * of the property access.
1508 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001509class V8EXPORT AccessorInfo {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001510 public:
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001511 inline AccessorInfo(internal::Object** args)
1512 : args_(args) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001513 inline Local<Value> Data() const;
1514 inline Local<Object> This() const;
1515 inline Local<Object> Holder() const;
1516 private:
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001517 internal::Object** args_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001518};
1519
1520
1521typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
1522
1523typedef int (*LookupCallback)(Local<Object> self, Local<String> name);
1524
1525/**
1526 * Accessor[Getter|Setter] are used as callback functions when
1527 * setting|getting a particular property. See objectTemplate::SetAccessor.
1528 */
1529typedef Handle<Value> (*AccessorGetter)(Local<String> property,
1530 const AccessorInfo& info);
1531
1532
1533typedef void (*AccessorSetter)(Local<String> property,
1534 Local<Value> value,
1535 const AccessorInfo& info);
1536
1537
1538/**
1539 * NamedProperty[Getter|Setter] are used as interceptors on object.
1540 * See ObjectTemplate::SetNamedPropertyHandler.
1541 */
1542typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
1543 const AccessorInfo& info);
1544
1545
1546/**
1547 * Returns the value if the setter intercepts the request.
1548 * Otherwise, returns an empty handle.
1549 */
1550typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
1551 Local<Value> value,
1552 const AccessorInfo& info);
1553
1554
1555/**
1556 * Returns a non-empty handle if the interceptor intercepts the request.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001557 * The result is true if the property exists and false otherwise.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001558 */
1559typedef Handle<Boolean> (*NamedPropertyQuery)(Local<String> property,
1560 const AccessorInfo& info);
1561
1562
1563/**
1564 * Returns a non-empty handle if the deleter intercepts the request.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001565 * The return value is true if the property could be deleted and false
1566 * otherwise.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001567 */
1568typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
1569 const AccessorInfo& info);
1570
1571/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001572 * Returns an array containing the names of the properties the named
1573 * property getter intercepts.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001574 */
1575typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
1576
v8.team.kasperl727e9952008-09-02 14:56:44 +00001577
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001578/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001579 * Returns the value of the property if the getter intercepts the
1580 * request. Otherwise, returns an empty handle.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001581 */
1582typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
1583 const AccessorInfo& info);
1584
1585
1586/**
1587 * Returns the value if the setter intercepts the request.
1588 * Otherwise, returns an empty handle.
1589 */
1590typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
1591 Local<Value> value,
1592 const AccessorInfo& info);
1593
1594
1595/**
1596 * Returns a non-empty handle if the interceptor intercepts the request.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001597 * The result is true if the property exists and false otherwise.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001598 */
1599typedef Handle<Boolean> (*IndexedPropertyQuery)(uint32_t index,
1600 const AccessorInfo& info);
1601
1602/**
1603 * Returns a non-empty handle if the deleter intercepts the request.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001604 * The return value is true if the property could be deleted and false
1605 * otherwise.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001606 */
1607typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
1608 const AccessorInfo& info);
1609
v8.team.kasperl727e9952008-09-02 14:56:44 +00001610/**
1611 * Returns an array containing the indices of the properties the
1612 * indexed property getter intercepts.
1613 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001614typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
1615
1616
1617/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001618 * Access control specifications.
1619 *
1620 * Some accessors should be accessible across contexts. These
1621 * accessors have an explicit access control parameter which specifies
1622 * the kind of cross-context access that should be allowed.
ager@chromium.org870a0b62008-11-04 11:43:05 +00001623 *
1624 * Additionally, for security, accessors can prohibit overwriting by
1625 * accessors defined in JavaScript. For objects that have such
1626 * accessors either locally or in their prototype chain it is not
1627 * possible to overwrite the accessor by using __defineGetter__ or
1628 * __defineSetter__ from JavaScript code.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001629 */
1630enum AccessControl {
ager@chromium.org870a0b62008-11-04 11:43:05 +00001631 DEFAULT = 0,
1632 ALL_CAN_READ = 1,
1633 ALL_CAN_WRITE = 1 << 1,
1634 PROHIBITS_OVERWRITING = 1 << 2
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001635};
1636
1637
1638/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001639 * Access type specification.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001640 */
1641enum AccessType {
1642 ACCESS_GET,
1643 ACCESS_SET,
1644 ACCESS_HAS,
1645 ACCESS_DELETE,
1646 ACCESS_KEYS
1647};
1648
v8.team.kasperl727e9952008-09-02 14:56:44 +00001649
1650/**
1651 * Returns true if cross-context access should be allowed to the named
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001652 * property with the given key on the host object.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001653 */
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001654typedef bool (*NamedSecurityCallback)(Local<Object> host,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001655 Local<Value> key,
1656 AccessType type,
1657 Local<Value> data);
1658
v8.team.kasperl727e9952008-09-02 14:56:44 +00001659
1660/**
1661 * Returns true if cross-context access should be allowed to the indexed
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001662 * property with the given index on the host object.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001663 */
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001664typedef bool (*IndexedSecurityCallback)(Local<Object> host,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001665 uint32_t index,
1666 AccessType type,
1667 Local<Value> data);
1668
1669
1670/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001671 * A FunctionTemplate is used to create functions at runtime. There
1672 * can only be one function created from a FunctionTemplate in a
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001673 * context. The lifetime of the created function is equal to the
1674 * lifetime of the context. So in case the embedder needs to create
1675 * temporary functions that can be collected using Scripts is
1676 * preferred.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001677 *
1678 * A FunctionTemplate can have properties, these properties are added to the
v8.team.kasperl727e9952008-09-02 14:56:44 +00001679 * function object when it is created.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001680 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001681 * A FunctionTemplate has a corresponding instance template which is
1682 * used to create object instances when the function is used as a
1683 * constructor. Properties added to the instance template are added to
1684 * each object instance.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001685 *
1686 * A FunctionTemplate can have a prototype template. The prototype template
1687 * is used to create the prototype object of the function.
1688 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001689 * The following example shows how to use a FunctionTemplate:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001690 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001691 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001692 * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
1693 * t->Set("func_property", v8::Number::New(1));
1694 *
1695 * v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
1696 * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
1697 * proto_t->Set("proto_const", v8::Number::New(2));
1698 *
1699 * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
1700 * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
1701 * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
1702 * instance_t->Set("instance_property", Number::New(3));
1703 *
1704 * v8::Local<v8::Function> function = t->GetFunction();
1705 * v8::Local<v8::Object> instance = function->NewInstance();
v8.team.kasperl727e9952008-09-02 14:56:44 +00001706 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001707 *
1708 * Let's use "function" as the JS variable name of the function object
v8.team.kasperl727e9952008-09-02 14:56:44 +00001709 * and "instance" for the instance object created above. The function
1710 * and the instance will have the following properties:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001711 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001712 * \code
1713 * func_property in function == true;
1714 * function.func_property == 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001715 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001716 * function.prototype.proto_method() invokes 'InvokeCallback'
1717 * function.prototype.proto_const == 2;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001718 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001719 * instance instanceof function == true;
1720 * instance.instance_accessor calls 'InstanceAccessorCallback'
1721 * instance.instance_property == 3;
1722 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001723 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001724 * A FunctionTemplate can inherit from another one by calling the
1725 * FunctionTemplate::Inherit method. The following graph illustrates
1726 * the semantics of inheritance:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001727 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001728 * \code
1729 * FunctionTemplate Parent -> Parent() . prototype -> { }
1730 * ^ ^
1731 * | Inherit(Parent) | .__proto__
1732 * | |
1733 * FunctionTemplate Child -> Child() . prototype -> { }
1734 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001735 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001736 * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
1737 * object of the Child() function has __proto__ pointing to the
1738 * Parent() function's prototype object. An instance of the Child
1739 * function has all properties on Parent's instance templates.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001740 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001741 * Let Parent be the FunctionTemplate initialized in the previous
1742 * section and create a Child FunctionTemplate by:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001743 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001744 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001745 * Local<FunctionTemplate> parent = t;
1746 * Local<FunctionTemplate> child = FunctionTemplate::New();
1747 * child->Inherit(parent);
1748 *
1749 * Local<Function> child_function = child->GetFunction();
1750 * Local<Object> child_instance = child_function->NewInstance();
v8.team.kasperl727e9952008-09-02 14:56:44 +00001751 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001752 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001753 * The Child function and Child instance will have the following
1754 * properties:
1755 *
1756 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001757 * child_func.prototype.__proto__ == function.prototype;
v8.team.kasperl727e9952008-09-02 14:56:44 +00001758 * child_instance.instance_accessor calls 'InstanceAccessorCallback'
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001759 * child_instance.instance_property == 3;
v8.team.kasperl727e9952008-09-02 14:56:44 +00001760 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001761 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001762class V8EXPORT FunctionTemplate : public Template {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001763 public:
1764 /** Creates a function template.*/
v8.team.kasperl727e9952008-09-02 14:56:44 +00001765 static Local<FunctionTemplate> New(
1766 InvocationCallback callback = 0,
1767 Handle<Value> data = Handle<Value>(),
1768 Handle<Signature> signature = Handle<Signature>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001769 /** Returns the unique function instance in the current execution context.*/
1770 Local<Function> GetFunction();
1771
v8.team.kasperl727e9952008-09-02 14:56:44 +00001772 /**
1773 * Set the call-handler callback for a FunctionTemplate. This
1774 * callback is called whenever the function created from this
1775 * FunctionTemplate is called.
1776 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001777 void SetCallHandler(InvocationCallback callback,
1778 Handle<Value> data = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001779
v8.team.kasperl727e9952008-09-02 14:56:44 +00001780 /** Get the InstanceTemplate. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001781 Local<ObjectTemplate> InstanceTemplate();
1782
1783 /** Causes the function template to inherit from a parent function template.*/
1784 void Inherit(Handle<FunctionTemplate> parent);
1785
1786 /**
1787 * A PrototypeTemplate is the template used to create the prototype object
1788 * of the function created by this template.
1789 */
1790 Local<ObjectTemplate> PrototypeTemplate();
1791
v8.team.kasperl727e9952008-09-02 14:56:44 +00001792
1793 /**
1794 * Set the class name of the FunctionTemplate. This is used for
1795 * printing objects created with the function created from the
1796 * FunctionTemplate as its constructor.
1797 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001798 void SetClassName(Handle<String> name);
1799
1800 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001801 * Determines whether the __proto__ accessor ignores instances of
1802 * the function template. If instances of the function template are
1803 * ignored, __proto__ skips all instances and instead returns the
1804 * next object in the prototype chain.
1805 *
1806 * Call with a value of true to make the __proto__ accessor ignore
1807 * instances of the function template. Call with a value of false
1808 * to make the __proto__ accessor not ignore instances of the
1809 * function template. By default, instances of a function template
1810 * are not ignored.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001811 */
1812 void SetHiddenPrototype(bool value);
1813
1814 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001815 * Returns true if the given object is an instance of this function
1816 * template.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001817 */
1818 bool HasInstance(Handle<Value> object);
1819
1820 private:
1821 FunctionTemplate();
1822 void AddInstancePropertyAccessor(Handle<String> name,
1823 AccessorGetter getter,
1824 AccessorSetter setter,
1825 Handle<Value> data,
1826 AccessControl settings,
1827 PropertyAttribute attributes);
1828 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
1829 NamedPropertySetter setter,
1830 NamedPropertyQuery query,
1831 NamedPropertyDeleter remover,
1832 NamedPropertyEnumerator enumerator,
1833 Handle<Value> data);
1834 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
1835 IndexedPropertySetter setter,
1836 IndexedPropertyQuery query,
1837 IndexedPropertyDeleter remover,
1838 IndexedPropertyEnumerator enumerator,
1839 Handle<Value> data);
1840 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
1841 Handle<Value> data);
1842
1843 friend class Context;
1844 friend class ObjectTemplate;
1845};
1846
1847
1848/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001849 * An ObjectTemplate is used to create objects at runtime.
1850 *
1851 * Properties added to an ObjectTemplate are added to each object
1852 * created from the ObjectTemplate.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001853 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001854class V8EXPORT ObjectTemplate : public Template {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001855 public:
v8.team.kasperl727e9952008-09-02 14:56:44 +00001856 /** Creates an ObjectTemplate. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001857 static Local<ObjectTemplate> New();
v8.team.kasperl727e9952008-09-02 14:56:44 +00001858
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001859 /** Creates a new instance of this template.*/
1860 Local<Object> NewInstance();
1861
1862 /**
1863 * Sets an accessor on the object template.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001864 *
1865 * Whenever the property with the given name is accessed on objects
1866 * created from this ObjectTemplate the getter and setter callbacks
1867 * are called instead of getting and setting the property directly
1868 * on the JavaScript object.
1869 *
1870 * \param name The name of the property for which an accessor is added.
1871 * \param getter The callback to invoke when getting the property.
1872 * \param setter The callback to invoke when setting the property.
1873 * \param data A piece of data that will be passed to the getter and setter
1874 * callbacks whenever they are invoked.
1875 * \param settings Access control settings for the accessor. This is a bit
1876 * field consisting of one of more of
1877 * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
1878 * The default is to not allow cross-context access.
1879 * ALL_CAN_READ means that all cross-context reads are allowed.
1880 * ALL_CAN_WRITE means that all cross-context writes are allowed.
1881 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
1882 * cross-context access.
1883 * \param attribute The attributes of the property for which an accessor
1884 * is added.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001885 */
1886 void SetAccessor(Handle<String> name,
1887 AccessorGetter getter,
1888 AccessorSetter setter = 0,
1889 Handle<Value> data = Handle<Value>(),
1890 AccessControl settings = DEFAULT,
1891 PropertyAttribute attribute = None);
1892
1893 /**
1894 * Sets a named property handler on the object template.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001895 *
1896 * Whenever a named property is accessed on objects created from
1897 * this object template, the provided callback is invoked instead of
1898 * accessing the property directly on the JavaScript object.
1899 *
1900 * \param getter The callback to invoke when getting a property.
1901 * \param setter The callback to invoke when setting a property.
1902 * \param query The callback to invoke to check is an object has a property.
1903 * \param deleter The callback to invoke when deleting a property.
1904 * \param enumerator The callback to invoke to enumerate all the named
1905 * properties of an object.
1906 * \param data A piece of data that will be passed to the callbacks
1907 * whenever they are invoked.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001908 */
1909 void SetNamedPropertyHandler(NamedPropertyGetter getter,
1910 NamedPropertySetter setter = 0,
1911 NamedPropertyQuery query = 0,
1912 NamedPropertyDeleter deleter = 0,
1913 NamedPropertyEnumerator enumerator = 0,
1914 Handle<Value> data = Handle<Value>());
1915
1916 /**
1917 * Sets an indexed property handler on the object template.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001918 *
1919 * Whenever an indexed property is accessed on objects created from
1920 * this object template, the provided callback is invoked instead of
1921 * accessing the property directly on the JavaScript object.
1922 *
1923 * \param getter The callback to invoke when getting a property.
1924 * \param setter The callback to invoke when setting a property.
1925 * \param query The callback to invoke to check is an object has a property.
1926 * \param deleter The callback to invoke when deleting a property.
1927 * \param enumerator The callback to invoke to enumerate all the indexed
1928 * properties of an object.
1929 * \param data A piece of data that will be passed to the callbacks
1930 * whenever they are invoked.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001931 */
1932 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
1933 IndexedPropertySetter setter = 0,
1934 IndexedPropertyQuery query = 0,
1935 IndexedPropertyDeleter deleter = 0,
1936 IndexedPropertyEnumerator enumerator = 0,
1937 Handle<Value> data = Handle<Value>());
1938 /**
1939 * Sets the callback to be used when calling instances created from
1940 * this template as a function. If no callback is set, instances
v8.team.kasperl727e9952008-09-02 14:56:44 +00001941 * behave like normal JavaScript objects that cannot be called as a
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001942 * function.
1943 */
1944 void SetCallAsFunctionHandler(InvocationCallback callback,
1945 Handle<Value> data = Handle<Value>());
1946
v8.team.kasperl727e9952008-09-02 14:56:44 +00001947 /**
1948 * Mark object instances of the template as undetectable.
1949 *
1950 * In many ways, undetectable objects behave as though they are not
1951 * there. They behave like 'undefined' in conditionals and when
1952 * printed. However, properties can be accessed and called as on
1953 * normal objects.
1954 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001955 void MarkAsUndetectable();
1956
v8.team.kasperl727e9952008-09-02 14:56:44 +00001957 /**
1958 * Sets access check callbacks on the object template.
1959 *
1960 * When accessing properties on instances of this object template,
1961 * the access check callback will be called to determine whether or
1962 * not to allow cross-context access to the properties.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001963 * The last parameter specifies whether access checks are turned
1964 * on by default on instances. If access checks are off by default,
1965 * they can be turned on on individual instances by calling
1966 * Object::TurnOnAccessCheck().
v8.team.kasperl727e9952008-09-02 14:56:44 +00001967 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001968 void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
1969 IndexedSecurityCallback indexed_handler,
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001970 Handle<Value> data = Handle<Value>(),
1971 bool turned_on_by_default = true);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001972
kasper.lund212ac232008-07-16 07:07:30 +00001973 /**
1974 * Gets the number of internal fields for objects generated from
1975 * this template.
1976 */
1977 int InternalFieldCount();
1978
1979 /**
1980 * Sets the number of internal fields for objects generated from
1981 * this template.
1982 */
1983 void SetInternalFieldCount(int value);
1984
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001985 private:
1986 ObjectTemplate();
1987 static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
1988 friend class FunctionTemplate;
1989};
1990
1991
1992/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001993 * A Signature specifies which receivers and arguments a function can
1994 * legally be called with.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001995 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001996class V8EXPORT Signature : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001997 public:
1998 static Local<Signature> New(Handle<FunctionTemplate> receiver =
1999 Handle<FunctionTemplate>(),
2000 int argc = 0,
2001 Handle<FunctionTemplate> argv[] = 0);
2002 private:
2003 Signature();
2004};
2005
2006
2007/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002008 * A utility for determining the type of objects based on the template
2009 * they were constructed from.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002010 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002011class V8EXPORT TypeSwitch : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002012 public:
2013 static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
2014 static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
2015 int match(Handle<Value> value);
2016 private:
2017 TypeSwitch();
2018};
2019
2020
2021// --- E x t e n s i o n s ---
2022
2023
2024/**
2025 * Ignore
2026 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002027class V8EXPORT Extension { // NOLINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002028 public:
2029 Extension(const char* name,
2030 const char* source = 0,
2031 int dep_count = 0,
2032 const char** deps = 0);
2033 virtual ~Extension() { }
2034 virtual v8::Handle<v8::FunctionTemplate>
2035 GetNativeFunction(v8::Handle<v8::String> name) {
2036 return v8::Handle<v8::FunctionTemplate>();
2037 }
2038
2039 const char* name() { return name_; }
2040 const char* source() { return source_; }
2041 int dependency_count() { return dep_count_; }
2042 const char** dependencies() { return deps_; }
2043 void set_auto_enable(bool value) { auto_enable_ = value; }
2044 bool auto_enable() { return auto_enable_; }
2045
2046 private:
2047 const char* name_;
2048 const char* source_;
2049 int dep_count_;
2050 const char** deps_;
2051 bool auto_enable_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00002052
2053 // Disallow copying and assigning.
2054 Extension(const Extension&);
2055 void operator=(const Extension&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002056};
2057
2058
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002059void V8EXPORT RegisterExtension(Extension* extension);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002060
2061
2062/**
2063 * Ignore
2064 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002065class V8EXPORT DeclareExtension {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002066 public:
2067 inline DeclareExtension(Extension* extension) {
2068 RegisterExtension(extension);
2069 }
2070};
2071
2072
2073// --- S t a t i c s ---
2074
2075
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002076Handle<Primitive> V8EXPORT Undefined();
2077Handle<Primitive> V8EXPORT Null();
2078Handle<Boolean> V8EXPORT True();
2079Handle<Boolean> V8EXPORT False();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002080
2081
2082/**
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002083 * A set of constraints that specifies the limits of the runtime's memory use.
2084 * You must set the heap size before initializing the VM - the size cannot be
2085 * adjusted after the VM is initialized.
2086 *
2087 * If you are using threads then you should hold the V8::Locker lock while
2088 * setting the stack limit and you must set a non-default stack limit separately
2089 * for each thread.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002090 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002091class V8EXPORT ResourceConstraints {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002092 public:
2093 ResourceConstraints();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002094 int max_young_space_size() const { return max_young_space_size_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002095 void set_max_young_space_size(int value) { max_young_space_size_ = value; }
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002096 int max_old_space_size() const { return max_old_space_size_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002097 void set_max_old_space_size(int value) { max_old_space_size_ = value; }
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002098 uint32_t* stack_limit() const { return stack_limit_; }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002099 // Sets an address beyond which the VM's stack may not grow.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002100 void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
2101 private:
2102 int max_young_space_size_;
2103 int max_old_space_size_;
2104 uint32_t* stack_limit_;
2105};
2106
2107
2108bool SetResourceConstraints(ResourceConstraints* constraints);
2109
2110
2111// --- E x c e p t i o n s ---
2112
2113
2114typedef void (*FatalErrorCallback)(const char* location, const char* message);
2115
2116
2117typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
2118
2119
2120/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002121 * Schedules an exception to be thrown when returning to JavaScript. When an
2122 * exception has been scheduled it is illegal to invoke any JavaScript
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002123 * operation; the caller must return immediately and only after the exception
v8.team.kasperl727e9952008-09-02 14:56:44 +00002124 * has been handled does it become legal to invoke JavaScript operations.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002125 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002126Handle<Value> V8EXPORT ThrowException(Handle<Value> exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002127
2128/**
2129 * Create new error objects by calling the corresponding error object
2130 * constructor with the message.
2131 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002132class V8EXPORT Exception {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002133 public:
2134 static Local<Value> RangeError(Handle<String> message);
2135 static Local<Value> ReferenceError(Handle<String> message);
2136 static Local<Value> SyntaxError(Handle<String> message);
2137 static Local<Value> TypeError(Handle<String> message);
2138 static Local<Value> Error(Handle<String> message);
2139};
2140
2141
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002142// --- C o u n t e r s C a l l b a c k s ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002143
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002144typedef int* (*CounterLookupCallback)(const char* name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002145
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002146typedef void* (*CreateHistogramCallback)(const char* name,
2147 int min,
2148 int max,
2149 size_t buckets);
2150
2151typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
2152
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002153// --- F a i l e d A c c e s s C h e c k C a l l b a c k ---
2154typedef void (*FailedAccessCheckCallback)(Local<Object> target,
2155 AccessType type,
2156 Local<Value> data);
2157
2158// --- G a r b a g e C o l l e c t i o n C a l l b a c k s
2159
2160/**
2161 * Applications can register a callback function which is called
v8.team.kasperl727e9952008-09-02 14:56:44 +00002162 * before and after a major garbage collection. Allocations are not
2163 * allowed in the callback function, you therefore cannot manipulate
2164 * objects (set or delete properties for example) since it is possible
2165 * such operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002166 */
2167typedef void (*GCCallback)();
2168
2169
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002170// --- C o n t e x t G e n e r a t o r ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002171
2172/**
2173 * Applications must provide a callback function which is called to generate
v8.team.kasperl727e9952008-09-02 14:56:44 +00002174 * a context if a context was not deserialized from the snapshot.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002175 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002176typedef Persistent<Context> (*ContextGenerator)();
2177
2178
2179/**
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002180 * Profiler modules.
2181 *
2182 * In V8, profiler consists of several modules: CPU profiler, and different
2183 * kinds of heap profiling. Each can be turned on / off independently.
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +00002184 * When PROFILER_MODULE_HEAP_SNAPSHOT flag is passed to ResumeProfilerEx,
2185 * modules are enabled only temporarily for making a snapshot of the heap.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002186 */
2187enum ProfilerModules {
2188 PROFILER_MODULE_NONE = 0,
2189 PROFILER_MODULE_CPU = 1,
2190 PROFILER_MODULE_HEAP_STATS = 1 << 1,
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +00002191 PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2,
2192 PROFILER_MODULE_HEAP_SNAPSHOT = 1 << 16
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002193};
2194
2195
2196/**
ager@chromium.org3811b432009-10-28 14:53:37 +00002197 * Collection of V8 heap information.
2198 *
2199 * Instances of this class can be passed to v8::V8::HeapStatistics to
2200 * get heap statistics from V8.
2201 */
2202class V8EXPORT HeapStatistics {
2203 public:
2204 HeapStatistics();
2205 size_t total_heap_size() { return total_heap_size_; }
2206 size_t used_heap_size() { return used_heap_size_; }
2207
2208 private:
2209 void set_total_heap_size(size_t size) { total_heap_size_ = size; }
2210 void set_used_heap_size(size_t size) { used_heap_size_ = size; }
2211
2212 size_t total_heap_size_;
2213 size_t used_heap_size_;
2214
2215 friend class V8;
2216};
2217
2218
2219/**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002220 * Container class for static utility functions.
2221 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002222class V8EXPORT V8 {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002223 public:
v8.team.kasperl727e9952008-09-02 14:56:44 +00002224 /** Set the callback to invoke in case of fatal errors. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002225 static void SetFatalErrorHandler(FatalErrorCallback that);
2226
v8.team.kasperl727e9952008-09-02 14:56:44 +00002227 /**
2228 * Ignore out-of-memory exceptions.
2229 *
2230 * V8 running out of memory is treated as a fatal error by default.
2231 * This means that the fatal error handler is called and that V8 is
2232 * terminated.
2233 *
2234 * IgnoreOutOfMemoryException can be used to not treat a
2235 * out-of-memory situation as a fatal error. This way, the contexts
2236 * that did not cause the out of memory problem might be able to
2237 * continue execution.
2238 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002239 static void IgnoreOutOfMemoryException();
2240
v8.team.kasperl727e9952008-09-02 14:56:44 +00002241 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002242 * Check if V8 is dead and therefore unusable. This is the case after
v8.team.kasperl727e9952008-09-02 14:56:44 +00002243 * fatal errors such as out-of-memory situations.
2244 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002245 static bool IsDead();
2246
2247 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002248 * Adds a message listener.
2249 *
2250 * The same message listener can be added more than once and it that
2251 * case it will be called more than once for each message.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002252 */
2253 static bool AddMessageListener(MessageCallback that,
2254 Handle<Value> data = Handle<Value>());
2255
2256 /**
2257 * Remove all message listeners from the specified callback function.
2258 */
2259 static void RemoveMessageListeners(MessageCallback that);
2260
2261 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002262 * Sets V8 flags from a string.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002263 */
2264 static void SetFlagsFromString(const char* str, int length);
2265
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002266 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002267 * Sets V8 flags from the command line.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002268 */
2269 static void SetFlagsFromCommandLine(int* argc,
2270 char** argv,
2271 bool remove_flags);
2272
kasper.lund7276f142008-07-30 08:49:36 +00002273 /** Get the version string. */
2274 static const char* GetVersion();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002275
2276 /**
2277 * Enables the host application to provide a mechanism for recording
2278 * statistics counters.
2279 */
2280 static void SetCounterFunction(CounterLookupCallback);
2281
2282 /**
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002283 * Enables the host application to provide a mechanism for recording
2284 * histograms. The CreateHistogram function returns a
2285 * histogram which will later be passed to the AddHistogramSample
2286 * function.
2287 */
2288 static void SetCreateHistogramFunction(CreateHistogramCallback);
2289 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
2290
2291 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002292 * Enables the computation of a sliding window of states. The sliding
2293 * window information is recorded in statistics counters.
2294 */
2295 static void EnableSlidingStateWindow();
2296
2297 /** Callback function for reporting failed access checks.*/
2298 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
2299
2300 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002301 * Enables the host application to receive a notification before a
2302 * major garbage colletion. Allocations are not allowed in the
2303 * callback function, you therefore cannot manipulate objects (set
2304 * or delete properties for example) since it is possible such
2305 * operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002306 */
2307 static void SetGlobalGCPrologueCallback(GCCallback);
2308
2309 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002310 * Enables the host application to receive a notification after a
2311 * major garbage collection. Allocations are not allowed in the
2312 * callback function, you therefore cannot manipulate objects (set
2313 * or delete properties for example) since it is possible such
2314 * operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002315 */
2316 static void SetGlobalGCEpilogueCallback(GCCallback);
2317
2318 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002319 * Allows the host application to group objects together. If one
2320 * object in the group is alive, all objects in the group are alive.
2321 * After each garbage collection, object groups are removed. It is
2322 * intended to be used in the before-garbage-collection callback
ager@chromium.org8bb60582008-12-11 12:02:20 +00002323 * function, for instance to simulate DOM tree connections among JS
v8.team.kasperl727e9952008-09-02 14:56:44 +00002324 * wrapper objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002325 */
ager@chromium.org8bb60582008-12-11 12:02:20 +00002326 static void AddObjectGroup(Persistent<Value>* objects, size_t length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002327
2328 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002329 * Initializes from snapshot if possible. Otherwise, attempts to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002330 * initialize from scratch. This function is called implicitly if
2331 * you use the API without calling it first.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002332 */
2333 static bool Initialize();
2334
kasper.lund7276f142008-07-30 08:49:36 +00002335 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002336 * Adjusts the amount of registered external memory. Used to give
2337 * V8 an indication of the amount of externally allocated memory
2338 * that is kept alive by JavaScript objects. V8 uses this to decide
2339 * when to perform global garbage collections. Registering
2340 * externally allocated memory will trigger global garbage
2341 * collections more often than otherwise in an attempt to garbage
2342 * collect the JavaScript objects keeping the externally allocated
2343 * memory alive.
2344 *
2345 * \param change_in_bytes the change in externally allocated memory
2346 * that is kept alive by JavaScript objects.
2347 * \returns the adjusted value.
kasper.lund7276f142008-07-30 08:49:36 +00002348 */
2349 static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
2350
iposva@chromium.org245aa852009-02-10 00:49:54 +00002351 /**
2352 * Suspends recording of tick samples in the profiler.
2353 * When the V8 profiling mode is enabled (usually via command line
2354 * switches) this function suspends recording of tick samples.
2355 * Profiling ticks are discarded until ResumeProfiler() is called.
2356 *
2357 * See also the --prof and --prof_auto command line switches to
2358 * enable V8 profiling.
2359 */
2360 static void PauseProfiler();
2361
2362 /**
2363 * Resumes recording of tick samples in the profiler.
2364 * See also PauseProfiler().
2365 */
2366 static void ResumeProfiler();
2367
ager@chromium.org41826e72009-03-30 13:30:57 +00002368 /**
kasperl@chromium.org71affb52009-05-26 05:44:31 +00002369 * Return whether profiler is currently paused.
2370 */
2371 static bool IsProfilerPaused();
2372
2373 /**
ager@chromium.org5c838252010-02-19 08:53:10 +00002374 * Resumes specified profiler modules. Can be called several times to
2375 * mark the opening of a profiler events block with the given tag.
2376 *
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002377 * "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CPU)".
2378 * See ProfilerModules enum.
2379 *
2380 * \param flags Flags specifying profiler modules.
ager@chromium.org5c838252010-02-19 08:53:10 +00002381 * \param tag Profile tag.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002382 */
ager@chromium.org5c838252010-02-19 08:53:10 +00002383 static void ResumeProfilerEx(int flags, int tag = 0);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002384
2385 /**
ager@chromium.org5c838252010-02-19 08:53:10 +00002386 * Pauses specified profiler modules. Each call to "PauseProfilerEx" closes
2387 * a block of profiler events opened by a call to "ResumeProfilerEx" with the
2388 * same tag value. There is no need for blocks to be properly nested.
2389 * The profiler is paused when the last opened block is closed.
2390 *
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002391 * "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)".
2392 * See ProfilerModules enum.
2393 *
2394 * \param flags Flags specifying profiler modules.
ager@chromium.org5c838252010-02-19 08:53:10 +00002395 * \param tag Profile tag.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002396 */
ager@chromium.org5c838252010-02-19 08:53:10 +00002397 static void PauseProfilerEx(int flags, int tag = 0);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002398
2399 /**
2400 * Returns active (resumed) profiler modules.
2401 * See ProfilerModules enum.
2402 *
2403 * \returns active profiler modules.
2404 */
2405 static int GetActiveProfilerModules();
2406
2407 /**
ager@chromium.org9085a012009-05-11 19:22:57 +00002408 * If logging is performed into a memory buffer (via --logfile=*), allows to
2409 * retrieve previously written messages. This can be used for retrieving
2410 * profiler log data in the application. This function is thread-safe.
2411 *
2412 * Caller provides a destination buffer that must exist during GetLogLines
2413 * call. Only whole log lines are copied into the buffer.
2414 *
2415 * \param from_pos specified a point in a buffer to read from, 0 is the
2416 * beginning of a buffer. It is assumed that caller updates its current
2417 * position using returned size value from the previous call.
2418 * \param dest_buf destination buffer for log data.
2419 * \param max_size size of the destination buffer.
2420 * \returns actual size of log data copied into buffer.
2421 */
2422 static int GetLogLines(int from_pos, char* dest_buf, int max_size);
2423
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00002424 /**
2425 * Retrieve the V8 thread id of the calling thread.
2426 *
2427 * The thread id for a thread should only be retrieved after the V8
2428 * lock has been acquired with a Locker object with that thread.
2429 */
2430 static int GetCurrentThreadId();
2431
2432 /**
2433 * Forcefully terminate execution of a JavaScript thread. This can
2434 * be used to terminate long-running scripts.
2435 *
2436 * TerminateExecution should only be called when then V8 lock has
2437 * been acquired with a Locker object. Therefore, in order to be
2438 * able to terminate long-running threads, preemption must be
2439 * enabled to allow the user of TerminateExecution to acquire the
2440 * lock.
2441 *
2442 * The termination is achieved by throwing an exception that is
2443 * uncatchable by JavaScript exception handlers. Termination
2444 * exceptions act as if they were caught by a C++ TryCatch exception
2445 * handlers. If forceful termination is used, any C++ TryCatch
2446 * exception handler that catches an exception should check if that
2447 * exception is a termination exception and immediately return if
2448 * that is the case. Returning immediately in that case will
2449 * continue the propagation of the termination exception if needed.
2450 *
2451 * The thread id passed to TerminateExecution must have been
2452 * obtained by calling GetCurrentThreadId on the thread in question.
2453 *
2454 * \param thread_id The thread id of the thread to terminate.
2455 */
2456 static void TerminateExecution(int thread_id);
2457
2458 /**
2459 * Forcefully terminate the current thread of JavaScript execution.
2460 *
2461 * This method can be used by any thread even if that thread has not
2462 * acquired the V8 lock with a Locker object.
2463 */
2464 static void TerminateExecution();
ager@chromium.org9085a012009-05-11 19:22:57 +00002465
2466 /**
sgjesse@chromium.org2ab99522010-03-10 09:03:43 +00002467 * Is V8 terminating JavaScript execution.
2468 *
2469 * Returns true if JavaScript execution is currently terminating
2470 * because of a call to TerminateExecution. In that case there are
2471 * still JavaScript frames on the stack and the termination
2472 * exception is still active.
2473 */
2474 static bool IsExecutionTerminating();
2475
2476 /**
ager@chromium.org41826e72009-03-30 13:30:57 +00002477 * Releases any resources used by v8 and stops any utility threads
2478 * that may be running. Note that disposing v8 is permanent, it
2479 * cannot be reinitialized.
2480 *
2481 * It should generally not be necessary to dispose v8 before exiting
2482 * a process, this should happen automatically. It is only necessary
2483 * to use if the process needs the resources taken up by v8.
2484 */
2485 static bool Dispose();
2486
ager@chromium.org3811b432009-10-28 14:53:37 +00002487 /**
2488 * Get statistics about the heap memory usage.
2489 */
2490 static void GetHeapStatistics(HeapStatistics* heap_statistics);
ager@chromium.orgadd848f2009-08-13 12:44:13 +00002491
2492 /**
2493 * Optional notification that the embedder is idle.
2494 * V8 uses the notification to reduce memory footprint.
ager@chromium.orgab99eea2009-08-25 07:05:41 +00002495 * This call can be used repeatedly if the embedder remains idle.
ager@chromium.orgab99eea2009-08-25 07:05:41 +00002496 * Returns true if the embedder should stop calling IdleNotification
2497 * until real work has been done. This indicates that V8 has done
2498 * as much cleanup as it will be able to do.
ager@chromium.orgadd848f2009-08-13 12:44:13 +00002499 */
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002500 static bool IdleNotification();
ager@chromium.orgadd848f2009-08-13 12:44:13 +00002501
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00002502 /**
2503 * Optional notification that the system is running low on memory.
2504 * V8 uses these notifications to attempt to free memory.
2505 */
2506 static void LowMemoryNotification();
2507
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00002508 /**
2509 * Optional notification that a context has been disposed. V8 uses
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00002510 * these notifications to guide the GC heuristic. Returns the number
2511 * of context disposals - including this one - since the last time
2512 * V8 had a chance to clean up.
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00002513 */
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00002514 static int ContextDisposedNotification();
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00002515
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002516 private:
2517 V8();
2518
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002519 static internal::Object** GlobalizeReference(internal::Object** handle);
2520 static void DisposeGlobal(internal::Object** global_handle);
2521 static void MakeWeak(internal::Object** global_handle,
2522 void* data,
2523 WeakReferenceCallback);
2524 static void ClearWeak(internal::Object** global_handle);
2525 static bool IsGlobalNearDeath(internal::Object** global_handle);
2526 static bool IsGlobalWeak(internal::Object** global_handle);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002527
2528 template <class T> friend class Handle;
2529 template <class T> friend class Local;
2530 template <class T> friend class Persistent;
2531 friend class Context;
2532};
2533
2534
2535/**
2536 * An external exception handler.
2537 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002538class V8EXPORT TryCatch {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002539 public:
2540
2541 /**
2542 * Creates a new try/catch block and registers it with v8.
2543 */
2544 TryCatch();
2545
2546 /**
2547 * Unregisters and deletes this try/catch block.
2548 */
2549 ~TryCatch();
2550
2551 /**
2552 * Returns true if an exception has been caught by this try/catch block.
2553 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002554 bool HasCaught() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002555
2556 /**
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00002557 * For certain types of exceptions, it makes no sense to continue
2558 * execution.
2559 *
2560 * Currently, the only type of exception that can be caught by a
2561 * TryCatch handler and for which it does not make sense to continue
2562 * is termination exception. Such exceptions are thrown when the
2563 * TerminateExecution methods are called to terminate a long-running
2564 * script.
2565 *
2566 * If CanContinue returns false, the correct action is to perform
2567 * any C++ cleanup needed and then return.
2568 */
2569 bool CanContinue() const;
2570
2571 /**
christian.plesner.hansen@gmail.comb9ce6372009-11-03 11:38:18 +00002572 * Throws the exception caught by this TryCatch in a way that avoids
2573 * it being caught again by this same TryCatch. As with ThrowException
2574 * it is illegal to execute any JavaScript operations after calling
2575 * ReThrow; the caller must return immediately to where the exception
2576 * is caught.
2577 */
2578 Handle<Value> ReThrow();
2579
2580 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002581 * Returns the exception caught by this try/catch block. If no exception has
2582 * been caught an empty handle is returned.
2583 *
2584 * The returned handle is valid until this TryCatch block has been destroyed.
2585 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002586 Local<Value> Exception() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002587
2588 /**
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00002589 * Returns the .stack property of the thrown object. If no .stack
2590 * property is present an empty handle is returned.
2591 */
2592 Local<Value> StackTrace() const;
2593
2594 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002595 * Returns the message associated with this exception. If there is
2596 * no message associated an empty handle is returned.
2597 *
2598 * The returned handle is valid until this TryCatch block has been
2599 * destroyed.
2600 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002601 Local<v8::Message> Message() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002602
2603 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002604 * Clears any exceptions that may have been caught by this try/catch block.
2605 * After this method has been called, HasCaught() will return false.
2606 *
2607 * It is not necessary to clear a try/catch block before using it again; if
2608 * another exception is thrown the previously caught exception will just be
2609 * overwritten. However, it is often a good idea since it makes it easier
2610 * to determine which operation threw a given exception.
2611 */
2612 void Reset();
2613
v8.team.kasperl727e9952008-09-02 14:56:44 +00002614 /**
2615 * Set verbosity of the external exception handler.
2616 *
2617 * By default, exceptions that are caught by an external exception
2618 * handler are not reported. Call SetVerbose with true on an
2619 * external exception handler to have exceptions caught by the
2620 * handler reported as if they were not caught.
2621 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002622 void SetVerbose(bool value);
2623
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002624 /**
2625 * Set whether or not this TryCatch should capture a Message object
2626 * which holds source information about where the exception
2627 * occurred. True by default.
2628 */
2629 void SetCaptureMessage(bool value);
2630
ager@chromium.orgc4c92722009-11-18 14:12:51 +00002631 private:
2632 void* next_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002633 void* exception_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002634 void* message_;
christian.plesner.hansen@gmail.comb9ce6372009-11-03 11:38:18 +00002635 bool is_verbose_ : 1;
2636 bool can_continue_ : 1;
2637 bool capture_message_ : 1;
2638 bool rethrow_ : 1;
ager@chromium.orgc4c92722009-11-18 14:12:51 +00002639
2640 friend class v8::internal::Top;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002641};
2642
2643
2644// --- C o n t e x t ---
2645
2646
2647/**
2648 * Ignore
2649 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002650class V8EXPORT ExtensionConfiguration {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002651 public:
2652 ExtensionConfiguration(int name_count, const char* names[])
2653 : name_count_(name_count), names_(names) { }
2654 private:
2655 friend class ImplementationUtilities;
2656 int name_count_;
2657 const char** names_;
2658};
2659
2660
2661/**
2662 * A sandboxed execution context with its own set of built-in objects
2663 * and functions.
2664 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002665class V8EXPORT Context {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002666 public:
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002667 /** Returns the global object of the context. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002668 Local<Object> Global();
2669
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002670 /**
2671 * Detaches the global object from its context before
2672 * the global object can be reused to create a new context.
2673 */
2674 void DetachGlobal();
2675
v8.team.kasperl727e9952008-09-02 14:56:44 +00002676 /** Creates a new context. */
2677 static Persistent<Context> New(
2678 ExtensionConfiguration* extensions = 0,
2679 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
2680 Handle<Value> global_object = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002681
kasper.lund44510672008-07-25 07:37:58 +00002682 /** Returns the last entered context. */
2683 static Local<Context> GetEntered();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002684
kasper.lund44510672008-07-25 07:37:58 +00002685 /** Returns the context that is on the top of the stack. */
2686 static Local<Context> GetCurrent();
2687
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002688 /**
ager@chromium.org1bf0cd02009-05-20 11:34:19 +00002689 * Returns the context of the calling JavaScript code. That is the
2690 * context of the top-most JavaScript frame. If there are no
2691 * JavaScript frames an empty handle is returned.
2692 */
2693 static Local<Context> GetCalling();
2694
2695 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002696 * Sets the security token for the context. To access an object in
2697 * another context, the security tokens must match.
2698 */
2699 void SetSecurityToken(Handle<Value> token);
2700
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002701 /** Restores the security token to the default value. */
2702 void UseDefaultSecurityToken();
2703
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002704 /** Returns the security token of this context.*/
2705 Handle<Value> GetSecurityToken();
2706
v8.team.kasperl727e9952008-09-02 14:56:44 +00002707 /**
2708 * Enter this context. After entering a context, all code compiled
2709 * and run is compiled and run in this context. If another context
2710 * is already entered, this old context is saved so it can be
2711 * restored when the new context is exited.
2712 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002713 void Enter();
v8.team.kasperl727e9952008-09-02 14:56:44 +00002714
2715 /**
2716 * Exit this context. Exiting the current context restores the
2717 * context that was in place when entering the current context.
2718 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002719 void Exit();
2720
v8.team.kasperl727e9952008-09-02 14:56:44 +00002721 /** Returns true if the context has experienced an out of memory situation. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002722 bool HasOutOfMemoryException();
2723
v8.team.kasperl727e9952008-09-02 14:56:44 +00002724 /** Returns true if V8 has a current context. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002725 static bool InContext();
2726
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002727 /**
ager@chromium.org9085a012009-05-11 19:22:57 +00002728 * Associate an additional data object with the context. This is mainly used
2729 * with the debugger to provide additional information on the context through
2730 * the debugger API.
2731 */
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +00002732 void SetData(Handle<String> data);
ager@chromium.org9085a012009-05-11 19:22:57 +00002733 Local<Value> GetData();
2734
2735 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002736 * Stack-allocated class which sets the execution context for all
2737 * operations executed within a local scope.
2738 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002739 class V8EXPORT Scope {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002740 public:
2741 inline Scope(Handle<Context> context) : context_(context) {
2742 context_->Enter();
2743 }
2744 inline ~Scope() { context_->Exit(); }
2745 private:
2746 Handle<Context> context_;
2747 };
2748
2749 private:
2750 friend class Value;
2751 friend class Script;
2752 friend class Object;
2753 friend class Function;
2754};
2755
2756
2757/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002758 * Multiple threads in V8 are allowed, but only one thread at a time
2759 * is allowed to use V8. The definition of 'using V8' includes
2760 * accessing handles or holding onto object pointers obtained from V8
2761 * handles. It is up to the user of V8 to ensure (perhaps with
2762 * locking) that this constraint is not violated.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002763 *
2764 * If you wish to start using V8 in a thread you can do this by constructing
2765 * a v8::Locker object. After the code using V8 has completed for the
2766 * current thread you can call the destructor. This can be combined
2767 * with C++ scope-based construction as follows:
2768 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002769 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002770 * ...
2771 * {
2772 * v8::Locker locker;
2773 * ...
2774 * // Code using V8 goes here.
2775 * ...
2776 * } // Destructor called here
v8.team.kasperl727e9952008-09-02 14:56:44 +00002777 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002778 *
2779 * If you wish to stop using V8 in a thread A you can do this by either
2780 * by destroying the v8::Locker object as above or by constructing a
2781 * v8::Unlocker object:
2782 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002783 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002784 * {
2785 * v8::Unlocker unlocker;
2786 * ...
2787 * // Code not using V8 goes here while V8 can run in another thread.
2788 * ...
2789 * } // Destructor called here.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002790 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002791 *
2792 * The Unlocker object is intended for use in a long-running callback
2793 * from V8, where you want to release the V8 lock for other threads to
2794 * use.
2795 *
2796 * The v8::Locker is a recursive lock. That is, you can lock more than
2797 * once in a given thread. This can be useful if you have code that can
2798 * be called either from code that holds the lock or from code that does
2799 * not. The Unlocker is not recursive so you can not have several
2800 * Unlockers on the stack at once, and you can not use an Unlocker in a
2801 * thread that is not inside a Locker's scope.
2802 *
2803 * An unlocker will unlock several lockers if it has to and reinstate
2804 * the correct depth of locking on its destruction. eg.:
2805 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002806 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002807 * // V8 not locked.
2808 * {
2809 * v8::Locker locker;
2810 * // V8 locked.
2811 * {
2812 * v8::Locker another_locker;
2813 * // V8 still locked (2 levels).
2814 * {
2815 * v8::Unlocker unlocker;
2816 * // V8 not locked.
2817 * }
2818 * // V8 locked again (2 levels).
2819 * }
2820 * // V8 still locked (1 level).
2821 * }
2822 * // V8 Now no longer locked.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002823 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002824 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002825class V8EXPORT Unlocker {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002826 public:
2827 Unlocker();
2828 ~Unlocker();
2829};
2830
2831
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002832class V8EXPORT Locker {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002833 public:
2834 Locker();
2835 ~Locker();
v8.team.kasperl727e9952008-09-02 14:56:44 +00002836
2837 /**
2838 * Start preemption.
2839 *
2840 * When preemption is started, a timer is fired every n milli seconds
2841 * that will switch between multiple threads that are in contention
2842 * for the V8 lock.
2843 */
2844 static void StartPreemption(int every_n_ms);
2845
2846 /**
2847 * Stop preemption.
2848 */
2849 static void StopPreemption();
2850
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002851 /**
2852 * Returns whether or not the locker is locked by the current thread.
2853 */
2854 static bool IsLocked();
2855
ager@chromium.orgddb913d2009-01-27 10:01:48 +00002856 /**
2857 * Returns whether v8::Locker is being used by this V8 instance.
2858 */
2859 static bool IsActive() { return active_; }
2860
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002861 private:
2862 bool has_lock_;
2863 bool top_level_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00002864
ager@chromium.orgddb913d2009-01-27 10:01:48 +00002865 static bool active_;
2866
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00002867 // Disallow copying and assigning.
2868 Locker(const Locker&);
2869 void operator=(const Locker&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002870};
2871
2872
2873
2874// --- I m p l e m e n t a t i o n ---
2875
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002876
2877namespace internal {
2878
2879
2880// Tag information for HeapObject.
2881const int kHeapObjectTag = 1;
2882const int kHeapObjectTagSize = 2;
2883const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
2884
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002885// Tag information for Smi.
2886const int kSmiTag = 0;
2887const int kSmiTagSize = 1;
2888const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
2889
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002890template <size_t ptr_size> struct SmiConstants;
2891
2892// Smi constants for 32-bit systems.
2893template <> struct SmiConstants<4> {
2894 static const int kSmiShiftSize = 0;
2895 static const int kSmiValueSize = 31;
2896 static inline int SmiToInt(internal::Object* value) {
2897 int shift_bits = kSmiTagSize + kSmiShiftSize;
2898 // Throw away top 32 bits and shift down (requires >> to be sign extending).
2899 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
2900 }
2901};
2902
2903// Smi constants for 64-bit systems.
2904template <> struct SmiConstants<8> {
2905 static const int kSmiShiftSize = 31;
2906 static const int kSmiValueSize = 32;
2907 static inline int SmiToInt(internal::Object* value) {
2908 int shift_bits = kSmiTagSize + kSmiShiftSize;
2909 // Shift down and throw away top 32 bits.
2910 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
2911 }
2912};
2913
2914const int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize;
2915const int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002916
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00002917template <size_t ptr_size> struct InternalConstants;
2918
2919// Internal constants for 32-bit systems.
2920template <> struct InternalConstants<4> {
2921 static const int kStringResourceOffset = 3 * sizeof(void*);
2922};
2923
2924// Internal constants for 64-bit systems.
2925template <> struct InternalConstants<8> {
2926 static const int kStringResourceOffset = 2 * sizeof(void*);
2927};
2928
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002929/**
2930 * This class exports constants and functionality from within v8 that
2931 * is necessary to implement inline functions in the v8 api. Don't
2932 * depend on functions and constants defined here.
2933 */
2934class Internals {
2935 public:
2936
2937 // These values match non-compiler-dependent values defined within
2938 // the implementation of v8.
2939 static const int kHeapObjectMapOffset = 0;
2940 static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int);
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00002941 static const int kStringResourceOffset =
2942 InternalConstants<sizeof(void*)>::kStringResourceOffset;
2943
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002944 static const int kProxyProxyOffset = sizeof(void*);
2945 static const int kJSObjectHeaderSize = 3 * sizeof(void*);
2946 static const int kFullStringRepresentationMask = 0x07;
2947 static const int kExternalTwoByteRepresentationTag = 0x03;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002948
2949 // These constants are compiler dependent so their values must be
2950 // defined within the implementation.
ager@chromium.org4af710e2009-09-15 12:20:11 +00002951 V8EXPORT static int kJSObjectType;
2952 V8EXPORT static int kFirstNonstringType;
2953 V8EXPORT static int kProxyType;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002954
2955 static inline bool HasHeapObjectTag(internal::Object* value) {
2956 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
2957 kHeapObjectTag);
2958 }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002959
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002960 static inline bool HasSmiTag(internal::Object* value) {
2961 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
2962 }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002963
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002964 static inline int SmiValue(internal::Object* value) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002965 return SmiConstants<sizeof(void*)>::SmiToInt(value);
2966 }
2967
2968 static inline int GetInstanceType(internal::Object* obj) {
2969 typedef internal::Object O;
2970 O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
2971 return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
2972 }
2973
2974 static inline void* GetExternalPointer(internal::Object* obj) {
2975 if (HasSmiTag(obj)) {
2976 return obj;
2977 } else if (GetInstanceType(obj) == kProxyType) {
2978 return ReadField<void*>(obj, kProxyProxyOffset);
2979 } else {
2980 return NULL;
2981 }
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002982 }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002983
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002984 static inline bool IsExternalTwoByteString(int instance_type) {
2985 int representation = (instance_type & kFullStringRepresentationMask);
2986 return representation == kExternalTwoByteRepresentationTag;
2987 }
2988
2989 template <typename T>
2990 static inline T ReadField(Object* ptr, int offset) {
2991 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
2992 return *reinterpret_cast<T*>(addr);
2993 }
2994
2995};
2996
2997}
2998
2999
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003000template <class T>
3001Handle<T>::Handle() : val_(0) { }
3002
3003
3004template <class T>
3005Local<T>::Local() : Handle<T>() { }
3006
3007
3008template <class T>
3009Local<T> Local<T>::New(Handle<T> that) {
3010 if (that.IsEmpty()) return Local<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003011 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003012 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
3013}
3014
3015
3016template <class T>
3017Persistent<T> Persistent<T>::New(Handle<T> that) {
3018 if (that.IsEmpty()) return Persistent<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003019 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003020 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
3021}
3022
3023
3024template <class T>
ager@chromium.org32912102009-01-16 10:38:43 +00003025bool Persistent<T>::IsNearDeath() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003026 if (this->IsEmpty()) return false;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003027 return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003028}
3029
3030
3031template <class T>
ager@chromium.org32912102009-01-16 10:38:43 +00003032bool Persistent<T>::IsWeak() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003033 if (this->IsEmpty()) return false;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003034 return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003035}
3036
3037
3038template <class T>
3039void Persistent<T>::Dispose() {
3040 if (this->IsEmpty()) return;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003041 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003042}
3043
3044
3045template <class T>
3046Persistent<T>::Persistent() : Handle<T>() { }
3047
3048template <class T>
3049void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003050 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
3051 parameters,
3052 callback);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003053}
3054
3055template <class T>
3056void Persistent<T>::ClearWeak() {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003057 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003058}
3059
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003060Local<Value> Arguments::operator[](int i) const {
3061 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
3062 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
3063}
3064
3065
3066Local<Function> Arguments::Callee() const {
3067 return callee_;
3068}
3069
3070
3071Local<Object> Arguments::This() const {
3072 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
3073}
3074
3075
3076Local<Object> Arguments::Holder() const {
3077 return holder_;
3078}
3079
3080
3081Local<Value> Arguments::Data() const {
3082 return data_;
3083}
3084
3085
3086bool Arguments::IsConstructCall() const {
3087 return is_construct_call_;
3088}
3089
3090
3091int Arguments::Length() const {
3092 return length_;
3093}
3094
3095
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003096template <class T>
3097Local<T> HandleScope::Close(Handle<T> value) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003098 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
3099 internal::Object** after = RawClose(before);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003100 return Local<T>(reinterpret_cast<T*>(after));
3101}
3102
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003103Handle<Value> ScriptOrigin::ResourceName() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003104 return resource_name_;
3105}
3106
3107
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003108Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003109 return resource_line_offset_;
3110}
3111
3112
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003113Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003114 return resource_column_offset_;
3115}
3116
3117
3118Handle<Boolean> Boolean::New(bool value) {
3119 return value ? True() : False();
3120}
3121
3122
3123void Template::Set(const char* name, v8::Handle<Data> value) {
3124 Set(v8::String::New(name), value);
3125}
3126
3127
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003128Local<Value> Object::GetInternalField(int index) {
3129#ifndef V8_ENABLE_CHECKS
3130 Local<Value> quick_result = UncheckedGetInternalField(index);
3131 if (!quick_result.IsEmpty()) return quick_result;
3132#endif
3133 return CheckedGetInternalField(index);
3134}
3135
3136
3137Local<Value> Object::UncheckedGetInternalField(int index) {
3138 typedef internal::Object O;
3139 typedef internal::Internals I;
3140 O* obj = *reinterpret_cast<O**>(this);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00003141 if (I::GetInstanceType(obj) == I::kJSObjectType) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003142 // If the object is a plain JSObject, which is the common case,
3143 // we know where to find the internal fields and can return the
3144 // value directly.
3145 int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index);
3146 O* value = I::ReadField<O*>(obj, offset);
3147 O** result = HandleScope::CreateHandle(value);
3148 return Local<Value>(reinterpret_cast<Value*>(result));
3149 } else {
3150 return Local<Value>();
3151 }
3152}
3153
3154
3155void* External::Unwrap(Handle<v8::Value> obj) {
3156#ifdef V8_ENABLE_CHECKS
3157 return FullUnwrap(obj);
3158#else
3159 return QuickUnwrap(obj);
3160#endif
3161}
3162
3163
3164void* External::QuickUnwrap(Handle<v8::Value> wrapper) {
3165 typedef internal::Object O;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003166 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00003167 return internal::Internals::GetExternalPointer(obj);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003168}
3169
3170
3171void* Object::GetPointerFromInternalField(int index) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00003172 typedef internal::Object O;
3173 typedef internal::Internals I;
3174
3175 O* obj = *reinterpret_cast<O**>(this);
3176
3177 if (I::GetInstanceType(obj) == I::kJSObjectType) {
3178 // If the object is a plain JSObject, which is the common case,
3179 // we know where to find the internal fields and can return the
3180 // value directly.
3181 int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index);
3182 O* value = I::ReadField<O*>(obj, offset);
3183 return I::GetExternalPointer(value);
3184 }
3185
3186 return SlowGetPointerFromInternalField(index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003187}
3188
3189
3190String* String::Cast(v8::Value* value) {
3191#ifdef V8_ENABLE_CHECKS
3192 CheckCast(value);
3193#endif
3194 return static_cast<String*>(value);
3195}
3196
3197
3198String::ExternalStringResource* String::GetExternalStringResource() const {
3199 typedef internal::Object O;
3200 typedef internal::Internals I;
3201 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003202 String::ExternalStringResource* result;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00003203 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003204 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
3205 result = reinterpret_cast<String::ExternalStringResource*>(value);
3206 } else {
3207 result = NULL;
3208 }
3209#ifdef V8_ENABLE_CHECKS
3210 VerifyExternalStringResource(result);
3211#endif
3212 return result;
3213}
3214
3215
3216bool Value::IsString() const {
3217#ifdef V8_ENABLE_CHECKS
3218 return FullIsString();
3219#else
3220 return QuickIsString();
3221#endif
3222}
3223
3224bool Value::QuickIsString() const {
3225 typedef internal::Object O;
3226 typedef internal::Internals I;
3227 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
3228 if (!I::HasHeapObjectTag(obj)) return false;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00003229 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00003230}
3231
3232
3233Number* Number::Cast(v8::Value* value) {
3234#ifdef V8_ENABLE_CHECKS
3235 CheckCast(value);
3236#endif
3237 return static_cast<Number*>(value);
3238}
3239
3240
3241Integer* Integer::Cast(v8::Value* value) {
3242#ifdef V8_ENABLE_CHECKS
3243 CheckCast(value);
3244#endif
3245 return static_cast<Integer*>(value);
3246}
3247
3248
3249Date* Date::Cast(v8::Value* value) {
3250#ifdef V8_ENABLE_CHECKS
3251 CheckCast(value);
3252#endif
3253 return static_cast<Date*>(value);
3254}
3255
3256
3257Object* Object::Cast(v8::Value* value) {
3258#ifdef V8_ENABLE_CHECKS
3259 CheckCast(value);
3260#endif
3261 return static_cast<Object*>(value);
3262}
3263
3264
3265Array* Array::Cast(v8::Value* value) {
3266#ifdef V8_ENABLE_CHECKS
3267 CheckCast(value);
3268#endif
3269 return static_cast<Array*>(value);
3270}
3271
3272
3273Function* Function::Cast(v8::Value* value) {
3274#ifdef V8_ENABLE_CHECKS
3275 CheckCast(value);
3276#endif
3277 return static_cast<Function*>(value);
3278}
3279
3280
3281External* External::Cast(v8::Value* value) {
3282#ifdef V8_ENABLE_CHECKS
3283 CheckCast(value);
3284#endif
3285 return static_cast<External*>(value);
3286}
3287
3288
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00003289Local<Value> AccessorInfo::Data() const {
3290 return Local<Value>(reinterpret_cast<Value*>(&args_[-3]));
3291}
3292
3293
3294Local<Object> AccessorInfo::This() const {
3295 return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
3296}
3297
3298
3299Local<Object> AccessorInfo::Holder() const {
3300 return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
3301}
3302
3303
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003304/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003305 * \example shell.cc
3306 * A simple shell that takes a list of expressions on the
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003307 * command-line and executes them.
3308 */
3309
3310
3311/**
3312 * \example process.cc
3313 */
3314
3315
3316} // namespace v8
3317
3318
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003319#undef V8EXPORT
3320#undef V8EXPORT_INLINE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003321#undef TYPE_CHECK
3322
3323
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003324#endif // V8_H_