sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1 | // Copyright 2011 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 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 41 | #include "v8stdint.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef _WIN32 |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 44 | |
| 45 | // Setup for Windows DLL export/import. When building the V8 DLL the |
| 46 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
| 47 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
| 48 | // static library or building a program which uses the V8 static library neither |
| 49 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 50 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
| 51 | #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ |
| 52 | build configuration to ensure that at most one of these is set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 55 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 56 | #define V8EXPORT __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 57 | #elif USING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 58 | #define V8EXPORT __declspec(dllimport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 59 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 60 | #define V8EXPORT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 61 | #endif // BUILDING_V8_SHARED |
| 62 | |
| 63 | #else // _WIN32 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 64 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 65 | // Setup for Linux shared library export. There is no need to distinguish |
| 66 | // between building or using the V8 shared library, but we should not |
| 67 | // export symbols when we are building a static library. |
| 68 | #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED) |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 69 | #define V8EXPORT __attribute__ ((visibility("default"))) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 70 | #else // defined(__GNUC__) && (__GNUC__ >= 4) |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 71 | #define V8EXPORT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 72 | #endif // defined(__GNUC__) && (__GNUC__ >= 4) |
| 73 | |
| 74 | #endif // _WIN32 |
| 75 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 77 | * The v8 JavaScript engine. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | */ |
| 79 | namespace v8 { |
| 80 | |
| 81 | class Context; |
| 82 | class String; |
| 83 | class Value; |
| 84 | class Utils; |
| 85 | class Number; |
| 86 | class Object; |
| 87 | class Array; |
| 88 | class Int32; |
| 89 | class Uint32; |
| 90 | class External; |
| 91 | class Primitive; |
| 92 | class Boolean; |
| 93 | class Integer; |
| 94 | class Function; |
| 95 | class Date; |
| 96 | class ImplementationUtilities; |
| 97 | class Signature; |
| 98 | template <class T> class Handle; |
| 99 | template <class T> class Local; |
| 100 | template <class T> class Persistent; |
| 101 | class FunctionTemplate; |
| 102 | class ObjectTemplate; |
| 103 | class Data; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 104 | class AccessorInfo; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 105 | class StackTrace; |
| 106 | class StackFrame; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 108 | namespace internal { |
| 109 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 110 | class Arguments; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 111 | class Object; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 112 | class Heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 113 | class HeapObject; |
| 114 | class Isolate; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 115 | } |
| 116 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 118 | // --- Weak Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | |
| 120 | |
| 121 | /** |
| 122 | * A weak reference callback function. |
| 123 | * |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 124 | * This callback should either explicitly invoke Dispose on |object| if |
| 125 | * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| 126 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | * \param object the weak global object to be reclaimed by the garbage collector |
| 128 | * \param parameter the value passed in when making the weak global object |
| 129 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 130 | typedef void (*WeakReferenceCallback)(Persistent<Value> object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | void* parameter); |
| 132 | |
| 133 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 134 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 136 | #define TYPE_CHECK(T, S) \ |
| 137 | while (false) { \ |
| 138 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * An object reference managed by the v8 garbage collector. |
| 143 | * |
| 144 | * All objects returned from v8 have to be tracked by the garbage |
| 145 | * collector so that it knows that the objects are still alive. Also, |
| 146 | * because the garbage collector may move objects, it is unsafe to |
| 147 | * point directly to an object. Instead, all objects are stored in |
| 148 | * handles which are known by the garbage collector and updated |
| 149 | * whenever an object moves. Handles should always be passed by value |
| 150 | * (except in cases like out-parameters) and they should never be |
| 151 | * allocated on the heap. |
| 152 | * |
| 153 | * There are two types of handles: local and persistent handles. |
| 154 | * Local handles are light-weight and transient and typically used in |
| 155 | * local operations. They are managed by HandleScopes. Persistent |
| 156 | * handles can be used when storing objects across several independent |
| 157 | * operations and have to be explicitly deallocated when they're no |
| 158 | * longer used. |
| 159 | * |
| 160 | * It is safe to extract the object stored in the handle by |
| 161 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 162 | * a Handle<Object>); the value will still be governed by a handle |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 163 | * behind the scenes and the same rules apply to these values as to |
| 164 | * their handles. |
| 165 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 166 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | public: |
| 168 | |
| 169 | /** |
| 170 | * Creates an empty handle. |
| 171 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 172 | inline Handle(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Creates a new handle for the specified value. |
| 176 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 177 | inline explicit Handle(T* val) : val_(val) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * Creates a handle for the contents of the specified handle. This |
| 181 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 182 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 184 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 185 | * between compatible handles, for instance assigning a |
| 186 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 187 | * because String is a subclass of Value. |
| 188 | */ |
| 189 | template <class S> inline Handle(Handle<S> that) |
| 190 | : val_(reinterpret_cast<T*>(*that)) { |
| 191 | /** |
| 192 | * This check fails when trying to convert between incompatible |
| 193 | * handles. For example, converting from a Handle<String> to a |
| 194 | * Handle<Number>. |
| 195 | */ |
| 196 | TYPE_CHECK(T, S); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Returns true if the handle is empty. |
| 201 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 202 | inline bool IsEmpty() const { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 204 | inline T* operator->() const { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 206 | inline T* operator*() const { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 210 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 211 | inline void Clear() { this->val_ = 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * Checks whether two handles are the same. |
| 215 | * Returns true if both are empty, or if the objects |
| 216 | * to which they refer are identical. |
| 217 | * The handles' references are not checked. |
| 218 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 219 | template <class S> inline bool operator==(Handle<S> that) const { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 220 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 221 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | if (a == 0) return b == 0; |
| 223 | if (b == 0) return false; |
| 224 | return *a == *b; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Checks whether two handles are different. |
| 229 | * Returns true if only one of the handles is empty, or if |
| 230 | * the objects to which they refer are different. |
| 231 | * The handles' references are not checked. |
| 232 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 233 | template <class S> inline bool operator!=(Handle<S> that) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 234 | return !operator==(that); |
| 235 | } |
| 236 | |
| 237 | template <class S> static inline Handle<T> Cast(Handle<S> that) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 238 | #ifdef V8_ENABLE_CHECKS |
| 239 | // If we're going to perform the type check then we have to check |
| 240 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 242 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | return Handle<T>(T::Cast(*that)); |
| 244 | } |
| 245 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 246 | template <class S> inline Handle<S> As() { |
| 247 | return Handle<S>::Cast(*this); |
| 248 | } |
| 249 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | private: |
| 251 | T* val_; |
| 252 | }; |
| 253 | |
| 254 | |
| 255 | /** |
| 256 | * A light-weight stack-allocated object handle. All operations |
| 257 | * that return objects from within v8 return them in local handles. They |
| 258 | * are created within HandleScopes, and all local handles allocated within a |
| 259 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 260 | * is not necessary to explicitly deallocate local handles. |
| 261 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 262 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | public: |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 264 | inline Local(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | template <class S> inline Local(Local<S> that) |
| 266 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 267 | /** |
| 268 | * This check fails when trying to convert between incompatible |
| 269 | * handles. For example, converting from a Handle<String> to a |
| 270 | * Handle<Number>. |
| 271 | */ |
| 272 | TYPE_CHECK(T, S); |
| 273 | } |
| 274 | template <class S> inline Local(S* that) : Handle<T>(that) { } |
| 275 | template <class S> static inline Local<T> Cast(Local<S> that) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 276 | #ifdef V8_ENABLE_CHECKS |
| 277 | // If we're going to perform the type check then we have to check |
| 278 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 280 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | return Local<T>(T::Cast(*that)); |
| 282 | } |
| 283 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 284 | template <class S> inline Local<S> As() { |
| 285 | return Local<S>::Cast(*this); |
| 286 | } |
| 287 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 288 | /** Create a local handle for the content of another handle. |
| 289 | * The referee is kept alive by the local handle even when |
| 290 | * the original handle is destroyed/disposed. |
| 291 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 292 | inline static Local<T> New(Handle<T> that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | |
| 296 | /** |
| 297 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 298 | * 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] | 299 | * allocated, a Persistent handle remains valid until it is explicitly |
| 300 | * disposed. |
| 301 | * |
| 302 | * A persistent handle contains a reference to a storage cell within |
| 303 | * the v8 engine which holds an object value and which is updated by |
| 304 | * the garbage collector whenever the object is moved. A new storage |
| 305 | * cell can be created using Persistent::New and existing handles can |
| 306 | * be disposed using Persistent::Dispose. Since persistent handles |
| 307 | * are passed by value you may have many persistent handle objects |
| 308 | * that point to the same storage cell. For instance, if you pass a |
| 309 | * persistent handle as an argument to a function you will not get two |
| 310 | * different storage cells but rather two references to the same |
| 311 | * storage cell. |
| 312 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 313 | template <class T> class Persistent : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | public: |
| 315 | |
| 316 | /** |
| 317 | * Creates an empty persistent handle that doesn't point to any |
| 318 | * storage cell. |
| 319 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 320 | inline Persistent(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 321 | |
| 322 | /** |
| 323 | * Creates a persistent handle for the same storage cell as the |
| 324 | * specified handle. This constructor allows you to pass persistent |
| 325 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 326 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 327 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 328 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 329 | * between compatible persistent handles, for instance assigning a |
| 330 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 331 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | */ |
| 333 | template <class S> inline Persistent(Persistent<S> that) |
| 334 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 335 | /** |
| 336 | * This check fails when trying to convert between incompatible |
| 337 | * handles. For example, converting from a Handle<String> to a |
| 338 | * Handle<Number>. |
| 339 | */ |
| 340 | TYPE_CHECK(T, S); |
| 341 | } |
| 342 | |
| 343 | template <class S> inline Persistent(S* that) : Handle<T>(that) { } |
| 344 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 345 | /** |
| 346 | * "Casts" a plain handle which is known to be a persistent handle |
| 347 | * to a persistent handle. |
| 348 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | template <class S> explicit inline Persistent(Handle<S> that) |
| 350 | : Handle<T>(*that) { } |
| 351 | |
| 352 | template <class S> static inline Persistent<T> Cast(Persistent<S> that) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 353 | #ifdef V8_ENABLE_CHECKS |
| 354 | // If we're going to perform the type check then we have to check |
| 355 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 356 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 357 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 358 | return Persistent<T>(T::Cast(*that)); |
| 359 | } |
| 360 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 361 | template <class S> inline Persistent<S> As() { |
| 362 | return Persistent<S>::Cast(*this); |
| 363 | } |
| 364 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 365 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 366 | * Creates a new persistent handle for an existing local or |
| 367 | * persistent handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 368 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 369 | inline static Persistent<T> New(Handle<T> that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 370 | |
| 371 | /** |
| 372 | * Releases the storage cell referenced by this persistent handle. |
| 373 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 374 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | * cell remain and IsEmpty will still return false. |
| 376 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 377 | inline void Dispose(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 378 | |
| 379 | /** |
| 380 | * Make the reference to this object weak. When only weak handles |
| 381 | * refer to the object, the garbage collector will perform a |
| 382 | * callback to the given V8::WeakReferenceCallback function, passing |
| 383 | * it the object reference and the given parameters. |
| 384 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 385 | inline void MakeWeak(void* parameters, WeakReferenceCallback callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 386 | |
| 387 | /** Clears the weak reference to this object.*/ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 388 | inline void ClearWeak(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 389 | |
| 390 | /** |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame^] | 391 | * Marks the reference to this object independent. Garbage collector |
| 392 | * is free to ignore any object groups containing this object. |
| 393 | * Weak callback for an independent handle should not |
| 394 | * assume that it will be preceded by a global GC prologue callback |
| 395 | * or followed by a global GC epilogue callback. |
| 396 | */ |
| 397 | inline void MarkIndependent(); |
| 398 | |
| 399 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 400 | *Checks if the handle holds the only reference to an object. |
| 401 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 402 | inline bool IsNearDeath() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 403 | |
| 404 | /** |
| 405 | * Returns true if the handle's reference is weak. |
| 406 | */ |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 407 | inline bool IsWeak() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 408 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 409 | /** |
| 410 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo |
| 411 | * interface description in v8-profiler.h for details. |
| 412 | */ |
| 413 | inline void SetWrapperClassId(uint16_t class_id); |
| 414 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 415 | private: |
| 416 | friend class ImplementationUtilities; |
| 417 | friend class ObjectTemplate; |
| 418 | }; |
| 419 | |
| 420 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 421 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 422 | * A stack-allocated class that governs a number of local handles. |
| 423 | * After a handle scope has been created, all local handles will be |
| 424 | * allocated within that handle scope until either the handle scope is |
| 425 | * deleted or another handle scope is created. If there is already a |
| 426 | * 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] | 427 | * 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] | 428 | * new handles will again be allocated in the original handle scope. |
| 429 | * |
| 430 | * After the handle scope of a local handle has been deleted the |
| 431 | * garbage collector will no longer track the object stored in the |
| 432 | * handle and may deallocate it. The behavior of accessing a handle |
| 433 | * for which the handle scope has been deleted is undefined. |
| 434 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 435 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 436 | public: |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 437 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 438 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 439 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 440 | |
| 441 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 442 | * Closes the handle scope and returns the value as a handle in the |
| 443 | * previous scope, which is the new current scope after the call. |
| 444 | */ |
| 445 | template <class T> Local<T> Close(Handle<T> value); |
| 446 | |
| 447 | /** |
| 448 | * Counts the number of allocated handles. |
| 449 | */ |
| 450 | static int NumberOfHandles(); |
| 451 | |
| 452 | /** |
| 453 | * Creates a new handle with the given value. |
| 454 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 455 | static internal::Object** CreateHandle(internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 456 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 457 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | |
| 459 | private: |
| 460 | // Make it impossible to create heap-allocated or illegal handle |
| 461 | // scopes by disallowing certain operations. |
| 462 | HandleScope(const HandleScope&); |
| 463 | void operator=(const HandleScope&); |
| 464 | void* operator new(size_t size); |
| 465 | void operator delete(void*, size_t); |
| 466 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 467 | // This Data class is accessible internally as HandleScopeData through a |
| 468 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 469 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 470 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 471 | internal::Object** next; |
| 472 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 473 | int level; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 474 | inline void Initialize() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 476 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | } |
| 478 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 479 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 480 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 481 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 482 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 483 | internal::Object** prev_next_; |
| 484 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 485 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 486 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 487 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 489 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | friend class ImplementationUtilities; |
| 492 | }; |
| 493 | |
| 494 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 495 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | |
| 497 | |
| 498 | /** |
| 499 | * The superclass of values and API object templates. |
| 500 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 501 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 502 | private: |
| 503 | Data(); |
| 504 | }; |
| 505 | |
| 506 | |
| 507 | /** |
| 508 | * Pre-compilation data that can be associated with a script. This |
| 509 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 510 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 511 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 512 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 513 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 514 | public: |
| 515 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 516 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 517 | /** |
| 518 | * Pre-compiles the specified script (context-independent). |
| 519 | * |
| 520 | * \param input Pointer to UTF-8 script source code. |
| 521 | * \param length Length of UTF-8 script source code. |
| 522 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 525 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 526 | * Pre-compiles the specified script (context-independent). |
| 527 | * |
| 528 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 529 | * without using Lockers. |
| 530 | * |
| 531 | * \param source Script source code. |
| 532 | */ |
| 533 | static ScriptData* PreCompile(Handle<String> source); |
| 534 | |
| 535 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 536 | * Load previous pre-compilation data. |
| 537 | * |
| 538 | * \param data Pointer to data returned by a call to Data() of a previous |
| 539 | * ScriptData. Ownership is not transferred. |
| 540 | * \param length Length of data. |
| 541 | */ |
| 542 | static ScriptData* New(const char* data, int length); |
| 543 | |
| 544 | /** |
| 545 | * Returns the length of Data(). |
| 546 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 548 | |
| 549 | /** |
| 550 | * Returns a serialized representation of this ScriptData that can later be |
| 551 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 552 | */ |
| 553 | virtual const char* Data() = 0; |
| 554 | |
| 555 | /** |
| 556 | * Returns true if the source code could not be parsed. |
| 557 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 558 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | }; |
| 560 | |
| 561 | |
| 562 | /** |
| 563 | * The origin, within a file, of a script. |
| 564 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 565 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 567 | inline ScriptOrigin( |
| 568 | Handle<Value> resource_name, |
| 569 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
| 570 | Handle<Integer> resource_column_offset = Handle<Integer>()) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | : resource_name_(resource_name), |
| 572 | resource_line_offset_(resource_line_offset), |
| 573 | resource_column_offset_(resource_column_offset) { } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 574 | inline Handle<Value> ResourceName() const; |
| 575 | inline Handle<Integer> ResourceLineOffset() const; |
| 576 | inline Handle<Integer> ResourceColumnOffset() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 577 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 578 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 579 | Handle<Integer> resource_line_offset_; |
| 580 | Handle<Integer> resource_column_offset_; |
| 581 | }; |
| 582 | |
| 583 | |
| 584 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 585 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 587 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | public: |
| 589 | |
| 590 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 591 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 592 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 593 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 594 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 595 | * when New() returns |
| 596 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 597 | * using pre_data speeds compilation if it's done multiple times. |
| 598 | * Owned by caller, no references are kept when New() returns. |
| 599 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 600 | * this has same effect as calling SetData(), but allows data to be |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 601 | * available to compile event handlers. |
| 602 | * \return Compiled script object (context independent; when run it |
| 603 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 605 | static Local<Script> New(Handle<String> source, |
| 606 | ScriptOrigin* origin = NULL, |
| 607 | ScriptData* pre_data = NULL, |
| 608 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 609 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 610 | /** |
| 611 | * Compiles the specified script using the specified file name |
| 612 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 613 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 614 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 615 | * \param file_name file name object (typically a string) to be used |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 616 | * as the script's origin. |
| 617 | * \return Compiled script object (context independent; when run it |
| 618 | * will use the currently entered context). |
| 619 | */ |
| 620 | static Local<Script> New(Handle<String> source, |
| 621 | Handle<Value> file_name); |
| 622 | |
| 623 | /** |
| 624 | * Compiles the specified script (bound to current context). |
| 625 | * |
| 626 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 627 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 628 | * when Compile() returns |
| 629 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 630 | * using pre_data speeds compilation if it's done multiple times. |
| 631 | * Owned by caller, no references are kept when Compile() returns. |
| 632 | * \param script_data Arbitrary data associated with script. Using |
| 633 | * this has same effect as calling SetData(), but makes data available |
| 634 | * earlier (i.e. to compile event handlers). |
| 635 | * \return Compiled script object, bound to the context that was active |
| 636 | * when this function was called. When run it will always use this |
| 637 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 638 | */ |
| 639 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 640 | ScriptOrigin* origin = NULL, |
| 641 | ScriptData* pre_data = NULL, |
| 642 | Handle<String> script_data = Handle<String>()); |
| 643 | |
| 644 | /** |
| 645 | * Compiles the specified script using the specified file name |
| 646 | * object (typically a string) as the script's origin. |
| 647 | * |
| 648 | * \param source Script source code. |
| 649 | * \param file_name File name to use as script's origin |
| 650 | * \param script_data Arbitrary data associated with script. Using |
| 651 | * this has same effect as calling SetData(), but makes data available |
| 652 | * earlier (i.e. to compile event handlers). |
| 653 | * \return Compiled script object, bound to the context that was active |
| 654 | * when this function was called. When run it will always use this |
| 655 | * context. |
| 656 | */ |
| 657 | static Local<Script> Compile(Handle<String> source, |
| 658 | Handle<Value> file_name, |
| 659 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 660 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 661 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 662 | * Runs the script returning the resulting value. If the script is |
| 663 | * context independent (created using ::New) it will be run in the |
| 664 | * currently entered context. If it is context specific (created |
| 665 | * using ::Compile) it will be run in the context in which it was |
| 666 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 667 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * Returns the script id value. |
| 672 | */ |
| 673 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 674 | |
| 675 | /** |
| 676 | * Associate an additional data object with the script. This is mainly used |
| 677 | * with the debugger as this data object is only available through the |
| 678 | * debugger API. |
| 679 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 680 | void SetData(Handle<String> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 681 | }; |
| 682 | |
| 683 | |
| 684 | /** |
| 685 | * An error message. |
| 686 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 687 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 688 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 689 | Local<String> Get() const; |
| 690 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 691 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 692 | /** |
| 693 | * Returns the resource name for the script from where the function causing |
| 694 | * the error originates. |
| 695 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 696 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 697 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 698 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 699 | * Returns the resource data for the script from where the function causing |
| 700 | * the error originates. |
| 701 | */ |
| 702 | Handle<Value> GetScriptData() const; |
| 703 | |
| 704 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 705 | * Exception stack trace. By default stack traces are not captured for |
| 706 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 707 | * to change this option. |
| 708 | */ |
| 709 | Handle<StackTrace> GetStackTrace() const; |
| 710 | |
| 711 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 712 | * Returns the number, 1-based, of the line where the error occurred. |
| 713 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 714 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 715 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 716 | /** |
| 717 | * Returns the index within the script of the first character where |
| 718 | * the error occurred. |
| 719 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 720 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 721 | |
| 722 | /** |
| 723 | * Returns the index within the script of the last character where |
| 724 | * the error occurred. |
| 725 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 726 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 727 | |
| 728 | /** |
| 729 | * Returns the index within the line of the first character where |
| 730 | * the error occurred. |
| 731 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 732 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 733 | |
| 734 | /** |
| 735 | * Returns the index within the line of the last character where |
| 736 | * the error occurred. |
| 737 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 738 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 739 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 740 | // TODO(1245381): Print to a string instead of on a FILE. |
| 741 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 742 | |
| 743 | static const int kNoLineNumberInfo = 0; |
| 744 | static const int kNoColumnInfo = 0; |
| 745 | }; |
| 746 | |
| 747 | |
| 748 | /** |
| 749 | * Representation of a JavaScript stack trace. The information collected is a |
| 750 | * snapshot of the execution stack and the information remains valid after |
| 751 | * execution continues. |
| 752 | */ |
| 753 | class V8EXPORT StackTrace { |
| 754 | public: |
| 755 | /** |
| 756 | * Flags that determine what information is placed captured for each |
| 757 | * StackFrame when grabbing the current stack trace. |
| 758 | */ |
| 759 | enum StackTraceOptions { |
| 760 | kLineNumber = 1, |
| 761 | kColumnOffset = 1 << 1 | kLineNumber, |
| 762 | kScriptName = 1 << 2, |
| 763 | kFunctionName = 1 << 3, |
| 764 | kIsEval = 1 << 4, |
| 765 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 766 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 767 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 768 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 769 | }; |
| 770 | |
| 771 | /** |
| 772 | * Returns a StackFrame at a particular index. |
| 773 | */ |
| 774 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 775 | |
| 776 | /** |
| 777 | * Returns the number of StackFrames. |
| 778 | */ |
| 779 | int GetFrameCount() const; |
| 780 | |
| 781 | /** |
| 782 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 783 | */ |
| 784 | Local<Array> AsArray(); |
| 785 | |
| 786 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 787 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 788 | * |
| 789 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 790 | * \param options Enumerates the set of things we will capture for each |
| 791 | * StackFrame. |
| 792 | */ |
| 793 | static Local<StackTrace> CurrentStackTrace( |
| 794 | int frame_limit, |
| 795 | StackTraceOptions options = kOverview); |
| 796 | }; |
| 797 | |
| 798 | |
| 799 | /** |
| 800 | * A single JavaScript stack frame. |
| 801 | */ |
| 802 | class V8EXPORT StackFrame { |
| 803 | public: |
| 804 | /** |
| 805 | * Returns the number, 1-based, of the line for the associate function call. |
| 806 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 807 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 808 | * when capturing the StackTrace. |
| 809 | */ |
| 810 | int GetLineNumber() const; |
| 811 | |
| 812 | /** |
| 813 | * Returns the 1-based column offset on the line for the associated function |
| 814 | * call. |
| 815 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 816 | * the column number, or if kColumnOffset was not passed as an option when |
| 817 | * capturing the StackTrace. |
| 818 | */ |
| 819 | int GetColumn() const; |
| 820 | |
| 821 | /** |
| 822 | * Returns the name of the resource that contains the script for the |
| 823 | * function for this StackFrame. |
| 824 | */ |
| 825 | Local<String> GetScriptName() const; |
| 826 | |
| 827 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 828 | * Returns the name of the resource that contains the script for the |
| 829 | * function for this StackFrame or sourceURL value if the script name |
| 830 | * is undefined and its source ends with //@ sourceURL=... string. |
| 831 | */ |
| 832 | Local<String> GetScriptNameOrSourceURL() const; |
| 833 | |
| 834 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 835 | * Returns the name of the function associated with this stack frame. |
| 836 | */ |
| 837 | Local<String> GetFunctionName() const; |
| 838 | |
| 839 | /** |
| 840 | * Returns whether or not the associated function is compiled via a call to |
| 841 | * eval(). |
| 842 | */ |
| 843 | bool IsEval() const; |
| 844 | |
| 845 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 846 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 847 | * constructor via "new". |
| 848 | */ |
| 849 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 850 | }; |
| 851 | |
| 852 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 853 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 854 | |
| 855 | |
| 856 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 857 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 859 | class Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | public: |
| 861 | |
| 862 | /** |
| 863 | * Returns true if this value is the undefined value. See ECMA-262 |
| 864 | * 4.3.10. |
| 865 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 866 | V8EXPORT bool IsUndefined() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | |
| 868 | /** |
| 869 | * Returns true if this value is the null value. See ECMA-262 |
| 870 | * 4.3.11. |
| 871 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 872 | V8EXPORT bool IsNull() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 873 | |
| 874 | /** |
| 875 | * Returns true if this value is true. |
| 876 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 877 | V8EXPORT bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | |
| 879 | /** |
| 880 | * Returns true if this value is false. |
| 881 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 882 | V8EXPORT bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 883 | |
| 884 | /** |
| 885 | * Returns true if this value is an instance of the String type. |
| 886 | * See ECMA-262 8.4. |
| 887 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 888 | inline bool IsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | |
| 890 | /** |
| 891 | * Returns true if this value is a function. |
| 892 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 893 | V8EXPORT bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 894 | |
| 895 | /** |
| 896 | * Returns true if this value is an array. |
| 897 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 898 | V8EXPORT bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 899 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 900 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 901 | * Returns true if this value is an object. |
| 902 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 903 | V8EXPORT bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 904 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 905 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 906 | * Returns true if this value is boolean. |
| 907 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 908 | V8EXPORT bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 909 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 910 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | * Returns true if this value is a number. |
| 912 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 913 | V8EXPORT bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 914 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 915 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 916 | * Returns true if this value is external. |
| 917 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 918 | V8EXPORT bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 919 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 920 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | * Returns true if this value is a 32-bit signed integer. |
| 922 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 923 | V8EXPORT bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 925 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 926 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 927 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 928 | V8EXPORT bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 929 | |
| 930 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 931 | * Returns true if this value is a Date. |
| 932 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 933 | V8EXPORT bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 934 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 935 | /** |
| 936 | * Returns true if this value is a RegExp. |
| 937 | */ |
| 938 | V8EXPORT bool IsRegExp() const; |
| 939 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 940 | V8EXPORT Local<Boolean> ToBoolean() const; |
| 941 | V8EXPORT Local<Number> ToNumber() const; |
| 942 | V8EXPORT Local<String> ToString() const; |
| 943 | V8EXPORT Local<String> ToDetailString() const; |
| 944 | V8EXPORT Local<Object> ToObject() const; |
| 945 | V8EXPORT Local<Integer> ToInteger() const; |
| 946 | V8EXPORT Local<Uint32> ToUint32() const; |
| 947 | V8EXPORT Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 948 | |
| 949 | /** |
| 950 | * Attempts to convert a string to an array index. |
| 951 | * Returns an empty handle if the conversion fails. |
| 952 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 953 | V8EXPORT Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 954 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 955 | V8EXPORT bool BooleanValue() const; |
| 956 | V8EXPORT double NumberValue() const; |
| 957 | V8EXPORT int64_t IntegerValue() const; |
| 958 | V8EXPORT uint32_t Uint32Value() const; |
| 959 | V8EXPORT int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 960 | |
| 961 | /** JS == */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 962 | V8EXPORT bool Equals(Handle<Value> that) const; |
| 963 | V8EXPORT bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 964 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 965 | private: |
| 966 | inline bool QuickIsString() const; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 967 | V8EXPORT bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 968 | }; |
| 969 | |
| 970 | |
| 971 | /** |
| 972 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 973 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 974 | class Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 975 | |
| 976 | |
| 977 | /** |
| 978 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 979 | * or false value. |
| 980 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 981 | class Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 982 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 983 | V8EXPORT bool Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 984 | static inline Handle<Boolean> New(bool value); |
| 985 | }; |
| 986 | |
| 987 | |
| 988 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 989 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 991 | class String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 992 | public: |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 993 | |
| 994 | /** |
| 995 | * Returns the number of characters in this string. |
| 996 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 997 | V8EXPORT int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 998 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 999 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1000 | * Returns the number of bytes in the UTF-8 encoded |
| 1001 | * representation of this string. |
| 1002 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1003 | V8EXPORT int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1004 | |
| 1005 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1006 | * Write the contents of the string to an external buffer. |
| 1007 | * If no arguments are given, expects the buffer to be large |
| 1008 | * enough to hold the entire string and NULL terminator. Copies |
| 1009 | * the contents of the string and the NULL terminator into the |
| 1010 | * buffer. |
| 1011 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1012 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1013 | * before the end of the buffer. |
| 1014 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1015 | * Copies up to length characters into the output buffer. |
| 1016 | * Only null-terminates if there is enough space in the buffer. |
| 1017 | * |
| 1018 | * \param buffer The buffer into which the string will be copied. |
| 1019 | * \param start The starting position within the string at which |
| 1020 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1021 | * \param length The number of characters to copy from the string. For |
| 1022 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1023 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1024 | * \param hints Various hints that might affect performance of this or |
| 1025 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1026 | * \return The number of characters copied to the buffer excluding the null |
| 1027 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
| 1028 | * including the null terminator. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1029 | */ |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1030 | enum WriteHints { |
| 1031 | NO_HINTS = 0, |
| 1032 | HINT_MANY_WRITES_EXPECTED = 1 |
| 1033 | }; |
| 1034 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1035 | V8EXPORT int Write(uint16_t* buffer, |
| 1036 | int start = 0, |
| 1037 | int length = -1, |
| 1038 | WriteHints hints = NO_HINTS) const; // UTF-16 |
| 1039 | V8EXPORT int WriteAscii(char* buffer, |
| 1040 | int start = 0, |
| 1041 | int length = -1, |
| 1042 | WriteHints hints = NO_HINTS) const; // ASCII |
| 1043 | V8EXPORT int WriteUtf8(char* buffer, |
| 1044 | int length = -1, |
| 1045 | int* nchars_ref = NULL, |
| 1046 | WriteHints hints = NO_HINTS) const; // UTF-8 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1047 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1048 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1049 | * A zero length string. |
| 1050 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1051 | V8EXPORT static v8::Local<v8::String> Empty(); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1052 | |
| 1053 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1054 | * Returns true if the string is external |
| 1055 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1056 | V8EXPORT bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1057 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1058 | /** |
| 1059 | * Returns true if the string is both external and ascii |
| 1060 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1061 | V8EXPORT bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1062 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1063 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1064 | public: |
| 1065 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1066 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1067 | protected: |
| 1068 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1069 | |
| 1070 | /** |
| 1071 | * Internally V8 will call this Dispose method when the external string |
| 1072 | * resource is no longer needed. The default implementation will use the |
| 1073 | * delete operator. This method can be overridden in subclasses to |
| 1074 | * control how allocated external string resources are disposed. |
| 1075 | */ |
| 1076 | virtual void Dispose() { delete this; } |
| 1077 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1078 | private: |
| 1079 | // Disallow copying and assigning. |
| 1080 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1081 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1082 | |
| 1083 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1084 | }; |
| 1085 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1086 | /** |
| 1087 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1088 | * buffer that resides outside V8's heap. Implement an |
| 1089 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1090 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1091 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1092 | class V8EXPORT ExternalStringResource |
| 1093 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1094 | public: |
| 1095 | /** |
| 1096 | * Override the destructor to manage the life cycle of the underlying |
| 1097 | * buffer. |
| 1098 | */ |
| 1099 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1100 | |
| 1101 | /** |
| 1102 | * The string data from the underlying buffer. |
| 1103 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1104 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1105 | |
| 1106 | /** |
| 1107 | * The length of the string. That is, the number of two-byte characters. |
| 1108 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1109 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1110 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1111 | protected: |
| 1112 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1113 | }; |
| 1114 | |
| 1115 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1116 | * An ExternalAsciiStringResource is a wrapper around an ascii |
| 1117 | * string buffer that resides outside V8's heap. Implement an |
| 1118 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1119 | * underlying buffer. Note that the string data must be immutable |
| 1120 | * and that the data must be strict 7-bit ASCII, not Latin1 or |
| 1121 | * UTF-8, which would require special treatment internally in the |
| 1122 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1123 | * 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] | 1124 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1125 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1126 | class V8EXPORT ExternalAsciiStringResource |
| 1127 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1128 | public: |
| 1129 | /** |
| 1130 | * Override the destructor to manage the life cycle of the underlying |
| 1131 | * buffer. |
| 1132 | */ |
| 1133 | virtual ~ExternalAsciiStringResource() {} |
| 1134 | /** The string data from the underlying buffer.*/ |
| 1135 | virtual const char* data() const = 0; |
| 1136 | /** The number of ascii characters in the string.*/ |
| 1137 | virtual size_t length() const = 0; |
| 1138 | protected: |
| 1139 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1140 | }; |
| 1141 | |
| 1142 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1143 | * Get the ExternalStringResource for an external string. Returns |
| 1144 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1145 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1146 | inline ExternalStringResource* GetExternalStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1147 | |
| 1148 | /** |
| 1149 | * Get the ExternalAsciiStringResource for an external ascii string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1150 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1151 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1152 | V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1153 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1154 | static inline String* Cast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1155 | |
| 1156 | /** |
| 1157 | * Allocates a new string from either utf-8 encoded or ascii data. |
| 1158 | * The second parameter 'length' gives the buffer length. |
| 1159 | * If the data is utf-8 encoded, the caller must |
| 1160 | * be careful to supply the length parameter. |
| 1161 | * If it is not given, the function calls |
| 1162 | * 'strlen' to determine the buffer length, it might be |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1163 | * wrong if 'data' contains a null character. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1164 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1165 | V8EXPORT static Local<String> New(const char* data, int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1166 | |
| 1167 | /** Allocates a new string from utf16 data.*/ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1168 | V8EXPORT static Local<String> New(const uint16_t* data, int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1169 | |
| 1170 | /** Creates a symbol. Returns one if it exists already.*/ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1171 | V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1172 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1173 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1174 | * Creates a new string by concatenating the left and the right strings |
| 1175 | * passed in as parameters. |
| 1176 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1177 | V8EXPORT static Local<String> Concat(Handle<String> left, |
| 1178 | Handle<String>right); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1179 | |
| 1180 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1181 | * Creates a new external string using the data defined in the given |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1182 | * resource. When the external string is no longer live on V8's heap the |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1183 | * resource will be disposed by calling its Dispose method. The caller of |
| 1184 | * this function should not otherwise delete or modify the resource. Neither |
| 1185 | * should the underlying buffer be deallocated or modified except through the |
| 1186 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1187 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1188 | V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1189 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1190 | /** |
| 1191 | * Associate an external string resource with this string by transforming it |
| 1192 | * in place so that existing references to this string in the JavaScript heap |
| 1193 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1194 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1195 | * Returns true if the string has been changed to be an external string. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1196 | * The string is not modified if the operation fails. See NewExternal for |
| 1197 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1198 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1199 | V8EXPORT bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1200 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1201 | /** |
| 1202 | * Creates a new external string using the ascii data defined in the given |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1203 | * resource. When the external string is no longer live on V8's heap the |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1204 | * resource will be disposed by calling its Dispose method. The caller of |
| 1205 | * this function should not otherwise delete or modify the resource. Neither |
| 1206 | * should the underlying buffer be deallocated or modified except through the |
| 1207 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1208 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1209 | V8EXPORT static Local<String> NewExternal( |
| 1210 | ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1211 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1212 | /** |
| 1213 | * Associate an external string resource with this string by transforming it |
| 1214 | * in place so that existing references to this string in the JavaScript heap |
| 1215 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1216 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1217 | * Returns true if the string has been changed to be an external string. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1218 | * The string is not modified if the operation fails. See NewExternal for |
| 1219 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1220 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1221 | V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1222 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1223 | /** |
| 1224 | * Returns true if this string can be made external. |
| 1225 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1226 | V8EXPORT bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1227 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1228 | /** Creates an undetectable string from the supplied ascii or utf-8 data.*/ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1229 | V8EXPORT static Local<String> NewUndetectable(const char* data, |
| 1230 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1231 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1232 | /** Creates an undetectable string from the supplied utf-16 data.*/ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1233 | V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, |
| 1234 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1235 | |
| 1236 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1237 | * Converts an object to a utf8-encoded character array. Useful if |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1238 | * you want to print the object. If conversion to a string fails |
| 1239 | * (eg. due to an exception in the toString() method of the object) |
| 1240 | * then the length() method returns 0 and the * operator returns |
| 1241 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1242 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1243 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1244 | public: |
| 1245 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1246 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1247 | char* operator*() { return str_; } |
| 1248 | const char* operator*() const { return str_; } |
| 1249 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1250 | private: |
| 1251 | char* str_; |
| 1252 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1253 | |
| 1254 | // Disallow copying and assigning. |
| 1255 | Utf8Value(const Utf8Value&); |
| 1256 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1257 | }; |
| 1258 | |
| 1259 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1260 | * Converts an object to an ascii string. |
| 1261 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1262 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1263 | * method of the object) then the length() method returns 0 and the * operator |
| 1264 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1265 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1266 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1267 | public: |
| 1268 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1269 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1270 | char* operator*() { return str_; } |
| 1271 | const char* operator*() const { return str_; } |
| 1272 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1273 | private: |
| 1274 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1275 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1276 | |
| 1277 | // Disallow copying and assigning. |
| 1278 | AsciiValue(const AsciiValue&); |
| 1279 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1280 | }; |
| 1281 | |
| 1282 | /** |
| 1283 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1284 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1285 | * method of the object) then the length() method returns 0 and the * operator |
| 1286 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1287 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1288 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1289 | public: |
| 1290 | explicit Value(Handle<v8::Value> obj); |
| 1291 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1292 | uint16_t* operator*() { return str_; } |
| 1293 | const uint16_t* operator*() const { return str_; } |
| 1294 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1295 | private: |
| 1296 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1297 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1298 | |
| 1299 | // Disallow copying and assigning. |
| 1300 | Value(const Value&); |
| 1301 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1302 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1303 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1304 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1305 | V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1306 | V8EXPORT static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | }; |
| 1308 | |
| 1309 | |
| 1310 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1311 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1312 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1313 | class Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1315 | V8EXPORT double Value() const; |
| 1316 | V8EXPORT static Local<Number> New(double value); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1317 | static inline Number* Cast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1318 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1319 | V8EXPORT Number(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1320 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1321 | }; |
| 1322 | |
| 1323 | |
| 1324 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1325 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1326 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1327 | class Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1328 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1329 | V8EXPORT static Local<Integer> New(int32_t value); |
| 1330 | V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1331 | V8EXPORT int64_t Value() const; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1332 | static inline Integer* Cast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1333 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1334 | V8EXPORT Integer(); |
| 1335 | V8EXPORT static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1336 | }; |
| 1337 | |
| 1338 | |
| 1339 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1340 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1341 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1342 | class Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1343 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1344 | V8EXPORT int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1345 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1346 | V8EXPORT Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1347 | }; |
| 1348 | |
| 1349 | |
| 1350 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1351 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1353 | class Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1354 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1355 | V8EXPORT uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1356 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1357 | V8EXPORT Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1358 | }; |
| 1359 | |
| 1360 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1361 | enum PropertyAttribute { |
| 1362 | None = 0, |
| 1363 | ReadOnly = 1 << 0, |
| 1364 | DontEnum = 1 << 1, |
| 1365 | DontDelete = 1 << 2 |
| 1366 | }; |
| 1367 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1368 | enum ExternalArrayType { |
| 1369 | kExternalByteArray = 1, |
| 1370 | kExternalUnsignedByteArray, |
| 1371 | kExternalShortArray, |
| 1372 | kExternalUnsignedShortArray, |
| 1373 | kExternalIntArray, |
| 1374 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1375 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1376 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1377 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1378 | }; |
| 1379 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1380 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1381 | * Accessor[Getter|Setter] are used as callback functions when |
| 1382 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1383 | * method SetAccessor. |
| 1384 | */ |
| 1385 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1386 | const AccessorInfo& info); |
| 1387 | |
| 1388 | |
| 1389 | typedef void (*AccessorSetter)(Local<String> property, |
| 1390 | Local<Value> value, |
| 1391 | const AccessorInfo& info); |
| 1392 | |
| 1393 | |
| 1394 | /** |
| 1395 | * Access control specifications. |
| 1396 | * |
| 1397 | * Some accessors should be accessible across contexts. These |
| 1398 | * accessors have an explicit access control parameter which specifies |
| 1399 | * the kind of cross-context access that should be allowed. |
| 1400 | * |
| 1401 | * Additionally, for security, accessors can prohibit overwriting by |
| 1402 | * accessors defined in JavaScript. For objects that have such |
| 1403 | * accessors either locally or in their prototype chain it is not |
| 1404 | * possible to overwrite the accessor by using __defineGetter__ or |
| 1405 | * __defineSetter__ from JavaScript code. |
| 1406 | */ |
| 1407 | enum AccessControl { |
| 1408 | DEFAULT = 0, |
| 1409 | ALL_CAN_READ = 1, |
| 1410 | ALL_CAN_WRITE = 1 << 1, |
| 1411 | PROHIBITS_OVERWRITING = 1 << 2 |
| 1412 | }; |
| 1413 | |
| 1414 | |
| 1415 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1416 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1417 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1418 | class Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1419 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1420 | V8EXPORT bool Set(Handle<Value> key, |
| 1421 | Handle<Value> value, |
| 1422 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1423 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1424 | V8EXPORT bool Set(uint32_t index, |
| 1425 | Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1426 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1427 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1428 | // overriding accessors or read-only properties. |
| 1429 | // |
| 1430 | // Note that if the object has an interceptor the property will be set |
| 1431 | // locally, but since the interceptor takes precedence the local property |
| 1432 | // will only be returned if the interceptor doesn't return a value. |
| 1433 | // |
| 1434 | // Note also that this only works for named properties. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1435 | V8EXPORT bool ForceSet(Handle<Value> key, |
| 1436 | Handle<Value> value, |
| 1437 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1438 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1439 | V8EXPORT Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1440 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1441 | V8EXPORT Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1442 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1443 | // TODO(1245389): Replace the type-specific versions of these |
| 1444 | // functions with generic ones that accept a Handle<Value> key. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1445 | V8EXPORT bool Has(Handle<String> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1446 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1447 | V8EXPORT bool Delete(Handle<String> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1448 | |
| 1449 | // Delete a property on this object bypassing interceptors and |
| 1450 | // ignoring dont-delete attributes. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1451 | V8EXPORT bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1452 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1453 | V8EXPORT bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1454 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1455 | V8EXPORT bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1457 | V8EXPORT bool SetAccessor(Handle<String> name, |
| 1458 | AccessorGetter getter, |
| 1459 | AccessorSetter setter = 0, |
| 1460 | Handle<Value> data = Handle<Value>(), |
| 1461 | AccessControl settings = DEFAULT, |
| 1462 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1463 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1464 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1465 | * Returns an array containing the names of the enumerable properties |
| 1466 | * of this object, including properties from prototype objects. The |
| 1467 | * array returned by this method contains the same values as would |
| 1468 | * be enumerated by a for-in statement over this object. |
| 1469 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1470 | V8EXPORT Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1471 | |
| 1472 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1473 | * Get the prototype object. This does not skip objects marked to |
| 1474 | * be skipped by __proto__ and it does not consult the security |
| 1475 | * handler. |
| 1476 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1477 | V8EXPORT Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1478 | |
| 1479 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1480 | * Set the prototype object. This does not skip objects marked to |
| 1481 | * be skipped by __proto__ and it does not consult the security |
| 1482 | * handler. |
| 1483 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1484 | V8EXPORT bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1485 | |
| 1486 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 1487 | * Finds an instance of the given function template in the prototype |
| 1488 | * chain. |
| 1489 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1490 | V8EXPORT Local<Object> FindInstanceInPrototypeChain( |
| 1491 | Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 1492 | |
| 1493 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1494 | * Call builtin Object.prototype.toString on this object. |
| 1495 | * This is different from Value::ToString() that may call |
| 1496 | * user-defined toString function. This one does not. |
| 1497 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1498 | V8EXPORT Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1499 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 1500 | /** |
| 1501 | * Returns the name of the function invoked as a constructor for this object. |
| 1502 | */ |
| 1503 | V8EXPORT Local<String> GetConstructorName(); |
| 1504 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1505 | /** Gets the number of internal fields for this Object. */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1506 | V8EXPORT int InternalFieldCount(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1507 | /** Gets the value in an internal field. */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1508 | inline Local<Value> GetInternalField(int index); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1509 | /** Sets the value in an internal field. */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1510 | V8EXPORT void SetInternalField(int index, Handle<Value> value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1511 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1512 | /** Gets a native pointer from an internal field. */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1513 | inline void* GetPointerFromInternalField(int index); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1514 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1515 | /** Sets a native pointer in an internal field. */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1516 | V8EXPORT void SetPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1517 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1518 | // Testers for local properties. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1519 | V8EXPORT bool HasOwnProperty(Handle<String> key); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1520 | V8EXPORT bool HasRealNamedProperty(Handle<String> key); |
| 1521 | V8EXPORT bool HasRealIndexedProperty(uint32_t index); |
| 1522 | V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1523 | |
| 1524 | /** |
| 1525 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 1526 | * This means interceptors in the prototype chain are not called. |
| 1527 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1528 | V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain( |
| 1529 | Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 1530 | |
| 1531 | /** |
| 1532 | * If result.IsEmpty() no real property was located on the object or |
| 1533 | * in the prototype chain. |
| 1534 | * This means interceptors in the prototype chain are not called. |
| 1535 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1536 | V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1537 | |
| 1538 | /** Tests for a named lookup interceptor.*/ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1539 | V8EXPORT bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1540 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1541 | /** Tests for an index lookup interceptor.*/ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1542 | V8EXPORT bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1543 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1544 | /** |
| 1545 | * Turns on access check on the object if the object is an instance of |
| 1546 | * a template that has access check callbacks. If an object has no |
| 1547 | * access check info, the object cannot be accessed by anyone. |
| 1548 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1549 | V8EXPORT void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 1550 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1551 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1552 | * Returns the identity hash for this object. The current implementation |
| 1553 | * uses a hidden property on the object to store the identity hash. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1554 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1555 | * The return value will never be 0. Also, it is not guaranteed to be |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1556 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1557 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1558 | V8EXPORT int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 1559 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1560 | /** |
| 1561 | * Access hidden properties on JavaScript objects. These properties are |
| 1562 | * hidden from the executing JavaScript and only accessible through the V8 |
| 1563 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 1564 | * identity hash) are prefixed with "v8::". |
| 1565 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1566 | V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 1567 | V8EXPORT Local<Value> GetHiddenValue(Handle<String> key); |
| 1568 | V8EXPORT bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1569 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1570 | /** |
| 1571 | * Returns true if this is an instance of an api function (one |
| 1572 | * created from a function created from a function template) and has |
| 1573 | * been modified since it was created. Note that this method is |
| 1574 | * conservative and may return true for objects that haven't actually |
| 1575 | * been modified. |
| 1576 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1577 | V8EXPORT bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1578 | |
| 1579 | /** |
| 1580 | * Clone this object with a fast but shallow copy. Values will point |
| 1581 | * to the same values as the original object. |
| 1582 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1583 | V8EXPORT Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1584 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1585 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1586 | * Returns the context in which the object was created. |
| 1587 | */ |
| 1588 | V8EXPORT Local<Context> CreationContext(); |
| 1589 | |
| 1590 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1591 | * Set the backing store of the indexed properties to be managed by the |
| 1592 | * embedding layer. Access to the indexed properties will follow the rules |
| 1593 | * spelled out in CanvasPixelArray. |
| 1594 | * Note: The embedding program still owns the data and needs to ensure that |
| 1595 | * the backing store is preserved while V8 has a reference. |
| 1596 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1597 | V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1598 | V8EXPORT bool HasIndexedPropertiesInPixelData(); |
| 1599 | V8EXPORT uint8_t* GetIndexedPropertiesPixelData(); |
| 1600 | V8EXPORT int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1601 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1602 | /** |
| 1603 | * Set the backing store of the indexed properties to be managed by the |
| 1604 | * embedding layer. Access to the indexed properties will follow the rules |
| 1605 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 1606 | * Note: The embedding program still owns the data and needs to ensure that |
| 1607 | * the backing store is preserved while V8 has a reference. |
| 1608 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1609 | V8EXPORT void SetIndexedPropertiesToExternalArrayData( |
| 1610 | void* data, |
| 1611 | ExternalArrayType array_type, |
| 1612 | int number_of_elements); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1613 | V8EXPORT bool HasIndexedPropertiesInExternalArrayData(); |
| 1614 | V8EXPORT void* GetIndexedPropertiesExternalArrayData(); |
| 1615 | V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 1616 | V8EXPORT int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1617 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1618 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1619 | * Checks whether a callback is set by the |
| 1620 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1621 | * When an Object is callable this method returns true. |
| 1622 | */ |
| 1623 | V8EXPORT bool IsCallable(); |
| 1624 | |
| 1625 | /** |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1626 | * Call an Object as a function if a callback is set by the |
| 1627 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1628 | */ |
| 1629 | V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv, |
| 1630 | int argc, |
| 1631 | Handle<Value> argv[]); |
| 1632 | |
| 1633 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1634 | * Call an Object as a constructor if a callback is set by the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1635 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1636 | * Note: This method behaves like the Function::NewInstance method. |
| 1637 | */ |
| 1638 | V8EXPORT Local<Value> CallAsConstructor(int argc, |
| 1639 | Handle<Value> argv[]); |
| 1640 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1641 | V8EXPORT static Local<Object> New(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1642 | static inline Object* Cast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1643 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1644 | V8EXPORT Object(); |
| 1645 | V8EXPORT static void CheckCast(Value* obj); |
| 1646 | V8EXPORT Local<Value> CheckedGetInternalField(int index); |
| 1647 | V8EXPORT void* SlowGetPointerFromInternalField(int index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1648 | |
| 1649 | /** |
| 1650 | * If quick access to the internal field is possible this method |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1651 | * returns the value. Otherwise an empty handle is returned. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1652 | */ |
| 1653 | inline Local<Value> UncheckedGetInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1654 | }; |
| 1655 | |
| 1656 | |
| 1657 | /** |
| 1658 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 1659 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1660 | class Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1662 | V8EXPORT uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1663 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1664 | /** |
| 1665 | * Clones an element at index |index|. Returns an empty |
| 1666 | * handle if cloning fails (for any reason). |
| 1667 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1668 | V8EXPORT Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1669 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1670 | /** |
| 1671 | * Creates a JavaScript array with the given length. If the length |
| 1672 | * is negative the returned array will have length 0. |
| 1673 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1674 | V8EXPORT static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1675 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1676 | static inline Array* Cast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1677 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1678 | V8EXPORT Array(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1679 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1680 | }; |
| 1681 | |
| 1682 | |
| 1683 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1684 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1685 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1686 | class Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1687 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1688 | V8EXPORT Local<Object> NewInstance() const; |
| 1689 | V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 1690 | V8EXPORT Local<Value> Call(Handle<Object> recv, |
| 1691 | int argc, |
| 1692 | Handle<Value> argv[]); |
| 1693 | V8EXPORT void SetName(Handle<String> name); |
| 1694 | V8EXPORT Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1695 | |
| 1696 | /** |
| 1697 | * Returns zero based line number of function body and |
| 1698 | * kLineOffsetNotFound if no information available. |
| 1699 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1700 | V8EXPORT int GetScriptLineNumber() const; |
| 1701 | V8EXPORT ScriptOrigin GetScriptOrigin() const; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1702 | static inline Function* Cast(Value* obj); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1703 | V8EXPORT static const int kLineOffsetNotFound; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1704 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1705 | V8EXPORT Function(); |
| 1706 | V8EXPORT static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1707 | }; |
| 1708 | |
| 1709 | |
| 1710 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1711 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 1712 | */ |
| 1713 | class Date : public Object { |
| 1714 | public: |
| 1715 | V8EXPORT static Local<Value> New(double time); |
| 1716 | |
| 1717 | /** |
| 1718 | * A specialization of Value::NumberValue that is more efficient |
| 1719 | * because we know the structure of this object. |
| 1720 | */ |
| 1721 | V8EXPORT double NumberValue() const; |
| 1722 | |
| 1723 | static inline Date* Cast(v8::Value* obj); |
| 1724 | |
| 1725 | /** |
| 1726 | * Notification that the embedder has changed the time zone, |
| 1727 | * daylight savings time, or other date / time configuration |
| 1728 | * parameters. V8 keeps a cache of various values used for |
| 1729 | * date / time computation. This notification will reset |
| 1730 | * those cached values for the current context so that date / |
| 1731 | * time configuration changes would be reflected in the Date |
| 1732 | * object. |
| 1733 | * |
| 1734 | * This API should not be called more than needed as it will |
| 1735 | * negatively impact the performance of date operations. |
| 1736 | */ |
| 1737 | V8EXPORT static void DateTimeConfigurationChangeNotification(); |
| 1738 | |
| 1739 | private: |
| 1740 | V8EXPORT static void CheckCast(v8::Value* obj); |
| 1741 | }; |
| 1742 | |
| 1743 | |
| 1744 | /** |
| 1745 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 1746 | */ |
| 1747 | class RegExp : public Object { |
| 1748 | public: |
| 1749 | /** |
| 1750 | * Regular expression flag bits. They can be or'ed to enable a set |
| 1751 | * of flags. |
| 1752 | */ |
| 1753 | enum Flags { |
| 1754 | kNone = 0, |
| 1755 | kGlobal = 1, |
| 1756 | kIgnoreCase = 2, |
| 1757 | kMultiline = 4 |
| 1758 | }; |
| 1759 | |
| 1760 | /** |
| 1761 | * Creates a regular expression from the given pattern string and |
| 1762 | * the flags bit field. May throw a JavaScript exception as |
| 1763 | * described in ECMA-262, 15.10.4.1. |
| 1764 | * |
| 1765 | * For example, |
| 1766 | * RegExp::New(v8::String::New("foo"), |
| 1767 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 1768 | * is equivalent to evaluating "/foo/gm". |
| 1769 | */ |
| 1770 | V8EXPORT static Local<RegExp> New(Handle<String> pattern, |
| 1771 | Flags flags); |
| 1772 | |
| 1773 | /** |
| 1774 | * Returns the value of the source property: a string representing |
| 1775 | * the regular expression. |
| 1776 | */ |
| 1777 | V8EXPORT Local<String> GetSource() const; |
| 1778 | |
| 1779 | /** |
| 1780 | * Returns the flags bit field. |
| 1781 | */ |
| 1782 | V8EXPORT Flags GetFlags() const; |
| 1783 | |
| 1784 | static inline RegExp* Cast(v8::Value* obj); |
| 1785 | |
| 1786 | private: |
| 1787 | V8EXPORT static void CheckCast(v8::Value* obj); |
| 1788 | }; |
| 1789 | |
| 1790 | |
| 1791 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1792 | * A JavaScript value that wraps a C++ void*. This type of value is |
| 1793 | * mainly used to associate C++ data structures with JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1794 | * objects. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1795 | * |
| 1796 | * The Wrap function V8 will return the most optimal Value object wrapping the |
| 1797 | * C++ void*. The type of the value is not guaranteed to be an External object |
| 1798 | * and no assumptions about its type should be made. To access the wrapped |
| 1799 | * value Unwrap should be used, all other operations on that object will lead |
| 1800 | * to unpredictable results. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1801 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1802 | class External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1803 | public: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1804 | V8EXPORT static Local<Value> Wrap(void* data); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1805 | static inline void* Unwrap(Handle<Value> obj); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1806 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1807 | V8EXPORT static Local<External> New(void* value); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1808 | static inline External* Cast(Value* obj); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1809 | V8EXPORT void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1810 | private: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1811 | V8EXPORT External(); |
| 1812 | V8EXPORT static void CheckCast(v8::Value* obj); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1813 | static inline void* QuickUnwrap(Handle<v8::Value> obj); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1814 | V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1815 | }; |
| 1816 | |
| 1817 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1818 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1819 | |
| 1820 | |
| 1821 | /** |
| 1822 | * The superclass of object and function templates. |
| 1823 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1824 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1825 | public: |
| 1826 | /** Adds a property to each instance created by this template.*/ |
| 1827 | void Set(Handle<String> name, Handle<Data> value, |
| 1828 | PropertyAttribute attributes = None); |
| 1829 | inline void Set(const char* name, Handle<Data> value); |
| 1830 | private: |
| 1831 | Template(); |
| 1832 | |
| 1833 | friend class ObjectTemplate; |
| 1834 | friend class FunctionTemplate; |
| 1835 | }; |
| 1836 | |
| 1837 | |
| 1838 | /** |
| 1839 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1840 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1841 | * including the receiver, the number and values of arguments, and |
| 1842 | * the holder of the function. |
| 1843 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1844 | class Arguments { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1845 | public: |
| 1846 | inline int Length() const; |
| 1847 | inline Local<Value> operator[](int i) const; |
| 1848 | inline Local<Function> Callee() const; |
| 1849 | inline Local<Object> This() const; |
| 1850 | inline Local<Object> Holder() const; |
| 1851 | inline bool IsConstructCall() const; |
| 1852 | inline Local<Value> Data() const; |
| 1853 | private: |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1854 | static const int kDataIndex = 0; |
| 1855 | static const int kCalleeIndex = -1; |
| 1856 | static const int kHolderIndex = -2; |
| 1857 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1858 | friend class ImplementationUtilities; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1859 | inline Arguments(internal::Object** implicit_args, |
| 1860 | internal::Object** values, |
| 1861 | int length, |
| 1862 | bool is_construct_call); |
| 1863 | internal::Object** implicit_args_; |
| 1864 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1865 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1866 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1867 | }; |
| 1868 | |
| 1869 | |
| 1870 | /** |
| 1871 | * The information passed to an accessor callback about the context |
| 1872 | * of the property access. |
| 1873 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1874 | class V8EXPORT AccessorInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1875 | public: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1876 | inline AccessorInfo(internal::Object** args) |
| 1877 | : args_(args) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1878 | inline Local<Value> Data() const; |
| 1879 | inline Local<Object> This() const; |
| 1880 | inline Local<Object> Holder() const; |
| 1881 | private: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1882 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1883 | }; |
| 1884 | |
| 1885 | |
| 1886 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
| 1887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1888 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1889 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 1890 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 1891 | */ |
| 1892 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 1893 | const AccessorInfo& info); |
| 1894 | |
| 1895 | |
| 1896 | /** |
| 1897 | * Returns the value if the setter intercepts the request. |
| 1898 | * Otherwise, returns an empty handle. |
| 1899 | */ |
| 1900 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 1901 | Local<Value> value, |
| 1902 | const AccessorInfo& info); |
| 1903 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | /** |
| 1905 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1906 | * The result is an integer encoding property attributes (like v8::None, |
| 1907 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1908 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1909 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 1910 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1911 | |
| 1912 | |
| 1913 | /** |
| 1914 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1915 | * The return value is true if the property could be deleted and false |
| 1916 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1917 | */ |
| 1918 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 1919 | const AccessorInfo& info); |
| 1920 | |
| 1921 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1922 | * Returns an array containing the names of the properties the named |
| 1923 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1924 | */ |
| 1925 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
| 1926 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1927 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1928 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1929 | * Returns the value of the property if the getter intercepts the |
| 1930 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1931 | */ |
| 1932 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 1933 | const AccessorInfo& info); |
| 1934 | |
| 1935 | |
| 1936 | /** |
| 1937 | * Returns the value if the setter intercepts the request. |
| 1938 | * Otherwise, returns an empty handle. |
| 1939 | */ |
| 1940 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 1941 | Local<Value> value, |
| 1942 | const AccessorInfo& info); |
| 1943 | |
| 1944 | |
| 1945 | /** |
| 1946 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1947 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1949 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 1950 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1951 | |
| 1952 | /** |
| 1953 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1954 | * The return value is true if the property could be deleted and false |
| 1955 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1956 | */ |
| 1957 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 1958 | const AccessorInfo& info); |
| 1959 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1960 | /** |
| 1961 | * Returns an array containing the indices of the properties the |
| 1962 | * indexed property getter intercepts. |
| 1963 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1964 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
| 1965 | |
| 1966 | |
| 1967 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1968 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1969 | */ |
| 1970 | enum AccessType { |
| 1971 | ACCESS_GET, |
| 1972 | ACCESS_SET, |
| 1973 | ACCESS_HAS, |
| 1974 | ACCESS_DELETE, |
| 1975 | ACCESS_KEYS |
| 1976 | }; |
| 1977 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1978 | |
| 1979 | /** |
| 1980 | * Returns true if cross-context access should be allowed to the named |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1981 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1982 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1983 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1984 | Local<Value> key, |
| 1985 | AccessType type, |
| 1986 | Local<Value> data); |
| 1987 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1988 | |
| 1989 | /** |
| 1990 | * Returns true if cross-context access should be allowed to the indexed |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1991 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1992 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1993 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1994 | uint32_t index, |
| 1995 | AccessType type, |
| 1996 | Local<Value> data); |
| 1997 | |
| 1998 | |
| 1999 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2000 | * A FunctionTemplate is used to create functions at runtime. There |
| 2001 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2002 | * context. The lifetime of the created function is equal to the |
| 2003 | * lifetime of the context. So in case the embedder needs to create |
| 2004 | * temporary functions that can be collected using Scripts is |
| 2005 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2006 | * |
| 2007 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2008 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2009 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2010 | * A FunctionTemplate has a corresponding instance template which is |
| 2011 | * used to create object instances when the function is used as a |
| 2012 | * constructor. Properties added to the instance template are added to |
| 2013 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2014 | * |
| 2015 | * A FunctionTemplate can have a prototype template. The prototype template |
| 2016 | * is used to create the prototype object of the function. |
| 2017 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2018 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2019 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2020 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2021 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 2022 | * t->Set("func_property", v8::Number::New(1)); |
| 2023 | * |
| 2024 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 2025 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 2026 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 2027 | * |
| 2028 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 2029 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 2030 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 2031 | * instance_t->Set("instance_property", Number::New(3)); |
| 2032 | * |
| 2033 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 2034 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2035 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2036 | * |
| 2037 | * 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] | 2038 | * and "instance" for the instance object created above. The function |
| 2039 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2040 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2041 | * \code |
| 2042 | * func_property in function == true; |
| 2043 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2044 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2045 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 2046 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2047 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2048 | * instance instanceof function == true; |
| 2049 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 2050 | * instance.instance_property == 3; |
| 2051 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2052 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2053 | * A FunctionTemplate can inherit from another one by calling the |
| 2054 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 2055 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2056 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2057 | * \code |
| 2058 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 2059 | * ^ ^ |
| 2060 | * | Inherit(Parent) | .__proto__ |
| 2061 | * | | |
| 2062 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 2063 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2064 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2065 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 2066 | * object of the Child() function has __proto__ pointing to the |
| 2067 | * Parent() function's prototype object. An instance of the Child |
| 2068 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2069 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2070 | * Let Parent be the FunctionTemplate initialized in the previous |
| 2071 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2072 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2073 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2074 | * Local<FunctionTemplate> parent = t; |
| 2075 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 2076 | * child->Inherit(parent); |
| 2077 | * |
| 2078 | * Local<Function> child_function = child->GetFunction(); |
| 2079 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2080 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2081 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2082 | * The Child function and Child instance will have the following |
| 2083 | * properties: |
| 2084 | * |
| 2085 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2086 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2087 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2088 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2089 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2090 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2091 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2092 | public: |
| 2093 | /** Creates a function template.*/ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2094 | static Local<FunctionTemplate> New( |
| 2095 | InvocationCallback callback = 0, |
| 2096 | Handle<Value> data = Handle<Value>(), |
| 2097 | Handle<Signature> signature = Handle<Signature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2098 | /** Returns the unique function instance in the current execution context.*/ |
| 2099 | Local<Function> GetFunction(); |
| 2100 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2101 | /** |
| 2102 | * Set the call-handler callback for a FunctionTemplate. This |
| 2103 | * callback is called whenever the function created from this |
| 2104 | * FunctionTemplate is called. |
| 2105 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2106 | void SetCallHandler(InvocationCallback callback, |
| 2107 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2108 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2109 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2110 | Local<ObjectTemplate> InstanceTemplate(); |
| 2111 | |
| 2112 | /** Causes the function template to inherit from a parent function template.*/ |
| 2113 | void Inherit(Handle<FunctionTemplate> parent); |
| 2114 | |
| 2115 | /** |
| 2116 | * A PrototypeTemplate is the template used to create the prototype object |
| 2117 | * of the function created by this template. |
| 2118 | */ |
| 2119 | Local<ObjectTemplate> PrototypeTemplate(); |
| 2120 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2121 | |
| 2122 | /** |
| 2123 | * Set the class name of the FunctionTemplate. This is used for |
| 2124 | * printing objects created with the function created from the |
| 2125 | * FunctionTemplate as its constructor. |
| 2126 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2127 | void SetClassName(Handle<String> name); |
| 2128 | |
| 2129 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2130 | * Determines whether the __proto__ accessor ignores instances of |
| 2131 | * the function template. If instances of the function template are |
| 2132 | * ignored, __proto__ skips all instances and instead returns the |
| 2133 | * next object in the prototype chain. |
| 2134 | * |
| 2135 | * Call with a value of true to make the __proto__ accessor ignore |
| 2136 | * instances of the function template. Call with a value of false |
| 2137 | * to make the __proto__ accessor not ignore instances of the |
| 2138 | * function template. By default, instances of a function template |
| 2139 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2140 | */ |
| 2141 | void SetHiddenPrototype(bool value); |
| 2142 | |
| 2143 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2144 | * Returns true if the given object is an instance of this function |
| 2145 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2146 | */ |
| 2147 | bool HasInstance(Handle<Value> object); |
| 2148 | |
| 2149 | private: |
| 2150 | FunctionTemplate(); |
| 2151 | void AddInstancePropertyAccessor(Handle<String> name, |
| 2152 | AccessorGetter getter, |
| 2153 | AccessorSetter setter, |
| 2154 | Handle<Value> data, |
| 2155 | AccessControl settings, |
| 2156 | PropertyAttribute attributes); |
| 2157 | void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, |
| 2158 | NamedPropertySetter setter, |
| 2159 | NamedPropertyQuery query, |
| 2160 | NamedPropertyDeleter remover, |
| 2161 | NamedPropertyEnumerator enumerator, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2162 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2163 | void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, |
| 2164 | IndexedPropertySetter setter, |
| 2165 | IndexedPropertyQuery query, |
| 2166 | IndexedPropertyDeleter remover, |
| 2167 | IndexedPropertyEnumerator enumerator, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2168 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2169 | void SetInstanceCallAsFunctionHandler(InvocationCallback callback, |
| 2170 | Handle<Value> data); |
| 2171 | |
| 2172 | friend class Context; |
| 2173 | friend class ObjectTemplate; |
| 2174 | }; |
| 2175 | |
| 2176 | |
| 2177 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2178 | * An ObjectTemplate is used to create objects at runtime. |
| 2179 | * |
| 2180 | * Properties added to an ObjectTemplate are added to each object |
| 2181 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2182 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2183 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2184 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2185 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2186 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2187 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2188 | /** Creates a new instance of this template.*/ |
| 2189 | Local<Object> NewInstance(); |
| 2190 | |
| 2191 | /** |
| 2192 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2193 | * |
| 2194 | * Whenever the property with the given name is accessed on objects |
| 2195 | * created from this ObjectTemplate the getter and setter callbacks |
| 2196 | * are called instead of getting and setting the property directly |
| 2197 | * on the JavaScript object. |
| 2198 | * |
| 2199 | * \param name The name of the property for which an accessor is added. |
| 2200 | * \param getter The callback to invoke when getting the property. |
| 2201 | * \param setter The callback to invoke when setting the property. |
| 2202 | * \param data A piece of data that will be passed to the getter and setter |
| 2203 | * callbacks whenever they are invoked. |
| 2204 | * \param settings Access control settings for the accessor. This is a bit |
| 2205 | * field consisting of one of more of |
| 2206 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 2207 | * The default is to not allow cross-context access. |
| 2208 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 2209 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 2210 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 2211 | * cross-context access. |
| 2212 | * \param attribute The attributes of the property for which an accessor |
| 2213 | * is added. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2214 | */ |
| 2215 | void SetAccessor(Handle<String> name, |
| 2216 | AccessorGetter getter, |
| 2217 | AccessorSetter setter = 0, |
| 2218 | Handle<Value> data = Handle<Value>(), |
| 2219 | AccessControl settings = DEFAULT, |
| 2220 | PropertyAttribute attribute = None); |
| 2221 | |
| 2222 | /** |
| 2223 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2224 | * |
| 2225 | * Whenever a named property is accessed on objects created from |
| 2226 | * this object template, the provided callback is invoked instead of |
| 2227 | * accessing the property directly on the JavaScript object. |
| 2228 | * |
| 2229 | * \param getter The callback to invoke when getting a property. |
| 2230 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2231 | * \param query The callback to invoke to check if a property is present, |
| 2232 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2233 | * \param deleter The callback to invoke when deleting a property. |
| 2234 | * \param enumerator The callback to invoke to enumerate all the named |
| 2235 | * properties of an object. |
| 2236 | * \param data A piece of data that will be passed to the callbacks |
| 2237 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2238 | */ |
| 2239 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 2240 | NamedPropertySetter setter = 0, |
| 2241 | NamedPropertyQuery query = 0, |
| 2242 | NamedPropertyDeleter deleter = 0, |
| 2243 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2244 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2245 | |
| 2246 | /** |
| 2247 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2248 | * |
| 2249 | * Whenever an indexed property is accessed on objects created from |
| 2250 | * this object template, the provided callback is invoked instead of |
| 2251 | * accessing the property directly on the JavaScript object. |
| 2252 | * |
| 2253 | * \param getter The callback to invoke when getting a property. |
| 2254 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2255 | * \param query The callback to invoke to check if an object has a property. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2256 | * \param deleter The callback to invoke when deleting a property. |
| 2257 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 2258 | * properties of an object. |
| 2259 | * \param data A piece of data that will be passed to the callbacks |
| 2260 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2261 | */ |
| 2262 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 2263 | IndexedPropertySetter setter = 0, |
| 2264 | IndexedPropertyQuery query = 0, |
| 2265 | IndexedPropertyDeleter deleter = 0, |
| 2266 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2267 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2268 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | /** |
| 2270 | * Sets the callback to be used when calling instances created from |
| 2271 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2272 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2273 | * function. |
| 2274 | */ |
| 2275 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 2276 | Handle<Value> data = Handle<Value>()); |
| 2277 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2278 | /** |
| 2279 | * Mark object instances of the template as undetectable. |
| 2280 | * |
| 2281 | * In many ways, undetectable objects behave as though they are not |
| 2282 | * there. They behave like 'undefined' in conditionals and when |
| 2283 | * printed. However, properties can be accessed and called as on |
| 2284 | * normal objects. |
| 2285 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2286 | void MarkAsUndetectable(); |
| 2287 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2288 | /** |
| 2289 | * Sets access check callbacks on the object template. |
| 2290 | * |
| 2291 | * When accessing properties on instances of this object template, |
| 2292 | * the access check callback will be called to determine whether or |
| 2293 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2294 | * The last parameter specifies whether access checks are turned |
| 2295 | * on by default on instances. If access checks are off by default, |
| 2296 | * they can be turned on on individual instances by calling |
| 2297 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2298 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2299 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 2300 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2301 | Handle<Value> data = Handle<Value>(), |
| 2302 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2303 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2304 | /** |
| 2305 | * Gets the number of internal fields for objects generated from |
| 2306 | * this template. |
| 2307 | */ |
| 2308 | int InternalFieldCount(); |
| 2309 | |
| 2310 | /** |
| 2311 | * Sets the number of internal fields for objects generated from |
| 2312 | * this template. |
| 2313 | */ |
| 2314 | void SetInternalFieldCount(int value); |
| 2315 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2316 | private: |
| 2317 | ObjectTemplate(); |
| 2318 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 2319 | friend class FunctionTemplate; |
| 2320 | }; |
| 2321 | |
| 2322 | |
| 2323 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2324 | * A Signature specifies which receivers and arguments a function can |
| 2325 | * legally be called with. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2326 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2327 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2328 | public: |
| 2329 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 2330 | Handle<FunctionTemplate>(), |
| 2331 | int argc = 0, |
| 2332 | Handle<FunctionTemplate> argv[] = 0); |
| 2333 | private: |
| 2334 | Signature(); |
| 2335 | }; |
| 2336 | |
| 2337 | |
| 2338 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2339 | * A utility for determining the type of objects based on the template |
| 2340 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2341 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2342 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2343 | public: |
| 2344 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 2345 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 2346 | int match(Handle<Value> value); |
| 2347 | private: |
| 2348 | TypeSwitch(); |
| 2349 | }; |
| 2350 | |
| 2351 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2352 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2353 | |
| 2354 | |
| 2355 | /** |
| 2356 | * Ignore |
| 2357 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2358 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2359 | public: |
| 2360 | Extension(const char* name, |
| 2361 | const char* source = 0, |
| 2362 | int dep_count = 0, |
| 2363 | const char** deps = 0); |
| 2364 | virtual ~Extension() { } |
| 2365 | virtual v8::Handle<v8::FunctionTemplate> |
| 2366 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 2367 | return v8::Handle<v8::FunctionTemplate>(); |
| 2368 | } |
| 2369 | |
| 2370 | const char* name() { return name_; } |
| 2371 | const char* source() { return source_; } |
| 2372 | int dependency_count() { return dep_count_; } |
| 2373 | const char** dependencies() { return deps_; } |
| 2374 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 2375 | bool auto_enable() { return auto_enable_; } |
| 2376 | |
| 2377 | private: |
| 2378 | const char* name_; |
| 2379 | const char* source_; |
| 2380 | int dep_count_; |
| 2381 | const char** deps_; |
| 2382 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2383 | |
| 2384 | // Disallow copying and assigning. |
| 2385 | Extension(const Extension&); |
| 2386 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2387 | }; |
| 2388 | |
| 2389 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2390 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2391 | |
| 2392 | |
| 2393 | /** |
| 2394 | * Ignore |
| 2395 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2396 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2397 | public: |
| 2398 | inline DeclareExtension(Extension* extension) { |
| 2399 | RegisterExtension(extension); |
| 2400 | } |
| 2401 | }; |
| 2402 | |
| 2403 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2404 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2405 | |
| 2406 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2407 | Handle<Primitive> V8EXPORT Undefined(); |
| 2408 | Handle<Primitive> V8EXPORT Null(); |
| 2409 | Handle<Boolean> V8EXPORT True(); |
| 2410 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2411 | |
| 2412 | |
| 2413 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2414 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 2415 | * You must set the heap size before initializing the VM - the size cannot be |
| 2416 | * adjusted after the VM is initialized. |
| 2417 | * |
| 2418 | * If you are using threads then you should hold the V8::Locker lock while |
| 2419 | * setting the stack limit and you must set a non-default stack limit separately |
| 2420 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2421 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2422 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2423 | public: |
| 2424 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2425 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2426 | 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] | 2427 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2428 | void set_max_old_space_size(int value) { max_old_space_size_ = value; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2429 | int max_executable_size() { return max_executable_size_; } |
| 2430 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2431 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2432 | // Sets an address beyond which the VM's stack may not grow. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2433 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 2434 | private: |
| 2435 | int max_young_space_size_; |
| 2436 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2437 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2438 | uint32_t* stack_limit_; |
| 2439 | }; |
| 2440 | |
| 2441 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2442 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2443 | |
| 2444 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2445 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2446 | |
| 2447 | |
| 2448 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 2449 | |
| 2450 | |
| 2451 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data); |
| 2452 | |
| 2453 | |
| 2454 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2455 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 2456 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2457 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2458 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2459 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2460 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2461 | |
| 2462 | /** |
| 2463 | * Create new error objects by calling the corresponding error object |
| 2464 | * constructor with the message. |
| 2465 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2466 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2467 | public: |
| 2468 | static Local<Value> RangeError(Handle<String> message); |
| 2469 | static Local<Value> ReferenceError(Handle<String> message); |
| 2470 | static Local<Value> SyntaxError(Handle<String> message); |
| 2471 | static Local<Value> TypeError(Handle<String> message); |
| 2472 | static Local<Value> Error(Handle<String> message); |
| 2473 | }; |
| 2474 | |
| 2475 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2476 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2477 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2478 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2479 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2480 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 2481 | int min, |
| 2482 | int max, |
| 2483 | size_t buckets); |
| 2484 | |
| 2485 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 2486 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2487 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 2488 | enum ObjectSpace { |
| 2489 | kObjectSpaceNewSpace = 1 << 0, |
| 2490 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 2491 | kObjectSpaceOldDataSpace = 1 << 2, |
| 2492 | kObjectSpaceCodeSpace = 1 << 3, |
| 2493 | kObjectSpaceMapSpace = 1 << 4, |
| 2494 | kObjectSpaceLoSpace = 1 << 5, |
| 2495 | |
| 2496 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 2497 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 2498 | kObjectSpaceLoSpace |
| 2499 | }; |
| 2500 | |
| 2501 | enum AllocationAction { |
| 2502 | kAllocationActionAllocate = 1 << 0, |
| 2503 | kAllocationActionFree = 1 << 1, |
| 2504 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 2505 | }; |
| 2506 | |
| 2507 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 2508 | AllocationAction action, |
| 2509 | int size); |
| 2510 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2511 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2512 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 2513 | AccessType type, |
| 2514 | Local<Value> data); |
| 2515 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2516 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 2517 | |
| 2518 | /** |
| 2519 | * Callback to check if code generation from strings is allowed. See |
| 2520 | * Context::AllowCodeGenerationFromStrings. |
| 2521 | */ |
| 2522 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 2523 | |
| 2524 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2525 | |
| 2526 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2527 | * Applications can register callback functions which will be called |
| 2528 | * before and after a garbage collection. Allocations are not |
| 2529 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2530 | * objects (set or delete properties for example) since it is possible |
| 2531 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2532 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2533 | enum GCType { |
| 2534 | kGCTypeScavenge = 1 << 0, |
| 2535 | kGCTypeMarkSweepCompact = 1 << 1, |
| 2536 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 2537 | }; |
| 2538 | |
| 2539 | enum GCCallbackFlags { |
| 2540 | kNoGCCallbackFlags = 0, |
| 2541 | kGCCallbackFlagCompacted = 1 << 0 |
| 2542 | }; |
| 2543 | |
| 2544 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 2545 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 2546 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2547 | typedef void (*GCCallback)(); |
| 2548 | |
| 2549 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2550 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2551 | * Profiler modules. |
| 2552 | * |
| 2553 | * In V8, profiler consists of several modules: CPU profiler, and different |
| 2554 | * kinds of heap profiling. Each can be turned on / off independently. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 2555 | * When PROFILER_MODULE_HEAP_SNAPSHOT flag is passed to ResumeProfilerEx, |
| 2556 | * modules are enabled only temporarily for making a snapshot of the heap. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2557 | */ |
| 2558 | enum ProfilerModules { |
| 2559 | PROFILER_MODULE_NONE = 0, |
| 2560 | PROFILER_MODULE_CPU = 1, |
| 2561 | PROFILER_MODULE_HEAP_STATS = 1 << 1, |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 2562 | PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2, |
| 2563 | PROFILER_MODULE_HEAP_SNAPSHOT = 1 << 16 |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2564 | }; |
| 2565 | |
| 2566 | |
| 2567 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2568 | * Collection of V8 heap information. |
| 2569 | * |
| 2570 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 2571 | * get heap statistics from V8. |
| 2572 | */ |
| 2573 | class V8EXPORT HeapStatistics { |
| 2574 | public: |
| 2575 | HeapStatistics(); |
| 2576 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2577 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2578 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2579 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2580 | |
| 2581 | private: |
| 2582 | void set_total_heap_size(size_t size) { total_heap_size_ = size; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2583 | void set_total_heap_size_executable(size_t size) { |
| 2584 | total_heap_size_executable_ = size; |
| 2585 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2586 | void set_used_heap_size(size_t size) { used_heap_size_ = size; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2587 | void set_heap_size_limit(size_t size) { heap_size_limit_ = size; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2588 | |
| 2589 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2590 | size_t total_heap_size_executable_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2591 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2592 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2593 | |
| 2594 | friend class V8; |
| 2595 | }; |
| 2596 | |
| 2597 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2598 | class RetainedObjectInfo; |
| 2599 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2600 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2601 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 2602 | * isolates have completely separate states. Objects from one isolate |
| 2603 | * must not be used in other isolates. When V8 is initialized a |
| 2604 | * default isolate is implicitly created and entered. The embedder |
| 2605 | * can create additional isolates and use them in parallel in multiple |
| 2606 | * threads. An isolate can be entered by at most one thread at any |
| 2607 | * given time. The Locker/Unlocker API can be used to synchronize. |
| 2608 | */ |
| 2609 | class V8EXPORT Isolate { |
| 2610 | public: |
| 2611 | /** |
| 2612 | * Stack-allocated class which sets the isolate for all operations |
| 2613 | * executed within a local scope. |
| 2614 | */ |
| 2615 | class V8EXPORT Scope { |
| 2616 | public: |
| 2617 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 2618 | isolate->Enter(); |
| 2619 | } |
| 2620 | |
| 2621 | ~Scope() { isolate_->Exit(); } |
| 2622 | |
| 2623 | private: |
| 2624 | Isolate* const isolate_; |
| 2625 | |
| 2626 | // Prevent copying of Scope objects. |
| 2627 | Scope(const Scope&); |
| 2628 | Scope& operator=(const Scope&); |
| 2629 | }; |
| 2630 | |
| 2631 | /** |
| 2632 | * Creates a new isolate. Does not change the currently entered |
| 2633 | * isolate. |
| 2634 | * |
| 2635 | * When an isolate is no longer used its resources should be freed |
| 2636 | * by calling Dispose(). Using the delete operator is not allowed. |
| 2637 | */ |
| 2638 | static Isolate* New(); |
| 2639 | |
| 2640 | /** |
| 2641 | * Returns the entered isolate for the current thread or NULL in |
| 2642 | * case there is no current isolate. |
| 2643 | */ |
| 2644 | static Isolate* GetCurrent(); |
| 2645 | |
| 2646 | /** |
| 2647 | * Methods below this point require holding a lock (using Locker) in |
| 2648 | * a multi-threaded environment. |
| 2649 | */ |
| 2650 | |
| 2651 | /** |
| 2652 | * Sets this isolate as the entered one for the current thread. |
| 2653 | * Saves the previously entered one (if any), so that it can be |
| 2654 | * restored when exiting. Re-entering an isolate is allowed. |
| 2655 | */ |
| 2656 | void Enter(); |
| 2657 | |
| 2658 | /** |
| 2659 | * Exits this isolate by restoring the previously entered one in the |
| 2660 | * current thread. The isolate may still stay the same, if it was |
| 2661 | * entered more than once. |
| 2662 | * |
| 2663 | * Requires: this == Isolate::GetCurrent(). |
| 2664 | */ |
| 2665 | void Exit(); |
| 2666 | |
| 2667 | /** |
| 2668 | * Disposes the isolate. The isolate must not be entered by any |
| 2669 | * thread to be disposable. |
| 2670 | */ |
| 2671 | void Dispose(); |
| 2672 | |
| 2673 | private: |
| 2674 | |
| 2675 | Isolate(); |
| 2676 | Isolate(const Isolate&); |
| 2677 | ~Isolate(); |
| 2678 | Isolate& operator=(const Isolate&); |
| 2679 | void* operator new(size_t size); |
| 2680 | void operator delete(void*, size_t); |
| 2681 | }; |
| 2682 | |
| 2683 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2684 | class StartupData { |
| 2685 | public: |
| 2686 | enum CompressionAlgorithm { |
| 2687 | kUncompressed, |
| 2688 | kBZip2 |
| 2689 | }; |
| 2690 | |
| 2691 | const char* data; |
| 2692 | int compressed_size; |
| 2693 | int raw_size; |
| 2694 | }; |
| 2695 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2696 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2697 | * Container class for static utility functions. |
| 2698 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2699 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2700 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2701 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2702 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 2703 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2704 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2705 | * Set the callback to invoke to check if code generation from |
| 2706 | * strings should be allowed. |
| 2707 | */ |
| 2708 | static void SetAllowCodeGenerationFromStringsCallback( |
| 2709 | AllowCodeGenerationFromStringsCallback that); |
| 2710 | |
| 2711 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2712 | * Ignore out-of-memory exceptions. |
| 2713 | * |
| 2714 | * V8 running out of memory is treated as a fatal error by default. |
| 2715 | * This means that the fatal error handler is called and that V8 is |
| 2716 | * terminated. |
| 2717 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2718 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2719 | * out-of-memory situation as a fatal error. This way, the contexts |
| 2720 | * that did not cause the out of memory problem might be able to |
| 2721 | * continue execution. |
| 2722 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2723 | static void IgnoreOutOfMemoryException(); |
| 2724 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2725 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2726 | * 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] | 2727 | * fatal errors such as out-of-memory situations. |
| 2728 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2729 | static bool IsDead(); |
| 2730 | |
| 2731 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2732 | * The following 4 functions are to be used when V8 is built with |
| 2733 | * the 'compress_startup_data' flag enabled. In this case, the |
| 2734 | * embedder must decompress startup data prior to initializing V8. |
| 2735 | * |
| 2736 | * This is how interaction with V8 should look like: |
| 2737 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 2738 | * v8::StartupData* compressed_data = |
| 2739 | * new v8::StartupData[compressed_data_count]; |
| 2740 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 2741 | * ... decompress data (compressed_data can be updated in-place) ... |
| 2742 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 2743 | * ... now V8 can be initialized |
| 2744 | * ... make sure the decompressed data stays valid until V8 shutdown |
| 2745 | */ |
| 2746 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 2747 | static int GetCompressedStartupDataCount(); |
| 2748 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 2749 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 2750 | |
| 2751 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2752 | * Adds a message listener. |
| 2753 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2754 | * The same message listener can be added more than once and in that |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2755 | * case it will be called more than once for each message. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2756 | */ |
| 2757 | static bool AddMessageListener(MessageCallback that, |
| 2758 | Handle<Value> data = Handle<Value>()); |
| 2759 | |
| 2760 | /** |
| 2761 | * Remove all message listeners from the specified callback function. |
| 2762 | */ |
| 2763 | static void RemoveMessageListeners(MessageCallback that); |
| 2764 | |
| 2765 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2766 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 2767 | * and report it to the message listeners. The option is off by default. |
| 2768 | */ |
| 2769 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 2770 | bool capture, |
| 2771 | int frame_limit = 10, |
| 2772 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 2773 | |
| 2774 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2775 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2776 | */ |
| 2777 | static void SetFlagsFromString(const char* str, int length); |
| 2778 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2779 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2780 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2781 | */ |
| 2782 | static void SetFlagsFromCommandLine(int* argc, |
| 2783 | char** argv, |
| 2784 | bool remove_flags); |
| 2785 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2786 | /** Get the version string. */ |
| 2787 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2788 | |
| 2789 | /** |
| 2790 | * Enables the host application to provide a mechanism for recording |
| 2791 | * statistics counters. |
| 2792 | */ |
| 2793 | static void SetCounterFunction(CounterLookupCallback); |
| 2794 | |
| 2795 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2796 | * Enables the host application to provide a mechanism for recording |
| 2797 | * histograms. The CreateHistogram function returns a |
| 2798 | * histogram which will later be passed to the AddHistogramSample |
| 2799 | * function. |
| 2800 | */ |
| 2801 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 2802 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 2803 | |
| 2804 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2805 | * Enables the computation of a sliding window of states. The sliding |
| 2806 | * window information is recorded in statistics counters. |
| 2807 | */ |
| 2808 | static void EnableSlidingStateWindow(); |
| 2809 | |
| 2810 | /** Callback function for reporting failed access checks.*/ |
| 2811 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 2812 | |
| 2813 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2814 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2815 | * garbage collection. Allocations are not allowed in the |
| 2816 | * callback function, you therefore cannot manipulate objects (set |
| 2817 | * or delete properties for example) since it is possible such |
| 2818 | * operations will result in the allocation of objects. It is possible |
| 2819 | * to specify the GCType filter for your callback. But it is not possible to |
| 2820 | * register the same callback function two times with different |
| 2821 | * GCType filters. |
| 2822 | */ |
| 2823 | static void AddGCPrologueCallback( |
| 2824 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 2825 | |
| 2826 | /** |
| 2827 | * This function removes callback which was installed by |
| 2828 | * AddGCPrologueCallback function. |
| 2829 | */ |
| 2830 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 2831 | |
| 2832 | /** |
| 2833 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 2834 | * Enables the host application to receive a notification before a |
| 2835 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2836 | * callback function, you therefore cannot manipulate objects (set |
| 2837 | * or delete properties for example) since it is possible such |
| 2838 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2839 | */ |
| 2840 | static void SetGlobalGCPrologueCallback(GCCallback); |
| 2841 | |
| 2842 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2843 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2844 | * garbage collection. Allocations are not allowed in the |
| 2845 | * callback function, you therefore cannot manipulate objects (set |
| 2846 | * or delete properties for example) since it is possible such |
| 2847 | * operations will result in the allocation of objects. It is possible |
| 2848 | * to specify the GCType filter for your callback. But it is not possible to |
| 2849 | * register the same callback function two times with different |
| 2850 | * GCType filters. |
| 2851 | */ |
| 2852 | static void AddGCEpilogueCallback( |
| 2853 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 2854 | |
| 2855 | /** |
| 2856 | * This function removes callback which was installed by |
| 2857 | * AddGCEpilogueCallback function. |
| 2858 | */ |
| 2859 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 2860 | |
| 2861 | /** |
| 2862 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 2863 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2864 | * major garbage collection. Allocations are not allowed in the |
| 2865 | * callback function, you therefore cannot manipulate objects (set |
| 2866 | * or delete properties for example) since it is possible such |
| 2867 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2868 | */ |
| 2869 | static void SetGlobalGCEpilogueCallback(GCCallback); |
| 2870 | |
| 2871 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 2872 | * Enables the host application to provide a mechanism to be notified |
| 2873 | * and perform custom logging when V8 Allocates Executable Memory. |
| 2874 | */ |
| 2875 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 2876 | ObjectSpace space, |
| 2877 | AllocationAction action); |
| 2878 | |
| 2879 | /** |
| 2880 | * This function removes callback which was installed by |
| 2881 | * AddMemoryAllocationCallback function. |
| 2882 | */ |
| 2883 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 2884 | |
| 2885 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2886 | * Allows the host application to group objects together. If one |
| 2887 | * object in the group is alive, all objects in the group are alive. |
| 2888 | * After each garbage collection, object groups are removed. It is |
| 2889 | * intended to be used in the before-garbage-collection callback |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2890 | * function, for instance to simulate DOM tree connections among JS |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2891 | * wrapper objects. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2892 | * See v8-profiler.h for RetainedObjectInfo interface description. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2893 | */ |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2894 | static void AddObjectGroup(Persistent<Value>* objects, |
| 2895 | size_t length, |
| 2896 | RetainedObjectInfo* info = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2897 | |
| 2898 | /** |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2899 | * Allows the host application to declare implicit references between |
| 2900 | * the objects: if |parent| is alive, all |children| are alive too. |
| 2901 | * After each garbage collection, all implicit references |
| 2902 | * are removed. It is intended to be used in the before-garbage-collection |
| 2903 | * callback function. |
| 2904 | */ |
| 2905 | static void AddImplicitReferences(Persistent<Object> parent, |
| 2906 | Persistent<Value>* children, |
| 2907 | size_t length); |
| 2908 | |
| 2909 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2910 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2911 | * initialize from scratch. This function is called implicitly if |
| 2912 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2913 | */ |
| 2914 | static bool Initialize(); |
| 2915 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2916 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2917 | * Adjusts the amount of registered external memory. Used to give |
| 2918 | * V8 an indication of the amount of externally allocated memory |
| 2919 | * that is kept alive by JavaScript objects. V8 uses this to decide |
| 2920 | * when to perform global garbage collections. Registering |
| 2921 | * externally allocated memory will trigger global garbage |
| 2922 | * collections more often than otherwise in an attempt to garbage |
| 2923 | * collect the JavaScript objects keeping the externally allocated |
| 2924 | * memory alive. |
| 2925 | * |
| 2926 | * \param change_in_bytes the change in externally allocated memory |
| 2927 | * that is kept alive by JavaScript objects. |
| 2928 | * \returns the adjusted value. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2929 | */ |
| 2930 | static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes); |
| 2931 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2932 | /** |
| 2933 | * Suspends recording of tick samples in the profiler. |
| 2934 | * When the V8 profiling mode is enabled (usually via command line |
| 2935 | * switches) this function suspends recording of tick samples. |
| 2936 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 2937 | * |
| 2938 | * See also the --prof and --prof_auto command line switches to |
| 2939 | * enable V8 profiling. |
| 2940 | */ |
| 2941 | static void PauseProfiler(); |
| 2942 | |
| 2943 | /** |
| 2944 | * Resumes recording of tick samples in the profiler. |
| 2945 | * See also PauseProfiler(). |
| 2946 | */ |
| 2947 | static void ResumeProfiler(); |
| 2948 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2949 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2950 | * Return whether profiler is currently paused. |
| 2951 | */ |
| 2952 | static bool IsProfilerPaused(); |
| 2953 | |
| 2954 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2955 | * Resumes specified profiler modules. Can be called several times to |
| 2956 | * mark the opening of a profiler events block with the given tag. |
| 2957 | * |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2958 | * "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CPU)". |
| 2959 | * See ProfilerModules enum. |
| 2960 | * |
| 2961 | * \param flags Flags specifying profiler modules. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2962 | * \param tag Profile tag. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2963 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2964 | static void ResumeProfilerEx(int flags, int tag = 0); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2965 | |
| 2966 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2967 | * Pauses specified profiler modules. Each call to "PauseProfilerEx" closes |
| 2968 | * a block of profiler events opened by a call to "ResumeProfilerEx" with the |
| 2969 | * same tag value. There is no need for blocks to be properly nested. |
| 2970 | * The profiler is paused when the last opened block is closed. |
| 2971 | * |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2972 | * "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)". |
| 2973 | * See ProfilerModules enum. |
| 2974 | * |
| 2975 | * \param flags Flags specifying profiler modules. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2976 | * \param tag Profile tag. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2977 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2978 | static void PauseProfilerEx(int flags, int tag = 0); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2979 | |
| 2980 | /** |
| 2981 | * Returns active (resumed) profiler modules. |
| 2982 | * See ProfilerModules enum. |
| 2983 | * |
| 2984 | * \returns active profiler modules. |
| 2985 | */ |
| 2986 | static int GetActiveProfilerModules(); |
| 2987 | |
| 2988 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2989 | * If logging is performed into a memory buffer (via --logfile=*), allows to |
| 2990 | * retrieve previously written messages. This can be used for retrieving |
| 2991 | * profiler log data in the application. This function is thread-safe. |
| 2992 | * |
| 2993 | * Caller provides a destination buffer that must exist during GetLogLines |
| 2994 | * call. Only whole log lines are copied into the buffer. |
| 2995 | * |
| 2996 | * \param from_pos specified a point in a buffer to read from, 0 is the |
| 2997 | * beginning of a buffer. It is assumed that caller updates its current |
| 2998 | * position using returned size value from the previous call. |
| 2999 | * \param dest_buf destination buffer for log data. |
| 3000 | * \param max_size size of the destination buffer. |
| 3001 | * \returns actual size of log data copied into buffer. |
| 3002 | */ |
| 3003 | static int GetLogLines(int from_pos, char* dest_buf, int max_size); |
| 3004 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3005 | /** |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3006 | * The minimum allowed size for a log lines buffer. If the size of |
| 3007 | * the buffer given will not be enough to hold a line of the maximum |
| 3008 | * length, an attempt to find a log line end in GetLogLines will |
| 3009 | * fail, and an empty result will be returned. |
| 3010 | */ |
| 3011 | static const int kMinimumSizeForLogLinesBuffer = 2048; |
| 3012 | |
| 3013 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3014 | * Retrieve the V8 thread id of the calling thread. |
| 3015 | * |
| 3016 | * The thread id for a thread should only be retrieved after the V8 |
| 3017 | * lock has been acquired with a Locker object with that thread. |
| 3018 | */ |
| 3019 | static int GetCurrentThreadId(); |
| 3020 | |
| 3021 | /** |
| 3022 | * Forcefully terminate execution of a JavaScript thread. This can |
| 3023 | * be used to terminate long-running scripts. |
| 3024 | * |
| 3025 | * TerminateExecution should only be called when then V8 lock has |
| 3026 | * been acquired with a Locker object. Therefore, in order to be |
| 3027 | * able to terminate long-running threads, preemption must be |
| 3028 | * enabled to allow the user of TerminateExecution to acquire the |
| 3029 | * lock. |
| 3030 | * |
| 3031 | * The termination is achieved by throwing an exception that is |
| 3032 | * uncatchable by JavaScript exception handlers. Termination |
| 3033 | * exceptions act as if they were caught by a C++ TryCatch exception |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3034 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3035 | * exception handler that catches an exception should check if that |
| 3036 | * exception is a termination exception and immediately return if |
| 3037 | * that is the case. Returning immediately in that case will |
| 3038 | * continue the propagation of the termination exception if needed. |
| 3039 | * |
| 3040 | * The thread id passed to TerminateExecution must have been |
| 3041 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 3042 | * |
| 3043 | * \param thread_id The thread id of the thread to terminate. |
| 3044 | */ |
| 3045 | static void TerminateExecution(int thread_id); |
| 3046 | |
| 3047 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3048 | * Forcefully terminate the current thread of JavaScript execution |
| 3049 | * in the given isolate. If no isolate is provided, the default |
| 3050 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3051 | * |
| 3052 | * This method can be used by any thread even if that thread has not |
| 3053 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3054 | * |
| 3055 | * \param isolate The isolate in which to terminate the current JS execution. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3056 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3057 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3058 | |
| 3059 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 3060 | * Is V8 terminating JavaScript execution. |
| 3061 | * |
| 3062 | * Returns true if JavaScript execution is currently terminating |
| 3063 | * because of a call to TerminateExecution. In that case there are |
| 3064 | * still JavaScript frames on the stack and the termination |
| 3065 | * exception is still active. |
| 3066 | */ |
| 3067 | static bool IsExecutionTerminating(); |
| 3068 | |
| 3069 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3070 | * Releases any resources used by v8 and stops any utility threads |
| 3071 | * that may be running. Note that disposing v8 is permanent, it |
| 3072 | * cannot be reinitialized. |
| 3073 | * |
| 3074 | * It should generally not be necessary to dispose v8 before exiting |
| 3075 | * a process, this should happen automatically. It is only necessary |
| 3076 | * to use if the process needs the resources taken up by v8. |
| 3077 | */ |
| 3078 | static bool Dispose(); |
| 3079 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3080 | /** |
| 3081 | * Get statistics about the heap memory usage. |
| 3082 | */ |
| 3083 | static void GetHeapStatistics(HeapStatistics* heap_statistics); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3084 | |
| 3085 | /** |
| 3086 | * Optional notification that the embedder is idle. |
| 3087 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3088 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3089 | * Returns true if the embedder should stop calling IdleNotification |
| 3090 | * until real work has been done. This indicates that V8 has done |
| 3091 | * as much cleanup as it will be able to do. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3092 | */ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3093 | static bool IdleNotification(); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3094 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3095 | /** |
| 3096 | * Optional notification that the system is running low on memory. |
| 3097 | * V8 uses these notifications to attempt to free memory. |
| 3098 | */ |
| 3099 | static void LowMemoryNotification(); |
| 3100 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3101 | /** |
| 3102 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3103 | * these notifications to guide the GC heuristic. Returns the number |
| 3104 | * of context disposals - including this one - since the last time |
| 3105 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3106 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3107 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3108 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3109 | private: |
| 3110 | V8(); |
| 3111 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3112 | static internal::Object** GlobalizeReference(internal::Object** handle); |
| 3113 | static void DisposeGlobal(internal::Object** global_handle); |
| 3114 | static void MakeWeak(internal::Object** global_handle, |
| 3115 | void* data, |
| 3116 | WeakReferenceCallback); |
| 3117 | static void ClearWeak(internal::Object** global_handle); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame^] | 3118 | static void MarkIndependent(internal::Object** global_handle); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3119 | static bool IsGlobalNearDeath(internal::Object** global_handle); |
| 3120 | static bool IsGlobalWeak(internal::Object** global_handle); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3121 | static void SetWrapperClassId(internal::Object** global_handle, |
| 3122 | uint16_t class_id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3123 | |
| 3124 | template <class T> friend class Handle; |
| 3125 | template <class T> friend class Local; |
| 3126 | template <class T> friend class Persistent; |
| 3127 | friend class Context; |
| 3128 | }; |
| 3129 | |
| 3130 | |
| 3131 | /** |
| 3132 | * An external exception handler. |
| 3133 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3134 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3135 | public: |
| 3136 | |
| 3137 | /** |
| 3138 | * Creates a new try/catch block and registers it with v8. |
| 3139 | */ |
| 3140 | TryCatch(); |
| 3141 | |
| 3142 | /** |
| 3143 | * Unregisters and deletes this try/catch block. |
| 3144 | */ |
| 3145 | ~TryCatch(); |
| 3146 | |
| 3147 | /** |
| 3148 | * Returns true if an exception has been caught by this try/catch block. |
| 3149 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3150 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3151 | |
| 3152 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3153 | * For certain types of exceptions, it makes no sense to continue |
| 3154 | * execution. |
| 3155 | * |
| 3156 | * Currently, the only type of exception that can be caught by a |
| 3157 | * TryCatch handler and for which it does not make sense to continue |
| 3158 | * is termination exception. Such exceptions are thrown when the |
| 3159 | * TerminateExecution methods are called to terminate a long-running |
| 3160 | * script. |
| 3161 | * |
| 3162 | * If CanContinue returns false, the correct action is to perform |
| 3163 | * any C++ cleanup needed and then return. |
| 3164 | */ |
| 3165 | bool CanContinue() const; |
| 3166 | |
| 3167 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 3168 | * Throws the exception caught by this TryCatch in a way that avoids |
| 3169 | * it being caught again by this same TryCatch. As with ThrowException |
| 3170 | * it is illegal to execute any JavaScript operations after calling |
| 3171 | * ReThrow; the caller must return immediately to where the exception |
| 3172 | * is caught. |
| 3173 | */ |
| 3174 | Handle<Value> ReThrow(); |
| 3175 | |
| 3176 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3177 | * Returns the exception caught by this try/catch block. If no exception has |
| 3178 | * been caught an empty handle is returned. |
| 3179 | * |
| 3180 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 3181 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3182 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3183 | |
| 3184 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3185 | * Returns the .stack property of the thrown object. If no .stack |
| 3186 | * property is present an empty handle is returned. |
| 3187 | */ |
| 3188 | Local<Value> StackTrace() const; |
| 3189 | |
| 3190 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3191 | * Returns the message associated with this exception. If there is |
| 3192 | * no message associated an empty handle is returned. |
| 3193 | * |
| 3194 | * The returned handle is valid until this TryCatch block has been |
| 3195 | * destroyed. |
| 3196 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3197 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3198 | |
| 3199 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3200 | * Clears any exceptions that may have been caught by this try/catch block. |
| 3201 | * After this method has been called, HasCaught() will return false. |
| 3202 | * |
| 3203 | * It is not necessary to clear a try/catch block before using it again; if |
| 3204 | * another exception is thrown the previously caught exception will just be |
| 3205 | * overwritten. However, it is often a good idea since it makes it easier |
| 3206 | * to determine which operation threw a given exception. |
| 3207 | */ |
| 3208 | void Reset(); |
| 3209 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3210 | /** |
| 3211 | * Set verbosity of the external exception handler. |
| 3212 | * |
| 3213 | * By default, exceptions that are caught by an external exception |
| 3214 | * handler are not reported. Call SetVerbose with true on an |
| 3215 | * external exception handler to have exceptions caught by the |
| 3216 | * handler reported as if they were not caught. |
| 3217 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3218 | void SetVerbose(bool value); |
| 3219 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3220 | /** |
| 3221 | * Set whether or not this TryCatch should capture a Message object |
| 3222 | * which holds source information about where the exception |
| 3223 | * occurred. True by default. |
| 3224 | */ |
| 3225 | void SetCaptureMessage(bool value); |
| 3226 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3227 | private: |
| 3228 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3229 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3230 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 3231 | bool is_verbose_ : 1; |
| 3232 | bool can_continue_ : 1; |
| 3233 | bool capture_message_ : 1; |
| 3234 | bool rethrow_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3235 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3236 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3237 | }; |
| 3238 | |
| 3239 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3240 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3241 | |
| 3242 | |
| 3243 | /** |
| 3244 | * Ignore |
| 3245 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3246 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3247 | public: |
| 3248 | ExtensionConfiguration(int name_count, const char* names[]) |
| 3249 | : name_count_(name_count), names_(names) { } |
| 3250 | private: |
| 3251 | friend class ImplementationUtilities; |
| 3252 | int name_count_; |
| 3253 | const char** names_; |
| 3254 | }; |
| 3255 | |
| 3256 | |
| 3257 | /** |
| 3258 | * A sandboxed execution context with its own set of built-in objects |
| 3259 | * and functions. |
| 3260 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3261 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3262 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3263 | /** |
| 3264 | * Returns the global proxy object or global object itself for |
| 3265 | * detached contexts. |
| 3266 | * |
| 3267 | * Global proxy object is a thin wrapper whose prototype points to |
| 3268 | * actual context's global object with the properties like Object, etc. |
| 3269 | * This is done that way for security reasons (for more details see |
| 3270 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 3271 | * |
| 3272 | * Please note that changes to global proxy object prototype most probably |
| 3273 | * would break VM---v8 expects only global object as a prototype of |
| 3274 | * global proxy object. |
| 3275 | * |
| 3276 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 3277 | * object until global is reattached with ReattachGlobal(). |
| 3278 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3279 | Local<Object> Global(); |
| 3280 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3281 | /** |
| 3282 | * Detaches the global object from its context before |
| 3283 | * the global object can be reused to create a new context. |
| 3284 | */ |
| 3285 | void DetachGlobal(); |
| 3286 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 3287 | /** |
| 3288 | * Reattaches a global object to a context. This can be used to |
| 3289 | * restore the connection between a global object and a context |
| 3290 | * after DetachGlobal has been called. |
| 3291 | * |
| 3292 | * \param global_object The global object to reattach to the |
| 3293 | * context. For this to work, the global object must be the global |
| 3294 | * object that was associated with this context before a call to |
| 3295 | * DetachGlobal. |
| 3296 | */ |
| 3297 | void ReattachGlobal(Handle<Object> global_object); |
| 3298 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3299 | /** Creates a new context. |
| 3300 | * |
| 3301 | * Returns a persistent handle to the newly allocated context. This |
| 3302 | * persistent handle has to be disposed when the context is no |
| 3303 | * longer used so the context can be garbage collected. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3304 | * |
| 3305 | * \param extensions An optional extension configuration containing |
| 3306 | * the extensions to be installed in the newly created context. |
| 3307 | * |
| 3308 | * \param global_template An optional object template from which the |
| 3309 | * global object for the newly created context will be created. |
| 3310 | * |
| 3311 | * \param global_object An optional global object to be reused for |
| 3312 | * the newly created context. This global object must have been |
| 3313 | * created by a previous call to Context::New with the same global |
| 3314 | * template. The state of the global object will be completely reset |
| 3315 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3316 | */ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3317 | static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3318 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3319 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 3320 | Handle<Value> global_object = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3321 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 3322 | /** Returns the last entered context. */ |
| 3323 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3324 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 3325 | /** Returns the context that is on the top of the stack. */ |
| 3326 | static Local<Context> GetCurrent(); |
| 3327 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3328 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 3329 | * Returns the context of the calling JavaScript code. That is the |
| 3330 | * context of the top-most JavaScript frame. If there are no |
| 3331 | * JavaScript frames an empty handle is returned. |
| 3332 | */ |
| 3333 | static Local<Context> GetCalling(); |
| 3334 | |
| 3335 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3336 | * Sets the security token for the context. To access an object in |
| 3337 | * another context, the security tokens must match. |
| 3338 | */ |
| 3339 | void SetSecurityToken(Handle<Value> token); |
| 3340 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3341 | /** Restores the security token to the default value. */ |
| 3342 | void UseDefaultSecurityToken(); |
| 3343 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3344 | /** Returns the security token of this context.*/ |
| 3345 | Handle<Value> GetSecurityToken(); |
| 3346 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3347 | /** |
| 3348 | * Enter this context. After entering a context, all code compiled |
| 3349 | * and run is compiled and run in this context. If another context |
| 3350 | * is already entered, this old context is saved so it can be |
| 3351 | * restored when the new context is exited. |
| 3352 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3353 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3354 | |
| 3355 | /** |
| 3356 | * Exit this context. Exiting the current context restores the |
| 3357 | * context that was in place when entering the current context. |
| 3358 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3359 | void Exit(); |
| 3360 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3361 | /** 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] | 3362 | bool HasOutOfMemoryException(); |
| 3363 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3364 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3365 | static bool InContext(); |
| 3366 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3367 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3368 | * Associate an additional data object with the context. This is mainly used |
| 3369 | * with the debugger to provide additional information on the context through |
| 3370 | * the debugger API. |
| 3371 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 3372 | void SetData(Handle<String> data); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3373 | Local<Value> GetData(); |
| 3374 | |
| 3375 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3376 | * Control whether code generation from strings is allowed. Calling |
| 3377 | * this method with false will disable 'eval' and the 'Function' |
| 3378 | * constructor for code running in this context. If 'eval' or the |
| 3379 | * 'Function' constructor are used an exception will be thrown. |
| 3380 | * |
| 3381 | * If code generation from strings is not allowed the |
| 3382 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 3383 | * set before blocking the call to 'eval' or the 'Function' |
| 3384 | * constructor. If that callback returns true, the call will be |
| 3385 | * allowed, otherwise an exception will be thrown. If no callback is |
| 3386 | * set an exception will be thrown. |
| 3387 | */ |
| 3388 | void AllowCodeGenerationFromStrings(bool allow); |
| 3389 | |
| 3390 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3391 | * Stack-allocated class which sets the execution context for all |
| 3392 | * operations executed within a local scope. |
| 3393 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3394 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3395 | public: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3396 | explicit inline Scope(Handle<Context> context) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3397 | context_->Enter(); |
| 3398 | } |
| 3399 | inline ~Scope() { context_->Exit(); } |
| 3400 | private: |
| 3401 | Handle<Context> context_; |
| 3402 | }; |
| 3403 | |
| 3404 | private: |
| 3405 | friend class Value; |
| 3406 | friend class Script; |
| 3407 | friend class Object; |
| 3408 | friend class Function; |
| 3409 | }; |
| 3410 | |
| 3411 | |
| 3412 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3413 | * Multiple threads in V8 are allowed, but only one thread at a time |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3414 | * is allowed to use any given V8 isolate. See Isolate class |
| 3415 | * comments. The definition of 'using V8 isolate' includes |
| 3416 | * accessing handles or holding onto object pointers obtained |
| 3417 | * from V8 handles while in the particular V8 isolate. It is up |
| 3418 | * to the user of V8 to ensure (perhaps with locking) that this |
| 3419 | * constraint is not violated. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3420 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3421 | * v8::Locker is a scoped lock object. While it's |
| 3422 | * active (i.e. between its construction and destruction) the current thread is |
| 3423 | * allowed to use the locked isolate. V8 guarantees that an isolate can be locked |
| 3424 | * by at most one thread at any time. In other words, the scope of a v8::Locker is |
| 3425 | * a critical section. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3426 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3427 | * Sample usage: |
| 3428 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3429 | * ... |
| 3430 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3431 | * v8::Locker locker(isolate); |
| 3432 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3433 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3434 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3435 | * ... |
| 3436 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3437 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3438 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3439 | * If you wish to stop using V8 in a thread A you can do this either |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3440 | * by destroying the v8::Locker object as above or by constructing a |
| 3441 | * v8::Unlocker object: |
| 3442 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3443 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3444 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3445 | * isolate->Exit(); |
| 3446 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3447 | * ... |
| 3448 | * // Code not using V8 goes here while V8 can run in another thread. |
| 3449 | * ... |
| 3450 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3451 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3452 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3453 | * |
| 3454 | * The Unlocker object is intended for use in a long-running callback |
| 3455 | * from V8, where you want to release the V8 lock for other threads to |
| 3456 | * use. |
| 3457 | * |
| 3458 | * The v8::Locker is a recursive lock. That is, you can lock more than |
| 3459 | * once in a given thread. This can be useful if you have code that can |
| 3460 | * be called either from code that holds the lock or from code that does |
| 3461 | * not. The Unlocker is not recursive so you can not have several |
| 3462 | * Unlockers on the stack at once, and you can not use an Unlocker in a |
| 3463 | * thread that is not inside a Locker's scope. |
| 3464 | * |
| 3465 | * An unlocker will unlock several lockers if it has to and reinstate |
| 3466 | * the correct depth of locking on its destruction. eg.: |
| 3467 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3468 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3469 | * // V8 not locked. |
| 3470 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3471 | * v8::Locker locker(isolate); |
| 3472 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3473 | * // V8 locked. |
| 3474 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3475 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3476 | * // V8 still locked (2 levels). |
| 3477 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3478 | * isolate->Exit(); |
| 3479 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3480 | * // V8 not locked. |
| 3481 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3482 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3483 | * // V8 locked again (2 levels). |
| 3484 | * } |
| 3485 | * // V8 still locked (1 level). |
| 3486 | * } |
| 3487 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3488 | * \endcode |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3489 | * |
| 3490 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3491 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3492 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3493 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3494 | /** |
| 3495 | * Initialize Unlocker for a given Isolate. NULL means default isolate. |
| 3496 | */ |
| 3497 | explicit Unlocker(Isolate* isolate = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3498 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3499 | private: |
| 3500 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3501 | }; |
| 3502 | |
| 3503 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3504 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3505 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3506 | /** |
| 3507 | * Initialize Locker for a given Isolate. NULL means default isolate. |
| 3508 | */ |
| 3509 | explicit Locker(Isolate* isolate = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3510 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3511 | |
| 3512 | /** |
| 3513 | * Start preemption. |
| 3514 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3515 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3516 | * that will switch between multiple threads that are in contention |
| 3517 | * for the V8 lock. |
| 3518 | */ |
| 3519 | static void StartPreemption(int every_n_ms); |
| 3520 | |
| 3521 | /** |
| 3522 | * Stop preemption. |
| 3523 | */ |
| 3524 | static void StopPreemption(); |
| 3525 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3526 | /** |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3527 | * Returns whether or not the locker for a given isolate, or default isolate if NULL is given, |
| 3528 | * is locked by the current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3529 | */ |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3530 | static bool IsLocked(Isolate* isolate = NULL); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3531 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 3532 | /** |
| 3533 | * Returns whether v8::Locker is being used by this V8 instance. |
| 3534 | */ |
| 3535 | static bool IsActive() { return active_; } |
| 3536 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3537 | private: |
| 3538 | bool has_lock_; |
| 3539 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3540 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3541 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 3542 | static bool active_; |
| 3543 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3544 | // Disallow copying and assigning. |
| 3545 | Locker(const Locker&); |
| 3546 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3547 | }; |
| 3548 | |
| 3549 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3550 | /** |
| 3551 | * An interface for exporting data from V8, using "push" model. |
| 3552 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3553 | class V8EXPORT OutputStream { // NOLINT |
| 3554 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3555 | enum OutputEncoding { |
| 3556 | kAscii = 0 // 7-bit ASCII. |
| 3557 | }; |
| 3558 | enum WriteResult { |
| 3559 | kContinue = 0, |
| 3560 | kAbort = 1 |
| 3561 | }; |
| 3562 | virtual ~OutputStream() {} |
| 3563 | /** Notify about the end of stream. */ |
| 3564 | virtual void EndOfStream() = 0; |
| 3565 | /** Get preferred output chunk size. Called only once. */ |
| 3566 | virtual int GetChunkSize() { return 1024; } |
| 3567 | /** Get preferred output encoding. Called only once. */ |
| 3568 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 3569 | /** |
| 3570 | * Writes the next chunk of snapshot data into the stream. Writing |
| 3571 | * can be stopped by returning kAbort as function result. EndOfStream |
| 3572 | * will not be called in case writing was aborted. |
| 3573 | */ |
| 3574 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
| 3575 | }; |
| 3576 | |
| 3577 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3578 | /** |
| 3579 | * An interface for reporting progress and controlling long-running |
| 3580 | * activities. |
| 3581 | */ |
| 3582 | class V8EXPORT ActivityControl { // NOLINT |
| 3583 | public: |
| 3584 | enum ControlOption { |
| 3585 | kContinue = 0, |
| 3586 | kAbort = 1 |
| 3587 | }; |
| 3588 | virtual ~ActivityControl() {} |
| 3589 | /** |
| 3590 | * Notify about current progress. The activity can be stopped by |
| 3591 | * returning kAbort as the callback result. |
| 3592 | */ |
| 3593 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 3594 | }; |
| 3595 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3596 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3597 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3598 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3599 | |
| 3600 | namespace internal { |
| 3601 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3602 | static const int kApiPointerSize = sizeof(void*); // NOLINT |
| 3603 | static const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3604 | |
| 3605 | // Tag information for HeapObject. |
| 3606 | const int kHeapObjectTag = 1; |
| 3607 | const int kHeapObjectTagSize = 2; |
| 3608 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 3609 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3610 | // Tag information for Smi. |
| 3611 | const int kSmiTag = 0; |
| 3612 | const int kSmiTagSize = 1; |
| 3613 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 3614 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3615 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3616 | |
| 3617 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3618 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3619 | static const int kSmiShiftSize = 0; |
| 3620 | static const int kSmiValueSize = 31; |
| 3621 | static inline int SmiToInt(internal::Object* value) { |
| 3622 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3623 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 3624 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 3625 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3626 | |
| 3627 | // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi |
| 3628 | // with a plain reinterpret_cast. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3629 | static const uintptr_t kEncodablePointerMask = 0x1; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3630 | static const int kPointerToSmiShift = 0; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3631 | }; |
| 3632 | |
| 3633 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3634 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3635 | static const int kSmiShiftSize = 31; |
| 3636 | static const int kSmiValueSize = 32; |
| 3637 | static inline int SmiToInt(internal::Object* value) { |
| 3638 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3639 | // Shift down and throw away top 32 bits. |
| 3640 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 3641 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3642 | |
| 3643 | // To maximize the range of pointers that can be encoded |
| 3644 | // in the available 32 bits, we require them to be 8 bytes aligned. |
| 3645 | // This gives 2 ^ (32 + 3) = 32G address space covered. |
| 3646 | // It might be not enough to cover stack allocated objects on some platforms. |
| 3647 | static const int kPointerAlignment = 3; |
| 3648 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3649 | static const uintptr_t kEncodablePointerMask = |
| 3650 | ~(uintptr_t(0xffffffff) << kPointerAlignment); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3651 | |
| 3652 | static const int kPointerToSmiShift = |
| 3653 | kSmiTagSize + kSmiShiftSize - kPointerAlignment; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3654 | }; |
| 3655 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3656 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 3657 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 3658 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3659 | const uintptr_t kEncodablePointerMask = |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3660 | PlatformSmiTagging::kEncodablePointerMask; |
| 3661 | const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3662 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3663 | template <size_t ptr_size> struct InternalConstants; |
| 3664 | |
| 3665 | // Internal constants for 32-bit systems. |
| 3666 | template <> struct InternalConstants<4> { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3667 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3668 | }; |
| 3669 | |
| 3670 | // Internal constants for 64-bit systems. |
| 3671 | template <> struct InternalConstants<8> { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3672 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3673 | }; |
| 3674 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3675 | /** |
| 3676 | * This class exports constants and functionality from within v8 that |
| 3677 | * is necessary to implement inline functions in the v8 api. Don't |
| 3678 | * depend on functions and constants defined here. |
| 3679 | */ |
| 3680 | class Internals { |
| 3681 | public: |
| 3682 | |
| 3683 | // These values match non-compiler-dependent values defined within |
| 3684 | // the implementation of v8. |
| 3685 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3686 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3687 | static const int kStringResourceOffset = |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3688 | InternalConstants<kApiPointerSize>::kStringResourceOffset; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3689 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3690 | static const int kProxyProxyOffset = kApiPointerSize; |
| 3691 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3692 | static const int kFullStringRepresentationMask = 0x07; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 3693 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3694 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3695 | static const int kJSObjectType = 0xa2; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3696 | static const int kFirstNonstringType = 0x80; |
| 3697 | static const int kProxyType = 0x85; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3698 | |
| 3699 | static inline bool HasHeapObjectTag(internal::Object* value) { |
| 3700 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 3701 | kHeapObjectTag); |
| 3702 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3703 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3704 | static inline bool HasSmiTag(internal::Object* value) { |
| 3705 | return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 3706 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3707 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3708 | static inline int SmiValue(internal::Object* value) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3709 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | static inline int GetInstanceType(internal::Object* obj) { |
| 3713 | typedef internal::Object O; |
| 3714 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 3715 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 3716 | } |
| 3717 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3718 | static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3719 | const uintptr_t address = reinterpret_cast<uintptr_t>(value); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3720 | return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 3721 | } |
| 3722 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3723 | static inline void* GetExternalPointer(internal::Object* obj) { |
| 3724 | if (HasSmiTag(obj)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3725 | return GetExternalPointerFromSmi(obj); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3726 | } else if (GetInstanceType(obj) == kProxyType) { |
| 3727 | return ReadField<void*>(obj, kProxyProxyOffset); |
| 3728 | } else { |
| 3729 | return NULL; |
| 3730 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3731 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3732 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3733 | static inline bool IsExternalTwoByteString(int instance_type) { |
| 3734 | int representation = (instance_type & kFullStringRepresentationMask); |
| 3735 | return representation == kExternalTwoByteRepresentationTag; |
| 3736 | } |
| 3737 | |
| 3738 | template <typename T> |
| 3739 | static inline T ReadField(Object* ptr, int offset) { |
| 3740 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 3741 | return *reinterpret_cast<T*>(addr); |
| 3742 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3743 | |
| 3744 | static inline bool CanCastToHeapObject(void* o) { return false; } |
| 3745 | static inline bool CanCastToHeapObject(Context* o) { return true; } |
| 3746 | static inline bool CanCastToHeapObject(String* o) { return true; } |
| 3747 | static inline bool CanCastToHeapObject(Object* o) { return true; } |
| 3748 | static inline bool CanCastToHeapObject(Message* o) { return true; } |
| 3749 | static inline bool CanCastToHeapObject(StackTrace* o) { return true; } |
| 3750 | static inline bool CanCastToHeapObject(StackFrame* o) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3751 | }; |
| 3752 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3753 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3754 | |
| 3755 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3756 | template <class T> |
| 3757 | Handle<T>::Handle() : val_(0) { } |
| 3758 | |
| 3759 | |
| 3760 | template <class T> |
| 3761 | Local<T>::Local() : Handle<T>() { } |
| 3762 | |
| 3763 | |
| 3764 | template <class T> |
| 3765 | Local<T> Local<T>::New(Handle<T> that) { |
| 3766 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3767 | T* that_ptr = *that; |
| 3768 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 3769 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 3770 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 3771 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 3772 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3773 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 3774 | } |
| 3775 | |
| 3776 | |
| 3777 | template <class T> |
| 3778 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
| 3779 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3780 | internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3781 | return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); |
| 3782 | } |
| 3783 | |
| 3784 | |
| 3785 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3786 | bool Persistent<T>::IsNearDeath() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3787 | if (this->IsEmpty()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3788 | return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | |
| 3792 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3793 | bool Persistent<T>::IsWeak() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3794 | if (this->IsEmpty()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3795 | return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | |
| 3799 | template <class T> |
| 3800 | void Persistent<T>::Dispose() { |
| 3801 | if (this->IsEmpty()) return; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3802 | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | |
| 3806 | template <class T> |
| 3807 | Persistent<T>::Persistent() : Handle<T>() { } |
| 3808 | |
| 3809 | template <class T> |
| 3810 | void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3811 | V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), |
| 3812 | parameters, |
| 3813 | callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | template <class T> |
| 3817 | void Persistent<T>::ClearWeak() { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3818 | V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3819 | } |
| 3820 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3821 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame^] | 3822 | void Persistent<T>::MarkIndependent() { |
| 3823 | V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this)); |
| 3824 | } |
| 3825 | |
| 3826 | template <class T> |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3827 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
| 3828 | V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id); |
| 3829 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3830 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3831 | Arguments::Arguments(internal::Object** implicit_args, |
| 3832 | internal::Object** values, int length, |
| 3833 | bool is_construct_call) |
| 3834 | : implicit_args_(implicit_args), |
| 3835 | values_(values), |
| 3836 | length_(length), |
| 3837 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3838 | |
| 3839 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3840 | Local<Value> Arguments::operator[](int i) const { |
| 3841 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 3842 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 3843 | } |
| 3844 | |
| 3845 | |
| 3846 | Local<Function> Arguments::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3847 | return Local<Function>(reinterpret_cast<Function*>( |
| 3848 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | |
| 3852 | Local<Object> Arguments::This() const { |
| 3853 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 3854 | } |
| 3855 | |
| 3856 | |
| 3857 | Local<Object> Arguments::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3858 | return Local<Object>(reinterpret_cast<Object*>( |
| 3859 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | |
| 3863 | Local<Value> Arguments::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3864 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | |
| 3868 | bool Arguments::IsConstructCall() const { |
| 3869 | return is_construct_call_; |
| 3870 | } |
| 3871 | |
| 3872 | |
| 3873 | int Arguments::Length() const { |
| 3874 | return length_; |
| 3875 | } |
| 3876 | |
| 3877 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3878 | template <class T> |
| 3879 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3880 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 3881 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3882 | return Local<T>(reinterpret_cast<T*>(after)); |
| 3883 | } |
| 3884 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3885 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3886 | return resource_name_; |
| 3887 | } |
| 3888 | |
| 3889 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3890 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3891 | return resource_line_offset_; |
| 3892 | } |
| 3893 | |
| 3894 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3895 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3896 | return resource_column_offset_; |
| 3897 | } |
| 3898 | |
| 3899 | |
| 3900 | Handle<Boolean> Boolean::New(bool value) { |
| 3901 | return value ? True() : False(); |
| 3902 | } |
| 3903 | |
| 3904 | |
| 3905 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 3906 | Set(v8::String::New(name), value); |
| 3907 | } |
| 3908 | |
| 3909 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3910 | Local<Value> Object::GetInternalField(int index) { |
| 3911 | #ifndef V8_ENABLE_CHECKS |
| 3912 | Local<Value> quick_result = UncheckedGetInternalField(index); |
| 3913 | if (!quick_result.IsEmpty()) return quick_result; |
| 3914 | #endif |
| 3915 | return CheckedGetInternalField(index); |
| 3916 | } |
| 3917 | |
| 3918 | |
| 3919 | Local<Value> Object::UncheckedGetInternalField(int index) { |
| 3920 | typedef internal::Object O; |
| 3921 | typedef internal::Internals I; |
| 3922 | O* obj = *reinterpret_cast<O**>(this); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3923 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3924 | // If the object is a plain JSObject, which is the common case, |
| 3925 | // we know where to find the internal fields and can return the |
| 3926 | // value directly. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3927 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3928 | O* value = I::ReadField<O*>(obj, offset); |
| 3929 | O** result = HandleScope::CreateHandle(value); |
| 3930 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 3931 | } else { |
| 3932 | return Local<Value>(); |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | |
| 3937 | void* External::Unwrap(Handle<v8::Value> obj) { |
| 3938 | #ifdef V8_ENABLE_CHECKS |
| 3939 | return FullUnwrap(obj); |
| 3940 | #else |
| 3941 | return QuickUnwrap(obj); |
| 3942 | #endif |
| 3943 | } |
| 3944 | |
| 3945 | |
| 3946 | void* External::QuickUnwrap(Handle<v8::Value> wrapper) { |
| 3947 | typedef internal::Object O; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3948 | O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3949 | return internal::Internals::GetExternalPointer(obj); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | |
| 3953 | void* Object::GetPointerFromInternalField(int index) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3954 | typedef internal::Object O; |
| 3955 | typedef internal::Internals I; |
| 3956 | |
| 3957 | O* obj = *reinterpret_cast<O**>(this); |
| 3958 | |
| 3959 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 3960 | // If the object is a plain JSObject, which is the common case, |
| 3961 | // we know where to find the internal fields and can return the |
| 3962 | // value directly. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3963 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3964 | O* value = I::ReadField<O*>(obj, offset); |
| 3965 | return I::GetExternalPointer(value); |
| 3966 | } |
| 3967 | |
| 3968 | return SlowGetPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | |
| 3972 | String* String::Cast(v8::Value* value) { |
| 3973 | #ifdef V8_ENABLE_CHECKS |
| 3974 | CheckCast(value); |
| 3975 | #endif |
| 3976 | return static_cast<String*>(value); |
| 3977 | } |
| 3978 | |
| 3979 | |
| 3980 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 3981 | typedef internal::Object O; |
| 3982 | typedef internal::Internals I; |
| 3983 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3984 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3985 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3986 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 3987 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 3988 | } else { |
| 3989 | result = NULL; |
| 3990 | } |
| 3991 | #ifdef V8_ENABLE_CHECKS |
| 3992 | VerifyExternalStringResource(result); |
| 3993 | #endif |
| 3994 | return result; |
| 3995 | } |
| 3996 | |
| 3997 | |
| 3998 | bool Value::IsString() const { |
| 3999 | #ifdef V8_ENABLE_CHECKS |
| 4000 | return FullIsString(); |
| 4001 | #else |
| 4002 | return QuickIsString(); |
| 4003 | #endif |
| 4004 | } |
| 4005 | |
| 4006 | bool Value::QuickIsString() const { |
| 4007 | typedef internal::Object O; |
| 4008 | typedef internal::Internals I; |
| 4009 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 4010 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4011 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | |
| 4015 | Number* Number::Cast(v8::Value* value) { |
| 4016 | #ifdef V8_ENABLE_CHECKS |
| 4017 | CheckCast(value); |
| 4018 | #endif |
| 4019 | return static_cast<Number*>(value); |
| 4020 | } |
| 4021 | |
| 4022 | |
| 4023 | Integer* Integer::Cast(v8::Value* value) { |
| 4024 | #ifdef V8_ENABLE_CHECKS |
| 4025 | CheckCast(value); |
| 4026 | #endif |
| 4027 | return static_cast<Integer*>(value); |
| 4028 | } |
| 4029 | |
| 4030 | |
| 4031 | Date* Date::Cast(v8::Value* value) { |
| 4032 | #ifdef V8_ENABLE_CHECKS |
| 4033 | CheckCast(value); |
| 4034 | #endif |
| 4035 | return static_cast<Date*>(value); |
| 4036 | } |
| 4037 | |
| 4038 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4039 | RegExp* RegExp::Cast(v8::Value* value) { |
| 4040 | #ifdef V8_ENABLE_CHECKS |
| 4041 | CheckCast(value); |
| 4042 | #endif |
| 4043 | return static_cast<RegExp*>(value); |
| 4044 | } |
| 4045 | |
| 4046 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4047 | Object* Object::Cast(v8::Value* value) { |
| 4048 | #ifdef V8_ENABLE_CHECKS |
| 4049 | CheckCast(value); |
| 4050 | #endif |
| 4051 | return static_cast<Object*>(value); |
| 4052 | } |
| 4053 | |
| 4054 | |
| 4055 | Array* Array::Cast(v8::Value* value) { |
| 4056 | #ifdef V8_ENABLE_CHECKS |
| 4057 | CheckCast(value); |
| 4058 | #endif |
| 4059 | return static_cast<Array*>(value); |
| 4060 | } |
| 4061 | |
| 4062 | |
| 4063 | Function* Function::Cast(v8::Value* value) { |
| 4064 | #ifdef V8_ENABLE_CHECKS |
| 4065 | CheckCast(value); |
| 4066 | #endif |
| 4067 | return static_cast<Function*>(value); |
| 4068 | } |
| 4069 | |
| 4070 | |
| 4071 | External* External::Cast(v8::Value* value) { |
| 4072 | #ifdef V8_ENABLE_CHECKS |
| 4073 | CheckCast(value); |
| 4074 | #endif |
| 4075 | return static_cast<External*>(value); |
| 4076 | } |
| 4077 | |
| 4078 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4079 | Local<Value> AccessorInfo::Data() const { |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 4080 | return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | |
| 4084 | Local<Object> AccessorInfo::This() const { |
| 4085 | return Local<Object>(reinterpret_cast<Object*>(&args_[0])); |
| 4086 | } |
| 4087 | |
| 4088 | |
| 4089 | Local<Object> AccessorInfo::Holder() const { |
| 4090 | return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); |
| 4091 | } |
| 4092 | |
| 4093 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4094 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4095 | * \example shell.cc |
| 4096 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4097 | * command-line and executes them. |
| 4098 | */ |
| 4099 | |
| 4100 | |
| 4101 | /** |
| 4102 | * \example process.cc |
| 4103 | */ |
| 4104 | |
| 4105 | |
| 4106 | } // namespace v8 |
| 4107 | |
| 4108 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4109 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4110 | #undef TYPE_CHECK |
| 4111 | |
| 4112 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4113 | #endif // V8_H_ |