blob: 9adb1c041cf20bd2ed12d7a04dfe07c53cd1712b [file] [log] [blame]
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00001// Copyright 2012 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
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +000041#include "v8stdint.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000042
43#ifdef _WIN32
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000044
45// Setup for Windows DLL export/import. When building the V8 DLL the
46// BUILDING_V8_SHARED needs to be defined. When building a program which uses
47// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
48// static library or building a program which uses the V8 static library neither
49// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000050#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
51#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
52 build configuration to ensure that at most one of these is set
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000053#endif
54
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000055#ifdef BUILDING_V8_SHARED
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000056#define V8EXPORT __declspec(dllexport)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000057#elif USING_V8_SHARED
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000058#define V8EXPORT __declspec(dllimport)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000059#else
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000060#define V8EXPORT
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000061#endif // BUILDING_V8_SHARED
62
63#else // _WIN32
ager@chromium.org9085a012009-05-11 19:22:57 +000064
ulan@chromium.orgd6899c32012-05-18 14:12:25 +000065// Setup for Linux shared library export.
verwaest@chromium.orgb6d052d2012-07-27 08:03:27 +000066#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
67 (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
ulan@chromium.orgd6899c32012-05-18 14:12:25 +000068#ifdef BUILDING_V8_SHARED
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000069#define V8EXPORT __attribute__ ((visibility("default")))
ulan@chromium.orgd6899c32012-05-18 14:12:25 +000070#else
71#define V8EXPORT
72#endif
verwaest@chromium.orgb6d052d2012-07-27 08:03:27 +000073#else
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000074#define V8EXPORT
verwaest@chromium.orgb6d052d2012-07-27 08:03:27 +000075#endif
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000076
77#endif // _WIN32
78
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +000079#if defined(__GNUC__) && !defined(DEBUG)
80#define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator
81#elif defined(_MSC_VER) && !defined(DEBUG)
82#define V8_INLINE(declarator) __forceinline declarator
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +000083#else
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +000084#define V8_INLINE(declarator) inline declarator
85#endif
86
87#if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS
88#define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated))
89#elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS
90#define V8_DEPRECATED(declarator) __declspec(deprecated) declarator
91#else
92#define V8_DEPRECATED(declarator) declarator
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +000093#endif
94
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000095/**
v8.team.kasperl727e9952008-09-02 14:56:44 +000096 * The v8 JavaScript engine.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000097 */
98namespace v8 {
99
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000100class AccessorInfo;
101class AccessorSignature;
102class Array;
103class Boolean;
104class BooleanObject;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000105class Context;
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000106class CpuProfiler;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000107class Data;
108class Date;
109class DeclaredAccessorDescriptor;
110class External;
111class Function;
112class FunctionTemplate;
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000113class HeapProfiler;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000114class ImplementationUtilities;
115class Int32;
116class Integer;
117class Isolate;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000118class Number;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000119class NumberObject;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000120class Object;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000121class ObjectOperationDescriptor;
122class ObjectTemplate;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000123class Primitive;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000124class RawOperationDescriptor;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000125class Signature;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000126class StackFrame;
127class StackTrace;
128class String;
129class StringObject;
130class Uint32;
131class Utils;
132class Value;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000133template <class T> class Handle;
134template <class T> class Local;
135template <class T> class Persistent;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000136
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000137namespace internal {
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000138class Arguments;
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000139class Heap;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000140class HeapObject;
141class Isolate;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000142class Object;
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000143}
144
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000145
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000146// --- Weak Handles ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000147
148
149/**
150 * A weak reference callback function.
151 *
fschneider@chromium.orged78ffd2010-07-21 11:05:19 +0000152 * This callback should either explicitly invoke Dispose on |object| if
153 * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak.
154 *
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000155 * \param object the weak global object to be reclaimed by the garbage collector
156 * \param parameter the value passed in when making the weak global object
157 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000158typedef void (*WeakReferenceCallback)(Persistent<Value> object,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000159 void* parameter);
160
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000161// TODO(svenpanne) Temporary definition until Chrome is in sync.
162typedef void (*NearDeathCallback)(Isolate* isolate,
163 Persistent<Value> object,
164 void* parameter);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000165
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000166// --- Handles ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000167
fschneider@chromium.orged78ffd2010-07-21 11:05:19 +0000168#define TYPE_CHECK(T, S) \
169 while (false) { \
170 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000171 }
172
173/**
174 * An object reference managed by the v8 garbage collector.
175 *
176 * All objects returned from v8 have to be tracked by the garbage
177 * collector so that it knows that the objects are still alive. Also,
178 * because the garbage collector may move objects, it is unsafe to
179 * point directly to an object. Instead, all objects are stored in
180 * handles which are known by the garbage collector and updated
181 * whenever an object moves. Handles should always be passed by value
182 * (except in cases like out-parameters) and they should never be
183 * allocated on the heap.
184 *
185 * There are two types of handles: local and persistent handles.
186 * Local handles are light-weight and transient and typically used in
187 * local operations. They are managed by HandleScopes. Persistent
188 * handles can be used when storing objects across several independent
189 * operations and have to be explicitly deallocated when they're no
190 * longer used.
191 *
192 * It is safe to extract the object stored in the handle by
193 * dereferencing the handle (for instance, to extract the Object* from
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000194 * a Handle<Object>); the value will still be governed by a handle
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000195 * behind the scenes and the same rules apply to these values as to
196 * their handles.
197 */
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000198template <class T> class Handle {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000199 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000200 /**
201 * Creates an empty handle.
202 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000203 V8_INLINE(Handle()) : val_(0) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000204
205 /**
206 * Creates a new handle for the specified value.
207 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000208 V8_INLINE(explicit Handle(T* val)) : val_(val) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000209
210 /**
211 * Creates a handle for the contents of the specified handle. This
212 * constructor allows you to pass handles as arguments by value and
v8.team.kasperl727e9952008-09-02 14:56:44 +0000213 * to assign between handles. However, if you try to assign between
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000214 * incompatible handles, for instance from a Handle<String> to a
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000215 * Handle<Number> it will cause a compile-time error. Assigning
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000216 * between compatible handles, for instance assigning a
217 * Handle<String> to a variable declared as Handle<Value>, is legal
218 * because String is a subclass of Value.
219 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000220 template <class S> V8_INLINE(Handle(Handle<S> that))
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000221 : val_(reinterpret_cast<T*>(*that)) {
222 /**
223 * This check fails when trying to convert between incompatible
224 * handles. For example, converting from a Handle<String> to a
225 * Handle<Number>.
226 */
227 TYPE_CHECK(T, S);
228 }
229
230 /**
231 * Returns true if the handle is empty.
232 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000233 V8_INLINE(bool IsEmpty() const) { return val_ == 0; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000234
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000235 /**
236 * Sets the handle to be empty. IsEmpty() will then return true.
237 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000238 V8_INLINE(void Clear()) { val_ = 0; }
danno@chromium.orgb6451162011-08-17 14:33:23 +0000239
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000240 V8_INLINE(T* operator->() const) { return val_; }
danno@chromium.orgb6451162011-08-17 14:33:23 +0000241
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000242 V8_INLINE(T* operator*() const) { return val_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000243
244 /**
245 * Checks whether two handles are the same.
246 * Returns true if both are empty, or if the objects
247 * to which they refer are identical.
248 * The handles' references are not checked.
249 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000250 template <class S> V8_INLINE(bool operator==(Handle<S> that) const) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000251 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
252 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000253 if (a == 0) return b == 0;
254 if (b == 0) return false;
255 return *a == *b;
256 }
257
258 /**
259 * Checks whether two handles are different.
260 * Returns true if only one of the handles is empty, or if
261 * the objects to which they refer are different.
262 * The handles' references are not checked.
263 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000264 template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000265 return !operator==(that);
266 }
267
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000268 template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000269#ifdef V8_ENABLE_CHECKS
270 // If we're going to perform the type check then we have to check
271 // that the handle isn't empty before doing the checked cast.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000272 if (that.IsEmpty()) return Handle<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000273#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000274 return Handle<T>(T::Cast(*that));
275 }
276
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000277 template <class S> V8_INLINE(Handle<S> As()) {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000278 return Handle<S>::Cast(*this);
279 }
280
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000281 private:
282 T* val_;
283};
284
285
286/**
287 * A light-weight stack-allocated object handle. All operations
288 * that return objects from within v8 return them in local handles. They
289 * are created within HandleScopes, and all local handles allocated within a
290 * handle scope are destroyed when the handle scope is destroyed. Hence it
291 * is not necessary to explicitly deallocate local handles.
292 */
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000293template <class T> class Local : public Handle<T> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000294 public:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000295 V8_INLINE(Local());
296 template <class S> V8_INLINE(Local(Local<S> that))
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000297 : Handle<T>(reinterpret_cast<T*>(*that)) {
298 /**
299 * This check fails when trying to convert between incompatible
300 * handles. For example, converting from a Handle<String> to a
301 * Handle<Number>.
302 */
303 TYPE_CHECK(T, S);
304 }
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000305 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { }
306 template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000307#ifdef V8_ENABLE_CHECKS
308 // If we're going to perform the type check then we have to check
309 // that the handle isn't empty before doing the checked cast.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000310 if (that.IsEmpty()) return Local<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000311#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000312 return Local<T>(T::Cast(*that));
313 }
314
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000315 template <class S> V8_INLINE(Local<S> As()) {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000316 return Local<S>::Cast(*this);
317 }
318
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000319 /**
320 * Create a local handle for the content of another handle.
321 * The referee is kept alive by the local handle even when
322 * the original handle is destroyed/disposed.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000323 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000324 V8_INLINE(static Local<T> New(Handle<T> that));
325 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000326};
327
328
329/**
330 * An object reference that is independent of any handle scope. Where
v8.team.kasperl727e9952008-09-02 14:56:44 +0000331 * a Local handle only lives as long as the HandleScope in which it was
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000332 * allocated, a Persistent handle remains valid until it is explicitly
333 * disposed.
334 *
335 * A persistent handle contains a reference to a storage cell within
336 * the v8 engine which holds an object value and which is updated by
337 * the garbage collector whenever the object is moved. A new storage
338 * cell can be created using Persistent::New and existing handles can
339 * be disposed using Persistent::Dispose. Since persistent handles
340 * are passed by value you may have many persistent handle objects
341 * that point to the same storage cell. For instance, if you pass a
342 * persistent handle as an argument to a function you will not get two
343 * different storage cells but rather two references to the same
344 * storage cell.
345 */
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000346template <class T> class Persistent : public Handle<T> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000347 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000348 /**
349 * Creates an empty persistent handle that doesn't point to any
350 * storage cell.
351 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000352 V8_INLINE(Persistent());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000353
354 /**
355 * Creates a persistent handle for the same storage cell as the
356 * specified handle. This constructor allows you to pass persistent
357 * handles as arguments by value and to assign between persistent
v8.team.kasperl727e9952008-09-02 14:56:44 +0000358 * handles. However, attempting to assign between incompatible
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000359 * persistent handles, for instance from a Persistent<String> to a
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000360 * Persistent<Number> will cause a compile-time error. Assigning
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000361 * between compatible persistent handles, for instance assigning a
362 * Persistent<String> to a variable declared as Persistent<Value>,
v8.team.kasperl727e9952008-09-02 14:56:44 +0000363 * is allowed as String is a subclass of Value.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000364 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000365 template <class S> V8_INLINE(Persistent(Persistent<S> that))
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000366 : Handle<T>(reinterpret_cast<T*>(*that)) {
367 /**
368 * This check fails when trying to convert between incompatible
369 * handles. For example, converting from a Handle<String> to a
370 * Handle<Number>.
371 */
372 TYPE_CHECK(T, S);
373 }
374
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000375 template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000376
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000377 /**
378 * "Casts" a plain handle which is known to be a persistent handle
379 * to a persistent handle.
380 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000381 template <class S> explicit V8_INLINE(Persistent(Handle<S> that))
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000382 : Handle<T>(*that) { }
383
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000384 template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000385#ifdef V8_ENABLE_CHECKS
386 // If we're going to perform the type check then we have to check
387 // that the handle isn't empty before doing the checked cast.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000388 if (that.IsEmpty()) return Persistent<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000389#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000390 return Persistent<T>(T::Cast(*that));
391 }
392
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000393 template <class S> V8_INLINE(Persistent<S> As()) {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000394 return Persistent<S>::Cast(*this);
395 }
396
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000397 /** Deprecated. Use Isolate version instead. */
398 V8_DEPRECATED(static Persistent<T> New(Handle<T> that));
399
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000400 /**
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000401 * Creates a new persistent handle for an existing local or persistent handle.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000402 */
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000403 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that));
404
405 /** Deprecated. Use Isolate version instead. */
406 V8_DEPRECATED(void Dispose());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000407
408 /**
409 * Releases the storage cell referenced by this persistent handle.
410 * Does not remove the reference to the cell from any handles.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000411 * This handle's reference, and any other references to the storage
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000412 * cell remain and IsEmpty will still return false.
413 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000414 V8_INLINE(void Dispose(Isolate* isolate));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000415
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000416 /** Deprecated. Use Isolate version instead. */
417 V8_DEPRECATED(void MakeWeak(void* parameters,
418 WeakReferenceCallback callback));
419
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000420 /**
421 * Make the reference to this object weak. When only weak handles
422 * refer to the object, the garbage collector will perform a
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000423 * callback to the given V8::NearDeathCallback function, passing
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000424 * it the object reference and the given parameters.
425 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000426 V8_INLINE(void MakeWeak(Isolate* isolate,
427 void* parameters,
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000428 NearDeathCallback callback));
429
430 /** Deprecated. Use Isolate version instead. */
431 V8_DEPRECATED(void ClearWeak());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000432
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000433 /** Clears the weak reference to this object. */
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000434 V8_INLINE(void ClearWeak(Isolate* isolate));
435
436 /** Deprecated. Use Isolate version instead. */
437 V8_DEPRECATED(void MarkIndependent());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000438
439 /**
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000440 * Marks the reference to this object independent. Garbage collector is free
441 * to ignore any object groups containing this object. Weak callback for an
442 * independent handle should not assume that it will be preceded by a global
443 * GC prologue callback or followed by a global GC epilogue callback.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000444 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000445 V8_INLINE(void MarkIndependent(Isolate* isolate));
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000446
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000447 /** Deprecated. Use Isolate version instead. */
448 V8_DEPRECATED(void MarkPartiallyDependent());
449
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000450 /**
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000451 * Marks the reference to this object partially dependent. Partially dependent
452 * handles only depend on other partially dependent handles and these
453 * dependencies are provided through object groups. It provides a way to build
454 * smaller object groups for young objects that represent only a subset of all
455 * external dependencies. This mark is automatically cleared after each
456 * garbage collection.
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000457 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000458 V8_INLINE(void MarkPartiallyDependent(Isolate* isolate));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000459
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000460 /** Deprecated. Use Isolate version instead. */
461 V8_DEPRECATED(bool IsIndependent() const);
462
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000463 /** Returns true if this handle was previously marked as independent. */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000464 V8_INLINE(bool IsIndependent(Isolate* isolate) const);
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000465
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000466 /** Deprecated. Use Isolate version instead. */
467 V8_DEPRECATED(bool IsNearDeath() const);
468
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000469 /** Checks if the handle holds the only reference to an object. */
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000470 V8_INLINE(bool IsNearDeath(Isolate* isolate) const);
471
472 /** Deprecated. Use Isolate version instead. */
473 V8_DEPRECATED(bool IsWeak() const);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000474
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000475 /** Returns true if the handle's reference is weak. */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000476 V8_INLINE(bool IsWeak(Isolate* isolate) const);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000477
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000478 /** Deprecated. Use Isolate version instead. */
479 V8_DEPRECATED(void SetWrapperClassId(uint16_t class_id));
whesse@chromium.orgb08986c2011-03-14 16:13:42 +0000480
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000481 /**
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000482 * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
483 * description in v8-profiler.h for details.
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000484 */
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +0000485 V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id));
486
487 /** Deprecated. Use Isolate version instead. */
488 V8_DEPRECATED(uint16_t WrapperClassId() const);
489
490 /**
491 * Returns the class ID previously assigned to this handle or 0 if no class ID
492 * was previously assigned.
493 */
494 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const);
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000495
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000496 private:
497 friend class ImplementationUtilities;
498 friend class ObjectTemplate;
499};
500
501
v8.team.kasperl727e9952008-09-02 14:56:44 +0000502 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000503 * A stack-allocated class that governs a number of local handles.
504 * After a handle scope has been created, all local handles will be
505 * allocated within that handle scope until either the handle scope is
506 * deleted or another handle scope is created. If there is already a
507 * handle scope and a new one is created, all allocations will take
v8.team.kasperl727e9952008-09-02 14:56:44 +0000508 * place in the new handle scope until it is deleted. After that,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000509 * new handles will again be allocated in the original handle scope.
510 *
511 * After the handle scope of a local handle has been deleted the
512 * garbage collector will no longer track the object stored in the
513 * handle and may deallocate it. The behavior of accessing a handle
514 * for which the handle scope has been deleted is undefined.
515 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000516class V8EXPORT HandleScope {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000517 public:
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000518 // TODO(svenpanne) Deprecate me when Chrome is fixed!
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000519 HandleScope();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000520
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000521 HandleScope(Isolate* isolate);
522
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000523 ~HandleScope();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000524
525 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000526 * Closes the handle scope and returns the value as a handle in the
527 * previous scope, which is the new current scope after the call.
528 */
529 template <class T> Local<T> Close(Handle<T> value);
530
531 /**
532 * Counts the number of allocated handles.
533 */
534 static int NumberOfHandles();
535
536 /**
537 * Creates a new handle with the given value.
538 */
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000539 static internal::Object** CreateHandle(internal::Object* value);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000540 static internal::Object** CreateHandle(internal::Isolate* isolate,
541 internal::Object* value);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000542 // Faster version, uses HeapObject to obtain the current Isolate.
543 static internal::Object** CreateHandle(internal::HeapObject* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000544
545 private:
mmassi@chromium.org49a44672012-12-04 13:52:03 +0000546 // Make it hard to create heap-allocated or illegal handle scopes by
547 // disallowing certain operations.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000548 HandleScope(const HandleScope&);
549 void operator=(const HandleScope&);
550 void* operator new(size_t size);
551 void operator delete(void*, size_t);
552
ager@chromium.org3811b432009-10-28 14:53:37 +0000553 // This Data class is accessible internally as HandleScopeData through a
554 // typedef in the ImplementationUtilities class.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000555 class V8EXPORT Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000556 public:
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000557 internal::Object** next;
558 internal::Object** limit;
lrn@chromium.org303ada72010-10-27 09:33:13 +0000559 int level;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000560 V8_INLINE(void Initialize()) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000561 next = limit = NULL;
lrn@chromium.org303ada72010-10-27 09:33:13 +0000562 level = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000563 }
564 };
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +0000565
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000566 void Initialize(Isolate* isolate);
lrn@chromium.org303ada72010-10-27 09:33:13 +0000567 void Leave();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000568
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000569 internal::Isolate* isolate_;
lrn@chromium.org303ada72010-10-27 09:33:13 +0000570 internal::Object** prev_next_;
571 internal::Object** prev_limit_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000572
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000573 // Allow for the active closing of HandleScopes which allows to pass a handle
574 // from the HandleScope being closed to the next top most HandleScope.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000575 bool is_closed_;
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000576 internal::Object** RawClose(internal::Object** value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000577
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000578 friend class ImplementationUtilities;
579};
580
581
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000582// --- Special objects ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000583
584
585/**
586 * The superclass of values and API object templates.
587 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000588class V8EXPORT Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000589 private:
590 Data();
591};
592
593
594/**
595 * Pre-compilation data that can be associated with a script. This
596 * data can be calculated for a script in advance of actually
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000597 * compiling it, and can be stored between compilations. When script
v8.team.kasperl727e9952008-09-02 14:56:44 +0000598 * data is given to the compile method compilation will be faster.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000599 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000600class V8EXPORT ScriptData { // NOLINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000601 public:
602 virtual ~ScriptData() { }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000603
kmillikin@chromium.org9155e252010-05-26 13:27:57 +0000604 /**
605 * Pre-compiles the specified script (context-independent).
606 *
607 * \param input Pointer to UTF-8 script source code.
608 * \param length Length of UTF-8 script source code.
609 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000610 static ScriptData* PreCompile(const char* input, int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000611
kmillikin@chromium.org9155e252010-05-26 13:27:57 +0000612 /**
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000613 * Pre-compiles the specified script (context-independent).
614 *
615 * NOTE: Pre-compilation using this method cannot happen on another thread
616 * without using Lockers.
617 *
618 * \param source Script source code.
619 */
620 static ScriptData* PreCompile(Handle<String> source);
621
622 /**
kmillikin@chromium.org9155e252010-05-26 13:27:57 +0000623 * Load previous pre-compilation data.
624 *
625 * \param data Pointer to data returned by a call to Data() of a previous
626 * ScriptData. Ownership is not transferred.
627 * \param length Length of data.
628 */
629 static ScriptData* New(const char* data, int length);
630
631 /**
632 * Returns the length of Data().
633 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000634 virtual int Length() = 0;
kmillikin@chromium.org9155e252010-05-26 13:27:57 +0000635
636 /**
637 * Returns a serialized representation of this ScriptData that can later be
638 * passed to New(). NOTE: Serialized data is platform-dependent.
639 */
640 virtual const char* Data() = 0;
641
642 /**
643 * Returns true if the source code could not be parsed.
644 */
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000645 virtual bool HasError() = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000646};
647
648
649/**
650 * The origin, within a file, of a script.
651 */
mvstanton@chromium.org6bec0092013-01-23 13:46:53 +0000652class ScriptOrigin {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000653 public:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000654 V8_INLINE(ScriptOrigin(
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000655 Handle<Value> resource_name,
656 Handle<Integer> resource_line_offset = Handle<Integer>(),
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000657 Handle<Integer> resource_column_offset = Handle<Integer>()))
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000658 : resource_name_(resource_name),
659 resource_line_offset_(resource_line_offset),
660 resource_column_offset_(resource_column_offset) { }
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000661 V8_INLINE(Handle<Value> ResourceName() const);
662 V8_INLINE(Handle<Integer> ResourceLineOffset() const);
663 V8_INLINE(Handle<Integer> ResourceColumnOffset() const);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000664 private:
mads.s.agercbaa0602008-08-14 13:41:48 +0000665 Handle<Value> resource_name_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000666 Handle<Integer> resource_line_offset_;
667 Handle<Integer> resource_column_offset_;
668};
669
670
671/**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000672 * A compiled JavaScript script.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000673 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000674class V8EXPORT Script {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000675 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000676 /**
ager@chromium.org5c838252010-02-19 08:53:10 +0000677 * Compiles the specified script (context-independent).
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000678 *
ager@chromium.org5c838252010-02-19 08:53:10 +0000679 * \param source Script source code.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000680 * \param origin Script origin, owned by caller, no references are kept
ager@chromium.org5c838252010-02-19 08:53:10 +0000681 * when New() returns
682 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
683 * using pre_data speeds compilation if it's done multiple times.
684 * Owned by caller, no references are kept when New() returns.
685 * \param script_data Arbitrary data associated with script. Using
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000686 * this has same effect as calling SetData(), but allows data to be
ager@chromium.org5c838252010-02-19 08:53:10 +0000687 * available to compile event handlers.
688 * \return Compiled script object (context independent; when run it
689 * will use the currently entered context).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000690 */
ager@chromium.org5c838252010-02-19 08:53:10 +0000691 static Local<Script> New(Handle<String> source,
692 ScriptOrigin* origin = NULL,
693 ScriptData* pre_data = NULL,
694 Handle<String> script_data = Handle<String>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000695
mads.s.agercbaa0602008-08-14 13:41:48 +0000696 /**
697 * Compiles the specified script using the specified file name
698 * object (typically a string) as the script's origin.
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000699 *
ager@chromium.org5c838252010-02-19 08:53:10 +0000700 * \param source Script source code.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000701 * \param file_name file name object (typically a string) to be used
ager@chromium.org5c838252010-02-19 08:53:10 +0000702 * as the script's origin.
703 * \return Compiled script object (context independent; when run it
704 * will use the currently entered context).
705 */
706 static Local<Script> New(Handle<String> source,
707 Handle<Value> file_name);
708
709 /**
710 * Compiles the specified script (bound to current context).
711 *
712 * \param source Script source code.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000713 * \param origin Script origin, owned by caller, no references are kept
ager@chromium.org5c838252010-02-19 08:53:10 +0000714 * when Compile() returns
715 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
716 * using pre_data speeds compilation if it's done multiple times.
717 * Owned by caller, no references are kept when Compile() returns.
718 * \param script_data Arbitrary data associated with script. Using
719 * this has same effect as calling SetData(), but makes data available
720 * earlier (i.e. to compile event handlers).
721 * \return Compiled script object, bound to the context that was active
722 * when this function was called. When run it will always use this
723 * context.
mads.s.agercbaa0602008-08-14 13:41:48 +0000724 */
725 static Local<Script> Compile(Handle<String> source,
ager@chromium.org5c838252010-02-19 08:53:10 +0000726 ScriptOrigin* origin = NULL,
727 ScriptData* pre_data = NULL,
728 Handle<String> script_data = Handle<String>());
729
730 /**
731 * Compiles the specified script using the specified file name
732 * object (typically a string) as the script's origin.
733 *
734 * \param source Script source code.
735 * \param file_name File name to use as script's origin
736 * \param script_data Arbitrary data associated with script. Using
737 * this has same effect as calling SetData(), but makes data available
738 * earlier (i.e. to compile event handlers).
739 * \return Compiled script object, bound to the context that was active
740 * when this function was called. When run it will always use this
741 * context.
742 */
743 static Local<Script> Compile(Handle<String> source,
744 Handle<Value> file_name,
745 Handle<String> script_data = Handle<String>());
mads.s.agercbaa0602008-08-14 13:41:48 +0000746
v8.team.kasperl727e9952008-09-02 14:56:44 +0000747 /**
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000748 * Runs the script returning the resulting value. If the script is
749 * context independent (created using ::New) it will be run in the
750 * currently entered context. If it is context specific (created
751 * using ::Compile) it will be run in the context in which it was
752 * compiled.
v8.team.kasperl727e9952008-09-02 14:56:44 +0000753 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000754 Local<Value> Run();
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000755
756 /**
757 * Returns the script id value.
758 */
759 Local<Value> Id();
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000760
761 /**
762 * Associate an additional data object with the script. This is mainly used
763 * with the debugger as this data object is only available through the
764 * debugger API.
765 */
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +0000766 void SetData(Handle<String> data);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000767};
768
769
770/**
771 * An error message.
772 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000773class V8EXPORT Message {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000774 public:
ager@chromium.org32912102009-01-16 10:38:43 +0000775 Local<String> Get() const;
776 Local<String> GetSourceLine() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000777
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000778 /**
779 * Returns the resource name for the script from where the function causing
780 * the error originates.
781 */
ager@chromium.org32912102009-01-16 10:38:43 +0000782 Handle<Value> GetScriptResourceName() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000783
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000784 /**
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000785 * Returns the resource data for the script from where the function causing
786 * the error originates.
787 */
788 Handle<Value> GetScriptData() const;
789
790 /**
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000791 * Exception stack trace. By default stack traces are not captured for
792 * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
793 * to change this option.
794 */
795 Handle<StackTrace> GetStackTrace() const;
796
797 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000798 * Returns the number, 1-based, of the line where the error occurred.
799 */
ager@chromium.org32912102009-01-16 10:38:43 +0000800 int GetLineNumber() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000801
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000802 /**
803 * Returns the index within the script of the first character where
804 * the error occurred.
805 */
ager@chromium.org32912102009-01-16 10:38:43 +0000806 int GetStartPosition() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000807
808 /**
809 * Returns the index within the script of the last character where
810 * the error occurred.
811 */
ager@chromium.org32912102009-01-16 10:38:43 +0000812 int GetEndPosition() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000813
814 /**
815 * Returns the index within the line of the first character where
816 * the error occurred.
817 */
ager@chromium.org32912102009-01-16 10:38:43 +0000818 int GetStartColumn() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000819
820 /**
821 * Returns the index within the line of the last character where
822 * the error occurred.
823 */
ager@chromium.org32912102009-01-16 10:38:43 +0000824 int GetEndColumn() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000825
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000826 // TODO(1245381): Print to a string instead of on a FILE.
827 static void PrintCurrentStackTrace(FILE* out);
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000828
829 static const int kNoLineNumberInfo = 0;
830 static const int kNoColumnInfo = 0;
831};
832
833
834/**
835 * Representation of a JavaScript stack trace. The information collected is a
836 * snapshot of the execution stack and the information remains valid after
837 * execution continues.
838 */
839class V8EXPORT StackTrace {
840 public:
841 /**
842 * Flags that determine what information is placed captured for each
843 * StackFrame when grabbing the current stack trace.
844 */
845 enum StackTraceOptions {
846 kLineNumber = 1,
847 kColumnOffset = 1 << 1 | kLineNumber,
848 kScriptName = 1 << 2,
849 kFunctionName = 1 << 3,
850 kIsEval = 1 << 4,
851 kIsConstructor = 1 << 5,
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000852 kScriptNameOrSourceURL = 1 << 6,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000853 kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000854 kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000855 };
856
857 /**
858 * Returns a StackFrame at a particular index.
859 */
860 Local<StackFrame> GetFrame(uint32_t index) const;
861
862 /**
863 * Returns the number of StackFrames.
864 */
865 int GetFrameCount() const;
866
867 /**
868 * Returns StackTrace as a v8::Array that contains StackFrame objects.
869 */
870 Local<Array> AsArray();
871
872 /**
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000873 * Grab a snapshot of the current JavaScript execution stack.
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000874 *
875 * \param frame_limit The maximum number of stack frames we want to capture.
876 * \param options Enumerates the set of things we will capture for each
877 * StackFrame.
878 */
879 static Local<StackTrace> CurrentStackTrace(
880 int frame_limit,
881 StackTraceOptions options = kOverview);
882};
883
884
885/**
886 * A single JavaScript stack frame.
887 */
888class V8EXPORT StackFrame {
889 public:
890 /**
891 * Returns the number, 1-based, of the line for the associate function call.
892 * This method will return Message::kNoLineNumberInfo if it is unable to
893 * retrieve the line number, or if kLineNumber was not passed as an option
894 * when capturing the StackTrace.
895 */
896 int GetLineNumber() const;
897
898 /**
899 * Returns the 1-based column offset on the line for the associated function
900 * call.
901 * This method will return Message::kNoColumnInfo if it is unable to retrieve
902 * the column number, or if kColumnOffset was not passed as an option when
903 * capturing the StackTrace.
904 */
905 int GetColumn() const;
906
907 /**
908 * Returns the name of the resource that contains the script for the
909 * function for this StackFrame.
910 */
911 Local<String> GetScriptName() const;
912
913 /**
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000914 * Returns the name of the resource that contains the script for the
915 * function for this StackFrame or sourceURL value if the script name
916 * is undefined and its source ends with //@ sourceURL=... string.
917 */
918 Local<String> GetScriptNameOrSourceURL() const;
919
920 /**
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000921 * Returns the name of the function associated with this stack frame.
922 */
923 Local<String> GetFunctionName() const;
924
925 /**
926 * Returns whether or not the associated function is compiled via a call to
927 * eval().
928 */
929 bool IsEval() const;
930
931 /**
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000932 * Returns whether or not the associated function is called as a
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000933 * constructor via "new".
934 */
935 bool IsConstructor() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000936};
937
938
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000939// --- Value ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000940
941
942/**
v8.team.kasperl727e9952008-09-02 14:56:44 +0000943 * The superclass of all JavaScript values and objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000944 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000945class V8EXPORT Value : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000946 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000947 /**
948 * Returns true if this value is the undefined value. See ECMA-262
949 * 4.3.10.
950 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000951 V8_INLINE(bool IsUndefined() const);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000952
953 /**
954 * Returns true if this value is the null value. See ECMA-262
955 * 4.3.11.
956 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000957 V8_INLINE(bool IsNull() const);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000958
959 /**
960 * Returns true if this value is true.
961 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000962 bool IsTrue() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000963
964 /**
965 * Returns true if this value is false.
966 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000967 bool IsFalse() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000968
969 /**
970 * Returns true if this value is an instance of the String type.
971 * See ECMA-262 8.4.
972 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +0000973 V8_INLINE(bool IsString() const);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000974
975 /**
976 * Returns true if this value is a function.
977 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000978 bool IsFunction() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000979
980 /**
981 * Returns true if this value is an array.
982 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000983 bool IsArray() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000984
v8.team.kasperl727e9952008-09-02 14:56:44 +0000985 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000986 * Returns true if this value is an object.
987 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000988 bool IsObject() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000989
v8.team.kasperl727e9952008-09-02 14:56:44 +0000990 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000991 * Returns true if this value is boolean.
992 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000993 bool IsBoolean() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000994
v8.team.kasperl727e9952008-09-02 14:56:44 +0000995 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000996 * Returns true if this value is a number.
997 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000998 bool IsNumber() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000999
v8.team.kasperl727e9952008-09-02 14:56:44 +00001000 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001001 * Returns true if this value is external.
1002 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001003 bool IsExternal() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001004
v8.team.kasperl727e9952008-09-02 14:56:44 +00001005 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001006 * Returns true if this value is a 32-bit signed integer.
1007 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001008 bool IsInt32() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001009
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001010 /**
lrn@chromium.orgc34f5802010-04-28 12:53:43 +00001011 * Returns true if this value is a 32-bit unsigned integer.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001012 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001013 bool IsUint32() const;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001014
1015 /**
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001016 * Returns true if this value is a Date.
1017 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001018 bool IsDate() const;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001019
vegorov@chromium.org26c16f82010-08-11 13:41:03 +00001020 /**
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001021 * Returns true if this value is a Boolean object.
1022 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001023 bool IsBooleanObject() const;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001024
1025 /**
1026 * Returns true if this value is a Number object.
1027 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001028 bool IsNumberObject() const;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001029
1030 /**
1031 * Returns true if this value is a String object.
1032 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001033 bool IsStringObject() const;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001034
1035 /**
1036 * Returns true if this value is a NativeError.
1037 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001038 bool IsNativeError() const;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001039
1040 /**
vegorov@chromium.org26c16f82010-08-11 13:41:03 +00001041 * Returns true if this value is a RegExp.
1042 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001043 bool IsRegExp() const;
vegorov@chromium.org26c16f82010-08-11 13:41:03 +00001044
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001045 Local<Boolean> ToBoolean() const;
1046 Local<Number> ToNumber() const;
1047 Local<String> ToString() const;
1048 Local<String> ToDetailString() const;
1049 Local<Object> ToObject() const;
1050 Local<Integer> ToInteger() const;
1051 Local<Uint32> ToUint32() const;
1052 Local<Int32> ToInt32() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001053
1054 /**
1055 * Attempts to convert a string to an array index.
1056 * Returns an empty handle if the conversion fails.
1057 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001058 Local<Uint32> ToArrayIndex() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001059
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001060 bool BooleanValue() const;
1061 double NumberValue() const;
1062 int64_t IntegerValue() const;
1063 uint32_t Uint32Value() const;
1064 int32_t Int32Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001065
1066 /** JS == */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001067 bool Equals(Handle<Value> that) const;
1068 bool StrictEquals(Handle<Value> that) const;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001069
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001070 private:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001071 V8_INLINE(bool QuickIsUndefined() const);
1072 V8_INLINE(bool QuickIsNull() const);
1073 V8_INLINE(bool QuickIsString() const);
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001074 bool FullIsUndefined() const;
1075 bool FullIsNull() const;
1076 bool FullIsString() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001077};
1078
1079
1080/**
1081 * The superclass of primitive values. See ECMA-262 4.3.2.
1082 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001083class V8EXPORT Primitive : public Value { };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001084
1085
1086/**
1087 * A primitive boolean value (ECMA-262, 4.3.14). Either the true
1088 * or false value.
1089 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001090class V8EXPORT Boolean : public Primitive {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001091 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001092 bool Value() const;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001093 V8_INLINE(static Handle<Boolean> New(bool value));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001094};
1095
1096
1097/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001098 * A JavaScript string value (ECMA-262, 4.3.17).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001099 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001100class V8EXPORT String : public Primitive {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001101 public:
ulan@chromium.org56c14af2012-09-20 12:51:09 +00001102 enum Encoding {
1103 UNKNOWN_ENCODING = 0x1,
1104 TWO_BYTE_ENCODING = 0x0,
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001105 ASCII_ENCODING = 0x4,
1106 ONE_BYTE_ENCODING = 0x4
ulan@chromium.org56c14af2012-09-20 12:51:09 +00001107 };
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001108 /**
1109 * Returns the number of characters in this string.
1110 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001111 int Length() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001112
v8.team.kasperl727e9952008-09-02 14:56:44 +00001113 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001114 * Returns the number of bytes in the UTF-8 encoded
1115 * representation of this string.
1116 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001117 int Utf8Length() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001118
1119 /**
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00001120 * A fast conservative check for non-ASCII characters. May
1121 * return true even for ASCII strings, but if it returns
1122 * false you can be sure that all characters are in the range
1123 * 0-127.
1124 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001125 bool MayContainNonAscii() const;
1126
1127 /**
1128 * Returns whether this string contains only one byte data.
1129 */
1130 bool IsOneByte() const;
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00001131
1132 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001133 * Write the contents of the string to an external buffer.
1134 * If no arguments are given, expects the buffer to be large
1135 * enough to hold the entire string and NULL terminator. Copies
1136 * the contents of the string and the NULL terminator into the
1137 * buffer.
1138 *
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001139 * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
1140 * before the end of the buffer.
1141 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00001142 * Copies up to length characters into the output buffer.
1143 * Only null-terminates if there is enough space in the buffer.
1144 *
1145 * \param buffer The buffer into which the string will be copied.
1146 * \param start The starting position within the string at which
1147 * copying begins.
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001148 * \param length The number of characters to copy from the string. For
1149 * WriteUtf8 the number of bytes in the buffer.
ager@chromium.org357bf652010-04-12 11:30:10 +00001150 * \param nchars_ref The number of characters written, can be NULL.
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001151 * \param options Various options that might affect performance of this or
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00001152 * subsequent operations.
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001153 * \return The number of characters copied to the buffer excluding the null
1154 * terminator. For WriteUtf8: The number of bytes copied to the buffer
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001155 * including the null terminator (if written).
v8.team.kasperl727e9952008-09-02 14:56:44 +00001156 */
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001157 enum WriteOptions {
1158 NO_OPTIONS = 0,
1159 HINT_MANY_WRITES_EXPECTED = 1,
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001160 NO_NULL_TERMINATION = 2,
1161 PRESERVE_ASCII_NULL = 4
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +00001162 };
1163
lrn@chromium.org34e60782011-09-15 07:25:40 +00001164 // 16-bit character codes.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001165 int Write(uint16_t* buffer,
1166 int start = 0,
1167 int length = -1,
1168 int options = NO_OPTIONS) const;
lrn@chromium.org34e60782011-09-15 07:25:40 +00001169 // ASCII characters.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001170 int WriteAscii(char* buffer,
1171 int start = 0,
1172 int length = -1,
1173 int options = NO_OPTIONS) const;
1174 // One byte characters.
1175 int WriteOneByte(uint8_t* buffer,
1176 int start = 0,
1177 int length = -1,
1178 int options = NO_OPTIONS) const;
lrn@chromium.org34e60782011-09-15 07:25:40 +00001179 // UTF-8 encoded characters.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001180 int WriteUtf8(char* buffer,
1181 int length = -1,
1182 int* nchars_ref = NULL,
1183 int options = NO_OPTIONS) const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001184
v8.team.kasperl727e9952008-09-02 14:56:44 +00001185 /**
ager@chromium.org563b8dc2009-03-20 14:23:52 +00001186 * A zero length string.
1187 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001188 static v8::Local<v8::String> Empty();
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001189 V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate));
ager@chromium.org563b8dc2009-03-20 14:23:52 +00001190
1191 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001192 * Returns true if the string is external
1193 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001194 bool IsExternal() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001195
v8.team.kasperl727e9952008-09-02 14:56:44 +00001196 /**
lrn@chromium.org34e60782011-09-15 07:25:40 +00001197 * Returns true if the string is both external and ASCII
v8.team.kasperl727e9952008-09-02 14:56:44 +00001198 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001199 bool IsExternalAscii() const;
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001200
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +00001201 class V8EXPORT ExternalStringResourceBase { // NOLINT
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001202 public:
1203 virtual ~ExternalStringResourceBase() {}
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001204
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001205 protected:
1206 ExternalStringResourceBase() {}
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001207
1208 /**
1209 * Internally V8 will call this Dispose method when the external string
1210 * resource is no longer needed. The default implementation will use the
1211 * delete operator. This method can be overridden in subclasses to
1212 * control how allocated external string resources are disposed.
1213 */
1214 virtual void Dispose() { delete this; }
1215
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001216 private:
1217 // Disallow copying and assigning.
1218 ExternalStringResourceBase(const ExternalStringResourceBase&);
1219 void operator=(const ExternalStringResourceBase&);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001220
1221 friend class v8::internal::Heap;
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001222 };
1223
v8.team.kasperl727e9952008-09-02 14:56:44 +00001224 /**
1225 * An ExternalStringResource is a wrapper around a two-byte string
1226 * buffer that resides outside V8's heap. Implement an
1227 * ExternalStringResource to manage the life cycle of the underlying
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001228 * buffer. Note that the string data must be immutable.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001229 */
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001230 class V8EXPORT ExternalStringResource
1231 : public ExternalStringResourceBase {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001232 public:
1233 /**
1234 * Override the destructor to manage the life cycle of the underlying
1235 * buffer.
1236 */
1237 virtual ~ExternalStringResource() {}
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001238
1239 /**
1240 * The string data from the underlying buffer.
1241 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001242 virtual const uint16_t* data() const = 0;
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001243
1244 /**
1245 * The length of the string. That is, the number of two-byte characters.
1246 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001247 virtual size_t length() const = 0;
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001248
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001249 protected:
1250 ExternalStringResource() {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001251 };
1252
1253 /**
lrn@chromium.org34e60782011-09-15 07:25:40 +00001254 * An ExternalAsciiStringResource is a wrapper around an ASCII
v8.team.kasperl727e9952008-09-02 14:56:44 +00001255 * string buffer that resides outside V8's heap. Implement an
1256 * ExternalAsciiStringResource to manage the life cycle of the
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001257 * underlying buffer. Note that the string data must be immutable
lrn@chromium.org34e60782011-09-15 07:25:40 +00001258 * and that the data must be strict (7-bit) ASCII, not Latin-1 or
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001259 * UTF-8, which would require special treatment internally in the
1260 * engine and, in the case of UTF-8, do not allow efficient indexing.
1261 * Use String::New or convert to 16 bit data for non-ASCII.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001262 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001263
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001264 class V8EXPORT ExternalAsciiStringResource
1265 : public ExternalStringResourceBase {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001266 public:
1267 /**
1268 * Override the destructor to manage the life cycle of the underlying
1269 * buffer.
1270 */
1271 virtual ~ExternalAsciiStringResource() {}
1272 /** The string data from the underlying buffer.*/
1273 virtual const char* data() const = 0;
lrn@chromium.org34e60782011-09-15 07:25:40 +00001274 /** The number of ASCII characters in the string.*/
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001275 virtual size_t length() const = 0;
1276 protected:
1277 ExternalAsciiStringResource() {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001278 };
1279
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001280 typedef ExternalAsciiStringResource ExternalOneByteStringResource;
1281
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001282 /**
ulan@chromium.org56c14af2012-09-20 12:51:09 +00001283 * If the string is an external string, return the ExternalStringResourceBase
1284 * regardless of the encoding, otherwise return NULL. The encoding of the
1285 * string is returned in encoding_out.
1286 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001287 V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase(
1288 Encoding* encoding_out) const);
ulan@chromium.org56c14af2012-09-20 12:51:09 +00001289
1290 /**
ager@chromium.org9085a012009-05-11 19:22:57 +00001291 * Get the ExternalStringResource for an external string. Returns
1292 * NULL if IsExternal() doesn't return true.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001293 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001294 V8_INLINE(ExternalStringResource* GetExternalStringResource() const);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001295
1296 /**
lrn@chromium.org34e60782011-09-15 07:25:40 +00001297 * Get the ExternalAsciiStringResource for an external ASCII string.
ager@chromium.org9085a012009-05-11 19:22:57 +00001298 * Returns NULL if IsExternalAscii() doesn't return true.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001299 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001300 const ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001301
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001302 V8_INLINE(static String* Cast(v8::Value* obj));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001303
1304 /**
lrn@chromium.org34e60782011-09-15 07:25:40 +00001305 * Allocates a new string from either UTF-8 encoded or ASCII data.
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00001306 * The second parameter 'length' gives the buffer length. If omitted,
1307 * the function calls 'strlen' to determine the buffer length.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001308 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001309 static Local<String> New(const char* data, int length = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001310
lrn@chromium.org34e60782011-09-15 07:25:40 +00001311 /** Allocates a new string from 16-bit character codes.*/
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001312 static Local<String> New(const uint16_t* data, int length = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001313
1314 /** Creates a symbol. Returns one if it exists already.*/
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001315 static Local<String> NewSymbol(const char* data, int length = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001316
v8.team.kasperl727e9952008-09-02 14:56:44 +00001317 /**
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001318 * Creates a new string by concatenating the left and the right strings
1319 * passed in as parameters.
1320 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001321 static Local<String> Concat(Handle<String> left, Handle<String> right);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001322
1323 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001324 * Creates a new external string using the data defined in the given
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00001325 * resource. When the external string is no longer live on V8's heap the
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001326 * resource will be disposed by calling its Dispose method. The caller of
1327 * this function should not otherwise delete or modify the resource. Neither
1328 * should the underlying buffer be deallocated or modified except through the
1329 * destructor of the external string resource.
v8.team.kasperl727e9952008-09-02 14:56:44 +00001330 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001331 static Local<String> NewExternal(ExternalStringResource* resource);
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001332
ager@chromium.org6f10e412009-02-13 10:11:16 +00001333 /**
1334 * Associate an external string resource with this string by transforming it
1335 * in place so that existing references to this string in the JavaScript heap
1336 * will use the external string resource. The external string resource's
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001337 * character contents need to be equivalent to this string.
ager@chromium.org6f10e412009-02-13 10:11:16 +00001338 * Returns true if the string has been changed to be an external string.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00001339 * The string is not modified if the operation fails. See NewExternal for
1340 * information on the lifetime of the resource.
ager@chromium.org6f10e412009-02-13 10:11:16 +00001341 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001342 bool MakeExternal(ExternalStringResource* resource);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001343
v8.team.kasperl727e9952008-09-02 14:56:44 +00001344 /**
lrn@chromium.org34e60782011-09-15 07:25:40 +00001345 * Creates a new external string using the ASCII data defined in the given
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00001346 * resource. When the external string is no longer live on V8's heap the
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001347 * resource will be disposed by calling its Dispose method. The caller of
1348 * this function should not otherwise delete or modify the resource. Neither
1349 * should the underlying buffer be deallocated or modified except through the
1350 * destructor of the external string resource.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001351 */
1352 static Local<String> NewExternal(ExternalAsciiStringResource* resource);
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001353
ager@chromium.org6f10e412009-02-13 10:11:16 +00001354 /**
1355 * Associate an external string resource with this string by transforming it
1356 * in place so that existing references to this string in the JavaScript heap
1357 * will use the external string resource. The external string resource's
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001358 * character contents need to be equivalent to this string.
ager@chromium.org6f10e412009-02-13 10:11:16 +00001359 * Returns true if the string has been changed to be an external string.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00001360 * The string is not modified if the operation fails. See NewExternal for
1361 * information on the lifetime of the resource.
ager@chromium.org6f10e412009-02-13 10:11:16 +00001362 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001363 bool MakeExternal(ExternalAsciiStringResource* resource);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001364
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +00001365 /**
1366 * Returns true if this string can be made external.
1367 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001368 bool CanMakeExternal();
christian.plesner.hansen@gmail.com5a6af922009-08-12 14:20:51 +00001369
lrn@chromium.org34e60782011-09-15 07:25:40 +00001370 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001371 static Local<String> NewUndetectable(const char* data, int length = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001372
lrn@chromium.org34e60782011-09-15 07:25:40 +00001373 /** Creates an undetectable string from the supplied 16-bit character codes.*/
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001374 static Local<String> NewUndetectable(const uint16_t* data, int length = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001375
1376 /**
lrn@chromium.org34e60782011-09-15 07:25:40 +00001377 * Converts an object to a UTF-8-encoded character array. Useful if
ager@chromium.org71daaf62009-04-01 07:22:49 +00001378 * you want to print the object. If conversion to a string fails
lrn@chromium.org34e60782011-09-15 07:25:40 +00001379 * (e.g. due to an exception in the toString() method of the object)
ager@chromium.org71daaf62009-04-01 07:22:49 +00001380 * then the length() method returns 0 and the * operator returns
1381 * NULL.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001382 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001383 class V8EXPORT Utf8Value {
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001384 public:
1385 explicit Utf8Value(Handle<v8::Value> obj);
1386 ~Utf8Value();
ager@chromium.orga1645e22009-09-09 19:27:10 +00001387 char* operator*() { return str_; }
1388 const char* operator*() const { return str_; }
1389 int length() const { return length_; }
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001390 private:
1391 char* str_;
1392 int length_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001393
1394 // Disallow copying and assigning.
1395 Utf8Value(const Utf8Value&);
1396 void operator=(const Utf8Value&);
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001397 };
1398
1399 /**
lrn@chromium.org34e60782011-09-15 07:25:40 +00001400 * Converts an object to an ASCII string.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001401 * Useful if you want to print the object.
ager@chromium.org71daaf62009-04-01 07:22:49 +00001402 * If conversion to a string fails (eg. due to an exception in the toString()
1403 * method of the object) then the length() method returns 0 and the * operator
1404 * returns NULL.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001405 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001406 class V8EXPORT AsciiValue {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001407 public:
1408 explicit AsciiValue(Handle<v8::Value> obj);
1409 ~AsciiValue();
ager@chromium.orga1645e22009-09-09 19:27:10 +00001410 char* operator*() { return str_; }
1411 const char* operator*() const { return str_; }
1412 int length() const { return length_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001413 private:
1414 char* str_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001415 int length_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001416
1417 // Disallow copying and assigning.
1418 AsciiValue(const AsciiValue&);
1419 void operator=(const AsciiValue&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001420 };
1421
1422 /**
1423 * Converts an object to a two-byte string.
ager@chromium.org71daaf62009-04-01 07:22:49 +00001424 * If conversion to a string fails (eg. due to an exception in the toString()
1425 * method of the object) then the length() method returns 0 and the * operator
1426 * returns NULL.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001427 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001428 class V8EXPORT Value {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001429 public:
1430 explicit Value(Handle<v8::Value> obj);
1431 ~Value();
ager@chromium.orga1645e22009-09-09 19:27:10 +00001432 uint16_t* operator*() { return str_; }
1433 const uint16_t* operator*() const { return str_; }
1434 int length() const { return length_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001435 private:
1436 uint16_t* str_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001437 int length_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001438
1439 // Disallow copying and assigning.
1440 Value(const Value&);
1441 void operator=(const Value&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001442 };
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001443
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001444 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001445 void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
1446 Encoding encoding) const;
1447 void VerifyExternalStringResource(ExternalStringResource* val) const;
1448 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001449};
1450
1451
1452/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001453 * A JavaScript number value (ECMA-262, 4.3.20)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001454 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001455class V8EXPORT Number : public Primitive {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001456 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001457 double Value() const;
1458 static Local<Number> New(double value);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001459 V8_INLINE(static Number* Cast(v8::Value* obj));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001460 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001461 Number();
1462 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001463};
1464
1465
1466/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001467 * A JavaScript value representing a signed integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001468 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001469class V8EXPORT Integer : public Number {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001470 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001471 static Local<Integer> New(int32_t value);
1472 static Local<Integer> NewFromUnsigned(uint32_t value);
1473 static Local<Integer> New(int32_t value, Isolate*);
1474 static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*);
1475 int64_t Value() const;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001476 V8_INLINE(static Integer* Cast(v8::Value* obj));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001477 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001478 Integer();
1479 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001480};
1481
1482
1483/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001484 * A JavaScript value representing a 32-bit signed integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001485 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001486class V8EXPORT Int32 : public Integer {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001487 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001488 int32_t Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001489 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001490 Int32();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001491};
1492
1493
1494/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001495 * A JavaScript value representing a 32-bit unsigned integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001496 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001497class V8EXPORT Uint32 : public Integer {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001498 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001499 uint32_t Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001500 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001501 Uint32();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001502};
1503
1504
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001505enum PropertyAttribute {
1506 None = 0,
1507 ReadOnly = 1 << 0,
1508 DontEnum = 1 << 1,
1509 DontDelete = 1 << 2
1510};
1511
ager@chromium.org3811b432009-10-28 14:53:37 +00001512enum ExternalArrayType {
1513 kExternalByteArray = 1,
1514 kExternalUnsignedByteArray,
1515 kExternalShortArray,
1516 kExternalUnsignedShortArray,
1517 kExternalIntArray,
1518 kExternalUnsignedIntArray,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001519 kExternalFloatArray,
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00001520 kExternalDoubleArray,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001521 kExternalPixelArray
ager@chromium.org3811b432009-10-28 14:53:37 +00001522};
1523
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001524/**
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00001525 * Accessor[Getter|Setter] are used as callback functions when
1526 * setting|getting a particular property. See Object and ObjectTemplate's
1527 * method 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 * Access control specifications.
1540 *
1541 * Some accessors should be accessible across contexts. These
1542 * accessors have an explicit access control parameter which specifies
1543 * the kind of cross-context access that should be allowed.
1544 *
1545 * Additionally, for security, accessors can prohibit overwriting by
1546 * accessors defined in JavaScript. For objects that have such
1547 * accessors either locally or in their prototype chain it is not
1548 * possible to overwrite the accessor by using __defineGetter__ or
1549 * __defineSetter__ from JavaScript code.
1550 */
1551enum AccessControl {
1552 DEFAULT = 0,
1553 ALL_CAN_READ = 1,
1554 ALL_CAN_WRITE = 1 << 1,
1555 PROHIBITS_OVERWRITING = 1 << 2
1556};
1557
1558
1559/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001560 * A JavaScript object (ECMA-262, 4.3.3)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001561 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001562class V8EXPORT Object : public Value {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001563 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001564 bool Set(Handle<Value> key,
1565 Handle<Value> value,
1566 PropertyAttribute attribs = None);
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001567
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001568 bool Set(uint32_t index, Handle<Value> value);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001569
ager@chromium.orge2902be2009-06-08 12:21:35 +00001570 // Sets a local property on this object bypassing interceptors and
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001571 // overriding accessors or read-only properties.
1572 //
1573 // Note that if the object has an interceptor the property will be set
1574 // locally, but since the interceptor takes precedence the local property
1575 // will only be returned if the interceptor doesn't return a value.
1576 //
1577 // Note also that this only works for named properties.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001578 bool ForceSet(Handle<Value> key,
1579 Handle<Value> value,
1580 PropertyAttribute attribs = None);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001581
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001582 Local<Value> Get(Handle<Value> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001583
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001584 Local<Value> Get(uint32_t index);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001585
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001586 /**
1587 * Gets the property attributes of a property which can be None or
1588 * any combination of ReadOnly, DontEnum and DontDelete. Returns
1589 * None when the property doesn't exist.
1590 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001591 PropertyAttribute GetPropertyAttributes(Handle<Value> key);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001592
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001593 // TODO(1245389): Replace the type-specific versions of these
1594 // functions with generic ones that accept a Handle<Value> key.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001595 bool Has(Handle<String> key);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001596
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001597 bool Delete(Handle<String> key);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001598
1599 // Delete a property on this object bypassing interceptors and
1600 // ignoring dont-delete attributes.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001601 bool ForceDelete(Handle<Value> key);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001602
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001603 bool Has(uint32_t index);
ager@chromium.orge2902be2009-06-08 12:21:35 +00001604
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001605 bool Delete(uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001606
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001607 bool SetAccessor(Handle<String> name,
1608 AccessorGetter getter,
1609 AccessorSetter setter = 0,
1610 Handle<Value> data = Handle<Value>(),
1611 AccessControl settings = DEFAULT,
1612 PropertyAttribute attribute = None);
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00001613
ulan@chromium.org750145a2013-03-07 15:14:13 +00001614 // This function is not yet stable and should not be used at this time.
1615 bool SetAccessor(Handle<String> name,
1616 Handle<DeclaredAccessorDescriptor> descriptor,
1617 AccessControl settings = DEFAULT,
1618 PropertyAttribute attribute = None);
1619
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001620 /**
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001621 * Returns an array containing the names of the enumerable properties
1622 * of this object, including properties from prototype objects. The
1623 * array returned by this method contains the same values as would
1624 * be enumerated by a for-in statement over this object.
1625 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001626 Local<Array> GetPropertyNames();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001627
1628 /**
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001629 * This function has the same functionality as GetPropertyNames but
1630 * the returned array doesn't contain the names of properties from
1631 * prototype objects.
1632 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001633 Local<Array> GetOwnPropertyNames();
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001634
1635 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001636 * Get the prototype object. This does not skip objects marked to
1637 * be skipped by __proto__ and it does not consult the security
1638 * handler.
1639 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001640 Local<Value> GetPrototype();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001641
1642 /**
ager@chromium.org5c838252010-02-19 08:53:10 +00001643 * Set the prototype object. This does not skip objects marked to
1644 * be skipped by __proto__ and it does not consult the security
1645 * handler.
1646 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001647 bool SetPrototype(Handle<Value> prototype);
ager@chromium.org5c838252010-02-19 08:53:10 +00001648
1649 /**
sgjesse@chromium.org900d3b72009-08-07 11:24:25 +00001650 * Finds an instance of the given function template in the prototype
1651 * chain.
1652 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001653 Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl);
sgjesse@chromium.org900d3b72009-08-07 11:24:25 +00001654
1655 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001656 * Call builtin Object.prototype.toString on this object.
1657 * This is different from Value::ToString() that may call
1658 * user-defined toString function. This one does not.
1659 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001660 Local<String> ObjectProtoToString();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001661
ager@chromium.orgbeb25712010-11-29 08:02:25 +00001662 /**
yangguo@chromium.orgc74d6742012-06-29 15:15:45 +00001663 * Returns the function invoked as a constructor for this object.
1664 * May be the null value.
1665 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001666 Local<Value> GetConstructor();
yangguo@chromium.orgc74d6742012-06-29 15:15:45 +00001667
1668 /**
ager@chromium.orgbeb25712010-11-29 08:02:25 +00001669 * Returns the name of the function invoked as a constructor for this object.
1670 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001671 Local<String> GetConstructorName();
ager@chromium.orgbeb25712010-11-29 08:02:25 +00001672
kasper.lund212ac232008-07-16 07:07:30 +00001673 /** Gets the number of internal fields for this Object. */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001674 int InternalFieldCount();
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00001675
1676 /** Gets the value from an internal field. */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001677 V8_INLINE(Local<Value> GetInternalField(int index));
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00001678
kasper.lund212ac232008-07-16 07:07:30 +00001679 /** Sets the value in an internal field. */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001680 void SetInternalField(int index, Handle<Value> value);
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00001681
1682 /**
1683 * Gets a 2-byte-aligned native pointer from an internal field. This field
1684 * must have been set by SetAlignedPointerInInternalField, everything else
1685 * leads to undefined behavior.
1686 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001687 V8_INLINE(void* GetAlignedPointerFromInternalField(int index));
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00001688
1689 /**
1690 * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
1691 * a field, GetAlignedPointerFromInternalField must be used, everything else
1692 * leads to undefined behavior.
1693 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001694 void SetAlignedPointerInInternalField(int index, void* value);
kasperl@chromium.orge959c182009-07-27 08:59:04 +00001695
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001696 // Testers for local properties.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001697 bool HasOwnProperty(Handle<String> key);
1698 bool HasRealNamedProperty(Handle<String> key);
1699 bool HasRealIndexedProperty(uint32_t index);
1700 bool HasRealNamedCallbackProperty(Handle<String> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001701
1702 /**
1703 * If result.IsEmpty() no real property was located in the prototype chain.
1704 * This means interceptors in the prototype chain are not called.
1705 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001706 Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
sgjesse@chromium.org98aff2f2009-09-30 08:27:10 +00001707
1708 /**
1709 * If result.IsEmpty() no real property was located on the object or
1710 * in the prototype chain.
1711 * This means interceptors in the prototype chain are not called.
1712 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001713 Local<Value> GetRealNamedProperty(Handle<String> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001714
1715 /** Tests for a named lookup interceptor.*/
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001716 bool HasNamedLookupInterceptor();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001717
kasper.lund212ac232008-07-16 07:07:30 +00001718 /** Tests for an index lookup interceptor.*/
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001719 bool HasIndexedLookupInterceptor();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001720
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001721 /**
1722 * Turns on access check on the object if the object is an instance of
1723 * a template that has access check callbacks. If an object has no
1724 * access check info, the object cannot be accessed by anyone.
1725 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001726 void TurnOnAccessCheck();
ager@chromium.org41826e72009-03-30 13:30:57 +00001727
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001728 /**
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001729 * Returns the identity hash for this object. The current implementation
1730 * uses a hidden property on the object to store the identity hash.
ager@chromium.org5ec48922009-05-05 07:25:34 +00001731 *
ager@chromium.org9085a012009-05-11 19:22:57 +00001732 * The return value will never be 0. Also, it is not guaranteed to be
ager@chromium.org5ec48922009-05-05 07:25:34 +00001733 * unique.
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001734 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001735 int GetIdentityHash();
ager@chromium.org41826e72009-03-30 13:30:57 +00001736
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001737 /**
1738 * Access hidden properties on JavaScript objects. These properties are
1739 * hidden from the executing JavaScript and only accessible through the V8
1740 * C++ API. Hidden properties introduced by V8 internally (for example the
1741 * identity hash) are prefixed with "v8::".
1742 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001743 bool SetHiddenValue(Handle<String> key, Handle<Value> value);
1744 Local<Value> GetHiddenValue(Handle<String> key);
1745 bool DeleteHiddenValue(Handle<String> key);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001746
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001747 /**
1748 * Returns true if this is an instance of an api function (one
1749 * created from a function created from a function template) and has
1750 * been modified since it was created. Note that this method is
1751 * conservative and may return true for objects that haven't actually
1752 * been modified.
1753 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001754 bool IsDirty();
ager@chromium.org3b45ab52009-03-19 22:21:34 +00001755
1756 /**
1757 * Clone this object with a fast but shallow copy. Values will point
1758 * to the same values as the original object.
1759 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001760 Local<Object> Clone();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001761
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001762 /**
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001763 * Returns the context in which the object was created.
1764 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001765 Local<Context> CreationContext();
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001766
1767 /**
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001768 * Set the backing store of the indexed properties to be managed by the
1769 * embedding layer. Access to the indexed properties will follow the rules
1770 * spelled out in CanvasPixelArray.
1771 * Note: The embedding program still owns the data and needs to ensure that
1772 * the backing store is preserved while V8 has a reference.
1773 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001774 void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
1775 bool HasIndexedPropertiesInPixelData();
1776 uint8_t* GetIndexedPropertiesPixelData();
1777 int GetIndexedPropertiesPixelDataLength();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001778
ager@chromium.org3811b432009-10-28 14:53:37 +00001779 /**
1780 * Set the backing store of the indexed properties to be managed by the
1781 * embedding layer. Access to the indexed properties will follow the rules
1782 * spelled out for the CanvasArray subtypes in the WebGL specification.
1783 * Note: The embedding program still owns the data and needs to ensure that
1784 * the backing store is preserved while V8 has a reference.
1785 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001786 void SetIndexedPropertiesToExternalArrayData(void* data,
1787 ExternalArrayType array_type,
1788 int number_of_elements);
1789 bool HasIndexedPropertiesInExternalArrayData();
1790 void* GetIndexedPropertiesExternalArrayData();
1791 ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
1792 int GetIndexedPropertiesExternalArrayDataLength();
ager@chromium.org3811b432009-10-28 14:53:37 +00001793
lrn@chromium.org1c092762011-05-09 09:42:16 +00001794 /**
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001795 * Checks whether a callback is set by the
1796 * ObjectTemplate::SetCallAsFunctionHandler method.
1797 * When an Object is callable this method returns true.
1798 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001799 bool IsCallable();
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001800
1801 /**
fschneider@chromium.org1805e212011-09-05 10:49:12 +00001802 * Call an Object as a function if a callback is set by the
lrn@chromium.org1c092762011-05-09 09:42:16 +00001803 * ObjectTemplate::SetCallAsFunctionHandler method.
1804 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001805 Local<Value> CallAsFunction(Handle<Object> recv,
1806 int argc,
1807 Handle<Value> argv[]);
lrn@chromium.org1c092762011-05-09 09:42:16 +00001808
1809 /**
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001810 * Call an Object as a constructor if a callback is set by the
lrn@chromium.org1c092762011-05-09 09:42:16 +00001811 * ObjectTemplate::SetCallAsFunctionHandler method.
1812 * Note: This method behaves like the Function::NewInstance method.
1813 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001814 Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]);
lrn@chromium.org1c092762011-05-09 09:42:16 +00001815
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001816 static Local<Object> New();
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001817 V8_INLINE(static Object* Cast(Value* obj));
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00001818
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001819 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001820 Object();
1821 static void CheckCast(Value* obj);
1822 Local<Value> SlowGetInternalField(int index);
1823 void* SlowGetAlignedPointerFromInternalField(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001824};
1825
1826
1827/**
1828 * An instance of the built-in array constructor (ECMA-262, 15.4.2).
1829 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001830class V8EXPORT Array : public Object {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001831 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001832 uint32_t Length() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001833
ager@chromium.org3e875802009-06-29 08:26:34 +00001834 /**
1835 * Clones an element at index |index|. Returns an empty
1836 * handle if cloning fails (for any reason).
1837 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001838 Local<Object> CloneElementAt(uint32_t index);
ager@chromium.org3e875802009-06-29 08:26:34 +00001839
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +00001840 /**
1841 * Creates a JavaScript array with the given length. If the length
1842 * is negative the returned array will have length 0.
1843 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001844 static Local<Array> New(int length = 0);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +00001845
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001846 V8_INLINE(static Array* Cast(Value* obj));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001847 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001848 Array();
1849 static void CheckCast(Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001850};
1851
1852
1853/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00001854 * A JavaScript function object (ECMA-262, 15.3).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001855 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001856class V8EXPORT Function : public Object {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001857 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001858 Local<Object> NewInstance() const;
1859 Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
1860 Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]);
1861 void SetName(Handle<String> name);
1862 Handle<Value> GetName() const;
ager@chromium.org5c838252010-02-19 08:53:10 +00001863
1864 /**
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00001865 * Name inferred from variable or property assignment of this function.
1866 * Used to facilitate debugging and profiling of JavaScript code written
1867 * in an OO style, where many functions are anonymous but are assigned
1868 * to object properties.
1869 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001870 Handle<Value> GetInferredName() const;
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00001871
1872 /**
ager@chromium.org5c838252010-02-19 08:53:10 +00001873 * Returns zero based line number of function body and
1874 * kLineOffsetNotFound if no information available.
1875 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001876 int GetScriptLineNumber() const;
danno@chromium.orgc612e022011-11-10 11:38:15 +00001877 /**
1878 * Returns zero based column number of function body and
1879 * kLineOffsetNotFound if no information available.
1880 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001881 int GetScriptColumnNumber() const;
1882 Handle<Value> GetScriptId() const;
1883 ScriptOrigin GetScriptOrigin() const;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001884 V8_INLINE(static Function* Cast(Value* obj));
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001885 static const int kLineOffsetNotFound;
danno@chromium.orgc612e022011-11-10 11:38:15 +00001886
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001887 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001888 Function();
1889 static void CheckCast(Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001890};
1891
1892
1893/**
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001894 * An instance of the built-in Date constructor (ECMA-262, 15.9).
1895 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001896class V8EXPORT Date : public Object {
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001897 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001898 static Local<Value> New(double time);
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001899
1900 /**
1901 * A specialization of Value::NumberValue that is more efficient
1902 * because we know the structure of this object.
1903 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001904 double NumberValue() const;
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001905
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001906 V8_INLINE(static Date* Cast(v8::Value* obj));
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001907
1908 /**
1909 * Notification that the embedder has changed the time zone,
1910 * daylight savings time, or other date / time configuration
1911 * parameters. V8 keeps a cache of various values used for
1912 * date / time computation. This notification will reset
1913 * those cached values for the current context so that date /
1914 * time configuration changes would be reflected in the Date
1915 * object.
1916 *
1917 * This API should not be called more than needed as it will
1918 * negatively impact the performance of date operations.
1919 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001920 static void DateTimeConfigurationChangeNotification();
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001921
1922 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001923 static void CheckCast(v8::Value* obj);
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001924};
1925
1926
1927/**
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001928 * A Number object (ECMA-262, 4.3.21).
1929 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001930class V8EXPORT NumberObject : public Object {
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001931 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001932 static Local<Value> New(double value);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001933
1934 /**
1935 * Returns the Number held by the object.
1936 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001937 double NumberValue() const;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001938
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001939 V8_INLINE(static NumberObject* Cast(v8::Value* obj));
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001940
1941 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001942 static void CheckCast(v8::Value* obj);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001943};
1944
1945
1946/**
1947 * A Boolean object (ECMA-262, 4.3.15).
1948 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001949class V8EXPORT BooleanObject : public Object {
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001950 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001951 static Local<Value> New(bool value);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001952
1953 /**
1954 * Returns the Boolean held by the object.
1955 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001956 bool BooleanValue() const;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001957
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001958 V8_INLINE(static BooleanObject* Cast(v8::Value* obj));
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001959
1960 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001961 static void CheckCast(v8::Value* obj);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001962};
1963
1964
1965/**
1966 * A String object (ECMA-262, 4.3.18).
1967 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001968class V8EXPORT StringObject : public Object {
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001969 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001970 static Local<Value> New(Handle<String> value);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001971
1972 /**
1973 * Returns the String held by the object.
1974 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001975 Local<String> StringValue() const;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001976
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001977 V8_INLINE(static StringObject* Cast(v8::Value* obj));
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001978
1979 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001980 static void CheckCast(v8::Value* obj);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001981};
1982
1983
1984/**
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001985 * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
1986 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00001987class V8EXPORT RegExp : public Object {
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001988 public:
1989 /**
1990 * Regular expression flag bits. They can be or'ed to enable a set
1991 * of flags.
1992 */
1993 enum Flags {
1994 kNone = 0,
1995 kGlobal = 1,
1996 kIgnoreCase = 2,
1997 kMultiline = 4
1998 };
1999
2000 /**
2001 * Creates a regular expression from the given pattern string and
2002 * the flags bit field. May throw a JavaScript exception as
2003 * described in ECMA-262, 15.10.4.1.
2004 *
2005 * For example,
2006 * RegExp::New(v8::String::New("foo"),
2007 * static_cast<RegExp::Flags>(kGlobal | kMultiline))
2008 * is equivalent to evaluating "/foo/gm".
2009 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002010 static Local<RegExp> New(Handle<String> pattern, Flags flags);
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002011
2012 /**
2013 * Returns the value of the source property: a string representing
2014 * the regular expression.
2015 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002016 Local<String> GetSource() const;
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002017
2018 /**
2019 * Returns the flags bit field.
2020 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002021 Flags GetFlags() const;
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002022
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002023 V8_INLINE(static RegExp* Cast(v8::Value* obj));
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002024
2025 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002026 static void CheckCast(v8::Value* obj);
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002027};
2028
2029
2030/**
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00002031 * A JavaScript value that wraps a C++ void*. This type of value is mainly used
2032 * to associate C++ data structures with JavaScript objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002033 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002034class V8EXPORT External : public Value {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002035 public:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002036 static Local<External> New(void* value);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002037 V8_INLINE(static External* Cast(Value* obj));
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002038 void* Value() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002039 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002040 static void CheckCast(v8::Value* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002041};
2042
2043
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002044// --- Templates ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002045
2046
2047/**
2048 * The superclass of object and function templates.
2049 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002050class V8EXPORT Template : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002051 public:
2052 /** Adds a property to each instance created by this template.*/
2053 void Set(Handle<String> name, Handle<Data> value,
2054 PropertyAttribute attributes = None);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002055 V8_INLINE(void Set(const char* name, Handle<Data> value));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002056 private:
2057 Template();
2058
2059 friend class ObjectTemplate;
2060 friend class FunctionTemplate;
2061};
2062
2063
2064/**
2065 * The argument information given to function call callbacks. This
v8.team.kasperl727e9952008-09-02 14:56:44 +00002066 * class provides access to information about the context of the call,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002067 * including the receiver, the number and values of arguments, and
2068 * the holder of the function.
2069 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00002070class V8EXPORT Arguments {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002071 public:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002072 V8_INLINE(int Length() const);
2073 V8_INLINE(Local<Value> operator[](int i) const);
2074 V8_INLINE(Local<Function> Callee() const);
2075 V8_INLINE(Local<Object> This() const);
2076 V8_INLINE(Local<Object> Holder() const);
2077 V8_INLINE(bool IsConstructCall() const);
2078 V8_INLINE(Local<Value> Data() const);
2079 V8_INLINE(Isolate* GetIsolate() const);
jkummerow@chromium.org3ee08a62012-04-13 13:01:33 +00002080
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002081 private:
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00002082 static const int kIsolateIndex = 0;
2083 static const int kDataIndex = -1;
2084 static const int kCalleeIndex = -2;
2085 static const int kHolderIndex = -3;
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00002086
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002087 friend class ImplementationUtilities;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002088 V8_INLINE(Arguments(internal::Object** implicit_args,
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00002089 internal::Object** values,
2090 int length,
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002091 bool is_construct_call));
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00002092 internal::Object** implicit_args_;
2093 internal::Object** values_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002094 int length_;
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00002095 bool is_construct_call_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002096};
2097
2098
2099/**
2100 * The information passed to an accessor callback about the context
2101 * of the property access.
2102 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002103class V8EXPORT AccessorInfo {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002104 public:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002105 V8_INLINE(AccessorInfo(internal::Object** args))
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002106 : args_(args) { }
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002107 V8_INLINE(Isolate* GetIsolate() const);
2108 V8_INLINE(Local<Value> Data() const);
2109 V8_INLINE(Local<Object> This() const);
2110 V8_INLINE(Local<Object> Holder() const);
jkummerow@chromium.org3ee08a62012-04-13 13:01:33 +00002111
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002112 private:
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002113 internal::Object** args_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002114};
2115
2116
2117typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
2118
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002119/**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002120 * NamedProperty[Getter|Setter] are used as interceptors on object.
2121 * See ObjectTemplate::SetNamedPropertyHandler.
2122 */
2123typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
2124 const AccessorInfo& info);
2125
2126
2127/**
2128 * Returns the value if the setter intercepts the request.
2129 * Otherwise, returns an empty handle.
2130 */
2131typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
2132 Local<Value> value,
2133 const AccessorInfo& info);
2134
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002135/**
2136 * Returns a non-empty handle if the interceptor intercepts the request.
whesse@chromium.org2c186ca2010-06-16 11:32:39 +00002137 * The result is an integer encoding property attributes (like v8::None,
2138 * v8::DontEnum, etc.)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002139 */
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00002140typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
2141 const AccessorInfo& info);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002142
2143
2144/**
2145 * Returns a non-empty handle if the deleter intercepts the request.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002146 * The return value is true if the property could be deleted and false
2147 * otherwise.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002148 */
2149typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
2150 const AccessorInfo& info);
2151
2152/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002153 * Returns an array containing the names of the properties the named
2154 * property getter intercepts.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002155 */
2156typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
2157
v8.team.kasperl727e9952008-09-02 14:56:44 +00002158
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002159/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002160 * Returns the value of the property if the getter intercepts the
2161 * request. Otherwise, returns an empty handle.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002162 */
2163typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
2164 const AccessorInfo& info);
2165
2166
2167/**
2168 * Returns the value if the setter intercepts the request.
2169 * Otherwise, returns an empty handle.
2170 */
2171typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
2172 Local<Value> value,
2173 const AccessorInfo& info);
2174
2175
2176/**
2177 * Returns a non-empty handle if the interceptor intercepts the request.
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002178 * The result is an integer encoding property attributes.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002179 */
vegorov@chromium.org26c16f82010-08-11 13:41:03 +00002180typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
2181 const AccessorInfo& info);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002182
2183/**
2184 * Returns a non-empty handle if the deleter intercepts the request.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002185 * The return value is true if the property could be deleted and false
2186 * otherwise.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002187 */
2188typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
2189 const AccessorInfo& info);
2190
v8.team.kasperl727e9952008-09-02 14:56:44 +00002191/**
2192 * Returns an array containing the indices of the properties the
2193 * indexed property getter intercepts.
2194 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002195typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
2196
2197
2198/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002199 * Access type specification.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002200 */
2201enum AccessType {
2202 ACCESS_GET,
2203 ACCESS_SET,
2204 ACCESS_HAS,
2205 ACCESS_DELETE,
2206 ACCESS_KEYS
2207};
2208
v8.team.kasperl727e9952008-09-02 14:56:44 +00002209
2210/**
2211 * Returns true if cross-context access should be allowed to the named
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00002212 * property with the given key on the host object.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002213 */
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00002214typedef bool (*NamedSecurityCallback)(Local<Object> host,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002215 Local<Value> key,
2216 AccessType type,
2217 Local<Value> data);
2218
v8.team.kasperl727e9952008-09-02 14:56:44 +00002219
2220/**
2221 * Returns true if cross-context access should be allowed to the indexed
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00002222 * property with the given index on the host object.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002223 */
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00002224typedef bool (*IndexedSecurityCallback)(Local<Object> host,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002225 uint32_t index,
2226 AccessType type,
2227 Local<Value> data);
2228
2229
2230/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002231 * A FunctionTemplate is used to create functions at runtime. There
2232 * can only be one function created from a FunctionTemplate in a
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002233 * context. The lifetime of the created function is equal to the
2234 * lifetime of the context. So in case the embedder needs to create
2235 * temporary functions that can be collected using Scripts is
2236 * preferred.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002237 *
2238 * A FunctionTemplate can have properties, these properties are added to the
v8.team.kasperl727e9952008-09-02 14:56:44 +00002239 * function object when it is created.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002240 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002241 * A FunctionTemplate has a corresponding instance template which is
2242 * used to create object instances when the function is used as a
2243 * constructor. Properties added to the instance template are added to
2244 * each object instance.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002245 *
2246 * A FunctionTemplate can have a prototype template. The prototype template
2247 * is used to create the prototype object of the function.
2248 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002249 * The following example shows how to use a FunctionTemplate:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002250 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002251 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002252 * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
2253 * t->Set("func_property", v8::Number::New(1));
2254 *
2255 * v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
2256 * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
2257 * proto_t->Set("proto_const", v8::Number::New(2));
2258 *
2259 * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
2260 * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
2261 * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
2262 * instance_t->Set("instance_property", Number::New(3));
2263 *
2264 * v8::Local<v8::Function> function = t->GetFunction();
2265 * v8::Local<v8::Object> instance = function->NewInstance();
v8.team.kasperl727e9952008-09-02 14:56:44 +00002266 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002267 *
2268 * Let's use "function" as the JS variable name of the function object
v8.team.kasperl727e9952008-09-02 14:56:44 +00002269 * and "instance" for the instance object created above. The function
2270 * and the instance will have the following properties:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002271 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002272 * \code
2273 * func_property in function == true;
2274 * function.func_property == 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002275 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002276 * function.prototype.proto_method() invokes 'InvokeCallback'
2277 * function.prototype.proto_const == 2;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002278 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002279 * instance instanceof function == true;
2280 * instance.instance_accessor calls 'InstanceAccessorCallback'
2281 * instance.instance_property == 3;
2282 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002283 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002284 * A FunctionTemplate can inherit from another one by calling the
2285 * FunctionTemplate::Inherit method. The following graph illustrates
2286 * the semantics of inheritance:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002287 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002288 * \code
2289 * FunctionTemplate Parent -> Parent() . prototype -> { }
2290 * ^ ^
2291 * | Inherit(Parent) | .__proto__
2292 * | |
2293 * FunctionTemplate Child -> Child() . prototype -> { }
2294 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002295 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002296 * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
2297 * object of the Child() function has __proto__ pointing to the
2298 * Parent() function's prototype object. An instance of the Child
2299 * function has all properties on Parent's instance templates.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002300 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002301 * Let Parent be the FunctionTemplate initialized in the previous
2302 * section and create a Child FunctionTemplate by:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002303 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002304 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002305 * Local<FunctionTemplate> parent = t;
2306 * Local<FunctionTemplate> child = FunctionTemplate::New();
2307 * child->Inherit(parent);
2308 *
2309 * Local<Function> child_function = child->GetFunction();
2310 * Local<Object> child_instance = child_function->NewInstance();
v8.team.kasperl727e9952008-09-02 14:56:44 +00002311 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002312 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00002313 * The Child function and Child instance will have the following
2314 * properties:
2315 *
2316 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002317 * child_func.prototype.__proto__ == function.prototype;
v8.team.kasperl727e9952008-09-02 14:56:44 +00002318 * child_instance.instance_accessor calls 'InstanceAccessorCallback'
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002319 * child_instance.instance_property == 3;
v8.team.kasperl727e9952008-09-02 14:56:44 +00002320 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002321 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002322class V8EXPORT FunctionTemplate : public Template {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002323 public:
2324 /** Creates a function template.*/
v8.team.kasperl727e9952008-09-02 14:56:44 +00002325 static Local<FunctionTemplate> New(
2326 InvocationCallback callback = 0,
2327 Handle<Value> data = Handle<Value>(),
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00002328 Handle<Signature> signature = Handle<Signature>(),
2329 int length = 0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002330 /** Returns the unique function instance in the current execution context.*/
2331 Local<Function> GetFunction();
2332
v8.team.kasperl727e9952008-09-02 14:56:44 +00002333 /**
2334 * Set the call-handler callback for a FunctionTemplate. This
2335 * callback is called whenever the function created from this
2336 * FunctionTemplate is called.
2337 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002338 void SetCallHandler(InvocationCallback callback,
2339 Handle<Value> data = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002340
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00002341 /** Set the predefined length property for the FunctionTemplate. */
2342 void SetLength(int length);
2343
v8.team.kasperl727e9952008-09-02 14:56:44 +00002344 /** Get the InstanceTemplate. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002345 Local<ObjectTemplate> InstanceTemplate();
2346
2347 /** Causes the function template to inherit from a parent function template.*/
2348 void Inherit(Handle<FunctionTemplate> parent);
2349
2350 /**
2351 * A PrototypeTemplate is the template used to create the prototype object
2352 * of the function created by this template.
2353 */
2354 Local<ObjectTemplate> PrototypeTemplate();
2355
v8.team.kasperl727e9952008-09-02 14:56:44 +00002356 /**
2357 * Set the class name of the FunctionTemplate. This is used for
2358 * printing objects created with the function created from the
2359 * FunctionTemplate as its constructor.
2360 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002361 void SetClassName(Handle<String> name);
2362
2363 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002364 * Determines whether the __proto__ accessor ignores instances of
2365 * the function template. If instances of the function template are
2366 * ignored, __proto__ skips all instances and instead returns the
2367 * next object in the prototype chain.
2368 *
2369 * Call with a value of true to make the __proto__ accessor ignore
2370 * instances of the function template. Call with a value of false
2371 * to make the __proto__ accessor not ignore instances of the
2372 * function template. By default, instances of a function template
2373 * are not ignored.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002374 */
2375 void SetHiddenPrototype(bool value);
2376
2377 /**
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002378 * Sets the ReadOnly flag in the attributes of the 'prototype' property
2379 * of functions created from this FunctionTemplate to true.
ager@chromium.org04921a82011-06-27 13:21:41 +00002380 */
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002381 void ReadOnlyPrototype();
ager@chromium.org04921a82011-06-27 13:21:41 +00002382
2383 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002384 * Returns true if the given object is an instance of this function
2385 * template.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002386 */
2387 bool HasInstance(Handle<Value> object);
2388
2389 private:
2390 FunctionTemplate();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002391 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
2392 NamedPropertySetter setter,
2393 NamedPropertyQuery query,
2394 NamedPropertyDeleter remover,
2395 NamedPropertyEnumerator enumerator,
whesse@chromium.org2c186ca2010-06-16 11:32:39 +00002396 Handle<Value> data);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002397 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
2398 IndexedPropertySetter setter,
2399 IndexedPropertyQuery query,
2400 IndexedPropertyDeleter remover,
2401 IndexedPropertyEnumerator enumerator,
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002402 Handle<Value> data);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002403 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
2404 Handle<Value> data);
2405
2406 friend class Context;
2407 friend class ObjectTemplate;
2408};
2409
2410
2411/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002412 * An ObjectTemplate is used to create objects at runtime.
2413 *
2414 * Properties added to an ObjectTemplate are added to each object
2415 * created from the ObjectTemplate.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002416 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002417class V8EXPORT ObjectTemplate : public Template {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002418 public:
v8.team.kasperl727e9952008-09-02 14:56:44 +00002419 /** Creates an ObjectTemplate. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002420 static Local<ObjectTemplate> New();
v8.team.kasperl727e9952008-09-02 14:56:44 +00002421
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002422 /** Creates a new instance of this template.*/
2423 Local<Object> NewInstance();
2424
2425 /**
2426 * Sets an accessor on the object template.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002427 *
2428 * Whenever the property with the given name is accessed on objects
2429 * created from this ObjectTemplate the getter and setter callbacks
2430 * are called instead of getting and setting the property directly
2431 * on the JavaScript object.
2432 *
2433 * \param name The name of the property for which an accessor is added.
2434 * \param getter The callback to invoke when getting the property.
2435 * \param setter The callback to invoke when setting the property.
2436 * \param data A piece of data that will be passed to the getter and setter
2437 * callbacks whenever they are invoked.
2438 * \param settings Access control settings for the accessor. This is a bit
2439 * field consisting of one of more of
2440 * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
2441 * The default is to not allow cross-context access.
2442 * ALL_CAN_READ means that all cross-context reads are allowed.
2443 * ALL_CAN_WRITE means that all cross-context writes are allowed.
2444 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
2445 * cross-context access.
2446 * \param attribute The attributes of the property for which an accessor
2447 * is added.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002448 * \param signature The signature describes valid receivers for the accessor
2449 * and is used to perform implicit instance checks against them. If the
2450 * receiver is incompatible (i.e. is not an instance of the constructor as
2451 * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
2452 * thrown and no callback is invoked.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002453 */
2454 void SetAccessor(Handle<String> name,
2455 AccessorGetter getter,
2456 AccessorSetter setter = 0,
2457 Handle<Value> data = Handle<Value>(),
2458 AccessControl settings = DEFAULT,
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002459 PropertyAttribute attribute = None,
2460 Handle<AccessorSignature> signature =
2461 Handle<AccessorSignature>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002462
ulan@chromium.org750145a2013-03-07 15:14:13 +00002463 // This function is not yet stable and should not be used at this time.
2464 bool SetAccessor(Handle<String> name,
2465 Handle<DeclaredAccessorDescriptor> descriptor,
2466 AccessControl settings = DEFAULT,
2467 PropertyAttribute attribute = None,
2468 Handle<AccessorSignature> signature =
2469 Handle<AccessorSignature>());
2470
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002471 /**
2472 * Sets a named property handler on the object template.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002473 *
2474 * Whenever a named property is accessed on objects created from
2475 * this object template, the provided callback is invoked instead of
2476 * accessing the property directly on the JavaScript object.
2477 *
2478 * \param getter The callback to invoke when getting a property.
2479 * \param setter The callback to invoke when setting a property.
whesse@chromium.org2c186ca2010-06-16 11:32:39 +00002480 * \param query The callback to invoke to check if a property is present,
2481 * and if present, get its attributes.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002482 * \param deleter The callback to invoke when deleting a property.
2483 * \param enumerator The callback to invoke to enumerate all the named
2484 * properties of an object.
2485 * \param data A piece of data that will be passed to the callbacks
2486 * whenever they are invoked.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002487 */
2488 void SetNamedPropertyHandler(NamedPropertyGetter getter,
2489 NamedPropertySetter setter = 0,
2490 NamedPropertyQuery query = 0,
2491 NamedPropertyDeleter deleter = 0,
2492 NamedPropertyEnumerator enumerator = 0,
whesse@chromium.org2c186ca2010-06-16 11:32:39 +00002493 Handle<Value> data = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002494
2495 /**
2496 * Sets an indexed property handler on the object template.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002497 *
2498 * Whenever an indexed property is accessed on objects created from
2499 * this object template, the provided callback is invoked instead of
2500 * accessing the property directly on the JavaScript object.
2501 *
2502 * \param getter The callback to invoke when getting a property.
2503 * \param setter The callback to invoke when setting a property.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00002504 * \param query The callback to invoke to check if an object has a property.
v8.team.kasperl727e9952008-09-02 14:56:44 +00002505 * \param deleter The callback to invoke when deleting a property.
2506 * \param enumerator The callback to invoke to enumerate all the indexed
2507 * properties of an object.
2508 * \param data A piece of data that will be passed to the callbacks
2509 * whenever they are invoked.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002510 */
2511 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
2512 IndexedPropertySetter setter = 0,
2513 IndexedPropertyQuery query = 0,
2514 IndexedPropertyDeleter deleter = 0,
2515 IndexedPropertyEnumerator enumerator = 0,
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002516 Handle<Value> data = Handle<Value>());
vegorov@chromium.org26c16f82010-08-11 13:41:03 +00002517
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002518 /**
2519 * Sets the callback to be used when calling instances created from
2520 * this template as a function. If no callback is set, instances
v8.team.kasperl727e9952008-09-02 14:56:44 +00002521 * behave like normal JavaScript objects that cannot be called as a
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002522 * function.
2523 */
2524 void SetCallAsFunctionHandler(InvocationCallback callback,
2525 Handle<Value> data = Handle<Value>());
2526
v8.team.kasperl727e9952008-09-02 14:56:44 +00002527 /**
2528 * Mark object instances of the template as undetectable.
2529 *
2530 * In many ways, undetectable objects behave as though they are not
2531 * there. They behave like 'undefined' in conditionals and when
2532 * printed. However, properties can be accessed and called as on
2533 * normal objects.
2534 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002535 void MarkAsUndetectable();
2536
v8.team.kasperl727e9952008-09-02 14:56:44 +00002537 /**
2538 * Sets access check callbacks on the object template.
2539 *
2540 * When accessing properties on instances of this object template,
2541 * the access check callback will be called to determine whether or
2542 * not to allow cross-context access to the properties.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002543 * The last parameter specifies whether access checks are turned
2544 * on by default on instances. If access checks are off by default,
2545 * they can be turned on on individual instances by calling
2546 * Object::TurnOnAccessCheck().
v8.team.kasperl727e9952008-09-02 14:56:44 +00002547 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002548 void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
2549 IndexedSecurityCallback indexed_handler,
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002550 Handle<Value> data = Handle<Value>(),
2551 bool turned_on_by_default = true);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002552
kasper.lund212ac232008-07-16 07:07:30 +00002553 /**
2554 * Gets the number of internal fields for objects generated from
2555 * this template.
2556 */
2557 int InternalFieldCount();
2558
2559 /**
2560 * Sets the number of internal fields for objects generated from
2561 * this template.
2562 */
2563 void SetInternalFieldCount(int value);
2564
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002565 private:
2566 ObjectTemplate();
2567 static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
2568 friend class FunctionTemplate;
2569};
2570
2571
2572/**
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002573 * A Signature specifies which receivers and arguments are valid
2574 * parameters to a function.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002575 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002576class V8EXPORT Signature : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002577 public:
2578 static Local<Signature> New(Handle<FunctionTemplate> receiver =
2579 Handle<FunctionTemplate>(),
2580 int argc = 0,
2581 Handle<FunctionTemplate> argv[] = 0);
2582 private:
2583 Signature();
2584};
2585
2586
2587/**
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002588 * An AccessorSignature specifies which receivers are valid parameters
2589 * to an accessor callback.
2590 */
2591class V8EXPORT AccessorSignature : public Data {
2592 public:
2593 static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver =
2594 Handle<FunctionTemplate>());
2595 private:
2596 AccessorSignature();
2597};
2598
2599
ulan@chromium.org750145a2013-03-07 15:14:13 +00002600class V8EXPORT DeclaredAccessorDescriptor : public Data {
2601 private:
2602 DeclaredAccessorDescriptor();
2603};
2604
2605
2606class V8EXPORT ObjectOperationDescriptor : public Data {
2607 public:
2608 // This function is not yet stable and should not be used at this time.
2609 static Local<RawOperationDescriptor> NewInternalFieldDereference(
2610 Isolate* isolate,
2611 int internal_field);
2612 private:
2613 ObjectOperationDescriptor();
2614};
2615
2616
2617enum DeclaredAccessorDescriptorDataType {
2618 kDescriptorBoolType,
2619 kDescriptorInt8Type, kDescriptorUint8Type,
2620 kDescriptorInt16Type, kDescriptorUint16Type,
2621 kDescriptorInt32Type, kDescriptorUint32Type,
2622 kDescriptorFloatType, kDescriptorDoubleType
2623};
2624
2625
2626class V8EXPORT RawOperationDescriptor : public Data {
2627 public:
2628 Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate);
2629 Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate);
2630 Local<RawOperationDescriptor> NewRawShift(Isolate* isolate,
2631 int16_t byte_offset);
2632 Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate,
2633 void* compare_value);
2634 Local<DeclaredAccessorDescriptor> NewPrimitiveValue(
2635 Isolate* isolate,
2636 DeclaredAccessorDescriptorDataType data_type,
2637 uint8_t bool_offset = 0);
2638 Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate,
2639 uint8_t bitmask,
2640 uint8_t compare_value);
2641 Local<DeclaredAccessorDescriptor> NewBitmaskCompare16(
2642 Isolate* isolate,
2643 uint16_t bitmask,
2644 uint16_t compare_value);
2645 Local<DeclaredAccessorDescriptor> NewBitmaskCompare32(
2646 Isolate* isolate,
2647 uint32_t bitmask,
2648 uint32_t compare_value);
2649
2650 private:
2651 RawOperationDescriptor();
2652};
2653
2654
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002655/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002656 * A utility for determining the type of objects based on the template
2657 * they were constructed from.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002658 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002659class V8EXPORT TypeSwitch : public Data {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002660 public:
2661 static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
2662 static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
2663 int match(Handle<Value> value);
2664 private:
2665 TypeSwitch();
2666};
2667
2668
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002669// --- Extensions ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002670
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002671class V8EXPORT ExternalAsciiStringResourceImpl
2672 : public String::ExternalAsciiStringResource {
2673 public:
2674 ExternalAsciiStringResourceImpl() : data_(0), length_(0) {}
2675 ExternalAsciiStringResourceImpl(const char* data, size_t length)
2676 : data_(data), length_(length) {}
2677 const char* data() const { return data_; }
2678 size_t length() const { return length_; }
2679
2680 private:
2681 const char* data_;
2682 size_t length_;
2683};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002684
2685/**
2686 * Ignore
2687 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002688class V8EXPORT Extension { // NOLINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002689 public:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002690 // Note that the strings passed into this constructor must live as long
2691 // as the Extension itself.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002692 Extension(const char* name,
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002693 const char* source = 0,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002694 int dep_count = 0,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002695 const char** deps = 0,
2696 int source_length = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002697 virtual ~Extension() { }
2698 virtual v8::Handle<v8::FunctionTemplate>
2699 GetNativeFunction(v8::Handle<v8::String> name) {
2700 return v8::Handle<v8::FunctionTemplate>();
2701 }
2702
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002703 const char* name() const { return name_; }
2704 size_t source_length() const { return source_length_; }
2705 const String::ExternalAsciiStringResource* source() const {
2706 return &source_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002707 int dependency_count() { return dep_count_; }
2708 const char** dependencies() { return deps_; }
2709 void set_auto_enable(bool value) { auto_enable_ = value; }
2710 bool auto_enable() { return auto_enable_; }
2711
2712 private:
2713 const char* name_;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002714 size_t source_length_; // expected to initialize before source_
2715 ExternalAsciiStringResourceImpl source_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002716 int dep_count_;
2717 const char** deps_;
2718 bool auto_enable_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00002719
2720 // Disallow copying and assigning.
2721 Extension(const Extension&);
2722 void operator=(const Extension&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002723};
2724
2725
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002726void V8EXPORT RegisterExtension(Extension* extension);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002727
2728
2729/**
2730 * Ignore
2731 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002732class V8EXPORT DeclareExtension {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002733 public:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002734 V8_INLINE(DeclareExtension(Extension* extension)) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002735 RegisterExtension(extension);
2736 }
2737};
2738
2739
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002740// --- Statics ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002741
2742
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002743Handle<Primitive> V8EXPORT Undefined();
2744Handle<Primitive> V8EXPORT Null();
2745Handle<Boolean> V8EXPORT True();
2746Handle<Boolean> V8EXPORT False();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002747
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002748V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate));
2749V8_INLINE(Handle<Primitive> Null(Isolate* isolate));
2750V8_INLINE(Handle<Boolean> True(Isolate* isolate));
2751V8_INLINE(Handle<Boolean> False(Isolate* isolate));
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00002752
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002753
2754/**
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002755 * A set of constraints that specifies the limits of the runtime's memory use.
2756 * You must set the heap size before initializing the VM - the size cannot be
2757 * adjusted after the VM is initialized.
2758 *
2759 * If you are using threads then you should hold the V8::Locker lock while
2760 * setting the stack limit and you must set a non-default stack limit separately
2761 * for each thread.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002762 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002763class V8EXPORT ResourceConstraints {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002764 public:
2765 ResourceConstraints();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002766 int max_young_space_size() const { return max_young_space_size_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002767 void set_max_young_space_size(int value) { max_young_space_size_ = value; }
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002768 int max_old_space_size() const { return max_old_space_size_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002769 void set_max_old_space_size(int value) { max_old_space_size_ = value; }
ager@chromium.org01fe7df2010-11-10 11:59:11 +00002770 int max_executable_size() { return max_executable_size_; }
2771 void set_max_executable_size(int value) { max_executable_size_ = value; }
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002772 uint32_t* stack_limit() const { return stack_limit_; }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00002773 // Sets an address beyond which the VM's stack may not grow.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002774 void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
2775 private:
2776 int max_young_space_size_;
2777 int max_old_space_size_;
ager@chromium.org01fe7df2010-11-10 11:59:11 +00002778 int max_executable_size_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002779 uint32_t* stack_limit_;
2780};
2781
2782
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +00002783bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002784
2785
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002786// --- Exceptions ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002787
2788
2789typedef void (*FatalErrorCallback)(const char* location, const char* message);
2790
2791
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00002792typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002793
2794
2795/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00002796 * Schedules an exception to be thrown when returning to JavaScript. When an
2797 * exception has been scheduled it is illegal to invoke any JavaScript
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002798 * operation; the caller must return immediately and only after the exception
v8.team.kasperl727e9952008-09-02 14:56:44 +00002799 * has been handled does it become legal to invoke JavaScript operations.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002800 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002801Handle<Value> V8EXPORT ThrowException(Handle<Value> exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002802
2803/**
2804 * Create new error objects by calling the corresponding error object
2805 * constructor with the message.
2806 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002807class V8EXPORT Exception {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002808 public:
2809 static Local<Value> RangeError(Handle<String> message);
2810 static Local<Value> ReferenceError(Handle<String> message);
2811 static Local<Value> SyntaxError(Handle<String> message);
2812 static Local<Value> TypeError(Handle<String> message);
2813 static Local<Value> Error(Handle<String> message);
2814};
2815
2816
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002817// --- Counters Callbacks ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002818
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002819typedef int* (*CounterLookupCallback)(const char* name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002820
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002821typedef void* (*CreateHistogramCallback)(const char* name,
2822 int min,
2823 int max,
2824 size_t buckets);
2825
2826typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
2827
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002828// --- Memory Allocation Callback ---
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +00002829 enum ObjectSpace {
2830 kObjectSpaceNewSpace = 1 << 0,
2831 kObjectSpaceOldPointerSpace = 1 << 1,
2832 kObjectSpaceOldDataSpace = 1 << 2,
2833 kObjectSpaceCodeSpace = 1 << 3,
2834 kObjectSpaceMapSpace = 1 << 4,
2835 kObjectSpaceLoSpace = 1 << 5,
2836
2837 kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
2838 kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
2839 kObjectSpaceLoSpace
2840 };
2841
2842 enum AllocationAction {
2843 kAllocationActionAllocate = 1 << 0,
2844 kAllocationActionFree = 1 << 1,
2845 kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
2846 };
2847
2848typedef void (*MemoryAllocationCallback)(ObjectSpace space,
2849 AllocationAction action,
2850 int size);
2851
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00002852// --- Leave Script Callback ---
2853typedef void (*CallCompletedCallback)();
2854
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002855// --- Failed Access Check Callback ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002856typedef void (*FailedAccessCheckCallback)(Local<Object> target,
2857 AccessType type,
2858 Local<Value> data);
2859
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00002860// --- AllowCodeGenerationFromStrings callbacks ---
2861
2862/**
2863 * Callback to check if code generation from strings is allowed. See
2864 * Context::AllowCodeGenerationFromStrings.
2865 */
2866typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
2867
2868// --- Garbage Collection Callbacks ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002869
2870/**
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00002871 * Applications can register callback functions which will be called
2872 * before and after a garbage collection. Allocations are not
2873 * allowed in the callback functions, you therefore cannot manipulate
v8.team.kasperl727e9952008-09-02 14:56:44 +00002874 * objects (set or delete properties for example) since it is possible
2875 * such operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002876 */
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00002877enum GCType {
2878 kGCTypeScavenge = 1 << 0,
2879 kGCTypeMarkSweepCompact = 1 << 1,
2880 kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
2881};
2882
2883enum GCCallbackFlags {
2884 kNoGCCallbackFlags = 0,
2885 kGCCallbackFlagCompacted = 1 << 0
2886};
2887
2888typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
2889typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
2890
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002891typedef void (*GCCallback)();
2892
2893
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002894/**
ager@chromium.org3811b432009-10-28 14:53:37 +00002895 * Collection of V8 heap information.
2896 *
2897 * Instances of this class can be passed to v8::V8::HeapStatistics to
2898 * get heap statistics from V8.
2899 */
2900class V8EXPORT HeapStatistics {
2901 public:
2902 HeapStatistics();
2903 size_t total_heap_size() { return total_heap_size_; }
ager@chromium.org01fe7df2010-11-10 11:59:11 +00002904 size_t total_heap_size_executable() { return total_heap_size_executable_; }
danno@chromium.org72204d52012-10-31 10:02:10 +00002905 size_t total_physical_size() { return total_physical_size_; }
ager@chromium.org3811b432009-10-28 14:53:37 +00002906 size_t used_heap_size() { return used_heap_size_; }
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00002907 size_t heap_size_limit() { return heap_size_limit_; }
ager@chromium.org3811b432009-10-28 14:53:37 +00002908
2909 private:
ager@chromium.org3811b432009-10-28 14:53:37 +00002910 size_t total_heap_size_;
ager@chromium.org01fe7df2010-11-10 11:59:11 +00002911 size_t total_heap_size_executable_;
danno@chromium.org72204d52012-10-31 10:02:10 +00002912 size_t total_physical_size_;
ager@chromium.org3811b432009-10-28 14:53:37 +00002913 size_t used_heap_size_;
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00002914 size_t heap_size_limit_;
ager@chromium.org3811b432009-10-28 14:53:37 +00002915
2916 friend class V8;
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +00002917 friend class Isolate;
ager@chromium.org3811b432009-10-28 14:53:37 +00002918};
2919
2920
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00002921class RetainedObjectInfo;
2922
ager@chromium.org3811b432009-10-28 14:53:37 +00002923/**
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002924 * Isolate represents an isolated instance of the V8 engine. V8
2925 * isolates have completely separate states. Objects from one isolate
2926 * must not be used in other isolates. When V8 is initialized a
2927 * default isolate is implicitly created and entered. The embedder
2928 * can create additional isolates and use them in parallel in multiple
2929 * threads. An isolate can be entered by at most one thread at any
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00002930 * given time. The Locker/Unlocker API must be used to synchronize.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002931 */
2932class V8EXPORT Isolate {
2933 public:
2934 /**
2935 * Stack-allocated class which sets the isolate for all operations
2936 * executed within a local scope.
2937 */
2938 class V8EXPORT Scope {
2939 public:
2940 explicit Scope(Isolate* isolate) : isolate_(isolate) {
2941 isolate->Enter();
2942 }
2943
2944 ~Scope() { isolate_->Exit(); }
2945
2946 private:
2947 Isolate* const isolate_;
2948
2949 // Prevent copying of Scope objects.
2950 Scope(const Scope&);
2951 Scope& operator=(const Scope&);
2952 };
2953
2954 /**
2955 * Creates a new isolate. Does not change the currently entered
2956 * isolate.
2957 *
2958 * When an isolate is no longer used its resources should be freed
2959 * by calling Dispose(). Using the delete operator is not allowed.
2960 */
2961 static Isolate* New();
2962
2963 /**
2964 * Returns the entered isolate for the current thread or NULL in
2965 * case there is no current isolate.
2966 */
2967 static Isolate* GetCurrent();
2968
2969 /**
2970 * Methods below this point require holding a lock (using Locker) in
2971 * a multi-threaded environment.
2972 */
2973
2974 /**
2975 * Sets this isolate as the entered one for the current thread.
2976 * Saves the previously entered one (if any), so that it can be
2977 * restored when exiting. Re-entering an isolate is allowed.
2978 */
2979 void Enter();
2980
2981 /**
2982 * Exits this isolate by restoring the previously entered one in the
2983 * current thread. The isolate may still stay the same, if it was
2984 * entered more than once.
2985 *
2986 * Requires: this == Isolate::GetCurrent().
2987 */
2988 void Exit();
2989
2990 /**
2991 * Disposes the isolate. The isolate must not be entered by any
2992 * thread to be disposable.
2993 */
2994 void Dispose();
2995
ager@chromium.orgea91cc52011-05-23 06:06:11 +00002996 /**
2997 * Associate embedder-specific data with the isolate
2998 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00002999 V8_INLINE(void SetData(void* data));
ager@chromium.orgea91cc52011-05-23 06:06:11 +00003000
3001 /**
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00003002 * Retrieve embedder-specific data from the isolate.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00003003 * Returns NULL if SetData has never been called.
3004 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003005 V8_INLINE(void* GetData());
ager@chromium.orgea91cc52011-05-23 06:06:11 +00003006
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +00003007 /**
3008 * Get statistics about the heap memory usage.
3009 */
3010 void GetHeapStatistics(HeapStatistics* heap_statistics);
3011
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003012 /**
3013 * Adjusts the amount of registered external memory. Used to give V8 an
3014 * indication of the amount of externally allocated memory that is kept alive
3015 * by JavaScript objects. V8 uses this to decide when to perform global
3016 * garbage collections. Registering externally allocated memory will trigger
3017 * global garbage collections more often than it would otherwise in an attempt
3018 * to garbage collect the JavaScript objects that keep the externally
3019 * allocated memory alive.
3020 *
3021 * \param change_in_bytes the change in externally allocated memory that is
3022 * kept alive by JavaScript objects.
3023 * \returns the adjusted value.
3024 */
3025 intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes);
3026
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00003027 /**
3028 * Returns heap profiler for this isolate. Will return NULL until the isolate
3029 * is initialized.
3030 */
3031 HeapProfiler* GetHeapProfiler();
3032
3033 /**
3034 * Returns CPU profiler for this isolate. Will return NULL until the isolate
3035 * is initialized.
3036 */
3037 CpuProfiler* GetCpuProfiler();
3038
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003039 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003040 Isolate();
3041 Isolate(const Isolate&);
3042 ~Isolate();
3043 Isolate& operator=(const Isolate&);
3044 void* operator new(size_t size);
3045 void operator delete(void*, size_t);
3046};
3047
3048
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00003049class V8EXPORT StartupData {
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00003050 public:
3051 enum CompressionAlgorithm {
3052 kUncompressed,
3053 kBZip2
3054 };
3055
3056 const char* data;
3057 int compressed_size;
3058 int raw_size;
3059};
3060
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00003061
3062/**
3063 * A helper class for driving V8 startup data decompression. It is based on
3064 * "CompressedStartupData" API functions from the V8 class. It isn't mandatory
3065 * for an embedder to use this class, instead, API functions can be used
3066 * directly.
3067 *
3068 * For an example of the class usage, see the "shell.cc" sample application.
3069 */
3070class V8EXPORT StartupDataDecompressor { // NOLINT
3071 public:
3072 StartupDataDecompressor();
3073 virtual ~StartupDataDecompressor();
3074 int Decompress();
3075
3076 protected:
3077 virtual int DecompressData(char* raw_data,
3078 int* raw_data_size,
3079 const char* compressed_data,
3080 int compressed_data_size) = 0;
3081
3082 private:
3083 char** raw_data;
3084};
3085
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003086
3087/**
3088 * EntropySource is used as a callback function when v8 needs a source
3089 * of entropy.
3090 */
3091typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
3092
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003093
3094/**
ulan@chromium.org967e2702012-02-28 09:49:15 +00003095 * ReturnAddressLocationResolver is used as a callback function when v8 is
3096 * resolving the location of a return address on the stack. Profilers that
3097 * change the return address on the stack can use this to resolve the stack
3098 * location to whereever the profiler stashed the original return address.
verwaest@chromium.org753aee42012-07-17 16:15:42 +00003099 *
3100 * \param return_addr_location points to a location on stack where a machine
3101 * return address resides.
3102 * \returns either return_addr_location, or else a pointer to the profiler's
3103 * copy of the original return address.
3104 *
3105 * \note the resolver function must not cause garbage collection.
ulan@chromium.org967e2702012-02-28 09:49:15 +00003106 */
3107typedef uintptr_t (*ReturnAddressLocationResolver)(
3108 uintptr_t return_addr_location);
3109
3110
3111/**
verwaest@chromium.org753aee42012-07-17 16:15:42 +00003112 * FunctionEntryHook is the type of the profile entry hook called at entry to
3113 * any generated function when function-level profiling is enabled.
3114 *
3115 * \param function the address of the function that's being entered.
3116 * \param return_addr_location points to a location on stack where the machine
3117 * return address resides. This can be used to identify the caller of
3118 * \p function, and/or modified to divert execution when \p function exits.
3119 *
3120 * \note the entry hook must not cause garbage collection.
3121 */
3122typedef void (*FunctionEntryHook)(uintptr_t function,
3123 uintptr_t return_addr_location);
3124
3125
3126/**
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003127 * A JIT code event is issued each time code is added, moved or removed.
3128 *
3129 * \note removal events are not currently issued.
3130 */
3131struct JitCodeEvent {
3132 enum EventType {
3133 CODE_ADDED,
3134 CODE_MOVED,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00003135 CODE_REMOVED,
3136 CODE_ADD_LINE_POS_INFO,
3137 CODE_START_LINE_INFO_RECORDING,
3138 CODE_END_LINE_INFO_RECORDING
3139 };
3140 // Definition of the code position type. The "POSITION" type means the place
3141 // in the source code which are of interest when making stack traces to
3142 // pin-point the source location of a stack frame as close as possible.
3143 // The "STATEMENT_POSITION" means the place at the beginning of each
3144 // statement, and is used to indicate possible break locations.
3145 enum PositionType {
3146 POSITION,
3147 STATEMENT_POSITION
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003148 };
3149
3150 // Type of event.
3151 EventType type;
3152 // Start of the instructions.
3153 void* code_start;
3154 // Size of the instructions.
3155 size_t code_len;
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00003156 // Script info for CODE_ADDED event.
3157 Handle<Script> script;
3158 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
3159 // code line information which is returned from the
3160 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
3161 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
3162 void* user_data;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003163
3164 union {
3165 // Only valid for CODE_ADDED.
3166 struct {
3167 // Name of the object associated with the code, note that the string is
3168 // not zero-terminated.
3169 const char* str;
3170 // Number of chars in str.
3171 size_t len;
3172 } name;
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00003173
3174 // Only valid for CODE_ADD_LINE_POS_INFO
3175 struct {
3176 // PC offset
3177 size_t offset;
3178 // Code postion
3179 size_t pos;
3180 // The position type.
3181 PositionType position_type;
3182 } line_info;
3183
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003184 // New location of instructions. Only valid for CODE_MOVED.
3185 void* new_code_start;
3186 };
3187};
3188
3189/**
3190 * Option flags passed to the SetJitCodeEventHandler function.
3191 */
3192enum JitCodeEventOptions {
3193 kJitCodeEventDefault = 0,
3194 // Generate callbacks for already existent code.
3195 kJitCodeEventEnumExisting = 1
3196};
3197
3198
3199/**
3200 * Callback function passed to SetJitCodeEventHandler.
3201 *
3202 * \param event code add, move or removal event.
3203 */
3204typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
3205
3206
3207/**
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003208 * Interface for iterating through all external resources in the heap.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003209 */
3210class V8EXPORT ExternalResourceVisitor { // NOLINT
3211 public:
3212 virtual ~ExternalResourceVisitor() {}
3213 virtual void VisitExternalString(Handle<String> string) {}
3214};
3215
3216
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003217/**
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003218 * Interface for iterating through all the persistent handles in the heap.
3219 */
3220class V8EXPORT PersistentHandleVisitor { // NOLINT
3221 public:
3222 virtual ~PersistentHandleVisitor() {}
3223 virtual void VisitPersistentHandle(Persistent<Value> value,
3224 uint16_t class_id) {}
3225};
3226
3227
3228/**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003229 * Container class for static utility functions.
3230 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003231class V8EXPORT V8 {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003232 public:
v8.team.kasperl727e9952008-09-02 14:56:44 +00003233 /** Set the callback to invoke in case of fatal errors. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003234 static void SetFatalErrorHandler(FatalErrorCallback that);
3235
v8.team.kasperl727e9952008-09-02 14:56:44 +00003236 /**
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00003237 * Set the callback to invoke to check if code generation from
3238 * strings should be allowed.
3239 */
3240 static void SetAllowCodeGenerationFromStringsCallback(
3241 AllowCodeGenerationFromStringsCallback that);
3242
3243 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003244 * Ignore out-of-memory exceptions.
3245 *
3246 * V8 running out of memory is treated as a fatal error by default.
3247 * This means that the fatal error handler is called and that V8 is
3248 * terminated.
3249 *
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00003250 * IgnoreOutOfMemoryException can be used to not treat an
v8.team.kasperl727e9952008-09-02 14:56:44 +00003251 * out-of-memory situation as a fatal error. This way, the contexts
3252 * that did not cause the out of memory problem might be able to
3253 * continue execution.
3254 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003255 static void IgnoreOutOfMemoryException();
3256
v8.team.kasperl727e9952008-09-02 14:56:44 +00003257 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003258 * Check if V8 is dead and therefore unusable. This is the case after
v8.team.kasperl727e9952008-09-02 14:56:44 +00003259 * fatal errors such as out-of-memory situations.
3260 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003261 static bool IsDead();
3262
3263 /**
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00003264 * The following 4 functions are to be used when V8 is built with
3265 * the 'compress_startup_data' flag enabled. In this case, the
3266 * embedder must decompress startup data prior to initializing V8.
3267 *
3268 * This is how interaction with V8 should look like:
3269 * int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
3270 * v8::StartupData* compressed_data =
3271 * new v8::StartupData[compressed_data_count];
3272 * v8::V8::GetCompressedStartupData(compressed_data);
3273 * ... decompress data (compressed_data can be updated in-place) ...
3274 * v8::V8::SetDecompressedStartupData(compressed_data);
3275 * ... now V8 can be initialized
3276 * ... make sure the decompressed data stays valid until V8 shutdown
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00003277 *
3278 * A helper class StartupDataDecompressor is provided. It implements
3279 * the protocol of the interaction described above, and can be used in
3280 * most cases instead of calling these API functions directly.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00003281 */
3282 static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
3283 static int GetCompressedStartupDataCount();
3284 static void GetCompressedStartupData(StartupData* compressed_data);
3285 static void SetDecompressedStartupData(StartupData* decompressed_data);
3286
3287 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003288 * Adds a message listener.
3289 *
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00003290 * The same message listener can be added more than once and in that
v8.team.kasperl727e9952008-09-02 14:56:44 +00003291 * case it will be called more than once for each message.
hpayer@chromium.org8432c912013-02-28 15:55:26 +00003292 *
3293 * If data is specified, it will be passed to the callback when it is called.
3294 * Otherwise, the exception object will be passed to the callback instead.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003295 */
hpayer@chromium.org8432c912013-02-28 15:55:26 +00003296 static bool AddMessageListener(MessageCallback that,
3297 Handle<Value> data = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003298
3299 /**
3300 * Remove all message listeners from the specified callback function.
3301 */
3302 static void RemoveMessageListeners(MessageCallback that);
3303
3304 /**
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00003305 * Tells V8 to capture current stack trace when uncaught exception occurs
3306 * and report it to the message listeners. The option is off by default.
3307 */
3308 static void SetCaptureStackTraceForUncaughtExceptions(
3309 bool capture,
3310 int frame_limit = 10,
3311 StackTrace::StackTraceOptions options = StackTrace::kOverview);
3312
3313 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003314 * Sets V8 flags from a string.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003315 */
3316 static void SetFlagsFromString(const char* str, int length);
3317
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00003318 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003319 * Sets V8 flags from the command line.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00003320 */
3321 static void SetFlagsFromCommandLine(int* argc,
3322 char** argv,
3323 bool remove_flags);
3324
kasper.lund7276f142008-07-30 08:49:36 +00003325 /** Get the version string. */
3326 static const char* GetVersion();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003327
3328 /**
3329 * Enables the host application to provide a mechanism for recording
3330 * statistics counters.
3331 */
3332 static void SetCounterFunction(CounterLookupCallback);
3333
3334 /**
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003335 * Enables the host application to provide a mechanism for recording
3336 * histograms. The CreateHistogram function returns a
3337 * histogram which will later be passed to the AddHistogramSample
3338 * function.
3339 */
3340 static void SetCreateHistogramFunction(CreateHistogramCallback);
3341 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
3342
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003343 /** Callback function for reporting failed access checks.*/
3344 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
3345
3346 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003347 * Enables the host application to receive a notification before a
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00003348 * garbage collection. Allocations are not allowed in the
3349 * callback function, you therefore cannot manipulate objects (set
3350 * or delete properties for example) since it is possible such
3351 * operations will result in the allocation of objects. It is possible
3352 * to specify the GCType filter for your callback. But it is not possible to
3353 * register the same callback function two times with different
3354 * GCType filters.
3355 */
3356 static void AddGCPrologueCallback(
3357 GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
3358
3359 /**
3360 * This function removes callback which was installed by
3361 * AddGCPrologueCallback function.
3362 */
3363 static void RemoveGCPrologueCallback(GCPrologueCallback callback);
3364
3365 /**
3366 * The function is deprecated. Please use AddGCPrologueCallback instead.
3367 * Enables the host application to receive a notification before a
3368 * garbage collection. Allocations are not allowed in the
v8.team.kasperl727e9952008-09-02 14:56:44 +00003369 * callback function, you therefore cannot manipulate objects (set
3370 * or delete properties for example) since it is possible such
3371 * operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003372 */
yangguo@chromium.org003650e2013-01-24 16:31:08 +00003373 V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003374
3375 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003376 * Enables the host application to receive a notification after a
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00003377 * garbage collection. Allocations are not allowed in the
3378 * callback function, you therefore cannot manipulate objects (set
3379 * or delete properties for example) since it is possible such
3380 * operations will result in the allocation of objects. It is possible
3381 * to specify the GCType filter for your callback. But it is not possible to
3382 * register the same callback function two times with different
3383 * GCType filters.
3384 */
3385 static void AddGCEpilogueCallback(
3386 GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
3387
3388 /**
3389 * This function removes callback which was installed by
3390 * AddGCEpilogueCallback function.
3391 */
3392 static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
3393
3394 /**
3395 * The function is deprecated. Please use AddGCEpilogueCallback instead.
3396 * Enables the host application to receive a notification after a
v8.team.kasperl727e9952008-09-02 14:56:44 +00003397 * major garbage collection. Allocations are not allowed in the
3398 * callback function, you therefore cannot manipulate objects (set
3399 * or delete properties for example) since it is possible such
3400 * operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003401 */
yangguo@chromium.org003650e2013-01-24 16:31:08 +00003402 V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003403
3404 /**
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +00003405 * Enables the host application to provide a mechanism to be notified
3406 * and perform custom logging when V8 Allocates Executable Memory.
3407 */
3408 static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
3409 ObjectSpace space,
3410 AllocationAction action);
3411
3412 /**
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00003413 * Removes callback that was installed by AddMemoryAllocationCallback.
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +00003414 */
3415 static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
3416
3417 /**
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00003418 * Adds a callback to notify the host application when a script finished
3419 * running. If a script re-enters the runtime during executing, the
3420 * CallCompletedCallback is only invoked when the outer-most script
3421 * execution ends. Executing scripts inside the callback do not trigger
3422 * further callbacks.
3423 */
3424 static void AddCallCompletedCallback(CallCompletedCallback callback);
3425
3426 /**
3427 * Removes callback that was installed by AddCallCompletedCallback.
3428 */
3429 static void RemoveCallCompletedCallback(CallCompletedCallback callback);
3430
3431 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003432 * Allows the host application to group objects together. If one
3433 * object in the group is alive, all objects in the group are alive.
3434 * After each garbage collection, object groups are removed. It is
3435 * intended to be used in the before-garbage-collection callback
ager@chromium.org8bb60582008-12-11 12:02:20 +00003436 * function, for instance to simulate DOM tree connections among JS
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003437 * wrapper objects. Object groups for all dependent handles need to
3438 * be provided for kGCTypeMarkSweepCompact collections, for all other
3439 * garbage collection types it is sufficient to provide object groups
3440 * for partially dependent handles only.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00003441 * See v8-profiler.h for RetainedObjectInfo interface description.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003442 */
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00003443 static void AddObjectGroup(Persistent<Value>* objects,
3444 size_t length,
3445 RetainedObjectInfo* info = NULL);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003446 static void AddObjectGroup(Isolate* isolate,
3447 Persistent<Value>* objects,
3448 size_t length,
3449 RetainedObjectInfo* info = NULL);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003450
3451 /**
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +00003452 * Allows the host application to declare implicit references between
3453 * the objects: if |parent| is alive, all |children| are alive too.
3454 * After each garbage collection, all implicit references
3455 * are removed. It is intended to be used in the before-garbage-collection
3456 * callback function.
3457 */
3458 static void AddImplicitReferences(Persistent<Object> parent,
3459 Persistent<Value>* children,
3460 size_t length);
3461
3462 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003463 * Initializes from snapshot if possible. Otherwise, attempts to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00003464 * initialize from scratch. This function is called implicitly if
3465 * you use the API without calling it first.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003466 */
3467 static bool Initialize();
3468
kasper.lund7276f142008-07-30 08:49:36 +00003469 /**
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003470 * Allows the host application to provide a callback which can be used
3471 * as a source of entropy for random number generators.
3472 */
3473 static void SetEntropySource(EntropySource source);
3474
3475 /**
ulan@chromium.org967e2702012-02-28 09:49:15 +00003476 * Allows the host application to provide a callback that allows v8 to
3477 * cooperate with a profiler that rewrites return addresses on stack.
3478 */
3479 static void SetReturnAddressLocationResolver(
3480 ReturnAddressLocationResolver return_address_resolver);
3481
3482 /**
verwaest@chromium.org753aee42012-07-17 16:15:42 +00003483 * Allows the host application to provide the address of a function that's
3484 * invoked on entry to every V8-generated function.
3485 * Note that \p entry_hook is invoked at the very start of each
3486 * generated function.
3487 *
3488 * \param entry_hook a function that will be invoked on entry to every
3489 * V8-generated function.
3490 * \returns true on success on supported platforms, false on failure.
3491 * \note Setting a new entry hook function when one is already active will
3492 * fail.
3493 */
3494 static bool SetFunctionEntryHook(FunctionEntryHook entry_hook);
3495
3496 /**
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003497 * Allows the host application to provide the address of a function that is
3498 * notified each time code is added, moved or removed.
3499 *
3500 * \param options options for the JIT code event handler.
3501 * \param event_handler the JIT code event handler, which will be invoked
3502 * each time code is added, moved or removed.
3503 * \note \p event_handler won't get notified of existent code.
3504 * \note since code removal notifications are not currently issued, the
3505 * \p event_handler may get notifications of code that overlaps earlier
3506 * code notifications. This happens when code areas are reused, and the
3507 * earlier overlapping code areas should therefore be discarded.
3508 * \note the events passed to \p event_handler and the strings they point to
3509 * are not guaranteed to live past each call. The \p event_handler must
3510 * copy strings and other parameters it needs to keep around.
3511 * \note the set of events declared in JitCodeEvent::EventType is expected to
3512 * grow over time, and the JitCodeEvent structure is expected to accrue
3513 * new members. The \p event_handler function must ignore event codes
3514 * it does not recognize to maintain future compatibility.
3515 */
3516 static void SetJitCodeEventHandler(JitCodeEventOptions options,
3517 JitCodeEventHandler event_handler);
3518
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003519 // TODO(svenpanne) Really deprecate me when Chrome is fixed.
3520 /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00003521 static intptr_t AdjustAmountOfExternalAllocatedMemory(
3522 intptr_t change_in_bytes);
kasper.lund7276f142008-07-30 08:49:36 +00003523
iposva@chromium.org245aa852009-02-10 00:49:54 +00003524 /**
3525 * Suspends recording of tick samples in the profiler.
3526 * When the V8 profiling mode is enabled (usually via command line
3527 * switches) this function suspends recording of tick samples.
3528 * Profiling ticks are discarded until ResumeProfiler() is called.
3529 *
3530 * See also the --prof and --prof_auto command line switches to
3531 * enable V8 profiling.
3532 */
3533 static void PauseProfiler();
3534
3535 /**
3536 * Resumes recording of tick samples in the profiler.
3537 * See also PauseProfiler().
3538 */
3539 static void ResumeProfiler();
3540
ager@chromium.org41826e72009-03-30 13:30:57 +00003541 /**
kasperl@chromium.org71affb52009-05-26 05:44:31 +00003542 * Return whether profiler is currently paused.
3543 */
3544 static bool IsProfilerPaused();
3545
3546 /**
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003547 * Retrieve the V8 thread id of the calling thread.
3548 *
3549 * The thread id for a thread should only be retrieved after the V8
3550 * lock has been acquired with a Locker object with that thread.
3551 */
3552 static int GetCurrentThreadId();
3553
3554 /**
3555 * Forcefully terminate execution of a JavaScript thread. This can
3556 * be used to terminate long-running scripts.
3557 *
3558 * TerminateExecution should only be called when then V8 lock has
3559 * been acquired with a Locker object. Therefore, in order to be
3560 * able to terminate long-running threads, preemption must be
3561 * enabled to allow the user of TerminateExecution to acquire the
3562 * lock.
3563 *
3564 * The termination is achieved by throwing an exception that is
3565 * uncatchable by JavaScript exception handlers. Termination
3566 * exceptions act as if they were caught by a C++ TryCatch exception
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00003567 * handler. If forceful termination is used, any C++ TryCatch
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003568 * exception handler that catches an exception should check if that
3569 * exception is a termination exception and immediately return if
3570 * that is the case. Returning immediately in that case will
3571 * continue the propagation of the termination exception if needed.
3572 *
3573 * The thread id passed to TerminateExecution must have been
3574 * obtained by calling GetCurrentThreadId on the thread in question.
3575 *
3576 * \param thread_id The thread id of the thread to terminate.
3577 */
3578 static void TerminateExecution(int thread_id);
3579
3580 /**
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003581 * Forcefully terminate the current thread of JavaScript execution
3582 * in the given isolate. If no isolate is provided, the default
3583 * isolate is used.
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003584 *
3585 * This method can be used by any thread even if that thread has not
3586 * acquired the V8 lock with a Locker object.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003587 *
3588 * \param isolate The isolate in which to terminate the current JS execution.
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003589 */
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003590 static void TerminateExecution(Isolate* isolate = NULL);
ager@chromium.org9085a012009-05-11 19:22:57 +00003591
3592 /**
sgjesse@chromium.org2ab99522010-03-10 09:03:43 +00003593 * Is V8 terminating JavaScript execution.
3594 *
3595 * Returns true if JavaScript execution is currently terminating
3596 * because of a call to TerminateExecution. In that case there are
3597 * still JavaScript frames on the stack and the termination
3598 * exception is still active.
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003599 *
3600 * \param isolate The isolate in which to check.
sgjesse@chromium.org2ab99522010-03-10 09:03:43 +00003601 */
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003602 static bool IsExecutionTerminating(Isolate* isolate = NULL);
sgjesse@chromium.org2ab99522010-03-10 09:03:43 +00003603
3604 /**
ager@chromium.org41826e72009-03-30 13:30:57 +00003605 * Releases any resources used by v8 and stops any utility threads
3606 * that may be running. Note that disposing v8 is permanent, it
3607 * cannot be reinitialized.
3608 *
3609 * It should generally not be necessary to dispose v8 before exiting
3610 * a process, this should happen automatically. It is only necessary
3611 * to use if the process needs the resources taken up by v8.
3612 */
3613 static bool Dispose();
3614
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +00003615 /** Deprecated. Use Isolate::GetHeapStatistics instead. */
3616 V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics));
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003617
3618 /**
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003619 * Iterates through all external resources referenced from current isolate
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00003620 * heap. GC is not invoked prior to iterating, therefore there is no
3621 * guarantee that visited objects are still alive.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003622 */
3623 static void VisitExternalResources(ExternalResourceVisitor* visitor);
3624
3625 /**
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003626 * Iterates through all the persistent handles in the current isolate's heap
3627 * that have class_ids.
3628 */
3629 static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
3630
3631 /**
yangguo@chromium.org003650e2013-01-24 16:31:08 +00003632 * Iterates through all the persistent handles in the current isolate's heap
3633 * that have class_ids and are candidates to be marked as partially dependent
3634 * handles. This will visit handles to young objects created since the last
3635 * garbage collection but is free to visit an arbitrary superset of these
3636 * objects.
3637 */
3638 static void VisitHandlesForPartialDependence(
3639 Isolate* isolate, PersistentHandleVisitor* visitor);
3640
3641 /**
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003642 * Optional notification that the embedder is idle.
3643 * V8 uses the notification to reduce memory footprint.
ager@chromium.orgab99eea2009-08-25 07:05:41 +00003644 * This call can be used repeatedly if the embedder remains idle.
ager@chromium.orgab99eea2009-08-25 07:05:41 +00003645 * Returns true if the embedder should stop calling IdleNotification
3646 * until real work has been done. This indicates that V8 has done
3647 * as much cleanup as it will be able to do.
svenpanne@chromium.orgecb9dd62011-12-01 08:22:35 +00003648 *
3649 * The hint argument specifies the amount of work to be done in the function
3650 * on scale from 1 to 1000. There is no guarantee that the actual work will
3651 * match the hint.
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003652 */
svenpanne@chromium.orgecb9dd62011-12-01 08:22:35 +00003653 static bool IdleNotification(int hint = 1000);
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003654
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003655 /**
3656 * Optional notification that the system is running low on memory.
3657 * V8 uses these notifications to attempt to free memory.
3658 */
3659 static void LowMemoryNotification();
3660
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00003661 /**
3662 * Optional notification that a context has been disposed. V8 uses
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00003663 * these notifications to guide the GC heuristic. Returns the number
3664 * of context disposals - including this one - since the last time
3665 * V8 had a chance to clean up.
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00003666 */
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00003667 static int ContextDisposedNotification();
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00003668
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003669 private:
3670 V8();
3671
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00003672 static internal::Object** GlobalizeReference(internal::Isolate* isolate,
3673 internal::Object** handle);
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00003674 static void DisposeGlobal(internal::Isolate* isolate,
3675 internal::Object** global_handle);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003676 static void MakeWeak(internal::Isolate* isolate,
3677 internal::Object** global_handle,
3678 void* data,
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00003679 WeakReferenceCallback weak_reference_callback,
3680 NearDeathCallback near_death_callback);
3681 static void ClearWeak(internal::Isolate* isolate,
3682 internal::Object** global_handle);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003683
3684 template <class T> friend class Handle;
3685 template <class T> friend class Local;
3686 template <class T> friend class Persistent;
3687 friend class Context;
3688};
3689
3690
3691/**
3692 * An external exception handler.
3693 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003694class V8EXPORT TryCatch {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003695 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003696 /**
mmassi@chromium.org49a44672012-12-04 13:52:03 +00003697 * Creates a new try/catch block and registers it with v8. Note that
3698 * all TryCatch blocks should be stack allocated because the memory
3699 * location itself is compared against JavaScript try/catch blocks.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003700 */
3701 TryCatch();
3702
3703 /**
3704 * Unregisters and deletes this try/catch block.
3705 */
3706 ~TryCatch();
3707
3708 /**
3709 * Returns true if an exception has been caught by this try/catch block.
3710 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003711 bool HasCaught() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003712
3713 /**
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003714 * For certain types of exceptions, it makes no sense to continue
3715 * execution.
3716 *
3717 * Currently, the only type of exception that can be caught by a
3718 * TryCatch handler and for which it does not make sense to continue
3719 * is termination exception. Such exceptions are thrown when the
3720 * TerminateExecution methods are called to terminate a long-running
3721 * script.
3722 *
3723 * If CanContinue returns false, the correct action is to perform
3724 * any C++ cleanup needed and then return.
3725 */
3726 bool CanContinue() const;
3727
3728 /**
christian.plesner.hansen@gmail.comb9ce6372009-11-03 11:38:18 +00003729 * Throws the exception caught by this TryCatch in a way that avoids
3730 * it being caught again by this same TryCatch. As with ThrowException
3731 * it is illegal to execute any JavaScript operations after calling
3732 * ReThrow; the caller must return immediately to where the exception
3733 * is caught.
3734 */
3735 Handle<Value> ReThrow();
3736
3737 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003738 * Returns the exception caught by this try/catch block. If no exception has
3739 * been caught an empty handle is returned.
3740 *
3741 * The returned handle is valid until this TryCatch block has been destroyed.
3742 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003743 Local<Value> Exception() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003744
3745 /**
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00003746 * Returns the .stack property of the thrown object. If no .stack
3747 * property is present an empty handle is returned.
3748 */
3749 Local<Value> StackTrace() const;
3750
3751 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003752 * Returns the message associated with this exception. If there is
3753 * no message associated an empty handle is returned.
3754 *
3755 * The returned handle is valid until this TryCatch block has been
3756 * destroyed.
3757 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003758 Local<v8::Message> Message() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003759
3760 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003761 * Clears any exceptions that may have been caught by this try/catch block.
3762 * After this method has been called, HasCaught() will return false.
3763 *
3764 * It is not necessary to clear a try/catch block before using it again; if
3765 * another exception is thrown the previously caught exception will just be
3766 * overwritten. However, it is often a good idea since it makes it easier
3767 * to determine which operation threw a given exception.
3768 */
3769 void Reset();
3770
v8.team.kasperl727e9952008-09-02 14:56:44 +00003771 /**
3772 * Set verbosity of the external exception handler.
3773 *
3774 * By default, exceptions that are caught by an external exception
3775 * handler are not reported. Call SetVerbose with true on an
3776 * external exception handler to have exceptions caught by the
3777 * handler reported as if they were not caught.
3778 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003779 void SetVerbose(bool value);
3780
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003781 /**
3782 * Set whether or not this TryCatch should capture a Message object
3783 * which holds source information about where the exception
3784 * occurred. True by default.
3785 */
3786 void SetCaptureMessage(bool value);
3787
ager@chromium.orgc4c92722009-11-18 14:12:51 +00003788 private:
mmassi@chromium.org49a44672012-12-04 13:52:03 +00003789 // Make it hard to create heap-allocated TryCatch blocks.
3790 TryCatch(const TryCatch&);
3791 void operator=(const TryCatch&);
3792 void* operator new(size_t size);
3793 void operator delete(void*, size_t);
3794
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00003795 v8::internal::Isolate* isolate_;
ager@chromium.orgc4c92722009-11-18 14:12:51 +00003796 void* next_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003797 void* exception_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003798 void* message_;
christian.plesner.hansen@gmail.comb9ce6372009-11-03 11:38:18 +00003799 bool is_verbose_ : 1;
3800 bool can_continue_ : 1;
3801 bool capture_message_ : 1;
3802 bool rethrow_ : 1;
ager@chromium.orgc4c92722009-11-18 14:12:51 +00003803
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003804 friend class v8::internal::Isolate;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003805};
3806
3807
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00003808// --- Context ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003809
3810
3811/**
3812 * Ignore
3813 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003814class V8EXPORT ExtensionConfiguration {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003815 public:
3816 ExtensionConfiguration(int name_count, const char* names[])
3817 : name_count_(name_count), names_(names) { }
3818 private:
3819 friend class ImplementationUtilities;
3820 int name_count_;
3821 const char** names_;
3822};
3823
3824
3825/**
3826 * A sandboxed execution context with its own set of built-in objects
3827 * and functions.
3828 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003829class V8EXPORT Context {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003830 public:
whesse@chromium.org7a392b32011-01-31 11:30:36 +00003831 /**
3832 * Returns the global proxy object or global object itself for
3833 * detached contexts.
3834 *
3835 * Global proxy object is a thin wrapper whose prototype points to
3836 * actual context's global object with the properties like Object, etc.
3837 * This is done that way for security reasons (for more details see
3838 * https://wiki.mozilla.org/Gecko:SplitWindow).
3839 *
3840 * Please note that changes to global proxy object prototype most probably
3841 * would break VM---v8 expects only global object as a prototype of
3842 * global proxy object.
3843 *
3844 * If DetachGlobal() has been invoked, Global() would return actual global
3845 * object until global is reattached with ReattachGlobal().
3846 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003847 Local<Object> Global();
3848
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003849 /**
3850 * Detaches the global object from its context before
3851 * the global object can be reused to create a new context.
3852 */
3853 void DetachGlobal();
3854
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +00003855 /**
3856 * Reattaches a global object to a context. This can be used to
3857 * restore the connection between a global object and a context
3858 * after DetachGlobal has been called.
3859 *
3860 * \param global_object The global object to reattach to the
3861 * context. For this to work, the global object must be the global
3862 * object that was associated with this context before a call to
3863 * DetachGlobal.
3864 */
3865 void ReattachGlobal(Handle<Object> global_object);
3866
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00003867 /** Creates a new context.
3868 *
3869 * Returns a persistent handle to the newly allocated context. This
3870 * persistent handle has to be disposed when the context is no
3871 * longer used so the context can be garbage collected.
lrn@chromium.org5d00b602011-01-05 09:51:43 +00003872 *
3873 * \param extensions An optional extension configuration containing
3874 * the extensions to be installed in the newly created context.
3875 *
3876 * \param global_template An optional object template from which the
3877 * global object for the newly created context will be created.
3878 *
3879 * \param global_object An optional global object to be reused for
3880 * the newly created context. This global object must have been
3881 * created by a previous call to Context::New with the same global
3882 * template. The state of the global object will be completely reset
3883 * and only object identify will remain.
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00003884 */
v8.team.kasperl727e9952008-09-02 14:56:44 +00003885 static Persistent<Context> New(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00003886 ExtensionConfiguration* extensions = NULL,
v8.team.kasperl727e9952008-09-02 14:56:44 +00003887 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
3888 Handle<Value> global_object = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003889
kasper.lund44510672008-07-25 07:37:58 +00003890 /** Returns the last entered context. */
3891 static Local<Context> GetEntered();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003892
kasper.lund44510672008-07-25 07:37:58 +00003893 /** Returns the context that is on the top of the stack. */
3894 static Local<Context> GetCurrent();
3895
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003896 /**
ager@chromium.org1bf0cd02009-05-20 11:34:19 +00003897 * Returns the context of the calling JavaScript code. That is the
3898 * context of the top-most JavaScript frame. If there are no
3899 * JavaScript frames an empty handle is returned.
3900 */
3901 static Local<Context> GetCalling();
3902
3903 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003904 * Sets the security token for the context. To access an object in
3905 * another context, the security tokens must match.
3906 */
3907 void SetSecurityToken(Handle<Value> token);
3908
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003909 /** Restores the security token to the default value. */
3910 void UseDefaultSecurityToken();
3911
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003912 /** Returns the security token of this context.*/
3913 Handle<Value> GetSecurityToken();
3914
v8.team.kasperl727e9952008-09-02 14:56:44 +00003915 /**
3916 * Enter this context. After entering a context, all code compiled
3917 * and run is compiled and run in this context. If another context
3918 * is already entered, this old context is saved so it can be
3919 * restored when the new context is exited.
3920 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003921 void Enter();
v8.team.kasperl727e9952008-09-02 14:56:44 +00003922
3923 /**
3924 * Exit this context. Exiting the current context restores the
3925 * context that was in place when entering the current context.
3926 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003927 void Exit();
3928
v8.team.kasperl727e9952008-09-02 14:56:44 +00003929 /** Returns true if the context has experienced an out of memory situation. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003930 bool HasOutOfMemoryException();
3931
v8.team.kasperl727e9952008-09-02 14:56:44 +00003932 /** Returns true if V8 has a current context. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003933 static bool InContext();
3934
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00003935 /** Returns an isolate associated with a current context. */
3936 v8::Isolate* GetIsolate();
yangguo@chromium.orge19986e2013-01-16 09:48:20 +00003937
3938 /**
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00003939 * Gets the embedder data with the given index, which must have been set by a
3940 * previous call to SetEmbedderData with the same index. Note that index 0
3941 * currently has a special meaning for Chrome's debugger.
3942 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003943 V8_INLINE(Local<Value> GetEmbedderData(int index));
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00003944
3945 /**
3946 * Sets the embedder data with the given index, growing the data as
3947 * needed. Note that index 0 currently has a special meaning for Chrome's
3948 * debugger.
3949 */
3950 void SetEmbedderData(int index, Handle<Value> value);
3951
3952 /**
3953 * Gets a 2-byte-aligned native pointer from the embedder data with the given
3954 * index, which must have bees set by a previous call to
3955 * SetAlignedPointerInEmbedderData with the same index. Note that index 0
3956 * currently has a special meaning for Chrome's debugger.
3957 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003958 V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index));
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00003959
3960 /**
3961 * Sets a 2-byte-aligned native pointer in the embedder data with the given
3962 * index, growing the data as needed. Note that index 0 currently has a
3963 * special meaning for Chrome's debugger.
3964 */
3965 void SetAlignedPointerInEmbedderData(int index, void* value);
ager@chromium.org9085a012009-05-11 19:22:57 +00003966
3967 /**
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00003968 * Control whether code generation from strings is allowed. Calling
3969 * this method with false will disable 'eval' and the 'Function'
3970 * constructor for code running in this context. If 'eval' or the
3971 * 'Function' constructor are used an exception will be thrown.
3972 *
3973 * If code generation from strings is not allowed the
3974 * V8::AllowCodeGenerationFromStrings callback will be invoked if
3975 * set before blocking the call to 'eval' or the 'Function'
3976 * constructor. If that callback returns true, the call will be
3977 * allowed, otherwise an exception will be thrown. If no callback is
3978 * set an exception will be thrown.
3979 */
3980 void AllowCodeGenerationFromStrings(bool allow);
3981
3982 /**
jkummerow@chromium.org1145ef82012-02-02 16:21:15 +00003983 * Returns true if code generation from strings is allowed for the context.
3984 * For more details see AllowCodeGenerationFromStrings(bool) documentation.
3985 */
3986 bool IsCodeGenerationFromStringsAllowed();
3987
3988 /**
ulan@chromium.org56c14af2012-09-20 12:51:09 +00003989 * Sets the error description for the exception that is thrown when
3990 * code generation from strings is not allowed and 'eval' or the 'Function'
3991 * constructor are called.
3992 */
3993 void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message);
3994
3995 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003996 * Stack-allocated class which sets the execution context for all
3997 * operations executed within a local scope.
3998 */
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00003999 class Scope {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004000 public:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004001 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004002 context_->Enter();
4003 }
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004004 V8_INLINE(~Scope()) { context_->Exit(); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004005 private:
4006 Handle<Context> context_;
4007 };
4008
4009 private:
4010 friend class Value;
4011 friend class Script;
4012 friend class Object;
4013 friend class Function;
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004014
4015 Local<Value> SlowGetEmbedderData(int index);
4016 void* SlowGetAlignedPointerFromEmbedderData(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004017};
4018
4019
4020/**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004021 * Multiple threads in V8 are allowed, but only one thread at a time is allowed
4022 * to use any given V8 isolate, see the comments in the Isolate class. The
4023 * definition of 'using a V8 isolate' includes accessing handles or holding onto
4024 * object pointers obtained from V8 handles while in the particular V8 isolate.
4025 * It is up to the user of V8 to ensure, perhaps with locking, that this
4026 * constraint is not violated. In addition to any other synchronization
4027 * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be
4028 * used to signal thead switches to V8.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004029 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004030 * v8::Locker is a scoped lock object. While it's active, i.e. between its
4031 * construction and destruction, the current thread is allowed to use the locked
4032 * isolate. V8 guarantees that an isolate can be locked by at most one thread at
4033 * any time. In other words, the scope of a v8::Locker is a critical section.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004034 *
lrn@chromium.org1c092762011-05-09 09:42:16 +00004035 * Sample usage:
4036* \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004037 * ...
4038 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004039 * v8::Locker locker(isolate);
4040 * v8::Isolate::Scope isolate_scope(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004041 * ...
lrn@chromium.org1c092762011-05-09 09:42:16 +00004042 * // Code using V8 and isolate goes here.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004043 * ...
4044 * } // Destructor called here
v8.team.kasperl727e9952008-09-02 14:56:44 +00004045 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004046 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004047 * If you wish to stop using V8 in a thread A you can do this either by
4048 * destroying the v8::Locker object as above or by constructing a v8::Unlocker
4049 * object:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004050 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00004051 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004052 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004053 * isolate->Exit();
4054 * v8::Unlocker unlocker(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004055 * ...
4056 * // Code not using V8 goes here while V8 can run in another thread.
4057 * ...
4058 * } // Destructor called here.
lrn@chromium.org1c092762011-05-09 09:42:16 +00004059 * isolate->Enter();
v8.team.kasperl727e9952008-09-02 14:56:44 +00004060 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004061 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004062 * The Unlocker object is intended for use in a long-running callback from V8,
4063 * where you want to release the V8 lock for other threads to use.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004064 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004065 * The v8::Locker is a recursive lock, i.e. you can lock more than once in a
4066 * given thread. This can be useful if you have code that can be called either
4067 * from code that holds the lock or from code that does not. The Unlocker is
4068 * not recursive so you can not have several Unlockers on the stack at once, and
4069 * you can not use an Unlocker in a thread that is not inside a Locker's scope.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004070 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004071 * An unlocker will unlock several lockers if it has to and reinstate the
4072 * correct depth of locking on its destruction, e.g.:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004073 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00004074 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004075 * // V8 not locked.
4076 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004077 * v8::Locker locker(isolate);
4078 * Isolate::Scope isolate_scope(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004079 * // V8 locked.
4080 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004081 * v8::Locker another_locker(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004082 * // V8 still locked (2 levels).
4083 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004084 * isolate->Exit();
4085 * v8::Unlocker unlocker(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004086 * // V8 not locked.
4087 * }
lrn@chromium.org1c092762011-05-09 09:42:16 +00004088 * isolate->Enter();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004089 * // V8 locked again (2 levels).
4090 * }
4091 * // V8 still locked (1 level).
4092 * }
4093 * // V8 Now no longer locked.
v8.team.kasperl727e9952008-09-02 14:56:44 +00004094 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004095 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00004096class V8EXPORT Unlocker {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004097 public:
lrn@chromium.org1c092762011-05-09 09:42:16 +00004098 /**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004099 * Initialize Unlocker for a given Isolate.
lrn@chromium.org1c092762011-05-09 09:42:16 +00004100 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004101 V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); }
4102
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004103 /** Deprecated. Use Isolate version instead. */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004104 V8_DEPRECATED(Unlocker());
4105
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004106 ~Unlocker();
lrn@chromium.org1c092762011-05-09 09:42:16 +00004107 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004108 void Initialize(Isolate* isolate);
4109
lrn@chromium.org1c092762011-05-09 09:42:16 +00004110 internal::Isolate* isolate_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004111};
4112
4113
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00004114class V8EXPORT Locker {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004115 public:
lrn@chromium.org1c092762011-05-09 09:42:16 +00004116 /**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004117 * Initialize Locker for a given Isolate.
lrn@chromium.org1c092762011-05-09 09:42:16 +00004118 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004119 V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); }
4120
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004121 /** Deprecated. Use Isolate version instead. */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004122 V8_DEPRECATED(Locker());
4123
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004124 ~Locker();
v8.team.kasperl727e9952008-09-02 14:56:44 +00004125
4126 /**
4127 * Start preemption.
4128 *
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00004129 * When preemption is started, a timer is fired every n milliseconds
v8.team.kasperl727e9952008-09-02 14:56:44 +00004130 * that will switch between multiple threads that are in contention
4131 * for the V8 lock.
4132 */
4133 static void StartPreemption(int every_n_ms);
4134
4135 /**
4136 * Stop preemption.
4137 */
4138 static void StopPreemption();
4139
ager@chromium.org9258b6b2008-09-11 09:11:10 +00004140 /**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004141 * Returns whether or not the locker for a given isolate, is locked by the
4142 * current thread.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00004143 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004144 static bool IsLocked(Isolate* isolate);
ager@chromium.org9258b6b2008-09-11 09:11:10 +00004145
ager@chromium.orgddb913d2009-01-27 10:01:48 +00004146 /**
4147 * Returns whether v8::Locker is being used by this V8 instance.
4148 */
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00004149 static bool IsActive();
ager@chromium.orgddb913d2009-01-27 10:01:48 +00004150
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004151 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004152 void Initialize(Isolate* isolate);
4153
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004154 bool has_lock_;
4155 bool top_level_;
lrn@chromium.org1c092762011-05-09 09:42:16 +00004156 internal::Isolate* isolate_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00004157
ager@chromium.orgddb913d2009-01-27 10:01:48 +00004158 static bool active_;
4159
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00004160 // Disallow copying and assigning.
4161 Locker(const Locker&);
4162 void operator=(const Locker&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004163};
4164
4165
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004166/**
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004167 * A struct for exporting HeapStats data from V8, using "push" model.
4168 */
4169struct HeapStatsUpdate;
4170
4171
4172/**
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004173 * An interface for exporting data from V8, using "push" model.
4174 */
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +00004175class V8EXPORT OutputStream { // NOLINT
4176 public:
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004177 enum OutputEncoding {
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004178 kAscii = 0 // 7-bit ASCII.
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004179 };
4180 enum WriteResult {
4181 kContinue = 0,
4182 kAbort = 1
4183 };
4184 virtual ~OutputStream() {}
4185 /** Notify about the end of stream. */
4186 virtual void EndOfStream() = 0;
4187 /** Get preferred output chunk size. Called only once. */
4188 virtual int GetChunkSize() { return 1024; }
4189 /** Get preferred output encoding. Called only once. */
4190 virtual OutputEncoding GetOutputEncoding() { return kAscii; }
4191 /**
4192 * Writes the next chunk of snapshot data into the stream. Writing
4193 * can be stopped by returning kAbort as function result. EndOfStream
4194 * will not be called in case writing was aborted.
4195 */
4196 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00004197 /**
4198 * Writes the next chunk of heap stats data into the stream. Writing
4199 * can be stopped by returning kAbort as function result. EndOfStream
4200 * will not be called in case writing was aborted.
4201 */
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004202 virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
jkummerow@chromium.org3ee08a62012-04-13 13:01:33 +00004203 return kAbort;
4204 };
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004205};
4206
4207
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00004208/**
4209 * An interface for reporting progress and controlling long-running
4210 * activities.
4211 */
4212class V8EXPORT ActivityControl { // NOLINT
4213 public:
4214 enum ControlOption {
4215 kContinue = 0,
4216 kAbort = 1
4217 };
4218 virtual ~ActivityControl() {}
4219 /**
4220 * Notify about current progress. The activity can be stopped by
4221 * returning kAbort as the callback result.
4222 */
4223 virtual ControlOption ReportProgressValue(int done, int total) = 0;
4224};
4225
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004226
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00004227// --- Implementation ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004228
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004229
4230namespace internal {
4231
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00004232const int kApiPointerSize = sizeof(void*); // NOLINT
4233const int kApiIntSize = sizeof(int); // NOLINT
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004234
4235// Tag information for HeapObject.
4236const int kHeapObjectTag = 1;
4237const int kHeapObjectTagSize = 2;
4238const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
4239
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004240// Tag information for Smi.
4241const int kSmiTag = 0;
4242const int kSmiTagSize = 1;
4243const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
4244
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004245template <size_t ptr_size> struct SmiTagging;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004246
4247// Smi constants for 32-bit systems.
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004248template <> struct SmiTagging<4> {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004249 static const int kSmiShiftSize = 0;
4250 static const int kSmiValueSize = 31;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004251 V8_INLINE(static int SmiToInt(internal::Object* value)) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004252 int shift_bits = kSmiTagSize + kSmiShiftSize;
4253 // Throw away top 32 bits and shift down (requires >> to be sign extending).
4254 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
4255 }
4256};
4257
4258// Smi constants for 64-bit systems.
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004259template <> struct SmiTagging<8> {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004260 static const int kSmiShiftSize = 31;
4261 static const int kSmiValueSize = 32;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004262 V8_INLINE(static int SmiToInt(internal::Object* value)) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004263 int shift_bits = kSmiTagSize + kSmiShiftSize;
4264 // Shift down and throw away top 32 bits.
4265 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
4266 }
4267};
4268
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004269typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
4270const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
4271const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004272
4273/**
4274 * This class exports constants and functionality from within v8 that
4275 * is necessary to implement inline functions in the v8 api. Don't
4276 * depend on functions and constants defined here.
4277 */
4278class Internals {
4279 public:
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004280 // These values match non-compiler-dependent values defined within
4281 // the implementation of v8.
4282 static const int kHeapObjectMapOffset = 0;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004283 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004284 static const int kStringResourceOffset = 3 * kApiPointerSize;
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00004285
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004286 static const int kOddballKindOffset = 3 * kApiPointerSize;
ager@chromium.orgea91cc52011-05-23 06:06:11 +00004287 static const int kForeignAddressOffset = kApiPointerSize;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00004288 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004289 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
4290 static const int kContextHeaderSize = 2 * kApiPointerSize;
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00004291 static const int kContextEmbedderDataIndex = 55;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004292 static const int kFullStringRepresentationMask = 0x07;
ulan@chromium.org56c14af2012-09-20 12:51:09 +00004293 static const int kStringEncodingMask = 0x4;
sgjesse@chromium.org82dbbab2010-06-02 08:57:44 +00004294 static const int kExternalTwoByteRepresentationTag = 0x02;
ulan@chromium.org56c14af2012-09-20 12:51:09 +00004295 static const int kExternalAsciiRepresentationTag = 0x06;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004296
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004297 static const int kIsolateStateOffset = 0;
4298 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
4299 static const int kIsolateRootsOffset = 3 * kApiPointerSize;
4300 static const int kUndefinedValueRootIndex = 5;
4301 static const int kNullValueRootIndex = 7;
4302 static const int kTrueValueRootIndex = 8;
4303 static const int kFalseValueRootIndex = 9;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004304 static const int kEmptyStringRootIndex = 119;
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004305
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004306 static const int kNodeClassIdOffset = 1 * kApiPointerSize;
4307 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
4308 static const int kNodeStateMask = 0xf;
4309 static const int kNodeStateIsWeakValue = 2;
4310 static const int kNodeStateIsNearDeathValue = 4;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004311 static const int kNodeIsIndependentShift = 4;
4312 static const int kNodeIsPartiallyDependentShift = 5;
4313
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004314 static const int kJSObjectType = 0xae;
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +00004315 static const int kFirstNonstringType = 0x80;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004316 static const int kOddballType = 0x83;
4317 static const int kForeignType = 0x86;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004318
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004319 static const int kUndefinedOddballKind = 5;
4320 static const int kNullOddballKind = 3;
4321
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004322 V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004323 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
4324 kHeapObjectTag);
4325 }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00004326
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004327 V8_INLINE(static int SmiValue(internal::Object* value)) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004328 return PlatformSmiTagging::SmiToInt(value);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004329 }
4330
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004331 V8_INLINE(static int GetInstanceType(internal::Object* obj)) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004332 typedef internal::Object O;
4333 O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
4334 return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
4335 }
4336
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004337 V8_INLINE(static int GetOddballKind(internal::Object* obj)) {
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004338 typedef internal::Object O;
4339 return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
4340 }
4341
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004342 V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004343 int representation = (instance_type & kFullStringRepresentationMask);
4344 return representation == kExternalTwoByteRepresentationTag;
4345 }
4346
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004347 V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004348 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
4349 return *reinterpret_cast<int*>(addr) == 1;
4350 }
4351
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004352 V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) {
4353 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4354 return *addr & (1 << shift);
4355 }
4356
4357 V8_INLINE(static void UpdateNodeFlag(internal::Object** obj,
4358 bool value, int shift)) {
4359 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4360 uint8_t mask = 1 << shift;
4361 *addr = (*addr & ~mask) | (value << shift);
4362 }
4363
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004364 V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) {
4365 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4366 return *addr & kNodeStateMask;
4367 }
4368
4369 V8_INLINE(static void UpdateNodeState(internal::Object** obj,
4370 uint8_t value)) {
4371 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4372 *addr = (*addr & ~kNodeStateMask) | value;
4373 }
4374
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004375 V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004376 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4377 kIsolateEmbedderDataOffset;
4378 *reinterpret_cast<void**>(addr) = data;
4379 }
4380
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004381 V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004382 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4383 kIsolateEmbedderDataOffset;
4384 return *reinterpret_cast<void**>(addr);
4385 }
4386
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004387 V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate,
4388 int index)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004389 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
4390 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
4391 }
4392
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004393 template <typename T>
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004394 V8_INLINE(static T ReadField(Object* ptr, int offset)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004395 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
4396 return *reinterpret_cast<T*>(addr);
4397 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004398
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004399 template <typename T>
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004400 V8_INLINE(static T ReadEmbedderData(Context* context, int index)) {
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004401 typedef internal::Object O;
4402 typedef internal::Internals I;
4403 O* ctx = *reinterpret_cast<O**>(context);
4404 int embedder_data_offset = I::kContextHeaderSize +
4405 (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
4406 O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
4407 int value_offset =
4408 I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
4409 return I::ReadField<T>(embedder_data, value_offset);
4410 }
4411
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004412 V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; }
4413 V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; }
4414 V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; }
4415 V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; }
4416 V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; }
4417 V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; }
4418 V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; }
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004419};
4420
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +00004421} // namespace internal
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004422
4423
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004424template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004425Local<T>::Local() : Handle<T>() { }
4426
4427
4428template <class T>
4429Local<T> Local<T>::New(Handle<T> that) {
4430 if (that.IsEmpty()) return Local<T>();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004431 T* that_ptr = *that;
4432 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
4433 if (internal::Internals::CanCastToHeapObject(that_ptr)) {
4434 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
4435 reinterpret_cast<internal::HeapObject*>(*p))));
4436 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004437 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
4438}
4439
4440
4441template <class T>
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004442Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) {
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004443 if (that.IsEmpty()) return Local<T>();
4444 T* that_ptr = *that;
4445 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
4446 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
4447 reinterpret_cast<internal::Isolate*>(isolate), *p)));
4448}
4449
4450
4451template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004452Persistent<T> Persistent<T>::New(Handle<T> that) {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004453 return New(Isolate::GetCurrent(), that);
4454}
4455
4456
4457template <class T>
4458Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004459 if (that.IsEmpty()) return Persistent<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004460 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004461 return Persistent<T>(reinterpret_cast<T*>(
4462 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
4463 p)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004464}
4465
4466
4467template <class T>
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004468bool Persistent<T>::IsIndependent() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004469 return IsIndependent(Isolate::GetCurrent());
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004470}
4471
4472
4473template <class T>
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004474bool Persistent<T>::IsIndependent(Isolate* isolate) const {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004475 typedef internal::Internals I;
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004476 if (this->IsEmpty()) return false;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004477 if (!I::IsInitialized(isolate)) return false;
4478 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(**this),
4479 I::kNodeIsIndependentShift);
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004480}
4481
4482
4483template <class T>
ager@chromium.org32912102009-01-16 10:38:43 +00004484bool Persistent<T>::IsNearDeath() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004485 return IsNearDeath(Isolate::GetCurrent());
4486}
4487
4488
4489template <class T>
4490bool Persistent<T>::IsNearDeath(Isolate* isolate) const {
4491 typedef internal::Internals I;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004492 if (this->IsEmpty()) return false;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004493 if (!I::IsInitialized(isolate)) return false;
4494 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) ==
4495 I::kNodeStateIsNearDeathValue;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004496}
4497
4498
4499template <class T>
ager@chromium.org32912102009-01-16 10:38:43 +00004500bool Persistent<T>::IsWeak() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004501 return IsWeak(Isolate::GetCurrent());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004502}
4503
4504
4505template <class T>
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004506bool Persistent<T>::IsWeak(Isolate* isolate) const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004507 typedef internal::Internals I;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004508 if (this->IsEmpty()) return false;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004509 if (!I::IsInitialized(isolate)) return false;
4510 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) ==
4511 I::kNodeStateIsWeakValue;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004512}
4513
4514
4515template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004516void Persistent<T>::Dispose() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004517 Dispose(Isolate::GetCurrent());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004518}
4519
4520
4521template <class T>
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004522void Persistent<T>::Dispose(Isolate* isolate) {
4523 if (this->IsEmpty()) return;
4524 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate),
4525 reinterpret_cast<internal::Object**>(**this));
4526}
4527
4528
4529template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004530Persistent<T>::Persistent() : Handle<T>() { }
4531
4532template <class T>
4533void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004534 Isolate* isolate = Isolate::GetCurrent();
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004535 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate),
4536 reinterpret_cast<internal::Object**>(**this),
4537 parameters,
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004538 callback,
4539 NULL);
4540}
4541
4542template <class T>
4543void Persistent<T>::MakeWeak(Isolate* isolate,
4544 void* parameters,
4545 NearDeathCallback callback) {
4546 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate),
4547 reinterpret_cast<internal::Object**>(**this),
4548 parameters,
4549 NULL,
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004550 callback);
4551}
4552
4553template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004554void Persistent<T>::ClearWeak() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004555 ClearWeak(Isolate::GetCurrent());
4556}
4557
4558template <class T>
4559void Persistent<T>::ClearWeak(Isolate* isolate) {
4560 V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate),
4561 reinterpret_cast<internal::Object**>(**this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004562}
4563
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00004564template <class T>
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004565void Persistent<T>::MarkIndependent() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004566 MarkIndependent(Isolate::GetCurrent());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004567}
4568
4569template <class T>
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004570void Persistent<T>::MarkIndependent(Isolate* isolate) {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004571 typedef internal::Internals I;
4572 if (this->IsEmpty()) return;
4573 if (!I::IsInitialized(isolate)) return;
4574 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this),
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004575 true,
4576 I::kNodeIsIndependentShift);
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004577}
4578
4579template <class T>
4580void Persistent<T>::MarkPartiallyDependent() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004581 MarkPartiallyDependent(Isolate::GetCurrent());
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004582}
4583
4584template <class T>
4585void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004586 typedef internal::Internals I;
4587 if (this->IsEmpty()) return;
4588 if (!I::IsInitialized(isolate)) return;
4589 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this),
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004590 true,
4591 I::kNodeIsPartiallyDependentShift);
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004592}
4593
4594template <class T>
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00004595void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004596 SetWrapperClassId(Isolate::GetCurrent(), class_id);
4597}
4598
4599template <class T>
4600void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004601 typedef internal::Internals I;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004602 if (this->IsEmpty()) return;
4603 if (!I::IsInitialized(isolate)) return;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004604 internal::Object** obj = reinterpret_cast<internal::Object**>(**this);
4605 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
4606 *reinterpret_cast<uint16_t*>(addr) = class_id;
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00004607}
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004608
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004609template <class T>
4610uint16_t Persistent<T>::WrapperClassId() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004611 return WrapperClassId(Isolate::GetCurrent());
4612}
4613
4614template <class T>
4615uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004616 typedef internal::Internals I;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004617 if (this->IsEmpty()) return 0;
4618 if (!I::IsInitialized(isolate)) return 0;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004619 internal::Object** obj = reinterpret_cast<internal::Object**>(**this);
4620 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
4621 return *reinterpret_cast<uint16_t*>(addr);
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004622}
4623
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004624Arguments::Arguments(internal::Object** implicit_args,
4625 internal::Object** values, int length,
4626 bool is_construct_call)
4627 : implicit_args_(implicit_args),
4628 values_(values),
4629 length_(length),
4630 is_construct_call_(is_construct_call) { }
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004631
4632
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004633Local<Value> Arguments::operator[](int i) const {
4634 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
4635 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
4636}
4637
4638
4639Local<Function> Arguments::Callee() const {
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004640 return Local<Function>(reinterpret_cast<Function*>(
4641 &implicit_args_[kCalleeIndex]));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004642}
4643
4644
4645Local<Object> Arguments::This() const {
4646 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
4647}
4648
4649
4650Local<Object> Arguments::Holder() const {
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004651 return Local<Object>(reinterpret_cast<Object*>(
4652 &implicit_args_[kHolderIndex]));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004653}
4654
4655
4656Local<Value> Arguments::Data() const {
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004657 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004658}
4659
4660
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00004661Isolate* Arguments::GetIsolate() const {
4662 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
4663}
4664
4665
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004666bool Arguments::IsConstructCall() const {
4667 return is_construct_call_;
4668}
4669
4670
4671int Arguments::Length() const {
4672 return length_;
4673}
4674
4675
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004676template <class T>
4677Local<T> HandleScope::Close(Handle<T> value) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004678 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
4679 internal::Object** after = RawClose(before);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004680 return Local<T>(reinterpret_cast<T*>(after));
4681}
4682
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00004683Handle<Value> ScriptOrigin::ResourceName() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004684 return resource_name_;
4685}
4686
4687
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00004688Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004689 return resource_line_offset_;
4690}
4691
4692
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00004693Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004694 return resource_column_offset_;
4695}
4696
4697
4698Handle<Boolean> Boolean::New(bool value) {
4699 return value ? True() : False();
4700}
4701
4702
4703void Template::Set(const char* name, v8::Handle<Data> value) {
4704 Set(v8::String::New(name), value);
4705}
4706
4707
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004708Local<Value> Object::GetInternalField(int index) {
4709#ifndef V8_ENABLE_CHECKS
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004710 typedef internal::Object O;
4711 typedef internal::Internals I;
4712 O* obj = *reinterpret_cast<O**>(this);
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004713 // Fast path: If the object is a plain JSObject, which is the common case, we
4714 // know where to find the internal fields and can return the value directly.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004715 if (I::GetInstanceType(obj) == I::kJSObjectType) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00004716 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004717 O* value = I::ReadField<O*>(obj, offset);
4718 O** result = HandleScope::CreateHandle(value);
4719 return Local<Value>(reinterpret_cast<Value*>(result));
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004720 }
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004721#endif
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004722 return SlowGetInternalField(index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004723}
4724
4725
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004726void* Object::GetAlignedPointerFromInternalField(int index) {
4727#ifndef V8_ENABLE_CHECKS
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004728 typedef internal::Object O;
4729 typedef internal::Internals I;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004730 O* obj = *reinterpret_cast<O**>(this);
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004731 // Fast path: If the object is a plain JSObject, which is the common case, we
4732 // know where to find the internal fields and can return the value directly.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004733 if (I::GetInstanceType(obj) == I::kJSObjectType) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00004734 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004735 return I::ReadField<void*>(obj, offset);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004736 }
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004737#endif
4738 return SlowGetAlignedPointerFromInternalField(index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004739}
4740
4741
4742String* String::Cast(v8::Value* value) {
4743#ifdef V8_ENABLE_CHECKS
4744 CheckCast(value);
4745#endif
4746 return static_cast<String*>(value);
4747}
4748
4749
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004750Local<String> String::Empty(Isolate* isolate) {
4751 typedef internal::Object* S;
4752 typedef internal::Internals I;
4753 if (!I::IsInitialized(isolate)) return Empty();
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004754 S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004755 return Local<String>(reinterpret_cast<String*>(slot));
4756}
4757
4758
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004759String::ExternalStringResource* String::GetExternalStringResource() const {
4760 typedef internal::Object O;
4761 typedef internal::Internals I;
4762 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004763 String::ExternalStringResource* result;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004764 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004765 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4766 result = reinterpret_cast<String::ExternalStringResource*>(value);
4767 } else {
4768 result = NULL;
4769 }
4770#ifdef V8_ENABLE_CHECKS
4771 VerifyExternalStringResource(result);
4772#endif
4773 return result;
4774}
4775
4776
ulan@chromium.org56c14af2012-09-20 12:51:09 +00004777String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
4778 String::Encoding* encoding_out) const {
4779 typedef internal::Object O;
4780 typedef internal::Internals I;
4781 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4782 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
4783 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
4784 ExternalStringResourceBase* resource = NULL;
4785 if (type == I::kExternalAsciiRepresentationTag ||
4786 type == I::kExternalTwoByteRepresentationTag) {
4787 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4788 resource = static_cast<ExternalStringResourceBase*>(value);
4789 }
4790#ifdef V8_ENABLE_CHECKS
4791 VerifyExternalStringResourceBase(resource, *encoding_out);
4792#endif
4793 return resource;
4794}
4795
4796
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004797bool Value::IsUndefined() const {
4798#ifdef V8_ENABLE_CHECKS
4799 return FullIsUndefined();
4800#else
4801 return QuickIsUndefined();
4802#endif
4803}
4804
4805bool Value::QuickIsUndefined() const {
4806 typedef internal::Object O;
4807 typedef internal::Internals I;
4808 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4809 if (!I::HasHeapObjectTag(obj)) return false;
4810 if (I::GetInstanceType(obj) != I::kOddballType) return false;
4811 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
4812}
4813
4814
4815bool Value::IsNull() const {
4816#ifdef V8_ENABLE_CHECKS
4817 return FullIsNull();
4818#else
4819 return QuickIsNull();
4820#endif
4821}
4822
4823bool Value::QuickIsNull() const {
4824 typedef internal::Object O;
4825 typedef internal::Internals I;
4826 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4827 if (!I::HasHeapObjectTag(obj)) return false;
4828 if (I::GetInstanceType(obj) != I::kOddballType) return false;
4829 return (I::GetOddballKind(obj) == I::kNullOddballKind);
4830}
4831
4832
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004833bool Value::IsString() const {
4834#ifdef V8_ENABLE_CHECKS
4835 return FullIsString();
4836#else
4837 return QuickIsString();
4838#endif
4839}
4840
4841bool Value::QuickIsString() const {
4842 typedef internal::Object O;
4843 typedef internal::Internals I;
4844 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4845 if (!I::HasHeapObjectTag(obj)) return false;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004846 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004847}
4848
4849
4850Number* Number::Cast(v8::Value* value) {
4851#ifdef V8_ENABLE_CHECKS
4852 CheckCast(value);
4853#endif
4854 return static_cast<Number*>(value);
4855}
4856
4857
4858Integer* Integer::Cast(v8::Value* value) {
4859#ifdef V8_ENABLE_CHECKS
4860 CheckCast(value);
4861#endif
4862 return static_cast<Integer*>(value);
4863}
4864
4865
4866Date* Date::Cast(v8::Value* value) {
4867#ifdef V8_ENABLE_CHECKS
4868 CheckCast(value);
4869#endif
4870 return static_cast<Date*>(value);
4871}
4872
4873
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004874StringObject* StringObject::Cast(v8::Value* value) {
4875#ifdef V8_ENABLE_CHECKS
4876 CheckCast(value);
4877#endif
4878 return static_cast<StringObject*>(value);
4879}
4880
4881
4882NumberObject* NumberObject::Cast(v8::Value* value) {
4883#ifdef V8_ENABLE_CHECKS
4884 CheckCast(value);
4885#endif
4886 return static_cast<NumberObject*>(value);
4887}
4888
4889
4890BooleanObject* BooleanObject::Cast(v8::Value* value) {
4891#ifdef V8_ENABLE_CHECKS
4892 CheckCast(value);
4893#endif
4894 return static_cast<BooleanObject*>(value);
4895}
4896
4897
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00004898RegExp* RegExp::Cast(v8::Value* value) {
4899#ifdef V8_ENABLE_CHECKS
4900 CheckCast(value);
4901#endif
4902 return static_cast<RegExp*>(value);
4903}
4904
4905
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004906Object* Object::Cast(v8::Value* value) {
4907#ifdef V8_ENABLE_CHECKS
4908 CheckCast(value);
4909#endif
4910 return static_cast<Object*>(value);
4911}
4912
4913
4914Array* Array::Cast(v8::Value* value) {
4915#ifdef V8_ENABLE_CHECKS
4916 CheckCast(value);
4917#endif
4918 return static_cast<Array*>(value);
4919}
4920
4921
4922Function* Function::Cast(v8::Value* value) {
4923#ifdef V8_ENABLE_CHECKS
4924 CheckCast(value);
4925#endif
4926 return static_cast<Function*>(value);
4927}
4928
4929
4930External* External::Cast(v8::Value* value) {
4931#ifdef V8_ENABLE_CHECKS
4932 CheckCast(value);
4933#endif
4934 return static_cast<External*>(value);
4935}
4936
4937
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00004938Isolate* AccessorInfo::GetIsolate() const {
4939 return *reinterpret_cast<Isolate**>(&args_[-3]);
4940}
4941
4942
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00004943Local<Value> AccessorInfo::Data() const {
ager@chromium.orgb26c50a2010-03-26 09:27:16 +00004944 return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00004945}
4946
4947
4948Local<Object> AccessorInfo::This() const {
4949 return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
4950}
4951
4952
4953Local<Object> AccessorInfo::Holder() const {
4954 return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
4955}
4956
4957
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004958Handle<Primitive> Undefined(Isolate* isolate) {
4959 typedef internal::Object* S;
4960 typedef internal::Internals I;
4961 if (!I::IsInitialized(isolate)) return Undefined();
4962 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
4963 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
4964}
4965
4966
4967Handle<Primitive> Null(Isolate* isolate) {
4968 typedef internal::Object* S;
4969 typedef internal::Internals I;
4970 if (!I::IsInitialized(isolate)) return Null();
4971 S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
4972 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
4973}
4974
4975
4976Handle<Boolean> True(Isolate* isolate) {
4977 typedef internal::Object* S;
4978 typedef internal::Internals I;
4979 if (!I::IsInitialized(isolate)) return True();
4980 S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
4981 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
4982}
4983
4984
4985Handle<Boolean> False(Isolate* isolate) {
4986 typedef internal::Object* S;
4987 typedef internal::Internals I;
4988 if (!I::IsInitialized(isolate)) return False();
4989 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
4990 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
4991}
4992
4993
4994void Isolate::SetData(void* data) {
4995 typedef internal::Internals I;
4996 I::SetEmbedderData(this, data);
4997}
4998
4999
5000void* Isolate::GetData() {
5001 typedef internal::Internals I;
5002 return I::GetEmbedderData(this);
5003}
5004
5005
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00005006Local<Value> Context::GetEmbedderData(int index) {
5007#ifndef V8_ENABLE_CHECKS
5008 typedef internal::Object O;
5009 typedef internal::Internals I;
5010 O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index));
5011 return Local<Value>(reinterpret_cast<Value*>(result));
5012#else
5013 return SlowGetEmbedderData(index);
5014#endif
5015}
5016
5017
5018void* Context::GetAlignedPointerFromEmbedderData(int index) {
5019#ifndef V8_ENABLE_CHECKS
5020 typedef internal::Internals I;
5021 return I::ReadEmbedderData<void*>(this, index);
5022#else
5023 return SlowGetAlignedPointerFromEmbedderData(index);
5024#endif
5025}
5026
5027
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005028/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00005029 * \example shell.cc
5030 * A simple shell that takes a list of expressions on the
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005031 * command-line and executes them.
5032 */
5033
5034
5035/**
5036 * \example process.cc
5037 */
5038
5039
5040} // namespace v8
5041
5042
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00005043#undef V8EXPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005044#undef TYPE_CHECK
5045
5046
ager@chromium.org9258b6b2008-09-11 09:11:10 +00005047#endif // V8_H_