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