jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 28 | /** \mainpage V8 API Reference Guide |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 29 | * |
| 30 | * V8 is Google's open source JavaScript engine. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | * |
| 32 | * This set of documents provides reference material generated from the |
| 33 | * V8 header file, include/v8.h. |
| 34 | * |
| 35 | * For other documentation see http://code.google.com/apis/v8/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | */ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 37 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 38 | #ifndef V8_H_ |
| 39 | #define V8_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 41 | #include "v8stdint.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef _WIN32 |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 44 | |
| 45 | // Setup for Windows DLL export/import. When building the V8 DLL the |
| 46 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
| 47 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
| 48 | // static library or building a program which uses the V8 static library neither |
| 49 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 50 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
| 51 | #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ |
| 52 | build configuration to ensure that at most one of these is set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 55 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 56 | #define V8EXPORT __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 57 | #elif USING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 58 | #define V8EXPORT __declspec(dllimport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 59 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 60 | #define V8EXPORT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 61 | #endif // BUILDING_V8_SHARED |
| 62 | |
| 63 | #else // _WIN32 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 64 | |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 65 | // Setup for Linux shared library export. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 66 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ |
| 67 | (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 68 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 69 | #define V8EXPORT __attribute__ ((visibility("default"))) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 70 | #else |
| 71 | #define V8EXPORT |
| 72 | #endif |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 73 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 74 | #define V8EXPORT |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 75 | #endif |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 76 | |
| 77 | #endif // _WIN32 |
| 78 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 79 | #if defined(__GNUC__) && !defined(DEBUG) |
| 80 | #define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator |
| 81 | #elif defined(_MSC_VER) && !defined(DEBUG) |
| 82 | #define V8_INLINE(declarator) __forceinline declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 83 | #else |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 84 | #define V8_INLINE(declarator) inline declarator |
| 85 | #endif |
| 86 | |
| 87 | #if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS |
| 88 | #define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated)) |
| 89 | #elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS |
| 90 | #define V8_DEPRECATED(declarator) __declspec(deprecated) declarator |
| 91 | #else |
| 92 | #define V8_DEPRECATED(declarator) declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 93 | #endif |
| 94 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 95 | #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) |
| 96 | #define V8_UNLIKELY(condition) __builtin_expect((condition), 0) |
| 97 | #define V8_LIKELY(condition) __builtin_expect((condition), 1) |
| 98 | #else |
| 99 | #define V8_UNLIKELY(condition) (condition) |
| 100 | #define V8_LIKELY(condition) (condition) |
| 101 | #endif |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 104 | * The v8 JavaScript engine. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | */ |
| 106 | namespace v8 { |
| 107 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 108 | class AccessorInfo; |
| 109 | class AccessorSignature; |
| 110 | class Array; |
| 111 | class Boolean; |
| 112 | class BooleanObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | class Context; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 114 | class CpuProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 115 | class Data; |
| 116 | class Date; |
| 117 | class DeclaredAccessorDescriptor; |
| 118 | class External; |
| 119 | class Function; |
| 120 | class FunctionTemplate; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 121 | class HeapProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 122 | class ImplementationUtilities; |
| 123 | class Int32; |
| 124 | class Integer; |
| 125 | class Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | class Number; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 127 | class NumberObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | class Object; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 129 | class ObjectOperationDescriptor; |
| 130 | class ObjectTemplate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | class Primitive; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 132 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | class Signature; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 134 | class StackFrame; |
| 135 | class StackTrace; |
| 136 | class String; |
| 137 | class StringObject; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 138 | class Symbol; |
| 139 | class SymbolObject; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 140 | class Uint32; |
| 141 | class Utils; |
| 142 | class Value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | template <class T> class Handle; |
| 144 | template <class T> class Local; |
| 145 | template <class T> class Persistent; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 147 | namespace internal { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 148 | class Arguments; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 149 | class Heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 150 | class HeapObject; |
| 151 | class Isolate; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 152 | class Object; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 153 | } |
| 154 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 155 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 156 | /** |
| 157 | * General purpose unique identifier. |
| 158 | */ |
| 159 | class UniqueId { |
| 160 | public: |
| 161 | explicit UniqueId(intptr_t data) |
| 162 | : data_(data) {} |
| 163 | |
| 164 | bool operator==(const UniqueId& other) const { |
| 165 | return data_ == other.data_; |
| 166 | } |
| 167 | |
| 168 | bool operator!=(const UniqueId& other) const { |
| 169 | return data_ != other.data_; |
| 170 | } |
| 171 | |
| 172 | bool operator<(const UniqueId& other) const { |
| 173 | return data_ < other.data_; |
| 174 | } |
| 175 | |
| 176 | private: |
| 177 | intptr_t data_; |
| 178 | }; |
| 179 | |
| 180 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 181 | // --- Weak Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 182 | |
| 183 | |
| 184 | /** |
| 185 | * A weak reference callback function. |
| 186 | * |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 187 | * This callback should either explicitly invoke Dispose on |object| if |
| 188 | * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| 189 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 190 | * \param object the weak global object to be reclaimed by the garbage collector |
| 191 | * \param parameter the value passed in when making the weak global object |
| 192 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 193 | typedef void (*WeakReferenceCallback)(Persistent<Value> object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | void* parameter); |
| 195 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 196 | // TODO(svenpanne) Temporary definition until Chrome is in sync. |
| 197 | typedef void (*NearDeathCallback)(Isolate* isolate, |
| 198 | Persistent<Value> object, |
| 199 | void* parameter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 201 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 203 | #define TYPE_CHECK(T, S) \ |
| 204 | while (false) { \ |
| 205 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /** |
| 209 | * An object reference managed by the v8 garbage collector. |
| 210 | * |
| 211 | * All objects returned from v8 have to be tracked by the garbage |
| 212 | * collector so that it knows that the objects are still alive. Also, |
| 213 | * because the garbage collector may move objects, it is unsafe to |
| 214 | * point directly to an object. Instead, all objects are stored in |
| 215 | * handles which are known by the garbage collector and updated |
| 216 | * whenever an object moves. Handles should always be passed by value |
| 217 | * (except in cases like out-parameters) and they should never be |
| 218 | * allocated on the heap. |
| 219 | * |
| 220 | * There are two types of handles: local and persistent handles. |
| 221 | * Local handles are light-weight and transient and typically used in |
| 222 | * local operations. They are managed by HandleScopes. Persistent |
| 223 | * handles can be used when storing objects across several independent |
| 224 | * operations and have to be explicitly deallocated when they're no |
| 225 | * longer used. |
| 226 | * |
| 227 | * It is safe to extract the object stored in the handle by |
| 228 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 229 | * 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] | 230 | * behind the scenes and the same rules apply to these values as to |
| 231 | * their handles. |
| 232 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 233 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 234 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | /** |
| 236 | * Creates an empty handle. |
| 237 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 238 | V8_INLINE(Handle()) : val_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * Creates a new handle for the specified value. |
| 242 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 243 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * Creates a handle for the contents of the specified handle. This |
| 247 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 248 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 250 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | * between compatible handles, for instance assigning a |
| 252 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 253 | * because String is a subclass of Value. |
| 254 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 255 | template <class S> V8_INLINE(Handle(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 256 | : val_(reinterpret_cast<T*>(*that)) { |
| 257 | /** |
| 258 | * This check fails when trying to convert between incompatible |
| 259 | * handles. For example, converting from a Handle<String> to a |
| 260 | * Handle<Number>. |
| 261 | */ |
| 262 | TYPE_CHECK(T, S); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Returns true if the handle is empty. |
| 267 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 268 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 270 | /** |
| 271 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 272 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 273 | V8_INLINE(void Clear()) { val_ = 0; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 274 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 275 | V8_INLINE(T* operator->() const) { return val_; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 276 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 277 | V8_INLINE(T* operator*() const) { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * Checks whether two handles are the same. |
| 281 | * Returns true if both are empty, or if the objects |
| 282 | * to which they refer are identical. |
| 283 | * The handles' references are not checked. |
| 284 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 285 | template <class S> V8_INLINE(bool operator==(Handle<S> that) const) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 286 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 287 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 288 | if (a == 0) return b == 0; |
| 289 | if (b == 0) return false; |
| 290 | return *a == *b; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Checks whether two handles are different. |
| 295 | * Returns true if only one of the handles is empty, or if |
| 296 | * the objects to which they refer are different. |
| 297 | * The handles' references are not checked. |
| 298 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 299 | template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 300 | return !operator==(that); |
| 301 | } |
| 302 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 303 | 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] | 304 | #ifdef V8_ENABLE_CHECKS |
| 305 | // If we're going to perform the type check then we have to check |
| 306 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 307 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 308 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | return Handle<T>(T::Cast(*that)); |
| 310 | } |
| 311 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 312 | template <class S> V8_INLINE(Handle<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 313 | return Handle<S>::Cast(*this); |
| 314 | } |
| 315 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | private: |
| 317 | T* val_; |
| 318 | }; |
| 319 | |
| 320 | |
| 321 | /** |
| 322 | * A light-weight stack-allocated object handle. All operations |
| 323 | * that return objects from within v8 return them in local handles. They |
| 324 | * are created within HandleScopes, and all local handles allocated within a |
| 325 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 326 | * is not necessary to explicitly deallocate local handles. |
| 327 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 328 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 329 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 330 | V8_INLINE(Local()); |
| 331 | template <class S> V8_INLINE(Local(Local<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 333 | /** |
| 334 | * This check fails when trying to convert between incompatible |
| 335 | * handles. For example, converting from a Handle<String> to a |
| 336 | * Handle<Number>. |
| 337 | */ |
| 338 | TYPE_CHECK(T, S); |
| 339 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 340 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 341 | 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] | 342 | #ifdef V8_ENABLE_CHECKS |
| 343 | // If we're going to perform the type check then we have to check |
| 344 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 346 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 347 | return Local<T>(T::Cast(*that)); |
| 348 | } |
| 349 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 350 | template <class S> V8_INLINE(Local<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 351 | return Local<S>::Cast(*this); |
| 352 | } |
| 353 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 354 | /** |
| 355 | * Create a local handle for the content of another handle. |
| 356 | * The referee is kept alive by the local handle even when |
| 357 | * the original handle is destroyed/disposed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 358 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 359 | V8_INLINE(static Local<T> New(Handle<T> that)); |
| 360 | V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | |
| 364 | /** |
| 365 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 366 | * 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] | 367 | * allocated, a Persistent handle remains valid until it is explicitly |
| 368 | * disposed. |
| 369 | * |
| 370 | * A persistent handle contains a reference to a storage cell within |
| 371 | * the v8 engine which holds an object value and which is updated by |
| 372 | * the garbage collector whenever the object is moved. A new storage |
| 373 | * cell can be created using Persistent::New and existing handles can |
| 374 | * be disposed using Persistent::Dispose. Since persistent handles |
| 375 | * are passed by value you may have many persistent handle objects |
| 376 | * that point to the same storage cell. For instance, if you pass a |
| 377 | * persistent handle as an argument to a function you will not get two |
| 378 | * different storage cells but rather two references to the same |
| 379 | * storage cell. |
| 380 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 381 | template <class T> class Persistent : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | /** |
| 384 | * Creates an empty persistent handle that doesn't point to any |
| 385 | * storage cell. |
| 386 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 387 | V8_INLINE(Persistent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 388 | |
| 389 | /** |
| 390 | * Creates a persistent handle for the same storage cell as the |
| 391 | * specified handle. This constructor allows you to pass persistent |
| 392 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 393 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 395 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 396 | * between compatible persistent handles, for instance assigning a |
| 397 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 398 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 399 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 400 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 401 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 402 | /** |
| 403 | * This check fails when trying to convert between incompatible |
| 404 | * handles. For example, converting from a Handle<String> to a |
| 405 | * Handle<Number>. |
| 406 | */ |
| 407 | TYPE_CHECK(T, S); |
| 408 | } |
| 409 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 410 | template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 411 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 412 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 413 | * A constructor that creates a new global cell pointing to that. In contrast |
| 414 | * to the copy constructor, this creates a new persistent handle which needs |
| 415 | * to be separately disposed. |
| 416 | */ |
| 417 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 418 | : Handle<T>(New(isolate, that)) { } |
| 419 | |
| 420 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 421 | * "Casts" a plain handle which is known to be a persistent handle |
| 422 | * to a persistent handle. |
| 423 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 424 | template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | : Handle<T>(*that) { } |
| 426 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 427 | 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] | 428 | #ifdef V8_ENABLE_CHECKS |
| 429 | // If we're going to perform the type check then we have to check |
| 430 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 432 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | return Persistent<T>(T::Cast(*that)); |
| 434 | } |
| 435 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 436 | template <class S> V8_INLINE(Persistent<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 437 | return Persistent<S>::Cast(*this); |
| 438 | } |
| 439 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 440 | /** Deprecated. Use Isolate version instead. */ |
| 441 | V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 442 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 443 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 444 | * Creates a new persistent handle for an existing local or persistent handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 445 | */ |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 446 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
| 447 | |
| 448 | /** Deprecated. Use Isolate version instead. */ |
| 449 | V8_DEPRECATED(void Dispose()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | |
| 451 | /** |
| 452 | * Releases the storage cell referenced by this persistent handle. |
| 453 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 454 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | * cell remain and IsEmpty will still return false. |
| 456 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 457 | V8_INLINE(void Dispose(Isolate* isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 459 | /** Deprecated. Use Isolate version instead. */ |
| 460 | V8_DEPRECATED(void MakeWeak(void* parameters, |
| 461 | WeakReferenceCallback callback)); |
| 462 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | /** |
| 464 | * Make the reference to this object weak. When only weak handles |
| 465 | * refer to the object, the garbage collector will perform a |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 466 | * callback to the given V8::NearDeathCallback function, passing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 467 | * it the object reference and the given parameters. |
| 468 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 469 | V8_INLINE(void MakeWeak(Isolate* isolate, |
| 470 | void* parameters, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 471 | NearDeathCallback callback)); |
| 472 | |
| 473 | /** Deprecated. Use Isolate version instead. */ |
| 474 | V8_DEPRECATED(void ClearWeak()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 476 | /** Clears the weak reference to this object. */ |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 477 | V8_INLINE(void ClearWeak(Isolate* isolate)); |
| 478 | |
| 479 | /** Deprecated. Use Isolate version instead. */ |
| 480 | V8_DEPRECATED(void MarkIndependent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 481 | |
| 482 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 483 | * Marks the reference to this object independent. Garbage collector is free |
| 484 | * to ignore any object groups containing this object. Weak callback for an |
| 485 | * independent handle should not assume that it will be preceded by a global |
| 486 | * GC prologue callback or followed by a global GC epilogue callback. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 487 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 488 | V8_INLINE(void MarkIndependent(Isolate* isolate)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 489 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 490 | /** Deprecated. Use Isolate version instead. */ |
| 491 | V8_DEPRECATED(void MarkPartiallyDependent()); |
| 492 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 493 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 494 | * Marks the reference to this object partially dependent. Partially dependent |
| 495 | * handles only depend on other partially dependent handles and these |
| 496 | * dependencies are provided through object groups. It provides a way to build |
| 497 | * smaller object groups for young objects that represent only a subset of all |
| 498 | * external dependencies. This mark is automatically cleared after each |
| 499 | * garbage collection. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 500 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 501 | V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 502 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 503 | /** Deprecated. Use Isolate version instead. */ |
| 504 | V8_DEPRECATED(bool IsIndependent() const); |
| 505 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 506 | /** Returns true if this handle was previously marked as independent. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 507 | V8_INLINE(bool IsIndependent(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 508 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 509 | /** Deprecated. Use Isolate version instead. */ |
| 510 | V8_DEPRECATED(bool IsNearDeath() const); |
| 511 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 512 | /** Checks if the handle holds the only reference to an object. */ |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 513 | V8_INLINE(bool IsNearDeath(Isolate* isolate) const); |
| 514 | |
| 515 | /** Deprecated. Use Isolate version instead. */ |
| 516 | V8_DEPRECATED(bool IsWeak() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 518 | /** Returns true if the handle's reference is weak. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 519 | V8_INLINE(bool IsWeak(Isolate* isolate) const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 521 | /** Deprecated. Use Isolate version instead. */ |
| 522 | V8_DEPRECATED(void SetWrapperClassId(uint16_t class_id)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 523 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 524 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 525 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 526 | * description in v8-profiler.h for details. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 527 | */ |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 528 | V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); |
| 529 | |
| 530 | /** Deprecated. Use Isolate version instead. */ |
| 531 | V8_DEPRECATED(uint16_t WrapperClassId() const); |
| 532 | |
| 533 | /** |
| 534 | * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 535 | * was previously assigned. |
| 536 | */ |
| 537 | V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 538 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | private: |
| 540 | friend class ImplementationUtilities; |
| 541 | friend class ObjectTemplate; |
| 542 | }; |
| 543 | |
| 544 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 545 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 546 | * A stack-allocated class that governs a number of local handles. |
| 547 | * After a handle scope has been created, all local handles will be |
| 548 | * allocated within that handle scope until either the handle scope is |
| 549 | * deleted or another handle scope is created. If there is already a |
| 550 | * 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] | 551 | * 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] | 552 | * new handles will again be allocated in the original handle scope. |
| 553 | * |
| 554 | * After the handle scope of a local handle has been deleted the |
| 555 | * garbage collector will no longer track the object stored in the |
| 556 | * handle and may deallocate it. The behavior of accessing a handle |
| 557 | * for which the handle scope has been deleted is undefined. |
| 558 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 559 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 560 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 561 | // TODO(svenpanne) Deprecate me when Chrome is fixed! |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 562 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 563 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 564 | HandleScope(Isolate* isolate); |
| 565 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 566 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | |
| 568 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 569 | * Closes the handle scope and returns the value as a handle in the |
| 570 | * previous scope, which is the new current scope after the call. |
| 571 | */ |
| 572 | template <class T> Local<T> Close(Handle<T> value); |
| 573 | |
| 574 | /** |
| 575 | * Counts the number of allocated handles. |
| 576 | */ |
| 577 | static int NumberOfHandles(); |
| 578 | |
| 579 | /** |
| 580 | * Creates a new handle with the given value. |
| 581 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 582 | static internal::Object** CreateHandle(internal::Object* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 583 | static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 584 | internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 585 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 586 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 587 | |
| 588 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 589 | // Make it hard to create heap-allocated or illegal handle scopes by |
| 590 | // disallowing certain operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | HandleScope(const HandleScope&); |
| 592 | void operator=(const HandleScope&); |
| 593 | void* operator new(size_t size); |
| 594 | void operator delete(void*, size_t); |
| 595 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 596 | // This Data class is accessible internally as HandleScopeData through a |
| 597 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 598 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 599 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 600 | internal::Object** next; |
| 601 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 602 | int level; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 603 | V8_INLINE(void Initialize()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 605 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | } |
| 607 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 608 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 609 | void Initialize(Isolate* isolate); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 610 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 612 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 613 | internal::Object** prev_next_; |
| 614 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 616 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 617 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 618 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 619 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 620 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 621 | friend class ImplementationUtilities; |
| 622 | }; |
| 623 | |
| 624 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 625 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | |
| 627 | |
| 628 | /** |
| 629 | * The superclass of values and API object templates. |
| 630 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 631 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 632 | private: |
| 633 | Data(); |
| 634 | }; |
| 635 | |
| 636 | |
| 637 | /** |
| 638 | * Pre-compilation data that can be associated with a script. This |
| 639 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 640 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 641 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 643 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 644 | public: |
| 645 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 646 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 647 | /** |
| 648 | * Pre-compiles the specified script (context-independent). |
| 649 | * |
| 650 | * \param input Pointer to UTF-8 script source code. |
| 651 | * \param length Length of UTF-8 script source code. |
| 652 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 653 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 655 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 656 | * Pre-compiles the specified script (context-independent). |
| 657 | * |
| 658 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 659 | * without using Lockers. |
| 660 | * |
| 661 | * \param source Script source code. |
| 662 | */ |
| 663 | static ScriptData* PreCompile(Handle<String> source); |
| 664 | |
| 665 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 666 | * Load previous pre-compilation data. |
| 667 | * |
| 668 | * \param data Pointer to data returned by a call to Data() of a previous |
| 669 | * ScriptData. Ownership is not transferred. |
| 670 | * \param length Length of data. |
| 671 | */ |
| 672 | static ScriptData* New(const char* data, int length); |
| 673 | |
| 674 | /** |
| 675 | * Returns the length of Data(). |
| 676 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 678 | |
| 679 | /** |
| 680 | * Returns a serialized representation of this ScriptData that can later be |
| 681 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 682 | */ |
| 683 | virtual const char* Data() = 0; |
| 684 | |
| 685 | /** |
| 686 | * Returns true if the source code could not be parsed. |
| 687 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 688 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 689 | }; |
| 690 | |
| 691 | |
| 692 | /** |
| 693 | * The origin, within a file, of a script. |
| 694 | */ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 695 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 696 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 697 | V8_INLINE(ScriptOrigin( |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 698 | Handle<Value> resource_name, |
| 699 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 700 | Handle<Integer> resource_column_offset = Handle<Integer>())) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | : resource_name_(resource_name), |
| 702 | resource_line_offset_(resource_line_offset), |
| 703 | resource_column_offset_(resource_column_offset) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 704 | V8_INLINE(Handle<Value> ResourceName() const); |
| 705 | V8_INLINE(Handle<Integer> ResourceLineOffset() const); |
| 706 | V8_INLINE(Handle<Integer> ResourceColumnOffset() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 707 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 708 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | Handle<Integer> resource_line_offset_; |
| 710 | Handle<Integer> resource_column_offset_; |
| 711 | }; |
| 712 | |
| 713 | |
| 714 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 715 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 717 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 718 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 719 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 720 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 721 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 722 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 723 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 724 | * when New() returns |
| 725 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 726 | * using pre_data speeds compilation if it's done multiple times. |
| 727 | * Owned by caller, no references are kept when New() returns. |
| 728 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 729 | * 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] | 730 | * available to compile event handlers. |
| 731 | * \return Compiled script object (context independent; when run it |
| 732 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 733 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 734 | static Local<Script> New(Handle<String> source, |
| 735 | ScriptOrigin* origin = NULL, |
| 736 | ScriptData* pre_data = NULL, |
| 737 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 738 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 739 | /** |
| 740 | * Compiles the specified script using the specified file name |
| 741 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 742 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 743 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 744 | * \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] | 745 | * as the script's origin. |
| 746 | * \return Compiled script object (context independent; when run it |
| 747 | * will use the currently entered context). |
| 748 | */ |
| 749 | static Local<Script> New(Handle<String> source, |
| 750 | Handle<Value> file_name); |
| 751 | |
| 752 | /** |
| 753 | * Compiles the specified script (bound to current context). |
| 754 | * |
| 755 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 756 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 757 | * when Compile() returns |
| 758 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 759 | * using pre_data speeds compilation if it's done multiple times. |
| 760 | * Owned by caller, no references are kept when Compile() returns. |
| 761 | * \param script_data Arbitrary data associated with script. Using |
| 762 | * this has same effect as calling SetData(), but makes data available |
| 763 | * earlier (i.e. to compile event handlers). |
| 764 | * \return Compiled script object, bound to the context that was active |
| 765 | * when this function was called. When run it will always use this |
| 766 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 767 | */ |
| 768 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 769 | ScriptOrigin* origin = NULL, |
| 770 | ScriptData* pre_data = NULL, |
| 771 | Handle<String> script_data = Handle<String>()); |
| 772 | |
| 773 | /** |
| 774 | * Compiles the specified script using the specified file name |
| 775 | * object (typically a string) as the script's origin. |
| 776 | * |
| 777 | * \param source Script source code. |
| 778 | * \param file_name File name to use as script's origin |
| 779 | * \param script_data Arbitrary data associated with script. Using |
| 780 | * this has same effect as calling SetData(), but makes data available |
| 781 | * earlier (i.e. to compile event handlers). |
| 782 | * \return Compiled script object, bound to the context that was active |
| 783 | * when this function was called. When run it will always use this |
| 784 | * context. |
| 785 | */ |
| 786 | static Local<Script> Compile(Handle<String> source, |
| 787 | Handle<Value> file_name, |
| 788 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 789 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 790 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 791 | * Runs the script returning the resulting value. If the script is |
| 792 | * context independent (created using ::New) it will be run in the |
| 793 | * currently entered context. If it is context specific (created |
| 794 | * using ::Compile) it will be run in the context in which it was |
| 795 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 796 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 798 | |
| 799 | /** |
| 800 | * Returns the script id value. |
| 801 | */ |
| 802 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 803 | |
| 804 | /** |
| 805 | * Associate an additional data object with the script. This is mainly used |
| 806 | * with the debugger as this data object is only available through the |
| 807 | * debugger API. |
| 808 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 809 | void SetData(Handle<String> data); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 810 | |
| 811 | /** |
| 812 | * Returns the name value of one Script. |
| 813 | */ |
| 814 | Handle<Value> GetScriptName(); |
| 815 | |
| 816 | /** |
| 817 | * Returns zero based line number of the code_pos location in the script. |
| 818 | * -1 will be returned if no information available. |
| 819 | */ |
| 820 | int GetLineNumber(int code_pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 821 | }; |
| 822 | |
| 823 | |
| 824 | /** |
| 825 | * An error message. |
| 826 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 827 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 828 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 829 | Local<String> Get() const; |
| 830 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 832 | /** |
| 833 | * Returns the resource name for the script from where the function causing |
| 834 | * the error originates. |
| 835 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 836 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 837 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 838 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 839 | * Returns the resource data for the script from where the function causing |
| 840 | * the error originates. |
| 841 | */ |
| 842 | Handle<Value> GetScriptData() const; |
| 843 | |
| 844 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 845 | * Exception stack trace. By default stack traces are not captured for |
| 846 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 847 | * to change this option. |
| 848 | */ |
| 849 | Handle<StackTrace> GetStackTrace() const; |
| 850 | |
| 851 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 852 | * Returns the number, 1-based, of the line where the error occurred. |
| 853 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 854 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 856 | /** |
| 857 | * Returns the index within the script of the first character where |
| 858 | * the error occurred. |
| 859 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 860 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 861 | |
| 862 | /** |
| 863 | * Returns the index within the script of the last character where |
| 864 | * the error occurred. |
| 865 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 866 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 867 | |
| 868 | /** |
| 869 | * Returns the index within the line of the first character where |
| 870 | * the error occurred. |
| 871 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 872 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 873 | |
| 874 | /** |
| 875 | * Returns the index within the line of the last character where |
| 876 | * the error occurred. |
| 877 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 878 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 879 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 880 | // TODO(1245381): Print to a string instead of on a FILE. |
| 881 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 882 | |
| 883 | static const int kNoLineNumberInfo = 0; |
| 884 | static const int kNoColumnInfo = 0; |
| 885 | }; |
| 886 | |
| 887 | |
| 888 | /** |
| 889 | * Representation of a JavaScript stack trace. The information collected is a |
| 890 | * snapshot of the execution stack and the information remains valid after |
| 891 | * execution continues. |
| 892 | */ |
| 893 | class V8EXPORT StackTrace { |
| 894 | public: |
| 895 | /** |
| 896 | * Flags that determine what information is placed captured for each |
| 897 | * StackFrame when grabbing the current stack trace. |
| 898 | */ |
| 899 | enum StackTraceOptions { |
| 900 | kLineNumber = 1, |
| 901 | kColumnOffset = 1 << 1 | kLineNumber, |
| 902 | kScriptName = 1 << 2, |
| 903 | kFunctionName = 1 << 3, |
| 904 | kIsEval = 1 << 4, |
| 905 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 906 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 907 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 908 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 909 | }; |
| 910 | |
| 911 | /** |
| 912 | * Returns a StackFrame at a particular index. |
| 913 | */ |
| 914 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 915 | |
| 916 | /** |
| 917 | * Returns the number of StackFrames. |
| 918 | */ |
| 919 | int GetFrameCount() const; |
| 920 | |
| 921 | /** |
| 922 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 923 | */ |
| 924 | Local<Array> AsArray(); |
| 925 | |
| 926 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 927 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 928 | * |
| 929 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 930 | * \param options Enumerates the set of things we will capture for each |
| 931 | * StackFrame. |
| 932 | */ |
| 933 | static Local<StackTrace> CurrentStackTrace( |
| 934 | int frame_limit, |
| 935 | StackTraceOptions options = kOverview); |
| 936 | }; |
| 937 | |
| 938 | |
| 939 | /** |
| 940 | * A single JavaScript stack frame. |
| 941 | */ |
| 942 | class V8EXPORT StackFrame { |
| 943 | public: |
| 944 | /** |
| 945 | * Returns the number, 1-based, of the line for the associate function call. |
| 946 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 947 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 948 | * when capturing the StackTrace. |
| 949 | */ |
| 950 | int GetLineNumber() const; |
| 951 | |
| 952 | /** |
| 953 | * Returns the 1-based column offset on the line for the associated function |
| 954 | * call. |
| 955 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 956 | * the column number, or if kColumnOffset was not passed as an option when |
| 957 | * capturing the StackTrace. |
| 958 | */ |
| 959 | int GetColumn() const; |
| 960 | |
| 961 | /** |
| 962 | * Returns the name of the resource that contains the script for the |
| 963 | * function for this StackFrame. |
| 964 | */ |
| 965 | Local<String> GetScriptName() const; |
| 966 | |
| 967 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 968 | * Returns the name of the resource that contains the script for the |
| 969 | * function for this StackFrame or sourceURL value if the script name |
| 970 | * is undefined and its source ends with //@ sourceURL=... string. |
| 971 | */ |
| 972 | Local<String> GetScriptNameOrSourceURL() const; |
| 973 | |
| 974 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 975 | * Returns the name of the function associated with this stack frame. |
| 976 | */ |
| 977 | Local<String> GetFunctionName() const; |
| 978 | |
| 979 | /** |
| 980 | * Returns whether or not the associated function is compiled via a call to |
| 981 | * eval(). |
| 982 | */ |
| 983 | bool IsEval() const; |
| 984 | |
| 985 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 986 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 987 | * constructor via "new". |
| 988 | */ |
| 989 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | }; |
| 991 | |
| 992 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 993 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 994 | |
| 995 | |
| 996 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 997 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 998 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 999 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1000 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | /** |
| 1002 | * Returns true if this value is the undefined value. See ECMA-262 |
| 1003 | * 4.3.10. |
| 1004 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1005 | V8_INLINE(bool IsUndefined() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1006 | |
| 1007 | /** |
| 1008 | * Returns true if this value is the null value. See ECMA-262 |
| 1009 | * 4.3.11. |
| 1010 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1011 | V8_INLINE(bool IsNull() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1012 | |
| 1013 | /** |
| 1014 | * Returns true if this value is true. |
| 1015 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1016 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1017 | |
| 1018 | /** |
| 1019 | * Returns true if this value is false. |
| 1020 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1021 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1022 | |
| 1023 | /** |
| 1024 | * Returns true if this value is an instance of the String type. |
| 1025 | * See ECMA-262 8.4. |
| 1026 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1027 | V8_INLINE(bool IsString() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1028 | |
| 1029 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1030 | * Returns true if this value is a symbol. |
| 1031 | * This is an experimental feature. |
| 1032 | */ |
| 1033 | bool IsSymbol() const; |
| 1034 | |
| 1035 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1036 | * Returns true if this value is a function. |
| 1037 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1038 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1039 | |
| 1040 | /** |
| 1041 | * Returns true if this value is an array. |
| 1042 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1043 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1044 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1045 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1046 | * Returns true if this value is an object. |
| 1047 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1048 | bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1049 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1050 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1051 | * Returns true if this value is boolean. |
| 1052 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1053 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1054 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1055 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | * Returns true if this value is a number. |
| 1057 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1058 | bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1059 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1060 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1061 | * Returns true if this value is external. |
| 1062 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1063 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1064 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1065 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1066 | * Returns true if this value is a 32-bit signed integer. |
| 1067 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1068 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1069 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1070 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1071 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1072 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1073 | bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1074 | |
| 1075 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1076 | * Returns true if this value is a Date. |
| 1077 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1078 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1079 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1080 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1081 | * Returns true if this value is a Boolean object. |
| 1082 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1083 | bool IsBooleanObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1084 | |
| 1085 | /** |
| 1086 | * Returns true if this value is a Number object. |
| 1087 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1088 | bool IsNumberObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1089 | |
| 1090 | /** |
| 1091 | * Returns true if this value is a String object. |
| 1092 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1093 | bool IsStringObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1094 | |
| 1095 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1096 | * Returns true if this value is a Symbol object. |
| 1097 | * This is an experimental feature. |
| 1098 | */ |
| 1099 | bool IsSymbolObject() const; |
| 1100 | |
| 1101 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1102 | * Returns true if this value is a NativeError. |
| 1103 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1104 | bool IsNativeError() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1105 | |
| 1106 | /** |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1107 | * Returns true if this value is a RegExp. |
| 1108 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1109 | bool IsRegExp() const; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1110 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1111 | Local<Boolean> ToBoolean() const; |
| 1112 | Local<Number> ToNumber() const; |
| 1113 | Local<String> ToString() const; |
| 1114 | Local<String> ToDetailString() const; |
| 1115 | Local<Object> ToObject() const; |
| 1116 | Local<Integer> ToInteger() const; |
| 1117 | Local<Uint32> ToUint32() const; |
| 1118 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1119 | |
| 1120 | /** |
| 1121 | * Attempts to convert a string to an array index. |
| 1122 | * Returns an empty handle if the conversion fails. |
| 1123 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1124 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1125 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1126 | bool BooleanValue() const; |
| 1127 | double NumberValue() const; |
| 1128 | int64_t IntegerValue() const; |
| 1129 | uint32_t Uint32Value() const; |
| 1130 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1131 | |
| 1132 | /** JS == */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1133 | bool Equals(Handle<Value> that) const; |
| 1134 | bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1135 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1136 | private: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1137 | V8_INLINE(bool QuickIsUndefined() const); |
| 1138 | V8_INLINE(bool QuickIsNull() const); |
| 1139 | V8_INLINE(bool QuickIsString() const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1140 | bool FullIsUndefined() const; |
| 1141 | bool FullIsNull() const; |
| 1142 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1143 | }; |
| 1144 | |
| 1145 | |
| 1146 | /** |
| 1147 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 1148 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1149 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1150 | |
| 1151 | |
| 1152 | /** |
| 1153 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 1154 | * or false value. |
| 1155 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1156 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1157 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1158 | bool Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1159 | V8_INLINE(static Handle<Boolean> New(bool value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1160 | }; |
| 1161 | |
| 1162 | |
| 1163 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1164 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1165 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1166 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1167 | public: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1168 | enum Encoding { |
| 1169 | UNKNOWN_ENCODING = 0x1, |
| 1170 | TWO_BYTE_ENCODING = 0x0, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1171 | ASCII_ENCODING = 0x4, |
| 1172 | ONE_BYTE_ENCODING = 0x4 |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1173 | }; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1174 | /** |
| 1175 | * Returns the number of characters in this string. |
| 1176 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1177 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1178 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1179 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1180 | * Returns the number of bytes in the UTF-8 encoded |
| 1181 | * representation of this string. |
| 1182 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1183 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1184 | |
| 1185 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 1186 | * This function is no longer useful. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1187 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 1188 | // TODO(dcarney): deprecate |
| 1189 | V8_INLINE(bool MayContainNonAscii()) const { return true; } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1190 | |
| 1191 | /** |
| 1192 | * Returns whether this string contains only one byte data. |
| 1193 | */ |
| 1194 | bool IsOneByte() const; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1195 | |
| 1196 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1197 | * Write the contents of the string to an external buffer. |
| 1198 | * If no arguments are given, expects the buffer to be large |
| 1199 | * enough to hold the entire string and NULL terminator. Copies |
| 1200 | * the contents of the string and the NULL terminator into the |
| 1201 | * buffer. |
| 1202 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1203 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1204 | * before the end of the buffer. |
| 1205 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1206 | * Copies up to length characters into the output buffer. |
| 1207 | * Only null-terminates if there is enough space in the buffer. |
| 1208 | * |
| 1209 | * \param buffer The buffer into which the string will be copied. |
| 1210 | * \param start The starting position within the string at which |
| 1211 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1212 | * \param length The number of characters to copy from the string. For |
| 1213 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1214 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1215 | * \param options Various options that might affect performance of this or |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1216 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1217 | * \return The number of characters copied to the buffer excluding the null |
| 1218 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1219 | * including the null terminator (if written). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1220 | */ |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1221 | enum WriteOptions { |
| 1222 | NO_OPTIONS = 0, |
| 1223 | HINT_MANY_WRITES_EXPECTED = 1, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1224 | NO_NULL_TERMINATION = 2, |
| 1225 | PRESERVE_ASCII_NULL = 4 |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1226 | }; |
| 1227 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1228 | // 16-bit character codes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1229 | int Write(uint16_t* buffer, |
| 1230 | int start = 0, |
| 1231 | int length = -1, |
| 1232 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1233 | // ASCII characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1234 | int WriteAscii(char* buffer, |
| 1235 | int start = 0, |
| 1236 | int length = -1, |
| 1237 | int options = NO_OPTIONS) const; |
| 1238 | // One byte characters. |
| 1239 | int WriteOneByte(uint8_t* buffer, |
| 1240 | int start = 0, |
| 1241 | int length = -1, |
| 1242 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1243 | // UTF-8 encoded characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1244 | int WriteUtf8(char* buffer, |
| 1245 | int length = -1, |
| 1246 | int* nchars_ref = NULL, |
| 1247 | int options = NO_OPTIONS) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1248 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1249 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1250 | * A zero length string. |
| 1251 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1252 | static v8::Local<v8::String> Empty(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1253 | V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate)); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1254 | |
| 1255 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1256 | * Returns true if the string is external |
| 1257 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1258 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1259 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1260 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1261 | * Returns true if the string is both external and ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1262 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1263 | bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1264 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1265 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1266 | public: |
| 1267 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1268 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1269 | protected: |
| 1270 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1271 | |
| 1272 | /** |
| 1273 | * Internally V8 will call this Dispose method when the external string |
| 1274 | * resource is no longer needed. The default implementation will use the |
| 1275 | * delete operator. This method can be overridden in subclasses to |
| 1276 | * control how allocated external string resources are disposed. |
| 1277 | */ |
| 1278 | virtual void Dispose() { delete this; } |
| 1279 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1280 | private: |
| 1281 | // Disallow copying and assigning. |
| 1282 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1283 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1284 | |
| 1285 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1286 | }; |
| 1287 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1288 | /** |
| 1289 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1290 | * buffer that resides outside V8's heap. Implement an |
| 1291 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1292 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1293 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1294 | class V8EXPORT ExternalStringResource |
| 1295 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1296 | public: |
| 1297 | /** |
| 1298 | * Override the destructor to manage the life cycle of the underlying |
| 1299 | * buffer. |
| 1300 | */ |
| 1301 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1302 | |
| 1303 | /** |
| 1304 | * The string data from the underlying buffer. |
| 1305 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1306 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1307 | |
| 1308 | /** |
| 1309 | * The length of the string. That is, the number of two-byte characters. |
| 1310 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1311 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1312 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1313 | protected: |
| 1314 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1315 | }; |
| 1316 | |
| 1317 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1318 | * An ExternalAsciiStringResource is a wrapper around an ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1319 | * string buffer that resides outside V8's heap. Implement an |
| 1320 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1321 | * underlying buffer. Note that the string data must be immutable |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1322 | * 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] | 1323 | * UTF-8, which would require special treatment internally in the |
| 1324 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1325 | * 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] | 1326 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1327 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1328 | class V8EXPORT ExternalAsciiStringResource |
| 1329 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1330 | public: |
| 1331 | /** |
| 1332 | * Override the destructor to manage the life cycle of the underlying |
| 1333 | * buffer. |
| 1334 | */ |
| 1335 | virtual ~ExternalAsciiStringResource() {} |
| 1336 | /** The string data from the underlying buffer.*/ |
| 1337 | virtual const char* data() const = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1338 | /** The number of ASCII characters in the string.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1339 | virtual size_t length() const = 0; |
| 1340 | protected: |
| 1341 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1342 | }; |
| 1343 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1344 | typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1345 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1346 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1347 | * If the string is an external string, return the ExternalStringResourceBase |
| 1348 | * regardless of the encoding, otherwise return NULL. The encoding of the |
| 1349 | * string is returned in encoding_out. |
| 1350 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1351 | V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
| 1352 | Encoding* encoding_out) const); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1353 | |
| 1354 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1355 | * Get the ExternalStringResource for an external string. Returns |
| 1356 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1357 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1358 | V8_INLINE(ExternalStringResource* GetExternalStringResource() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1359 | |
| 1360 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1361 | * Get the ExternalAsciiStringResource for an external ASCII string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1362 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1363 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1364 | const ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1365 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1366 | V8_INLINE(static String* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1367 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1368 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1369 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1370 | * 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] | 1371 | * The second parameter 'length' gives the buffer length. If omitted, |
| 1372 | * the function calls 'strlen' to determine the buffer length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1373 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1374 | V8_INLINE(static Local<String> New(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1375 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1376 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1377 | /** Allocates a new string from 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1378 | V8_INLINE(static Local<String> New(const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1379 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1380 | // TODO(dcarney): deprecate |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1381 | /** |
| 1382 | * Creates an internalized string (historically called a "symbol", |
| 1383 | * not to be confused with ES6 symbols). Returns one if it exists already. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1384 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1385 | V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1)); |
| 1386 | |
| 1387 | enum NewStringType { |
| 1388 | kNormalString, kInternalizedString, kUndetectableString |
| 1389 | }; |
| 1390 | |
| 1391 | /** Allocates a new string from UTF-8 data.*/ |
| 1392 | static Local<String> NewFromUtf8(Isolate* isolate, |
| 1393 | const char* data, |
| 1394 | NewStringType type = kNormalString, |
| 1395 | int length = -1); |
| 1396 | |
| 1397 | /** Allocates a new string from Latin-1 data.*/ |
| 1398 | static Local<String> NewFromOneByte( |
| 1399 | Isolate* isolate, |
| 1400 | const uint8_t* data, |
| 1401 | NewStringType type = kNormalString, |
| 1402 | int length = -1); |
| 1403 | |
| 1404 | /** Allocates a new string from UTF-16 data.*/ |
| 1405 | static Local<String> NewFromTwoByte( |
| 1406 | Isolate* isolate, |
| 1407 | const uint16_t* data, |
| 1408 | NewStringType type = kNormalString, |
| 1409 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1410 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1411 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1412 | * Creates a new string by concatenating the left and the right strings |
| 1413 | * passed in as parameters. |
| 1414 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1415 | 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] | 1416 | |
| 1417 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1418 | * 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] | 1419 | * 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] | 1420 | * resource will be disposed by calling its Dispose method. The caller of |
| 1421 | * this function should not otherwise delete or modify the resource. Neither |
| 1422 | * should the underlying buffer be deallocated or modified except through the |
| 1423 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1424 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1425 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1426 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1427 | /** |
| 1428 | * Associate an external string resource with this string by transforming it |
| 1429 | * in place so that existing references to this string in the JavaScript heap |
| 1430 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1431 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1432 | * 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] | 1433 | * The string is not modified if the operation fails. See NewExternal for |
| 1434 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1435 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1436 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1437 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1438 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1439 | * 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] | 1440 | * 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] | 1441 | * resource will be disposed by calling its Dispose method. The caller of |
| 1442 | * this function should not otherwise delete or modify the resource. Neither |
| 1443 | * should the underlying buffer be deallocated or modified except through the |
| 1444 | * destructor of the external string resource. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1445 | */ |
| 1446 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1447 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1448 | /** |
| 1449 | * Associate an external string resource with this string by transforming it |
| 1450 | * in place so that existing references to this string in the JavaScript heap |
| 1451 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1452 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1453 | * 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] | 1454 | * The string is not modified if the operation fails. See NewExternal for |
| 1455 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1456 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1457 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1458 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1459 | /** |
| 1460 | * Returns true if this string can be made external. |
| 1461 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1462 | bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1463 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1464 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1465 | /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1466 | V8_INLINE( |
| 1467 | static Local<String> NewUndetectable(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1468 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1469 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1470 | /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1471 | V8_INLINE(static Local<String> NewUndetectable( |
| 1472 | const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1473 | |
| 1474 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1475 | * 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] | 1476 | * 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] | 1477 | * (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] | 1478 | * then the length() method returns 0 and the * operator returns |
| 1479 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1480 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1481 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1482 | public: |
| 1483 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1484 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1485 | char* operator*() { return str_; } |
| 1486 | const char* operator*() const { return str_; } |
| 1487 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1488 | private: |
| 1489 | char* str_; |
| 1490 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1491 | |
| 1492 | // Disallow copying and assigning. |
| 1493 | Utf8Value(const Utf8Value&); |
| 1494 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1495 | }; |
| 1496 | |
| 1497 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1498 | * Converts an object to an ASCII string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1499 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1500 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1501 | * method of the object) then the length() method returns 0 and the * operator |
| 1502 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1503 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1504 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1505 | public: |
| 1506 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1507 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1508 | char* operator*() { return str_; } |
| 1509 | const char* operator*() const { return str_; } |
| 1510 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1511 | private: |
| 1512 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1513 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1514 | |
| 1515 | // Disallow copying and assigning. |
| 1516 | AsciiValue(const AsciiValue&); |
| 1517 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1518 | }; |
| 1519 | |
| 1520 | /** |
| 1521 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1522 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1523 | * method of the object) then the length() method returns 0 and the * operator |
| 1524 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1525 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1526 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1527 | public: |
| 1528 | explicit Value(Handle<v8::Value> obj); |
| 1529 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1530 | uint16_t* operator*() { return str_; } |
| 1531 | const uint16_t* operator*() const { return str_; } |
| 1532 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1533 | private: |
| 1534 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1535 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1536 | |
| 1537 | // Disallow copying and assigning. |
| 1538 | Value(const Value&); |
| 1539 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1540 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1541 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1542 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1543 | void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1544 | Encoding encoding) const; |
| 1545 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1546 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1547 | }; |
| 1548 | |
| 1549 | |
| 1550 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1551 | * A JavaScript symbol (ECMA-262 edition 6) |
| 1552 | * |
| 1553 | * This is an experimental feature. Use at your own risk. |
| 1554 | */ |
| 1555 | class V8EXPORT Symbol : public Primitive { |
| 1556 | public: |
| 1557 | // Returns the print name string of the symbol, or undefined if none. |
| 1558 | Local<Value> Name() const; |
| 1559 | |
| 1560 | // Create a symbol without a print name. |
| 1561 | static Local<Symbol> New(Isolate* isolate); |
| 1562 | |
| 1563 | // Create a symbol with a print name. |
| 1564 | static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); |
| 1565 | |
| 1566 | V8_INLINE(static Symbol* Cast(v8::Value* obj)); |
| 1567 | private: |
| 1568 | Symbol(); |
| 1569 | static void CheckCast(v8::Value* obj); |
| 1570 | }; |
| 1571 | |
| 1572 | |
| 1573 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1574 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1575 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1576 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1577 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1578 | double Value() const; |
| 1579 | static Local<Number> New(double value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1580 | V8_INLINE(static Number* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1581 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1582 | Number(); |
| 1583 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1584 | }; |
| 1585 | |
| 1586 | |
| 1587 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1588 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1589 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1590 | class V8EXPORT Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1591 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1592 | static Local<Integer> New(int32_t value); |
| 1593 | static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1594 | static Local<Integer> New(int32_t value, Isolate*); |
| 1595 | static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); |
| 1596 | int64_t Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1597 | V8_INLINE(static Integer* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1598 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1599 | Integer(); |
| 1600 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1601 | }; |
| 1602 | |
| 1603 | |
| 1604 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1605 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1607 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1608 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1609 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1610 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1611 | Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1612 | }; |
| 1613 | |
| 1614 | |
| 1615 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1616 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1617 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1618 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1619 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1620 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1621 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1622 | Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1623 | }; |
| 1624 | |
| 1625 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1626 | enum PropertyAttribute { |
| 1627 | None = 0, |
| 1628 | ReadOnly = 1 << 0, |
| 1629 | DontEnum = 1 << 1, |
| 1630 | DontDelete = 1 << 2 |
| 1631 | }; |
| 1632 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1633 | enum ExternalArrayType { |
| 1634 | kExternalByteArray = 1, |
| 1635 | kExternalUnsignedByteArray, |
| 1636 | kExternalShortArray, |
| 1637 | kExternalUnsignedShortArray, |
| 1638 | kExternalIntArray, |
| 1639 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1640 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1641 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1642 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1643 | }; |
| 1644 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1646 | * Accessor[Getter|Setter] are used as callback functions when |
| 1647 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1648 | * method SetAccessor. |
| 1649 | */ |
| 1650 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1651 | const AccessorInfo& info); |
| 1652 | |
| 1653 | |
| 1654 | typedef void (*AccessorSetter)(Local<String> property, |
| 1655 | Local<Value> value, |
| 1656 | const AccessorInfo& info); |
| 1657 | |
| 1658 | |
| 1659 | /** |
| 1660 | * Access control specifications. |
| 1661 | * |
| 1662 | * Some accessors should be accessible across contexts. These |
| 1663 | * accessors have an explicit access control parameter which specifies |
| 1664 | * the kind of cross-context access that should be allowed. |
| 1665 | * |
| 1666 | * Additionally, for security, accessors can prohibit overwriting by |
| 1667 | * accessors defined in JavaScript. For objects that have such |
| 1668 | * accessors either locally or in their prototype chain it is not |
| 1669 | * possible to overwrite the accessor by using __defineGetter__ or |
| 1670 | * __defineSetter__ from JavaScript code. |
| 1671 | */ |
| 1672 | enum AccessControl { |
| 1673 | DEFAULT = 0, |
| 1674 | ALL_CAN_READ = 1, |
| 1675 | ALL_CAN_WRITE = 1 << 1, |
| 1676 | PROHIBITS_OVERWRITING = 1 << 2 |
| 1677 | }; |
| 1678 | |
| 1679 | |
| 1680 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1681 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1682 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1683 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1684 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1685 | bool Set(Handle<Value> key, |
| 1686 | Handle<Value> value, |
| 1687 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1688 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1689 | bool Set(uint32_t index, Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1690 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1691 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1692 | // overriding accessors or read-only properties. |
| 1693 | // |
| 1694 | // Note that if the object has an interceptor the property will be set |
| 1695 | // locally, but since the interceptor takes precedence the local property |
| 1696 | // will only be returned if the interceptor doesn't return a value. |
| 1697 | // |
| 1698 | // Note also that this only works for named properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1699 | bool ForceSet(Handle<Value> key, |
| 1700 | Handle<Value> value, |
| 1701 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1702 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1703 | Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1704 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1705 | Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1706 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1707 | /** |
| 1708 | * Gets the property attributes of a property which can be None or |
| 1709 | * any combination of ReadOnly, DontEnum and DontDelete. Returns |
| 1710 | * None when the property doesn't exist. |
| 1711 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1712 | PropertyAttribute GetPropertyAttributes(Handle<Value> key); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1713 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1714 | bool Has(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1715 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1716 | bool Delete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1717 | |
| 1718 | // Delete a property on this object bypassing interceptors and |
| 1719 | // ignoring dont-delete attributes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1720 | bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1721 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1722 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1723 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1724 | bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1725 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1726 | bool SetAccessor(Handle<String> name, |
| 1727 | AccessorGetter getter, |
| 1728 | AccessorSetter setter = 0, |
| 1729 | Handle<Value> data = Handle<Value>(), |
| 1730 | AccessControl settings = DEFAULT, |
| 1731 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1732 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1733 | // This function is not yet stable and should not be used at this time. |
| 1734 | bool SetAccessor(Handle<String> name, |
| 1735 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 1736 | AccessControl settings = DEFAULT, |
| 1737 | PropertyAttribute attribute = None); |
| 1738 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1739 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1740 | * Returns an array containing the names of the enumerable properties |
| 1741 | * of this object, including properties from prototype objects. The |
| 1742 | * array returned by this method contains the same values as would |
| 1743 | * be enumerated by a for-in statement over this object. |
| 1744 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1745 | Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1746 | |
| 1747 | /** |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1748 | * This function has the same functionality as GetPropertyNames but |
| 1749 | * the returned array doesn't contain the names of properties from |
| 1750 | * prototype objects. |
| 1751 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1752 | Local<Array> GetOwnPropertyNames(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1753 | |
| 1754 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1755 | * Get the prototype object. This does not skip objects marked to |
| 1756 | * be skipped by __proto__ and it does not consult the security |
| 1757 | * handler. |
| 1758 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1759 | Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1760 | |
| 1761 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1762 | * Set the prototype object. This does not skip objects marked to |
| 1763 | * be skipped by __proto__ and it does not consult the security |
| 1764 | * handler. |
| 1765 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1766 | bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1767 | |
| 1768 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 1769 | * Finds an instance of the given function template in the prototype |
| 1770 | * chain. |
| 1771 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1772 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 1773 | |
| 1774 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1775 | * Call builtin Object.prototype.toString on this object. |
| 1776 | * This is different from Value::ToString() that may call |
| 1777 | * user-defined toString function. This one does not. |
| 1778 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1779 | Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1780 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 1781 | /** |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 1782 | * Returns the function invoked as a constructor for this object. |
| 1783 | * May be the null value. |
| 1784 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1785 | Local<Value> GetConstructor(); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 1786 | |
| 1787 | /** |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 1788 | * Returns the name of the function invoked as a constructor for this object. |
| 1789 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1790 | Local<String> GetConstructorName(); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 1791 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1792 | /** Gets the number of internal fields for this Object. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1793 | int InternalFieldCount(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1794 | |
| 1795 | /** Gets the value from an internal field. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1796 | V8_INLINE(Local<Value> GetInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1797 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1798 | /** Sets the value in an internal field. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1799 | void SetInternalField(int index, Handle<Value> value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1800 | |
| 1801 | /** |
| 1802 | * Gets a 2-byte-aligned native pointer from an internal field. This field |
| 1803 | * must have been set by SetAlignedPointerInInternalField, everything else |
| 1804 | * leads to undefined behavior. |
| 1805 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1806 | V8_INLINE(void* GetAlignedPointerFromInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1807 | |
| 1808 | /** |
| 1809 | * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
| 1810 | * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 1811 | * leads to undefined behavior. |
| 1812 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1813 | void SetAlignedPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1814 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1815 | // Testers for local properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1816 | bool HasOwnProperty(Handle<String> key); |
| 1817 | bool HasRealNamedProperty(Handle<String> key); |
| 1818 | bool HasRealIndexedProperty(uint32_t index); |
| 1819 | bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | |
| 1821 | /** |
| 1822 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 1823 | * This means interceptors in the prototype chain are not called. |
| 1824 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1825 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 1826 | |
| 1827 | /** |
| 1828 | * If result.IsEmpty() no real property was located on the object or |
| 1829 | * in the prototype chain. |
| 1830 | * This means interceptors in the prototype chain are not called. |
| 1831 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1832 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1833 | |
| 1834 | /** Tests for a named lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1835 | bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1836 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1837 | /** Tests for an index lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1838 | bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1839 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1840 | /** |
| 1841 | * Turns on access check on the object if the object is an instance of |
| 1842 | * a template that has access check callbacks. If an object has no |
| 1843 | * access check info, the object cannot be accessed by anyone. |
| 1844 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1845 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 1846 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1847 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1848 | * Returns the identity hash for this object. The current implementation |
| 1849 | * 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] | 1850 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1851 | * 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] | 1852 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1853 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1854 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 1855 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1856 | /** |
| 1857 | * Access hidden properties on JavaScript objects. These properties are |
| 1858 | * hidden from the executing JavaScript and only accessible through the V8 |
| 1859 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 1860 | * identity hash) are prefixed with "v8::". |
| 1861 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1862 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 1863 | Local<Value> GetHiddenValue(Handle<String> key); |
| 1864 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1865 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1866 | /** |
| 1867 | * Returns true if this is an instance of an api function (one |
| 1868 | * created from a function created from a function template) and has |
| 1869 | * been modified since it was created. Note that this method is |
| 1870 | * conservative and may return true for objects that haven't actually |
| 1871 | * been modified. |
| 1872 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1873 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 1874 | |
| 1875 | /** |
| 1876 | * Clone this object with a fast but shallow copy. Values will point |
| 1877 | * to the same values as the original object. |
| 1878 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1879 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1881 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1882 | * Returns the context in which the object was created. |
| 1883 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1884 | Local<Context> CreationContext(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1885 | |
| 1886 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1887 | * Set the backing store of the indexed properties to be managed by the |
| 1888 | * embedding layer. Access to the indexed properties will follow the rules |
| 1889 | * spelled out in CanvasPixelArray. |
| 1890 | * Note: The embedding program still owns the data and needs to ensure that |
| 1891 | * the backing store is preserved while V8 has a reference. |
| 1892 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1893 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 1894 | bool HasIndexedPropertiesInPixelData(); |
| 1895 | uint8_t* GetIndexedPropertiesPixelData(); |
| 1896 | int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1897 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1898 | /** |
| 1899 | * Set the backing store of the indexed properties to be managed by the |
| 1900 | * embedding layer. Access to the indexed properties will follow the rules |
| 1901 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 1902 | * Note: The embedding program still owns the data and needs to ensure that |
| 1903 | * the backing store is preserved while V8 has a reference. |
| 1904 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1905 | void SetIndexedPropertiesToExternalArrayData(void* data, |
| 1906 | ExternalArrayType array_type, |
| 1907 | int number_of_elements); |
| 1908 | bool HasIndexedPropertiesInExternalArrayData(); |
| 1909 | void* GetIndexedPropertiesExternalArrayData(); |
| 1910 | ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 1911 | int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1912 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1913 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1914 | * Checks whether a callback is set by the |
| 1915 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1916 | * When an Object is callable this method returns true. |
| 1917 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1918 | bool IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1919 | |
| 1920 | /** |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1921 | * 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] | 1922 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1923 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1924 | Local<Value> CallAsFunction(Handle<Object> recv, |
| 1925 | int argc, |
| 1926 | Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1927 | |
| 1928 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1929 | * 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] | 1930 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1931 | * Note: This method behaves like the Function::NewInstance method. |
| 1932 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1933 | Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1934 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1935 | static Local<Object> New(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1936 | V8_INLINE(static Object* Cast(Value* obj)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1937 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1938 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1939 | Object(); |
| 1940 | static void CheckCast(Value* obj); |
| 1941 | Local<Value> SlowGetInternalField(int index); |
| 1942 | void* SlowGetAlignedPointerFromInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1943 | }; |
| 1944 | |
| 1945 | |
| 1946 | /** |
| 1947 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 1948 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1949 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1950 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1951 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1952 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1953 | /** |
| 1954 | * Clones an element at index |index|. Returns an empty |
| 1955 | * handle if cloning fails (for any reason). |
| 1956 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1957 | Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1958 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1959 | /** |
| 1960 | * Creates a JavaScript array with the given length. If the length |
| 1961 | * is negative the returned array will have length 0. |
| 1962 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1963 | static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1964 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1965 | V8_INLINE(static Array* Cast(Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1966 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1967 | Array(); |
| 1968 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1969 | }; |
| 1970 | |
| 1971 | |
| 1972 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1973 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1974 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1975 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1976 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1977 | Local<Object> NewInstance() const; |
| 1978 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 1979 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 1980 | void SetName(Handle<String> name); |
| 1981 | Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1982 | |
| 1983 | /** |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1984 | * Name inferred from variable or property assignment of this function. |
| 1985 | * Used to facilitate debugging and profiling of JavaScript code written |
| 1986 | * in an OO style, where many functions are anonymous but are assigned |
| 1987 | * to object properties. |
| 1988 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1989 | Handle<Value> GetInferredName() const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1990 | |
| 1991 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1992 | * Returns zero based line number of function body and |
| 1993 | * kLineOffsetNotFound if no information available. |
| 1994 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1995 | int GetScriptLineNumber() const; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1996 | /** |
| 1997 | * Returns zero based column number of function body and |
| 1998 | * kLineOffsetNotFound if no information available. |
| 1999 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2000 | int GetScriptColumnNumber() const; |
| 2001 | Handle<Value> GetScriptId() const; |
| 2002 | ScriptOrigin GetScriptOrigin() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2003 | V8_INLINE(static Function* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2004 | static const int kLineOffsetNotFound; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2005 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2006 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2007 | Function(); |
| 2008 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2009 | }; |
| 2010 | |
| 2011 | |
| 2012 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 2013 | * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 2014 | * This API is experimental and may change significantly. |
| 2015 | */ |
| 2016 | class V8EXPORT ArrayBuffer : public Object { |
| 2017 | public: |
| 2018 | /** |
| 2019 | * Data length in bytes. |
| 2020 | */ |
| 2021 | size_t ByteLength() const; |
| 2022 | /** |
| 2023 | * Raw pointer to the array buffer data |
| 2024 | */ |
| 2025 | void* Data() const; |
| 2026 | |
| 2027 | /** |
| 2028 | * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 2029 | * Allocated memory will be owned by a created ArrayBuffer and |
| 2030 | * will be deallocated when it is garbage-collected. |
| 2031 | */ |
| 2032 | static Local<ArrayBuffer> New(size_t byte_length); |
| 2033 | |
| 2034 | /** |
| 2035 | * Create a new ArrayBuffer over an existing memory block. |
| 2036 | * The memory block will not be reclaimed when a created ArrayBuffer |
| 2037 | * is garbage-collected. |
| 2038 | */ |
| 2039 | static Local<ArrayBuffer> New(void* data, size_t byte_length); |
| 2040 | |
| 2041 | V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
| 2042 | |
| 2043 | private: |
| 2044 | ArrayBuffer(); |
| 2045 | static void CheckCast(Value* obj); |
| 2046 | }; |
| 2047 | |
| 2048 | |
| 2049 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2050 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 2051 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2052 | class V8EXPORT Date : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2053 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2054 | static Local<Value> New(double time); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2055 | |
| 2056 | /** |
| 2057 | * A specialization of Value::NumberValue that is more efficient |
| 2058 | * because we know the structure of this object. |
| 2059 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2060 | double NumberValue() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2061 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2062 | V8_INLINE(static Date* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2063 | |
| 2064 | /** |
| 2065 | * Notification that the embedder has changed the time zone, |
| 2066 | * daylight savings time, or other date / time configuration |
| 2067 | * parameters. V8 keeps a cache of various values used for |
| 2068 | * date / time computation. This notification will reset |
| 2069 | * those cached values for the current context so that date / |
| 2070 | * time configuration changes would be reflected in the Date |
| 2071 | * object. |
| 2072 | * |
| 2073 | * This API should not be called more than needed as it will |
| 2074 | * negatively impact the performance of date operations. |
| 2075 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2076 | static void DateTimeConfigurationChangeNotification(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2077 | |
| 2078 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2079 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2080 | }; |
| 2081 | |
| 2082 | |
| 2083 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2084 | * A Number object (ECMA-262, 4.3.21). |
| 2085 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2086 | class V8EXPORT NumberObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2087 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2088 | static Local<Value> New(double value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2089 | |
| 2090 | /** |
| 2091 | * Returns the Number held by the object. |
| 2092 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2093 | double NumberValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2094 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2095 | V8_INLINE(static NumberObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2096 | |
| 2097 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2098 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2099 | }; |
| 2100 | |
| 2101 | |
| 2102 | /** |
| 2103 | * A Boolean object (ECMA-262, 4.3.15). |
| 2104 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2105 | class V8EXPORT BooleanObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2106 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2107 | static Local<Value> New(bool value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2108 | |
| 2109 | /** |
| 2110 | * Returns the Boolean held by the object. |
| 2111 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2112 | bool BooleanValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2113 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2114 | V8_INLINE(static BooleanObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2115 | |
| 2116 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2117 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2118 | }; |
| 2119 | |
| 2120 | |
| 2121 | /** |
| 2122 | * A String object (ECMA-262, 4.3.18). |
| 2123 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2124 | class V8EXPORT StringObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2125 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2126 | static Local<Value> New(Handle<String> value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2127 | |
| 2128 | /** |
| 2129 | * Returns the String held by the object. |
| 2130 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2131 | Local<String> StringValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2132 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2133 | V8_INLINE(static StringObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2134 | |
| 2135 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2136 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2137 | }; |
| 2138 | |
| 2139 | |
| 2140 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2141 | * A Symbol object (ECMA-262 edition 6). |
| 2142 | * |
| 2143 | * This is an experimental feature. Use at your own risk. |
| 2144 | */ |
| 2145 | class V8EXPORT SymbolObject : public Object { |
| 2146 | public: |
| 2147 | static Local<Value> New(Isolate* isolate, Handle<Symbol> value); |
| 2148 | |
| 2149 | /** |
| 2150 | * Returns the Symbol held by the object. |
| 2151 | */ |
| 2152 | Local<Symbol> SymbolValue() const; |
| 2153 | |
| 2154 | V8_INLINE(static SymbolObject* Cast(v8::Value* obj)); |
| 2155 | |
| 2156 | private: |
| 2157 | static void CheckCast(v8::Value* obj); |
| 2158 | }; |
| 2159 | |
| 2160 | |
| 2161 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2162 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 2163 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2164 | class V8EXPORT RegExp : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2165 | public: |
| 2166 | /** |
| 2167 | * Regular expression flag bits. They can be or'ed to enable a set |
| 2168 | * of flags. |
| 2169 | */ |
| 2170 | enum Flags { |
| 2171 | kNone = 0, |
| 2172 | kGlobal = 1, |
| 2173 | kIgnoreCase = 2, |
| 2174 | kMultiline = 4 |
| 2175 | }; |
| 2176 | |
| 2177 | /** |
| 2178 | * Creates a regular expression from the given pattern string and |
| 2179 | * the flags bit field. May throw a JavaScript exception as |
| 2180 | * described in ECMA-262, 15.10.4.1. |
| 2181 | * |
| 2182 | * For example, |
| 2183 | * RegExp::New(v8::String::New("foo"), |
| 2184 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 2185 | * is equivalent to evaluating "/foo/gm". |
| 2186 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2187 | static Local<RegExp> New(Handle<String> pattern, Flags flags); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2188 | |
| 2189 | /** |
| 2190 | * Returns the value of the source property: a string representing |
| 2191 | * the regular expression. |
| 2192 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2193 | Local<String> GetSource() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2194 | |
| 2195 | /** |
| 2196 | * Returns the flags bit field. |
| 2197 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2198 | Flags GetFlags() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2199 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2200 | V8_INLINE(static RegExp* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2201 | |
| 2202 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2203 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2204 | }; |
| 2205 | |
| 2206 | |
| 2207 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2208 | * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
| 2209 | * to associate C++ data structures with JavaScript objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2210 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2211 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2212 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2213 | static Local<External> New(void* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2214 | V8_INLINE(static External* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2215 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2216 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2217 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2218 | }; |
| 2219 | |
| 2220 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2221 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2222 | |
| 2223 | |
| 2224 | /** |
| 2225 | * The superclass of object and function templates. |
| 2226 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2227 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2228 | public: |
| 2229 | /** Adds a property to each instance created by this template.*/ |
| 2230 | void Set(Handle<String> name, Handle<Data> value, |
| 2231 | PropertyAttribute attributes = None); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2232 | V8_INLINE(void Set(const char* name, Handle<Data> value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2233 | private: |
| 2234 | Template(); |
| 2235 | |
| 2236 | friend class ObjectTemplate; |
| 2237 | friend class FunctionTemplate; |
| 2238 | }; |
| 2239 | |
| 2240 | |
| 2241 | /** |
| 2242 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2243 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2244 | * including the receiver, the number and values of arguments, and |
| 2245 | * the holder of the function. |
| 2246 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2247 | class V8EXPORT Arguments { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2248 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2249 | V8_INLINE(int Length() const); |
| 2250 | V8_INLINE(Local<Value> operator[](int i) const); |
| 2251 | V8_INLINE(Local<Function> Callee() const); |
| 2252 | V8_INLINE(Local<Object> This() const); |
| 2253 | V8_INLINE(Local<Object> Holder() const); |
| 2254 | V8_INLINE(bool IsConstructCall() const); |
| 2255 | V8_INLINE(Local<Value> Data() const); |
| 2256 | V8_INLINE(Isolate* GetIsolate() const); |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2257 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2258 | private: |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2259 | static const int kIsolateIndex = 0; |
| 2260 | static const int kDataIndex = -1; |
| 2261 | static const int kCalleeIndex = -2; |
| 2262 | static const int kHolderIndex = -3; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2263 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2264 | friend class ImplementationUtilities; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2265 | V8_INLINE(Arguments(internal::Object** implicit_args, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2266 | internal::Object** values, |
| 2267 | int length, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2268 | bool is_construct_call)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2269 | internal::Object** implicit_args_; |
| 2270 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2271 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2272 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2273 | }; |
| 2274 | |
| 2275 | |
| 2276 | /** |
| 2277 | * The information passed to an accessor callback about the context |
| 2278 | * of the property access. |
| 2279 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2280 | class V8EXPORT AccessorInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2281 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2282 | V8_INLINE(AccessorInfo(internal::Object** args)) |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2283 | : args_(args) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2284 | V8_INLINE(Isolate* GetIsolate() const); |
| 2285 | V8_INLINE(Local<Value> Data() const); |
| 2286 | V8_INLINE(Local<Object> This() const); |
| 2287 | V8_INLINE(Local<Object> Holder() const); |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2288 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2289 | private: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2290 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2291 | }; |
| 2292 | |
| 2293 | |
| 2294 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
| 2295 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2296 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2297 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 2298 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 2299 | */ |
| 2300 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 2301 | const AccessorInfo& info); |
| 2302 | |
| 2303 | |
| 2304 | /** |
| 2305 | * Returns the value if the setter intercepts the request. |
| 2306 | * Otherwise, returns an empty handle. |
| 2307 | */ |
| 2308 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 2309 | Local<Value> value, |
| 2310 | const AccessorInfo& info); |
| 2311 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2312 | /** |
| 2313 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2314 | * The result is an integer encoding property attributes (like v8::None, |
| 2315 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2316 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2317 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 2318 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2319 | |
| 2320 | |
| 2321 | /** |
| 2322 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2323 | * The return value is true if the property could be deleted and false |
| 2324 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2325 | */ |
| 2326 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 2327 | const AccessorInfo& info); |
| 2328 | |
| 2329 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2330 | * Returns an array containing the names of the properties the named |
| 2331 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2332 | */ |
| 2333 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
| 2334 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2335 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2336 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2337 | * Returns the value of the property if the getter intercepts the |
| 2338 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2339 | */ |
| 2340 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 2341 | const AccessorInfo& info); |
| 2342 | |
| 2343 | |
| 2344 | /** |
| 2345 | * Returns the value if the setter intercepts the request. |
| 2346 | * Otherwise, returns an empty handle. |
| 2347 | */ |
| 2348 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 2349 | Local<Value> value, |
| 2350 | const AccessorInfo& info); |
| 2351 | |
| 2352 | |
| 2353 | /** |
| 2354 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2355 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2356 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2357 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 2358 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2359 | |
| 2360 | /** |
| 2361 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2362 | * The return value is true if the property could be deleted and false |
| 2363 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2364 | */ |
| 2365 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 2366 | const AccessorInfo& info); |
| 2367 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2368 | /** |
| 2369 | * Returns an array containing the indices of the properties the |
| 2370 | * indexed property getter intercepts. |
| 2371 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2372 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
| 2373 | |
| 2374 | |
| 2375 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2376 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2377 | */ |
| 2378 | enum AccessType { |
| 2379 | ACCESS_GET, |
| 2380 | ACCESS_SET, |
| 2381 | ACCESS_HAS, |
| 2382 | ACCESS_DELETE, |
| 2383 | ACCESS_KEYS |
| 2384 | }; |
| 2385 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2386 | |
| 2387 | /** |
| 2388 | * 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] | 2389 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2390 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2391 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2392 | Local<Value> key, |
| 2393 | AccessType type, |
| 2394 | Local<Value> data); |
| 2395 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2396 | |
| 2397 | /** |
| 2398 | * 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] | 2399 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2400 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2401 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2402 | uint32_t index, |
| 2403 | AccessType type, |
| 2404 | Local<Value> data); |
| 2405 | |
| 2406 | |
| 2407 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2408 | * A FunctionTemplate is used to create functions at runtime. There |
| 2409 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2410 | * context. The lifetime of the created function is equal to the |
| 2411 | * lifetime of the context. So in case the embedder needs to create |
| 2412 | * temporary functions that can be collected using Scripts is |
| 2413 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2414 | * |
| 2415 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2416 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2417 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2418 | * A FunctionTemplate has a corresponding instance template which is |
| 2419 | * used to create object instances when the function is used as a |
| 2420 | * constructor. Properties added to the instance template are added to |
| 2421 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2422 | * |
| 2423 | * A FunctionTemplate can have a prototype template. The prototype template |
| 2424 | * is used to create the prototype object of the function. |
| 2425 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2426 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2427 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2428 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2429 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 2430 | * t->Set("func_property", v8::Number::New(1)); |
| 2431 | * |
| 2432 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 2433 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 2434 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 2435 | * |
| 2436 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 2437 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 2438 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 2439 | * instance_t->Set("instance_property", Number::New(3)); |
| 2440 | * |
| 2441 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 2442 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2443 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2444 | * |
| 2445 | * 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] | 2446 | * and "instance" for the instance object created above. The function |
| 2447 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2448 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2449 | * \code |
| 2450 | * func_property in function == true; |
| 2451 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2452 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2453 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 2454 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2455 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2456 | * instance instanceof function == true; |
| 2457 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 2458 | * instance.instance_property == 3; |
| 2459 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2460 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2461 | * A FunctionTemplate can inherit from another one by calling the |
| 2462 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 2463 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2464 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2465 | * \code |
| 2466 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 2467 | * ^ ^ |
| 2468 | * | Inherit(Parent) | .__proto__ |
| 2469 | * | | |
| 2470 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 2471 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2472 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2473 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 2474 | * object of the Child() function has __proto__ pointing to the |
| 2475 | * Parent() function's prototype object. An instance of the Child |
| 2476 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2477 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2478 | * Let Parent be the FunctionTemplate initialized in the previous |
| 2479 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2480 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2481 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2482 | * Local<FunctionTemplate> parent = t; |
| 2483 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 2484 | * child->Inherit(parent); |
| 2485 | * |
| 2486 | * Local<Function> child_function = child->GetFunction(); |
| 2487 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2488 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2489 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2490 | * The Child function and Child instance will have the following |
| 2491 | * properties: |
| 2492 | * |
| 2493 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2494 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2495 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2496 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2497 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2498 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2499 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2500 | public: |
| 2501 | /** Creates a function template.*/ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2502 | static Local<FunctionTemplate> New( |
| 2503 | InvocationCallback callback = 0, |
| 2504 | Handle<Value> data = Handle<Value>(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2505 | Handle<Signature> signature = Handle<Signature>(), |
| 2506 | int length = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2507 | /** Returns the unique function instance in the current execution context.*/ |
| 2508 | Local<Function> GetFunction(); |
| 2509 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2510 | /** |
| 2511 | * Set the call-handler callback for a FunctionTemplate. This |
| 2512 | * callback is called whenever the function created from this |
| 2513 | * FunctionTemplate is called. |
| 2514 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2515 | void SetCallHandler(InvocationCallback callback, |
| 2516 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2517 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2518 | /** Set the predefined length property for the FunctionTemplate. */ |
| 2519 | void SetLength(int length); |
| 2520 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2521 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2522 | Local<ObjectTemplate> InstanceTemplate(); |
| 2523 | |
| 2524 | /** Causes the function template to inherit from a parent function template.*/ |
| 2525 | void Inherit(Handle<FunctionTemplate> parent); |
| 2526 | |
| 2527 | /** |
| 2528 | * A PrototypeTemplate is the template used to create the prototype object |
| 2529 | * of the function created by this template. |
| 2530 | */ |
| 2531 | Local<ObjectTemplate> PrototypeTemplate(); |
| 2532 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2533 | /** |
| 2534 | * Set the class name of the FunctionTemplate. This is used for |
| 2535 | * printing objects created with the function created from the |
| 2536 | * FunctionTemplate as its constructor. |
| 2537 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2538 | void SetClassName(Handle<String> name); |
| 2539 | |
| 2540 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2541 | * Determines whether the __proto__ accessor ignores instances of |
| 2542 | * the function template. If instances of the function template are |
| 2543 | * ignored, __proto__ skips all instances and instead returns the |
| 2544 | * next object in the prototype chain. |
| 2545 | * |
| 2546 | * Call with a value of true to make the __proto__ accessor ignore |
| 2547 | * instances of the function template. Call with a value of false |
| 2548 | * to make the __proto__ accessor not ignore instances of the |
| 2549 | * function template. By default, instances of a function template |
| 2550 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2551 | */ |
| 2552 | void SetHiddenPrototype(bool value); |
| 2553 | |
| 2554 | /** |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2555 | * Sets the ReadOnly flag in the attributes of the 'prototype' property |
| 2556 | * of functions created from this FunctionTemplate to true. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2557 | */ |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2558 | void ReadOnlyPrototype(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2559 | |
| 2560 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2561 | * Returns true if the given object is an instance of this function |
| 2562 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2563 | */ |
| 2564 | bool HasInstance(Handle<Value> object); |
| 2565 | |
| 2566 | private: |
| 2567 | FunctionTemplate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2568 | void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, |
| 2569 | NamedPropertySetter setter, |
| 2570 | NamedPropertyQuery query, |
| 2571 | NamedPropertyDeleter remover, |
| 2572 | NamedPropertyEnumerator enumerator, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2573 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2574 | void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, |
| 2575 | IndexedPropertySetter setter, |
| 2576 | IndexedPropertyQuery query, |
| 2577 | IndexedPropertyDeleter remover, |
| 2578 | IndexedPropertyEnumerator enumerator, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2579 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2580 | void SetInstanceCallAsFunctionHandler(InvocationCallback callback, |
| 2581 | Handle<Value> data); |
| 2582 | |
| 2583 | friend class Context; |
| 2584 | friend class ObjectTemplate; |
| 2585 | }; |
| 2586 | |
| 2587 | |
| 2588 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2589 | * An ObjectTemplate is used to create objects at runtime. |
| 2590 | * |
| 2591 | * Properties added to an ObjectTemplate are added to each object |
| 2592 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2593 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2594 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2595 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2596 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2597 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2598 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2599 | /** Creates a new instance of this template.*/ |
| 2600 | Local<Object> NewInstance(); |
| 2601 | |
| 2602 | /** |
| 2603 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2604 | * |
| 2605 | * Whenever the property with the given name is accessed on objects |
| 2606 | * created from this ObjectTemplate the getter and setter callbacks |
| 2607 | * are called instead of getting and setting the property directly |
| 2608 | * on the JavaScript object. |
| 2609 | * |
| 2610 | * \param name The name of the property for which an accessor is added. |
| 2611 | * \param getter The callback to invoke when getting the property. |
| 2612 | * \param setter The callback to invoke when setting the property. |
| 2613 | * \param data A piece of data that will be passed to the getter and setter |
| 2614 | * callbacks whenever they are invoked. |
| 2615 | * \param settings Access control settings for the accessor. This is a bit |
| 2616 | * field consisting of one of more of |
| 2617 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 2618 | * The default is to not allow cross-context access. |
| 2619 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 2620 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 2621 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 2622 | * cross-context access. |
| 2623 | * \param attribute The attributes of the property for which an accessor |
| 2624 | * is added. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2625 | * \param signature The signature describes valid receivers for the accessor |
| 2626 | * and is used to perform implicit instance checks against them. If the |
| 2627 | * receiver is incompatible (i.e. is not an instance of the constructor as |
| 2628 | * defined by FunctionTemplate::HasInstance()), an implicit TypeError is |
| 2629 | * thrown and no callback is invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2630 | */ |
| 2631 | void SetAccessor(Handle<String> name, |
| 2632 | AccessorGetter getter, |
| 2633 | AccessorSetter setter = 0, |
| 2634 | Handle<Value> data = Handle<Value>(), |
| 2635 | AccessControl settings = DEFAULT, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2636 | PropertyAttribute attribute = None, |
| 2637 | Handle<AccessorSignature> signature = |
| 2638 | Handle<AccessorSignature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2639 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2640 | // This function is not yet stable and should not be used at this time. |
| 2641 | bool SetAccessor(Handle<String> name, |
| 2642 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 2643 | AccessControl settings = DEFAULT, |
| 2644 | PropertyAttribute attribute = None, |
| 2645 | Handle<AccessorSignature> signature = |
| 2646 | Handle<AccessorSignature>()); |
| 2647 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2648 | /** |
| 2649 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2650 | * |
| 2651 | * Whenever a named property is accessed on objects created from |
| 2652 | * this object template, the provided callback is invoked instead of |
| 2653 | * accessing the property directly on the JavaScript object. |
| 2654 | * |
| 2655 | * \param getter The callback to invoke when getting a property. |
| 2656 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2657 | * \param query The callback to invoke to check if a property is present, |
| 2658 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2659 | * \param deleter The callback to invoke when deleting a property. |
| 2660 | * \param enumerator The callback to invoke to enumerate all the named |
| 2661 | * properties of an object. |
| 2662 | * \param data A piece of data that will be passed to the callbacks |
| 2663 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2664 | */ |
| 2665 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 2666 | NamedPropertySetter setter = 0, |
| 2667 | NamedPropertyQuery query = 0, |
| 2668 | NamedPropertyDeleter deleter = 0, |
| 2669 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2670 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2671 | |
| 2672 | /** |
| 2673 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2674 | * |
| 2675 | * Whenever an indexed property is accessed on objects created from |
| 2676 | * this object template, the provided callback is invoked instead of |
| 2677 | * accessing the property directly on the JavaScript object. |
| 2678 | * |
| 2679 | * \param getter The callback to invoke when getting a property. |
| 2680 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2681 | * \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] | 2682 | * \param deleter The callback to invoke when deleting a property. |
| 2683 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 2684 | * properties of an object. |
| 2685 | * \param data A piece of data that will be passed to the callbacks |
| 2686 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2687 | */ |
| 2688 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 2689 | IndexedPropertySetter setter = 0, |
| 2690 | IndexedPropertyQuery query = 0, |
| 2691 | IndexedPropertyDeleter deleter = 0, |
| 2692 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2693 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2694 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2695 | /** |
| 2696 | * Sets the callback to be used when calling instances created from |
| 2697 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2698 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2699 | * function. |
| 2700 | */ |
| 2701 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 2702 | Handle<Value> data = Handle<Value>()); |
| 2703 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2704 | /** |
| 2705 | * Mark object instances of the template as undetectable. |
| 2706 | * |
| 2707 | * In many ways, undetectable objects behave as though they are not |
| 2708 | * there. They behave like 'undefined' in conditionals and when |
| 2709 | * printed. However, properties can be accessed and called as on |
| 2710 | * normal objects. |
| 2711 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2712 | void MarkAsUndetectable(); |
| 2713 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2714 | /** |
| 2715 | * Sets access check callbacks on the object template. |
| 2716 | * |
| 2717 | * When accessing properties on instances of this object template, |
| 2718 | * the access check callback will be called to determine whether or |
| 2719 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2720 | * The last parameter specifies whether access checks are turned |
| 2721 | * on by default on instances. If access checks are off by default, |
| 2722 | * they can be turned on on individual instances by calling |
| 2723 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2724 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2725 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 2726 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2727 | Handle<Value> data = Handle<Value>(), |
| 2728 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2729 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2730 | /** |
| 2731 | * Gets the number of internal fields for objects generated from |
| 2732 | * this template. |
| 2733 | */ |
| 2734 | int InternalFieldCount(); |
| 2735 | |
| 2736 | /** |
| 2737 | * Sets the number of internal fields for objects generated from |
| 2738 | * this template. |
| 2739 | */ |
| 2740 | void SetInternalFieldCount(int value); |
| 2741 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2742 | private: |
| 2743 | ObjectTemplate(); |
| 2744 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 2745 | friend class FunctionTemplate; |
| 2746 | }; |
| 2747 | |
| 2748 | |
| 2749 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2750 | * A Signature specifies which receivers and arguments are valid |
| 2751 | * parameters to a function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2752 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2753 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2754 | public: |
| 2755 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 2756 | Handle<FunctionTemplate>(), |
| 2757 | int argc = 0, |
| 2758 | Handle<FunctionTemplate> argv[] = 0); |
| 2759 | private: |
| 2760 | Signature(); |
| 2761 | }; |
| 2762 | |
| 2763 | |
| 2764 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2765 | * An AccessorSignature specifies which receivers are valid parameters |
| 2766 | * to an accessor callback. |
| 2767 | */ |
| 2768 | class V8EXPORT AccessorSignature : public Data { |
| 2769 | public: |
| 2770 | static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = |
| 2771 | Handle<FunctionTemplate>()); |
| 2772 | private: |
| 2773 | AccessorSignature(); |
| 2774 | }; |
| 2775 | |
| 2776 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2777 | class V8EXPORT DeclaredAccessorDescriptor : public Data { |
| 2778 | private: |
| 2779 | DeclaredAccessorDescriptor(); |
| 2780 | }; |
| 2781 | |
| 2782 | |
| 2783 | class V8EXPORT ObjectOperationDescriptor : public Data { |
| 2784 | public: |
| 2785 | // This function is not yet stable and should not be used at this time. |
| 2786 | static Local<RawOperationDescriptor> NewInternalFieldDereference( |
| 2787 | Isolate* isolate, |
| 2788 | int internal_field); |
| 2789 | private: |
| 2790 | ObjectOperationDescriptor(); |
| 2791 | }; |
| 2792 | |
| 2793 | |
| 2794 | enum DeclaredAccessorDescriptorDataType { |
| 2795 | kDescriptorBoolType, |
| 2796 | kDescriptorInt8Type, kDescriptorUint8Type, |
| 2797 | kDescriptorInt16Type, kDescriptorUint16Type, |
| 2798 | kDescriptorInt32Type, kDescriptorUint32Type, |
| 2799 | kDescriptorFloatType, kDescriptorDoubleType |
| 2800 | }; |
| 2801 | |
| 2802 | |
| 2803 | class V8EXPORT RawOperationDescriptor : public Data { |
| 2804 | public: |
| 2805 | Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate); |
| 2806 | Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate); |
| 2807 | Local<RawOperationDescriptor> NewRawShift(Isolate* isolate, |
| 2808 | int16_t byte_offset); |
| 2809 | Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate, |
| 2810 | void* compare_value); |
| 2811 | Local<DeclaredAccessorDescriptor> NewPrimitiveValue( |
| 2812 | Isolate* isolate, |
| 2813 | DeclaredAccessorDescriptorDataType data_type, |
| 2814 | uint8_t bool_offset = 0); |
| 2815 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate, |
| 2816 | uint8_t bitmask, |
| 2817 | uint8_t compare_value); |
| 2818 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare16( |
| 2819 | Isolate* isolate, |
| 2820 | uint16_t bitmask, |
| 2821 | uint16_t compare_value); |
| 2822 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare32( |
| 2823 | Isolate* isolate, |
| 2824 | uint32_t bitmask, |
| 2825 | uint32_t compare_value); |
| 2826 | |
| 2827 | private: |
| 2828 | RawOperationDescriptor(); |
| 2829 | }; |
| 2830 | |
| 2831 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2832 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2833 | * A utility for determining the type of objects based on the template |
| 2834 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2835 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2836 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2837 | public: |
| 2838 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 2839 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 2840 | int match(Handle<Value> value); |
| 2841 | private: |
| 2842 | TypeSwitch(); |
| 2843 | }; |
| 2844 | |
| 2845 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2846 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2847 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2848 | class V8EXPORT ExternalAsciiStringResourceImpl |
| 2849 | : public String::ExternalAsciiStringResource { |
| 2850 | public: |
| 2851 | ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} |
| 2852 | ExternalAsciiStringResourceImpl(const char* data, size_t length) |
| 2853 | : data_(data), length_(length) {} |
| 2854 | const char* data() const { return data_; } |
| 2855 | size_t length() const { return length_; } |
| 2856 | |
| 2857 | private: |
| 2858 | const char* data_; |
| 2859 | size_t length_; |
| 2860 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2861 | |
| 2862 | /** |
| 2863 | * Ignore |
| 2864 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2865 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2866 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2867 | // Note that the strings passed into this constructor must live as long |
| 2868 | // as the Extension itself. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2869 | Extension(const char* name, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2870 | const char* source = 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2871 | int dep_count = 0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2872 | const char** deps = 0, |
| 2873 | int source_length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2874 | virtual ~Extension() { } |
| 2875 | virtual v8::Handle<v8::FunctionTemplate> |
| 2876 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 2877 | return v8::Handle<v8::FunctionTemplate>(); |
| 2878 | } |
| 2879 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2880 | const char* name() const { return name_; } |
| 2881 | size_t source_length() const { return source_length_; } |
| 2882 | const String::ExternalAsciiStringResource* source() const { |
| 2883 | return &source_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2884 | int dependency_count() { return dep_count_; } |
| 2885 | const char** dependencies() { return deps_; } |
| 2886 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 2887 | bool auto_enable() { return auto_enable_; } |
| 2888 | |
| 2889 | private: |
| 2890 | const char* name_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2891 | size_t source_length_; // expected to initialize before source_ |
| 2892 | ExternalAsciiStringResourceImpl source_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2893 | int dep_count_; |
| 2894 | const char** deps_; |
| 2895 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2896 | |
| 2897 | // Disallow copying and assigning. |
| 2898 | Extension(const Extension&); |
| 2899 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | }; |
| 2901 | |
| 2902 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2903 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2904 | |
| 2905 | |
| 2906 | /** |
| 2907 | * Ignore |
| 2908 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2909 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2910 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2911 | V8_INLINE(DeclareExtension(Extension* extension)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2912 | RegisterExtension(extension); |
| 2913 | } |
| 2914 | }; |
| 2915 | |
| 2916 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2917 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2918 | |
| 2919 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2920 | Handle<Primitive> V8EXPORT Undefined(); |
| 2921 | Handle<Primitive> V8EXPORT Null(); |
| 2922 | Handle<Boolean> V8EXPORT True(); |
| 2923 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2924 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2925 | V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate)); |
| 2926 | V8_INLINE(Handle<Primitive> Null(Isolate* isolate)); |
| 2927 | V8_INLINE(Handle<Boolean> True(Isolate* isolate)); |
| 2928 | V8_INLINE(Handle<Boolean> False(Isolate* isolate)); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 2929 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2930 | |
| 2931 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2932 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 2933 | * You must set the heap size before initializing the VM - the size cannot be |
| 2934 | * adjusted after the VM is initialized. |
| 2935 | * |
| 2936 | * If you are using threads then you should hold the V8::Locker lock while |
| 2937 | * setting the stack limit and you must set a non-default stack limit separately |
| 2938 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2939 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2940 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2941 | public: |
| 2942 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2943 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2944 | 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] | 2945 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2946 | 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] | 2947 | int max_executable_size() { return max_executable_size_; } |
| 2948 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2949 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2950 | // 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] | 2951 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 2952 | private: |
| 2953 | int max_young_space_size_; |
| 2954 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2955 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2956 | uint32_t* stack_limit_; |
| 2957 | }; |
| 2958 | |
| 2959 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2960 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2961 | |
| 2962 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2963 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2964 | |
| 2965 | |
| 2966 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 2967 | |
| 2968 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2969 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | |
| 2971 | |
| 2972 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2973 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 2974 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2975 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2976 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2977 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2978 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2979 | |
| 2980 | /** |
| 2981 | * Create new error objects by calling the corresponding error object |
| 2982 | * constructor with the message. |
| 2983 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2984 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2985 | public: |
| 2986 | static Local<Value> RangeError(Handle<String> message); |
| 2987 | static Local<Value> ReferenceError(Handle<String> message); |
| 2988 | static Local<Value> SyntaxError(Handle<String> message); |
| 2989 | static Local<Value> TypeError(Handle<String> message); |
| 2990 | static Local<Value> Error(Handle<String> message); |
| 2991 | }; |
| 2992 | |
| 2993 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2994 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2995 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2996 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2997 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2998 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 2999 | int min, |
| 3000 | int max, |
| 3001 | size_t buckets); |
| 3002 | |
| 3003 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 3004 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3005 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3006 | enum ObjectSpace { |
| 3007 | kObjectSpaceNewSpace = 1 << 0, |
| 3008 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 3009 | kObjectSpaceOldDataSpace = 1 << 2, |
| 3010 | kObjectSpaceCodeSpace = 1 << 3, |
| 3011 | kObjectSpaceMapSpace = 1 << 4, |
| 3012 | kObjectSpaceLoSpace = 1 << 5, |
| 3013 | |
| 3014 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 3015 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 3016 | kObjectSpaceLoSpace |
| 3017 | }; |
| 3018 | |
| 3019 | enum AllocationAction { |
| 3020 | kAllocationActionAllocate = 1 << 0, |
| 3021 | kAllocationActionFree = 1 << 1, |
| 3022 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 3023 | }; |
| 3024 | |
| 3025 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 3026 | AllocationAction action, |
| 3027 | int size); |
| 3028 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3029 | // --- Leave Script Callback --- |
| 3030 | typedef void (*CallCompletedCallback)(); |
| 3031 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3032 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3033 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 3034 | AccessType type, |
| 3035 | Local<Value> data); |
| 3036 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3037 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 3038 | |
| 3039 | /** |
| 3040 | * Callback to check if code generation from strings is allowed. See |
| 3041 | * Context::AllowCodeGenerationFromStrings. |
| 3042 | */ |
| 3043 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 3044 | |
| 3045 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3046 | |
| 3047 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3048 | * Applications can register callback functions which will be called |
| 3049 | * before and after a garbage collection. Allocations are not |
| 3050 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3051 | * objects (set or delete properties for example) since it is possible |
| 3052 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3053 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3054 | enum GCType { |
| 3055 | kGCTypeScavenge = 1 << 0, |
| 3056 | kGCTypeMarkSweepCompact = 1 << 1, |
| 3057 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 3058 | }; |
| 3059 | |
| 3060 | enum GCCallbackFlags { |
| 3061 | kNoGCCallbackFlags = 0, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 3062 | kGCCallbackFlagCompacted = 1 << 0, |
| 3063 | kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3064 | }; |
| 3065 | |
| 3066 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 3067 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 3068 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3069 | typedef void (*GCCallback)(); |
| 3070 | |
| 3071 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3072 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3073 | * Collection of V8 heap information. |
| 3074 | * |
| 3075 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 3076 | * get heap statistics from V8. |
| 3077 | */ |
| 3078 | class V8EXPORT HeapStatistics { |
| 3079 | public: |
| 3080 | HeapStatistics(); |
| 3081 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3082 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3083 | size_t total_physical_size() { return total_physical_size_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3084 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3085 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3086 | |
| 3087 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3088 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3089 | size_t total_heap_size_executable_; |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3090 | size_t total_physical_size_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3091 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3092 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3093 | |
| 3094 | friend class V8; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3095 | friend class Isolate; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3096 | }; |
| 3097 | |
| 3098 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3099 | class RetainedObjectInfo; |
| 3100 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3101 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3102 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 3103 | * isolates have completely separate states. Objects from one isolate |
| 3104 | * must not be used in other isolates. When V8 is initialized a |
| 3105 | * default isolate is implicitly created and entered. The embedder |
| 3106 | * can create additional isolates and use them in parallel in multiple |
| 3107 | * 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] | 3108 | * given time. The Locker/Unlocker API must be used to synchronize. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3109 | */ |
| 3110 | class V8EXPORT Isolate { |
| 3111 | public: |
| 3112 | /** |
| 3113 | * Stack-allocated class which sets the isolate for all operations |
| 3114 | * executed within a local scope. |
| 3115 | */ |
| 3116 | class V8EXPORT Scope { |
| 3117 | public: |
| 3118 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 3119 | isolate->Enter(); |
| 3120 | } |
| 3121 | |
| 3122 | ~Scope() { isolate_->Exit(); } |
| 3123 | |
| 3124 | private: |
| 3125 | Isolate* const isolate_; |
| 3126 | |
| 3127 | // Prevent copying of Scope objects. |
| 3128 | Scope(const Scope&); |
| 3129 | Scope& operator=(const Scope&); |
| 3130 | }; |
| 3131 | |
| 3132 | /** |
| 3133 | * Creates a new isolate. Does not change the currently entered |
| 3134 | * isolate. |
| 3135 | * |
| 3136 | * When an isolate is no longer used its resources should be freed |
| 3137 | * by calling Dispose(). Using the delete operator is not allowed. |
| 3138 | */ |
| 3139 | static Isolate* New(); |
| 3140 | |
| 3141 | /** |
| 3142 | * Returns the entered isolate for the current thread or NULL in |
| 3143 | * case there is no current isolate. |
| 3144 | */ |
| 3145 | static Isolate* GetCurrent(); |
| 3146 | |
| 3147 | /** |
| 3148 | * Methods below this point require holding a lock (using Locker) in |
| 3149 | * a multi-threaded environment. |
| 3150 | */ |
| 3151 | |
| 3152 | /** |
| 3153 | * Sets this isolate as the entered one for the current thread. |
| 3154 | * Saves the previously entered one (if any), so that it can be |
| 3155 | * restored when exiting. Re-entering an isolate is allowed. |
| 3156 | */ |
| 3157 | void Enter(); |
| 3158 | |
| 3159 | /** |
| 3160 | * Exits this isolate by restoring the previously entered one in the |
| 3161 | * current thread. The isolate may still stay the same, if it was |
| 3162 | * entered more than once. |
| 3163 | * |
| 3164 | * Requires: this == Isolate::GetCurrent(). |
| 3165 | */ |
| 3166 | void Exit(); |
| 3167 | |
| 3168 | /** |
| 3169 | * Disposes the isolate. The isolate must not be entered by any |
| 3170 | * thread to be disposable. |
| 3171 | */ |
| 3172 | void Dispose(); |
| 3173 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3174 | /** |
| 3175 | * Associate embedder-specific data with the isolate |
| 3176 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3177 | V8_INLINE(void SetData(void* data)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3178 | |
| 3179 | /** |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3180 | * Retrieve embedder-specific data from the isolate. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3181 | * Returns NULL if SetData has never been called. |
| 3182 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3183 | V8_INLINE(void* GetData()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3184 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3185 | /** |
| 3186 | * Get statistics about the heap memory usage. |
| 3187 | */ |
| 3188 | void GetHeapStatistics(HeapStatistics* heap_statistics); |
| 3189 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3190 | /** |
| 3191 | * Adjusts the amount of registered external memory. Used to give V8 an |
| 3192 | * indication of the amount of externally allocated memory that is kept alive |
| 3193 | * by JavaScript objects. V8 uses this to decide when to perform global |
| 3194 | * garbage collections. Registering externally allocated memory will trigger |
| 3195 | * global garbage collections more often than it would otherwise in an attempt |
| 3196 | * to garbage collect the JavaScript objects that keep the externally |
| 3197 | * allocated memory alive. |
| 3198 | * |
| 3199 | * \param change_in_bytes the change in externally allocated memory that is |
| 3200 | * kept alive by JavaScript objects. |
| 3201 | * \returns the adjusted value. |
| 3202 | */ |
| 3203 | intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); |
| 3204 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3205 | /** |
| 3206 | * Returns heap profiler for this isolate. Will return NULL until the isolate |
| 3207 | * is initialized. |
| 3208 | */ |
| 3209 | HeapProfiler* GetHeapProfiler(); |
| 3210 | |
| 3211 | /** |
| 3212 | * Returns CPU profiler for this isolate. Will return NULL until the isolate |
| 3213 | * is initialized. |
| 3214 | */ |
| 3215 | CpuProfiler* GetCpuProfiler(); |
| 3216 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 3217 | /** Returns the context that is on the top of the stack. */ |
| 3218 | Local<Context> GetCurrentContext(); |
| 3219 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 3220 | /** |
| 3221 | * Allows the host application to group objects together. If one |
| 3222 | * object in the group is alive, all objects in the group are alive. |
| 3223 | * After each garbage collection, object groups are removed. It is |
| 3224 | * intended to be used in the before-garbage-collection callback |
| 3225 | * function, for instance to simulate DOM tree connections among JS |
| 3226 | * wrapper objects. Object groups for all dependent handles need to |
| 3227 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3228 | * garbage collection types it is sufficient to provide object groups |
| 3229 | * for partially dependent handles only. |
| 3230 | */ |
| 3231 | void SetObjectGroupId(const Persistent<Value>& object, |
| 3232 | UniqueId id); |
| 3233 | |
| 3234 | /** |
| 3235 | * Allows the host application to declare implicit references from an object |
| 3236 | * group to an object. If the objects of the object group are alive, the child |
| 3237 | * object is alive too. After each garbage collection, all implicit references |
| 3238 | * are removed. It is intended to be used in the before-garbage-collection |
| 3239 | * callback function. |
| 3240 | */ |
| 3241 | void SetReferenceFromGroup(UniqueId id, |
| 3242 | const Persistent<Value>& child); |
| 3243 | |
| 3244 | /** |
| 3245 | * Allows the host application to declare implicit references from an object |
| 3246 | * to another object. If the parent object is alive, the child object is alive |
| 3247 | * too. After each garbage collection, all implicit references are removed. It |
| 3248 | * is intended to be used in the before-garbage-collection callback function. |
| 3249 | */ |
| 3250 | void SetReference(const Persistent<Object>& parent, |
| 3251 | const Persistent<Value>& child); |
| 3252 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3253 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3254 | Isolate(); |
| 3255 | Isolate(const Isolate&); |
| 3256 | ~Isolate(); |
| 3257 | Isolate& operator=(const Isolate&); |
| 3258 | void* operator new(size_t size); |
| 3259 | void operator delete(void*, size_t); |
| 3260 | }; |
| 3261 | |
| 3262 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3263 | class V8EXPORT StartupData { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3264 | public: |
| 3265 | enum CompressionAlgorithm { |
| 3266 | kUncompressed, |
| 3267 | kBZip2 |
| 3268 | }; |
| 3269 | |
| 3270 | const char* data; |
| 3271 | int compressed_size; |
| 3272 | int raw_size; |
| 3273 | }; |
| 3274 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3275 | |
| 3276 | /** |
| 3277 | * A helper class for driving V8 startup data decompression. It is based on |
| 3278 | * "CompressedStartupData" API functions from the V8 class. It isn't mandatory |
| 3279 | * for an embedder to use this class, instead, API functions can be used |
| 3280 | * directly. |
| 3281 | * |
| 3282 | * For an example of the class usage, see the "shell.cc" sample application. |
| 3283 | */ |
| 3284 | class V8EXPORT StartupDataDecompressor { // NOLINT |
| 3285 | public: |
| 3286 | StartupDataDecompressor(); |
| 3287 | virtual ~StartupDataDecompressor(); |
| 3288 | int Decompress(); |
| 3289 | |
| 3290 | protected: |
| 3291 | virtual int DecompressData(char* raw_data, |
| 3292 | int* raw_data_size, |
| 3293 | const char* compressed_data, |
| 3294 | int compressed_data_size) = 0; |
| 3295 | |
| 3296 | private: |
| 3297 | char** raw_data; |
| 3298 | }; |
| 3299 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3300 | |
| 3301 | /** |
| 3302 | * EntropySource is used as a callback function when v8 needs a source |
| 3303 | * of entropy. |
| 3304 | */ |
| 3305 | typedef bool (*EntropySource)(unsigned char* buffer, size_t length); |
| 3306 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3307 | |
| 3308 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3309 | * ReturnAddressLocationResolver is used as a callback function when v8 is |
| 3310 | * resolving the location of a return address on the stack. Profilers that |
| 3311 | * change the return address on the stack can use this to resolve the stack |
| 3312 | * location to whereever the profiler stashed the original return address. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3313 | * |
| 3314 | * \param return_addr_location points to a location on stack where a machine |
| 3315 | * return address resides. |
| 3316 | * \returns either return_addr_location, or else a pointer to the profiler's |
| 3317 | * copy of the original return address. |
| 3318 | * |
| 3319 | * \note the resolver function must not cause garbage collection. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3320 | */ |
| 3321 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
| 3322 | uintptr_t return_addr_location); |
| 3323 | |
| 3324 | |
| 3325 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3326 | * FunctionEntryHook is the type of the profile entry hook called at entry to |
| 3327 | * any generated function when function-level profiling is enabled. |
| 3328 | * |
| 3329 | * \param function the address of the function that's being entered. |
| 3330 | * \param return_addr_location points to a location on stack where the machine |
| 3331 | * return address resides. This can be used to identify the caller of |
| 3332 | * \p function, and/or modified to divert execution when \p function exits. |
| 3333 | * |
| 3334 | * \note the entry hook must not cause garbage collection. |
| 3335 | */ |
| 3336 | typedef void (*FunctionEntryHook)(uintptr_t function, |
| 3337 | uintptr_t return_addr_location); |
| 3338 | |
| 3339 | |
| 3340 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3341 | * A JIT code event is issued each time code is added, moved or removed. |
| 3342 | * |
| 3343 | * \note removal events are not currently issued. |
| 3344 | */ |
| 3345 | struct JitCodeEvent { |
| 3346 | enum EventType { |
| 3347 | CODE_ADDED, |
| 3348 | CODE_MOVED, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3349 | CODE_REMOVED, |
| 3350 | CODE_ADD_LINE_POS_INFO, |
| 3351 | CODE_START_LINE_INFO_RECORDING, |
| 3352 | CODE_END_LINE_INFO_RECORDING |
| 3353 | }; |
| 3354 | // Definition of the code position type. The "POSITION" type means the place |
| 3355 | // in the source code which are of interest when making stack traces to |
| 3356 | // pin-point the source location of a stack frame as close as possible. |
| 3357 | // The "STATEMENT_POSITION" means the place at the beginning of each |
| 3358 | // statement, and is used to indicate possible break locations. |
| 3359 | enum PositionType { |
| 3360 | POSITION, |
| 3361 | STATEMENT_POSITION |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3362 | }; |
| 3363 | |
| 3364 | // Type of event. |
| 3365 | EventType type; |
| 3366 | // Start of the instructions. |
| 3367 | void* code_start; |
| 3368 | // Size of the instructions. |
| 3369 | size_t code_len; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3370 | // Script info for CODE_ADDED event. |
| 3371 | Handle<Script> script; |
| 3372 | // User-defined data for *_LINE_INFO_* event. It's used to hold the source |
| 3373 | // code line information which is returned from the |
| 3374 | // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent |
| 3375 | // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. |
| 3376 | void* user_data; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3377 | |
| 3378 | union { |
| 3379 | // Only valid for CODE_ADDED. |
| 3380 | struct { |
| 3381 | // Name of the object associated with the code, note that the string is |
| 3382 | // not zero-terminated. |
| 3383 | const char* str; |
| 3384 | // Number of chars in str. |
| 3385 | size_t len; |
| 3386 | } name; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3387 | |
| 3388 | // Only valid for CODE_ADD_LINE_POS_INFO |
| 3389 | struct { |
| 3390 | // PC offset |
| 3391 | size_t offset; |
| 3392 | // Code postion |
| 3393 | size_t pos; |
| 3394 | // The position type. |
| 3395 | PositionType position_type; |
| 3396 | } line_info; |
| 3397 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3398 | // New location of instructions. Only valid for CODE_MOVED. |
| 3399 | void* new_code_start; |
| 3400 | }; |
| 3401 | }; |
| 3402 | |
| 3403 | /** |
| 3404 | * Option flags passed to the SetJitCodeEventHandler function. |
| 3405 | */ |
| 3406 | enum JitCodeEventOptions { |
| 3407 | kJitCodeEventDefault = 0, |
| 3408 | // Generate callbacks for already existent code. |
| 3409 | kJitCodeEventEnumExisting = 1 |
| 3410 | }; |
| 3411 | |
| 3412 | |
| 3413 | /** |
| 3414 | * Callback function passed to SetJitCodeEventHandler. |
| 3415 | * |
| 3416 | * \param event code add, move or removal event. |
| 3417 | */ |
| 3418 | typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); |
| 3419 | |
| 3420 | |
| 3421 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3422 | * Interface for iterating through all external resources in the heap. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3423 | */ |
| 3424 | class V8EXPORT ExternalResourceVisitor { // NOLINT |
| 3425 | public: |
| 3426 | virtual ~ExternalResourceVisitor() {} |
| 3427 | virtual void VisitExternalString(Handle<String> string) {} |
| 3428 | }; |
| 3429 | |
| 3430 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3431 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3432 | * Interface for iterating through all the persistent handles in the heap. |
| 3433 | */ |
| 3434 | class V8EXPORT PersistentHandleVisitor { // NOLINT |
| 3435 | public: |
| 3436 | virtual ~PersistentHandleVisitor() {} |
| 3437 | virtual void VisitPersistentHandle(Persistent<Value> value, |
| 3438 | uint16_t class_id) {} |
| 3439 | }; |
| 3440 | |
| 3441 | |
| 3442 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3443 | * Container class for static utility functions. |
| 3444 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3445 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3446 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3447 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3448 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 3449 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3450 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3451 | * Set the callback to invoke to check if code generation from |
| 3452 | * strings should be allowed. |
| 3453 | */ |
| 3454 | static void SetAllowCodeGenerationFromStringsCallback( |
| 3455 | AllowCodeGenerationFromStringsCallback that); |
| 3456 | |
| 3457 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3458 | * Ignore out-of-memory exceptions. |
| 3459 | * |
| 3460 | * V8 running out of memory is treated as a fatal error by default. |
| 3461 | * This means that the fatal error handler is called and that V8 is |
| 3462 | * terminated. |
| 3463 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3464 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3465 | * out-of-memory situation as a fatal error. This way, the contexts |
| 3466 | * that did not cause the out of memory problem might be able to |
| 3467 | * continue execution. |
| 3468 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3469 | static void IgnoreOutOfMemoryException(); |
| 3470 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3471 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3472 | * 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] | 3473 | * fatal errors such as out-of-memory situations. |
| 3474 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3475 | static bool IsDead(); |
| 3476 | |
| 3477 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3478 | * The following 4 functions are to be used when V8 is built with |
| 3479 | * the 'compress_startup_data' flag enabled. In this case, the |
| 3480 | * embedder must decompress startup data prior to initializing V8. |
| 3481 | * |
| 3482 | * This is how interaction with V8 should look like: |
| 3483 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 3484 | * v8::StartupData* compressed_data = |
| 3485 | * new v8::StartupData[compressed_data_count]; |
| 3486 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 3487 | * ... decompress data (compressed_data can be updated in-place) ... |
| 3488 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 3489 | * ... now V8 can be initialized |
| 3490 | * ... make sure the decompressed data stays valid until V8 shutdown |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3491 | * |
| 3492 | * A helper class StartupDataDecompressor is provided. It implements |
| 3493 | * the protocol of the interaction described above, and can be used in |
| 3494 | * most cases instead of calling these API functions directly. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3495 | */ |
| 3496 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 3497 | static int GetCompressedStartupDataCount(); |
| 3498 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 3499 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 3500 | |
| 3501 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3502 | * Adds a message listener. |
| 3503 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3504 | * 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] | 3505 | * case it will be called more than once for each message. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3506 | * |
| 3507 | * If data is specified, it will be passed to the callback when it is called. |
| 3508 | * Otherwise, the exception object will be passed to the callback instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3509 | */ |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3510 | static bool AddMessageListener(MessageCallback that, |
| 3511 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3512 | |
| 3513 | /** |
| 3514 | * Remove all message listeners from the specified callback function. |
| 3515 | */ |
| 3516 | static void RemoveMessageListeners(MessageCallback that); |
| 3517 | |
| 3518 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3519 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 3520 | * and report it to the message listeners. The option is off by default. |
| 3521 | */ |
| 3522 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 3523 | bool capture, |
| 3524 | int frame_limit = 10, |
| 3525 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 3526 | |
| 3527 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3528 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3529 | */ |
| 3530 | static void SetFlagsFromString(const char* str, int length); |
| 3531 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3532 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3533 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3534 | */ |
| 3535 | static void SetFlagsFromCommandLine(int* argc, |
| 3536 | char** argv, |
| 3537 | bool remove_flags); |
| 3538 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3539 | /** Get the version string. */ |
| 3540 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3541 | |
| 3542 | /** |
| 3543 | * Enables the host application to provide a mechanism for recording |
| 3544 | * statistics counters. |
| 3545 | */ |
| 3546 | static void SetCounterFunction(CounterLookupCallback); |
| 3547 | |
| 3548 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3549 | * Enables the host application to provide a mechanism for recording |
| 3550 | * histograms. The CreateHistogram function returns a |
| 3551 | * histogram which will later be passed to the AddHistogramSample |
| 3552 | * function. |
| 3553 | */ |
| 3554 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 3555 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 3556 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3557 | /** Callback function for reporting failed access checks.*/ |
| 3558 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 3559 | |
| 3560 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3561 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3562 | * garbage collection. Allocations are not allowed in the |
| 3563 | * callback function, you therefore cannot manipulate objects (set |
| 3564 | * or delete properties for example) since it is possible such |
| 3565 | * operations will result in the allocation of objects. It is possible |
| 3566 | * to specify the GCType filter for your callback. But it is not possible to |
| 3567 | * register the same callback function two times with different |
| 3568 | * GCType filters. |
| 3569 | */ |
| 3570 | static void AddGCPrologueCallback( |
| 3571 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 3572 | |
| 3573 | /** |
| 3574 | * This function removes callback which was installed by |
| 3575 | * AddGCPrologueCallback function. |
| 3576 | */ |
| 3577 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 3578 | |
| 3579 | /** |
| 3580 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 3581 | * Enables the host application to receive a notification before a |
| 3582 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3583 | * callback function, you therefore cannot manipulate objects (set |
| 3584 | * or delete properties for example) since it is possible such |
| 3585 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3586 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 3587 | V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3588 | |
| 3589 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3590 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3591 | * garbage collection. Allocations are not allowed in the |
| 3592 | * callback function, you therefore cannot manipulate objects (set |
| 3593 | * or delete properties for example) since it is possible such |
| 3594 | * operations will result in the allocation of objects. It is possible |
| 3595 | * to specify the GCType filter for your callback. But it is not possible to |
| 3596 | * register the same callback function two times with different |
| 3597 | * GCType filters. |
| 3598 | */ |
| 3599 | static void AddGCEpilogueCallback( |
| 3600 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 3601 | |
| 3602 | /** |
| 3603 | * This function removes callback which was installed by |
| 3604 | * AddGCEpilogueCallback function. |
| 3605 | */ |
| 3606 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 3607 | |
| 3608 | /** |
| 3609 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 3610 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3611 | * major garbage collection. Allocations are not allowed in the |
| 3612 | * callback function, you therefore cannot manipulate objects (set |
| 3613 | * or delete properties for example) since it is possible such |
| 3614 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3615 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 3616 | V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3617 | |
| 3618 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3619 | * Enables the host application to provide a mechanism to be notified |
| 3620 | * and perform custom logging when V8 Allocates Executable Memory. |
| 3621 | */ |
| 3622 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 3623 | ObjectSpace space, |
| 3624 | AllocationAction action); |
| 3625 | |
| 3626 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3627 | * Removes callback that was installed by AddMemoryAllocationCallback. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3628 | */ |
| 3629 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 3630 | |
| 3631 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3632 | * Adds a callback to notify the host application when a script finished |
| 3633 | * running. If a script re-enters the runtime during executing, the |
| 3634 | * CallCompletedCallback is only invoked when the outer-most script |
| 3635 | * execution ends. Executing scripts inside the callback do not trigger |
| 3636 | * further callbacks. |
| 3637 | */ |
| 3638 | static void AddCallCompletedCallback(CallCompletedCallback callback); |
| 3639 | |
| 3640 | /** |
| 3641 | * Removes callback that was installed by AddCallCompletedCallback. |
| 3642 | */ |
| 3643 | static void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 3644 | |
| 3645 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3646 | * Allows the host application to group objects together. If one |
| 3647 | * object in the group is alive, all objects in the group are alive. |
| 3648 | * After each garbage collection, object groups are removed. It is |
| 3649 | * intended to be used in the before-garbage-collection callback |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 3650 | * function, for instance to simulate DOM tree connections among JS |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3651 | * wrapper objects. Object groups for all dependent handles need to |
| 3652 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3653 | * garbage collection types it is sufficient to provide object groups |
| 3654 | * for partially dependent handles only. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3655 | * See v8-profiler.h for RetainedObjectInfo interface description. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3656 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 3657 | // TODO(marja): deprecate AddObjectGroup. Use Isolate::SetObjectGroupId and |
| 3658 | // HeapProfiler::SetRetainedObjectInfo instead. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3659 | static void AddObjectGroup(Persistent<Value>* objects, |
| 3660 | size_t length, |
| 3661 | RetainedObjectInfo* info = NULL); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3662 | static void AddObjectGroup(Isolate* isolate, |
| 3663 | Persistent<Value>* objects, |
| 3664 | size_t length, |
| 3665 | RetainedObjectInfo* info = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3666 | |
| 3667 | /** |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3668 | * Allows the host application to declare implicit references between |
| 3669 | * the objects: if |parent| is alive, all |children| are alive too. |
| 3670 | * After each garbage collection, all implicit references |
| 3671 | * are removed. It is intended to be used in the before-garbage-collection |
| 3672 | * callback function. |
| 3673 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 3674 | // TODO(marja): Deprecate AddImplicitReferences. Use |
| 3675 | // Isolate::SetReferenceFromGroup instead. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3676 | static void AddImplicitReferences(Persistent<Object> parent, |
| 3677 | Persistent<Value>* children, |
| 3678 | size_t length); |
| 3679 | |
| 3680 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3681 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3682 | * initialize from scratch. This function is called implicitly if |
| 3683 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3684 | */ |
| 3685 | static bool Initialize(); |
| 3686 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3687 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3688 | * Allows the host application to provide a callback which can be used |
| 3689 | * as a source of entropy for random number generators. |
| 3690 | */ |
| 3691 | static void SetEntropySource(EntropySource source); |
| 3692 | |
| 3693 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3694 | * Allows the host application to provide a callback that allows v8 to |
| 3695 | * cooperate with a profiler that rewrites return addresses on stack. |
| 3696 | */ |
| 3697 | static void SetReturnAddressLocationResolver( |
| 3698 | ReturnAddressLocationResolver return_address_resolver); |
| 3699 | |
| 3700 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3701 | * Allows the host application to provide the address of a function that's |
| 3702 | * invoked on entry to every V8-generated function. |
| 3703 | * Note that \p entry_hook is invoked at the very start of each |
| 3704 | * generated function. |
| 3705 | * |
| 3706 | * \param entry_hook a function that will be invoked on entry to every |
| 3707 | * V8-generated function. |
| 3708 | * \returns true on success on supported platforms, false on failure. |
| 3709 | * \note Setting a new entry hook function when one is already active will |
| 3710 | * fail. |
| 3711 | */ |
| 3712 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 3713 | |
| 3714 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3715 | * Allows the host application to provide the address of a function that is |
| 3716 | * notified each time code is added, moved or removed. |
| 3717 | * |
| 3718 | * \param options options for the JIT code event handler. |
| 3719 | * \param event_handler the JIT code event handler, which will be invoked |
| 3720 | * each time code is added, moved or removed. |
| 3721 | * \note \p event_handler won't get notified of existent code. |
| 3722 | * \note since code removal notifications are not currently issued, the |
| 3723 | * \p event_handler may get notifications of code that overlaps earlier |
| 3724 | * code notifications. This happens when code areas are reused, and the |
| 3725 | * earlier overlapping code areas should therefore be discarded. |
| 3726 | * \note the events passed to \p event_handler and the strings they point to |
| 3727 | * are not guaranteed to live past each call. The \p event_handler must |
| 3728 | * copy strings and other parameters it needs to keep around. |
| 3729 | * \note the set of events declared in JitCodeEvent::EventType is expected to |
| 3730 | * grow over time, and the JitCodeEvent structure is expected to accrue |
| 3731 | * new members. The \p event_handler function must ignore event codes |
| 3732 | * it does not recognize to maintain future compatibility. |
| 3733 | */ |
| 3734 | static void SetJitCodeEventHandler(JitCodeEventOptions options, |
| 3735 | JitCodeEventHandler event_handler); |
| 3736 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3737 | // TODO(svenpanne) Really deprecate me when Chrome is fixed. |
| 3738 | /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3739 | static intptr_t AdjustAmountOfExternalAllocatedMemory( |
| 3740 | intptr_t change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3741 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3742 | /** |
| 3743 | * Suspends recording of tick samples in the profiler. |
| 3744 | * When the V8 profiling mode is enabled (usually via command line |
| 3745 | * switches) this function suspends recording of tick samples. |
| 3746 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 3747 | * |
| 3748 | * See also the --prof and --prof_auto command line switches to |
| 3749 | * enable V8 profiling. |
| 3750 | */ |
| 3751 | static void PauseProfiler(); |
| 3752 | |
| 3753 | /** |
| 3754 | * Resumes recording of tick samples in the profiler. |
| 3755 | * See also PauseProfiler(). |
| 3756 | */ |
| 3757 | static void ResumeProfiler(); |
| 3758 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3759 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3760 | * Return whether profiler is currently paused. |
| 3761 | */ |
| 3762 | static bool IsProfilerPaused(); |
| 3763 | |
| 3764 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3765 | * Retrieve the V8 thread id of the calling thread. |
| 3766 | * |
| 3767 | * The thread id for a thread should only be retrieved after the V8 |
| 3768 | * lock has been acquired with a Locker object with that thread. |
| 3769 | */ |
| 3770 | static int GetCurrentThreadId(); |
| 3771 | |
| 3772 | /** |
| 3773 | * Forcefully terminate execution of a JavaScript thread. This can |
| 3774 | * be used to terminate long-running scripts. |
| 3775 | * |
| 3776 | * TerminateExecution should only be called when then V8 lock has |
| 3777 | * been acquired with a Locker object. Therefore, in order to be |
| 3778 | * able to terminate long-running threads, preemption must be |
| 3779 | * enabled to allow the user of TerminateExecution to acquire the |
| 3780 | * lock. |
| 3781 | * |
| 3782 | * The termination is achieved by throwing an exception that is |
| 3783 | * uncatchable by JavaScript exception handlers. Termination |
| 3784 | * 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] | 3785 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3786 | * exception handler that catches an exception should check if that |
| 3787 | * exception is a termination exception and immediately return if |
| 3788 | * that is the case. Returning immediately in that case will |
| 3789 | * continue the propagation of the termination exception if needed. |
| 3790 | * |
| 3791 | * The thread id passed to TerminateExecution must have been |
| 3792 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 3793 | * |
| 3794 | * \param thread_id The thread id of the thread to terminate. |
| 3795 | */ |
| 3796 | static void TerminateExecution(int thread_id); |
| 3797 | |
| 3798 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3799 | * Forcefully terminate the current thread of JavaScript execution |
| 3800 | * in the given isolate. If no isolate is provided, the default |
| 3801 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3802 | * |
| 3803 | * This method can be used by any thread even if that thread has not |
| 3804 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3805 | * |
| 3806 | * \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] | 3807 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3808 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3809 | |
| 3810 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 3811 | * Is V8 terminating JavaScript execution. |
| 3812 | * |
| 3813 | * Returns true if JavaScript execution is currently terminating |
| 3814 | * because of a call to TerminateExecution. In that case there are |
| 3815 | * still JavaScript frames on the stack and the termination |
| 3816 | * exception is still active. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3817 | * |
| 3818 | * \param isolate The isolate in which to check. |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 3819 | */ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3820 | static bool IsExecutionTerminating(Isolate* isolate = NULL); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 3821 | |
| 3822 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3823 | * Resume execution capability in the given isolate, whose execution |
| 3824 | * was previously forcefully terminated using TerminateExecution(). |
| 3825 | * |
| 3826 | * When execution is forcefully terminated using TerminateExecution(), |
| 3827 | * the isolate can not resume execution until all JavaScript frames |
| 3828 | * have propagated the uncatchable exception which is generated. This |
| 3829 | * method allows the program embedding the engine to handle the |
| 3830 | * termination event and resume execution capability, even if |
| 3831 | * JavaScript frames remain on the stack. |
| 3832 | * |
| 3833 | * This method can be used by any thread even if that thread has not |
| 3834 | * acquired the V8 lock with a Locker object. |
| 3835 | * |
| 3836 | * \param isolate The isolate in which to resume execution capability. |
| 3837 | */ |
| 3838 | static void CancelTerminateExecution(Isolate* isolate); |
| 3839 | |
| 3840 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3841 | * Releases any resources used by v8 and stops any utility threads |
| 3842 | * that may be running. Note that disposing v8 is permanent, it |
| 3843 | * cannot be reinitialized. |
| 3844 | * |
| 3845 | * It should generally not be necessary to dispose v8 before exiting |
| 3846 | * a process, this should happen automatically. It is only necessary |
| 3847 | * to use if the process needs the resources taken up by v8. |
| 3848 | */ |
| 3849 | static bool Dispose(); |
| 3850 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3851 | /** Deprecated. Use Isolate::GetHeapStatistics instead. */ |
| 3852 | V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3853 | |
| 3854 | /** |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3855 | * Iterates through all external resources referenced from current isolate |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3856 | * heap. GC is not invoked prior to iterating, therefore there is no |
| 3857 | * guarantee that visited objects are still alive. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3858 | */ |
| 3859 | static void VisitExternalResources(ExternalResourceVisitor* visitor); |
| 3860 | |
| 3861 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3862 | * Iterates through all the persistent handles in the current isolate's heap |
| 3863 | * that have class_ids. |
| 3864 | */ |
| 3865 | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); |
| 3866 | |
| 3867 | /** |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 3868 | * Iterates through all the persistent handles in the current isolate's heap |
| 3869 | * that have class_ids and are candidates to be marked as partially dependent |
| 3870 | * handles. This will visit handles to young objects created since the last |
| 3871 | * garbage collection but is free to visit an arbitrary superset of these |
| 3872 | * objects. |
| 3873 | */ |
| 3874 | static void VisitHandlesForPartialDependence( |
| 3875 | Isolate* isolate, PersistentHandleVisitor* visitor); |
| 3876 | |
| 3877 | /** |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3878 | * Optional notification that the embedder is idle. |
| 3879 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3880 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3881 | * Returns true if the embedder should stop calling IdleNotification |
| 3882 | * until real work has been done. This indicates that V8 has done |
| 3883 | * as much cleanup as it will be able to do. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3884 | * |
| 3885 | * The hint argument specifies the amount of work to be done in the function |
| 3886 | * on scale from 1 to 1000. There is no guarantee that the actual work will |
| 3887 | * match the hint. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3888 | */ |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3889 | static bool IdleNotification(int hint = 1000); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3890 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3891 | /** |
| 3892 | * Optional notification that the system is running low on memory. |
| 3893 | * V8 uses these notifications to attempt to free memory. |
| 3894 | */ |
| 3895 | static void LowMemoryNotification(); |
| 3896 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3897 | /** |
| 3898 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3899 | * these notifications to guide the GC heuristic. Returns the number |
| 3900 | * of context disposals - including this one - since the last time |
| 3901 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3902 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3903 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3904 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3905 | private: |
| 3906 | V8(); |
| 3907 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3908 | static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 3909 | internal::Object** handle); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3910 | static void DisposeGlobal(internal::Isolate* isolate, |
| 3911 | internal::Object** global_handle); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3912 | static void MakeWeak(internal::Isolate* isolate, |
| 3913 | internal::Object** global_handle, |
| 3914 | void* data, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3915 | WeakReferenceCallback weak_reference_callback, |
| 3916 | NearDeathCallback near_death_callback); |
| 3917 | static void ClearWeak(internal::Isolate* isolate, |
| 3918 | internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3919 | |
| 3920 | template <class T> friend class Handle; |
| 3921 | template <class T> friend class Local; |
| 3922 | template <class T> friend class Persistent; |
| 3923 | friend class Context; |
| 3924 | }; |
| 3925 | |
| 3926 | |
| 3927 | /** |
| 3928 | * An external exception handler. |
| 3929 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3930 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3931 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3932 | /** |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 3933 | * Creates a new try/catch block and registers it with v8. Note that |
| 3934 | * all TryCatch blocks should be stack allocated because the memory |
| 3935 | * location itself is compared against JavaScript try/catch blocks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3936 | */ |
| 3937 | TryCatch(); |
| 3938 | |
| 3939 | /** |
| 3940 | * Unregisters and deletes this try/catch block. |
| 3941 | */ |
| 3942 | ~TryCatch(); |
| 3943 | |
| 3944 | /** |
| 3945 | * Returns true if an exception has been caught by this try/catch block. |
| 3946 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3947 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3948 | |
| 3949 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3950 | * For certain types of exceptions, it makes no sense to continue execution. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3951 | * |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3952 | * If CanContinue returns false, the correct action is to perform any C++ |
| 3953 | * cleanup needed and then return. If CanContinue returns false and |
| 3954 | * HasTerminated returns true, it is possible to call |
| 3955 | * CancelTerminateExecution in order to continue calling into the engine. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3956 | */ |
| 3957 | bool CanContinue() const; |
| 3958 | |
| 3959 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3960 | * Returns true if an exception has been caught due to script execution |
| 3961 | * being terminated. |
| 3962 | * |
| 3963 | * There is no JavaScript representation of an execution termination |
| 3964 | * exception. Such exceptions are thrown when the TerminateExecution |
| 3965 | * methods are called to terminate a long-running script. |
| 3966 | * |
| 3967 | * If such an exception has been thrown, HasTerminated will return true, |
| 3968 | * indicating that it is possible to call CancelTerminateExecution in order |
| 3969 | * to continue calling into the engine. |
| 3970 | */ |
| 3971 | bool HasTerminated() const; |
| 3972 | |
| 3973 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 3974 | * Throws the exception caught by this TryCatch in a way that avoids |
| 3975 | * it being caught again by this same TryCatch. As with ThrowException |
| 3976 | * it is illegal to execute any JavaScript operations after calling |
| 3977 | * ReThrow; the caller must return immediately to where the exception |
| 3978 | * is caught. |
| 3979 | */ |
| 3980 | Handle<Value> ReThrow(); |
| 3981 | |
| 3982 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3983 | * Returns the exception caught by this try/catch block. If no exception has |
| 3984 | * been caught an empty handle is returned. |
| 3985 | * |
| 3986 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 3987 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3988 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3989 | |
| 3990 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3991 | * Returns the .stack property of the thrown object. If no .stack |
| 3992 | * property is present an empty handle is returned. |
| 3993 | */ |
| 3994 | Local<Value> StackTrace() const; |
| 3995 | |
| 3996 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3997 | * Returns the message associated with this exception. If there is |
| 3998 | * no message associated an empty handle is returned. |
| 3999 | * |
| 4000 | * The returned handle is valid until this TryCatch block has been |
| 4001 | * destroyed. |
| 4002 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4003 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4004 | |
| 4005 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4006 | * Clears any exceptions that may have been caught by this try/catch block. |
| 4007 | * After this method has been called, HasCaught() will return false. |
| 4008 | * |
| 4009 | * It is not necessary to clear a try/catch block before using it again; if |
| 4010 | * another exception is thrown the previously caught exception will just be |
| 4011 | * overwritten. However, it is often a good idea since it makes it easier |
| 4012 | * to determine which operation threw a given exception. |
| 4013 | */ |
| 4014 | void Reset(); |
| 4015 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4016 | /** |
| 4017 | * Set verbosity of the external exception handler. |
| 4018 | * |
| 4019 | * By default, exceptions that are caught by an external exception |
| 4020 | * handler are not reported. Call SetVerbose with true on an |
| 4021 | * external exception handler to have exceptions caught by the |
| 4022 | * handler reported as if they were not caught. |
| 4023 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4024 | void SetVerbose(bool value); |
| 4025 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4026 | /** |
| 4027 | * Set whether or not this TryCatch should capture a Message object |
| 4028 | * which holds source information about where the exception |
| 4029 | * occurred. True by default. |
| 4030 | */ |
| 4031 | void SetCaptureMessage(bool value); |
| 4032 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4033 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4034 | // Make it hard to create heap-allocated TryCatch blocks. |
| 4035 | TryCatch(const TryCatch&); |
| 4036 | void operator=(const TryCatch&); |
| 4037 | void* operator new(size_t size); |
| 4038 | void operator delete(void*, size_t); |
| 4039 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4040 | v8::internal::Isolate* isolate_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4041 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4042 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4043 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4044 | bool is_verbose_ : 1; |
| 4045 | bool can_continue_ : 1; |
| 4046 | bool capture_message_ : 1; |
| 4047 | bool rethrow_ : 1; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4048 | bool has_terminated_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4049 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4050 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4051 | }; |
| 4052 | |
| 4053 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4054 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4055 | |
| 4056 | |
| 4057 | /** |
| 4058 | * Ignore |
| 4059 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4060 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4061 | public: |
| 4062 | ExtensionConfiguration(int name_count, const char* names[]) |
| 4063 | : name_count_(name_count), names_(names) { } |
| 4064 | private: |
| 4065 | friend class ImplementationUtilities; |
| 4066 | int name_count_; |
| 4067 | const char** names_; |
| 4068 | }; |
| 4069 | |
| 4070 | |
| 4071 | /** |
| 4072 | * A sandboxed execution context with its own set of built-in objects |
| 4073 | * and functions. |
| 4074 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4075 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4076 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4077 | /** |
| 4078 | * Returns the global proxy object or global object itself for |
| 4079 | * detached contexts. |
| 4080 | * |
| 4081 | * Global proxy object is a thin wrapper whose prototype points to |
| 4082 | * actual context's global object with the properties like Object, etc. |
| 4083 | * This is done that way for security reasons (for more details see |
| 4084 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 4085 | * |
| 4086 | * Please note that changes to global proxy object prototype most probably |
| 4087 | * would break VM---v8 expects only global object as a prototype of |
| 4088 | * global proxy object. |
| 4089 | * |
| 4090 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 4091 | * object until global is reattached with ReattachGlobal(). |
| 4092 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4093 | Local<Object> Global(); |
| 4094 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4095 | /** |
| 4096 | * Detaches the global object from its context before |
| 4097 | * the global object can be reused to create a new context. |
| 4098 | */ |
| 4099 | void DetachGlobal(); |
| 4100 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4101 | /** |
| 4102 | * Reattaches a global object to a context. This can be used to |
| 4103 | * restore the connection between a global object and a context |
| 4104 | * after DetachGlobal has been called. |
| 4105 | * |
| 4106 | * \param global_object The global object to reattach to the |
| 4107 | * context. For this to work, the global object must be the global |
| 4108 | * object that was associated with this context before a call to |
| 4109 | * DetachGlobal. |
| 4110 | */ |
| 4111 | void ReattachGlobal(Handle<Object> global_object); |
| 4112 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4113 | /** |
| 4114 | * Creates a new context and returns a handle to the newly allocated |
| 4115 | * context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4116 | * |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4117 | * \param isolate The isolate in which to create the context. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4118 | * |
| 4119 | * \param extensions An optional extension configuration containing |
| 4120 | * the extensions to be installed in the newly created context. |
| 4121 | * |
| 4122 | * \param global_template An optional object template from which the |
| 4123 | * global object for the newly created context will be created. |
| 4124 | * |
| 4125 | * \param global_object An optional global object to be reused for |
| 4126 | * the newly created context. This global object must have been |
| 4127 | * created by a previous call to Context::New with the same global |
| 4128 | * template. The state of the global object will be completely reset |
| 4129 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4130 | */ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4131 | static Local<Context> New( |
| 4132 | Isolate* isolate, |
| 4133 | ExtensionConfiguration* extensions = NULL, |
| 4134 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4135 | Handle<Value> global_object = Handle<Value>()); |
| 4136 | |
| 4137 | /** Deprecated. Use Isolate version instead. */ |
| 4138 | // TODO(mstarzinger): Put this behind the V8_DEPRECATED guard. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4139 | static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4140 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4141 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4142 | Handle<Value> global_object = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4143 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4144 | /** Returns the last entered context. */ |
| 4145 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4146 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4147 | // TODO(svenpanne) Actually deprecate this. |
| 4148 | /** Deprecated. Use Isolate::GetCurrentContext instead. */ |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4149 | static Local<Context> GetCurrent(); |
| 4150 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4151 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4152 | * Returns the context of the calling JavaScript code. That is the |
| 4153 | * context of the top-most JavaScript frame. If there are no |
| 4154 | * JavaScript frames an empty handle is returned. |
| 4155 | */ |
| 4156 | static Local<Context> GetCalling(); |
| 4157 | |
| 4158 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4159 | * Sets the security token for the context. To access an object in |
| 4160 | * another context, the security tokens must match. |
| 4161 | */ |
| 4162 | void SetSecurityToken(Handle<Value> token); |
| 4163 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4164 | /** Restores the security token to the default value. */ |
| 4165 | void UseDefaultSecurityToken(); |
| 4166 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4167 | /** Returns the security token of this context.*/ |
| 4168 | Handle<Value> GetSecurityToken(); |
| 4169 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4170 | /** |
| 4171 | * Enter this context. After entering a context, all code compiled |
| 4172 | * and run is compiled and run in this context. If another context |
| 4173 | * is already entered, this old context is saved so it can be |
| 4174 | * restored when the new context is exited. |
| 4175 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4176 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4177 | |
| 4178 | /** |
| 4179 | * Exit this context. Exiting the current context restores the |
| 4180 | * context that was in place when entering the current context. |
| 4181 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4182 | void Exit(); |
| 4183 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4184 | /** 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] | 4185 | bool HasOutOfMemoryException(); |
| 4186 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4187 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4188 | static bool InContext(); |
| 4189 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4190 | /** Returns an isolate associated with a current context. */ |
| 4191 | v8::Isolate* GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4192 | |
| 4193 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4194 | * Gets the embedder data with the given index, which must have been set by a |
| 4195 | * previous call to SetEmbedderData with the same index. Note that index 0 |
| 4196 | * currently has a special meaning for Chrome's debugger. |
| 4197 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4198 | V8_INLINE(Local<Value> GetEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4199 | |
| 4200 | /** |
| 4201 | * Sets the embedder data with the given index, growing the data as |
| 4202 | * needed. Note that index 0 currently has a special meaning for Chrome's |
| 4203 | * debugger. |
| 4204 | */ |
| 4205 | void SetEmbedderData(int index, Handle<Value> value); |
| 4206 | |
| 4207 | /** |
| 4208 | * Gets a 2-byte-aligned native pointer from the embedder data with the given |
| 4209 | * index, which must have bees set by a previous call to |
| 4210 | * SetAlignedPointerInEmbedderData with the same index. Note that index 0 |
| 4211 | * currently has a special meaning for Chrome's debugger. |
| 4212 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4213 | V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4214 | |
| 4215 | /** |
| 4216 | * Sets a 2-byte-aligned native pointer in the embedder data with the given |
| 4217 | * index, growing the data as needed. Note that index 0 currently has a |
| 4218 | * special meaning for Chrome's debugger. |
| 4219 | */ |
| 4220 | void SetAlignedPointerInEmbedderData(int index, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4221 | |
| 4222 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4223 | * Control whether code generation from strings is allowed. Calling |
| 4224 | * this method with false will disable 'eval' and the 'Function' |
| 4225 | * constructor for code running in this context. If 'eval' or the |
| 4226 | * 'Function' constructor are used an exception will be thrown. |
| 4227 | * |
| 4228 | * If code generation from strings is not allowed the |
| 4229 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 4230 | * set before blocking the call to 'eval' or the 'Function' |
| 4231 | * constructor. If that callback returns true, the call will be |
| 4232 | * allowed, otherwise an exception will be thrown. If no callback is |
| 4233 | * set an exception will be thrown. |
| 4234 | */ |
| 4235 | void AllowCodeGenerationFromStrings(bool allow); |
| 4236 | |
| 4237 | /** |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4238 | * Returns true if code generation from strings is allowed for the context. |
| 4239 | * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
| 4240 | */ |
| 4241 | bool IsCodeGenerationFromStringsAllowed(); |
| 4242 | |
| 4243 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4244 | * Sets the error description for the exception that is thrown when |
| 4245 | * code generation from strings is not allowed and 'eval' or the 'Function' |
| 4246 | * constructor are called. |
| 4247 | */ |
| 4248 | void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); |
| 4249 | |
| 4250 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4251 | * Stack-allocated class which sets the execution context for all |
| 4252 | * operations executed within a local scope. |
| 4253 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4254 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4255 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4256 | explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4257 | context_->Enter(); |
| 4258 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4259 | V8_INLINE(~Scope()) { context_->Exit(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4260 | private: |
| 4261 | Handle<Context> context_; |
| 4262 | }; |
| 4263 | |
| 4264 | private: |
| 4265 | friend class Value; |
| 4266 | friend class Script; |
| 4267 | friend class Object; |
| 4268 | friend class Function; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4269 | |
| 4270 | Local<Value> SlowGetEmbedderData(int index); |
| 4271 | void* SlowGetAlignedPointerFromEmbedderData(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4272 | }; |
| 4273 | |
| 4274 | |
| 4275 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4276 | * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
| 4277 | * to use any given V8 isolate, see the comments in the Isolate class. The |
| 4278 | * definition of 'using a V8 isolate' includes accessing handles or holding onto |
| 4279 | * object pointers obtained from V8 handles while in the particular V8 isolate. |
| 4280 | * It is up to the user of V8 to ensure, perhaps with locking, that this |
| 4281 | * constraint is not violated. In addition to any other synchronization |
| 4282 | * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
| 4283 | * used to signal thead switches to V8. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4284 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4285 | * v8::Locker is a scoped lock object. While it's active, i.e. between its |
| 4286 | * construction and destruction, the current thread is allowed to use the locked |
| 4287 | * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
| 4288 | * 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] | 4289 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4290 | * Sample usage: |
| 4291 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4292 | * ... |
| 4293 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4294 | * v8::Locker locker(isolate); |
| 4295 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4296 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4297 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4298 | * ... |
| 4299 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4300 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4301 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4302 | * If you wish to stop using V8 in a thread A you can do this either by |
| 4303 | * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
| 4304 | * object: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4305 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4306 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4307 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4308 | * isolate->Exit(); |
| 4309 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4310 | * ... |
| 4311 | * // Code not using V8 goes here while V8 can run in another thread. |
| 4312 | * ... |
| 4313 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4314 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4315 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4316 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4317 | * The Unlocker object is intended for use in a long-running callback from V8, |
| 4318 | * 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] | 4319 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4320 | * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
| 4321 | * given thread. This can be useful if you have code that can be called either |
| 4322 | * from code that holds the lock or from code that does not. The Unlocker is |
| 4323 | * not recursive so you can not have several Unlockers on the stack at once, and |
| 4324 | * 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] | 4325 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4326 | * An unlocker will unlock several lockers if it has to and reinstate the |
| 4327 | * correct depth of locking on its destruction, e.g.: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4328 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4329 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4330 | * // V8 not locked. |
| 4331 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4332 | * v8::Locker locker(isolate); |
| 4333 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4334 | * // V8 locked. |
| 4335 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4336 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4337 | * // V8 still locked (2 levels). |
| 4338 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4339 | * isolate->Exit(); |
| 4340 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4341 | * // V8 not locked. |
| 4342 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4343 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4344 | * // V8 locked again (2 levels). |
| 4345 | * } |
| 4346 | * // V8 still locked (1 level). |
| 4347 | * } |
| 4348 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4349 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4350 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4351 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4352 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4353 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4354 | * Initialize Unlocker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4355 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4356 | V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 4357 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4358 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4359 | V8_DEPRECATED(Unlocker()); |
| 4360 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4361 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4362 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4363 | void Initialize(Isolate* isolate); |
| 4364 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4365 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4366 | }; |
| 4367 | |
| 4368 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4369 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4370 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4371 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4372 | * Initialize Locker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4373 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4374 | V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 4375 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4376 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4377 | V8_DEPRECATED(Locker()); |
| 4378 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4379 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4380 | |
| 4381 | /** |
| 4382 | * Start preemption. |
| 4383 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4384 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4385 | * that will switch between multiple threads that are in contention |
| 4386 | * for the V8 lock. |
| 4387 | */ |
| 4388 | static void StartPreemption(int every_n_ms); |
| 4389 | |
| 4390 | /** |
| 4391 | * Stop preemption. |
| 4392 | */ |
| 4393 | static void StopPreemption(); |
| 4394 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4395 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4396 | * Returns whether or not the locker for a given isolate, is locked by the |
| 4397 | * current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4398 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4399 | static bool IsLocked(Isolate* isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4400 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4401 | /** |
| 4402 | * Returns whether v8::Locker is being used by this V8 instance. |
| 4403 | */ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4404 | static bool IsActive(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4405 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4406 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4407 | void Initialize(Isolate* isolate); |
| 4408 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4409 | bool has_lock_; |
| 4410 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4411 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4412 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4413 | static bool active_; |
| 4414 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4415 | // Disallow copying and assigning. |
| 4416 | Locker(const Locker&); |
| 4417 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4418 | }; |
| 4419 | |
| 4420 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4421 | /** |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4422 | * A struct for exporting HeapStats data from V8, using "push" model. |
| 4423 | */ |
| 4424 | struct HeapStatsUpdate; |
| 4425 | |
| 4426 | |
| 4427 | /** |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4428 | * An interface for exporting data from V8, using "push" model. |
| 4429 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 4430 | class V8EXPORT OutputStream { // NOLINT |
| 4431 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4432 | enum OutputEncoding { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4433 | kAscii = 0 // 7-bit ASCII. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4434 | }; |
| 4435 | enum WriteResult { |
| 4436 | kContinue = 0, |
| 4437 | kAbort = 1 |
| 4438 | }; |
| 4439 | virtual ~OutputStream() {} |
| 4440 | /** Notify about the end of stream. */ |
| 4441 | virtual void EndOfStream() = 0; |
| 4442 | /** Get preferred output chunk size. Called only once. */ |
| 4443 | virtual int GetChunkSize() { return 1024; } |
| 4444 | /** Get preferred output encoding. Called only once. */ |
| 4445 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 4446 | /** |
| 4447 | * Writes the next chunk of snapshot data into the stream. Writing |
| 4448 | * can be stopped by returning kAbort as function result. EndOfStream |
| 4449 | * will not be called in case writing was aborted. |
| 4450 | */ |
| 4451 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4452 | /** |
| 4453 | * Writes the next chunk of heap stats data into the stream. Writing |
| 4454 | * can be stopped by returning kAbort as function result. EndOfStream |
| 4455 | * will not be called in case writing was aborted. |
| 4456 | */ |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4457 | virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 4458 | return kAbort; |
| 4459 | }; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4460 | }; |
| 4461 | |
| 4462 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4463 | /** |
| 4464 | * An interface for reporting progress and controlling long-running |
| 4465 | * activities. |
| 4466 | */ |
| 4467 | class V8EXPORT ActivityControl { // NOLINT |
| 4468 | public: |
| 4469 | enum ControlOption { |
| 4470 | kContinue = 0, |
| 4471 | kAbort = 1 |
| 4472 | }; |
| 4473 | virtual ~ActivityControl() {} |
| 4474 | /** |
| 4475 | * Notify about current progress. The activity can be stopped by |
| 4476 | * returning kAbort as the callback result. |
| 4477 | */ |
| 4478 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 4479 | }; |
| 4480 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4481 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4482 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4483 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4484 | |
| 4485 | namespace internal { |
| 4486 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4487 | const int kApiPointerSize = sizeof(void*); // NOLINT |
| 4488 | const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4489 | |
| 4490 | // Tag information for HeapObject. |
| 4491 | const int kHeapObjectTag = 1; |
| 4492 | const int kHeapObjectTagSize = 2; |
| 4493 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 4494 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4495 | // Tag information for Smi. |
| 4496 | const int kSmiTag = 0; |
| 4497 | const int kSmiTagSize = 1; |
| 4498 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 4499 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4500 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4501 | |
| 4502 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4503 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4504 | static const int kSmiShiftSize = 0; |
| 4505 | static const int kSmiValueSize = 31; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4506 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4507 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 4508 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 4509 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 4510 | } |
| 4511 | }; |
| 4512 | |
| 4513 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4514 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4515 | static const int kSmiShiftSize = 31; |
| 4516 | static const int kSmiValueSize = 32; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4517 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4518 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 4519 | // Shift down and throw away top 32 bits. |
| 4520 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 4521 | } |
| 4522 | }; |
| 4523 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4524 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 4525 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 4526 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4527 | |
| 4528 | /** |
| 4529 | * This class exports constants and functionality from within v8 that |
| 4530 | * is necessary to implement inline functions in the v8 api. Don't |
| 4531 | * depend on functions and constants defined here. |
| 4532 | */ |
| 4533 | class Internals { |
| 4534 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4535 | // These values match non-compiler-dependent values defined within |
| 4536 | // the implementation of v8. |
| 4537 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4538 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4539 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4540 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4541 | static const int kOddballKindOffset = 3 * kApiPointerSize; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4542 | static const int kForeignAddressOffset = kApiPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4543 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4544 | static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
| 4545 | static const int kContextHeaderSize = 2 * kApiPointerSize; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 4546 | static const int kContextEmbedderDataIndex = 56; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4547 | static const int kFullStringRepresentationMask = 0x07; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4548 | static const int kStringEncodingMask = 0x4; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 4549 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4550 | static const int kExternalAsciiRepresentationTag = 0x06; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4551 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4552 | static const int kIsolateStateOffset = 0; |
| 4553 | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 4554 | static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 4555 | static const int kUndefinedValueRootIndex = 5; |
| 4556 | static const int kNullValueRootIndex = 7; |
| 4557 | static const int kTrueValueRootIndex = 8; |
| 4558 | static const int kFalseValueRootIndex = 9; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4559 | static const int kEmptyStringRootIndex = 118; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4560 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4561 | static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 4562 | static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 4563 | static const int kNodeStateMask = 0xf; |
| 4564 | static const int kNodeStateIsWeakValue = 2; |
| 4565 | static const int kNodeStateIsNearDeathValue = 4; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4566 | static const int kNodeIsIndependentShift = 4; |
| 4567 | static const int kNodeIsPartiallyDependentShift = 5; |
| 4568 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4569 | static const int kJSObjectType = 0xae; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 4570 | static const int kFirstNonstringType = 0x80; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4571 | static const int kOddballType = 0x83; |
| 4572 | static const int kForeignType = 0x86; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4573 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4574 | static const int kUndefinedOddballKind = 5; |
| 4575 | static const int kNullOddballKind = 3; |
| 4576 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4577 | V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4578 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 4579 | kHeapObjectTag); |
| 4580 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4581 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4582 | V8_INLINE(static int SmiValue(internal::Object* value)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4583 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4584 | } |
| 4585 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4586 | V8_INLINE(static int GetInstanceType(internal::Object* obj)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4587 | typedef internal::Object O; |
| 4588 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 4589 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 4590 | } |
| 4591 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4592 | V8_INLINE(static int GetOddballKind(internal::Object* obj)) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4593 | typedef internal::Object O; |
| 4594 | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 4595 | } |
| 4596 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4597 | V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4598 | int representation = (instance_type & kFullStringRepresentationMask); |
| 4599 | return representation == kExternalTwoByteRepresentationTag; |
| 4600 | } |
| 4601 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4602 | V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4603 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 4604 | return *reinterpret_cast<int*>(addr) == 1; |
| 4605 | } |
| 4606 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4607 | V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { |
| 4608 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 4609 | return *addr & (1 << shift); |
| 4610 | } |
| 4611 | |
| 4612 | V8_INLINE(static void UpdateNodeFlag(internal::Object** obj, |
| 4613 | bool value, int shift)) { |
| 4614 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 4615 | uint8_t mask = 1 << shift; |
| 4616 | *addr = (*addr & ~mask) | (value << shift); |
| 4617 | } |
| 4618 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4619 | V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { |
| 4620 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 4621 | return *addr & kNodeStateMask; |
| 4622 | } |
| 4623 | |
| 4624 | V8_INLINE(static void UpdateNodeState(internal::Object** obj, |
| 4625 | uint8_t value)) { |
| 4626 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 4627 | *addr = (*addr & ~kNodeStateMask) | value; |
| 4628 | } |
| 4629 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4630 | V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4631 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 4632 | kIsolateEmbedderDataOffset; |
| 4633 | *reinterpret_cast<void**>(addr) = data; |
| 4634 | } |
| 4635 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4636 | V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4637 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 4638 | kIsolateEmbedderDataOffset; |
| 4639 | return *reinterpret_cast<void**>(addr); |
| 4640 | } |
| 4641 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4642 | V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate, |
| 4643 | int index)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4644 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 4645 | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 4646 | } |
| 4647 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4648 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4649 | V8_INLINE(static T ReadField(Object* ptr, int offset)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4650 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 4651 | return *reinterpret_cast<T*>(addr); |
| 4652 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4653 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4654 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4655 | V8_INLINE(static T ReadEmbedderData(Context* context, int index)) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4656 | typedef internal::Object O; |
| 4657 | typedef internal::Internals I; |
| 4658 | O* ctx = *reinterpret_cast<O**>(context); |
| 4659 | int embedder_data_offset = I::kContextHeaderSize + |
| 4660 | (internal::kApiPointerSize * I::kContextEmbedderDataIndex); |
| 4661 | O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); |
| 4662 | int value_offset = |
| 4663 | I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); |
| 4664 | return I::ReadField<T>(embedder_data, value_offset); |
| 4665 | } |
| 4666 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4667 | V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; } |
| 4668 | V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; } |
| 4669 | V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; } |
| 4670 | V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; } |
| 4671 | V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; } |
| 4672 | V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; } |
| 4673 | V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4674 | }; |
| 4675 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 4676 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4677 | |
| 4678 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4679 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4680 | Local<T>::Local() : Handle<T>() { } |
| 4681 | |
| 4682 | |
| 4683 | template <class T> |
| 4684 | Local<T> Local<T>::New(Handle<T> that) { |
| 4685 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4686 | T* that_ptr = *that; |
| 4687 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 4688 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 4689 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 4690 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 4691 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4692 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 4693 | } |
| 4694 | |
| 4695 | |
| 4696 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4697 | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4698 | if (that.IsEmpty()) return Local<T>(); |
| 4699 | T* that_ptr = *that; |
| 4700 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 4701 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 4702 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 4703 | } |
| 4704 | |
| 4705 | |
| 4706 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4707 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4708 | return New(Isolate::GetCurrent(), that); |
| 4709 | } |
| 4710 | |
| 4711 | |
| 4712 | template <class T> |
| 4713 | Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4714 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4715 | internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4716 | return Persistent<T>(reinterpret_cast<T*>( |
| 4717 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 4718 | p))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | |
| 4722 | template <class T> |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4723 | bool Persistent<T>::IsIndependent() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4724 | return IsIndependent(Isolate::GetCurrent()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | |
| 4728 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4729 | bool Persistent<T>::IsIndependent(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4730 | typedef internal::Internals I; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4731 | if (this->IsEmpty()) return false; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4732 | if (!I::IsInitialized(isolate)) return false; |
| 4733 | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(**this), |
| 4734 | I::kNodeIsIndependentShift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | |
| 4738 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4739 | bool Persistent<T>::IsNearDeath() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4740 | return IsNearDeath(Isolate::GetCurrent()); |
| 4741 | } |
| 4742 | |
| 4743 | |
| 4744 | template <class T> |
| 4745 | bool Persistent<T>::IsNearDeath(Isolate* isolate) const { |
| 4746 | typedef internal::Internals I; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4747 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4748 | if (!I::IsInitialized(isolate)) return false; |
| 4749 | return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) == |
| 4750 | I::kNodeStateIsNearDeathValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | |
| 4754 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4755 | bool Persistent<T>::IsWeak() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4756 | return IsWeak(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | |
| 4760 | template <class T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4761 | bool Persistent<T>::IsWeak(Isolate* isolate) const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4762 | typedef internal::Internals I; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4763 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4764 | if (!I::IsInitialized(isolate)) return false; |
| 4765 | return I::GetNodeState(reinterpret_cast<internal::Object**>(**this)) == |
| 4766 | I::kNodeStateIsWeakValue; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | |
| 4770 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4771 | void Persistent<T>::Dispose() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4772 | Dispose(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | |
| 4776 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4777 | void Persistent<T>::Dispose(Isolate* isolate) { |
| 4778 | if (this->IsEmpty()) return; |
| 4779 | V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), |
| 4780 | reinterpret_cast<internal::Object**>(**this)); |
| 4781 | } |
| 4782 | |
| 4783 | |
| 4784 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4785 | Persistent<T>::Persistent() : Handle<T>() { } |
| 4786 | |
| 4787 | template <class T> |
| 4788 | void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4789 | Isolate* isolate = Isolate::GetCurrent(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4790 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
| 4791 | reinterpret_cast<internal::Object**>(**this), |
| 4792 | parameters, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4793 | callback, |
| 4794 | NULL); |
| 4795 | } |
| 4796 | |
| 4797 | template <class T> |
| 4798 | void Persistent<T>::MakeWeak(Isolate* isolate, |
| 4799 | void* parameters, |
| 4800 | NearDeathCallback callback) { |
| 4801 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
| 4802 | reinterpret_cast<internal::Object**>(**this), |
| 4803 | parameters, |
| 4804 | NULL, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4805 | callback); |
| 4806 | } |
| 4807 | |
| 4808 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4809 | void Persistent<T>::ClearWeak() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4810 | ClearWeak(Isolate::GetCurrent()); |
| 4811 | } |
| 4812 | |
| 4813 | template <class T> |
| 4814 | void Persistent<T>::ClearWeak(Isolate* isolate) { |
| 4815 | V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), |
| 4816 | reinterpret_cast<internal::Object**>(**this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4817 | } |
| 4818 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4819 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4820 | void Persistent<T>::MarkIndependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4821 | MarkIndependent(Isolate::GetCurrent()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | template <class T> |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4825 | void Persistent<T>::MarkIndependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4826 | typedef internal::Internals I; |
| 4827 | if (this->IsEmpty()) return; |
| 4828 | if (!I::IsInitialized(isolate)) return; |
| 4829 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4830 | true, |
| 4831 | I::kNodeIsIndependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | template <class T> |
| 4835 | void Persistent<T>::MarkPartiallyDependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4836 | MarkPartiallyDependent(Isolate::GetCurrent()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | template <class T> |
| 4840 | void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4841 | typedef internal::Internals I; |
| 4842 | if (this->IsEmpty()) return; |
| 4843 | if (!I::IsInitialized(isolate)) return; |
| 4844 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(**this), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4845 | true, |
| 4846 | I::kNodeIsPartiallyDependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | template <class T> |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4850 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4851 | SetWrapperClassId(Isolate::GetCurrent(), class_id); |
| 4852 | } |
| 4853 | |
| 4854 | template <class T> |
| 4855 | void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4856 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4857 | if (this->IsEmpty()) return; |
| 4858 | if (!I::IsInitialized(isolate)) return; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4859 | internal::Object** obj = reinterpret_cast<internal::Object**>(**this); |
| 4860 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 4861 | *reinterpret_cast<uint16_t*>(addr) = class_id; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4862 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4863 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4864 | template <class T> |
| 4865 | uint16_t Persistent<T>::WrapperClassId() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4866 | return WrapperClassId(Isolate::GetCurrent()); |
| 4867 | } |
| 4868 | |
| 4869 | template <class T> |
| 4870 | uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4871 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4872 | if (this->IsEmpty()) return 0; |
| 4873 | if (!I::IsInitialized(isolate)) return 0; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4874 | internal::Object** obj = reinterpret_cast<internal::Object**>(**this); |
| 4875 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 4876 | return *reinterpret_cast<uint16_t*>(addr); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4877 | } |
| 4878 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 4879 | Arguments::Arguments(internal::Object** implicit_args, |
| 4880 | internal::Object** values, int length, |
| 4881 | bool is_construct_call) |
| 4882 | : implicit_args_(implicit_args), |
| 4883 | values_(values), |
| 4884 | length_(length), |
| 4885 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4886 | |
| 4887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4888 | Local<Value> Arguments::operator[](int i) const { |
| 4889 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 4890 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 4891 | } |
| 4892 | |
| 4893 | |
| 4894 | Local<Function> Arguments::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 4895 | return Local<Function>(reinterpret_cast<Function*>( |
| 4896 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | |
| 4900 | Local<Object> Arguments::This() const { |
| 4901 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 4902 | } |
| 4903 | |
| 4904 | |
| 4905 | Local<Object> Arguments::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 4906 | return Local<Object>(reinterpret_cast<Object*>( |
| 4907 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | |
| 4911 | Local<Value> Arguments::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 4912 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4916 | Isolate* Arguments::GetIsolate() const { |
| 4917 | return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); |
| 4918 | } |
| 4919 | |
| 4920 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4921 | bool Arguments::IsConstructCall() const { |
| 4922 | return is_construct_call_; |
| 4923 | } |
| 4924 | |
| 4925 | |
| 4926 | int Arguments::Length() const { |
| 4927 | return length_; |
| 4928 | } |
| 4929 | |
| 4930 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4931 | template <class T> |
| 4932 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4933 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 4934 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4935 | return Local<T>(reinterpret_cast<T*>(after)); |
| 4936 | } |
| 4937 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4938 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4939 | return resource_name_; |
| 4940 | } |
| 4941 | |
| 4942 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4943 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4944 | return resource_line_offset_; |
| 4945 | } |
| 4946 | |
| 4947 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4948 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4949 | return resource_column_offset_; |
| 4950 | } |
| 4951 | |
| 4952 | |
| 4953 | Handle<Boolean> Boolean::New(bool value) { |
| 4954 | return value ? True() : False(); |
| 4955 | } |
| 4956 | |
| 4957 | |
| 4958 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 4959 | Set(v8::String::New(name), value); |
| 4960 | } |
| 4961 | |
| 4962 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4963 | Local<Value> Object::GetInternalField(int index) { |
| 4964 | #ifndef V8_ENABLE_CHECKS |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4965 | typedef internal::Object O; |
| 4966 | typedef internal::Internals I; |
| 4967 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4968 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 4969 | // 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] | 4970 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4971 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4972 | O* value = I::ReadField<O*>(obj, offset); |
| 4973 | O** result = HandleScope::CreateHandle(value); |
| 4974 | return Local<Value>(reinterpret_cast<Value*>(result)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4975 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4976 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4977 | return SlowGetInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4981 | void* Object::GetAlignedPointerFromInternalField(int index) { |
| 4982 | #ifndef V8_ENABLE_CHECKS |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4983 | typedef internal::Object O; |
| 4984 | typedef internal::Internals I; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4985 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4986 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 4987 | // know where to find the internal fields and can return the value directly. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 4988 | if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4989 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4990 | return I::ReadField<void*>(obj, offset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4991 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4992 | #endif |
| 4993 | return SlowGetAlignedPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | |
| 4997 | String* String::Cast(v8::Value* value) { |
| 4998 | #ifdef V8_ENABLE_CHECKS |
| 4999 | CheckCast(value); |
| 5000 | #endif |
| 5001 | return static_cast<String*>(value); |
| 5002 | } |
| 5003 | |
| 5004 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5005 | Local<String> String::Empty(Isolate* isolate) { |
| 5006 | typedef internal::Object* S; |
| 5007 | typedef internal::Internals I; |
| 5008 | if (!I::IsInitialized(isolate)) return Empty(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5009 | S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5010 | return Local<String>(reinterpret_cast<String*>(slot)); |
| 5011 | } |
| 5012 | |
| 5013 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5014 | Local<String> String::New(const char* data, int length) { |
| 5015 | return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length); |
| 5016 | } |
| 5017 | |
| 5018 | |
| 5019 | Local<String> String::New(const uint16_t* data, int length) { |
| 5020 | return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length); |
| 5021 | } |
| 5022 | |
| 5023 | |
| 5024 | Local<String> String::NewSymbol(const char* data, int length) { |
| 5025 | return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length); |
| 5026 | } |
| 5027 | |
| 5028 | |
| 5029 | Local<String> String::NewUndetectable(const char* data, int length) { |
| 5030 | return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5031 | } |
| 5032 | |
| 5033 | |
| 5034 | Local<String> String::NewUndetectable(const uint16_t* data, int length) { |
| 5035 | return NewFromTwoByte( |
| 5036 | Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5037 | } |
| 5038 | |
| 5039 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5040 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 5041 | typedef internal::Object O; |
| 5042 | typedef internal::Internals I; |
| 5043 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5044 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5045 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5046 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5047 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 5048 | } else { |
| 5049 | result = NULL; |
| 5050 | } |
| 5051 | #ifdef V8_ENABLE_CHECKS |
| 5052 | VerifyExternalStringResource(result); |
| 5053 | #endif |
| 5054 | return result; |
| 5055 | } |
| 5056 | |
| 5057 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5058 | String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| 5059 | String::Encoding* encoding_out) const { |
| 5060 | typedef internal::Object O; |
| 5061 | typedef internal::Internals I; |
| 5062 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 5063 | int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 5064 | *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| 5065 | ExternalStringResourceBase* resource = NULL; |
| 5066 | if (type == I::kExternalAsciiRepresentationTag || |
| 5067 | type == I::kExternalTwoByteRepresentationTag) { |
| 5068 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5069 | resource = static_cast<ExternalStringResourceBase*>(value); |
| 5070 | } |
| 5071 | #ifdef V8_ENABLE_CHECKS |
| 5072 | VerifyExternalStringResourceBase(resource, *encoding_out); |
| 5073 | #endif |
| 5074 | return resource; |
| 5075 | } |
| 5076 | |
| 5077 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5078 | bool Value::IsUndefined() const { |
| 5079 | #ifdef V8_ENABLE_CHECKS |
| 5080 | return FullIsUndefined(); |
| 5081 | #else |
| 5082 | return QuickIsUndefined(); |
| 5083 | #endif |
| 5084 | } |
| 5085 | |
| 5086 | bool Value::QuickIsUndefined() const { |
| 5087 | typedef internal::Object O; |
| 5088 | typedef internal::Internals I; |
| 5089 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5090 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5091 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5092 | return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 5093 | } |
| 5094 | |
| 5095 | |
| 5096 | bool Value::IsNull() const { |
| 5097 | #ifdef V8_ENABLE_CHECKS |
| 5098 | return FullIsNull(); |
| 5099 | #else |
| 5100 | return QuickIsNull(); |
| 5101 | #endif |
| 5102 | } |
| 5103 | |
| 5104 | bool Value::QuickIsNull() const { |
| 5105 | typedef internal::Object O; |
| 5106 | typedef internal::Internals I; |
| 5107 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5108 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5109 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5110 | return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 5111 | } |
| 5112 | |
| 5113 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5114 | bool Value::IsString() const { |
| 5115 | #ifdef V8_ENABLE_CHECKS |
| 5116 | return FullIsString(); |
| 5117 | #else |
| 5118 | return QuickIsString(); |
| 5119 | #endif |
| 5120 | } |
| 5121 | |
| 5122 | bool Value::QuickIsString() const { |
| 5123 | typedef internal::Object O; |
| 5124 | typedef internal::Internals I; |
| 5125 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5126 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5127 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5131 | Symbol* Symbol::Cast(v8::Value* value) { |
| 5132 | #ifdef V8_ENABLE_CHECKS |
| 5133 | CheckCast(value); |
| 5134 | #endif |
| 5135 | return static_cast<Symbol*>(value); |
| 5136 | } |
| 5137 | |
| 5138 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5139 | Number* Number::Cast(v8::Value* value) { |
| 5140 | #ifdef V8_ENABLE_CHECKS |
| 5141 | CheckCast(value); |
| 5142 | #endif |
| 5143 | return static_cast<Number*>(value); |
| 5144 | } |
| 5145 | |
| 5146 | |
| 5147 | Integer* Integer::Cast(v8::Value* value) { |
| 5148 | #ifdef V8_ENABLE_CHECKS |
| 5149 | CheckCast(value); |
| 5150 | #endif |
| 5151 | return static_cast<Integer*>(value); |
| 5152 | } |
| 5153 | |
| 5154 | |
| 5155 | Date* Date::Cast(v8::Value* value) { |
| 5156 | #ifdef V8_ENABLE_CHECKS |
| 5157 | CheckCast(value); |
| 5158 | #endif |
| 5159 | return static_cast<Date*>(value); |
| 5160 | } |
| 5161 | |
| 5162 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5163 | StringObject* StringObject::Cast(v8::Value* value) { |
| 5164 | #ifdef V8_ENABLE_CHECKS |
| 5165 | CheckCast(value); |
| 5166 | #endif |
| 5167 | return static_cast<StringObject*>(value); |
| 5168 | } |
| 5169 | |
| 5170 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5171 | SymbolObject* SymbolObject::Cast(v8::Value* value) { |
| 5172 | #ifdef V8_ENABLE_CHECKS |
| 5173 | CheckCast(value); |
| 5174 | #endif |
| 5175 | return static_cast<SymbolObject*>(value); |
| 5176 | } |
| 5177 | |
| 5178 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5179 | NumberObject* NumberObject::Cast(v8::Value* value) { |
| 5180 | #ifdef V8_ENABLE_CHECKS |
| 5181 | CheckCast(value); |
| 5182 | #endif |
| 5183 | return static_cast<NumberObject*>(value); |
| 5184 | } |
| 5185 | |
| 5186 | |
| 5187 | BooleanObject* BooleanObject::Cast(v8::Value* value) { |
| 5188 | #ifdef V8_ENABLE_CHECKS |
| 5189 | CheckCast(value); |
| 5190 | #endif |
| 5191 | return static_cast<BooleanObject*>(value); |
| 5192 | } |
| 5193 | |
| 5194 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5195 | RegExp* RegExp::Cast(v8::Value* value) { |
| 5196 | #ifdef V8_ENABLE_CHECKS |
| 5197 | CheckCast(value); |
| 5198 | #endif |
| 5199 | return static_cast<RegExp*>(value); |
| 5200 | } |
| 5201 | |
| 5202 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5203 | Object* Object::Cast(v8::Value* value) { |
| 5204 | #ifdef V8_ENABLE_CHECKS |
| 5205 | CheckCast(value); |
| 5206 | #endif |
| 5207 | return static_cast<Object*>(value); |
| 5208 | } |
| 5209 | |
| 5210 | |
| 5211 | Array* Array::Cast(v8::Value* value) { |
| 5212 | #ifdef V8_ENABLE_CHECKS |
| 5213 | CheckCast(value); |
| 5214 | #endif |
| 5215 | return static_cast<Array*>(value); |
| 5216 | } |
| 5217 | |
| 5218 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame^] | 5219 | ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { |
| 5220 | #ifdef V8_ENABLE_CHECKS |
| 5221 | CheckCast(value); |
| 5222 | #endif |
| 5223 | return static_cast<ArrayBuffer*>(value); |
| 5224 | } |
| 5225 | |
| 5226 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5227 | Function* Function::Cast(v8::Value* value) { |
| 5228 | #ifdef V8_ENABLE_CHECKS |
| 5229 | CheckCast(value); |
| 5230 | #endif |
| 5231 | return static_cast<Function*>(value); |
| 5232 | } |
| 5233 | |
| 5234 | |
| 5235 | External* External::Cast(v8::Value* value) { |
| 5236 | #ifdef V8_ENABLE_CHECKS |
| 5237 | CheckCast(value); |
| 5238 | #endif |
| 5239 | return static_cast<External*>(value); |
| 5240 | } |
| 5241 | |
| 5242 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5243 | Isolate* AccessorInfo::GetIsolate() const { |
| 5244 | return *reinterpret_cast<Isolate**>(&args_[-3]); |
| 5245 | } |
| 5246 | |
| 5247 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5248 | Local<Value> AccessorInfo::Data() const { |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5249 | return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | |
| 5253 | Local<Object> AccessorInfo::This() const { |
| 5254 | return Local<Object>(reinterpret_cast<Object*>(&args_[0])); |
| 5255 | } |
| 5256 | |
| 5257 | |
| 5258 | Local<Object> AccessorInfo::Holder() const { |
| 5259 | return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); |
| 5260 | } |
| 5261 | |
| 5262 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5263 | Handle<Primitive> Undefined(Isolate* isolate) { |
| 5264 | typedef internal::Object* S; |
| 5265 | typedef internal::Internals I; |
| 5266 | if (!I::IsInitialized(isolate)) return Undefined(); |
| 5267 | S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 5268 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 5269 | } |
| 5270 | |
| 5271 | |
| 5272 | Handle<Primitive> Null(Isolate* isolate) { |
| 5273 | typedef internal::Object* S; |
| 5274 | typedef internal::Internals I; |
| 5275 | if (!I::IsInitialized(isolate)) return Null(); |
| 5276 | S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
| 5277 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 5278 | } |
| 5279 | |
| 5280 | |
| 5281 | Handle<Boolean> True(Isolate* isolate) { |
| 5282 | typedef internal::Object* S; |
| 5283 | typedef internal::Internals I; |
| 5284 | if (!I::IsInitialized(isolate)) return True(); |
| 5285 | S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 5286 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 5287 | } |
| 5288 | |
| 5289 | |
| 5290 | Handle<Boolean> False(Isolate* isolate) { |
| 5291 | typedef internal::Object* S; |
| 5292 | typedef internal::Internals I; |
| 5293 | if (!I::IsInitialized(isolate)) return False(); |
| 5294 | S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 5295 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 5296 | } |
| 5297 | |
| 5298 | |
| 5299 | void Isolate::SetData(void* data) { |
| 5300 | typedef internal::Internals I; |
| 5301 | I::SetEmbedderData(this, data); |
| 5302 | } |
| 5303 | |
| 5304 | |
| 5305 | void* Isolate::GetData() { |
| 5306 | typedef internal::Internals I; |
| 5307 | return I::GetEmbedderData(this); |
| 5308 | } |
| 5309 | |
| 5310 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5311 | Local<Value> Context::GetEmbedderData(int index) { |
| 5312 | #ifndef V8_ENABLE_CHECKS |
| 5313 | typedef internal::Object O; |
| 5314 | typedef internal::Internals I; |
| 5315 | O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); |
| 5316 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 5317 | #else |
| 5318 | return SlowGetEmbedderData(index); |
| 5319 | #endif |
| 5320 | } |
| 5321 | |
| 5322 | |
| 5323 | void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 5324 | #ifndef V8_ENABLE_CHECKS |
| 5325 | typedef internal::Internals I; |
| 5326 | return I::ReadEmbedderData<void*>(this, index); |
| 5327 | #else |
| 5328 | return SlowGetAlignedPointerFromEmbedderData(index); |
| 5329 | #endif |
| 5330 | } |
| 5331 | |
| 5332 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5333 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5334 | * \example shell.cc |
| 5335 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5336 | * command-line and executes them. |
| 5337 | */ |
| 5338 | |
| 5339 | |
| 5340 | /** |
| 5341 | * \example process.cc |
| 5342 | */ |
| 5343 | |
| 5344 | |
| 5345 | } // namespace v8 |
| 5346 | |
| 5347 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5348 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5349 | #undef TYPE_CHECK |
| 5350 | |
| 5351 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5352 | #endif // V8_H_ |