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