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