sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 1 | // Copyright 2007-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // 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.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 28 | /** \mainpage V8 API Reference Guide |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 29 | * |
| 30 | * V8 is Google's open source JavaScript engine. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | * |
| 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | */ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 37 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 38 | #ifndef V8_H_ |
| 39 | #define V8_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
| 41 | #include <stdio.h> |
| 42 | |
| 43 | #ifdef _WIN32 |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 44 | // When compiling on MinGW stdint.h is available. |
| 45 | #ifdef __MINGW32__ |
| 46 | #include <stdint.h> |
| 47 | #else // __MINGW32__ |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 48 | typedef signed char int8_t; |
| 49 | typedef unsigned char uint8_t; |
| 50 | typedef short int16_t; // NOLINT |
| 51 | typedef unsigned short uint16_t; // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | typedef int int32_t; |
| 53 | typedef unsigned int uint32_t; |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 54 | typedef __int64 int64_t; |
| 55 | typedef unsigned __int64 uint64_t; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 56 | // intptr_t and friends are defined in crtdefs.h through stdio.h. |
| 57 | #endif // __MINGW32__ |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 58 | |
| 59 | // Setup for Windows DLL export/import. When building the V8 DLL the |
| 60 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
| 61 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
| 62 | // static library or building a program which uses the V8 static library neither |
| 63 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 64 | // The reason for having both V8EXPORT and V8EXPORT_INLINE is that classes which |
| 65 | // have their code inside this header file need to have __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 66 | // when building the DLL but cannot have __declspec(dllimport) when building |
| 67 | // a program which uses the DLL. |
| 68 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
| 69 | #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ |
| 70 | build configuration to ensure that at most one of these is set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | #endif |
| 72 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 73 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 74 | #define V8EXPORT __declspec(dllexport) |
| 75 | #define V8EXPORT_INLINE __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 76 | #elif USING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 77 | #define V8EXPORT __declspec(dllimport) |
| 78 | #define V8EXPORT_INLINE |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 79 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 80 | #define V8EXPORT |
| 81 | #define V8EXPORT_INLINE |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 82 | #endif // BUILDING_V8_SHARED |
| 83 | |
| 84 | #else // _WIN32 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 85 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 86 | #include <stdint.h> |
| 87 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 88 | // Setup for Linux shared library export. There is no need to distinguish |
| 89 | // between building or using the V8 shared library, but we should not |
| 90 | // export symbols when we are building a static library. |
| 91 | #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED) |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 92 | #define V8EXPORT __attribute__ ((visibility("default"))) |
| 93 | #define V8EXPORT_INLINE __attribute__ ((visibility("default"))) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 94 | #else // defined(__GNUC__) && (__GNUC__ >= 4) |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 95 | #define V8EXPORT |
| 96 | #define V8EXPORT_INLINE |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 97 | #endif // defined(__GNUC__) && (__GNUC__ >= 4) |
| 98 | |
| 99 | #endif // _WIN32 |
| 100 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 102 | * The v8 JavaScript engine. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | */ |
| 104 | namespace v8 { |
| 105 | |
| 106 | class Context; |
| 107 | class String; |
| 108 | class Value; |
| 109 | class Utils; |
| 110 | class Number; |
| 111 | class Object; |
| 112 | class Array; |
| 113 | class Int32; |
| 114 | class Uint32; |
| 115 | class External; |
| 116 | class Primitive; |
| 117 | class Boolean; |
| 118 | class Integer; |
| 119 | class Function; |
| 120 | class Date; |
| 121 | class ImplementationUtilities; |
| 122 | class Signature; |
| 123 | template <class T> class Handle; |
| 124 | template <class T> class Local; |
| 125 | template <class T> class Persistent; |
| 126 | class FunctionTemplate; |
| 127 | class ObjectTemplate; |
| 128 | class Data; |
| 129 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 130 | namespace internal { |
| 131 | |
| 132 | class Object; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 133 | class Arguments; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 134 | |
| 135 | } |
| 136 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | |
| 138 | // --- W e a k H a n d l e s |
| 139 | |
| 140 | |
| 141 | /** |
| 142 | * A weak reference callback function. |
| 143 | * |
| 144 | * \param object the weak global object to be reclaimed by the garbage collector |
| 145 | * \param parameter the value passed in when making the weak global object |
| 146 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 147 | typedef void (*WeakReferenceCallback)(Persistent<Value> object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | void* parameter); |
| 149 | |
| 150 | |
| 151 | // --- H a n d l e s --- |
| 152 | |
| 153 | #define TYPE_CHECK(T, S) \ |
| 154 | while (false) { \ |
| 155 | *(static_cast<T**>(0)) = static_cast<S*>(0); \ |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * An object reference managed by the v8 garbage collector. |
| 160 | * |
| 161 | * All objects returned from v8 have to be tracked by the garbage |
| 162 | * collector so that it knows that the objects are still alive. Also, |
| 163 | * because the garbage collector may move objects, it is unsafe to |
| 164 | * point directly to an object. Instead, all objects are stored in |
| 165 | * handles which are known by the garbage collector and updated |
| 166 | * whenever an object moves. Handles should always be passed by value |
| 167 | * (except in cases like out-parameters) and they should never be |
| 168 | * allocated on the heap. |
| 169 | * |
| 170 | * There are two types of handles: local and persistent handles. |
| 171 | * Local handles are light-weight and transient and typically used in |
| 172 | * local operations. They are managed by HandleScopes. Persistent |
| 173 | * handles can be used when storing objects across several independent |
| 174 | * operations and have to be explicitly deallocated when they're no |
| 175 | * longer used. |
| 176 | * |
| 177 | * It is safe to extract the object stored in the handle by |
| 178 | * dereferencing the handle (for instance, to extract the Object* from |
| 179 | * an Handle<Object>); the value will still be governed by a handle |
| 180 | * behind the scenes and the same rules apply to these values as to |
| 181 | * their handles. |
| 182 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 183 | template <class T> class V8EXPORT_INLINE Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 184 | public: |
| 185 | |
| 186 | /** |
| 187 | * Creates an empty handle. |
| 188 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 189 | inline Handle(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * Creates a new handle for the specified value. |
| 193 | */ |
| 194 | explicit Handle(T* val) : val_(val) { } |
| 195 | |
| 196 | /** |
| 197 | * Creates a handle for the contents of the specified handle. This |
| 198 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 199 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | * incompatible handles, for instance from a Handle<String> to a |
| 201 | * Handle<Number> it will cause a compiletime error. Assigning |
| 202 | * between compatible handles, for instance assigning a |
| 203 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 204 | * because String is a subclass of Value. |
| 205 | */ |
| 206 | template <class S> inline Handle(Handle<S> that) |
| 207 | : val_(reinterpret_cast<T*>(*that)) { |
| 208 | /** |
| 209 | * This check fails when trying to convert between incompatible |
| 210 | * handles. For example, converting from a Handle<String> to a |
| 211 | * Handle<Number>. |
| 212 | */ |
| 213 | TYPE_CHECK(T, S); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Returns true if the handle is empty. |
| 218 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 219 | bool IsEmpty() const { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 220 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 221 | T* operator->() const { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 223 | T* operator*() const { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 227 | */ |
| 228 | void Clear() { this->val_ = 0; } |
| 229 | |
| 230 | /** |
| 231 | * Checks whether two handles are the same. |
| 232 | * Returns true if both are empty, or if the objects |
| 233 | * to which they refer are identical. |
| 234 | * The handles' references are not checked. |
| 235 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 236 | template <class S> bool operator==(Handle<S> that) const { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 237 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 238 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | if (a == 0) return b == 0; |
| 240 | if (b == 0) return false; |
| 241 | return *a == *b; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Checks whether two handles are different. |
| 246 | * Returns true if only one of the handles is empty, or if |
| 247 | * the objects to which they refer are different. |
| 248 | * The handles' references are not checked. |
| 249 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 250 | template <class S> bool operator!=(Handle<S> that) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | return !operator==(that); |
| 252 | } |
| 253 | |
| 254 | template <class S> static inline Handle<T> Cast(Handle<S> that) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 255 | #ifdef V8_ENABLE_CHECKS |
| 256 | // If we're going to perform the type check then we have to check |
| 257 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 259 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | return Handle<T>(T::Cast(*that)); |
| 261 | } |
| 262 | |
| 263 | private: |
| 264 | T* val_; |
| 265 | }; |
| 266 | |
| 267 | |
| 268 | /** |
| 269 | * A light-weight stack-allocated object handle. All operations |
| 270 | * that return objects from within v8 return them in local handles. They |
| 271 | * are created within HandleScopes, and all local handles allocated within a |
| 272 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 273 | * is not necessary to explicitly deallocate local handles. |
| 274 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 275 | template <class T> class V8EXPORT_INLINE Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | public: |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 277 | inline Local(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | template <class S> inline Local(Local<S> that) |
| 279 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 280 | /** |
| 281 | * This check fails when trying to convert between incompatible |
| 282 | * handles. For example, converting from a Handle<String> to a |
| 283 | * Handle<Number>. |
| 284 | */ |
| 285 | TYPE_CHECK(T, S); |
| 286 | } |
| 287 | template <class S> inline Local(S* that) : Handle<T>(that) { } |
| 288 | template <class S> static inline Local<T> Cast(Local<S> that) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 289 | #ifdef V8_ENABLE_CHECKS |
| 290 | // If we're going to perform the type check then we have to check |
| 291 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 292 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 293 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | return Local<T>(T::Cast(*that)); |
| 295 | } |
| 296 | |
| 297 | /** Create a local handle for the content of another handle. |
| 298 | * The referee is kept alive by the local handle even when |
| 299 | * the original handle is destroyed/disposed. |
| 300 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 301 | inline static Local<T> New(Handle<T> that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | |
| 305 | /** |
| 306 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 307 | * a Local handle only lives as long as the HandleScope in which it was |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 308 | * allocated, a Persistent handle remains valid until it is explicitly |
| 309 | * disposed. |
| 310 | * |
| 311 | * A persistent handle contains a reference to a storage cell within |
| 312 | * the v8 engine which holds an object value and which is updated by |
| 313 | * the garbage collector whenever the object is moved. A new storage |
| 314 | * cell can be created using Persistent::New and existing handles can |
| 315 | * be disposed using Persistent::Dispose. Since persistent handles |
| 316 | * are passed by value you may have many persistent handle objects |
| 317 | * that point to the same storage cell. For instance, if you pass a |
| 318 | * persistent handle as an argument to a function you will not get two |
| 319 | * different storage cells but rather two references to the same |
| 320 | * storage cell. |
| 321 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 322 | template <class T> class V8EXPORT_INLINE Persistent : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 323 | public: |
| 324 | |
| 325 | /** |
| 326 | * Creates an empty persistent handle that doesn't point to any |
| 327 | * storage cell. |
| 328 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 329 | inline Persistent(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | |
| 331 | /** |
| 332 | * Creates a persistent handle for the same storage cell as the |
| 333 | * specified handle. This constructor allows you to pass persistent |
| 334 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 335 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | * persistent handles, for instance from a Persistent<String> to a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 337 | * Persistent<Number> will cause a compiletime error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 338 | * between compatible persistent handles, for instance assigning a |
| 339 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 340 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 341 | */ |
| 342 | template <class S> inline Persistent(Persistent<S> that) |
| 343 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 344 | /** |
| 345 | * This check fails when trying to convert between incompatible |
| 346 | * handles. For example, converting from a Handle<String> to a |
| 347 | * Handle<Number>. |
| 348 | */ |
| 349 | TYPE_CHECK(T, S); |
| 350 | } |
| 351 | |
| 352 | template <class S> inline Persistent(S* that) : Handle<T>(that) { } |
| 353 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 354 | /** |
| 355 | * "Casts" a plain handle which is known to be a persistent handle |
| 356 | * to a persistent handle. |
| 357 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 358 | template <class S> explicit inline Persistent(Handle<S> that) |
| 359 | : Handle<T>(*that) { } |
| 360 | |
| 361 | template <class S> static inline Persistent<T> Cast(Persistent<S> that) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 362 | #ifdef V8_ENABLE_CHECKS |
| 363 | // If we're going to perform the type check then we have to check |
| 364 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 365 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 366 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 367 | return Persistent<T>(T::Cast(*that)); |
| 368 | } |
| 369 | |
| 370 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 371 | * Creates a new persistent handle for an existing local or |
| 372 | * persistent handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 373 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 374 | inline static Persistent<T> New(Handle<T> that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * Releases the storage cell referenced by this persistent handle. |
| 378 | * Does not remove the reference to the cell from any handles. |
| 379 | * This handle's reference, and any any other references to the storage |
| 380 | * cell remain and IsEmpty will still return false. |
| 381 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 382 | inline void Dispose(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | |
| 384 | /** |
| 385 | * Make the reference to this object weak. When only weak handles |
| 386 | * refer to the object, the garbage collector will perform a |
| 387 | * callback to the given V8::WeakReferenceCallback function, passing |
| 388 | * it the object reference and the given parameters. |
| 389 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 390 | inline void MakeWeak(void* parameters, WeakReferenceCallback callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | |
| 392 | /** Clears the weak reference to this object.*/ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 393 | inline void ClearWeak(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | |
| 395 | /** |
| 396 | *Checks if the handle holds the only reference to an object. |
| 397 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 398 | inline bool IsNearDeath() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 399 | |
| 400 | /** |
| 401 | * Returns true if the handle's reference is weak. |
| 402 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 403 | inline bool IsWeak() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 404 | |
| 405 | private: |
| 406 | friend class ImplementationUtilities; |
| 407 | friend class ObjectTemplate; |
| 408 | }; |
| 409 | |
| 410 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 411 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 412 | * A stack-allocated class that governs a number of local handles. |
| 413 | * After a handle scope has been created, all local handles will be |
| 414 | * allocated within that handle scope until either the handle scope is |
| 415 | * deleted or another handle scope is created. If there is already a |
| 416 | * handle scope and a new one is created, all allocations will take |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 417 | * place in the new handle scope until it is deleted. After that, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 418 | * new handles will again be allocated in the original handle scope. |
| 419 | * |
| 420 | * After the handle scope of a local handle has been deleted the |
| 421 | * garbage collector will no longer track the object stored in the |
| 422 | * handle and may deallocate it. The behavior of accessing a handle |
| 423 | * for which the handle scope has been deleted is undefined. |
| 424 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 425 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 426 | public: |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 427 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 428 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 429 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 430 | |
| 431 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 432 | * Closes the handle scope and returns the value as a handle in the |
| 433 | * previous scope, which is the new current scope after the call. |
| 434 | */ |
| 435 | template <class T> Local<T> Close(Handle<T> value); |
| 436 | |
| 437 | /** |
| 438 | * Counts the number of allocated handles. |
| 439 | */ |
| 440 | static int NumberOfHandles(); |
| 441 | |
| 442 | /** |
| 443 | * Creates a new handle with the given value. |
| 444 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 445 | static internal::Object** CreateHandle(internal::Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | |
| 447 | private: |
| 448 | // Make it impossible to create heap-allocated or illegal handle |
| 449 | // scopes by disallowing certain operations. |
| 450 | HandleScope(const HandleScope&); |
| 451 | void operator=(const HandleScope&); |
| 452 | void* operator new(size_t size); |
| 453 | void operator delete(void*, size_t); |
| 454 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 455 | // This Data class is accessible internally through a typedef in the |
| 456 | // ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 457 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | public: |
| 459 | int extensions; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 460 | internal::Object** next; |
| 461 | internal::Object** limit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 462 | inline void Initialize() { |
| 463 | extensions = -1; |
| 464 | next = limit = NULL; |
| 465 | } |
| 466 | }; |
| 467 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 468 | Data previous_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 470 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 471 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 473 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 474 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | friend class ImplementationUtilities; |
| 476 | }; |
| 477 | |
| 478 | |
| 479 | // --- S p e c i a l o b j e c t s --- |
| 480 | |
| 481 | |
| 482 | /** |
| 483 | * The superclass of values and API object templates. |
| 484 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 485 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 486 | private: |
| 487 | Data(); |
| 488 | }; |
| 489 | |
| 490 | |
| 491 | /** |
| 492 | * Pre-compilation data that can be associated with a script. This |
| 493 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 494 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 495 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 497 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | public: |
| 499 | virtual ~ScriptData() { } |
| 500 | static ScriptData* PreCompile(const char* input, int length); |
| 501 | static ScriptData* New(unsigned* data, int length); |
| 502 | |
| 503 | virtual int Length() = 0; |
| 504 | virtual unsigned* Data() = 0; |
| 505 | }; |
| 506 | |
| 507 | |
| 508 | /** |
| 509 | * The origin, within a file, of a script. |
| 510 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 511 | class V8EXPORT ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 512 | public: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 513 | ScriptOrigin(Handle<Value> resource_name, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 514 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
| 515 | Handle<Integer> resource_column_offset = Handle<Integer>()) |
| 516 | : resource_name_(resource_name), |
| 517 | resource_line_offset_(resource_line_offset), |
| 518 | resource_column_offset_(resource_column_offset) { } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 519 | inline Handle<Value> ResourceName() const; |
| 520 | inline Handle<Integer> ResourceLineOffset() const; |
| 521 | inline Handle<Integer> ResourceColumnOffset() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 523 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | Handle<Integer> resource_line_offset_; |
| 525 | Handle<Integer> resource_column_offset_; |
| 526 | }; |
| 527 | |
| 528 | |
| 529 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 530 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 532 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | public: |
| 534 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 535 | /** |
| 536 | * Compiles the specified script. The ScriptOrigin* and ScriptData* |
| 537 | * parameters are owned by the caller of Script::Compile. No |
| 538 | * references to these objects are kept after compilation finishes. |
| 539 | * |
| 540 | * The script object returned is context independent; when run it |
| 541 | * will use the currently entered context. |
| 542 | */ |
| 543 | static Local<Script> New(Handle<String> source, |
| 544 | ScriptOrigin* origin = NULL, |
| 545 | ScriptData* pre_data = NULL); |
| 546 | |
| 547 | /** |
| 548 | * Compiles the specified script using the specified file name |
| 549 | * object (typically a string) as the script's origin. |
| 550 | * |
| 551 | * The script object returned is context independent; when run it |
| 552 | * will use the currently entered context. |
| 553 | */ |
| 554 | static Local<Script> New(Handle<String> source, |
| 555 | Handle<Value> file_name); |
| 556 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | /** |
| 558 | * Compiles the specified script. The ScriptOrigin* and ScriptData* |
| 559 | * parameters are owned by the caller of Script::Compile. No |
| 560 | * references to these objects are kept after compilation finishes. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 561 | * |
| 562 | * The script object returned is bound to the context that was active |
| 563 | * when this function was called. When run it will always use this |
| 564 | * context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | */ |
| 566 | static Local<Script> Compile(Handle<String> source, |
| 567 | ScriptOrigin* origin = NULL, |
| 568 | ScriptData* pre_data = NULL); |
| 569 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 570 | /** |
| 571 | * Compiles the specified script using the specified file name |
| 572 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 573 | * |
| 574 | * The script object returned is bound to the context that was active |
| 575 | * when this function was called. When run it will always use this |
| 576 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 577 | */ |
| 578 | static Local<Script> Compile(Handle<String> source, |
| 579 | Handle<Value> file_name); |
| 580 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 581 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 582 | * Runs the script returning the resulting value. If the script is |
| 583 | * context independent (created using ::New) it will be run in the |
| 584 | * currently entered context. If it is context specific (created |
| 585 | * using ::Compile) it will be run in the context in which it was |
| 586 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 587 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 589 | |
| 590 | /** |
| 591 | * Returns the script id value. |
| 592 | */ |
| 593 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 594 | |
| 595 | /** |
| 596 | * Associate an additional data object with the script. This is mainly used |
| 597 | * with the debugger as this data object is only available through the |
| 598 | * debugger API. |
| 599 | */ |
| 600 | void SetData(Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | }; |
| 602 | |
| 603 | |
| 604 | /** |
| 605 | * An error message. |
| 606 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 607 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 609 | Local<String> Get() const; |
| 610 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 612 | /** |
| 613 | * Returns the resource name for the script from where the function causing |
| 614 | * the error originates. |
| 615 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 616 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 617 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 618 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 619 | * Returns the resource data for the script from where the function causing |
| 620 | * the error originates. |
| 621 | */ |
| 622 | Handle<Value> GetScriptData() const; |
| 623 | |
| 624 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 625 | * Returns the number, 1-based, of the line where the error occurred. |
| 626 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 627 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 628 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 629 | /** |
| 630 | * Returns the index within the script of the first character where |
| 631 | * the error occurred. |
| 632 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 633 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 634 | |
| 635 | /** |
| 636 | * Returns the index within the script of the last character where |
| 637 | * the error occurred. |
| 638 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 639 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 640 | |
| 641 | /** |
| 642 | * Returns the index within the line of the first character where |
| 643 | * the error occurred. |
| 644 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 645 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 646 | |
| 647 | /** |
| 648 | * Returns the index within the line of the last character where |
| 649 | * the error occurred. |
| 650 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 651 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 652 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 653 | // TODO(1245381): Print to a string instead of on a FILE. |
| 654 | static void PrintCurrentStackTrace(FILE* out); |
| 655 | }; |
| 656 | |
| 657 | |
| 658 | // --- V a l u e --- |
| 659 | |
| 660 | |
| 661 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 662 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 663 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 664 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | public: |
| 666 | |
| 667 | /** |
| 668 | * Returns true if this value is the undefined value. See ECMA-262 |
| 669 | * 4.3.10. |
| 670 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 671 | bool IsUndefined() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 672 | |
| 673 | /** |
| 674 | * Returns true if this value is the null value. See ECMA-262 |
| 675 | * 4.3.11. |
| 676 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 677 | bool IsNull() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 678 | |
| 679 | /** |
| 680 | * Returns true if this value is true. |
| 681 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 682 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | |
| 684 | /** |
| 685 | * Returns true if this value is false. |
| 686 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 687 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 688 | |
| 689 | /** |
| 690 | * Returns true if this value is an instance of the String type. |
| 691 | * See ECMA-262 8.4. |
| 692 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 693 | inline bool IsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 694 | |
| 695 | /** |
| 696 | * Returns true if this value is a function. |
| 697 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 698 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 699 | |
| 700 | /** |
| 701 | * Returns true if this value is an array. |
| 702 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 703 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 704 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 705 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | * Returns true if this value is an object. |
| 707 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 708 | bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 710 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 711 | * Returns true if this value is boolean. |
| 712 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 713 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 714 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 715 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | * Returns true if this value is a number. |
| 717 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 718 | bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 719 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 720 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 721 | * Returns true if this value is external. |
| 722 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 723 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 724 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 725 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 726 | * Returns true if this value is a 32-bit signed integer. |
| 727 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 728 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 729 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 730 | /** |
| 731 | * Returns true if this value is a Date. |
| 732 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 733 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 734 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 735 | Local<Boolean> ToBoolean() const; |
| 736 | Local<Number> ToNumber() const; |
| 737 | Local<String> ToString() const; |
| 738 | Local<String> ToDetailString() const; |
| 739 | Local<Object> ToObject() const; |
| 740 | Local<Integer> ToInteger() const; |
| 741 | Local<Uint32> ToUint32() const; |
| 742 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 743 | |
| 744 | /** |
| 745 | * Attempts to convert a string to an array index. |
| 746 | * Returns an empty handle if the conversion fails. |
| 747 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 748 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 749 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 750 | bool BooleanValue() const; |
| 751 | double NumberValue() const; |
| 752 | int64_t IntegerValue() const; |
| 753 | uint32_t Uint32Value() const; |
| 754 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 755 | |
| 756 | /** JS == */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 757 | bool Equals(Handle<Value> that) const; |
| 758 | bool StrictEquals(Handle<Value> that) const; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 759 | |
| 760 | private: |
| 761 | inline bool QuickIsString() const; |
| 762 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | |
| 766 | /** |
| 767 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 768 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 769 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 770 | |
| 771 | |
| 772 | /** |
| 773 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 774 | * or false value. |
| 775 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 776 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 778 | bool Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 779 | static inline Handle<Boolean> New(bool value); |
| 780 | }; |
| 781 | |
| 782 | |
| 783 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 784 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 785 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 786 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 787 | public: |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 788 | |
| 789 | /** |
| 790 | * Returns the number of characters in this string. |
| 791 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 792 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 793 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 794 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 795 | * Returns the number of bytes in the UTF-8 encoded |
| 796 | * representation of this string. |
| 797 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 798 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 799 | |
| 800 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 801 | * Write the contents of the string to an external buffer. |
| 802 | * If no arguments are given, expects the buffer to be large |
| 803 | * enough to hold the entire string and NULL terminator. Copies |
| 804 | * the contents of the string and the NULL terminator into the |
| 805 | * buffer. |
| 806 | * |
| 807 | * Copies up to length characters into the output buffer. |
| 808 | * Only null-terminates if there is enough space in the buffer. |
| 809 | * |
| 810 | * \param buffer The buffer into which the string will be copied. |
| 811 | * \param start The starting position within the string at which |
| 812 | * copying begins. |
| 813 | * \param length The number of bytes to copy from the string. |
| 814 | * \return The number of characters copied to the buffer |
| 815 | * excluding the NULL terminator. |
| 816 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 817 | int Write(uint16_t* buffer, int start = 0, int length = -1) const; // UTF-16 |
| 818 | int WriteAscii(char* buffer, int start = 0, int length = -1) const; // ASCII |
| 819 | int WriteUtf8(char* buffer, int length = -1) const; // UTF-8 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 820 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 821 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 822 | * A zero length string. |
| 823 | */ |
| 824 | static v8::Local<v8::String> Empty(); |
| 825 | |
| 826 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 827 | * Returns true if the string is external |
| 828 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 829 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 831 | /** |
| 832 | * Returns true if the string is both external and ascii |
| 833 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 834 | bool IsExternalAscii() const; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 835 | /** |
| 836 | * An ExternalStringResource is a wrapper around a two-byte string |
| 837 | * buffer that resides outside V8's heap. Implement an |
| 838 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 839 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 840 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 841 | class V8EXPORT ExternalStringResource { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 842 | public: |
| 843 | /** |
| 844 | * Override the destructor to manage the life cycle of the underlying |
| 845 | * buffer. |
| 846 | */ |
| 847 | virtual ~ExternalStringResource() {} |
| 848 | /** The string data from the underlying buffer.*/ |
| 849 | virtual const uint16_t* data() const = 0; |
| 850 | /** The length of the string. That is, the number of two-byte characters.*/ |
| 851 | virtual size_t length() const = 0; |
| 852 | protected: |
| 853 | ExternalStringResource() {} |
| 854 | private: |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 855 | // Disallow copying and assigning. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | ExternalStringResource(const ExternalStringResource&); |
| 857 | void operator=(const ExternalStringResource&); |
| 858 | }; |
| 859 | |
| 860 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 861 | * An ExternalAsciiStringResource is a wrapper around an ascii |
| 862 | * string buffer that resides outside V8's heap. Implement an |
| 863 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 864 | * underlying buffer. Note that the string data must be immutable |
| 865 | * and that the data must be strict 7-bit ASCII, not Latin1 or |
| 866 | * UTF-8, which would require special treatment internally in the |
| 867 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 868 | * Use String::New or convert to 16 bit data for non-ASCII. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 869 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 870 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 871 | class V8EXPORT ExternalAsciiStringResource { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | public: |
| 873 | /** |
| 874 | * Override the destructor to manage the life cycle of the underlying |
| 875 | * buffer. |
| 876 | */ |
| 877 | virtual ~ExternalAsciiStringResource() {} |
| 878 | /** The string data from the underlying buffer.*/ |
| 879 | virtual const char* data() const = 0; |
| 880 | /** The number of ascii characters in the string.*/ |
| 881 | virtual size_t length() const = 0; |
| 882 | protected: |
| 883 | ExternalAsciiStringResource() {} |
| 884 | private: |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 885 | // Disallow copying and assigning. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | ExternalAsciiStringResource(const ExternalAsciiStringResource&); |
| 887 | void operator=(const ExternalAsciiStringResource&); |
| 888 | }; |
| 889 | |
| 890 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 891 | * Get the ExternalStringResource for an external string. Returns |
| 892 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 894 | inline ExternalStringResource* GetExternalStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 895 | |
| 896 | /** |
| 897 | * Get the ExternalAsciiStringResource for an external ascii string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 898 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 899 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 900 | ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 901 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 902 | static inline String* Cast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 903 | |
| 904 | /** |
| 905 | * Allocates a new string from either utf-8 encoded or ascii data. |
| 906 | * The second parameter 'length' gives the buffer length. |
| 907 | * If the data is utf-8 encoded, the caller must |
| 908 | * be careful to supply the length parameter. |
| 909 | * If it is not given, the function calls |
| 910 | * 'strlen' to determine the buffer length, it might be |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 911 | * wrong if 'data' contains a null character. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 912 | */ |
| 913 | static Local<String> New(const char* data, int length = -1); |
| 914 | |
| 915 | /** Allocates a new string from utf16 data.*/ |
| 916 | static Local<String> New(const uint16_t* data, int length = -1); |
| 917 | |
| 918 | /** Creates a symbol. Returns one if it exists already.*/ |
| 919 | static Local<String> NewSymbol(const char* data, int length = -1); |
| 920 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 921 | /** |
| 922 | * Creates a new external string using the data defined in the given |
| 923 | * resource. The resource is deleted when the external string is no |
| 924 | * longer live on V8's heap. The caller of this function should not |
| 925 | * delete or modify the resource. Neither should the underlying buffer be |
| 926 | * deallocated or modified except through the destructor of the |
| 927 | * external string resource. |
| 928 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 929 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 930 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 931 | /** |
| 932 | * Associate an external string resource with this string by transforming it |
| 933 | * in place so that existing references to this string in the JavaScript heap |
| 934 | * will use the external string resource. The external string resource's |
| 935 | * character contents needs to be equivalent to this string. |
| 936 | * Returns true if the string has been changed to be an external string. |
| 937 | * The string is not modified if the operation fails. |
| 938 | */ |
| 939 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 941 | /** |
| 942 | * Creates a new external string using the ascii data defined in the given |
| 943 | * resource. The resource is deleted when the external string is no |
| 944 | * longer live on V8's heap. The caller of this function should not |
| 945 | * delete or modify the resource. Neither should the underlying buffer be |
| 946 | * deallocated or modified except through the destructor of the |
| 947 | * external string resource. |
| 948 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 949 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 950 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 951 | /** |
| 952 | * Associate an external string resource with this string by transforming it |
| 953 | * in place so that existing references to this string in the JavaScript heap |
| 954 | * will use the external string resource. The external string resource's |
| 955 | * character contents needs to be equivalent to this string. |
| 956 | * Returns true if the string has been changed to be an external string. |
| 957 | * The string is not modified if the operation fails. |
| 958 | */ |
| 959 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 960 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 961 | /** |
| 962 | * Returns true if this string can be made external. |
| 963 | */ |
| 964 | bool CanMakeExternal(); |
| 965 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 966 | /** Creates an undetectable string from the supplied ascii or utf-8 data.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 967 | static Local<String> NewUndetectable(const char* data, int length = -1); |
| 968 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 969 | /** Creates an undetectable string from the supplied utf-16 data.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 970 | static Local<String> NewUndetectable(const uint16_t* data, int length = -1); |
| 971 | |
| 972 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 973 | * Converts an object to a utf8-encoded character array. Useful if |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 974 | * you want to print the object. If conversion to a string fails |
| 975 | * (eg. due to an exception in the toString() method of the object) |
| 976 | * then the length() method returns 0 and the * operator returns |
| 977 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 978 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 979 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 980 | public: |
| 981 | explicit Utf8Value(Handle<v8::Value> obj); |
| 982 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 983 | char* operator*() { return str_; } |
| 984 | const char* operator*() const { return str_; } |
| 985 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 986 | private: |
| 987 | char* str_; |
| 988 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 989 | |
| 990 | // Disallow copying and assigning. |
| 991 | Utf8Value(const Utf8Value&); |
| 992 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 993 | }; |
| 994 | |
| 995 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 996 | * Converts an object to an ascii string. |
| 997 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 998 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 999 | * method of the object) then the length() method returns 0 and the * operator |
| 1000 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1002 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1003 | public: |
| 1004 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1005 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1006 | char* operator*() { return str_; } |
| 1007 | const char* operator*() const { return str_; } |
| 1008 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1009 | private: |
| 1010 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1011 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1012 | |
| 1013 | // Disallow copying and assigning. |
| 1014 | AsciiValue(const AsciiValue&); |
| 1015 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1016 | }; |
| 1017 | |
| 1018 | /** |
| 1019 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1020 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1021 | * method of the object) then the length() method returns 0 and the * operator |
| 1022 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1023 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1024 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1025 | public: |
| 1026 | explicit Value(Handle<v8::Value> obj); |
| 1027 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1028 | uint16_t* operator*() { return str_; } |
| 1029 | const uint16_t* operator*() const { return str_; } |
| 1030 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1031 | private: |
| 1032 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1033 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1034 | |
| 1035 | // Disallow copying and assigning. |
| 1036 | Value(const Value&); |
| 1037 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1038 | }; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1039 | |
| 1040 | private: |
| 1041 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1042 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1043 | }; |
| 1044 | |
| 1045 | |
| 1046 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1047 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1048 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1049 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1050 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1051 | double Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1052 | static Local<Number> New(double value); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1053 | static inline Number* Cast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1054 | private: |
| 1055 | Number(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1056 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1057 | }; |
| 1058 | |
| 1059 | |
| 1060 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1061 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1062 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1063 | class V8EXPORT Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1064 | public: |
| 1065 | static Local<Integer> New(int32_t value); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1066 | int64_t Value() const; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1067 | static inline Integer* Cast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1068 | private: |
| 1069 | Integer(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1070 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | }; |
| 1072 | |
| 1073 | |
| 1074 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1075 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1076 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1077 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1078 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1079 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1080 | private: |
| 1081 | Int32(); |
| 1082 | }; |
| 1083 | |
| 1084 | |
| 1085 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1086 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1087 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1088 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1089 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1090 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1091 | private: |
| 1092 | Uint32(); |
| 1093 | }; |
| 1094 | |
| 1095 | |
| 1096 | /** |
| 1097 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 1098 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1099 | class V8EXPORT Date : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1100 | public: |
| 1101 | static Local<Value> New(double time); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1102 | |
| 1103 | /** |
| 1104 | * A specialization of Value::NumberValue that is more efficient |
| 1105 | * because we know the structure of this object. |
| 1106 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1107 | double NumberValue() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1108 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1109 | static inline Date* Cast(v8::Value* obj); |
| 1110 | private: |
| 1111 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1112 | }; |
| 1113 | |
| 1114 | |
| 1115 | enum PropertyAttribute { |
| 1116 | None = 0, |
| 1117 | ReadOnly = 1 << 0, |
| 1118 | DontEnum = 1 << 1, |
| 1119 | DontDelete = 1 << 2 |
| 1120 | }; |
| 1121 | |
| 1122 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1123 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1124 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1125 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1126 | public: |
| 1127 | bool Set(Handle<Value> key, |
| 1128 | Handle<Value> value, |
| 1129 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1130 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1131 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1132 | // overriding accessors or read-only properties. |
| 1133 | // |
| 1134 | // Note that if the object has an interceptor the property will be set |
| 1135 | // locally, but since the interceptor takes precedence the local property |
| 1136 | // will only be returned if the interceptor doesn't return a value. |
| 1137 | // |
| 1138 | // Note also that this only works for named properties. |
| 1139 | bool ForceSet(Handle<Value> key, |
| 1140 | Handle<Value> value, |
| 1141 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1142 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1143 | Local<Value> Get(Handle<Value> key); |
| 1144 | |
| 1145 | // TODO(1245389): Replace the type-specific versions of these |
| 1146 | // functions with generic ones that accept a Handle<Value> key. |
| 1147 | bool Has(Handle<String> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1148 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1149 | bool Delete(Handle<String> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1150 | |
| 1151 | // Delete a property on this object bypassing interceptors and |
| 1152 | // ignoring dont-delete attributes. |
| 1153 | bool ForceDelete(Handle<Value> key); |
| 1154 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1155 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1156 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1157 | bool Delete(uint32_t index); |
| 1158 | |
| 1159 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1160 | * Returns an array containing the names of the enumerable properties |
| 1161 | * of this object, including properties from prototype objects. The |
| 1162 | * array returned by this method contains the same values as would |
| 1163 | * be enumerated by a for-in statement over this object. |
| 1164 | */ |
| 1165 | Local<Array> GetPropertyNames(); |
| 1166 | |
| 1167 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1168 | * Get the prototype object. This does not skip objects marked to |
| 1169 | * be skipped by __proto__ and it does not consult the security |
| 1170 | * handler. |
| 1171 | */ |
| 1172 | Local<Value> GetPrototype(); |
| 1173 | |
| 1174 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 1175 | * Finds an instance of the given function template in the prototype |
| 1176 | * chain. |
| 1177 | */ |
| 1178 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
| 1179 | |
| 1180 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1181 | * Call builtin Object.prototype.toString on this object. |
| 1182 | * This is different from Value::ToString() that may call |
| 1183 | * user-defined toString function. This one does not. |
| 1184 | */ |
| 1185 | Local<String> ObjectProtoToString(); |
| 1186 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1187 | /** Gets the number of internal fields for this Object. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1188 | int InternalFieldCount(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1189 | /** Gets the value in an internal field. */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1190 | inline Local<Value> GetInternalField(int index); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1191 | /** Sets the value in an internal field. */ |
| 1192 | void SetInternalField(int index, Handle<Value> value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1193 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1194 | /** Gets a native pointer from an internal field. */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1195 | inline void* GetPointerFromInternalField(int index); |
| 1196 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1197 | /** Sets a native pointer in an internal field. */ |
| 1198 | void SetPointerInInternalField(int index, void* value); |
| 1199 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1200 | // Testers for local properties. |
| 1201 | bool HasRealNamedProperty(Handle<String> key); |
| 1202 | bool HasRealIndexedProperty(uint32_t index); |
| 1203 | bool HasRealNamedCallbackProperty(Handle<String> key); |
| 1204 | |
| 1205 | /** |
| 1206 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 1207 | * This means interceptors in the prototype chain are not called. |
| 1208 | */ |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 1209 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
| 1210 | |
| 1211 | /** |
| 1212 | * If result.IsEmpty() no real property was located on the object or |
| 1213 | * in the prototype chain. |
| 1214 | * This means interceptors in the prototype chain are not called. |
| 1215 | */ |
| 1216 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1217 | |
| 1218 | /** Tests for a named lookup interceptor.*/ |
| 1219 | bool HasNamedLookupInterceptor(); |
| 1220 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1221 | /** Tests for an index lookup interceptor.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1222 | bool HasIndexedLookupInterceptor(); |
| 1223 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1224 | /** |
| 1225 | * Turns on access check on the object if the object is an instance of |
| 1226 | * a template that has access check callbacks. If an object has no |
| 1227 | * access check info, the object cannot be accessed by anyone. |
| 1228 | */ |
| 1229 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 1230 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1231 | /** |
| 1232 | * Returns the identity hash for this object. The current implemenation uses |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1233 | * a hidden property on the object to store the identity hash. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1234 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1235 | * The return value will never be 0. Also, it is not guaranteed to be |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1236 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1237 | */ |
| 1238 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 1239 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1240 | /** |
| 1241 | * Access hidden properties on JavaScript objects. These properties are |
| 1242 | * hidden from the executing JavaScript and only accessible through the V8 |
| 1243 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 1244 | * identity hash) are prefixed with "v8::". |
| 1245 | */ |
| 1246 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 1247 | Local<Value> GetHiddenValue(Handle<String> key); |
| 1248 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1249 | |
| 1250 | /** |
| 1251 | * Returns true if this is an instance of an api function (one |
| 1252 | * created from a function created from a function template) and has |
| 1253 | * been modified since it was created. Note that this method is |
| 1254 | * conservative and may return true for objects that haven't actually |
| 1255 | * been modified. |
| 1256 | */ |
| 1257 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1258 | |
| 1259 | /** |
| 1260 | * Clone this object with a fast but shallow copy. Values will point |
| 1261 | * to the same values as the original object. |
| 1262 | */ |
| 1263 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1265 | /** |
| 1266 | * Set the backing store of the indexed properties to be managed by the |
| 1267 | * embedding layer. Access to the indexed properties will follow the rules |
| 1268 | * spelled out in CanvasPixelArray. |
| 1269 | * Note: The embedding program still owns the data and needs to ensure that |
| 1270 | * the backing store is preserved while V8 has a reference. |
| 1271 | */ |
| 1272 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 1273 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | static Local<Object> New(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1275 | static inline Object* Cast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | private: |
| 1277 | Object(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1278 | static void CheckCast(Value* obj); |
| 1279 | Local<Value> CheckedGetInternalField(int index); |
| 1280 | |
| 1281 | /** |
| 1282 | * If quick access to the internal field is possible this method |
| 1283 | * returns the value. Otherwise an empty handle is returned. |
| 1284 | */ |
| 1285 | inline Local<Value> UncheckedGetInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1286 | }; |
| 1287 | |
| 1288 | |
| 1289 | /** |
| 1290 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 1291 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1292 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1293 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1294 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1295 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1296 | /** |
| 1297 | * Clones an element at index |index|. Returns an empty |
| 1298 | * handle if cloning fails (for any reason). |
| 1299 | */ |
| 1300 | Local<Object> CloneElementAt(uint32_t index); |
| 1301 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1302 | static Local<Array> New(int length = 0); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1303 | static inline Array* Cast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1304 | private: |
| 1305 | Array(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1306 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | }; |
| 1308 | |
| 1309 | |
| 1310 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1311 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1312 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1313 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1315 | Local<Object> NewInstance() const; |
| 1316 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1317 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 1318 | void SetName(Handle<String> name); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1319 | Handle<Value> GetName() const; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1320 | static inline Function* Cast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1321 | private: |
| 1322 | Function(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1323 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1324 | }; |
| 1325 | |
| 1326 | |
| 1327 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1328 | * A JavaScript value that wraps a C++ void*. This type of value is |
| 1329 | * mainly used to associate C++ data structures with JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1330 | * objects. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1331 | * |
| 1332 | * The Wrap function V8 will return the most optimal Value object wrapping the |
| 1333 | * C++ void*. The type of the value is not guaranteed to be an External object |
| 1334 | * and no assumptions about its type should be made. To access the wrapped |
| 1335 | * value Unwrap should be used, all other operations on that object will lead |
| 1336 | * to unpredictable results. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1337 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1338 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1339 | public: |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1340 | static Local<Value> Wrap(void* data); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1341 | static inline void* Unwrap(Handle<Value> obj); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1342 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1343 | static Local<External> New(void* value); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1344 | static inline External* Cast(Value* obj); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1345 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1346 | private: |
| 1347 | External(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1348 | static void CheckCast(v8::Value* obj); |
| 1349 | static inline void* QuickUnwrap(Handle<v8::Value> obj); |
| 1350 | static void* FullUnwrap(Handle<v8::Value> obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1351 | }; |
| 1352 | |
| 1353 | |
| 1354 | // --- T e m p l a t e s --- |
| 1355 | |
| 1356 | |
| 1357 | /** |
| 1358 | * The superclass of object and function templates. |
| 1359 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1360 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1361 | public: |
| 1362 | /** Adds a property to each instance created by this template.*/ |
| 1363 | void Set(Handle<String> name, Handle<Data> value, |
| 1364 | PropertyAttribute attributes = None); |
| 1365 | inline void Set(const char* name, Handle<Data> value); |
| 1366 | private: |
| 1367 | Template(); |
| 1368 | |
| 1369 | friend class ObjectTemplate; |
| 1370 | friend class FunctionTemplate; |
| 1371 | }; |
| 1372 | |
| 1373 | |
| 1374 | /** |
| 1375 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1376 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1377 | * including the receiver, the number and values of arguments, and |
| 1378 | * the holder of the function. |
| 1379 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1380 | class V8EXPORT Arguments { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1381 | public: |
| 1382 | inline int Length() const; |
| 1383 | inline Local<Value> operator[](int i) const; |
| 1384 | inline Local<Function> Callee() const; |
| 1385 | inline Local<Object> This() const; |
| 1386 | inline Local<Object> Holder() const; |
| 1387 | inline bool IsConstructCall() const; |
| 1388 | inline Local<Value> Data() const; |
| 1389 | private: |
| 1390 | Arguments(); |
| 1391 | friend class ImplementationUtilities; |
| 1392 | inline Arguments(Local<Value> data, |
| 1393 | Local<Object> holder, |
| 1394 | Local<Function> callee, |
| 1395 | bool is_construct_call, |
| 1396 | void** values, int length); |
| 1397 | Local<Value> data_; |
| 1398 | Local<Object> holder_; |
| 1399 | Local<Function> callee_; |
| 1400 | bool is_construct_call_; |
| 1401 | void** values_; |
| 1402 | int length_; |
| 1403 | }; |
| 1404 | |
| 1405 | |
| 1406 | /** |
| 1407 | * The information passed to an accessor callback about the context |
| 1408 | * of the property access. |
| 1409 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1410 | class V8EXPORT AccessorInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1411 | public: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 1412 | inline AccessorInfo(internal::Object** args) |
| 1413 | : args_(args) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1414 | inline Local<Value> Data() const; |
| 1415 | inline Local<Object> This() const; |
| 1416 | inline Local<Object> Holder() const; |
| 1417 | private: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 1418 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1419 | }; |
| 1420 | |
| 1421 | |
| 1422 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
| 1423 | |
| 1424 | typedef int (*LookupCallback)(Local<Object> self, Local<String> name); |
| 1425 | |
| 1426 | /** |
| 1427 | * Accessor[Getter|Setter] are used as callback functions when |
| 1428 | * setting|getting a particular property. See objectTemplate::SetAccessor. |
| 1429 | */ |
| 1430 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1431 | const AccessorInfo& info); |
| 1432 | |
| 1433 | |
| 1434 | typedef void (*AccessorSetter)(Local<String> property, |
| 1435 | Local<Value> value, |
| 1436 | const AccessorInfo& info); |
| 1437 | |
| 1438 | |
| 1439 | /** |
| 1440 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 1441 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 1442 | */ |
| 1443 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 1444 | const AccessorInfo& info); |
| 1445 | |
| 1446 | |
| 1447 | /** |
| 1448 | * Returns the value if the setter intercepts the request. |
| 1449 | * Otherwise, returns an empty handle. |
| 1450 | */ |
| 1451 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 1452 | Local<Value> value, |
| 1453 | const AccessorInfo& info); |
| 1454 | |
| 1455 | |
| 1456 | /** |
| 1457 | * Returns a non-empty handle if the interceptor intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1458 | * The result is true if the property exists and false otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1459 | */ |
| 1460 | typedef Handle<Boolean> (*NamedPropertyQuery)(Local<String> property, |
| 1461 | const AccessorInfo& info); |
| 1462 | |
| 1463 | |
| 1464 | /** |
| 1465 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1466 | * The return value is true if the property could be deleted and false |
| 1467 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1468 | */ |
| 1469 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 1470 | const AccessorInfo& info); |
| 1471 | |
| 1472 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1473 | * Returns an array containing the names of the properties the named |
| 1474 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1475 | */ |
| 1476 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
| 1477 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1478 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1480 | * Returns the value of the property if the getter intercepts the |
| 1481 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1482 | */ |
| 1483 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 1484 | const AccessorInfo& info); |
| 1485 | |
| 1486 | |
| 1487 | /** |
| 1488 | * Returns the value if the setter intercepts the request. |
| 1489 | * Otherwise, returns an empty handle. |
| 1490 | */ |
| 1491 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 1492 | Local<Value> value, |
| 1493 | const AccessorInfo& info); |
| 1494 | |
| 1495 | |
| 1496 | /** |
| 1497 | * Returns a non-empty handle if the interceptor intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1498 | * The result is true if the property exists and false otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1499 | */ |
| 1500 | typedef Handle<Boolean> (*IndexedPropertyQuery)(uint32_t index, |
| 1501 | const AccessorInfo& info); |
| 1502 | |
| 1503 | /** |
| 1504 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1505 | * The return value is true if the property could be deleted and false |
| 1506 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1507 | */ |
| 1508 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 1509 | const AccessorInfo& info); |
| 1510 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1511 | /** |
| 1512 | * Returns an array containing the indices of the properties the |
| 1513 | * indexed property getter intercepts. |
| 1514 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1515 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
| 1516 | |
| 1517 | |
| 1518 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1519 | * Access control specifications. |
| 1520 | * |
| 1521 | * Some accessors should be accessible across contexts. These |
| 1522 | * accessors have an explicit access control parameter which specifies |
| 1523 | * the kind of cross-context access that should be allowed. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1524 | * |
| 1525 | * Additionally, for security, accessors can prohibit overwriting by |
| 1526 | * accessors defined in JavaScript. For objects that have such |
| 1527 | * accessors either locally or in their prototype chain it is not |
| 1528 | * possible to overwrite the accessor by using __defineGetter__ or |
| 1529 | * __defineSetter__ from JavaScript code. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1530 | */ |
| 1531 | enum AccessControl { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1532 | DEFAULT = 0, |
| 1533 | ALL_CAN_READ = 1, |
| 1534 | ALL_CAN_WRITE = 1 << 1, |
| 1535 | PROHIBITS_OVERWRITING = 1 << 2 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1536 | }; |
| 1537 | |
| 1538 | |
| 1539 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1540 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1541 | */ |
| 1542 | enum AccessType { |
| 1543 | ACCESS_GET, |
| 1544 | ACCESS_SET, |
| 1545 | ACCESS_HAS, |
| 1546 | ACCESS_DELETE, |
| 1547 | ACCESS_KEYS |
| 1548 | }; |
| 1549 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1550 | |
| 1551 | /** |
| 1552 | * Returns true if cross-context access should be allowed to the named |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1553 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1554 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1555 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1556 | Local<Value> key, |
| 1557 | AccessType type, |
| 1558 | Local<Value> data); |
| 1559 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1560 | |
| 1561 | /** |
| 1562 | * Returns true if cross-context access should be allowed to the indexed |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1563 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1564 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1565 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1566 | uint32_t index, |
| 1567 | AccessType type, |
| 1568 | Local<Value> data); |
| 1569 | |
| 1570 | |
| 1571 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1572 | * A FunctionTemplate is used to create functions at runtime. There |
| 1573 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 1574 | * context. The lifetime of the created function is equal to the |
| 1575 | * lifetime of the context. So in case the embedder needs to create |
| 1576 | * temporary functions that can be collected using Scripts is |
| 1577 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1578 | * |
| 1579 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1580 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1581 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1582 | * A FunctionTemplate has a corresponding instance template which is |
| 1583 | * used to create object instances when the function is used as a |
| 1584 | * constructor. Properties added to the instance template are added to |
| 1585 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1586 | * |
| 1587 | * A FunctionTemplate can have a prototype template. The prototype template |
| 1588 | * is used to create the prototype object of the function. |
| 1589 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1590 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1591 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1592 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1593 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 1594 | * t->Set("func_property", v8::Number::New(1)); |
| 1595 | * |
| 1596 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 1597 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 1598 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 1599 | * |
| 1600 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 1601 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 1602 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 1603 | * instance_t->Set("instance_property", Number::New(3)); |
| 1604 | * |
| 1605 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 1606 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1607 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1608 | * |
| 1609 | * Let's use "function" as the JS variable name of the function object |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1610 | * and "instance" for the instance object created above. The function |
| 1611 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1612 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1613 | * \code |
| 1614 | * func_property in function == true; |
| 1615 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1616 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1617 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 1618 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1619 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1620 | * instance instanceof function == true; |
| 1621 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 1622 | * instance.instance_property == 3; |
| 1623 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1624 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1625 | * A FunctionTemplate can inherit from another one by calling the |
| 1626 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 1627 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1628 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1629 | * \code |
| 1630 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 1631 | * ^ ^ |
| 1632 | * | Inherit(Parent) | .__proto__ |
| 1633 | * | | |
| 1634 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 1635 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1636 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1637 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 1638 | * object of the Child() function has __proto__ pointing to the |
| 1639 | * Parent() function's prototype object. An instance of the Child |
| 1640 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1641 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1642 | * Let Parent be the FunctionTemplate initialized in the previous |
| 1643 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1644 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1645 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1646 | * Local<FunctionTemplate> parent = t; |
| 1647 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 1648 | * child->Inherit(parent); |
| 1649 | * |
| 1650 | * Local<Function> child_function = child->GetFunction(); |
| 1651 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1652 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1653 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1654 | * The Child function and Child instance will have the following |
| 1655 | * properties: |
| 1656 | * |
| 1657 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1658 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1659 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1660 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1661 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1662 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1663 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1664 | public: |
| 1665 | /** Creates a function template.*/ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1666 | static Local<FunctionTemplate> New( |
| 1667 | InvocationCallback callback = 0, |
| 1668 | Handle<Value> data = Handle<Value>(), |
| 1669 | Handle<Signature> signature = Handle<Signature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1670 | /** Returns the unique function instance in the current execution context.*/ |
| 1671 | Local<Function> GetFunction(); |
| 1672 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1673 | /** |
| 1674 | * Set the call-handler callback for a FunctionTemplate. This |
| 1675 | * callback is called whenever the function created from this |
| 1676 | * FunctionTemplate is called. |
| 1677 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1678 | void SetCallHandler(InvocationCallback callback, |
| 1679 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1680 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1681 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1682 | Local<ObjectTemplate> InstanceTemplate(); |
| 1683 | |
| 1684 | /** Causes the function template to inherit from a parent function template.*/ |
| 1685 | void Inherit(Handle<FunctionTemplate> parent); |
| 1686 | |
| 1687 | /** |
| 1688 | * A PrototypeTemplate is the template used to create the prototype object |
| 1689 | * of the function created by this template. |
| 1690 | */ |
| 1691 | Local<ObjectTemplate> PrototypeTemplate(); |
| 1692 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1693 | |
| 1694 | /** |
| 1695 | * Set the class name of the FunctionTemplate. This is used for |
| 1696 | * printing objects created with the function created from the |
| 1697 | * FunctionTemplate as its constructor. |
| 1698 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1699 | void SetClassName(Handle<String> name); |
| 1700 | |
| 1701 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1702 | * Determines whether the __proto__ accessor ignores instances of |
| 1703 | * the function template. If instances of the function template are |
| 1704 | * ignored, __proto__ skips all instances and instead returns the |
| 1705 | * next object in the prototype chain. |
| 1706 | * |
| 1707 | * Call with a value of true to make the __proto__ accessor ignore |
| 1708 | * instances of the function template. Call with a value of false |
| 1709 | * to make the __proto__ accessor not ignore instances of the |
| 1710 | * function template. By default, instances of a function template |
| 1711 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1712 | */ |
| 1713 | void SetHiddenPrototype(bool value); |
| 1714 | |
| 1715 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1716 | * Returns true if the given object is an instance of this function |
| 1717 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1718 | */ |
| 1719 | bool HasInstance(Handle<Value> object); |
| 1720 | |
| 1721 | private: |
| 1722 | FunctionTemplate(); |
| 1723 | void AddInstancePropertyAccessor(Handle<String> name, |
| 1724 | AccessorGetter getter, |
| 1725 | AccessorSetter setter, |
| 1726 | Handle<Value> data, |
| 1727 | AccessControl settings, |
| 1728 | PropertyAttribute attributes); |
| 1729 | void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, |
| 1730 | NamedPropertySetter setter, |
| 1731 | NamedPropertyQuery query, |
| 1732 | NamedPropertyDeleter remover, |
| 1733 | NamedPropertyEnumerator enumerator, |
| 1734 | Handle<Value> data); |
| 1735 | void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, |
| 1736 | IndexedPropertySetter setter, |
| 1737 | IndexedPropertyQuery query, |
| 1738 | IndexedPropertyDeleter remover, |
| 1739 | IndexedPropertyEnumerator enumerator, |
| 1740 | Handle<Value> data); |
| 1741 | void SetInstanceCallAsFunctionHandler(InvocationCallback callback, |
| 1742 | Handle<Value> data); |
| 1743 | |
| 1744 | friend class Context; |
| 1745 | friend class ObjectTemplate; |
| 1746 | }; |
| 1747 | |
| 1748 | |
| 1749 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1750 | * An ObjectTemplate is used to create objects at runtime. |
| 1751 | * |
| 1752 | * Properties added to an ObjectTemplate are added to each object |
| 1753 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1754 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1755 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1756 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1757 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1759 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1760 | /** Creates a new instance of this template.*/ |
| 1761 | Local<Object> NewInstance(); |
| 1762 | |
| 1763 | /** |
| 1764 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1765 | * |
| 1766 | * Whenever the property with the given name is accessed on objects |
| 1767 | * created from this ObjectTemplate the getter and setter callbacks |
| 1768 | * are called instead of getting and setting the property directly |
| 1769 | * on the JavaScript object. |
| 1770 | * |
| 1771 | * \param name The name of the property for which an accessor is added. |
| 1772 | * \param getter The callback to invoke when getting the property. |
| 1773 | * \param setter The callback to invoke when setting the property. |
| 1774 | * \param data A piece of data that will be passed to the getter and setter |
| 1775 | * callbacks whenever they are invoked. |
| 1776 | * \param settings Access control settings for the accessor. This is a bit |
| 1777 | * field consisting of one of more of |
| 1778 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 1779 | * The default is to not allow cross-context access. |
| 1780 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 1781 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 1782 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 1783 | * cross-context access. |
| 1784 | * \param attribute The attributes of the property for which an accessor |
| 1785 | * is added. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1786 | */ |
| 1787 | void SetAccessor(Handle<String> name, |
| 1788 | AccessorGetter getter, |
| 1789 | AccessorSetter setter = 0, |
| 1790 | Handle<Value> data = Handle<Value>(), |
| 1791 | AccessControl settings = DEFAULT, |
| 1792 | PropertyAttribute attribute = None); |
| 1793 | |
| 1794 | /** |
| 1795 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1796 | * |
| 1797 | * Whenever a named property is accessed on objects created from |
| 1798 | * this object template, the provided callback is invoked instead of |
| 1799 | * accessing the property directly on the JavaScript object. |
| 1800 | * |
| 1801 | * \param getter The callback to invoke when getting a property. |
| 1802 | * \param setter The callback to invoke when setting a property. |
| 1803 | * \param query The callback to invoke to check is an object has a property. |
| 1804 | * \param deleter The callback to invoke when deleting a property. |
| 1805 | * \param enumerator The callback to invoke to enumerate all the named |
| 1806 | * properties of an object. |
| 1807 | * \param data A piece of data that will be passed to the callbacks |
| 1808 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1809 | */ |
| 1810 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 1811 | NamedPropertySetter setter = 0, |
| 1812 | NamedPropertyQuery query = 0, |
| 1813 | NamedPropertyDeleter deleter = 0, |
| 1814 | NamedPropertyEnumerator enumerator = 0, |
| 1815 | Handle<Value> data = Handle<Value>()); |
| 1816 | |
| 1817 | /** |
| 1818 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1819 | * |
| 1820 | * Whenever an indexed property is accessed on objects created from |
| 1821 | * this object template, the provided callback is invoked instead of |
| 1822 | * accessing the property directly on the JavaScript object. |
| 1823 | * |
| 1824 | * \param getter The callback to invoke when getting a property. |
| 1825 | * \param setter The callback to invoke when setting a property. |
| 1826 | * \param query The callback to invoke to check is an object has a property. |
| 1827 | * \param deleter The callback to invoke when deleting a property. |
| 1828 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 1829 | * properties of an object. |
| 1830 | * \param data A piece of data that will be passed to the callbacks |
| 1831 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1832 | */ |
| 1833 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 1834 | IndexedPropertySetter setter = 0, |
| 1835 | IndexedPropertyQuery query = 0, |
| 1836 | IndexedPropertyDeleter deleter = 0, |
| 1837 | IndexedPropertyEnumerator enumerator = 0, |
| 1838 | Handle<Value> data = Handle<Value>()); |
| 1839 | /** |
| 1840 | * Sets the callback to be used when calling instances created from |
| 1841 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1842 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1843 | * function. |
| 1844 | */ |
| 1845 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 1846 | Handle<Value> data = Handle<Value>()); |
| 1847 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1848 | /** |
| 1849 | * Mark object instances of the template as undetectable. |
| 1850 | * |
| 1851 | * In many ways, undetectable objects behave as though they are not |
| 1852 | * there. They behave like 'undefined' in conditionals and when |
| 1853 | * printed. However, properties can be accessed and called as on |
| 1854 | * normal objects. |
| 1855 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1856 | void MarkAsUndetectable(); |
| 1857 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1858 | /** |
| 1859 | * Sets access check callbacks on the object template. |
| 1860 | * |
| 1861 | * When accessing properties on instances of this object template, |
| 1862 | * the access check callback will be called to determine whether or |
| 1863 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1864 | * The last parameter specifies whether access checks are turned |
| 1865 | * on by default on instances. If access checks are off by default, |
| 1866 | * they can be turned on on individual instances by calling |
| 1867 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1868 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1869 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 1870 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1871 | Handle<Value> data = Handle<Value>(), |
| 1872 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1873 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1874 | /** |
| 1875 | * Gets the number of internal fields for objects generated from |
| 1876 | * this template. |
| 1877 | */ |
| 1878 | int InternalFieldCount(); |
| 1879 | |
| 1880 | /** |
| 1881 | * Sets the number of internal fields for objects generated from |
| 1882 | * this template. |
| 1883 | */ |
| 1884 | void SetInternalFieldCount(int value); |
| 1885 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1886 | private: |
| 1887 | ObjectTemplate(); |
| 1888 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 1889 | friend class FunctionTemplate; |
| 1890 | }; |
| 1891 | |
| 1892 | |
| 1893 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1894 | * A Signature specifies which receivers and arguments a function can |
| 1895 | * legally be called with. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1896 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1897 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1898 | public: |
| 1899 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 1900 | Handle<FunctionTemplate>(), |
| 1901 | int argc = 0, |
| 1902 | Handle<FunctionTemplate> argv[] = 0); |
| 1903 | private: |
| 1904 | Signature(); |
| 1905 | }; |
| 1906 | |
| 1907 | |
| 1908 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1909 | * A utility for determining the type of objects based on the template |
| 1910 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1911 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1912 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1913 | public: |
| 1914 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 1915 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 1916 | int match(Handle<Value> value); |
| 1917 | private: |
| 1918 | TypeSwitch(); |
| 1919 | }; |
| 1920 | |
| 1921 | |
| 1922 | // --- E x t e n s i o n s --- |
| 1923 | |
| 1924 | |
| 1925 | /** |
| 1926 | * Ignore |
| 1927 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1928 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1929 | public: |
| 1930 | Extension(const char* name, |
| 1931 | const char* source = 0, |
| 1932 | int dep_count = 0, |
| 1933 | const char** deps = 0); |
| 1934 | virtual ~Extension() { } |
| 1935 | virtual v8::Handle<v8::FunctionTemplate> |
| 1936 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 1937 | return v8::Handle<v8::FunctionTemplate>(); |
| 1938 | } |
| 1939 | |
| 1940 | const char* name() { return name_; } |
| 1941 | const char* source() { return source_; } |
| 1942 | int dependency_count() { return dep_count_; } |
| 1943 | const char** dependencies() { return deps_; } |
| 1944 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 1945 | bool auto_enable() { return auto_enable_; } |
| 1946 | |
| 1947 | private: |
| 1948 | const char* name_; |
| 1949 | const char* source_; |
| 1950 | int dep_count_; |
| 1951 | const char** deps_; |
| 1952 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1953 | |
| 1954 | // Disallow copying and assigning. |
| 1955 | Extension(const Extension&); |
| 1956 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1957 | }; |
| 1958 | |
| 1959 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1960 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1961 | |
| 1962 | |
| 1963 | /** |
| 1964 | * Ignore |
| 1965 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1966 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1967 | public: |
| 1968 | inline DeclareExtension(Extension* extension) { |
| 1969 | RegisterExtension(extension); |
| 1970 | } |
| 1971 | }; |
| 1972 | |
| 1973 | |
| 1974 | // --- S t a t i c s --- |
| 1975 | |
| 1976 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1977 | Handle<Primitive> V8EXPORT Undefined(); |
| 1978 | Handle<Primitive> V8EXPORT Null(); |
| 1979 | Handle<Boolean> V8EXPORT True(); |
| 1980 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1981 | |
| 1982 | |
| 1983 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 1984 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 1985 | * You must set the heap size before initializing the VM - the size cannot be |
| 1986 | * adjusted after the VM is initialized. |
| 1987 | * |
| 1988 | * If you are using threads then you should hold the V8::Locker lock while |
| 1989 | * setting the stack limit and you must set a non-default stack limit separately |
| 1990 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1991 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1992 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1993 | public: |
| 1994 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1995 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1996 | void set_max_young_space_size(int value) { max_young_space_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1997 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1998 | void set_max_old_space_size(int value) { max_old_space_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1999 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 2000 | // Sets an address beyond which the VM's stack may not grow. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2001 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 2002 | private: |
| 2003 | int max_young_space_size_; |
| 2004 | int max_old_space_size_; |
| 2005 | uint32_t* stack_limit_; |
| 2006 | }; |
| 2007 | |
| 2008 | |
| 2009 | bool SetResourceConstraints(ResourceConstraints* constraints); |
| 2010 | |
| 2011 | |
| 2012 | // --- E x c e p t i o n s --- |
| 2013 | |
| 2014 | |
| 2015 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 2016 | |
| 2017 | |
| 2018 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data); |
| 2019 | |
| 2020 | |
| 2021 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2022 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 2023 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2024 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2025 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2026 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2027 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2028 | |
| 2029 | /** |
| 2030 | * Create new error objects by calling the corresponding error object |
| 2031 | * constructor with the message. |
| 2032 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2033 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2034 | public: |
| 2035 | static Local<Value> RangeError(Handle<String> message); |
| 2036 | static Local<Value> ReferenceError(Handle<String> message); |
| 2037 | static Local<Value> SyntaxError(Handle<String> message); |
| 2038 | static Local<Value> TypeError(Handle<String> message); |
| 2039 | static Local<Value> Error(Handle<String> message); |
| 2040 | }; |
| 2041 | |
| 2042 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2043 | // --- C o u n t e r s C a l l b a c k s --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2044 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2045 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2046 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2047 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 2048 | int min, |
| 2049 | int max, |
| 2050 | size_t buckets); |
| 2051 | |
| 2052 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 2053 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2054 | // --- F a i l e d A c c e s s C h e c k C a l l b a c k --- |
| 2055 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 2056 | AccessType type, |
| 2057 | Local<Value> data); |
| 2058 | |
| 2059 | // --- G a r b a g e C o l l e c t i o n C a l l b a c k s |
| 2060 | |
| 2061 | /** |
| 2062 | * Applications can register a callback function which is called |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2063 | * before and after a major garbage collection. Allocations are not |
| 2064 | * allowed in the callback function, you therefore cannot manipulate |
| 2065 | * objects (set or delete properties for example) since it is possible |
| 2066 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2067 | */ |
| 2068 | typedef void (*GCCallback)(); |
| 2069 | |
| 2070 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2071 | // --- C o n t e x t G e n e r a t o r --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2072 | |
| 2073 | /** |
| 2074 | * Applications must provide a callback function which is called to generate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2075 | * a context if a context was not deserialized from the snapshot. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2076 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2077 | typedef Persistent<Context> (*ContextGenerator)(); |
| 2078 | |
| 2079 | |
| 2080 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2081 | * Profiler modules. |
| 2082 | * |
| 2083 | * In V8, profiler consists of several modules: CPU profiler, and different |
| 2084 | * kinds of heap profiling. Each can be turned on / off independently. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 2085 | * When PROFILER_MODULE_HEAP_SNAPSHOT flag is passed to ResumeProfilerEx, |
| 2086 | * modules are enabled only temporarily for making a snapshot of the heap. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2087 | */ |
| 2088 | enum ProfilerModules { |
| 2089 | PROFILER_MODULE_NONE = 0, |
| 2090 | PROFILER_MODULE_CPU = 1, |
| 2091 | PROFILER_MODULE_HEAP_STATS = 1 << 1, |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 2092 | PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2, |
| 2093 | PROFILER_MODULE_HEAP_SNAPSHOT = 1 << 16 |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2094 | }; |
| 2095 | |
| 2096 | |
| 2097 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2098 | * Container class for static utility functions. |
| 2099 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2100 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2101 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2102 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2103 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 2104 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2105 | /** |
| 2106 | * Ignore out-of-memory exceptions. |
| 2107 | * |
| 2108 | * V8 running out of memory is treated as a fatal error by default. |
| 2109 | * This means that the fatal error handler is called and that V8 is |
| 2110 | * terminated. |
| 2111 | * |
| 2112 | * IgnoreOutOfMemoryException can be used to not treat a |
| 2113 | * out-of-memory situation as a fatal error. This way, the contexts |
| 2114 | * that did not cause the out of memory problem might be able to |
| 2115 | * continue execution. |
| 2116 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2117 | static void IgnoreOutOfMemoryException(); |
| 2118 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2119 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2120 | * Check if V8 is dead and therefore unusable. This is the case after |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2121 | * fatal errors such as out-of-memory situations. |
| 2122 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2123 | static bool IsDead(); |
| 2124 | |
| 2125 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2126 | * Adds a message listener. |
| 2127 | * |
| 2128 | * The same message listener can be added more than once and it that |
| 2129 | * case it will be called more than once for each message. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2130 | */ |
| 2131 | static bool AddMessageListener(MessageCallback that, |
| 2132 | Handle<Value> data = Handle<Value>()); |
| 2133 | |
| 2134 | /** |
| 2135 | * Remove all message listeners from the specified callback function. |
| 2136 | */ |
| 2137 | static void RemoveMessageListeners(MessageCallback that); |
| 2138 | |
| 2139 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2140 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2141 | */ |
| 2142 | static void SetFlagsFromString(const char* str, int length); |
| 2143 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2144 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2145 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2146 | */ |
| 2147 | static void SetFlagsFromCommandLine(int* argc, |
| 2148 | char** argv, |
| 2149 | bool remove_flags); |
| 2150 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2151 | /** Get the version string. */ |
| 2152 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2153 | |
| 2154 | /** |
| 2155 | * Enables the host application to provide a mechanism for recording |
| 2156 | * statistics counters. |
| 2157 | */ |
| 2158 | static void SetCounterFunction(CounterLookupCallback); |
| 2159 | |
| 2160 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2161 | * Enables the host application to provide a mechanism for recording |
| 2162 | * histograms. The CreateHistogram function returns a |
| 2163 | * histogram which will later be passed to the AddHistogramSample |
| 2164 | * function. |
| 2165 | */ |
| 2166 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 2167 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 2168 | |
| 2169 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2170 | * Enables the computation of a sliding window of states. The sliding |
| 2171 | * window information is recorded in statistics counters. |
| 2172 | */ |
| 2173 | static void EnableSlidingStateWindow(); |
| 2174 | |
| 2175 | /** Callback function for reporting failed access checks.*/ |
| 2176 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 2177 | |
| 2178 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2179 | * Enables the host application to receive a notification before a |
| 2180 | * major garbage colletion. Allocations are not allowed in the |
| 2181 | * callback function, you therefore cannot manipulate objects (set |
| 2182 | * or delete properties for example) since it is possible such |
| 2183 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2184 | */ |
| 2185 | static void SetGlobalGCPrologueCallback(GCCallback); |
| 2186 | |
| 2187 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2188 | * Enables the host application to receive a notification after a |
| 2189 | * major garbage collection. Allocations are not allowed in the |
| 2190 | * callback function, you therefore cannot manipulate objects (set |
| 2191 | * or delete properties for example) since it is possible such |
| 2192 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2193 | */ |
| 2194 | static void SetGlobalGCEpilogueCallback(GCCallback); |
| 2195 | |
| 2196 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2197 | * Allows the host application to group objects together. If one |
| 2198 | * object in the group is alive, all objects in the group are alive. |
| 2199 | * After each garbage collection, object groups are removed. It is |
| 2200 | * intended to be used in the before-garbage-collection callback |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2201 | * function, for instance to simulate DOM tree connections among JS |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2202 | * wrapper objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2203 | */ |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2204 | static void AddObjectGroup(Persistent<Value>* objects, size_t length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2205 | |
| 2206 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2207 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 2208 | * initialize from scratch. This function is called implicitly if |
| 2209 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2210 | */ |
| 2211 | static bool Initialize(); |
| 2212 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2213 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2214 | * Adjusts the amount of registered external memory. Used to give |
| 2215 | * V8 an indication of the amount of externally allocated memory |
| 2216 | * that is kept alive by JavaScript objects. V8 uses this to decide |
| 2217 | * when to perform global garbage collections. Registering |
| 2218 | * externally allocated memory will trigger global garbage |
| 2219 | * collections more often than otherwise in an attempt to garbage |
| 2220 | * collect the JavaScript objects keeping the externally allocated |
| 2221 | * memory alive. |
| 2222 | * |
| 2223 | * \param change_in_bytes the change in externally allocated memory |
| 2224 | * that is kept alive by JavaScript objects. |
| 2225 | * \returns the adjusted value. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2226 | */ |
| 2227 | static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes); |
| 2228 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2229 | /** |
| 2230 | * Suspends recording of tick samples in the profiler. |
| 2231 | * When the V8 profiling mode is enabled (usually via command line |
| 2232 | * switches) this function suspends recording of tick samples. |
| 2233 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 2234 | * |
| 2235 | * See also the --prof and --prof_auto command line switches to |
| 2236 | * enable V8 profiling. |
| 2237 | */ |
| 2238 | static void PauseProfiler(); |
| 2239 | |
| 2240 | /** |
| 2241 | * Resumes recording of tick samples in the profiler. |
| 2242 | * See also PauseProfiler(). |
| 2243 | */ |
| 2244 | static void ResumeProfiler(); |
| 2245 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2246 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2247 | * Return whether profiler is currently paused. |
| 2248 | */ |
| 2249 | static bool IsProfilerPaused(); |
| 2250 | |
| 2251 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2252 | * Resumes specified profiler modules. |
| 2253 | * "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CPU)". |
| 2254 | * See ProfilerModules enum. |
| 2255 | * |
| 2256 | * \param flags Flags specifying profiler modules. |
| 2257 | */ |
| 2258 | static void ResumeProfilerEx(int flags); |
| 2259 | |
| 2260 | /** |
| 2261 | * Pauses specified profiler modules. |
| 2262 | * "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)". |
| 2263 | * See ProfilerModules enum. |
| 2264 | * |
| 2265 | * \param flags Flags specifying profiler modules. |
| 2266 | */ |
| 2267 | static void PauseProfilerEx(int flags); |
| 2268 | |
| 2269 | /** |
| 2270 | * Returns active (resumed) profiler modules. |
| 2271 | * See ProfilerModules enum. |
| 2272 | * |
| 2273 | * \returns active profiler modules. |
| 2274 | */ |
| 2275 | static int GetActiveProfilerModules(); |
| 2276 | |
| 2277 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2278 | * If logging is performed into a memory buffer (via --logfile=*), allows to |
| 2279 | * retrieve previously written messages. This can be used for retrieving |
| 2280 | * profiler log data in the application. This function is thread-safe. |
| 2281 | * |
| 2282 | * Caller provides a destination buffer that must exist during GetLogLines |
| 2283 | * call. Only whole log lines are copied into the buffer. |
| 2284 | * |
| 2285 | * \param from_pos specified a point in a buffer to read from, 0 is the |
| 2286 | * beginning of a buffer. It is assumed that caller updates its current |
| 2287 | * position using returned size value from the previous call. |
| 2288 | * \param dest_buf destination buffer for log data. |
| 2289 | * \param max_size size of the destination buffer. |
| 2290 | * \returns actual size of log data copied into buffer. |
| 2291 | */ |
| 2292 | static int GetLogLines(int from_pos, char* dest_buf, int max_size); |
| 2293 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 2294 | /** |
| 2295 | * Retrieve the V8 thread id of the calling thread. |
| 2296 | * |
| 2297 | * The thread id for a thread should only be retrieved after the V8 |
| 2298 | * lock has been acquired with a Locker object with that thread. |
| 2299 | */ |
| 2300 | static int GetCurrentThreadId(); |
| 2301 | |
| 2302 | /** |
| 2303 | * Forcefully terminate execution of a JavaScript thread. This can |
| 2304 | * be used to terminate long-running scripts. |
| 2305 | * |
| 2306 | * TerminateExecution should only be called when then V8 lock has |
| 2307 | * been acquired with a Locker object. Therefore, in order to be |
| 2308 | * able to terminate long-running threads, preemption must be |
| 2309 | * enabled to allow the user of TerminateExecution to acquire the |
| 2310 | * lock. |
| 2311 | * |
| 2312 | * The termination is achieved by throwing an exception that is |
| 2313 | * uncatchable by JavaScript exception handlers. Termination |
| 2314 | * exceptions act as if they were caught by a C++ TryCatch exception |
| 2315 | * handlers. If forceful termination is used, any C++ TryCatch |
| 2316 | * exception handler that catches an exception should check if that |
| 2317 | * exception is a termination exception and immediately return if |
| 2318 | * that is the case. Returning immediately in that case will |
| 2319 | * continue the propagation of the termination exception if needed. |
| 2320 | * |
| 2321 | * The thread id passed to TerminateExecution must have been |
| 2322 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 2323 | * |
| 2324 | * \param thread_id The thread id of the thread to terminate. |
| 2325 | */ |
| 2326 | static void TerminateExecution(int thread_id); |
| 2327 | |
| 2328 | /** |
| 2329 | * Forcefully terminate the current thread of JavaScript execution. |
| 2330 | * |
| 2331 | * This method can be used by any thread even if that thread has not |
| 2332 | * acquired the V8 lock with a Locker object. |
| 2333 | */ |
| 2334 | static void TerminateExecution(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2335 | |
| 2336 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2337 | * Releases any resources used by v8 and stops any utility threads |
| 2338 | * that may be running. Note that disposing v8 is permanent, it |
| 2339 | * cannot be reinitialized. |
| 2340 | * |
| 2341 | * It should generally not be necessary to dispose v8 before exiting |
| 2342 | * a process, this should happen automatically. It is only necessary |
| 2343 | * to use if the process needs the resources taken up by v8. |
| 2344 | */ |
| 2345 | static bool Dispose(); |
| 2346 | |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 2347 | |
| 2348 | /** |
| 2349 | * Optional notification that the embedder is idle. |
| 2350 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2351 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2352 | * Returns true if the embedder should stop calling IdleNotification |
| 2353 | * until real work has been done. This indicates that V8 has done |
| 2354 | * as much cleanup as it will be able to do. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 2355 | */ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 2356 | static bool IdleNotification(); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 2357 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 2358 | /** |
| 2359 | * Optional notification that the system is running low on memory. |
| 2360 | * V8 uses these notifications to attempt to free memory. |
| 2361 | */ |
| 2362 | static void LowMemoryNotification(); |
| 2363 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2364 | private: |
| 2365 | V8(); |
| 2366 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2367 | static internal::Object** GlobalizeReference(internal::Object** handle); |
| 2368 | static void DisposeGlobal(internal::Object** global_handle); |
| 2369 | static void MakeWeak(internal::Object** global_handle, |
| 2370 | void* data, |
| 2371 | WeakReferenceCallback); |
| 2372 | static void ClearWeak(internal::Object** global_handle); |
| 2373 | static bool IsGlobalNearDeath(internal::Object** global_handle); |
| 2374 | static bool IsGlobalWeak(internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2375 | |
| 2376 | template <class T> friend class Handle; |
| 2377 | template <class T> friend class Local; |
| 2378 | template <class T> friend class Persistent; |
| 2379 | friend class Context; |
| 2380 | }; |
| 2381 | |
| 2382 | |
| 2383 | /** |
| 2384 | * An external exception handler. |
| 2385 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2386 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2387 | public: |
| 2388 | |
| 2389 | /** |
| 2390 | * Creates a new try/catch block and registers it with v8. |
| 2391 | */ |
| 2392 | TryCatch(); |
| 2393 | |
| 2394 | /** |
| 2395 | * Unregisters and deletes this try/catch block. |
| 2396 | */ |
| 2397 | ~TryCatch(); |
| 2398 | |
| 2399 | /** |
| 2400 | * Returns true if an exception has been caught by this try/catch block. |
| 2401 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2402 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2403 | |
| 2404 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 2405 | * For certain types of exceptions, it makes no sense to continue |
| 2406 | * execution. |
| 2407 | * |
| 2408 | * Currently, the only type of exception that can be caught by a |
| 2409 | * TryCatch handler and for which it does not make sense to continue |
| 2410 | * is termination exception. Such exceptions are thrown when the |
| 2411 | * TerminateExecution methods are called to terminate a long-running |
| 2412 | * script. |
| 2413 | * |
| 2414 | * If CanContinue returns false, the correct action is to perform |
| 2415 | * any C++ cleanup needed and then return. |
| 2416 | */ |
| 2417 | bool CanContinue() const; |
| 2418 | |
| 2419 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2420 | * Returns the exception caught by this try/catch block. If no exception has |
| 2421 | * been caught an empty handle is returned. |
| 2422 | * |
| 2423 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 2424 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2425 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2426 | |
| 2427 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2428 | * Returns the .stack property of the thrown object. If no .stack |
| 2429 | * property is present an empty handle is returned. |
| 2430 | */ |
| 2431 | Local<Value> StackTrace() const; |
| 2432 | |
| 2433 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2434 | * Returns the message associated with this exception. If there is |
| 2435 | * no message associated an empty handle is returned. |
| 2436 | * |
| 2437 | * The returned handle is valid until this TryCatch block has been |
| 2438 | * destroyed. |
| 2439 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2440 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2441 | |
| 2442 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2443 | * Clears any exceptions that may have been caught by this try/catch block. |
| 2444 | * After this method has been called, HasCaught() will return false. |
| 2445 | * |
| 2446 | * It is not necessary to clear a try/catch block before using it again; if |
| 2447 | * another exception is thrown the previously caught exception will just be |
| 2448 | * overwritten. However, it is often a good idea since it makes it easier |
| 2449 | * to determine which operation threw a given exception. |
| 2450 | */ |
| 2451 | void Reset(); |
| 2452 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2453 | /** |
| 2454 | * Set verbosity of the external exception handler. |
| 2455 | * |
| 2456 | * By default, exceptions that are caught by an external exception |
| 2457 | * handler are not reported. Call SetVerbose with true on an |
| 2458 | * external exception handler to have exceptions caught by the |
| 2459 | * handler reported as if they were not caught. |
| 2460 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2461 | void SetVerbose(bool value); |
| 2462 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2463 | /** |
| 2464 | * Set whether or not this TryCatch should capture a Message object |
| 2465 | * which holds source information about where the exception |
| 2466 | * occurred. True by default. |
| 2467 | */ |
| 2468 | void SetCaptureMessage(bool value); |
| 2469 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2470 | public: |
| 2471 | TryCatch* next_; |
| 2472 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2473 | void* message_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2474 | bool is_verbose_; |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 2475 | bool can_continue_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2476 | bool capture_message_; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2477 | void* js_handler_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2478 | }; |
| 2479 | |
| 2480 | |
| 2481 | // --- C o n t e x t --- |
| 2482 | |
| 2483 | |
| 2484 | /** |
| 2485 | * Ignore |
| 2486 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2487 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2488 | public: |
| 2489 | ExtensionConfiguration(int name_count, const char* names[]) |
| 2490 | : name_count_(name_count), names_(names) { } |
| 2491 | private: |
| 2492 | friend class ImplementationUtilities; |
| 2493 | int name_count_; |
| 2494 | const char** names_; |
| 2495 | }; |
| 2496 | |
| 2497 | |
| 2498 | /** |
| 2499 | * A sandboxed execution context with its own set of built-in objects |
| 2500 | * and functions. |
| 2501 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2502 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2503 | public: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2504 | /** Returns the global object of the context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2505 | Local<Object> Global(); |
| 2506 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2507 | /** |
| 2508 | * Detaches the global object from its context before |
| 2509 | * the global object can be reused to create a new context. |
| 2510 | */ |
| 2511 | void DetachGlobal(); |
| 2512 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2513 | /** Creates a new context. */ |
| 2514 | static Persistent<Context> New( |
| 2515 | ExtensionConfiguration* extensions = 0, |
| 2516 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 2517 | Handle<Value> global_object = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2518 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 2519 | /** Returns the last entered context. */ |
| 2520 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2521 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 2522 | /** Returns the context that is on the top of the stack. */ |
| 2523 | static Local<Context> GetCurrent(); |
| 2524 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2525 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 2526 | * Returns the context of the calling JavaScript code. That is the |
| 2527 | * context of the top-most JavaScript frame. If there are no |
| 2528 | * JavaScript frames an empty handle is returned. |
| 2529 | */ |
| 2530 | static Local<Context> GetCalling(); |
| 2531 | |
| 2532 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2533 | * Sets the security token for the context. To access an object in |
| 2534 | * another context, the security tokens must match. |
| 2535 | */ |
| 2536 | void SetSecurityToken(Handle<Value> token); |
| 2537 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2538 | /** Restores the security token to the default value. */ |
| 2539 | void UseDefaultSecurityToken(); |
| 2540 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2541 | /** Returns the security token of this context.*/ |
| 2542 | Handle<Value> GetSecurityToken(); |
| 2543 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2544 | /** |
| 2545 | * Enter this context. After entering a context, all code compiled |
| 2546 | * and run is compiled and run in this context. If another context |
| 2547 | * is already entered, this old context is saved so it can be |
| 2548 | * restored when the new context is exited. |
| 2549 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2550 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2551 | |
| 2552 | /** |
| 2553 | * Exit this context. Exiting the current context restores the |
| 2554 | * context that was in place when entering the current context. |
| 2555 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2556 | void Exit(); |
| 2557 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2558 | /** Returns true if the context has experienced an out of memory situation. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2559 | bool HasOutOfMemoryException(); |
| 2560 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2561 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2562 | static bool InContext(); |
| 2563 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2564 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2565 | * Associate an additional data object with the context. This is mainly used |
| 2566 | * with the debugger to provide additional information on the context through |
| 2567 | * the debugger API. |
| 2568 | */ |
| 2569 | void SetData(Handle<Value> data); |
| 2570 | Local<Value> GetData(); |
| 2571 | |
| 2572 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2573 | * Stack-allocated class which sets the execution context for all |
| 2574 | * operations executed within a local scope. |
| 2575 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2576 | class V8EXPORT Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2577 | public: |
| 2578 | inline Scope(Handle<Context> context) : context_(context) { |
| 2579 | context_->Enter(); |
| 2580 | } |
| 2581 | inline ~Scope() { context_->Exit(); } |
| 2582 | private: |
| 2583 | Handle<Context> context_; |
| 2584 | }; |
| 2585 | |
| 2586 | private: |
| 2587 | friend class Value; |
| 2588 | friend class Script; |
| 2589 | friend class Object; |
| 2590 | friend class Function; |
| 2591 | }; |
| 2592 | |
| 2593 | |
| 2594 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2595 | * Multiple threads in V8 are allowed, but only one thread at a time |
| 2596 | * is allowed to use V8. The definition of 'using V8' includes |
| 2597 | * accessing handles or holding onto object pointers obtained from V8 |
| 2598 | * handles. It is up to the user of V8 to ensure (perhaps with |
| 2599 | * locking) that this constraint is not violated. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2600 | * |
| 2601 | * If you wish to start using V8 in a thread you can do this by constructing |
| 2602 | * a v8::Locker object. After the code using V8 has completed for the |
| 2603 | * current thread you can call the destructor. This can be combined |
| 2604 | * with C++ scope-based construction as follows: |
| 2605 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2606 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2607 | * ... |
| 2608 | * { |
| 2609 | * v8::Locker locker; |
| 2610 | * ... |
| 2611 | * // Code using V8 goes here. |
| 2612 | * ... |
| 2613 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2614 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2615 | * |
| 2616 | * If you wish to stop using V8 in a thread A you can do this by either |
| 2617 | * by destroying the v8::Locker object as above or by constructing a |
| 2618 | * v8::Unlocker object: |
| 2619 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2620 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2621 | * { |
| 2622 | * v8::Unlocker unlocker; |
| 2623 | * ... |
| 2624 | * // Code not using V8 goes here while V8 can run in another thread. |
| 2625 | * ... |
| 2626 | * } // Destructor called here. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2627 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2628 | * |
| 2629 | * The Unlocker object is intended for use in a long-running callback |
| 2630 | * from V8, where you want to release the V8 lock for other threads to |
| 2631 | * use. |
| 2632 | * |
| 2633 | * The v8::Locker is a recursive lock. That is, you can lock more than |
| 2634 | * once in a given thread. This can be useful if you have code that can |
| 2635 | * be called either from code that holds the lock or from code that does |
| 2636 | * not. The Unlocker is not recursive so you can not have several |
| 2637 | * Unlockers on the stack at once, and you can not use an Unlocker in a |
| 2638 | * thread that is not inside a Locker's scope. |
| 2639 | * |
| 2640 | * An unlocker will unlock several lockers if it has to and reinstate |
| 2641 | * the correct depth of locking on its destruction. eg.: |
| 2642 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2643 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2644 | * // V8 not locked. |
| 2645 | * { |
| 2646 | * v8::Locker locker; |
| 2647 | * // V8 locked. |
| 2648 | * { |
| 2649 | * v8::Locker another_locker; |
| 2650 | * // V8 still locked (2 levels). |
| 2651 | * { |
| 2652 | * v8::Unlocker unlocker; |
| 2653 | * // V8 not locked. |
| 2654 | * } |
| 2655 | * // V8 locked again (2 levels). |
| 2656 | * } |
| 2657 | * // V8 still locked (1 level). |
| 2658 | * } |
| 2659 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2660 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2661 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2662 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2663 | public: |
| 2664 | Unlocker(); |
| 2665 | ~Unlocker(); |
| 2666 | }; |
| 2667 | |
| 2668 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2669 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2670 | public: |
| 2671 | Locker(); |
| 2672 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2673 | |
| 2674 | /** |
| 2675 | * Start preemption. |
| 2676 | * |
| 2677 | * When preemption is started, a timer is fired every n milli seconds |
| 2678 | * that will switch between multiple threads that are in contention |
| 2679 | * for the V8 lock. |
| 2680 | */ |
| 2681 | static void StartPreemption(int every_n_ms); |
| 2682 | |
| 2683 | /** |
| 2684 | * Stop preemption. |
| 2685 | */ |
| 2686 | static void StopPreemption(); |
| 2687 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2688 | /** |
| 2689 | * Returns whether or not the locker is locked by the current thread. |
| 2690 | */ |
| 2691 | static bool IsLocked(); |
| 2692 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2693 | /** |
| 2694 | * Returns whether v8::Locker is being used by this V8 instance. |
| 2695 | */ |
| 2696 | static bool IsActive() { return active_; } |
| 2697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2698 | private: |
| 2699 | bool has_lock_; |
| 2700 | bool top_level_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2701 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2702 | static bool active_; |
| 2703 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2704 | // Disallow copying and assigning. |
| 2705 | Locker(const Locker&); |
| 2706 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2707 | }; |
| 2708 | |
| 2709 | |
| 2710 | |
| 2711 | // --- I m p l e m e n t a t i o n --- |
| 2712 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2713 | |
| 2714 | namespace internal { |
| 2715 | |
| 2716 | |
| 2717 | // Tag information for HeapObject. |
| 2718 | const int kHeapObjectTag = 1; |
| 2719 | const int kHeapObjectTagSize = 2; |
| 2720 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 2721 | |
| 2722 | |
| 2723 | // Tag information for Smi. |
| 2724 | const int kSmiTag = 0; |
| 2725 | const int kSmiTagSize = 1; |
| 2726 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 2727 | |
| 2728 | |
| 2729 | /** |
| 2730 | * This class exports constants and functionality from within v8 that |
| 2731 | * is necessary to implement inline functions in the v8 api. Don't |
| 2732 | * depend on functions and constants defined here. |
| 2733 | */ |
| 2734 | class Internals { |
| 2735 | public: |
| 2736 | |
| 2737 | // These values match non-compiler-dependent values defined within |
| 2738 | // the implementation of v8. |
| 2739 | static const int kHeapObjectMapOffset = 0; |
| 2740 | static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int); |
| 2741 | static const int kStringResourceOffset = 2 * sizeof(void*); |
| 2742 | static const int kProxyProxyOffset = sizeof(void*); |
| 2743 | static const int kJSObjectHeaderSize = 3 * sizeof(void*); |
| 2744 | static const int kFullStringRepresentationMask = 0x07; |
| 2745 | static const int kExternalTwoByteRepresentationTag = 0x03; |
| 2746 | static const int kAlignedPointerShift = 2; |
| 2747 | |
| 2748 | // These constants are compiler dependent so their values must be |
| 2749 | // defined within the implementation. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2750 | V8EXPORT static int kJSObjectType; |
| 2751 | V8EXPORT static int kFirstNonstringType; |
| 2752 | V8EXPORT static int kProxyType; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2753 | |
| 2754 | static inline bool HasHeapObjectTag(internal::Object* value) { |
| 2755 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 2756 | kHeapObjectTag); |
| 2757 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 2758 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2759 | static inline bool HasSmiTag(internal::Object* value) { |
| 2760 | return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 2761 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 2762 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2763 | static inline int SmiValue(internal::Object* value) { |
| 2764 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> kSmiTagSize; |
| 2765 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 2766 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2767 | static inline bool IsExternalTwoByteString(int instance_type) { |
| 2768 | int representation = (instance_type & kFullStringRepresentationMask); |
| 2769 | return representation == kExternalTwoByteRepresentationTag; |
| 2770 | } |
| 2771 | |
| 2772 | template <typename T> |
| 2773 | static inline T ReadField(Object* ptr, int offset) { |
| 2774 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 2775 | return *reinterpret_cast<T*>(addr); |
| 2776 | } |
| 2777 | |
| 2778 | }; |
| 2779 | |
| 2780 | } |
| 2781 | |
| 2782 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2783 | template <class T> |
| 2784 | Handle<T>::Handle() : val_(0) { } |
| 2785 | |
| 2786 | |
| 2787 | template <class T> |
| 2788 | Local<T>::Local() : Handle<T>() { } |
| 2789 | |
| 2790 | |
| 2791 | template <class T> |
| 2792 | Local<T> Local<T>::New(Handle<T> that) { |
| 2793 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2794 | internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2795 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 2796 | } |
| 2797 | |
| 2798 | |
| 2799 | template <class T> |
| 2800 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
| 2801 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2802 | internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2803 | return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); |
| 2804 | } |
| 2805 | |
| 2806 | |
| 2807 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2808 | bool Persistent<T>::IsNearDeath() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2809 | if (this->IsEmpty()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2810 | return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | |
| 2814 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2815 | bool Persistent<T>::IsWeak() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2816 | if (this->IsEmpty()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2817 | return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | |
| 2821 | template <class T> |
| 2822 | void Persistent<T>::Dispose() { |
| 2823 | if (this->IsEmpty()) return; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2824 | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | |
| 2828 | template <class T> |
| 2829 | Persistent<T>::Persistent() : Handle<T>() { } |
| 2830 | |
| 2831 | template <class T> |
| 2832 | void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2833 | V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), |
| 2834 | parameters, |
| 2835 | callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | template <class T> |
| 2839 | void Persistent<T>::ClearWeak() { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2840 | V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2843 | Local<Value> Arguments::operator[](int i) const { |
| 2844 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 2845 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 2846 | } |
| 2847 | |
| 2848 | |
| 2849 | Local<Function> Arguments::Callee() const { |
| 2850 | return callee_; |
| 2851 | } |
| 2852 | |
| 2853 | |
| 2854 | Local<Object> Arguments::This() const { |
| 2855 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 2856 | } |
| 2857 | |
| 2858 | |
| 2859 | Local<Object> Arguments::Holder() const { |
| 2860 | return holder_; |
| 2861 | } |
| 2862 | |
| 2863 | |
| 2864 | Local<Value> Arguments::Data() const { |
| 2865 | return data_; |
| 2866 | } |
| 2867 | |
| 2868 | |
| 2869 | bool Arguments::IsConstructCall() const { |
| 2870 | return is_construct_call_; |
| 2871 | } |
| 2872 | |
| 2873 | |
| 2874 | int Arguments::Length() const { |
| 2875 | return length_; |
| 2876 | } |
| 2877 | |
| 2878 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2879 | template <class T> |
| 2880 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2881 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 2882 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2883 | return Local<T>(reinterpret_cast<T*>(after)); |
| 2884 | } |
| 2885 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2886 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2887 | return resource_name_; |
| 2888 | } |
| 2889 | |
| 2890 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2891 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2892 | return resource_line_offset_; |
| 2893 | } |
| 2894 | |
| 2895 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2896 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2897 | return resource_column_offset_; |
| 2898 | } |
| 2899 | |
| 2900 | |
| 2901 | Handle<Boolean> Boolean::New(bool value) { |
| 2902 | return value ? True() : False(); |
| 2903 | } |
| 2904 | |
| 2905 | |
| 2906 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 2907 | Set(v8::String::New(name), value); |
| 2908 | } |
| 2909 | |
| 2910 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2911 | Local<Value> Object::GetInternalField(int index) { |
| 2912 | #ifndef V8_ENABLE_CHECKS |
| 2913 | Local<Value> quick_result = UncheckedGetInternalField(index); |
| 2914 | if (!quick_result.IsEmpty()) return quick_result; |
| 2915 | #endif |
| 2916 | return CheckedGetInternalField(index); |
| 2917 | } |
| 2918 | |
| 2919 | |
| 2920 | Local<Value> Object::UncheckedGetInternalField(int index) { |
| 2921 | typedef internal::Object O; |
| 2922 | typedef internal::Internals I; |
| 2923 | O* obj = *reinterpret_cast<O**>(this); |
| 2924 | O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); |
| 2925 | int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); |
| 2926 | if (instance_type == I::kJSObjectType) { |
| 2927 | // If the object is a plain JSObject, which is the common case, |
| 2928 | // we know where to find the internal fields and can return the |
| 2929 | // value directly. |
| 2930 | int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index); |
| 2931 | O* value = I::ReadField<O*>(obj, offset); |
| 2932 | O** result = HandleScope::CreateHandle(value); |
| 2933 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 2934 | } else { |
| 2935 | return Local<Value>(); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | |
| 2940 | void* External::Unwrap(Handle<v8::Value> obj) { |
| 2941 | #ifdef V8_ENABLE_CHECKS |
| 2942 | return FullUnwrap(obj); |
| 2943 | #else |
| 2944 | return QuickUnwrap(obj); |
| 2945 | #endif |
| 2946 | } |
| 2947 | |
| 2948 | |
| 2949 | void* External::QuickUnwrap(Handle<v8::Value> wrapper) { |
| 2950 | typedef internal::Object O; |
| 2951 | typedef internal::Internals I; |
| 2952 | O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); |
| 2953 | if (I::HasSmiTag(obj)) { |
| 2954 | int value = I::SmiValue(obj) << I::kAlignedPointerShift; |
| 2955 | return reinterpret_cast<void*>(value); |
| 2956 | } else { |
| 2957 | O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); |
| 2958 | int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); |
| 2959 | if (instance_type == I::kProxyType) { |
| 2960 | return I::ReadField<void*>(obj, I::kProxyProxyOffset); |
| 2961 | } else { |
| 2962 | return NULL; |
| 2963 | } |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | |
| 2968 | void* Object::GetPointerFromInternalField(int index) { |
| 2969 | return External::Unwrap(GetInternalField(index)); |
| 2970 | } |
| 2971 | |
| 2972 | |
| 2973 | String* String::Cast(v8::Value* value) { |
| 2974 | #ifdef V8_ENABLE_CHECKS |
| 2975 | CheckCast(value); |
| 2976 | #endif |
| 2977 | return static_cast<String*>(value); |
| 2978 | } |
| 2979 | |
| 2980 | |
| 2981 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 2982 | typedef internal::Object O; |
| 2983 | typedef internal::Internals I; |
| 2984 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 2985 | O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); |
| 2986 | int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); |
| 2987 | String::ExternalStringResource* result; |
| 2988 | if (I::IsExternalTwoByteString(instance_type)) { |
| 2989 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 2990 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 2991 | } else { |
| 2992 | result = NULL; |
| 2993 | } |
| 2994 | #ifdef V8_ENABLE_CHECKS |
| 2995 | VerifyExternalStringResource(result); |
| 2996 | #endif |
| 2997 | return result; |
| 2998 | } |
| 2999 | |
| 3000 | |
| 3001 | bool Value::IsString() const { |
| 3002 | #ifdef V8_ENABLE_CHECKS |
| 3003 | return FullIsString(); |
| 3004 | #else |
| 3005 | return QuickIsString(); |
| 3006 | #endif |
| 3007 | } |
| 3008 | |
| 3009 | bool Value::QuickIsString() const { |
| 3010 | typedef internal::Object O; |
| 3011 | typedef internal::Internals I; |
| 3012 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 3013 | if (!I::HasHeapObjectTag(obj)) return false; |
| 3014 | O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); |
| 3015 | int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); |
| 3016 | return (instance_type < I::kFirstNonstringType); |
| 3017 | } |
| 3018 | |
| 3019 | |
| 3020 | Number* Number::Cast(v8::Value* value) { |
| 3021 | #ifdef V8_ENABLE_CHECKS |
| 3022 | CheckCast(value); |
| 3023 | #endif |
| 3024 | return static_cast<Number*>(value); |
| 3025 | } |
| 3026 | |
| 3027 | |
| 3028 | Integer* Integer::Cast(v8::Value* value) { |
| 3029 | #ifdef V8_ENABLE_CHECKS |
| 3030 | CheckCast(value); |
| 3031 | #endif |
| 3032 | return static_cast<Integer*>(value); |
| 3033 | } |
| 3034 | |
| 3035 | |
| 3036 | Date* Date::Cast(v8::Value* value) { |
| 3037 | #ifdef V8_ENABLE_CHECKS |
| 3038 | CheckCast(value); |
| 3039 | #endif |
| 3040 | return static_cast<Date*>(value); |
| 3041 | } |
| 3042 | |
| 3043 | |
| 3044 | Object* Object::Cast(v8::Value* value) { |
| 3045 | #ifdef V8_ENABLE_CHECKS |
| 3046 | CheckCast(value); |
| 3047 | #endif |
| 3048 | return static_cast<Object*>(value); |
| 3049 | } |
| 3050 | |
| 3051 | |
| 3052 | Array* Array::Cast(v8::Value* value) { |
| 3053 | #ifdef V8_ENABLE_CHECKS |
| 3054 | CheckCast(value); |
| 3055 | #endif |
| 3056 | return static_cast<Array*>(value); |
| 3057 | } |
| 3058 | |
| 3059 | |
| 3060 | Function* Function::Cast(v8::Value* value) { |
| 3061 | #ifdef V8_ENABLE_CHECKS |
| 3062 | CheckCast(value); |
| 3063 | #endif |
| 3064 | return static_cast<Function*>(value); |
| 3065 | } |
| 3066 | |
| 3067 | |
| 3068 | External* External::Cast(v8::Value* value) { |
| 3069 | #ifdef V8_ENABLE_CHECKS |
| 3070 | CheckCast(value); |
| 3071 | #endif |
| 3072 | return static_cast<External*>(value); |
| 3073 | } |
| 3074 | |
| 3075 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame^] | 3076 | Local<Value> AccessorInfo::Data() const { |
| 3077 | return Local<Value>(reinterpret_cast<Value*>(&args_[-3])); |
| 3078 | } |
| 3079 | |
| 3080 | |
| 3081 | Local<Object> AccessorInfo::This() const { |
| 3082 | return Local<Object>(reinterpret_cast<Object*>(&args_[0])); |
| 3083 | } |
| 3084 | |
| 3085 | |
| 3086 | Local<Object> AccessorInfo::Holder() const { |
| 3087 | return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); |
| 3088 | } |
| 3089 | |
| 3090 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3091 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3092 | * \example shell.cc |
| 3093 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3094 | * command-line and executes them. |
| 3095 | */ |
| 3096 | |
| 3097 | |
| 3098 | /** |
| 3099 | * \example process.cc |
| 3100 | */ |
| 3101 | |
| 3102 | |
| 3103 | } // namespace v8 |
| 3104 | |
| 3105 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3106 | #undef V8EXPORT |
| 3107 | #undef V8EXPORT_INLINE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3108 | #undef TYPE_CHECK |
| 3109 | |
| 3110 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3111 | #endif // V8_H_ |