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