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