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