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