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