blob: 3961503348ada2246c98243d8af7495cb1b19520 [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
mvstanton@chromium.org40ce96b2013-04-09 09:52:22 +00003039 /** Returns the context that is on the top of the stack. */
3040 Local<Context> GetCurrentContext();
3041
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003042 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003043 Isolate();
3044 Isolate(const Isolate&);
3045 ~Isolate();
3046 Isolate& operator=(const Isolate&);
3047 void* operator new(size_t size);
3048 void operator delete(void*, size_t);
3049};
3050
3051
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00003052class V8EXPORT StartupData {
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00003053 public:
3054 enum CompressionAlgorithm {
3055 kUncompressed,
3056 kBZip2
3057 };
3058
3059 const char* data;
3060 int compressed_size;
3061 int raw_size;
3062};
3063
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00003064
3065/**
3066 * A helper class for driving V8 startup data decompression. It is based on
3067 * "CompressedStartupData" API functions from the V8 class. It isn't mandatory
3068 * for an embedder to use this class, instead, API functions can be used
3069 * directly.
3070 *
3071 * For an example of the class usage, see the "shell.cc" sample application.
3072 */
3073class V8EXPORT StartupDataDecompressor { // NOLINT
3074 public:
3075 StartupDataDecompressor();
3076 virtual ~StartupDataDecompressor();
3077 int Decompress();
3078
3079 protected:
3080 virtual int DecompressData(char* raw_data,
3081 int* raw_data_size,
3082 const char* compressed_data,
3083 int compressed_data_size) = 0;
3084
3085 private:
3086 char** raw_data;
3087};
3088
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003089
3090/**
3091 * EntropySource is used as a callback function when v8 needs a source
3092 * of entropy.
3093 */
3094typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
3095
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003096
3097/**
ulan@chromium.org967e2702012-02-28 09:49:15 +00003098 * ReturnAddressLocationResolver is used as a callback function when v8 is
3099 * resolving the location of a return address on the stack. Profilers that
3100 * change the return address on the stack can use this to resolve the stack
3101 * location to whereever the profiler stashed the original return address.
verwaest@chromium.org753aee42012-07-17 16:15:42 +00003102 *
3103 * \param return_addr_location points to a location on stack where a machine
3104 * return address resides.
3105 * \returns either return_addr_location, or else a pointer to the profiler's
3106 * copy of the original return address.
3107 *
3108 * \note the resolver function must not cause garbage collection.
ulan@chromium.org967e2702012-02-28 09:49:15 +00003109 */
3110typedef uintptr_t (*ReturnAddressLocationResolver)(
3111 uintptr_t return_addr_location);
3112
3113
3114/**
verwaest@chromium.org753aee42012-07-17 16:15:42 +00003115 * FunctionEntryHook is the type of the profile entry hook called at entry to
3116 * any generated function when function-level profiling is enabled.
3117 *
3118 * \param function the address of the function that's being entered.
3119 * \param return_addr_location points to a location on stack where the machine
3120 * return address resides. This can be used to identify the caller of
3121 * \p function, and/or modified to divert execution when \p function exits.
3122 *
3123 * \note the entry hook must not cause garbage collection.
3124 */
3125typedef void (*FunctionEntryHook)(uintptr_t function,
3126 uintptr_t return_addr_location);
3127
3128
3129/**
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003130 * A JIT code event is issued each time code is added, moved or removed.
3131 *
3132 * \note removal events are not currently issued.
3133 */
3134struct JitCodeEvent {
3135 enum EventType {
3136 CODE_ADDED,
3137 CODE_MOVED,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00003138 CODE_REMOVED,
3139 CODE_ADD_LINE_POS_INFO,
3140 CODE_START_LINE_INFO_RECORDING,
3141 CODE_END_LINE_INFO_RECORDING
3142 };
3143 // Definition of the code position type. The "POSITION" type means the place
3144 // in the source code which are of interest when making stack traces to
3145 // pin-point the source location of a stack frame as close as possible.
3146 // The "STATEMENT_POSITION" means the place at the beginning of each
3147 // statement, and is used to indicate possible break locations.
3148 enum PositionType {
3149 POSITION,
3150 STATEMENT_POSITION
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003151 };
3152
3153 // Type of event.
3154 EventType type;
3155 // Start of the instructions.
3156 void* code_start;
3157 // Size of the instructions.
3158 size_t code_len;
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00003159 // Script info for CODE_ADDED event.
3160 Handle<Script> script;
3161 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
3162 // code line information which is returned from the
3163 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
3164 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
3165 void* user_data;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003166
3167 union {
3168 // Only valid for CODE_ADDED.
3169 struct {
3170 // Name of the object associated with the code, note that the string is
3171 // not zero-terminated.
3172 const char* str;
3173 // Number of chars in str.
3174 size_t len;
3175 } name;
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00003176
3177 // Only valid for CODE_ADD_LINE_POS_INFO
3178 struct {
3179 // PC offset
3180 size_t offset;
3181 // Code postion
3182 size_t pos;
3183 // The position type.
3184 PositionType position_type;
3185 } line_info;
3186
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003187 // New location of instructions. Only valid for CODE_MOVED.
3188 void* new_code_start;
3189 };
3190};
3191
3192/**
3193 * Option flags passed to the SetJitCodeEventHandler function.
3194 */
3195enum JitCodeEventOptions {
3196 kJitCodeEventDefault = 0,
3197 // Generate callbacks for already existent code.
3198 kJitCodeEventEnumExisting = 1
3199};
3200
3201
3202/**
3203 * Callback function passed to SetJitCodeEventHandler.
3204 *
3205 * \param event code add, move or removal event.
3206 */
3207typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
3208
3209
3210/**
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003211 * Interface for iterating through all external resources in the heap.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003212 */
3213class V8EXPORT ExternalResourceVisitor { // NOLINT
3214 public:
3215 virtual ~ExternalResourceVisitor() {}
3216 virtual void VisitExternalString(Handle<String> string) {}
3217};
3218
3219
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003220/**
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003221 * Interface for iterating through all the persistent handles in the heap.
3222 */
3223class V8EXPORT PersistentHandleVisitor { // NOLINT
3224 public:
3225 virtual ~PersistentHandleVisitor() {}
3226 virtual void VisitPersistentHandle(Persistent<Value> value,
3227 uint16_t class_id) {}
3228};
3229
3230
3231/**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003232 * Container class for static utility functions.
3233 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003234class V8EXPORT V8 {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003235 public:
v8.team.kasperl727e9952008-09-02 14:56:44 +00003236 /** Set the callback to invoke in case of fatal errors. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003237 static void SetFatalErrorHandler(FatalErrorCallback that);
3238
v8.team.kasperl727e9952008-09-02 14:56:44 +00003239 /**
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00003240 * Set the callback to invoke to check if code generation from
3241 * strings should be allowed.
3242 */
3243 static void SetAllowCodeGenerationFromStringsCallback(
3244 AllowCodeGenerationFromStringsCallback that);
3245
3246 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003247 * Ignore out-of-memory exceptions.
3248 *
3249 * V8 running out of memory is treated as a fatal error by default.
3250 * This means that the fatal error handler is called and that V8 is
3251 * terminated.
3252 *
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00003253 * IgnoreOutOfMemoryException can be used to not treat an
v8.team.kasperl727e9952008-09-02 14:56:44 +00003254 * out-of-memory situation as a fatal error. This way, the contexts
3255 * that did not cause the out of memory problem might be able to
3256 * continue execution.
3257 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003258 static void IgnoreOutOfMemoryException();
3259
v8.team.kasperl727e9952008-09-02 14:56:44 +00003260 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003261 * Check if V8 is dead and therefore unusable. This is the case after
v8.team.kasperl727e9952008-09-02 14:56:44 +00003262 * fatal errors such as out-of-memory situations.
3263 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003264 static bool IsDead();
3265
3266 /**
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00003267 * The following 4 functions are to be used when V8 is built with
3268 * the 'compress_startup_data' flag enabled. In this case, the
3269 * embedder must decompress startup data prior to initializing V8.
3270 *
3271 * This is how interaction with V8 should look like:
3272 * int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
3273 * v8::StartupData* compressed_data =
3274 * new v8::StartupData[compressed_data_count];
3275 * v8::V8::GetCompressedStartupData(compressed_data);
3276 * ... decompress data (compressed_data can be updated in-place) ...
3277 * v8::V8::SetDecompressedStartupData(compressed_data);
3278 * ... now V8 can be initialized
3279 * ... make sure the decompressed data stays valid until V8 shutdown
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00003280 *
3281 * A helper class StartupDataDecompressor is provided. It implements
3282 * the protocol of the interaction described above, and can be used in
3283 * most cases instead of calling these API functions directly.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00003284 */
3285 static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
3286 static int GetCompressedStartupDataCount();
3287 static void GetCompressedStartupData(StartupData* compressed_data);
3288 static void SetDecompressedStartupData(StartupData* decompressed_data);
3289
3290 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003291 * Adds a message listener.
3292 *
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00003293 * The same message listener can be added more than once and in that
v8.team.kasperl727e9952008-09-02 14:56:44 +00003294 * case it will be called more than once for each message.
hpayer@chromium.org8432c912013-02-28 15:55:26 +00003295 *
3296 * If data is specified, it will be passed to the callback when it is called.
3297 * Otherwise, the exception object will be passed to the callback instead.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003298 */
hpayer@chromium.org8432c912013-02-28 15:55:26 +00003299 static bool AddMessageListener(MessageCallback that,
3300 Handle<Value> data = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003301
3302 /**
3303 * Remove all message listeners from the specified callback function.
3304 */
3305 static void RemoveMessageListeners(MessageCallback that);
3306
3307 /**
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00003308 * Tells V8 to capture current stack trace when uncaught exception occurs
3309 * and report it to the message listeners. The option is off by default.
3310 */
3311 static void SetCaptureStackTraceForUncaughtExceptions(
3312 bool capture,
3313 int frame_limit = 10,
3314 StackTrace::StackTraceOptions options = StackTrace::kOverview);
3315
3316 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003317 * Sets V8 flags from a string.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003318 */
3319 static void SetFlagsFromString(const char* str, int length);
3320
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00003321 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003322 * Sets V8 flags from the command line.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00003323 */
3324 static void SetFlagsFromCommandLine(int* argc,
3325 char** argv,
3326 bool remove_flags);
3327
kasper.lund7276f142008-07-30 08:49:36 +00003328 /** Get the version string. */
3329 static const char* GetVersion();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003330
3331 /**
3332 * Enables the host application to provide a mechanism for recording
3333 * statistics counters.
3334 */
3335 static void SetCounterFunction(CounterLookupCallback);
3336
3337 /**
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003338 * Enables the host application to provide a mechanism for recording
3339 * histograms. The CreateHistogram function returns a
3340 * histogram which will later be passed to the AddHistogramSample
3341 * function.
3342 */
3343 static void SetCreateHistogramFunction(CreateHistogramCallback);
3344 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
3345
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003346 /** Callback function for reporting failed access checks.*/
3347 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
3348
3349 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003350 * Enables the host application to receive a notification before a
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00003351 * garbage collection. Allocations are not allowed in the
3352 * callback function, you therefore cannot manipulate objects (set
3353 * or delete properties for example) since it is possible such
3354 * operations will result in the allocation of objects. It is possible
3355 * to specify the GCType filter for your callback. But it is not possible to
3356 * register the same callback function two times with different
3357 * GCType filters.
3358 */
3359 static void AddGCPrologueCallback(
3360 GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
3361
3362 /**
3363 * This function removes callback which was installed by
3364 * AddGCPrologueCallback function.
3365 */
3366 static void RemoveGCPrologueCallback(GCPrologueCallback callback);
3367
3368 /**
3369 * The function is deprecated. Please use AddGCPrologueCallback instead.
3370 * Enables the host application to receive a notification before a
3371 * garbage collection. Allocations are not allowed in the
v8.team.kasperl727e9952008-09-02 14:56:44 +00003372 * callback function, you therefore cannot manipulate objects (set
3373 * or delete properties for example) since it is possible such
3374 * operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003375 */
yangguo@chromium.org003650e2013-01-24 16:31:08 +00003376 V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003377
3378 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003379 * Enables the host application to receive a notification after a
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00003380 * garbage collection. Allocations are not allowed in the
3381 * callback function, you therefore cannot manipulate objects (set
3382 * or delete properties for example) since it is possible such
3383 * operations will result in the allocation of objects. It is possible
3384 * to specify the GCType filter for your callback. But it is not possible to
3385 * register the same callback function two times with different
3386 * GCType filters.
3387 */
3388 static void AddGCEpilogueCallback(
3389 GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
3390
3391 /**
3392 * This function removes callback which was installed by
3393 * AddGCEpilogueCallback function.
3394 */
3395 static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
3396
3397 /**
3398 * The function is deprecated. Please use AddGCEpilogueCallback instead.
3399 * Enables the host application to receive a notification after a
v8.team.kasperl727e9952008-09-02 14:56:44 +00003400 * major garbage collection. Allocations are not allowed in the
3401 * callback function, you therefore cannot manipulate objects (set
3402 * or delete properties for example) since it is possible such
3403 * operations will result in the allocation of objects.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003404 */
yangguo@chromium.org003650e2013-01-24 16:31:08 +00003405 V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003406
3407 /**
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +00003408 * Enables the host application to provide a mechanism to be notified
3409 * and perform custom logging when V8 Allocates Executable Memory.
3410 */
3411 static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
3412 ObjectSpace space,
3413 AllocationAction action);
3414
3415 /**
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00003416 * Removes callback that was installed by AddMemoryAllocationCallback.
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +00003417 */
3418 static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
3419
3420 /**
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00003421 * Adds a callback to notify the host application when a script finished
3422 * running. If a script re-enters the runtime during executing, the
3423 * CallCompletedCallback is only invoked when the outer-most script
3424 * execution ends. Executing scripts inside the callback do not trigger
3425 * further callbacks.
3426 */
3427 static void AddCallCompletedCallback(CallCompletedCallback callback);
3428
3429 /**
3430 * Removes callback that was installed by AddCallCompletedCallback.
3431 */
3432 static void RemoveCallCompletedCallback(CallCompletedCallback callback);
3433
3434 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003435 * Allows the host application to group objects together. If one
3436 * object in the group is alive, all objects in the group are alive.
3437 * After each garbage collection, object groups are removed. It is
3438 * intended to be used in the before-garbage-collection callback
ager@chromium.org8bb60582008-12-11 12:02:20 +00003439 * function, for instance to simulate DOM tree connections among JS
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003440 * wrapper objects. Object groups for all dependent handles need to
3441 * be provided for kGCTypeMarkSweepCompact collections, for all other
3442 * garbage collection types it is sufficient to provide object groups
3443 * for partially dependent handles only.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00003444 * See v8-profiler.h for RetainedObjectInfo interface description.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003445 */
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00003446 static void AddObjectGroup(Persistent<Value>* objects,
3447 size_t length,
3448 RetainedObjectInfo* info = NULL);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003449 static void AddObjectGroup(Isolate* isolate,
3450 Persistent<Value>* objects,
3451 size_t length,
3452 RetainedObjectInfo* info = NULL);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003453
3454 /**
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +00003455 * Allows the host application to declare implicit references between
3456 * the objects: if |parent| is alive, all |children| are alive too.
3457 * After each garbage collection, all implicit references
3458 * are removed. It is intended to be used in the before-garbage-collection
3459 * callback function.
3460 */
3461 static void AddImplicitReferences(Persistent<Object> parent,
3462 Persistent<Value>* children,
3463 size_t length);
3464
3465 /**
v8.team.kasperl727e9952008-09-02 14:56:44 +00003466 * Initializes from snapshot if possible. Otherwise, attempts to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00003467 * initialize from scratch. This function is called implicitly if
3468 * you use the API without calling it first.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003469 */
3470 static bool Initialize();
3471
kasper.lund7276f142008-07-30 08:49:36 +00003472 /**
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003473 * Allows the host application to provide a callback which can be used
3474 * as a source of entropy for random number generators.
3475 */
3476 static void SetEntropySource(EntropySource source);
3477
3478 /**
ulan@chromium.org967e2702012-02-28 09:49:15 +00003479 * Allows the host application to provide a callback that allows v8 to
3480 * cooperate with a profiler that rewrites return addresses on stack.
3481 */
3482 static void SetReturnAddressLocationResolver(
3483 ReturnAddressLocationResolver return_address_resolver);
3484
3485 /**
verwaest@chromium.org753aee42012-07-17 16:15:42 +00003486 * Allows the host application to provide the address of a function that's
3487 * invoked on entry to every V8-generated function.
3488 * Note that \p entry_hook is invoked at the very start of each
3489 * generated function.
3490 *
3491 * \param entry_hook a function that will be invoked on entry to every
3492 * V8-generated function.
3493 * \returns true on success on supported platforms, false on failure.
3494 * \note Setting a new entry hook function when one is already active will
3495 * fail.
3496 */
3497 static bool SetFunctionEntryHook(FunctionEntryHook entry_hook);
3498
3499 /**
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00003500 * Allows the host application to provide the address of a function that is
3501 * notified each time code is added, moved or removed.
3502 *
3503 * \param options options for the JIT code event handler.
3504 * \param event_handler the JIT code event handler, which will be invoked
3505 * each time code is added, moved or removed.
3506 * \note \p event_handler won't get notified of existent code.
3507 * \note since code removal notifications are not currently issued, the
3508 * \p event_handler may get notifications of code that overlaps earlier
3509 * code notifications. This happens when code areas are reused, and the
3510 * earlier overlapping code areas should therefore be discarded.
3511 * \note the events passed to \p event_handler and the strings they point to
3512 * are not guaranteed to live past each call. The \p event_handler must
3513 * copy strings and other parameters it needs to keep around.
3514 * \note the set of events declared in JitCodeEvent::EventType is expected to
3515 * grow over time, and the JitCodeEvent structure is expected to accrue
3516 * new members. The \p event_handler function must ignore event codes
3517 * it does not recognize to maintain future compatibility.
3518 */
3519 static void SetJitCodeEventHandler(JitCodeEventOptions options,
3520 JitCodeEventHandler event_handler);
3521
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003522 // TODO(svenpanne) Really deprecate me when Chrome is fixed.
3523 /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00003524 static intptr_t AdjustAmountOfExternalAllocatedMemory(
3525 intptr_t change_in_bytes);
kasper.lund7276f142008-07-30 08:49:36 +00003526
iposva@chromium.org245aa852009-02-10 00:49:54 +00003527 /**
3528 * Suspends recording of tick samples in the profiler.
3529 * When the V8 profiling mode is enabled (usually via command line
3530 * switches) this function suspends recording of tick samples.
3531 * Profiling ticks are discarded until ResumeProfiler() is called.
3532 *
3533 * See also the --prof and --prof_auto command line switches to
3534 * enable V8 profiling.
3535 */
3536 static void PauseProfiler();
3537
3538 /**
3539 * Resumes recording of tick samples in the profiler.
3540 * See also PauseProfiler().
3541 */
3542 static void ResumeProfiler();
3543
ager@chromium.org41826e72009-03-30 13:30:57 +00003544 /**
kasperl@chromium.org71affb52009-05-26 05:44:31 +00003545 * Return whether profiler is currently paused.
3546 */
3547 static bool IsProfilerPaused();
3548
3549 /**
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003550 * Retrieve the V8 thread id of the calling thread.
3551 *
3552 * The thread id for a thread should only be retrieved after the V8
3553 * lock has been acquired with a Locker object with that thread.
3554 */
3555 static int GetCurrentThreadId();
3556
3557 /**
3558 * Forcefully terminate execution of a JavaScript thread. This can
3559 * be used to terminate long-running scripts.
3560 *
3561 * TerminateExecution should only be called when then V8 lock has
3562 * been acquired with a Locker object. Therefore, in order to be
3563 * able to terminate long-running threads, preemption must be
3564 * enabled to allow the user of TerminateExecution to acquire the
3565 * lock.
3566 *
3567 * The termination is achieved by throwing an exception that is
3568 * uncatchable by JavaScript exception handlers. Termination
3569 * exceptions act as if they were caught by a C++ TryCatch exception
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00003570 * handler. If forceful termination is used, any C++ TryCatch
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003571 * exception handler that catches an exception should check if that
3572 * exception is a termination exception and immediately return if
3573 * that is the case. Returning immediately in that case will
3574 * continue the propagation of the termination exception if needed.
3575 *
3576 * The thread id passed to TerminateExecution must have been
3577 * obtained by calling GetCurrentThreadId on the thread in question.
3578 *
3579 * \param thread_id The thread id of the thread to terminate.
3580 */
3581 static void TerminateExecution(int thread_id);
3582
3583 /**
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003584 * Forcefully terminate the current thread of JavaScript execution
3585 * in the given isolate. If no isolate is provided, the default
3586 * isolate is used.
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003587 *
3588 * This method can be used by any thread even if that thread has not
3589 * acquired the V8 lock with a Locker object.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003590 *
3591 * \param isolate The isolate in which to terminate the current JS execution.
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003592 */
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003593 static void TerminateExecution(Isolate* isolate = NULL);
ager@chromium.org9085a012009-05-11 19:22:57 +00003594
3595 /**
sgjesse@chromium.org2ab99522010-03-10 09:03:43 +00003596 * Is V8 terminating JavaScript execution.
3597 *
3598 * Returns true if JavaScript execution is currently terminating
3599 * because of a call to TerminateExecution. In that case there are
3600 * still JavaScript frames on the stack and the termination
3601 * exception is still active.
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003602 *
3603 * \param isolate The isolate in which to check.
sgjesse@chromium.org2ab99522010-03-10 09:03:43 +00003604 */
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003605 static bool IsExecutionTerminating(Isolate* isolate = NULL);
sgjesse@chromium.org2ab99522010-03-10 09:03:43 +00003606
3607 /**
ager@chromium.org41826e72009-03-30 13:30:57 +00003608 * Releases any resources used by v8 and stops any utility threads
3609 * that may be running. Note that disposing v8 is permanent, it
3610 * cannot be reinitialized.
3611 *
3612 * It should generally not be necessary to dispose v8 before exiting
3613 * a process, this should happen automatically. It is only necessary
3614 * to use if the process needs the resources taken up by v8.
3615 */
3616 static bool Dispose();
3617
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +00003618 /** Deprecated. Use Isolate::GetHeapStatistics instead. */
3619 V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics));
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003620
3621 /**
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003622 * Iterates through all external resources referenced from current isolate
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00003623 * heap. GC is not invoked prior to iterating, therefore there is no
3624 * guarantee that visited objects are still alive.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003625 */
3626 static void VisitExternalResources(ExternalResourceVisitor* visitor);
3627
3628 /**
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003629 * Iterates through all the persistent handles in the current isolate's heap
3630 * that have class_ids.
3631 */
3632 static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
3633
3634 /**
yangguo@chromium.org003650e2013-01-24 16:31:08 +00003635 * Iterates through all the persistent handles in the current isolate's heap
3636 * that have class_ids and are candidates to be marked as partially dependent
3637 * handles. This will visit handles to young objects created since the last
3638 * garbage collection but is free to visit an arbitrary superset of these
3639 * objects.
3640 */
3641 static void VisitHandlesForPartialDependence(
3642 Isolate* isolate, PersistentHandleVisitor* visitor);
3643
3644 /**
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003645 * Optional notification that the embedder is idle.
3646 * V8 uses the notification to reduce memory footprint.
ager@chromium.orgab99eea2009-08-25 07:05:41 +00003647 * This call can be used repeatedly if the embedder remains idle.
ager@chromium.orgab99eea2009-08-25 07:05:41 +00003648 * Returns true if the embedder should stop calling IdleNotification
3649 * until real work has been done. This indicates that V8 has done
3650 * as much cleanup as it will be able to do.
svenpanne@chromium.orgecb9dd62011-12-01 08:22:35 +00003651 *
3652 * The hint argument specifies the amount of work to be done in the function
3653 * on scale from 1 to 1000. There is no guarantee that the actual work will
3654 * match the hint.
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003655 */
svenpanne@chromium.orgecb9dd62011-12-01 08:22:35 +00003656 static bool IdleNotification(int hint = 1000);
ager@chromium.orgadd848f2009-08-13 12:44:13 +00003657
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003658 /**
3659 * Optional notification that the system is running low on memory.
3660 * V8 uses these notifications to attempt to free memory.
3661 */
3662 static void LowMemoryNotification();
3663
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00003664 /**
3665 * Optional notification that a context has been disposed. V8 uses
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00003666 * these notifications to guide the GC heuristic. Returns the number
3667 * of context disposals - including this one - since the last time
3668 * V8 had a chance to clean up.
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00003669 */
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00003670 static int ContextDisposedNotification();
kasperl@chromium.org8b2bb262010-03-01 09:46:28 +00003671
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003672 private:
3673 V8();
3674
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00003675 static internal::Object** GlobalizeReference(internal::Isolate* isolate,
3676 internal::Object** handle);
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00003677 static void DisposeGlobal(internal::Isolate* isolate,
3678 internal::Object** global_handle);
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003679 static void MakeWeak(internal::Isolate* isolate,
3680 internal::Object** global_handle,
3681 void* data,
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00003682 WeakReferenceCallback weak_reference_callback,
3683 NearDeathCallback near_death_callback);
3684 static void ClearWeak(internal::Isolate* isolate,
3685 internal::Object** global_handle);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003686
3687 template <class T> friend class Handle;
3688 template <class T> friend class Local;
3689 template <class T> friend class Persistent;
3690 friend class Context;
3691};
3692
3693
3694/**
3695 * An external exception handler.
3696 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003697class V8EXPORT TryCatch {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003698 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003699 /**
mmassi@chromium.org49a44672012-12-04 13:52:03 +00003700 * Creates a new try/catch block and registers it with v8. Note that
3701 * all TryCatch blocks should be stack allocated because the memory
3702 * location itself is compared against JavaScript try/catch blocks.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003703 */
3704 TryCatch();
3705
3706 /**
3707 * Unregisters and deletes this try/catch block.
3708 */
3709 ~TryCatch();
3710
3711 /**
3712 * Returns true if an exception has been caught by this try/catch block.
3713 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003714 bool HasCaught() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003715
3716 /**
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +00003717 * For certain types of exceptions, it makes no sense to continue
3718 * execution.
3719 *
3720 * Currently, the only type of exception that can be caught by a
3721 * TryCatch handler and for which it does not make sense to continue
3722 * is termination exception. Such exceptions are thrown when the
3723 * TerminateExecution methods are called to terminate a long-running
3724 * script.
3725 *
3726 * If CanContinue returns false, the correct action is to perform
3727 * any C++ cleanup needed and then return.
3728 */
3729 bool CanContinue() const;
3730
3731 /**
christian.plesner.hansen@gmail.comb9ce6372009-11-03 11:38:18 +00003732 * Throws the exception caught by this TryCatch in a way that avoids
3733 * it being caught again by this same TryCatch. As with ThrowException
3734 * it is illegal to execute any JavaScript operations after calling
3735 * ReThrow; the caller must return immediately to where the exception
3736 * is caught.
3737 */
3738 Handle<Value> ReThrow();
3739
3740 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003741 * Returns the exception caught by this try/catch block. If no exception has
3742 * been caught an empty handle is returned.
3743 *
3744 * The returned handle is valid until this TryCatch block has been destroyed.
3745 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003746 Local<Value> Exception() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003747
3748 /**
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00003749 * Returns the .stack property of the thrown object. If no .stack
3750 * property is present an empty handle is returned.
3751 */
3752 Local<Value> StackTrace() const;
3753
3754 /**
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003755 * Returns the message associated with this exception. If there is
3756 * no message associated an empty handle is returned.
3757 *
3758 * The returned handle is valid until this TryCatch block has been
3759 * destroyed.
3760 */
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003761 Local<v8::Message> Message() const;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003762
3763 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003764 * Clears any exceptions that may have been caught by this try/catch block.
3765 * After this method has been called, HasCaught() will return false.
3766 *
3767 * It is not necessary to clear a try/catch block before using it again; if
3768 * another exception is thrown the previously caught exception will just be
3769 * overwritten. However, it is often a good idea since it makes it easier
3770 * to determine which operation threw a given exception.
3771 */
3772 void Reset();
3773
v8.team.kasperl727e9952008-09-02 14:56:44 +00003774 /**
3775 * Set verbosity of the external exception handler.
3776 *
3777 * By default, exceptions that are caught by an external exception
3778 * handler are not reported. Call SetVerbose with true on an
3779 * external exception handler to have exceptions caught by the
3780 * handler reported as if they were not caught.
3781 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003782 void SetVerbose(bool value);
3783
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003784 /**
3785 * Set whether or not this TryCatch should capture a Message object
3786 * which holds source information about where the exception
3787 * occurred. True by default.
3788 */
3789 void SetCaptureMessage(bool value);
3790
ager@chromium.orgc4c92722009-11-18 14:12:51 +00003791 private:
mmassi@chromium.org49a44672012-12-04 13:52:03 +00003792 // Make it hard to create heap-allocated TryCatch blocks.
3793 TryCatch(const TryCatch&);
3794 void operator=(const TryCatch&);
3795 void* operator new(size_t size);
3796 void operator delete(void*, size_t);
3797
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00003798 v8::internal::Isolate* isolate_;
ager@chromium.orgc4c92722009-11-18 14:12:51 +00003799 void* next_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003800 void* exception_;
ager@chromium.org9258b6b2008-09-11 09:11:10 +00003801 void* message_;
christian.plesner.hansen@gmail.comb9ce6372009-11-03 11:38:18 +00003802 bool is_verbose_ : 1;
3803 bool can_continue_ : 1;
3804 bool capture_message_ : 1;
3805 bool rethrow_ : 1;
ager@chromium.orgc4c92722009-11-18 14:12:51 +00003806
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003807 friend class v8::internal::Isolate;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003808};
3809
3810
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00003811// --- Context ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003812
3813
3814/**
3815 * Ignore
3816 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003817class V8EXPORT ExtensionConfiguration {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003818 public:
3819 ExtensionConfiguration(int name_count, const char* names[])
3820 : name_count_(name_count), names_(names) { }
3821 private:
3822 friend class ImplementationUtilities;
3823 int name_count_;
3824 const char** names_;
3825};
3826
3827
3828/**
3829 * A sandboxed execution context with its own set of built-in objects
3830 * and functions.
3831 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003832class V8EXPORT Context {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003833 public:
whesse@chromium.org7a392b32011-01-31 11:30:36 +00003834 /**
3835 * Returns the global proxy object or global object itself for
3836 * detached contexts.
3837 *
3838 * Global proxy object is a thin wrapper whose prototype points to
3839 * actual context's global object with the properties like Object, etc.
3840 * This is done that way for security reasons (for more details see
3841 * https://wiki.mozilla.org/Gecko:SplitWindow).
3842 *
3843 * Please note that changes to global proxy object prototype most probably
3844 * would break VM---v8 expects only global object as a prototype of
3845 * global proxy object.
3846 *
3847 * If DetachGlobal() has been invoked, Global() would return actual global
3848 * object until global is reattached with ReattachGlobal().
3849 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003850 Local<Object> Global();
3851
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003852 /**
3853 * Detaches the global object from its context before
3854 * the global object can be reused to create a new context.
3855 */
3856 void DetachGlobal();
3857
sgjesse@chromium.orgdf7a2842010-03-25 14:34:15 +00003858 /**
3859 * Reattaches a global object to a context. This can be used to
3860 * restore the connection between a global object and a context
3861 * after DetachGlobal has been called.
3862 *
3863 * \param global_object The global object to reattach to the
3864 * context. For this to work, the global object must be the global
3865 * object that was associated with this context before a call to
3866 * DetachGlobal.
3867 */
3868 void ReattachGlobal(Handle<Object> global_object);
3869
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00003870 /** Creates a new context.
3871 *
3872 * Returns a persistent handle to the newly allocated context. This
3873 * persistent handle has to be disposed when the context is no
3874 * longer used so the context can be garbage collected.
lrn@chromium.org5d00b602011-01-05 09:51:43 +00003875 *
3876 * \param extensions An optional extension configuration containing
3877 * the extensions to be installed in the newly created context.
3878 *
3879 * \param global_template An optional object template from which the
3880 * global object for the newly created context will be created.
3881 *
3882 * \param global_object An optional global object to be reused for
3883 * the newly created context. This global object must have been
3884 * created by a previous call to Context::New with the same global
3885 * template. The state of the global object will be completely reset
3886 * and only object identify will remain.
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00003887 */
v8.team.kasperl727e9952008-09-02 14:56:44 +00003888 static Persistent<Context> New(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00003889 ExtensionConfiguration* extensions = NULL,
v8.team.kasperl727e9952008-09-02 14:56:44 +00003890 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
3891 Handle<Value> global_object = Handle<Value>());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003892
kasper.lund44510672008-07-25 07:37:58 +00003893 /** Returns the last entered context. */
3894 static Local<Context> GetEntered();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003895
kasper.lund44510672008-07-25 07:37:58 +00003896 /** Returns the context that is on the top of the stack. */
3897 static Local<Context> GetCurrent();
3898
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003899 /**
ager@chromium.org1bf0cd02009-05-20 11:34:19 +00003900 * Returns the context of the calling JavaScript code. That is the
3901 * context of the top-most JavaScript frame. If there are no
3902 * JavaScript frames an empty handle is returned.
3903 */
3904 static Local<Context> GetCalling();
3905
3906 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003907 * Sets the security token for the context. To access an object in
3908 * another context, the security tokens must match.
3909 */
3910 void SetSecurityToken(Handle<Value> token);
3911
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00003912 /** Restores the security token to the default value. */
3913 void UseDefaultSecurityToken();
3914
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003915 /** Returns the security token of this context.*/
3916 Handle<Value> GetSecurityToken();
3917
v8.team.kasperl727e9952008-09-02 14:56:44 +00003918 /**
3919 * Enter this context. After entering a context, all code compiled
3920 * and run is compiled and run in this context. If another context
3921 * is already entered, this old context is saved so it can be
3922 * restored when the new context is exited.
3923 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003924 void Enter();
v8.team.kasperl727e9952008-09-02 14:56:44 +00003925
3926 /**
3927 * Exit this context. Exiting the current context restores the
3928 * context that was in place when entering the current context.
3929 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003930 void Exit();
3931
v8.team.kasperl727e9952008-09-02 14:56:44 +00003932 /** Returns true if the context has experienced an out of memory situation. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003933 bool HasOutOfMemoryException();
3934
v8.team.kasperl727e9952008-09-02 14:56:44 +00003935 /** Returns true if V8 has a current context. */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003936 static bool InContext();
3937
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00003938 /** Returns an isolate associated with a current context. */
3939 v8::Isolate* GetIsolate();
yangguo@chromium.orge19986e2013-01-16 09:48:20 +00003940
3941 /**
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00003942 * Gets the embedder data with the given index, which must have been set by a
3943 * previous call to SetEmbedderData with the same index. Note that index 0
3944 * currently has a special meaning for Chrome's debugger.
3945 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003946 V8_INLINE(Local<Value> GetEmbedderData(int index));
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00003947
3948 /**
3949 * Sets the embedder data with the given index, growing the data as
3950 * needed. Note that index 0 currently has a special meaning for Chrome's
3951 * debugger.
3952 */
3953 void SetEmbedderData(int index, Handle<Value> value);
3954
3955 /**
3956 * Gets a 2-byte-aligned native pointer from the embedder data with the given
3957 * index, which must have bees set by a previous call to
3958 * SetAlignedPointerInEmbedderData with the same index. Note that index 0
3959 * currently has a special meaning for Chrome's debugger.
3960 */
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00003961 V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index));
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00003962
3963 /**
3964 * Sets a 2-byte-aligned native pointer in the embedder data with the given
3965 * index, growing the data as needed. Note that index 0 currently has a
3966 * special meaning for Chrome's debugger.
3967 */
3968 void SetAlignedPointerInEmbedderData(int index, void* value);
ager@chromium.org9085a012009-05-11 19:22:57 +00003969
3970 /**
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00003971 * Control whether code generation from strings is allowed. Calling
3972 * this method with false will disable 'eval' and the 'Function'
3973 * constructor for code running in this context. If 'eval' or the
3974 * 'Function' constructor are used an exception will be thrown.
3975 *
3976 * If code generation from strings is not allowed the
3977 * V8::AllowCodeGenerationFromStrings callback will be invoked if
3978 * set before blocking the call to 'eval' or the 'Function'
3979 * constructor. If that callback returns true, the call will be
3980 * allowed, otherwise an exception will be thrown. If no callback is
3981 * set an exception will be thrown.
3982 */
3983 void AllowCodeGenerationFromStrings(bool allow);
3984
3985 /**
jkummerow@chromium.org1145ef82012-02-02 16:21:15 +00003986 * Returns true if code generation from strings is allowed for the context.
3987 * For more details see AllowCodeGenerationFromStrings(bool) documentation.
3988 */
3989 bool IsCodeGenerationFromStringsAllowed();
3990
3991 /**
ulan@chromium.org56c14af2012-09-20 12:51:09 +00003992 * Sets the error description for the exception that is thrown when
3993 * code generation from strings is not allowed and 'eval' or the 'Function'
3994 * constructor are called.
3995 */
3996 void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message);
3997
3998 /**
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003999 * Stack-allocated class which sets the execution context for all
4000 * operations executed within a local scope.
4001 */
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004002 class Scope {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004003 public:
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004004 explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004005 context_->Enter();
4006 }
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004007 V8_INLINE(~Scope()) { context_->Exit(); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004008 private:
4009 Handle<Context> context_;
4010 };
4011
4012 private:
4013 friend class Value;
4014 friend class Script;
4015 friend class Object;
4016 friend class Function;
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004017
4018 Local<Value> SlowGetEmbedderData(int index);
4019 void* SlowGetAlignedPointerFromEmbedderData(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004020};
4021
4022
4023/**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004024 * Multiple threads in V8 are allowed, but only one thread at a time is allowed
4025 * to use any given V8 isolate, see the comments in the Isolate class. The
4026 * definition of 'using a V8 isolate' includes accessing handles or holding onto
4027 * object pointers obtained from V8 handles while in the particular V8 isolate.
4028 * It is up to the user of V8 to ensure, perhaps with locking, that this
4029 * constraint is not violated. In addition to any other synchronization
4030 * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be
4031 * used to signal thead switches to V8.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004032 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004033 * v8::Locker is a scoped lock object. While it's active, i.e. between its
4034 * construction and destruction, the current thread is allowed to use the locked
4035 * isolate. V8 guarantees that an isolate can be locked by at most one thread at
4036 * any time. In other words, the scope of a v8::Locker is a critical section.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004037 *
lrn@chromium.org1c092762011-05-09 09:42:16 +00004038 * Sample usage:
4039* \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004040 * ...
4041 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004042 * v8::Locker locker(isolate);
4043 * v8::Isolate::Scope isolate_scope(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004044 * ...
lrn@chromium.org1c092762011-05-09 09:42:16 +00004045 * // Code using V8 and isolate goes here.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004046 * ...
4047 * } // Destructor called here
v8.team.kasperl727e9952008-09-02 14:56:44 +00004048 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004049 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004050 * If you wish to stop using V8 in a thread A you can do this either by
4051 * destroying the v8::Locker object as above or by constructing a v8::Unlocker
4052 * object:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004053 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00004054 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004055 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004056 * isolate->Exit();
4057 * v8::Unlocker unlocker(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004058 * ...
4059 * // Code not using V8 goes here while V8 can run in another thread.
4060 * ...
4061 * } // Destructor called here.
lrn@chromium.org1c092762011-05-09 09:42:16 +00004062 * isolate->Enter();
v8.team.kasperl727e9952008-09-02 14:56:44 +00004063 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004064 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004065 * The Unlocker object is intended for use in a long-running callback from V8,
4066 * where you want to release the V8 lock for other threads to use.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004067 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004068 * The v8::Locker is a recursive lock, i.e. you can lock more than once in a
4069 * given thread. This can be useful if you have code that can be called either
4070 * from code that holds the lock or from code that does not. The Unlocker is
4071 * not recursive so you can not have several Unlockers on the stack at once, and
4072 * 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 +00004073 *
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004074 * An unlocker will unlock several lockers if it has to and reinstate the
4075 * correct depth of locking on its destruction, e.g.:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004076 *
v8.team.kasperl727e9952008-09-02 14:56:44 +00004077 * \code
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004078 * // V8 not locked.
4079 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004080 * v8::Locker locker(isolate);
4081 * Isolate::Scope isolate_scope(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004082 * // V8 locked.
4083 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004084 * v8::Locker another_locker(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004085 * // V8 still locked (2 levels).
4086 * {
lrn@chromium.org1c092762011-05-09 09:42:16 +00004087 * isolate->Exit();
4088 * v8::Unlocker unlocker(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004089 * // V8 not locked.
4090 * }
lrn@chromium.org1c092762011-05-09 09:42:16 +00004091 * isolate->Enter();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004092 * // V8 locked again (2 levels).
4093 * }
4094 * // V8 still locked (1 level).
4095 * }
4096 * // V8 Now no longer locked.
v8.team.kasperl727e9952008-09-02 14:56:44 +00004097 * \endcode
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004098 */
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00004099class V8EXPORT Unlocker {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004100 public:
lrn@chromium.org1c092762011-05-09 09:42:16 +00004101 /**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004102 * Initialize Unlocker for a given Isolate.
lrn@chromium.org1c092762011-05-09 09:42:16 +00004103 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004104 V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); }
4105
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004106 /** Deprecated. Use Isolate version instead. */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004107 V8_DEPRECATED(Unlocker());
4108
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004109 ~Unlocker();
lrn@chromium.org1c092762011-05-09 09:42:16 +00004110 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004111 void Initialize(Isolate* isolate);
4112
lrn@chromium.org1c092762011-05-09 09:42:16 +00004113 internal::Isolate* isolate_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004114};
4115
4116
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00004117class V8EXPORT Locker {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004118 public:
lrn@chromium.org1c092762011-05-09 09:42:16 +00004119 /**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004120 * Initialize Locker for a given Isolate.
lrn@chromium.org1c092762011-05-09 09:42:16 +00004121 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004122 V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); }
4123
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004124 /** Deprecated. Use Isolate version instead. */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004125 V8_DEPRECATED(Locker());
4126
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004127 ~Locker();
v8.team.kasperl727e9952008-09-02 14:56:44 +00004128
4129 /**
4130 * Start preemption.
4131 *
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00004132 * When preemption is started, a timer is fired every n milliseconds
v8.team.kasperl727e9952008-09-02 14:56:44 +00004133 * that will switch between multiple threads that are in contention
4134 * for the V8 lock.
4135 */
4136 static void StartPreemption(int every_n_ms);
4137
4138 /**
4139 * Stop preemption.
4140 */
4141 static void StopPreemption();
4142
ager@chromium.org9258b6b2008-09-11 09:11:10 +00004143 /**
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004144 * Returns whether or not the locker for a given isolate, is locked by the
4145 * current thread.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00004146 */
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004147 static bool IsLocked(Isolate* isolate);
ager@chromium.org9258b6b2008-09-11 09:11:10 +00004148
ager@chromium.orgddb913d2009-01-27 10:01:48 +00004149 /**
4150 * Returns whether v8::Locker is being used by this V8 instance.
4151 */
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00004152 static bool IsActive();
ager@chromium.orgddb913d2009-01-27 10:01:48 +00004153
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004154 private:
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004155 void Initialize(Isolate* isolate);
4156
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004157 bool has_lock_;
4158 bool top_level_;
lrn@chromium.org1c092762011-05-09 09:42:16 +00004159 internal::Isolate* isolate_;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00004160
ager@chromium.orgddb913d2009-01-27 10:01:48 +00004161 static bool active_;
4162
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00004163 // Disallow copying and assigning.
4164 Locker(const Locker&);
4165 void operator=(const Locker&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004166};
4167
4168
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004169/**
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004170 * A struct for exporting HeapStats data from V8, using "push" model.
4171 */
4172struct HeapStatsUpdate;
4173
4174
4175/**
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004176 * An interface for exporting data from V8, using "push" model.
4177 */
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +00004178class V8EXPORT OutputStream { // NOLINT
4179 public:
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004180 enum OutputEncoding {
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004181 kAscii = 0 // 7-bit ASCII.
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004182 };
4183 enum WriteResult {
4184 kContinue = 0,
4185 kAbort = 1
4186 };
4187 virtual ~OutputStream() {}
4188 /** Notify about the end of stream. */
4189 virtual void EndOfStream() = 0;
4190 /** Get preferred output chunk size. Called only once. */
4191 virtual int GetChunkSize() { return 1024; }
4192 /** Get preferred output encoding. Called only once. */
4193 virtual OutputEncoding GetOutputEncoding() { return kAscii; }
4194 /**
4195 * Writes the next chunk of snapshot data into the stream. Writing
4196 * can be stopped by returning kAbort as function result. EndOfStream
4197 * will not be called in case writing was aborted.
4198 */
4199 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00004200 /**
4201 * Writes the next chunk of heap stats data into the stream. Writing
4202 * can be stopped by returning kAbort as function result. EndOfStream
4203 * will not be called in case writing was aborted.
4204 */
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004205 virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
jkummerow@chromium.org3ee08a62012-04-13 13:01:33 +00004206 return kAbort;
4207 };
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +00004208};
4209
4210
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00004211/**
4212 * An interface for reporting progress and controlling long-running
4213 * activities.
4214 */
4215class V8EXPORT ActivityControl { // NOLINT
4216 public:
4217 enum ControlOption {
4218 kContinue = 0,
4219 kAbort = 1
4220 };
4221 virtual ~ActivityControl() {}
4222 /**
4223 * Notify about current progress. The activity can be stopped by
4224 * returning kAbort as the callback result.
4225 */
4226 virtual ControlOption ReportProgressValue(int done, int total) = 0;
4227};
4228
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004229
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00004230// --- Implementation ---
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004231
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004232
4233namespace internal {
4234
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00004235const int kApiPointerSize = sizeof(void*); // NOLINT
4236const int kApiIntSize = sizeof(int); // NOLINT
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004237
4238// Tag information for HeapObject.
4239const int kHeapObjectTag = 1;
4240const int kHeapObjectTagSize = 2;
4241const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
4242
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004243// Tag information for Smi.
4244const int kSmiTag = 0;
4245const int kSmiTagSize = 1;
4246const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
4247
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004248template <size_t ptr_size> struct SmiTagging;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004249
4250// Smi constants for 32-bit systems.
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004251template <> struct SmiTagging<4> {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004252 static const int kSmiShiftSize = 0;
4253 static const int kSmiValueSize = 31;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004254 V8_INLINE(static int SmiToInt(internal::Object* value)) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004255 int shift_bits = kSmiTagSize + kSmiShiftSize;
4256 // Throw away top 32 bits and shift down (requires >> to be sign extending).
4257 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
4258 }
4259};
4260
4261// Smi constants for 64-bit systems.
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004262template <> struct SmiTagging<8> {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004263 static const int kSmiShiftSize = 31;
4264 static const int kSmiValueSize = 32;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004265 V8_INLINE(static int SmiToInt(internal::Object* value)) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004266 int shift_bits = kSmiTagSize + kSmiShiftSize;
4267 // Shift down and throw away top 32 bits.
4268 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
4269 }
4270};
4271
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004272typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
4273const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
4274const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004275
4276/**
4277 * This class exports constants and functionality from within v8 that
4278 * is necessary to implement inline functions in the v8 api. Don't
4279 * depend on functions and constants defined here.
4280 */
4281class Internals {
4282 public:
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004283 // These values match non-compiler-dependent values defined within
4284 // the implementation of v8.
4285 static const int kHeapObjectMapOffset = 0;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004286 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004287 static const int kStringResourceOffset = 3 * kApiPointerSize;
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00004288
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004289 static const int kOddballKindOffset = 3 * kApiPointerSize;
ager@chromium.orgea91cc52011-05-23 06:06:11 +00004290 static const int kForeignAddressOffset = kApiPointerSize;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00004291 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004292 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
4293 static const int kContextHeaderSize = 2 * kApiPointerSize;
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00004294 static const int kContextEmbedderDataIndex = 55;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004295 static const int kFullStringRepresentationMask = 0x07;
ulan@chromium.org56c14af2012-09-20 12:51:09 +00004296 static const int kStringEncodingMask = 0x4;
sgjesse@chromium.org82dbbab2010-06-02 08:57:44 +00004297 static const int kExternalTwoByteRepresentationTag = 0x02;
ulan@chromium.org56c14af2012-09-20 12:51:09 +00004298 static const int kExternalAsciiRepresentationTag = 0x06;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004299
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004300 static const int kIsolateStateOffset = 0;
4301 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
4302 static const int kIsolateRootsOffset = 3 * kApiPointerSize;
4303 static const int kUndefinedValueRootIndex = 5;
4304 static const int kNullValueRootIndex = 7;
4305 static const int kTrueValueRootIndex = 8;
4306 static const int kFalseValueRootIndex = 9;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004307 static const int kEmptyStringRootIndex = 119;
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004308
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004309 static const int kNodeClassIdOffset = 1 * kApiPointerSize;
4310 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
4311 static const int kNodeStateMask = 0xf;
4312 static const int kNodeStateIsWeakValue = 2;
4313 static const int kNodeStateIsNearDeathValue = 4;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004314 static const int kNodeIsIndependentShift = 4;
4315 static const int kNodeIsPartiallyDependentShift = 5;
4316
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004317 static const int kJSObjectType = 0xae;
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +00004318 static const int kFirstNonstringType = 0x80;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004319 static const int kOddballType = 0x83;
4320 static const int kForeignType = 0x86;
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004321
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004322 static const int kUndefinedOddballKind = 5;
4323 static const int kNullOddballKind = 3;
4324
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004325 V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004326 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
4327 kHeapObjectTag);
4328 }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00004329
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004330 V8_INLINE(static int SmiValue(internal::Object* value)) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004331 return PlatformSmiTagging::SmiToInt(value);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004332 }
4333
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004334 V8_INLINE(static int GetInstanceType(internal::Object* obj)) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004335 typedef internal::Object O;
4336 O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
4337 return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
4338 }
4339
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004340 V8_INLINE(static int GetOddballKind(internal::Object* obj)) {
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004341 typedef internal::Object O;
4342 return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
4343 }
4344
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004345 V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004346 int representation = (instance_type & kFullStringRepresentationMask);
4347 return representation == kExternalTwoByteRepresentationTag;
4348 }
4349
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004350 V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004351 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
4352 return *reinterpret_cast<int*>(addr) == 1;
4353 }
4354
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004355 V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) {
4356 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4357 return *addr & (1 << shift);
4358 }
4359
4360 V8_INLINE(static void UpdateNodeFlag(internal::Object** obj,
4361 bool value, int shift)) {
4362 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4363 uint8_t mask = 1 << shift;
4364 *addr = (*addr & ~mask) | (value << shift);
4365 }
4366
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004367 V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) {
4368 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4369 return *addr & kNodeStateMask;
4370 }
4371
4372 V8_INLINE(static void UpdateNodeState(internal::Object** obj,
4373 uint8_t value)) {
4374 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
4375 *addr = (*addr & ~kNodeStateMask) | value;
4376 }
4377
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004378 V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004379 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4380 kIsolateEmbedderDataOffset;
4381 *reinterpret_cast<void**>(addr) = data;
4382 }
4383
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004384 V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004385 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4386 kIsolateEmbedderDataOffset;
4387 return *reinterpret_cast<void**>(addr);
4388 }
4389
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004390 V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate,
4391 int index)) {
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004392 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
4393 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
4394 }
4395
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004396 template <typename T>
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004397 V8_INLINE(static T ReadField(Object* ptr, int offset)) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004398 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
4399 return *reinterpret_cast<T*>(addr);
4400 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004401
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004402 template <typename T>
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004403 V8_INLINE(static T ReadEmbedderData(Context* context, int index)) {
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004404 typedef internal::Object O;
4405 typedef internal::Internals I;
4406 O* ctx = *reinterpret_cast<O**>(context);
4407 int embedder_data_offset = I::kContextHeaderSize +
4408 (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
4409 O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
4410 int value_offset =
4411 I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
4412 return I::ReadField<T>(embedder_data, value_offset);
4413 }
4414
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004415 V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; }
4416 V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; }
4417 V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; }
4418 V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; }
4419 V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; }
4420 V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; }
4421 V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; }
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004422};
4423
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +00004424} // namespace internal
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004425
4426
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004427template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004428Local<T>::Local() : Handle<T>() { }
4429
4430
4431template <class T>
4432Local<T> Local<T>::New(Handle<T> that) {
4433 if (that.IsEmpty()) return Local<T>();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004434 T* that_ptr = *that;
4435 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
4436 if (internal::Internals::CanCastToHeapObject(that_ptr)) {
4437 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
4438 reinterpret_cast<internal::HeapObject*>(*p))));
4439 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004440 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
4441}
4442
4443
4444template <class T>
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004445Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) {
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004446 if (that.IsEmpty()) return Local<T>();
4447 T* that_ptr = *that;
4448 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
4449 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
4450 reinterpret_cast<internal::Isolate*>(isolate), *p)));
4451}
4452
4453
4454template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004455Persistent<T> Persistent<T>::New(Handle<T> that) {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004456 return New(Isolate::GetCurrent(), that);
4457}
4458
4459
4460template <class T>
4461Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004462 if (that.IsEmpty()) return Persistent<T>();
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004463 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004464 return Persistent<T>(reinterpret_cast<T*>(
4465 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
4466 p)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004467}
4468
4469
4470template <class T>
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004471bool Persistent<T>::IsIndependent() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004472 return IsIndependent(Isolate::GetCurrent());
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004473}
4474
4475
4476template <class T>
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004477bool Persistent<T>::IsIndependent(Isolate* isolate) const {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004478 typedef internal::Internals I;
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004479 if (this->IsEmpty()) return false;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004480 if (!I::IsInitialized(isolate)) return false;
4481 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(**this),
4482 I::kNodeIsIndependentShift);
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004483}
4484
4485
4486template <class T>
ager@chromium.org32912102009-01-16 10:38:43 +00004487bool Persistent<T>::IsNearDeath() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004488 return IsNearDeath(Isolate::GetCurrent());
4489}
4490
4491
4492template <class T>
4493bool Persistent<T>::IsNearDeath(Isolate* isolate) const {
4494 typedef internal::Internals I;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004495 if (this->IsEmpty()) return false;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004496 if (!I::IsInitialized(isolate)) return false;
4497 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) ==
4498 I::kNodeStateIsNearDeathValue;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004499}
4500
4501
4502template <class T>
ager@chromium.org32912102009-01-16 10:38:43 +00004503bool Persistent<T>::IsWeak() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004504 return IsWeak(Isolate::GetCurrent());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004505}
4506
4507
4508template <class T>
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004509bool Persistent<T>::IsWeak(Isolate* isolate) const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004510 typedef internal::Internals I;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004511 if (this->IsEmpty()) return false;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004512 if (!I::IsInitialized(isolate)) return false;
4513 return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) ==
4514 I::kNodeStateIsWeakValue;
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004515}
4516
4517
4518template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004519void Persistent<T>::Dispose() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004520 Dispose(Isolate::GetCurrent());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004521}
4522
4523
4524template <class T>
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +00004525void Persistent<T>::Dispose(Isolate* isolate) {
4526 if (this->IsEmpty()) return;
4527 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate),
4528 reinterpret_cast<internal::Object**>(**this));
4529}
4530
4531
4532template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004533Persistent<T>::Persistent() : Handle<T>() { }
4534
4535template <class T>
4536void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004537 Isolate* isolate = Isolate::GetCurrent();
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004538 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate),
4539 reinterpret_cast<internal::Object**>(**this),
4540 parameters,
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004541 callback,
4542 NULL);
4543}
4544
4545template <class T>
4546void Persistent<T>::MakeWeak(Isolate* isolate,
4547 void* parameters,
4548 NearDeathCallback callback) {
4549 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate),
4550 reinterpret_cast<internal::Object**>(**this),
4551 parameters,
4552 NULL,
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00004553 callback);
4554}
4555
4556template <class T>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004557void Persistent<T>::ClearWeak() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004558 ClearWeak(Isolate::GetCurrent());
4559}
4560
4561template <class T>
4562void Persistent<T>::ClearWeak(Isolate* isolate) {
4563 V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate),
4564 reinterpret_cast<internal::Object**>(**this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004565}
4566
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00004567template <class T>
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004568void Persistent<T>::MarkIndependent() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004569 MarkIndependent(Isolate::GetCurrent());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00004570}
4571
4572template <class T>
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004573void Persistent<T>::MarkIndependent(Isolate* isolate) {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004574 typedef internal::Internals I;
4575 if (this->IsEmpty()) return;
4576 if (!I::IsInitialized(isolate)) return;
4577 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this),
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004578 true,
4579 I::kNodeIsIndependentShift);
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004580}
4581
4582template <class T>
4583void Persistent<T>::MarkPartiallyDependent() {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004584 MarkPartiallyDependent(Isolate::GetCurrent());
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004585}
4586
4587template <class T>
4588void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004589 typedef internal::Internals I;
4590 if (this->IsEmpty()) return;
4591 if (!I::IsInitialized(isolate)) return;
4592 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this),
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004593 true,
4594 I::kNodeIsPartiallyDependentShift);
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00004595}
4596
4597template <class T>
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00004598void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004599 SetWrapperClassId(Isolate::GetCurrent(), class_id);
4600}
4601
4602template <class T>
4603void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004604 typedef internal::Internals I;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004605 if (this->IsEmpty()) return;
4606 if (!I::IsInitialized(isolate)) return;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004607 internal::Object** obj = reinterpret_cast<internal::Object**>(**this);
4608 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
4609 *reinterpret_cast<uint16_t*>(addr) = class_id;
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00004610}
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004611
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004612template <class T>
4613uint16_t Persistent<T>::WrapperClassId() const {
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004614 return WrapperClassId(Isolate::GetCurrent());
4615}
4616
4617template <class T>
4618uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const {
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004619 typedef internal::Internals I;
mvstanton@chromium.orgd16d8532013-01-25 13:29:10 +00004620 if (this->IsEmpty()) return 0;
4621 if (!I::IsInitialized(isolate)) return 0;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +00004622 internal::Object** obj = reinterpret_cast<internal::Object**>(**this);
4623 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
4624 return *reinterpret_cast<uint16_t*>(addr);
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00004625}
4626
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004627Arguments::Arguments(internal::Object** implicit_args,
4628 internal::Object** values, int length,
4629 bool is_construct_call)
4630 : implicit_args_(implicit_args),
4631 values_(values),
4632 length_(length),
4633 is_construct_call_(is_construct_call) { }
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004634
4635
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004636Local<Value> Arguments::operator[](int i) const {
4637 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
4638 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
4639}
4640
4641
4642Local<Function> Arguments::Callee() const {
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004643 return Local<Function>(reinterpret_cast<Function*>(
4644 &implicit_args_[kCalleeIndex]));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004645}
4646
4647
4648Local<Object> Arguments::This() const {
4649 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
4650}
4651
4652
4653Local<Object> Arguments::Holder() const {
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004654 return Local<Object>(reinterpret_cast<Object*>(
4655 &implicit_args_[kHolderIndex]));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004656}
4657
4658
4659Local<Value> Arguments::Data() const {
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00004660 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004661}
4662
4663
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00004664Isolate* Arguments::GetIsolate() const {
4665 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
4666}
4667
4668
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004669bool Arguments::IsConstructCall() const {
4670 return is_construct_call_;
4671}
4672
4673
4674int Arguments::Length() const {
4675 return length_;
4676}
4677
4678
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004679template <class T>
4680Local<T> HandleScope::Close(Handle<T> value) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004681 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
4682 internal::Object** after = RawClose(before);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004683 return Local<T>(reinterpret_cast<T*>(after));
4684}
4685
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00004686Handle<Value> ScriptOrigin::ResourceName() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004687 return resource_name_;
4688}
4689
4690
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00004691Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004692 return resource_line_offset_;
4693}
4694
4695
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00004696Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004697 return resource_column_offset_;
4698}
4699
4700
4701Handle<Boolean> Boolean::New(bool value) {
4702 return value ? True() : False();
4703}
4704
4705
4706void Template::Set(const char* name, v8::Handle<Data> value) {
4707 Set(v8::String::New(name), value);
4708}
4709
4710
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004711Local<Value> Object::GetInternalField(int index) {
4712#ifndef V8_ENABLE_CHECKS
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004713 typedef internal::Object O;
4714 typedef internal::Internals I;
4715 O* obj = *reinterpret_cast<O**>(this);
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004716 // Fast path: If the object is a plain JSObject, which is the common case, we
4717 // know where to find the internal fields and can return the value directly.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004718 if (I::GetInstanceType(obj) == I::kJSObjectType) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00004719 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004720 O* value = I::ReadField<O*>(obj, offset);
4721 O** result = HandleScope::CreateHandle(value);
4722 return Local<Value>(reinterpret_cast<Value*>(result));
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004723 }
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004724#endif
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004725 return SlowGetInternalField(index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004726}
4727
4728
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004729void* Object::GetAlignedPointerFromInternalField(int index) {
4730#ifndef V8_ENABLE_CHECKS
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004731 typedef internal::Object O;
4732 typedef internal::Internals I;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004733 O* obj = *reinterpret_cast<O**>(this);
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004734 // Fast path: If the object is a plain JSObject, which is the common case, we
4735 // know where to find the internal fields and can return the value directly.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004736 if (I::GetInstanceType(obj) == I::kJSObjectType) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00004737 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004738 return I::ReadField<void*>(obj, offset);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004739 }
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00004740#endif
4741 return SlowGetAlignedPointerFromInternalField(index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004742}
4743
4744
4745String* String::Cast(v8::Value* value) {
4746#ifdef V8_ENABLE_CHECKS
4747 CheckCast(value);
4748#endif
4749 return static_cast<String*>(value);
4750}
4751
4752
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004753Local<String> String::Empty(Isolate* isolate) {
4754 typedef internal::Object* S;
4755 typedef internal::Internals I;
4756 if (!I::IsInitialized(isolate)) return Empty();
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00004757 S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004758 return Local<String>(reinterpret_cast<String*>(slot));
4759}
4760
4761
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004762String::ExternalStringResource* String::GetExternalStringResource() const {
4763 typedef internal::Object O;
4764 typedef internal::Internals I;
4765 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004766 String::ExternalStringResource* result;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004767 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004768 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4769 result = reinterpret_cast<String::ExternalStringResource*>(value);
4770 } else {
4771 result = NULL;
4772 }
4773#ifdef V8_ENABLE_CHECKS
4774 VerifyExternalStringResource(result);
4775#endif
4776 return result;
4777}
4778
4779
ulan@chromium.org56c14af2012-09-20 12:51:09 +00004780String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
4781 String::Encoding* encoding_out) const {
4782 typedef internal::Object O;
4783 typedef internal::Internals I;
4784 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4785 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
4786 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
4787 ExternalStringResourceBase* resource = NULL;
4788 if (type == I::kExternalAsciiRepresentationTag ||
4789 type == I::kExternalTwoByteRepresentationTag) {
4790 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4791 resource = static_cast<ExternalStringResourceBase*>(value);
4792 }
4793#ifdef V8_ENABLE_CHECKS
4794 VerifyExternalStringResourceBase(resource, *encoding_out);
4795#endif
4796 return resource;
4797}
4798
4799
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00004800bool Value::IsUndefined() const {
4801#ifdef V8_ENABLE_CHECKS
4802 return FullIsUndefined();
4803#else
4804 return QuickIsUndefined();
4805#endif
4806}
4807
4808bool Value::QuickIsUndefined() const {
4809 typedef internal::Object O;
4810 typedef internal::Internals I;
4811 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4812 if (!I::HasHeapObjectTag(obj)) return false;
4813 if (I::GetInstanceType(obj) != I::kOddballType) return false;
4814 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
4815}
4816
4817
4818bool Value::IsNull() const {
4819#ifdef V8_ENABLE_CHECKS
4820 return FullIsNull();
4821#else
4822 return QuickIsNull();
4823#endif
4824}
4825
4826bool Value::QuickIsNull() const {
4827 typedef internal::Object O;
4828 typedef internal::Internals I;
4829 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4830 if (!I::HasHeapObjectTag(obj)) return false;
4831 if (I::GetInstanceType(obj) != I::kOddballType) return false;
4832 return (I::GetOddballKind(obj) == I::kNullOddballKind);
4833}
4834
4835
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004836bool Value::IsString() const {
4837#ifdef V8_ENABLE_CHECKS
4838 return FullIsString();
4839#else
4840 return QuickIsString();
4841#endif
4842}
4843
4844bool Value::QuickIsString() const {
4845 typedef internal::Object O;
4846 typedef internal::Internals I;
4847 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4848 if (!I::HasHeapObjectTag(obj)) return false;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00004849 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004850}
4851
4852
4853Number* Number::Cast(v8::Value* value) {
4854#ifdef V8_ENABLE_CHECKS
4855 CheckCast(value);
4856#endif
4857 return static_cast<Number*>(value);
4858}
4859
4860
4861Integer* Integer::Cast(v8::Value* value) {
4862#ifdef V8_ENABLE_CHECKS
4863 CheckCast(value);
4864#endif
4865 return static_cast<Integer*>(value);
4866}
4867
4868
4869Date* Date::Cast(v8::Value* value) {
4870#ifdef V8_ENABLE_CHECKS
4871 CheckCast(value);
4872#endif
4873 return static_cast<Date*>(value);
4874}
4875
4876
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00004877StringObject* StringObject::Cast(v8::Value* value) {
4878#ifdef V8_ENABLE_CHECKS
4879 CheckCast(value);
4880#endif
4881 return static_cast<StringObject*>(value);
4882}
4883
4884
4885NumberObject* NumberObject::Cast(v8::Value* value) {
4886#ifdef V8_ENABLE_CHECKS
4887 CheckCast(value);
4888#endif
4889 return static_cast<NumberObject*>(value);
4890}
4891
4892
4893BooleanObject* BooleanObject::Cast(v8::Value* value) {
4894#ifdef V8_ENABLE_CHECKS
4895 CheckCast(value);
4896#endif
4897 return static_cast<BooleanObject*>(value);
4898}
4899
4900
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00004901RegExp* RegExp::Cast(v8::Value* value) {
4902#ifdef V8_ENABLE_CHECKS
4903 CheckCast(value);
4904#endif
4905 return static_cast<RegExp*>(value);
4906}
4907
4908
ager@chromium.org18ad94b2009-09-02 08:22:29 +00004909Object* Object::Cast(v8::Value* value) {
4910#ifdef V8_ENABLE_CHECKS
4911 CheckCast(value);
4912#endif
4913 return static_cast<Object*>(value);
4914}
4915
4916
4917Array* Array::Cast(v8::Value* value) {
4918#ifdef V8_ENABLE_CHECKS
4919 CheckCast(value);
4920#endif
4921 return static_cast<Array*>(value);
4922}
4923
4924
4925Function* Function::Cast(v8::Value* value) {
4926#ifdef V8_ENABLE_CHECKS
4927 CheckCast(value);
4928#endif
4929 return static_cast<Function*>(value);
4930}
4931
4932
4933External* External::Cast(v8::Value* value) {
4934#ifdef V8_ENABLE_CHECKS
4935 CheckCast(value);
4936#endif
4937 return static_cast<External*>(value);
4938}
4939
4940
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00004941Isolate* AccessorInfo::GetIsolate() const {
4942 return *reinterpret_cast<Isolate**>(&args_[-3]);
4943}
4944
4945
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00004946Local<Value> AccessorInfo::Data() const {
ager@chromium.orgb26c50a2010-03-26 09:27:16 +00004947 return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00004948}
4949
4950
4951Local<Object> AccessorInfo::This() const {
4952 return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
4953}
4954
4955
4956Local<Object> AccessorInfo::Holder() const {
4957 return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
4958}
4959
4960
yangguo@chromium.orgefdb9d72012-04-26 08:21:05 +00004961Handle<Primitive> Undefined(Isolate* isolate) {
4962 typedef internal::Object* S;
4963 typedef internal::Internals I;
4964 if (!I::IsInitialized(isolate)) return Undefined();
4965 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
4966 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
4967}
4968
4969
4970Handle<Primitive> Null(Isolate* isolate) {
4971 typedef internal::Object* S;
4972 typedef internal::Internals I;
4973 if (!I::IsInitialized(isolate)) return Null();
4974 S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
4975 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
4976}
4977
4978
4979Handle<Boolean> True(Isolate* isolate) {
4980 typedef internal::Object* S;
4981 typedef internal::Internals I;
4982 if (!I::IsInitialized(isolate)) return True();
4983 S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
4984 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
4985}
4986
4987
4988Handle<Boolean> False(Isolate* isolate) {
4989 typedef internal::Object* S;
4990 typedef internal::Internals I;
4991 if (!I::IsInitialized(isolate)) return False();
4992 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
4993 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
4994}
4995
4996
4997void Isolate::SetData(void* data) {
4998 typedef internal::Internals I;
4999 I::SetEmbedderData(this, data);
5000}
5001
5002
5003void* Isolate::GetData() {
5004 typedef internal::Internals I;
5005 return I::GetEmbedderData(this);
5006}
5007
5008
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +00005009Local<Value> Context::GetEmbedderData(int index) {
5010#ifndef V8_ENABLE_CHECKS
5011 typedef internal::Object O;
5012 typedef internal::Internals I;
5013 O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index));
5014 return Local<Value>(reinterpret_cast<Value*>(result));
5015#else
5016 return SlowGetEmbedderData(index);
5017#endif
5018}
5019
5020
5021void* Context::GetAlignedPointerFromEmbedderData(int index) {
5022#ifndef V8_ENABLE_CHECKS
5023 typedef internal::Internals I;
5024 return I::ReadEmbedderData<void*>(this, index);
5025#else
5026 return SlowGetAlignedPointerFromEmbedderData(index);
5027#endif
5028}
5029
5030
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005031/**
v8.team.kasperl727e9952008-09-02 14:56:44 +00005032 * \example shell.cc
5033 * A simple shell that takes a list of expressions on the
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005034 * command-line and executes them.
5035 */
5036
5037
5038/**
5039 * \example process.cc
5040 */
5041
5042
5043} // namespace v8
5044
5045
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00005046#undef V8EXPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005047#undef TYPE_CHECK
5048
5049
ager@chromium.org9258b6b2008-09-11 09:11:10 +00005050#endif // V8_H_