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